Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ stat(2) — posix — mips UMIPS RISC/os 4.52

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(2)

chown(2)

creat(2)

dup(2)

fcntl(2)

link(2)

mknod(2)

open(2)

pipe(2)

read(2)

stat(5)

time(2)

unlink(2)

utime(2)

write(2)



STAT(2-POSIX)       RISC/os Reference Manual        STAT(2-POSIX)



NAME
     stat, lstat, fstat - get file status

SYNOPSIS
     #include <sys/types.h>
     #include <sys/stat.h>

     int stat (path, buf)
     char *path;
     struct stat *buf;

     int lstat (path, buf)
     char *path;
     struct stat *buf;

     int fstat (fildes, buf)
     int fildes;
     struct stat *buf;

DESCRIPTION
     path points to a path name naming a file.  Read, write, or
     execute permission of the named file is not required, but
     all directories listed in the path name leading to the file
     must be searchable.  stat obtains information about the
     named file.

     lstat is the same as stat except that when path names a sym-
     bolic link, the information retrieved is for the symbolic
     link instead of the file it points to.

     fstat obtains information about an open file known by the
     file descriptor fildes, obtained from a successful open,
     creat, dup, dup2, 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 pointed to by buf include the
     following members:

     mode_t    st_mode;      /* File mode [see stat(5)] */
     ino_t     st_ino;       /* Inode number */
     dev_t     st_dev;       /* ID of the device containing */
                             /* a directory entry for this file */
     dev_t     st_rdev;      /* ID of the device. This entry is */
                             /* only defined for character special */
                             /* and block special files */
     nlink_t   st_nlink;     /* Number of links */
     uid_t     st_uid;       /* User ID of the file's owner */
     gid_t     st_gid;       /* Group ID of the file's group */
     off_t     st_size;      /* File size in bytes for regular files */
     time_t    st_atime;     /* Time of last access */



                         Printed 1/15/91                   Page 1





STAT(2-POSIX)       RISC/os Reference Manual        STAT(2-POSIX)



     time_t    st_mtime;     /* Time of last data modification */
     time_t    st_ctime;     /* Time of last file status change */
                             /* Times measured in seconds since the */
                             /* epoch (00:00:00 GMT, Jan. 1, 1970) */

     stmode   The mode of the file as described in stat(5).

     stino    This field uniquely identifies the file in a given
               file system.  The pair st_ino and st_dev uniquely
               identifies regular files.

     stdev    This field uniquely identifies the file system
               that contains the file.  Its value may be used as
               input to the ustat(2) system call to determine
               more information about this file system.  No other
               meaning is associated with this value.

     strdev   This field should be used only by administrative
               commands.  It is valid only for block special or
               character special files and only has meaning on
               the system where the file was configured.

     stnlink  This field should be used only by administrative
               commands.

     stuid    The user ID of the file's owner.

     stgid    The group ID of the file's group.

     stsize   For regular files, this is the address of the end
               of the file.  For pipes or fifos, this is the
               count of the data currently in the file.  For
               block special or character special, this is not
               defined.

     statime  Time when file data was last accessed.  Changed by
               the following system calls:  creat(2), mknod(2),
               pipe(2), utime(2), and read(2).

     stmtime  Time when data was last modified.  Changed by the
               following system calls:  creat(2), mknod(2),
               pipe(2), utime(2), and write(2).

     stctime  Time when file status was last changed.  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).

     The following macros are available for testing whether a
     file is of a specific type.  The value m supplied to the
     macros is the value of st_mode from a stat structure.  Each
     macro evaluates to a nonzero value if the test is true, zero



 Page 2                  Printed 1/15/91





STAT(2-POSIX)       RISC/os Reference Manual        STAT(2-POSIX)



     if the test is false.

     SISDIR(m)          Test whether m is a directory.
     SISCHR(m)          Test whether m is a character special file.
     SISBLK(m)          Test whether m is a block special file.
     SISREG(m)          Test whether m is a regular file.
     SISFIFO(m)         Test whether m is a FIFO.

RETURN VALUES
     Upon successful completion a value of 0 is returned.  Other-
     wise, a value of -1 is returned and errno is set to indicate
     the error.

ERRORS
     stat and lstat will fail if one or more of the following are
     true:

     [ENOTDIR]           A component of the path prefix is not a
                         directory.

     [ENOENT]            The named file does not exist or path
                         specifies an empty string.

     [EACCES]            Search permission is denied for a com-
                         ponent of the path prefix.

     [EFAULT]            buf or path points to an invalid
                         address.

     [EINTR]             A signal was caught during the stat sys-
                         tem call.

     [ENAMETOOLONG]      The length of path exceeds {PATH_MAX},
                         or a pathname component is longer than
                         {NAME_MAX} while {_POSIX_NO_TRUNC} is in
                         effect.

     fstat will fail if one or more of the following are true:

     [EBADF]             fildes is not a valid open file descrip-
                         tor.

     [EFAULT]            buf points to an invalid address.

SEE ALSO
     chmod(2), chown(2), creat(2), dup(2), fcntl(2), link(2),
     mknod(2), open(2), pipe(2), read(2), stat(5), time(2),
     unlink(2), utime(2), write(2).







                         Printed 1/15/91                   Page 3



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