Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(2)

chown(2)

creat(2)

link(2)

mknod(2)

pipe(2)

read(2)

time(2)

unlink(2)

utime(2)

write(2)

fattach(3C)

stat(5)

stat(2)  —  SYSTEM CALLS

NAME

stat, lstat, fstat − get file status

SYNOPSIS

#include <sys/types.h>
#include <sys/stat.h>

int stat(const char ∗path, struct stat ∗buf);

int lstat(const char ∗path, struct stat ∗buf);

int fstat(int fildes, struct stat ∗buf);

DESCRIPTION

path points to a path name naming a file.  Read, write, or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.  stat obtains information about the named file.  Note that in a Remote File Sharing environment, the information returned by stat depends on the user/group mapping set up between the local and remote computers. 

lstat obtains file attributes similar to stat, except when the named file is a symbolic link; in that case lstat returns information about the link, while stat returns information about the file the link references. 

fstat obtains information about an open file known by the file descriptor fildes, obtained from a successful open, creat, dup, fcntl, or pipe system call. 

buf is a pointer to a stat structure into which information is placed concerning the file.  The contents of the structure pointed to by buf include the following members:

dev_tst_dev;/∗ ID of device containing ∗/
/∗ a directory entry for this file ∗/
ino_tst_ino;/∗ Inode number ∗/
mode_tst_mode;/∗ File mode [see mknod(2)] ∗/
nlink_tst_nlink;/∗ Number of links ∗/
uid_tst_uid;/∗ User ID of the file’s owner ∗/
gid_tst_gid;/∗ Group ID of the file’s group ∗/
dev_tst_rdev;/∗ ID of device ∗/
/∗ This entry is defined only for ∗/
/∗ char special or block special files ∗/
off_tst_size;/∗ File size in bytes ∗/
time_tst_atime;/∗ Time of last access in seconds ∗/
ulong_tst_ausec;/∗ microsecond extension to st_atime (88k only) ∗/
time_tst_mtime;/∗ Time of last modify in seconds ∗/
ulong_tst_musec;/∗ microsecond extension to st_mtime (88k only) ∗/
time_tst_ctime;/∗ Time of last status change in secs ∗/
ulong_tst_cusec;/∗ microsecond extension to st_ctime (88k only) ∗/
timestruct_t  st_atim;/∗ Time of last access ∗/
timestruct_t  st_mtim;/∗ Time of last data modification ∗/
timestruct_t  st_ctim;/∗ Time of last file status change ∗/
/∗ Times measured in seconds since ∗/
/∗ 00:00:00 UTC, Jan. 1, 1970 ∗/
longst_blksize;/∗ Preferred I/O block size ∗/
longst_blocks;/∗ Number st_blksize blocks allocated ∗/
charst_fstype[_ST_FSTYPSZ]; /∗ File system type name ∗/

st_dev This field uniquely identifies the file system that contains the file.  Its value may be used as input to the ustat system call to determine more information about this file system.  No other meaning is associated with this value. 

st_ino This field uniquely identifies the file in a given file system.  The pair st_ino and st_dev uniquely identifies regular files. 

st_mode The mode of the file as described in mknod(2).  In addition to the modes described in mknod(2), the mode of a file may also be S_IFLNK if the file is a symbolic link.  (Note that S_IFLNK may only be returned by lstat.) 

st_nlink This field should be used only by administrative commands. 

st_uid The user ID of the file’s owner. 

st_gid The group ID of the file’s group. 

st_rdev This field should be used only by administrative commands.  It is valid only for block special files, character special files, or XENIX special named files.  The st_rdev field for block special and character special files only has meaning on the system where the file was configured. 

If the file is a XENIX special named file, it contains the type code [see stat(4) for the XENIX semaphore and shared data type code values S_INSEM and S_INSHD]. 

st_size For regular files, this is the address of the end of the file.  For block special, character special, or XENIX special named files, this is not defined.  For pipes or FIFOs, see pipe(2). 

st_atim Time (in seconds and microseconds) when file data was last accessed.  Changed by the following ­system calls: creat, mknod, pipe, utime, read, creatsem, opensem, sigsem, waitsem, sdget and sdfree. 

st_ctim Time (in seconds and microseconds) when file status was last changed.  Changed by the following system calls: chmod, chown, creat, link, mknod, pipe, unlink, utime, write, creatsem, sdget and sdfree. 

st_mtim Time (in seconds and microseconds) when data was last modified.  Changed by the following system calls: creat, mknod, pipe, utime, and write. 

st_atime, st_mtime, st_ctime
These are supplied for backward compatibility and are the same as st_atim.tv_sec, st_mtim.tv_sec, and st_ctim.tv_sec, respectively.  Note that on 68k machines these are #defines whereas on 88k machines they are part of the stat structure. 

st_ausec, st_musec, st_cusec
These are only in the 88k stat structure and correspond to st_atim.tv_nsec, st_mtim.tv_nsec, and st_ctim.tv_nsec, respectively. 

st_blksize
A hint as to the "best" unit size for I/O operations. This field is not defined for block-special or character-special files.

st_blocks The total number of physical blocks of size 512 bytes actually allocated on disk.  This field is not defined for block-special or character-special files. 

st_fstype File system type name of file system associated with the file. 

stat and lstat fail if one or more of the following are true:

EACCES Search permission is denied for a component of the path prefix. 

EFAULT buf or path points to an invalid address. 

EINTR A signal was caught during the stat or lstat system call. 

ELOOP Too many symbolic links were encountered in translating path. 

EMULTIHOP Components of path require hopping to multiple remote machines and the file system does not allow it. 

ENAMETOOLONG The length of the path argument exceeds {PATH_MAX}, or the length of a path component exceeds {NAME_MAX} while _POSIX_NO_TRUNC is in effect. 

ENOENT The named file does not exist or is the null pathname. 

ENOTDIR A component of the path prefix is not a directory. 

ENOLINK path points to a remote machine and the link to that machine is no longer active. 

EOVERFLOW A component is too large to store in the structure pointed to by buf. 

fstat fails if one or more of the following are true:

EBADF fildes is not a valid open file descriptor. 

EFAULT buf points to an invalid address. 

EINTR A signal was caught during the fstat system call. 

ENOLINK fildes points to a remote machine and the link to that machine is no longer active. 

EOVERFLOW A component is too large to store in the structure pointed to by buf. 

SEE ALSO

chmod(2), chown(2), creat(2), link(2), mknod(2), pipe(2), read(2), time(2), unlink(2), utime(2), write(2), fattach(3C), stat(5). 

DIAGNOSTICS

Upon successful completion, a value of 0 is returned.  Otherwise, a value of −1 is returned and errno is set to indicate the error. 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026