From dccab72215d3c8c5713234ca4fbb27d1b3243969 Mon Sep 17 00:00:00 2001 From: pngwt4f59 <1351816101@qq.com> Date: Thu, 8 Jul 2021 23:56:07 +0800 Subject: [PATCH] ADD file via upload --- getdents.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 getdents.c diff --git a/getdents.c b/getdents.c new file mode 100644 index 0000000..de118a1 --- /dev/null +++ b/getdents.c @@ -0,0 +1,96 @@ +#include +#include +#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 *d, unsigned int count) +{ + struct file *f; + struct m_inode * m; + struct buffer_head * b; + struct dir_entry * dir; + int i,j,k,res; + struct linux_dirent usrd; + i=0; + res=0; + f=current->filp[fd]; + m=f->f_inode; + b=bread(m->i_dev,m->i_zone[0]); + dir=(struct dir_entry*)b->b_data; + while(dir[i].inode>0) + { + if(res+sizeof(struct linux_dirent)>count) + break; + usrd.d_ino=dir[i].inode; + usrd.d_off=0; + usrd.d_reclen=sizeof(struct linux_dirent); + for(j=0;j<14;j++) + usrd.d_name[j]=dir[i].name[j]; + for(k=0;kroot->i_dev; + inode=current->pwd; + inum=inode->i_num; + b=bread(dev,inode->i_zone[0]); + d=(struct dir_entry*) b->b_data; + i=0; + l=0; + while(inum!=1) + { + inode=iget(dev, d[1].inode); + b=bread(dev,inode->i_zone[0]); + d=(struct dir_entry*) b->b_data; + j=0; + while(d[j].inode!=inum) j++; + inum=inode->i_num; + path[i]=d[j].name; + i++; + } + while(i>0) + { + i--; + put_fs_byte('/',buf+l); + l++; + k=0; + while(path[i][k]!='\0') + { + put_fs_byte(path[i][k],buf+l); + l++; + if(l>=size) break; + k++; + } + if(l>=size) break; + } + return buf; +} + + +