Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S

stat(5)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

stat: 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
blkcnt_tst_blocksnumber of blocks of a filesystem-specific size allocated for this object
shortst_fstypetype of filesystem this file is in; see vfsmount(2)
dev_tst_realdevreal device number of device containing the inode for this file

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, time_t and blkcnt_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_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: miscellaneous

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_ISVTX0001000set sticky bit on a directory file

File mode bits: permissions

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

File mode bits: obsolete permission names

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

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_ISGlD 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 bits into 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_ISCDF(m)Test for a context-dependent 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_ISLNK(m)Test for a symbolic link.
S_ISNWK(m)Test for a network special file.
S_ISREG(m)Test for a regular file.
S_ISSOCK(m)Test for a socket.

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

int chmod(const char *path, mode_t mode); int lstat(const char *path, struct stat *buf); int mkdir(const char *path, mode_t mode); int mkfifo(const char *path, mode_t mode); int mknod(const char *path, mode_t mode, dev_t dev); int stat(const char *path, struct stat *buf); mode_t umask(mode_t cmask);

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

WARNINGS

For 32-bit applications, st_ino will be truncated to its least significant 32-bits for file systems that use 64-bit values.

STANDARDS CONFORMANCE

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

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.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.