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)

readlink(2)

statfs(2)

time(2)

unlink(2)

ustat(2)

utime(2)

write(2)

stat(5)




stat(2) stat(2)
NAME stat, fstat, lstat - get file status SYNOPSIS #include <sys/types.h> #include <sys/stat.h> int stat(path, buf) char *path; struct stat *buf; int fstat(fildes, buf) int fildes; struct stat *buf; int lstat(path, buf) char *path; struct stat *buf; DESCRIPTION stat obtains information about the named file. path points to a pathname naming a file. Read, write, or execute permission of the named file is not required, but all directories listed in the pathname leading to the file must be searchable. lstat is like stat except in the case where the named file is a symbolic link, in which case lstat returns information about the link, while stat returns information about the file the link references. Similarly, 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 referenced by buf include the following members: ushort st_mode; File mode; see stat(5) ino_t st_ino; Inode number dev_t st_dev; ID of device containing a directory entry for this file dev_t st_rdev; ID of device. This entry is defined only for January 1992 1



stat(2) stat(2)
character-special or block-special files short st_nlink; Number of links ushort st_uid; User ID of the file's owner ushort st_gid; Group ID of the file's group off_t st_size; File size in bytes time_t st_atime; Time when file data were last accessed (times measured in seconds since 00:00:00 GMT, Jan. 1, 1970). Changed by the following system calls: creat(2), mknod(2), pipe(2), utime(2), and read(2). time_t st_mtime; Time when data were last modified (times measured in seconds since 00:00:00 GMT, Jan. 1, 1970). Changed by the following system calls: creat(2), mknod(2), pipe(2), utime(2), and write(2). time_t st_ctime; Time when file status last changed (times measured in seconds since 00:00:00 GMT, Jan. 1, 1970). Changed by the following system calls: chmod(2), chown(2), creat(2), link(2), mknod(2), pipe(2), unlink(2), utime(2), and write(2). long st_blksize; Optimal blocksize for I/O ops long st_blocks; Actual number of blocks allocated STATUS MESSAGES AND VALUES Upon successful completion a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. The stat and lstat programs will fail if one or more of the following is true: ENOTDIR A component of the path prefix is not a directory. EPERM A pathname contains a character with the high-order bit 2 January 1992



stat(2) stat(2)
set. ENAMETOOLONG A component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX. ELOOP Too many symbolic links were encountered in translating a pathname. ENOENT The named file does not exist. EACCES Search permission is denied for a component of the path prefix. EFAULT buf or path points to an invalid address. fstat will fail if one or both of the following is true: EBADF fildes is not a valid open file descriptor. EFAULT buf points to an invalid address. SEE ALSO chmod(2), chown(2), creat(2), link(2), mknod(2), pipe(2), read(2), readlink(2), statfs(2), time(2), unlink(2), ustat(2), utime(2), write(2), stat(5) January 1992 3

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