📄 read_write.c
字号:
/* * linux/fs/read_write.c * * Copyright (C) 1991, 1992 Linus Torvalds */#include <fairysky/types.h>#include <fairysky/errno.h>//#include <fairysky/stat.h>//#include <fairysky/kernel.h>#include <fairysky/scheduler.h>//#include <fairysky/minix_fs.h>#include <fairysky/limits.h>#include <asm/segment.h>/* * Count is not yet used: but we'll probably support reading several entries * at once in the future. Use count=1 in the library for future expansions. */int sys_readdir(u32 fd, struct direntry * direntry, count_t count){ struct file * file; struct inode * inode; if (fd >= NR_OPEN || !(file = current->file_pointer[fd]) || !(inode = file->f_inode)) { return -EBADF; } if (file->f_op && file->f_op->readdir) { verify_area(direntry, sizeof (*direntry)); return file->f_op->readdir(inode, file, direntry, count); } return -ENOTDIR;}int sys_lseek(unsigned int fd, off_t offset, unsigned int origin){ struct file * file; int tmp = -1; if (fd >= NR_OPEN || !(file=current->file_pointer[fd]) || !(file->f_inode)) { return -EBADF; } if (origin > 2) { return -EINVAL; } if (file->f_op && file->f_op->lseek) { return file->f_op->lseek(file->f_inode, file, offset, origin); }// this is the default handler if no lseek handler is present switch (origin) { case 0: tmp = offset; break; case 1: tmp = file->f_pos + offset; break; case 2: if (!file->f_inode) { return -EINVAL; } tmp = file->f_inode->i_size + offset; break; } if (tmp < 0) { return -EINVAL; } file->f_pos = tmp; return file->f_pos;}int sys_read(u32 fd, char * buf, count_t count){ struct file * file; struct inode * inode; if (fd >= NR_OPEN || !(file = current->file_pointer[fd]) || ! (inode = file->f_inode)) { return -EBADF; } if (!(file->f_mode & 1)) { return -EBADF; } if (! count) { return 0; } verify_area(buf, count); if (file->f_op && file->f_op->read) { return file->f_op->read(inode, file, buf, count); } return -EINVAL;}int sys_write(u32 fd, char * buf, count_t count){ struct file * file; struct inode * inode; if (fd >= NR_OPEN || ! (file = current->file_pointer[fd]) || ! (inode = file->f_inode)) { return -EBADF; } if (! (file->f_mode & 2)) { return -EBADF; } if (! count) { return 0; } if (file->f_op && file->f_op->write) { return file->f_op->write(inode, file, buf, count); } return -EINVAL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -