|
|
1.1.1.2 root 1: /*
2: * linux/fs/read_write.c
3: *
1.1.1.9 ! root 4: * Copyright (C) 1991, 1992 Linus Torvalds
1.1.1.2 root 5: */
6:
1.1.1.9 ! root 7: #include <linux/types.h>
! 8: #include <linux/errno.h>
1.1.1.7 root 9: #include <linux/stat.h>
1.1 root 10: #include <linux/kernel.h>
11: #include <linux/sched.h>
1.1.1.5 root 12: #include <linux/minix_fs.h>
1.1.1.9 ! root 13:
1.1 root 14: #include <asm/segment.h>
15:
1.1.1.5 root 16: /*
17: * Count is not yet used: but we'll probably support reading several entries
18: * at once in the future. Use count=1 in the library for future expansions.
19: */
20: int sys_readdir(unsigned int fd, struct dirent * dirent, unsigned int count)
21: {
22: struct file * file;
23: struct inode * inode;
24:
25: if (fd >= NR_OPEN || !(file = current->filp[fd]) ||
26: !(inode = file->f_inode))
27: return -EBADF;
28: if (file->f_op && file->f_op->readdir) {
29: verify_area(dirent, sizeof (*dirent));
1.1.1.6 root 30: return file->f_op->readdir(inode,file,dirent,count);
1.1.1.5 root 31: }
1.1.1.6 root 32: return -ENOTDIR;
1.1.1.5 root 33: }
34:
35: int sys_lseek(unsigned int fd, off_t offset, unsigned int origin)
1.1 root 36: {
37: struct file * file;
1.1.1.8 root 38: int tmp = -1;
1.1 root 39:
1.1.1.4 root 40: if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode))
1.1 root 41: return -EBADF;
1.1.1.4 root 42: if (origin > 2)
43: return -EINVAL;
44: if (file->f_op && file->f_op->lseek)
45: return file->f_op->lseek(file->f_inode,file,offset,origin);
1.1.1.5 root 46:
1.1.1.4 root 47: /* this is the default handler if no lseek handler is present */
1.1 root 48: switch (origin) {
49: case 0:
1.1.1.6 root 50: tmp = offset;
1.1 root 51: break;
52: case 1:
1.1.1.6 root 53: tmp = file->f_pos + offset;
1.1 root 54: break;
55: case 2:
1.1.1.6 root 56: if (!file->f_inode)
1.1 root 57: return -EINVAL;
1.1.1.6 root 58: tmp = file->f_inode->i_size + offset;
59: break;
1.1 root 60: }
1.1.1.6 root 61: if (tmp < 0)
62: return -EINVAL;
63: file->f_pos = tmp;
64: file->f_reada = 0;
1.1 root 65: return file->f_pos;
66: }
67:
1.1.1.4 root 68: int sys_read(unsigned int fd,char * buf,unsigned int count)
1.1 root 69: {
70: struct file * file;
1.1.1.4 root 71: struct inode * inode;
1.1 root 72:
1.1.1.4 root 73: if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
74: return -EBADF;
75: if (!(file->f_mode & 1))
76: return -EBADF;
1.1 root 77: if (!count)
78: return 0;
79: verify_area(buf,count);
1.1.1.4 root 80: if (file->f_op && file->f_op->read)
81: return file->f_op->read(inode,file,buf,count);
1.1 root 82: return -EINVAL;
83: }
84:
1.1.1.4 root 85: int sys_write(unsigned int fd,char * buf,unsigned int count)
1.1 root 86: {
87: struct file * file;
1.1.1.4 root 88: struct inode * inode;
1.1 root 89:
1.1.1.4 root 90: if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
91: return -EBADF;
92: if (!(file->f_mode&2))
93: return -EBADF;
1.1 root 94: if (!count)
95: return 0;
1.1.1.4 root 96: if (file->f_op && file->f_op->write)
97: return file->f_op->write(inode,file,buf,count);
1.1 root 98: return -EINVAL;
99: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.