词条 | Stat (system call) |
释义 |
{{Mono|stat()}} is a Unix system call that returns file attributes about an inode. The semantics of {{Mono|stat()}} vary between operating systems. As an example, Unix command {{Mono|ls}} uses this system call to retrieve information on files that includes:
stat appeared in Version 1 Unix. It is among the few original Unix system calls to change, with Version 4's addition of group permissions and larger file size.[1]stat() functionsThe C POSIX library header {{Mono|sys/stat.h}}, found on POSIX and other Unix-like operating systems, declares the The The family of functions was extended to implement large file support. Functions named The functions are defined as: stat structureThis structure is defined in {{Mono|sys/stat.h}} header file as follows, although implementations are free to define additional fields:{{sfn|Stevens|Rago|2013|p=94}} POSIX.1 does not require In older versions of POSIX.1 standard, the time-related fields were defined as The
The {{Anchor|RELATIME|NOATIME|LAZYTIME}}Criticism of atime{{undue weight section|date=March 2015}}Reading a file changes its {{Mono|atime}} eventually requiring a disk write, which has been criticized as it is inconsistent with a read only file system. File system cache may significantly reduce this activity to one disk write per cache flush. Linux kernel developer Ingo Molnár publicly criticized the concept and performance impact of atime in 2007,[3][4] and in 2009, the {{Mono|relatime}} mount option had become the default, which addresses this criticism.[5] The behavior behind the {{Mono|relatime}} mount option offers sufficient performance for most purposes and should not break any significant applications, as it has been extensively discussed.[6] Initially, {{Mono|relatime}} only updated atime if atime < mtime or atime < ctime; that was subsequently modified to update atimes that were 24 hours old or older, so that {{Mono|tmpwatch}} and Debian's popularity counter (popcon) would behave properly.[7]Current versions of the Linux kernel support four mount options, which can be specified in fstab:
Current versions of Linux, Mac OS X, Solaris, FreeBSD, and NetBSD support a {{Mono|noatime}} mount option in /etc/fstab, which causes the atime field never to be updated. Turning off atime updating breaks POSIX compliance, and some applications, such as mbox-driven "new mail" notifications,[8] and some file usage watching utilities, notably tmpwatch. The {{Mono|noatime}} option on OpenBSD behaves more like Linux {{Mono|relatime}}.[9] Version 4.0 of the Linux kernel mainline, which was released on April 12, 2015, introduced the new mount option {{Mono|lazytime}}. It allows POSIX-style atime updates to be performed in-memory and flushed to disk together with some non-time-related I/O operations on the same file; atime updates are also flushed to disk when some of the sync system calls is executed, or before the file's in-memory inode is evicted from the filesystem cache. Additionally, it is possible to configure for how long atime modifications can remain unflushed. That way, lazytime retains POSIX compatibility while offering performance improvements.[10][11] ctimeIt is tempting to believe that {{Mono|ctime}} originally meant creation time,[12], however while early unix did have modification and creation times, that was changed to be access time and modification time before there was any C structure in which to call anything {{Mono|ctime}}. The filesystems retained just the access time ({{Mono|atime}}) and modification time ({{Mono|mtime}}) through 6th edition unix. The {{Mono|ctime}} timestamp was added in the file system restructuring that occurred with 7th edition unix, and has always referred to inode change time. It is updated any time file metadata stored in the inode changes, such as file permissions, file ownership, and creation and deletion of hard links. In some implementations, {{Mono|ctime}} is affected by renaming a file (both original Unix, which implemented a renaming by making a link (updating {{Mono|ctime}}) and then unlinking the old name (updating {{Mono|ctime}} again) and modern Linux tend to do this). Unlike {{Mono|atime}} and {{Mono|mtime}}, {{Mono|ctime}} cannot be set to an arbitrary value with {{Mono|utime()}}, as used by the {{Mono|touch}} utility, for example. Instead, when {{Mono|utime()}} is used, or any other change to the inode other than an update to {{Mono|atime}} caused by accessing the file, the {{Mono|ctime}} value is set to the current time. Time granularity
ExampleReferences1. ^{{cite techreport |first1=M. D. |last1=McIlroy |authorlink1=Doug McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 |series=CSTR |number=139 |institution=Bell Labs}} {{refbegin}}2. ^{{cite web |url=http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html |work=The Open Group Base Specifications Issue 6—IEEE Std 1003.1, 2004 Edition |title= 3. ^Kernel Trap: Linux: Replacing atime With relatime, by Jeremy, August 7, 2007 4. ^[https://lwn.net/Articles/244829/ Once upon atime], LWN, by Jonathan Corbet, August 8, 2007 5. ^Linux kernel 2.6.30, Linux Kernel Newbies 6. ^[https://lwn.net/Articles/326471/ That massive filesystem thread], LWN, by Jonathan Corbet, March 31, 2009 7. ^Relatime Recap, Valerie Aurora 8. ^http://www.mail-archive.com/mutt-users@mutt.org/msg24912.html "the shell's $MAIL monitor ... depends on atime, pronouncing new email with atime($MAIL) < mtime($MAIL)" 9. ^{{cite web | url = https://man.openbsd.org/mount.2#MNT_NOATIME | title = mount(2) - OpenBSD manual pages | date = April 27, 2018 | accessdate = September 26, 2018 | website = openbsd.org}} 10. ^{{cite web | url = http://kernelnewbies.org/Linux_4.0#head-3e847edbcf4c617048c905b6972979f7bb7547a3 | title = Linux kernel 4.0, Section 1.5. 'lazytime' option for better update of file timestamps | date = May 1, 2015 | accessdate = May 2, 2015 | website = kernelnewbies.org}} 11. ^{{cite web | url = https://lwn.net/Articles/621046/ | title = Introducing lazytime | date = November 19, 2014 | accessdate = May 2, 2015 | author = Jonathan Corbet | publisher = LWN.net}} 12. ^https://www.bell-labs.com/usr/dmr/www/cacm.html 13. ^{{cite web |url=http://man7.org/linux/man-pages/man2/stat.2.html |title=stat(2) - Linux manual page |accessdate=February 27, 2015 |publisher=man7.org }} 14. ^{{citation |url=http://www.sourceware.org/ml/libc-alpha/2002-12/msg00011.html |publisher=mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project. |title=struct stat.h with nanosecond resolution |author=Andreas Jaeger |date=December 2, 2002 }} 15. ^MSDN: File Times
External links
4 : C POSIX library|POSIX|Unix file system-related software|System calls |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。