]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Register `getdents` to syscall_shim
authorSergiu Moga <sergiu.moga@protonmail.com>
Thu, 22 Apr 2021 16:49:28 +0000 (19:49 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 28 May 2021 09:32:13 +0000 (09:32 +0000)
Register `getdents` system call to syscall_shim library.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Laurentiu Barbulescu <lrbarbulescu@gmail.com>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #189

lib/vfscore/Makefile.uk
lib/vfscore/exportsyms.uk
lib/vfscore/main.c

index ec8965f564f5dd1f24b098f904de27419fe32ce0..8ee48301d32b2177a777958ca66cac48172bec8a 100644 (file)
@@ -72,3 +72,4 @@ UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += pipe2-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += symlink-2
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += unlink-1
 UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += chroot-1
+UK_PROVIDED_SYSCALLS-$(CONFIG_LIBVFSCORE) += getdents-3
index 758e501352f1f439891ec8264af90a439297c90d..596b62b85bb337ddf86cfb9a89cf983f9c10f001 100644 (file)
@@ -218,3 +218,6 @@ uk_syscall_r_utimes
 lutimes
 posix_fadvise
 scandir
+getdents
+uk_syscall_e_getdents
+uk_syscall_r_getdents
index 9386b8025459c57326e831ed787baf410a4b3478..3c82d2f30f63d19864a675297dc6e1662b1fcba5 100644 (file)
@@ -959,6 +959,45 @@ int scandir(const char *path, struct dirent ***res,
        return cnt;
 }
 
+UK_TRACEPOINT(trace_vfs_getdents, "%d %p %hu", int, struct dirent*, size_t);
+UK_TRACEPOINT(trace_vfs_getdents_ret, "");
+UK_TRACEPOINT(trace_vfs_getdents_err, "%d", int);
+
+UK_SYSCALL_R_DEFINE(int, getdents, int, fd, struct dirent*, dirp,
+                                       size_t, count) {
+       trace_vfs_getdents(fd, dirp, count);
+       if (dirp == NULL || count == 0)
+               return 0;
+
+       DIR dir = {
+               .fd = fd
+       };
+
+       size_t i = 0;
+       struct dirent entry, *result;
+       int error;
+
+       do {
+               error = readdir_r(&dir, &entry, &result);
+               if (error) {
+                       trace_vfs_getdents_err(error);
+                       return -error;
+
+               } else
+                       trace_vfs_getdents_ret();
+
+               if (result != NULL) {
+                       memcpy(dirp + i, result, sizeof(struct dirent));
+                       i++;
+
+               } else
+                       break;
+
+       } while (i < count);
+
+       return (i * sizeof(struct dirent));
+}
+
 struct dirent *readdir(DIR *dir)
 {
        static __thread struct dirent entry, *result;