sys_write

This commit is contained in:
fslongjin 2022-04-28 23:24:53 +08:00
parent d9399944e8
commit 3e101d71ff
2 changed files with 38 additions and 0 deletions

View File

@ -268,6 +268,43 @@ uint64_t sys_read(struct pt_regs *regs)
return ret; return ret;
} }
/**
* @brief
*
* @param fd_num regs->r8
* @param buf regs->r9
* @param count regs->r10
*
* @return uint64_t
*/
uint64_t sys_write(struct pt_regs *regs)
{
int fd_num = (int)regs->r8;
void *buf = (void *)regs->r9;
int64_t count = (int64_t)regs->r10;
// kdebug("sys read: fd=%d", fd_num);
// 校验文件描述符范围
if (fd_num < 0 || fd_num > PROC_MAX_FD_NUM)
return -EBADF;
// 文件描述符不存在
if (current_pcb->fds[fd_num] == NULL)
return -EBADF;
if (count < 0)
return -EINVAL;
struct vfs_file_t *file_ptr = current_pcb->fds[fd_num];
uint64_t ret;
if (file_ptr->file_ops && file_ptr->file_ops->write)
ret = file_ptr->file_ops->write(file_ptr, (char *)buf, count, &(file_ptr->position));
return ret;
}
ul sys_ahci_end_req(struct pt_regs *regs) ul sys_ahci_end_req(struct pt_regs *regs)
{ {
ahci_end_request(); ahci_end_request();

View File

@ -14,5 +14,6 @@
#define SYS_OPEN 2 #define SYS_OPEN 2
#define SYS_CLOSE 3 #define SYS_CLOSE 3
#define SYS_READ 4 #define SYS_READ 4
#define SYS_WRITE 5
#define SYS_AHCI_END_REQ 255 // AHCI DMA请求结束end_request的系统调用 #define SYS_AHCI_END_REQ 255 // AHCI DMA请求结束end_request的系统调用