5.6 Working through a Handle

These calls act on the file an open descriptor refers to, rather than on a name. Each is authorized by the access the descriptor was granted when it opened, so they work on the file you opened even if someone has since renamed it, and they cannot hit a different file that has taken the old name. They need a descriptor from peios_file_open; any other descriptor fails with EOPNOTSUPP.

5.6.1 Reading back the grant #

int peios_file_query_open(int fd, struct kacs_open_info *out);

Fills out from the open:

FieldMeaning
granted_accessThe access mask the descriptor carries. After a MAXIMUM_ALLOWED open, this is what you received.
share_accessThe KACS_FILE_SHARE_* sharing the open allows others.
flagsKACS_OPEN_INFO_MANAGED; _DELETE_PENDING if the file is marked for deletion; _DELETE_ON_CLOSE if this open will mark it when it closes; _ANCESTORS_PINNED if the open pins its parent directories.

The call needs no right: it reports only what the descriptor already carries.

5.6.2 Deleting through the handle #

int peios_file_set_disposition(int fd, uint32_t flags);

Sets the file's delete disposition — what happens to it once nothing has it open. The open needs DELETE, or the call fails with EACCES. The flags are those of NT's FILE_DISPOSITION_INFORMATION_EX:

FlagMeaning
KACS_DISPOSITION_DELETEMark the file delete-pending: it is removed when its last open closes, from whichever process. Without this flag, the call clears the mark.
KACS_DISPOSITION_POSIX_SEMANTICSWith DELETE: remove the name now, as unlink(2) does. Open descriptors carry on with the file.
KACS_DISPOSITION_ON_CLOSESet or clear this open's own delete-on-close instead: the file becomes delete-pending when this open closes.
KACS_DISPOSITION_IGNORE_READONLYDelete a read-only file. Needs FILE_WRITE_ATTRIBUTES too.

While a file is delete-pending its name stays and still lists, but every new open of it fails with EBUSY and the status KACS_STATUS_DELETE_PENDING. The removal is authorized by whoever set the mark, not by whoever closes the file last.

A read-only file fails with EPERM unless KACS_DISPOSITION_IGNORE_READONLY is given. A directory has to be empty when it is removed.

/* Delete the file once everyone has finished with it. */
if (peios_file_set_disposition(fd, KACS_DISPOSITION_DELETE) != 0) { /* errno */ }
close(fd);

5.6.3 Renaming through the handle #

int peios_file_rename(int fd, int newdirfd, const char *newpath, uint32_t flags);

Moves the link fd names to newpath, resolved relative to newdirfd as by renameat2(). The open needs DELETE; the destination directory is checked as for any rename. The flags are those of NT's FILE_RENAME_INFORMATION_EX:

FlagMeaning
KACS_RENAME_REPLACE_IF_EXISTSReplace an existing file at newpath. Without it, an existing name fails with EEXIST.
KACS_RENAME_POSIX_SEMANTICSReplace a file that is open, if all its opens share delete.
KACS_RENAME_IGNORE_READONLYReplace a read-only file.

A directory is never replaced. A file that is open, delete-pending, or read-only without the flag fails with EBUSY or EPERM. If the handle's link has been removed, the call fails with ENOENT. Both names have to be on the same mount, or the call fails with EXDEV.

5.6.4 See also #

  • Sharing and Deletion — the kernel's rules for delete-pending files and renaming through a handle.

Edit this page