HPlogo HP-UX Reference Volume 5 of 5 > s

stat(5)

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

NAME

sys/stat.h — data returned by the stat() function

SYNOPSIS

#include <sys/stat.h>

DESCRIPTION

The <sys/stat.h> header defines the structure of the data returned by the functions fstat(), lstat(), and stat(). The structure stat contains at least the following members:

dev_tst_devID of device containing file
ino_tst_inofile serial number
mode_tst_modemode of file (see below)
nlink_tst_nlinknumber of links to the file
uid_tst_uiduser ID of file
gid_tst_gidgroup ID of file
dev_tst_rdevdevice ID (if file is character or block special)
off_tst_sizefile size in bytes (if file is a regular file)
time_tst_atimetime of last access
time_tst_mtimetime of last data modification
time_tst_ctimetime of last status change
longst_blksizea filesystem-specific preferred I/O block size for this object. In some filesystem types, this may vary from file to file
longst_blocksnumber of blocks of a filesystem-specific size allocated for this object

File serial number and device ID taken together uniquely identify the file within the system. The dev_t, ino_t, mode_t, nlink_t, uid_t, gid_t, off_t, and time_t types are defined as described in <sys/types.h>. Times are given in seconds since the Epoch.

The following symbolic names for the values of st_mode are also defined:

File type:

S_IFMTtype of file
S_IFBLKblock special
S_IFCHRcharacter special
S_IFIFOFIFO special
S_IFREGregular
S_IFDIRdirectory
S_IFLNKsymbolic link

File mode bits:

S_IRWXUread, write, execute/search by owner
S_IRUSRread permission, owner
S_IWUSRwrite permission, owner
S_IXUSRexecute/search permission, owner
S_IRWXGread, write, execute/search by group
S_IRGRPread permission, group
S_IWGRPwrite permission, group
S_IXGRPexecute/search permission, group
S_IRWXOread, write, execute/search by others
S_IROTHread permission, others
S_IWOTHwrite permission, others
S_IXOTHexecute/search permission, others
S_ISUIDset-user-ID on execution
S_ISGIDset-group-ID on execution
S_ISVTXon directories, restricted deletion flag

The bits defined by S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, S_ISUID, S_ISGID and S_ISVTX are unique. S_IRWXU is the bitwise OR of S_IRUSR, S_IWUSR, and S_IXUSR. S_IRWXG is the bitwise OR of S_IRGRP, S_IWGRP, and S_IXGRP. S_IRWXO is the bitwise OR of S_IROTH, S_IWOTH, and S_IXOTH.

Implementations may OR other implementation-dependent bitsinto S_IRWXU, S_IRWXG, and S_IRWXO, but they will not overlap any of the other bits defined in this document. The file permission bits are defined to be those corresponding to the bitwise inclusive OR of S_IRWXU, S_IRWXG, and S_IRWXO.

The following macros will test whether a file is of the specified type. The value m supplied to the macros is the value of st_mode from a stat structure. The macro evaluates to a non-zero value if the test is true, 0 if the test is false.

S_ISBLK(m)Test for a block special file.
S_ISCHR(m)Test for a character special file.
S_ISDIR(m)Test for a directory.

S_ISFIFO(m)Test for a pipe or FIFO special file.
S_ISREG(m)Test for a regular file.
S_ISLNK(m)Test for a symbolic link.

The following are declared as functions and may also be defined as macros:

intchmod(const char *path, mode_t mode);
intlstat(const char *path, struct stat *buf);
intmkdir(const char *path, mode_t mode);
intmkfifo(const char *path, mode_t mode);
intmknod(const char *path, mode_t mode, dev_t dev);
intstat(const char *path, struct stat *buf);
mode_tumask(mode_t cmask);

APPLICATION USAGE

Use of the macros is recommended for determining the type of a file.

SEE ALSO

chmod(), fchmod(), fstat(), lstat(), mkdir(), mkfifo(), mknod(), stat(), umask(), <sys/types.h>.

CHANGE HISTORY

First released in Issue 1.

Derived from Issue 1 of the SVID.

Issue 4

The following changes are incorporated for alignment with the ISO POSIX-1 standard:

  • The function declarations in this header are expanded to full ISO C prototypes.

  • The DESCRIPTION section is expanded to indicate (a) how files are uniquely identified within the system, (b) that times are given in units of seconds since the Epoch, (c) rules governing the definition and use of the file mode bits, and (d) usage of the file type test macros.

Other changes are incorporated as follows:

  • Reference to the header <sys/types.h> is added for the definitions of dev_t, ino_t, mode_t, nlink_t, uid_t, gid_t, off_t, and time_t. This has been marked as an extension.

  • References to the S_IREAD, S_IWRITE, S_IEXEC file and S_ISVTX modes are removed.

  • The descriptions of the members of the stat structure in the DESCRIPTION section are corrected.

Issue 4, Version 2

The following changes are incorporated for X\/OPEN UNIX conformance:

  • The st_blksize and st_blocks members are added to the stat structure.

  • The S_IFLINK value of S_IFMT is defined.

  • The S_ISVTX file mode bit and the S_ISLNK file type test macro is defined.

  • The fchmod(), lstat(), and mknod() functions are added to the list of functions declared in this header.

stat HP-UX EXTENSIONS

NAME (HP-UX)

stat.h - file-specific information

DESCRIPTION

The contents of the stat structure include the following members:

ushort st_fstype;

/*Type of filesystem this file */

/* is in; see vfsmount(2) */

dev_t st_realdev;

/* Real device number of device */

/* containing the inode for this file */

The following symbolic names for the values of the st_mode field are defined as indicated:

File type:

S_IFMT0170000type of file
S_IFSOCK0140000socket
S_IFLNK0120000symbolic link
S_IFNWK0110000network special
S_IFREG0100000regular (ordinary)
S_IFBLK0060000block special
S_IFDIR0040000directory
S_IFCHR0020000character special
S_IFIFO0010000FIFO special (named pipe)

File mode bits:

File miscellaneous mode bits:

S_CDF0004000directory is a context-dependent file
S_ISUID0004000set user id on execution
S_ISGID0002000set group id on execution
S_ENFMT0002000set file-locking mode to enforced
S_ISVTX0001000save swapped text even after use

File permission mode bits:

S_IRWXU0000700owner's file access permission bits
S_IRUSR0000400read access permission for owner
S_IWUSR0000200write access permission for owner
S_IXUSR0000100execute/search access permission for owner
S_IRWXG0000070group's file access permission bits
S_IRGRP0000040read access permission for group
S_IWGRP0000020write access permission for group
S_IXGRP0000010execute/search access permission for group
S_IRWXO0000007others' access permission bits
S_IROTH0000004read access permission for others
S_IWOTH0000002write access permission for others
S_IXOTH0000001execute/search access permission for others

Obsolete names for file permission mode bits:

S_IREAD0000400read access permission for owner
S_IWRITE0000200write access permission for owner
S_IEXEC0000100execute/search access permission for owner

File type test macros:

S_ISCDF(m)test for a context-dependent file
S_ISNWK(m)test for a network special
S_ISSOCK(m)test for a socket

STANDARDS CONFORMANCE

<sys/stat.h>: AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1

© Hewlett-Packard Development Company, L.P.