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