Page MenuHomeFreeBSD

kern_linkat: modify to accept AT_ flags instead of FOLLOW/NOFOLLOW

Authored by trasz on Apr 15 2021, 1:32 PM.



This makes this API match other kern_xxxat() functions.

Diff Detail

R10 FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

trasz requested review of this revision.Apr 15 2021, 1:32 PM

Not that it's not tested yet; advice on how to exercise this functionality is welcome.

You should write (or find existing) test that uses linkat(AT_SYMLINK_FOLLOW) and linkat(0) on the symlink. In first case the link to the target should be created, in the second case perhaps error is returned (not sure which).

This revision is now accepted and ready to land.Apr 15 2021, 1:57 PM

Okay, it appears to work; I've tested with linkat_test, and also this:

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

main(int argc, char **argv)
int error;

error = linkat(AT_FDCWD, "name1", AT_FDCWD, "name2-bez-linkat", 0);

error = linkat(AT_FDCWD, "name1", AT_FDCWD, "name2-z-linkat", AT_SYMLINK_FOLLOW);

return (0);

Result, in both cases (with, and without the patch), is:

lrwx------  2 trasz  trasz    11 Apr 25 14:08 name2-bez-linkat -> /etc/passwd
-rw-r--r--  2 root   wheel  3801 Mar 30 14:42 name2-z-linkat