From 477f97e918f2d6b06df4c7ccea1c2cfbc56690bf Mon Sep 17 00:00:00 2001 From: pt7yg3sn6 <3081545786@qq.com> Date: Thu, 8 Jul 2021 23:53:03 +0800 Subject: [PATCH] ADD file via upload --- getdents.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 getdents.c diff --git a/getdents.c b/getdents.c new file mode 100644 index 0000000..edfcce8 --- /dev/null +++ b/getdents.c @@ -0,0 +1,46 @@ +#define __LIBRARY__ +#include +#include +#include +#include +#include +#include +#include +struct linux_dirent { + long d_ino; + off_t d_off; + unsigned short d_reclen; + char d_name[14]; +}; + +int sys_getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count) +{ + struct m_inode *m_ino; + struct buffer_head *buff_hd; + struct dir_entry *dir; + struct linux_dirent usr; + int i, j, res; + i = 0; + res = 0; + m_ino = current->filp[fd]->f_inode; + buff_hd = bread(m_ino->i_dev, m_ino->i_zone[0]); + dir = (struct dir_entry *)buff_hd->b_data; + while (dir[i].inode > 0) + { + if (res + sizeof(struct linux_dirent) > count) + break; + usr.d_ino = dir[i].inode; + usr.d_off = 0; + usr.d_reclen = sizeof(struct linux_dirent); + for (j = 0; j < 14; j++) + { + usr.d_name[j] = dir[i].name[j]; + } + for(j = 0;j