stat

getting file system information from Win32 

Miscellaneous Information


DESCRIPTION

On a UNIX system, the file system maintains information about files. On Windows systems, not all of this information is available. Following is a description of how PTC MKS Toolkit gets the information it needs about a file on one of the operating systems.

Information about a UNIX file is made available by a system call named stat(), which fills a structure of integer fields. On Windows systems, not all these fields are useful; however, the PTC MKS Toolkit maintains as much information as possible so as to support future file system enhancements.

The following values are available for PTC MKS Toolkit:

dev 

Disk device number, where A: is device 0, B: is 1, and so forth.

ino 

Set to 3 unless this is a root directory; On 2012/8.1/2012R2/10/2016/2019, a file system unique number is given, however it may change over boots, and some networked file systems may not support it.

mode 

Encoded description of file type and file access permissions

nlink 

Always the value 1. Note that the extended FAT file system does not support the linking of files. Even though NTFS does support multiple links, the PTC MKS Toolkit does not always provide this information (for performance reasons). See the description of TK_NTLINKS_OFF on the envvar reference page.

uid 

Numeric value of owner of file. On 2012/8.1/2012R2/10/2016/2019, this value is an arbitrary index into a table used internally by the MKS utilities.

gid 

Numeric value of file's primary group owner. On 2012/8.1/2012R2/10/2016/2019 this value is an arbitrary index into a table used internally by the MKS utilities.

rdev 

Always 0 (Windows systems have no device files)

size 

File size in bytes. Directories normally have size 0. On 2012/8.1/2012R2/10/2016/2019, directories may have a non-zero size but this depends on the file system and whether the Win32 api's returns this information for a particular directory.

mtime 

Time of file's last modification. This value is valid only if supported by the file's file system. This is supported by extended FAT, NTFS, NetWare and many other network file systems.

atime 

Time of file's last access. This value is valid only if supported by the file's file system. This is supported by the extended FAT and the NTFS file system on 2012/8.1/2012R2/10/2016/2019.

For other file systems (for example, networked), the value is dependent on what the file system server returns.

ctime 

Time of file's creation. This value is valid only if supported by the file's file system. This is supported by the extended FAT and the NTFS file system on 2012/8.1/2012R2/10/2016/2019.

The value returned for this file system is the same as mtime.

For other file systems (such as networked), the value is dependent on what the file system server returns.

The mode field encodes the file type (for example, regular file, directory), the file access permissions (for example, read, write, execute) and several file attributes (for example, read_only, hidden, system).

On UNIX systems the mode permission bits are encoded as shown in Table 1. Values can be OR-ed together to get an octal value for these three bits. These three bits are replicated three times; for the owner, group, and world permissions of this file. Thus, for example, the mode

0720 (octal)

provides permission to read, write, or execute a file by its owner, allows others in the same group to write the file, and prevents anyone else from accessing this file.

If this same permission was applied to a directory, then the owner could read, search, and add or delete files under the directory, and users in the same group could add or delete files, while anyone else could not do anything with this directory.

Regarding modes, the ls and chmod commands try to mirror the same capabilities as are available under UNIX systems. You can specify modes with the octal notation shown earlier, or by concatenating the indicated mode specifiers. For example, the octal mode 0720 could also be given as:

-rwx-w----

in the output of the ls command, and specified as

u=rwx,g=w

for the chmod command.

Bit Value Specifier File Directory

0 1 x executable can search directory
1 2 w write access can modify (delete/add files)
2 4 r read access read access

Table 1: Mode Permission Bits in UNIX Systems

The PTC MKS Toolkit does not support a distinction between owner, group and other because Windows systems do not support it. Therefore the owner permissions are automatically mirrored to the group and other permission fields. Further, the read and execute permission bits are always set and the write bit is cleared if the file's read-only attribute is set. So if the read-only attribute is set, the file mode looks like

-r-xr-xr-x or 0555 (octal)

Otherwise, the file mode is:

-rwxrwxrwx or 0777 (octal)

For Windows systems, there are additional mode bits that are used to store the file attributes such as the system, hidden, and archive attributes. Bit 10 is used to indicate that the archive attribute is set, bit 11 is used to indicate that the hidden attribute is set, and bit 12 is used to indicate that the system attribute is set.

Table 2 shows the assignment of these modes to PTC MKS Toolkit:

Attribute Description character used by ls

HIDDEN hidden file h (replaces owner x bit)
SYSTEM system file s (replaces group x bit)
ARCHIVE file requiring archival a (replaces other x bit)
COMPRESSED compressed file c (replaces owner h bit)
TEMPORARY temporary file not displayed

Table 2: Mode Mappings in PTC MKS Toolkit

If you run the ls command on some files, you can see how these attributes are displayed. The SYSTEM attribute is shown as a s replacing the x in the group part of the file mode. The HIDDEN attribute is shown as a h replacing the x in the user part of the file mode, while the ARCHIVE attribute is shown as a a replacing the x in the other part of the file mode.

For example, here is the mode of the IO.SYS file on a typical 2012/8.1/2012R2/10/2016/2019 system:

-r-hr-sr-a or 07555 (octal)

This means that IO.SYS is read-only, and is a hidden system file, with the archive bit set.

The find command in the PTC MKS Toolkit can manipulate the additional modes. For example, you can find all the system files on your hard disk with a command such as this:

$ find / -perm -02000

AVAILABILITY

PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
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


SEE ALSO

Commands:
chmod, find, ls


PTC MKS Toolkit 10.3 Documentation Build 39.