|
|
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 <sys/stat.h>
8: #include <errno.h>
9: #include <sys/types.h>
10:
11: #include <linux/kernel.h>
12: #include <linux/sched.h>
13: #include <asm/segment.h>
14:
1.1.1.4 ! root 15: int sys_lseek(unsigned int fd,off_t offset, unsigned int origin)
1.1 root 16: {
17: struct file * file;
18: int tmp;
19:
1.1.1.4 ! root 20: if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode))
1.1 root 21: return -EBADF;
1.1.1.4 ! root 22: if (origin > 2)
! 23: return -EINVAL;
1.1 root 24: if (file->f_inode->i_pipe)
25: return -ESPIPE;
1.1.1.4 ! root 26: if (file->f_op && file->f_op->lseek)
! 27: return file->f_op->lseek(file->f_inode,file,offset,origin);
! 28: /* this is the default handler if no lseek handler is present */
1.1 root 29: switch (origin) {
30: case 0:
31: if (offset<0) return -EINVAL;
32: file->f_pos=offset;
33: break;
34: case 1:
35: if (file->f_pos+offset<0) return -EINVAL;
36: file->f_pos += offset;
37: break;
38: case 2:
39: if ((tmp=file->f_inode->i_size+offset) < 0)
40: return -EINVAL;
41: file->f_pos = tmp;
42: }
43: return file->f_pos;
44: }
45:
1.1.1.4 ! root 46: int sys_read(unsigned int fd,char * buf,unsigned int count)
1.1 root 47: {
48: struct file * file;
1.1.1.4 ! root 49: struct inode * inode;
1.1 root 50:
1.1.1.4 ! root 51: if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
! 52: return -EBADF;
! 53: if (!(file->f_mode & 1))
! 54: return -EBADF;
1.1 root 55: if (!count)
56: return 0;
57: verify_area(buf,count);
1.1.1.4 ! root 58: if (file->f_op && file->f_op->read)
! 59: return file->f_op->read(inode,file,buf,count);
! 60: /* these are the default read-functions */
1.1 root 61: if (inode->i_pipe)
1.1.1.4 ! root 62: return pipe_read(inode,file,buf,count);
1.1 root 63: if (S_ISCHR(inode->i_mode))
1.1.1.4 ! root 64: return char_read(inode,file,buf,count);
1.1 root 65: if (S_ISBLK(inode->i_mode))
1.1.1.4 ! root 66: return block_read(inode,file,buf,count);
! 67: if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode))
! 68: return minix_file_read(inode,file,buf,count);
1.1 root 69: printk("(Read)inode->i_mode=%06o\n\r",inode->i_mode);
70: return -EINVAL;
71: }
72:
1.1.1.4 ! root 73: int sys_write(unsigned int fd,char * buf,unsigned int count)
1.1 root 74: {
75: struct file * file;
1.1.1.4 ! root 76: struct inode * inode;
1.1 root 77:
1.1.1.4 ! root 78: if (fd>=NR_OPEN || !(file=current->filp[fd]) || !(inode=file->f_inode))
! 79: return -EBADF;
! 80: if (!(file->f_mode&2))
! 81: return -EBADF;
1.1 root 82: if (!count)
83: return 0;
1.1.1.4 ! root 84: if (file->f_op && file->f_op->write)
! 85: return file->f_op->write(inode,file,buf,count);
! 86: /* these are the default read-functions */
1.1 root 87: if (inode->i_pipe)
1.1.1.4 ! root 88: return pipe_write(inode,file,buf,count);
1.1 root 89: if (S_ISCHR(inode->i_mode))
1.1.1.4 ! root 90: return char_write(inode,file,buf,count);
1.1 root 91: if (S_ISBLK(inode->i_mode))
1.1.1.4 ! root 92: return block_write(inode,file,buf,count);
1.1 root 93: if (S_ISREG(inode->i_mode))
1.1.1.4 ! root 94: return minix_file_write(inode,file,buf,count);
1.1 root 95: printk("(Write)inode->i_mode=%06o\n\r",inode->i_mode);
96: return -EINVAL;
97: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.