

fstat()                  General Function                 fstat()




Find file attributes

#include <sys/stat.h>
ffssttaatt(_d_e_s_c_r_i_p_t_o_r, _s_t_a_t_p_t_r) iinntt _d_e_s_c_r_i_p_t_o_r; ssttrruucctt ssttaatt *_s_t_a_t_p_t_r;

fstat returns a structure  that contains the attributes of a file
including  protection  information,  file  type, and  file  size.
descriptor is the file  descriptor for the open file, and statptr
points to a  structure of the type stat, which  is defined in the
header file stat.h.

The following summarizes  the structure stat and defines the per-
mission and file type bits.


struct stat {
    dev_t st_dev;
    ino_t st_ino;
    unsigned short st_mode;
    short st_nlink;
    short st_uid;
    short st_gid;
    dev_t st_rdev;
    size_t st_size;
    time_t st_atime;
    time_t st_mtime;
    time_t st_ctime;
};



#define S_IFMT 0170000 /* file types */
#define S_IFREG 0100000/* ordinary file */
#define S_IFDIR 0040000/* directory */
#define S_IFCHR 0020000/* character special */
#define S_IFBLK 0060000/* block special */
#define S_ISUID 0004000/* set user id */
#define S_ISGID 0002000/* set group id */
#define S_ISVTX 0001000/* save text bit */
#define S_IREAD 0000400/* owner read permission */
#define S_IWRITE 000200/* owner write permission */
#define S_IEXEC 0000100/* owner execute permission */


The entries st_dev  and st_ino together form a unique description
of the file.  The former is  the device on which the file and its
i-node  reside, whereas  the latter  is the  index number  of the
file.  The  entry st_mode gives the  permission bits, as outlined
above.  The entry st_nlink gives the number of links to the file.
The user  id and  group id  of the owner  are st_uid  and st_gid,
respectively.  The  entry st_rdev, valid only  for special files,
holds the major and minor numbers for the file.




COHERENT Lexicon                                           Page 1




fstat()                  General Function                 fstat()



The entry  st_size gives the size  of the file, in  bytes.  For a
pipe, the size is the number of bytes waiting to be read from the
pipe.

Three entries for each  file give the last occurrences of various
events in  the file's history.  st_atime gives  time the file was
last read  or written  to.  st_mtime gives  the time of  the last
modification, write for  files, create or delete entry for direc-
tories.  st_ctime  gives the last  change to the  attributes, not
including times and size.

***** Example *****

For an  example of how  to use this  function, see the  entry for
pipe.

***** Files *****

<sys/stat.h>

***** See Also *****

chmod(), chown(), COHERENT system calls, ls, open(), stat()

***** Notes *****

fstat differs  from the related  function stat mainly  in that it
accesses the file through its descriptor, which was returned by a
successful call to open,  whereas stat takes the file's path name
and opens it itself before checking its status.

***** Diagnostics *****

fstat returns  -1 if the file  is not found or  if statptr is in-
valid.






















COHERENT Lexicon                                           Page 2


