This source file includes following definitions.
- sys_readdir
- sys_lseek
- sys_read
- sys_write
1
2
3
4
5
6
7 #include <errno.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <sys/dirent.h>
11
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/minix_fs.h>
15 #include <asm/segment.h>
16
17
18
19
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));
31 return file->f_op->readdir(inode,file,dirent,count);
32 }
33 return -ENOTDIR;
34 }
35
36 int sys_lseek(unsigned int fd, off_t offset, unsigned int origin)
37 {
38 struct file * file;
39 int tmp;
40
41 if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode))
42 return -EBADF;
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);
47
48
49 switch (origin) {
50 case 0:
51 tmp = offset;
52 break;
53 case 1:
54 tmp = file->f_pos + offset;
55 break;
56 case 2:
57 if (!file->f_inode)
58 return -EINVAL;
59 tmp = file->f_inode->i_size + offset;
60 break;
61 }
62 if (tmp < 0)
63 return -EINVAL;
64 file->f_pos = tmp;
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 printk("(Read)inode->i_mode=%06o\n\r",inode->i_mode);
83 return -EINVAL;
84 }
85
86 int sys_write(unsigned int fd,char * buf,unsigned int count)
87 {
88 struct file * file;
89 struct inode * inode;
90
91 if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
92 return -EBADF;
93 if (!(file->f_mode&2))
94 return -EBADF;
95 if (!count)
96 return 0;
97 if (file->f_op && file->f_op->write)
98 return file->f_op->write(inode,file,buf,count);
99 printk("(Write)inode->i_mode=%06o\n\r",inode->i_mode);
100 return -EINVAL;
101 }