This source file includes following definitions.
- sys_readdir
- sys_lseek
- sys_read
- sys_write
1
2
3
4
5
6
7 #include <linux/types.h>
8 #include <linux/errno.h>
9 #include <linux/stat.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/minix_fs.h>
13
14 #include <asm/segment.h>
15
16
17
18
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));
30 return file->f_op->readdir(inode,file,dirent,count);
31 }
32 return -ENOTDIR;
33 }
34
35 int sys_lseek(unsigned int fd, off_t offset, unsigned int origin)
36 {
37 struct file * file;
38 int tmp = -1;
39
40 if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode))
41 return -EBADF;
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);
46
47
48 switch (origin) {
49 case 0:
50 tmp = offset;
51 break;
52 case 1:
53 tmp = file->f_pos + offset;
54 break;
55 case 2:
56 if (!file->f_inode)
57 return -EINVAL;
58 tmp = file->f_inode->i_size + offset;
59 break;
60 }
61 if (tmp < 0)
62 return -EINVAL;
63 file->f_pos = tmp;
64 file->f_reada = 0;
65 return file->f_pos;
66 }
67
68 int sys_read(unsigned int fd,char * buf,unsigned int count)
69 {
70 struct file * file;
71 struct inode * inode;
72
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;
77 if (!count)
78 return 0;
79 verify_area(buf,count);
80 if (file->f_op && file->f_op->read)
81 return file->f_op->read(inode,file,buf,count);
82 return -EINVAL;
83 }
84
85 int sys_write(unsigned int fd,char * buf,unsigned int count)
86 {
87 struct file * file;
88 struct inode * inode;
89
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;
94 if (!count)
95 return 0;
96 if (file->f_op && file->f_op->write)
97 return file->f_op->write(inode,file,buf,count);
98 return -EINVAL;
99 }