mikaku / Fiwix

A UNIX-like kernel for the i386 architecture
https://www.fiwix.org
Other
407 stars 32 forks source link

Support O_DIRECTORY flag to the open syscall #32

Closed rick-masters closed 1 year ago

rick-masters commented 1 year ago

The O_DIRECTORY option signifies that an open call should only succeed if the path is a directory. This is used, for example, by opendir in the musl library:

https://git.musl-libc.org/cgit/musl/tree/src/dirent/opendir.c

Some programs use opendir to determine if a path is a directory and so it is important to support.

The following is a test program which must be named opendir.c and run in the same directory as the source. However, any path to an existing file can be used to test whether O_DIRECTORY is working.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
        int dirfd = open("opendir.c", O_DIRECTORY);
        printf("dirfd is %d\n", dirfd);
}

If O_DIRECTORY is working, then the path will not open and dirfd will be -1.

A PR is forthcoming that implements O_DIRECTORY in Fiwix.

mikaku commented 1 year ago

Thank you.