.\" -*- coding: UTF-8 -*- .\" Copyright Drew Eckhardt .\" Copyright 1995, Nicolai Langfeldt .\" Copyright 2006-2014, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH \fIstat\fP 2 "8 février 2026" "Linux man\-pages 6.18" .SH NOM stat, fstat, lstat, fstatat \- Obtenir l'état d'un fichier (file status) .SH BIBLIOTHÈQUE Bibliothèque C standard (\fIlibc\fP,\ \fI\-lc\fP) .SH SYNOPSIS .nf \fB#include \fP .P \fBint stat(const char *restrict \fP\fIpath\fP\fB,\fP \fB struct stat *restrict \fP\fIstatbuf\fP\fB);\fP \fBint fstat(int \fP\fIfd\fP\fB, struct stat *\fP\fIstatbuf\fP\fB);\fP \fBint lstat(const char *restrict \fP\fIpath\fP\fB,\fP \fB struct stat *restrict \fP\fIstatbuf\fP\fB);\fP .P \fB#include \fP/* Définition des constantes \fBAT_*\fP */ \fB#include \fP .P \fBint fstatat(int \fP\fIdirfd\fP\fB, const char *restrict \fP\fIpath\fP\fB,\fP \fB struct stat *restrict \fP\fIstatbuf\fP\fB, int \fP\fIflags\fP\fB);\fP .fi .P .RS -4 Exigences de macros de test de fonctionnalités pour la glibc (consulter \fBfeature_test_macros\fP(7)) : .RE .P \fBlstat\fP()\ : .nf .\" _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED /* Depuis la glibc 2.20 */ _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500 || /* Depuis la glibc 2.10 : */ _POSIX_C_SOURCE >= 200112L || /* Pour la glibc antérieure et égale à 2.19 */ _BSD_SOURCE .fi .P \fBfstatat\fP()\ : .nf Depuis la glibc 2.10 : _POSIX_C_SOURCE >= 200809L avant la glibc 2.10 : _ATFILE_SOURCE .fi .SH DESCRIPTION These functions return information about a file, in the buffer pointed to by \fIstatbuf\fP. No permissions are required on the file itself, but\[em]in the case of \fBstat\fP(), \fBfstatat\fP(), and \fBlstat\fP()\[em]execute (search) permission is required on all of the directories in \fIpath\fP that lead to the file. .P \fBstat\fP() and \fBfstatat\fP() retrieve information about the file pointed to by \fIpath\fP; the differences for \fBfstatat\fP() are described below. .P \fBlstat\fP() is identical to \fBstat\fP(), except that if \fIpath\fP is a symbolic link, then it returns information about the link itself, not the file that the link refers to. .P .\" \fBfstat\fP() est identique à \fBstat\fP(), sauf que le fichier dont les renseignements sont à récupérer est référencé par le descripteur de fichier \fIfd\fP. .SS "La structure stat" Les trois fonctions renvoient une structure \fIstat\fP (consultez \fBstat\fP(3type)). .P .\" Background: inode attributes are modified with i_mutex held, but .\" read by stat() without taking the mutex. \fINote\fP : pour des raisons de performance et de simplicité, différents champs dans la structure \fIstat\fP peuvent contenir des informations d'état à différents moments durant l'exécution de l'appel système. Par exemple, si \fIst_mode\fP ou \fIst_uid\fP sont modifiés par un autre processus en appelant \fBchmod\fP(2) ou \fBchown\fP(2), \fBstat\fP() peut renvoyer l'ancien \fIst_mode\fP en même temps que le nouveau \fIst_uid\fP ou l'ancien \fIst_uid\fP en même temps que le nouveau \fIst_mode\fP. .SS fstatat() L'appel système \fBfstatat\fP() est une interface plus générale pour accéder à des informations de fichier qui peut encore fournir exactement le comportement de chaque appel à \fBstat\fP(), \fBlstat\fP() et \fBfstat\fP(). .P If \fIpath\fP is relative, then it is interpreted relative to the directory referred to by the file descriptor \fIdirfd\fP (rather than relative to the current working directory of the calling process, as is done by \fBstat\fP() and \fBlstat\fP() for a relative pathname). .P If \fIpath\fP is relative and \fIdirfd\fP is the special value \fBAT_FDCWD\fP, then \fIpath\fP is interpreted relative to the current working directory of the calling process (like \fBstat\fP() and \fBlstat\fP()). .P Si \fIpath\fP est absolu, alors \fIdirfd\fP est ignoré. .P L'argument \fIattributs\fP est soit 0, soit un \fIOU\fP binaire «\ |\ » avec les options suivantes\ : .TP \fBAT_EMPTY_PATH\fP (depuis Linux 2.6.39) .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed If \fIpath\fP is an empty string (or NULL, since Linux 6.11) operate on the file referred to by \fIdirfd\fP (which may have been obtained using the \fBopen\fP(2) \fBO_PATH\fP flag). In this case, \fIdirfd\fP can refer to any type of file, not just a directory, and the behavior of \fBfstatat\fP() is similar to that of \fBfstat\fP(). If \fIdirfd\fP is \fBAT_FDCWD\fP, the call operates on the current working directory. This flag is Linux\-specific; define \fB_GNU_SOURCE\fP to obtain its definition. .TP \fBAT_NO_AUTOMOUNT\fP (depuis Linux 2.6.38) Don't automount the terminal ("basename") component of \fIpath.\fP Since Linux 3.1 this flag is ignored. Since Linux 4.11 this flag is implied. .TP \fBAT_SYMLINK_NOFOLLOW\fP If \fIpath\fP is a symbolic link, do not dereference it: instead return information about the link itself, like \fBlstat\fP(). (By default, \fBfstatat\fP() dereferences symbolic links, like \fBstat\fP().) .P Consultez \fBopenat\fP(2) pour une explication de la nécessité de \fBfstatat\fP(). .SH "VALEUR RENVOYÉE" En cas de succès, zéro est renvoyé. En cas d'erreur, \fB\-1\fP est renvoyé et \fIerrno\fP est définie pour préciser l'erreur. .SH ERREURS .TP \fBEACCES\fP Search permission is denied for one of the directories in the path prefix of \fIpath\fP. (See also \fBpath_resolution\fP(7).) .TP \fBEBADF\fP Le descripteur de fichier \fIfd\fP est non valable. .TP \fBEBADF\fP (\fBfstatat\fP()) \fIpath\fP is relative but \fIdirfd\fP is neither \fBAT_FDCWD\fP nor a valid file descriptor. .TP \fBEFAULT\fP Un pointeur se trouve en dehors de l'espace d'adressage. .TP \fBEINVAL\fP (\fBfstatat\fP()) \fIattributs\fP contient un attribut non valable. .TP \fBELOOP\fP Trop de liens symboliques rencontrés dans le chemin d'accès. .TP \fBENAMETOOLONG\fP \fIpath\fP est trop long. .TP \fBENOENT\fP A component of \fIpath\fP does not exist or is a dangling symbolic link. .TP \fBENOENT\fP \fIpath\fP is an empty string and \fBAT_EMPTY_PATH\fP was not specified in \fIflags\fP. .TP \fBENOMEM\fP Pas assez de mémoire (mémoire noyau). .TP \fBENOTDIR\fP A component of the path prefix of \fIpath\fP is not a directory. .TP \fBENOTDIR\fP (\fBfstatat\fP()) \fIpath\fP is relative and \fIdirfd\fP is a file descriptor referring to a file other than a directory. .TP \fBEOVERFLOW\fP \fIpath\fP or \fIfd\fP refers to a file whose size, inode number, or number of blocks cannot be represented in, respectively, the types \fIoff_t\fP, \fIino_t\fP, or \fIblkcnt_t\fP. This error can occur when, for example, an application compiled on a 32\-bit platform without \fI\-D_FILE_OFFSET_BITS=64\fP calls \fBstat\fP() on a file whose size exceeds \fI(1<<31)\-1\fP bytes. .SH NORMES POSIX.1\-2024. .SH HISTORIQUE .TP \fBstat\fP() .TQ \fBfstat\fP() .TQ \fBlstat\fP() .\" SVr4 documents additional .\" .BR fstat () .\" error conditions EINTR, ENOLINK, and EOVERFLOW. SVr4 .\" documents additional .\" .BR stat () .\" and .\" .BR lstat () .\" error conditions EINTR, EMULTIHOP, ENOLINK, and EOVERFLOW. SVr4, 4.3BSD, POSIX.1\-2001. .TP \fBfstatat\fP() POSIX.1\-2008. Linux 2.6.16, glibc 2.4. .P D'après POSIX.1\-2001, \fBlstat\fP() sur un lien symbolique ne doit renvoyer des informations valables que dans le champ \fIst_size\fP et le type de fichier du champ \fIst_mode\fP de la structure \fIstat\fP. POSIX.1\-2008 renforce la spécification, obligeant \fBlstat\fP() à renvoyer des informations valables dans tous les champs à part les bits de mode dans \fIst_mode\fP. .P L'utilisation des champs \fIst_blocks\fP et \fIst_blksize\fP risque d'être moins portable (ils ont été introduits dans BSD. Leur interprétation change suivant les systèmes, voire sur un même système s'il y a des montages NFS). .SS "Différences entre bibliothèque C et noyau" .\" See include/asm-i386/stat.h in the Linux 2.4 source code for the .\" various versions of the structure definitions Avec le temps, l'augmentation de la taille de la structure \fIstat\fP a conduit à trois versions successives de \fBstat\fP() : \fIsys_stat\fP() (slot \fI__NR_oldstat\fP), \fIsys_newstat\fP() (slot \fI__NR_stat\fP) et \fIsys_stat64\fP() \fI__NR_stat64\fP) sur les plateformes 32 bits telles que i386. Les deux premières versions étaient déjà présentes dans Linux 1.0 (quoiqu'avec des noms différents), la dernière a été ajoutée dans Linux 2.4. La même remarque s'applique à \fBfstat\fP() et \fBlstat\fP(). .P Les versions internes du noyau de la structure \fIstat\fP traitées par les différentes versions étaient respectivement : .TP \fI__old_kernel_stat\fP La structure d'origine avec des champs plutôt étroits et pas de remplissage. .TP \fIstat\fP Un champ plus grand \fIst_ino\fP et le remplissage ont été ajoutés dans différentes parties de la structure pour autoriser un agrandissement futur. .TP \fIstat64\fP Un champ \fIst_ino\fP encore plus grand, des champs \fIst_uid\fP et \fIst_gid\fP plus grands pour s'adapter à l'extension à 32 bits des UID et GID dans Linux 2.4 et d'autres champs agrandis ainsi que plus de remplissage dans la structure. (Divers octets de remplissage étaient finalement consommés dans Linux 2.6 avec l'introduction d'ID de périphérique 32 bits et des composants en nanosecondes dans les champs d'horodatage.) .P .\" .\" A note from Andries Brouwer, July 2007 .\" .\" > Is the story not rather more complicated for some calls like .\" > stat(2)? .\" .\" Yes and no, mostly no. See "/usr/include/sys/stat.h". .\" .\" The idea is here not so much that syscalls change, but that .\" the definitions of struct stat and of the types dev_t and mode_t change. .\" This means that libc (even if it does not call the kernel .\" but only calls some internal function) must know what the .\" format of dev_t or of struct stat is. .\" The communication between the application and libc goes via .\" the include file that defines a _STAT_VER and .\" _MKNOD_VER describing the layout of the data that user space .\" uses. Each (almost each) occurrence of stat() is replaced by .\" an occurrence of xstat() where the first parameter of xstat() .\" is this version number _STAT_VER. .\" .\" Now, also the definitions used by the kernel change. .\" But glibc copes with this in the standard way, and the .\" struct stat as returned by the kernel is repacked into .\" the struct stat as expected by the application. .\" Thus, _STAT_VER and this setup cater for the application-libc .\" interface, rather than the libc-kernel interface. .\" .\" (Note that the details depend on gcc being used as c compiler.) La fonction d'enveloppe \fBstat\fP() de la glibc dissimule ces détails aux applications invoquant la version la plus récente de l'appel système fourni par le noyau, et recompresse l'information renvoyée si nécessaire pour les binaires anciens. .P Dans les systèmes modernes 64 bits, la vie est plus simple : il n'y a qu'un seul appel système \fBstat\fP() et le noyau s'occupe de la structure \fIstat\fP qui contient des champs d'une taille suffisante. .P .\" strace(1) shows the name "newfstatat" on x86-64 L'appel système sous\-jacent employé par la fonction d'enveloppe \fBfstatat()\fP de la glibc s'appelle en fait \fBfstatat64\fP() ou, sur certaines architectures, \fBnewfstatat\fP(). .SH EXEMPLES Le programme suivant appelle \fBlstat\fP() et affiche certains champs sélectionnés dans la structure \fIstat\fP renvoyée. .P .\" SRC BEGIN (stat.c) .EX #include #include #include #include #include #include \& int main(int argc, char *argv[]) { struct stat sb; \& if (argc != 2) { fprintf(stderr, "Usage: %s \[rs]n", argv[0]); exit(EXIT_FAILURE); } \& if (lstat(argv[1], &sb) == \-1) { perror("lstat"); exit(EXIT_FAILURE); } \& printf("ID of containing device: [%x,%x]\[rs]n", major(sb.st_dev), minor(sb.st_dev)); \& printf("File type: "); \& switch (sb.st_mode & S_IFMT) { case S_IFBLK: printf("block device\[rs]n"); break; case S_IFCHR: printf("character device\[rs]n"); break; case S_IFDIR: printf("directory\[rs]n"); break; case S_IFIFO: printf("FIFO/pipe\[rs]n"); break; case S_IFLNK: printf("symlink\[rs]n"); break; case S_IFREG: printf("regular file\[rs]n"); break; case S_IFSOCK: printf("socket\[rs]n"); break; default: printf("unknown?\[rs]n"); break; } \& printf("I\-node number: %ju\[rs]n", (uintmax_t) sb.st_ino); \& printf("Mode: %jo (octal)\[rs]n", (uintmax_t) sb.st_mode); \& printf("Link count: %ju\[rs]n", (uintmax_t) sb.st_nlink); printf("Ownership: UID=%ju GID=%ju\[rs]n", (uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid); \& printf("Preferred I/O block size: %jd bytes\[rs]n", (intmax_t) sb.st_blksize); printf("File size: %jd bytes\[rs]n", (intmax_t) sb.st_size); printf("Blocks allocated: %jd\[rs]n", (intmax_t) sb.st_blocks); \& printf("Last status change: %s", ctime(&sb.st_ctime)); printf("Last file access: %s", ctime(&sb.st_atime)); printf("Last file modification: %s", ctime(&sb.st_mtime)); \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "VOIR AUSSI" \fBls\fP(1), \fBstat\fP(1), \fBaccess\fP(2), \fBchmod\fP(2), \fBchown\fP(2), \fBreadlink\fP(2), \fBstatx\fP(2), \fButime\fP(2), \fBstat\fP(3type), \fBcapabilities\fP(7), \fBinode\fP(7), \fBsymlink\fP(7) .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Jean-Pierre Giraud . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .