Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tunlinkat should handle an open directory fid #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Tunlinkat should handle an open directory fid
citrus-it committed Apr 14, 2022
commit a843a1a0b82c01a26d5b7020e6e82cf3fdc59de0
26 changes: 24 additions & 2 deletions backend/fs.c
Original file line number Diff line number Diff line change
@@ -1751,8 +1751,19 @@ fs_remove(void *softc, struct l9p_fid *fid)
return (error);

if (unlinkat(file->ff_dirfd, file->ff_name,
S_ISDIR(cst.st_mode) ? AT_REMOVEDIR : 0) != 0)
S_ISDIR(cst.st_mode) ? AT_REMOVEDIR : 0) != 0) {
error = errno;
/*
* POSIX allows unlinkat() with AT_REMOVEDIR on a non-empty
* directory to return either ENOTEMPTY or EEXIST. illumos
* and Solaris return EEXIST, apparently because System V did
* not have ENOTEMPTY.
* Since Tunlinkat is part of 9P2000.L, which uses Linux
* errnos, translate that here.
*/
if (error == EEXIST && S_ISDIR(cst.st_mode))
error = ENOTEMPTY;
}

return (error);
}
@@ -2931,8 +2942,19 @@ fs_unlinkat(void *softc, struct l9p_request *req)
return (error);

if (req->lr_req.tunlinkat.flags & L9PL_AT_REMOVEDIR) {
if (unlinkat(dirff->ff_dirfd, newname, AT_REMOVEDIR) != 0)
if (unlinkat(dirff->ff_dirfd, newname, AT_REMOVEDIR) != 0) {
error = errno;
/*
* POSIX allows unlinkat() with AT_REMOVEDIR on a
* non-empty directory to return either ENOTEMPTY or
* EEXIST. illumos and Solaris return EEXIST, apparently
* because System V did not have ENOTEMPTY. Since
* Tunlinkat is part of 9P2000.L, which uses Linux
* errnos, translate that here.
*/
if (error == EEXIST)
error = ENOTEMPTY;
}
} else {
if (unlinkat(dirff->ff_dirfd, newname, 0) != 0)
error = errno;
6 changes: 3 additions & 3 deletions request.c
Original file line number Diff line number Diff line change
@@ -1404,12 +1404,12 @@ l9p_dispatch_trenameat(struct l9p_request *req)
int error;

error = fid_lookup(conn, req->lr_req.hdr.fid, ENOENT,
F_REQUIRE_DIR | F_FORBID_OPEN, &req->lr_fid);
F_REQUIRE_DIR, &req->lr_fid);
if (error)
return (error);

error = fid_lookup(conn, req->lr_req.trenameat.newdirfid, ENOENT,
F_REQUIRE_DIR | F_FORBID_OPEN, &req->lr_fid2);
F_REQUIRE_DIR, &req->lr_fid2);
if (error)
return (error);

@@ -1428,7 +1428,7 @@ l9p_dispatch_tunlinkat(struct l9p_request *req)
int error;

error = fid_lookup(conn, req->lr_req.hdr.fid, ENOENT,
F_REQUIRE_DIR | F_FORBID_OPEN, &req->lr_fid);
F_REQUIRE_DIR, &req->lr_fid);
if (error)
return (error);