struct stat, struct stat64

data structure containing detailed file information 

Data Structure


#include <sys/types.h>

#include <sys/stat.h>

struct stat {
	dev_t st_dev;
	ino_t st_ino;
	mode_t st_mode;
	nlink_t st_nlink;
	uid_t st_uid;
	gid_t st_gid;
	dev_t st_rdev;
	off_t st_size;
	time_t st_atime;
	time_t st_mtime;
	time_t st_ctime;
	blksize_t st_blksize;
	blkcnt_t st_blocks;
	mode_t st_attr;

struct stat64 {
	dev_t st_dev;
	ino64_t st_ino;
	mode_t st_mode;
	nlink_t st_nlink;
	uid_t st_uid;
	gid_t st_gid;
	dev_t st_rdev;
	off64_t st_size;
	time_t st_atime;
	time_t st_mtime;
	time_t st_ctime;
	blksize_t st_blksize;
	blkcnt64_t st_blocks;
	mode_t st_attr;


The stat structure is returned by the fstat() and stat() functions. It provides detailed information about a file. The information returned depends on the type of file and/or the file system on which the file resides.

The stat64 structure is similar to the stat structure, except that it is capable of returning information about files that are larger than 2 gigabytes. The stat64 structure is returned by the fstat64() and stat64() functions, which are a part of the large file extensions.

Fields of the Structure

The stat and stat64 structures contain the following fields:


ID of device containing the file.


Serial number for the file.


Access mode and file type for the file (see Flags).


Number of links to the file.


User ID of file owner.


Group ID of group owner.


Device ID (if the file is a character or block special device).


File size in bytes (if the file is a regular file).


Time of last access.


Time of last data modification.


Time of last file status change.


A file system-specific preferred I/O block size for this object. On some file system types, this may vary from file to file.


Number of blocks allocated for this file.


The DOS-style attributes for this file (see Flags). This is a PTC MKS Toolkit UNIX APIs extension.


The st_mode field contains flags that identify the access mode. There are several NuTCRACKER Platform extensions to the standard access modes, to describe the extended file permissions provided by Windows.

Flag Meaning
S_IRWXU Read, write, execute/search permission for owner.
S_IRUSR Read permission for owner.
S_IWUSR Write permission for owner.
S_IXUSR Execute/search permission for owner.
S_IRWXG Read, write, execute/search for group.
S_IRGRP Read permission for group.
S_IWGRP Write permission for group.
S_IXGRP Execute/search permission for group.
S_IRWXO Read, write, execute/search for others.
S_IROTH Read permission for others.
S_IWOTH Write permission for others.
S_IXOTH Execute/search permission for others.
S_IDPOU Delete, change permission, and take ownership for owner.
S_IDUSR Delete permission for owner.
S_IPUSR Change permission permission for owner.
S_IOUSR Take ownership permission for owner.
S_IDPOG Delete, change permission, and take ownership for group.
S_IDGRP Delete permission for group.
S_IPGRP Change permission permission for group.
S_IOGRP Take ownership permission for group.
S_IDPOO Delete, change permission, and take ownership for others.
S_IDOTH Delete permission for others.
S_IPOTH Change permission permission for others.
S_IOOTH Take ownership permission for others.
S_ISUID Set-user-ID on execution (not supported).
S_ISGID Set-group-ID on execution (not supported). If this bit is set, and S_IXGRP is not set, then mandatory locking is enabled for the file. Refer to fcntl() for more discussion on file locks.
S_ISVTX Restricted-deletion flag for directories

In addition, the st_mode field defines the file type, using the following flags. The macros described in Access Macros should be used rather than directly accessing the bits in st_mode.

Flag Meaning
S_IFMT Type of file.
S_IFBLK File is a block-device special file.
S_IFCHR File is a character-device special file.
S_IFIFO File is a FIFO special file.
S_IFREG File is a regular file.
S_IFDIR File is a directory.
S_IFSOCK File is a socket.

The NuTCRACKER Platform stat structure has an st_attr field which specifies the DOS-style attributes for a file, as follows:

Flag Meaning
S_IAREAD File is marked as read-only
S_IAHID File is marked as hidden
S_IASYS File is marked as a system file
S_IADIR File is a directory
S_IAENCR File is encrypted
S_IAARCH File needs backup ('archive' bit)
S_IANORM File is a normal file
S_IATEMP File is a temporary file
S_IASPARSE File is a sparse file
S_IAREPARSE File has an associated reparse point
S_IACOMP File is compressed
S_IAOFFL File is offline

Access Macros

The file type can be determined from the stat structure by testing the st_mode field of the structure with the following macros. Each returns a non-zero value if the file is of that type, or 0 if it is not.

Macro Meaning
S_ISBLK(m) File is a block-device special file.
S_ISCHR(m) File is a character-device special file.
S_ISFIFO(m) File is a FIFO special file.
S_ISREG(m) File is a regular file.
S_ISDIR(m) File is a directory.
S_ISSOCK(m) File is a socket.

File Type and File System Issues

The NuTCRACKER Platform cannot provide a complete stat structure for all files and devices, because of differences in the operating system's representation of the data, and in the implementation of special files. For disk files the following applies:

For special files and devices, you cannot depend on which fields are valid for a given device. The bits in st_mode which indicate the type of the file (for example, the S_ISXXX macros) are always valid.

For symbolic links, the st_mode member contains meaningful information when used with the file type macros, and the st_size member contains the length of the symbolic link. File mode bits and contents of the remaining members of the stat structure are unspecified. The value returned in the st_size member is the length of the contents of the symbolic link, and does not count any trailing null.


UNIX 98, with exceptions.


Because of Windows file system limitations, the NuTCRACKER Platform does not implement the full semantics defined by the referenced standard. Please refer to the File Management section of the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for more information.


PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


_NutFastStat(), chmod(), chown(), fchmod(), fchown(), fcntl(), fstat(), lstat(), mkdir(), mkfifo(), mknod(), stat(), symlink(), umask()


PTC MKS Toolkit 10.4 Documentation Build 39.