| This article brought to you by LWN subscribers Subscribers to LWN.net made this article — and everything that surrounds it — possible. If you appreciate our content, please buy a subscription and make the next set of articles possible. |
POSIX has long defined variants on the stat() system call, which returns information about files in the filesystem. There are a couple of limitations associated with stat() which have been seen as a problem for a while: it can only return the information defined in the standard, and it returns all of that information, regardless of whether the caller needs it. David Howells has attempted to address both problems with a new set of system calls:
ssize_t xstat(int dfd, const char *filename, unsigned atflag,
struct xstat *buffer, size_t buflen);
ssize_t fxstat(int fd, struct xstat *buffer, size_t buflen);
The struct xstat structure resembles struct stat, but with some differences. It includes fields for file metadata like the creation time, the inode "generation number," and the "data version number" for filesystems which support this information, and it has a version number to provide for changes in the system call API in the future.
What also has been added, though, is a query_flags field where the caller specifies which fields are actually desired; if all that is needed is the file size or the link count, for example, the caller can say so. The kernel may return other information as well, but it does not have to go out of its way to ensure that it's accurate. There can be a real performance benefit to this behavior, especially for network-mounted filesystems where getting an updated value may require a conversation with the server. There is also a provision for adding "extra results" for types of metadata which are not currently envisioned.
The addition of this sort of stat() variant has been discussed for years, so something is likely to be merged. Chances are good, though, that the API will change somewhat before the patch is finalized. There were objections to the use of a version number in the xstat structure; the overhead of supporting another system call, should one become necessary, will be less than that of dealing with multiple versions. There were also complaints about the use of that structure as both an input and an output parameter, so the input portion (the query flags) may just become a direct system call parameter instead.
Update: there is already a new version
of the patch available with some changes to the system call API.
| Index entries for this article | |
|---|---|
| Kernel | Filesystems/stat() |
| Kernel | System calls |
xstat() and fxstat()
Posted Jul 1, 2010 21:07 UTC (Thu) by vonbrand (guest, #4458) [Link]
This worries me, the updated version returns different data depending on the underlying filesytem. This will surely lead to breakage when someone gets that one wrong. The result should include the filesystem where the file lives somehow.
xstat() and fxstat()
Posted Jul 2, 2010 9:40 UTC (Fri) by etienne (guest, #25256) [Link]
xstat() and fxstat()
Posted Jul 4, 2010 18:03 UTC (Sun) by nybble41 (subscriber, #55106) [Link]
http://www.kernel.org/pub/linux/utils/fs/fat/fatattr/
Works like the 'attrib' utility in DOS/Windows, via ioctls.
xstat() and fxstat()
Posted Jul 6, 2010 10:46 UTC (Tue) by markh (subscriber, #33984) [Link]
Existing filesystems support timestamps prior to the epoch (i.e. negative tv_sec), so shouldn't at least tv_sec be signed?
As for tv_nsec, I assume that its size was increased solely for alignment purposes since its value must be in the range [0,999 999 999]. Would it not be better to save the extra 32 bits in a separate field for possible future use (e.g. for indicating timestamp granularity)?
Copyright © 2010, Eklektix, Inc.
This article may be redistributed under the terms of the
Creative
Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds