2 * linux/fs/read_write.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
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>
13 #include <asm/segment.h>
16 * Count is not yet used: but we'll probably support reading several entries
17 * at once in the future. Use count=1 in the library for future expansions.
19 asmlinkage
int sys_readdir(unsigned int fd
, struct dirent
* dirent
, unsigned int count
)
25 if (fd
>= NR_OPEN
|| !(file
= current
->filp
[fd
]) ||
26 !(inode
= file
->f_inode
))
29 if (file
->f_op
&& file
->f_op
->readdir
) {
30 error
= verify_area(VERIFY_WRITE
, dirent
, sizeof (*dirent
));
32 error
= file
->f_op
->readdir(inode
,file
,dirent
,count
);
37 asmlinkage
int sys_lseek(unsigned int fd
, off_t offset
, unsigned int origin
)
42 if (fd
>= NR_OPEN
|| !(file
=current
->filp
[fd
]) || !(file
->f_inode
))
46 if (file
->f_op
&& file
->f_op
->lseek
)
47 return file
->f_op
->lseek(file
->f_inode
,file
,offset
,origin
);
49 /* this is the default handler if no lseek handler is present */
55 tmp
= file
->f_pos
+ offset
;
60 tmp
= file
->f_inode
->i_size
+ offset
;
70 asmlinkage
int sys_read(unsigned int fd
,char * buf
,unsigned int count
)
76 if (fd
>=NR_OPEN
|| !(file
=current
->filp
[fd
]) || !(inode
=file
->f_inode
))
78 if (!(file
->f_mode
& 1))
80 if (!file
->f_op
|| !file
->f_op
->read
)
84 error
= verify_area(VERIFY_WRITE
,buf
,count
);
87 return file
->f_op
->read(inode
,file
,buf
,count
);
90 asmlinkage
int sys_write(unsigned int fd
,char * buf
,unsigned int count
)
96 if (fd
>=NR_OPEN
|| !(file
=current
->filp
[fd
]) || !(inode
=file
->f_inode
))
98 if (!(file
->f_mode
& 2))
100 if (!file
->f_op
|| !file
->f_op
->write
)
104 error
= verify_area(VERIFY_READ
,buf
,count
);
107 return file
->f_op
->write(inode
,file
,buf
,count
);