Commit b3c2b90e authored by 姜继扬's avatar 姜继扬
Browse files

getdents

parent 0b8ec988
No related merge requests found
Showing with 56 additions and 3 deletions
+56 -3
......@@ -130,7 +130,7 @@ extern uint64 sys_openat(void);
extern uint64 sys_dup3(void);
extern uint64 sys_mount(void);
extern uint64 sys_umount2(void);
// extern uint64 sys_getdents64(void);
extern uint64 sys_getdents64(void);
static uint64 (*syscalls[])(void) = {
[SYS_fork] sys_fork,
......@@ -175,7 +175,7 @@ static uint64 (*syscalls[])(void) = {
[SYS_pipe2] sys_pipe,
[SYS_mount] sys_mount,
[SYS_umount2] sys_umount2,
// [SYS_getdents64] sys_getdents64,
[SYS_getdents64] sys_getdents64,
};
static char *sysnames[] = {
......@@ -220,7 +220,7 @@ static char *sysnames[] = {
[SYS_pipe2] "pipe2",
[SYS_mount] "sys_mount",
[SYS_umount2] "sys_umount2",
// [SYS_getdents64] "getdents64",
[SYS_getdents64] "getdents64",
};
void
......
......@@ -620,3 +620,56 @@ fail:
eput(src);
return -1;
}
struct linux_dirent64
{
uint64 d_ino;
uint32 d_off;
unsigned short d_reclen;
unsigned char d_type;
char d_name[];
};
uint64
sys_getdents64(void)
{
int fd, len;
uint64 addr;
struct file *f;
int nread = 0;
struct dirent de;
int count = 0;
int ret;
struct linux_dirent64 tmp;
if (argint(0, &fd) < 0 || argint(2, &len) < 0 || argaddr(1, &addr) < 0)
{
return -1;
}
if (fd < 0 || fd >= NOFILE || (f = myproc()->ofile[fd]) == NULL)
return -1;
while (nread + (int)(sizeof(tmp)) <= len)
{
elock(f->ep);
// 跳过empty slots
while ((ret = enext(f->ep, &de, f->off, &count)) == 0)
{
f->off += count * 32;
}
eunlock(f->ep);
// 目录结尾
if (ret == -1)
return nread;
f->off += count * 32;
safestrcpy(tmp.d_name, de.filename, strlen(de.filename) + 1);
if (copyout2(addr, (char *)&tmp, sizeof(tmp)) < 0)
return -1;
addr += sizeof(tmp);
nread += (int)(sizeof(tmp));
}
return nread;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment