.\" -*- coding: UTF-8 -*- .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992 .\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95 .\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified by Michael Haardt .\" Modified 1993-07-24 by Rik Faith .\" Modified 1995-05-18 by Todd Larason .\" Modified 1997-01-31 by Eric S. Raymond .\" Modified 1995-01-09 by Richard Kettlewell .\" Modified 1998-05-13 by Michael Haardt .\" Modified 1999-07-06 by aeb & Albert Cahalan .\" Modified 2000-01-07 by aeb .\" Modified 2004-06-23 by Michael Kerrisk .\" 2007-06-08 mtk: Added example program .\" 2007-07-05 mtk: Added details on underlying system call interfaces .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH STAT 2 "13 sierpnia 2020 r." Linux "Podręcznik programisty Linuksa" .SH NAZWA stat, fstat, lstat, fstatat \- pobieranie stanu pliku .SH SKŁADNIA .nf \fB#include \fP \fB#include \fP \fB#include \fP .PP \fBint stat(const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIstatbuf\fP\fB);\fP \fBint fstat(int \fP\fIfd\fP\fB, struct stat *\fP\fIstatbuf\fP\fB);\fP \fBint lstat(const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIstatbuf\fP\fB);\fP \fB#include \fP/* Definicja stałych AT_* */ \fB#include \fP .PP \fBint fstatat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIstatbuf\fP\fB,\fP \fB int \fP\fIflags\fP\fB);\fP .fi .PP .RS -4 Wymagane ustawienia makr biblioteki glibc (patrz \fBfeature_test_macros\fP(7)): .RE .PP .ad l \fBlstat\fP(): .RS 4 .\" _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED /* glibc 2.19 i wcześniejsze */ _BSD_SOURCE || /* Od glibc 2.20 */ _DEFAULT_SOURCE || _XOPEN_SOURCE\ >=\ 500 || /* Od glibc 2.10: */ _POSIX_C_SOURCE\ >=\ 200112L .RE .PP \fBfstatat\fP(): .ad l .RS 4 .PD 0 .TP 4 Od glibc 2.10: _POSIX_C_SOURCE\ >=\ 200809L .TP Przed glibc 2.10: _ATFILE_SOURCE .RE .PD .ad .SH OPIS Funkcje te zwracają informacje o podanym pliku w buforze wskazanym przez \fIstatbuf\fP. Do uzyskania tej informacji nie są wymagane prawa dostępu do samego pliku, lecz \(em w przypadku \fBstat\fP, \fBfstatat\fP() i \fBlstat\fP() \(em konieczne są prawa wykonywania (przeszukiwania) do wszystkich katalogów na prowadzącej do pliku ścieżce \fIpathname\fP. .PP \fBstat\fP() i \fBfstatat\fP() pobierają informacje o pliku wskazanym przez \fIpathname\fP; cechy wyróżniające \fBfstatat\fP() opisano poniżej. .PP \fBlstat\fP() is identical to \fBstat\fP(), except that if \fIpathname\fP is a symbolic link, then it returns information about the link itself, not the file that the link refers to. .PP .\" \fBfstat\fP() jest identyczny z \fBstat\fP(), z tym wyjątkiem, że plik o którym mają być pobrane informacje, jest określony przez deskryptor pliku \fIfd\fP. .SS "The stat structure" Wszystkie te funkcje zwracają strukturę \fIstat\fP, zawierającą następujące pola: .PP .in +4n .EX struct stat { dev_t st_dev; /* ID urządzenia zawierającego plik */ ino_t st_ino; /* numer i\-węzła (inode) */ mode_t st_mode; /* tryb i typ pliku */ nlink_t st_nlink; /* liczba dowiązań stałych (hardlinks) */ uid_t st_uid; /* ID użytkownika właściciela */ gid_t st_gid; /* ID grupy właściciela */ dev_t st_rdev; /* ID urządzenia (jeśli plik specjalny) */ off_t st_size; /* całkowity rozmiar w bajtach */ blksize_t st_blksize; /* wielkość bloku dla I/O systemu plików */ blkcnt_t st_blocks; /* liczba zaalokowanych bloków 512\-bajtowych */ /* Od Linuksa 2.6 jądro obsługuje nanosekundową rozdzielczość następujących pól znaczników czasu. Szczegóły opisujące Linuksa w wersji starszej niż 2.6 znajdują się w rozdziale UWAGI */ struct timespec st_atim; /* czas ostatniego dostępu */ struct timespec st_mtim; /* czas ostatniej modyfikacji */ struct timespec st_ctim; /* czas ostatniej zmiany */ }; #define st_atime st_atim.tv_sec /* Kompatybilność wsteczna */ #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec }; .EE .in .PP \fIUwaga\fP: kolejność pól w strukturze \fIstat\fP różni się nieco w zależności od architektury. Dodatkowo, powyższa definicja nie pokazuje bajtów wyrównujących, które mogą być obecne pomiędzy niektórymi polami na różnych architekturach. Z tymi detalami można się zapoznać analizując glibc i kod źródłowy jądra. .PP .\" Background: inode attributes are modified with i_mutex held, but .\" read by stat() without taking the mutex. \fIUwaga\fP: Dla zachowania wydajności i prostoty, różne pola w strukturze \fIstat\fP mogą zawierać stany z różnych momentów wykonywania wywołania systemowego. Przykładowo, jeśli \fIst_mode\fP lub \fIst_uid\fP zostanie zmieniony przez inny proces za pomocą\ wywołania \fBchmod\fP(2) lub \fBchown\fP(2), \fBstat\fP() może zwrócić stary \fIst_mode\fP razem z nowym \fIst_uid\fP albo stary \fIst_uid\fP razem z nowym \fIst_mode\fP. .PP The fields in the \fIstat\fP structure are as follows: .TP \fIst_dev\fP This field describes the device on which this file resides. (The \fBmajor\fP(3) and \fBminor\fP(3) macros may be useful to decompose the device ID in this field.) .TP \fIst_ino\fP This field contains the file's inode number. .TP \fIst_mode\fP This field contains the file type and mode. See \fBinode\fP(7) for further information. .TP \fIst_nlink\fP This field contains the number of hard links to the file. .TP \fIst_uid\fP This field contains the user ID of the owner of the file. .TP \fIst_gid\fP This field contains the ID of the group owner of the file. .TP \fIst_rdev\fP This field describes the device that this file (inode) represents. .TP \fIst_size\fP This field gives the size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte. .TP \fIst_blksize\fP This field gives the "preferred" block size for efficient filesystem I/O. .TP \fIst_blocks\fP This field indicates the number of blocks allocated to the file, in 512\-byte units. (This may be smaller than \fIst_size\fP/512 when the file has holes.) .TP \fIst_atime\fP This is the time of the last access of file data. .TP \fIst_mtime\fP This is the time of last modification of file data. .TP \fIst_ctime\fP This is the file's last status change timestamp (time of last change to the inode). .PP .\" For further information on the above fields, see \fBinode\fP(7). .SS fstatat() The \fBfstatat\fP() system call is a more general interface for accessing file information which can still provide exactly the behavior of each of \fBstat\fP(), \fBlstat\fP(), and \fBfstat\fP(). .PP Jeśli ścieżka podana w \fIpathname\fP jest względna, jest to interpretowane w odniesieniu do katalogu do którego odnosi się deskryptor pliku \fIdirfd\fP (zamiast w odniesieniu do bieżącego katalogu roboczego procesu wywołującego, jak w stosunku do ścieżek względnych robi to \fBstat\fP() i \fBlstat\fP()). .PP Jeśli \fIpathname\fP jest względna a \fIdirfd\fP ma wartość specjalną \fBAT_FDCWD\fP, to \fIpathname\fP jest interpretowana w odniesieniu do bieżącego katalogu roboczego procesu wywołującego (jak \fBstat\fP() i \fBlstat\fP()). .PP If ścieżka \fIpathname\fP jest bezwzględna, to \fIdirfd\fP jest ignorowane. .PP \fIflags\fP mogą wynosić albo 0, albo składać się z co najmniej jednej z poniższych opcji połączonych operatorem OR: .TP \fBAT_EMPTY_PATH\fP (od Linuksa 2.6.39) .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed If \fIpathname\fP is an empty string, 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 (od Linuksa 2.6.38) .\" commit 42f46148217865a545e129612075f3d828a2c4e4 Don't automount the terminal ("basename") component of \fIpathname\fP if it is a directory that is an automount point. This allows the caller to gather attributes of an automount point (rather than the location it would mount). Since Linux 4.14, also don't instantiate a nonexistent name in an on\-demand directory such as used for automounter indirect maps. This flag has no effect if the mount point has already been mounted over. .IP Both \fBstat\fP() and \fBlstat\fP() act as though \fBAT_NO_AUTOMOUNT\fP was set. .IP The \fBAT_NO_AUTOMOUNT\fP can be used in tools that scan directories to prevent mass\-automounting of a directory of automount points. .IP .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed Jest to opcja charakterystyczna dla Linuksa, proszę zdefiniować \fB_GNU_SOURCE\fP, aby dostać się do jej definicji. .TP \fBAT_SYMLINK_NOFOLLOW\fP Jeśli \fIpathname\fP jest dowiązaniem symbolicznym nie podąża za nim, w zamian zwraca informacje o samym dowiązaniu, jak \fBlstat\fP(). Domyślnie \fBfstatat\fP () podąża za dowiązaniami symbolicznymi, jak \fBstat\fP().) .PP Więcej informacji o potrzebie wprowadzenia \fBfstatat\fP() można znaleźć w podręczniku \fBopenat\fP(2). .SH "WARTOŚĆ ZWRACANA" Po pomyślnym zakończeniu zwracane jest zero. Po błędzie zwracane jest \-1 i odpowiednio ustawiane jest \fIerrno\fP. .SH BŁĘDY .TP \fBEACCES\fP Brak uprawnień do przeszukiwania jednego z katalogów w ścieżce zaczynającej \fIpathname\fP. (Patrz także \fBpath_resolution\fP(7)). .TP \fBEBADF\fP \fIfd\fP nie jest prawidłowym otwartym deskryptorem pliku. .TP \fBEFAULT\fP Niepoprawny adres. .TP \fBELOOP\fP Podczas rozwiązywania ścieżki napotkano zbyt wiele dowiązań symbolicznych. .TP \fBENAMETOOLONG\fP Ścieżka \fIpathname\fP jest zbyt długa. .TP \fBENOENT\fP A component of \fIpathname\fP does not exist or is a dangling symbolic link. .TP \fBENOENT\fP \fIpathname\fP is an empty string and \fBAT_EMPTY_PATH\fP was not specified in \fIflags\fP. .TP \fBENOMEM\fP Brak pamięci (tj. pamięci jądra). .TP \fBENOTDIR\fP Składnik ścieżki \fIpathname\fP nie jest katalogiem. .TP \fBEOVERFLOW\fP \fIpathname\fP lub \fIfd\fP odnosi się do pliku, numeru i\-węzła lub numeru bloków, których rozmiar nie jest reprezentowalny w \- odpowiednio \- typie \fIoff_t\fP, \fIino_t\fP, \fIblkcnt_t\fP. Błąd ten może wystąpić na przykład wtedy, gdy aplikacja skompilowana na platformie 32\-bitowej bez \fI\-D_FILE_OFFSET_BITS=64\fP wywoła \fBstat\fP () na pliku, którego rozmiar jest większy niż \fI(1<<31)\-1\fP bajtów. .PP Mogą wystąpić następujące dodatkowe błędy dla \fBfstatat\fP(): .TP \fBEBADF\fP \fIdirfd\fP nie jest prawidłowym deskryptorem pliku. .TP \fBEINVAL\fP Podano nieprawidłową opcję w \fIflags\fP. .TP \fBENOTDIR\fP \fIpathname\fP jest względna a \fIdirfd\fP jest deskryptorem pliku odnoszącym się do pliku zamiast do katalogu. .SH WERSJE \fBfstatat\fP() zostało dodane do Linuksa w jądrze 2.6.16; obsługę biblioteki dodano do glibc w wersji 2.4. .SH "ZGODNE Z" .\" 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. \fBstat\fP(), \fBfstat\fP(), \fBlstat\fP(): SVr4, 4.3BSD, POSIX.1\-2001, POSIX.1.2008. .PP \fBfstatat\fP(): POSIX.1\-2008. .PP Według POSIX.1\-2001 \fBlstat\fP() na dowiązaniu symbolicznym powinien zwrócić poprawne wartości tylko w polu \fIst_size\fP i w części pola \fIst_mode\fP związanej z typem pliku struktury \fIstat\fP. POSIX.1\-2008 zaostrza tę specyfikację, wymagając od \fBlstat\fP() zwracania poprawnych informacji we wszystkich polach z wyjątkiem bitów trybu w \fIst_mode\fP. .PP Używanie pól \fIst_blocks\fP i \fIst_blksize\fP może być nieprzenośne. (Były wprowadzone w BSD; interpretacje różnią się zarówno między systemami, jak i na jednym systemie, jeśli użyty jest zdalny system plików montowany po NFS\-ie). .SH UWAGI .SS "Pola znaczników czasu" Starsze jądra i starsze standardy nie obsługują nanosekundowych pól znaczników czasu. Zamiast tego były trzy pola znaczników czasu \(em \fIst_atime\fP, \fIst_mtime\fP i \fIst_ctime\fP\(em zapisywane jako \fItime_t\fP przechowujące znaczniki czasu z sekundową precyzją. .PP .\" Since kernel 2.5.48, the \fIstat\fP structure supports nanosecond resolution for the three file timestamp fields. The nanosecond components of each timestamp are available via names of the form \fIst_atim.tv_nsec\fP, if suitable feature test macros are defined. Nanosecond timestamps were standardized in POSIX.1\-2008, and, starting with version 2.12, glibc exposes the nanosecond component names if \fB_POSIX_C_SOURCE\fP is defined with the value 200809L or greater, or \fB_XOPEN_SOURCE\fP is defined with the value 700 or greater. Up to and including glibc 2.19, the definitions of the nanoseconds components are also defined if \fB_BSD_SOURCE\fP or \fB_SVID_SOURCE\fP is defined. If none of the aforementioned macros are defined, then the nanosecond values are exposed with names of the form \fIst_atimensec\fP. .SS "Różnice biblioteki C/jądra" .\" See include/asm-i386/stat.h in the Linux 2.4 source code for the .\" various versions of the structure definitions Z upływem czasu, zwiększanie rozmiarów struktury \fIstat\fP doprowadziło do powstania trzech kolejnych wersji funkcji \fBstat\fP(): \fIsys_stat\fP() (slot \fI__NR_oldstat\fP), \fIsys_newstat\fP() (slot \fI__NR_stat\fP) i \fIsys_stat64()\fP (slot \fI__NR_stat64\fP) na platformach 32\-bitowych takich jak i386. Pierwsze dwie wersje były już\ obecne w Linuksie 1.0 (choć z różnymi nazwami), ostatnią\ dodano w Linuksie 2.4. Podobne uwagi mają zastosowanie do \fBfstat\fP() i \fBlstat\fP(). .PP Wewnątrzjądrowe wersje struktury \fIstat\fP, za pomocą\ których jądro obsługuje te różne wersje, to odpowiednio: .TP \fI__old_kernel_stat\fP Oryginalna struktura z dość wąskimi polami i brakiem dopełnienia (wyrównania). .TP \fIstat\fP Większe pole \fIst_ino\fP i dodane dopełnienie do różnych części struktury pozwalające na późniejszą\ rozbudowę. .TP \fIstat64\fP Jeszcze większe pole \fIst_ino\fP, większe pola \fIst_uid\fP i \fIst_gid\fP aby przyjąć rozszerzone w Linuksie 2.4 UID\-y i GID\-y do 32 bitów i różne inne poszerzenia pól oraz jeszcze więcej dopełnień w strukturze (dopełnione bajty zostały w końcu wykorzystane w Linuksie 2.6 po pojawieniu się 32\-bitowych identyfikatorów urządzeń oraz części nanosekundowej w polach znaczników czasowych). .PP .\" .\" 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.) Funkcja opakowująca glibc \fBstat\fP() ukrywa te detale przed użytkownikami, wywołując najnowszą wersję wywołania systemowego udostępnianą\ przez jądra i przepakowując zwracane informacje, jeśli jest to wymagane, dla starszych plików wykonywalnych. .PP Na współczesnych systemach 64\-bitowych wszystko jest prostsze: istnieje jedno wywołanie systemowe \fBstat\fP(), a jądro wykorzystuje strukturę \fIstat\fP zawierającą pola o wystarczającym rozmiarze. .PP .\" strace(1) shows the name "newfstatat" on x86-64 Wywołanie systemowe niższego stopnia używane przez funkcję opakowującą \fBfstatat\fP() glibc nazywa się w rzeczywistości \fBfstatat64\fP() lub, na niektórych architekturach, \fBnewfstatat\fP(). .SH PRZYKŁADY Poniższy program wywołuje \fBlstat\fP() i wypisuje wybrane pola zwrócone w strukturze \fIstat\fP: .PP .EX #include #include #include #include #include #include #include int main(int argc, char *argv[]) { struct stat sb; if (argc != 2) { fprintf(stderr, "Użycie: %s <ścieżka>\en", argv[0]); exit(EXIT_FAILURE); } if (lstat(argv[1], &sb) == \-1) { perror("lstat"); exit(EXIT_FAILURE); } printf("ID of containing device: [%jx,%jx]\en", (uintmax_t) major(sb.st_dev), (uintmax_t) minor(sb.st_dev)); printf("Typ pliku: "); switch (sb.st_mode & S_IFMT) { case S_IFBLK: printf("urządzenie blokowe\en"); break; case S_IFCHR: printf("urządzenie znakowe\en"); break; case S_IFDIR: printf("katalog\en"); break; case S_IFIFO: printf("FIFO/pipe\en"); break; case S_IFLNK: printf("dowiązanie symboliczne\en"); break; case S_IFREG: printf("zwykły plik\en"); break; case S_IFSOCK: printf("gniazdo\en"); break; default: printf("typ nieznany\en"); break; } printf("numer I\-węzła: %ju\en", (uintmax_t) sb.st_ino); printf("Tryb: %jo (octal)\en", (uintmax_t) sb.st_mode); printf("Liczba dowi◈za◈: %ju\en", (uintmax_t) sb.st_nlink); printf("W◈a◈ciciel: UID=%ju GID=%ju\en", (uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid); printf("Preferowany rozmiar bloku I/O: %jd bajtów\en", (intmax_t) sb.st_blksize); printf("Rozmiar bloku: %jd bajtów\en", (intmax_t) sb.st_size); printf("Liczba zaalokowanych bloków: %jd\en", (intmax_t) sb.st_blocks); printf("Ostatnia zmiana stanu: %s", ctime(&sb.st_ctime)); printf("Ostatni dostęp do pliku: %s", ctime(&sb.st_atime)); printf("Ostatnia zmiana pliku: %s", ctime(&sb.st_mtime)); exit(EXIT_SUCCESS); } .EE .SH "ZOBACZ TAKŻE" \fBls\fP(1), \fBstat\fP(1), \fBaccess\fP(2), \fBchmod\fP(2), \fBchown\fP(2), \fBreadlink\fP(2), \fBstatx\fP(2), \fButime\fP(2), \fBcapabilities\fP(7), \fBinode\fP(7), \fBsymlink\fP(7) .SH "O STRONIE" Angielska wersja tej strony pochodzi z wydania 5.10 projektu Linux \fIman\-pages\fP. Opis projektu, informacje dotyczące zgłaszania błędów oraz najnowszą wersję oryginału można znaleźć pod adresem \%https://www.kernel.org/doc/man\-pages/. .PP .SH TŁUMACZENIE Autorami polskiego tłumaczenia niniejszej strony podręcznika są: Przemek Borys , Robert Luberda i Michał Kułach . .PP Niniejsze tłumaczenie jest wolną dokumentacją. Bliższe informacje o warunkach licencji można uzyskać zapoznając się z .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License w wersji 3 .UE lub nowszej. Nie przyjmuje się ŻADNEJ ODPOWIEDZIALNOŚCI. .PP Błędy w tłumaczeniu strony podręcznika prosimy zgłaszać na adres listy dyskusyjnej .MT manpages-pl-list@lists.sourceforge.net .ME .