File descriptors obtained using open(directory, O_PATH | O_DIRECTORY) are useful not only for functions ...at() , but also for fchdir() (since kernel version 3.2.23, I think).
There is also a recent patch for the new syscall, fbind() , which will allow the use of very long Unix domain socket names. The socket file is first created with mknod(path, mode | S_IFSOCK, (dev_t)0) , then opened with open(file, O_PATH) . The file descriptor thus obtained and the Unix domain socket descriptor are passed to fbind() to associate the socket with the path name. Whether this will be included in the Linux kernel has not yet been noticed - although, even if it is, it will be years before it can be relied on that it is universally available. (As a workaround for Unix domain socket names that are too long, this would be more likely, rather.)
I would say that O_PATH is useful only for directories; file usage may be found in the future. Besides the possibility of future fbind() or similar future system calls, I donβt know how to use file descriptors for files opened with O_PATH . Even fstatvfs() will not work, at least on the 3.5.0 kernel.
On Linux, inodes (file contents and metadata) are freed only when the last open file descriptor is closed. When you delete (detach) a file, you only delete the file name associated with the inode. Thus, there are two separate filesystem objects associated with the file descriptor: the name used to open the object, and the base inode. The name is used only to resolve the path, i.e. When open() is called (or equivalent). All data and metadata are in the inode.
File descriptors obtained using O_PATH behave (at least on the 3.5.0 kernel), just like regular file descriptors. Moving and renaming components of the name or name used to open the handle. (The descriptor remains valid because it refers to the inode, and the file name object was used only during path resolution. Keeping the descriptor open will maintain allocated resources, even if the descriptor has been opened by O_PATH .)
source share