107 lines
2.1 KiB
Groff
107 lines
2.1 KiB
Groff
.TH STAT 2
|
|
.UC 4
|
|
.SH NAME
|
|
stat, fstat, lstat \- grab inode information.
|
|
.SH SYNOPSIS
|
|
.nf
|
|
.B #include <sys/stat.h>
|
|
.B #include <unistd.h>
|
|
.B "int stat (const char *file_name, struct stat_buf *buf);"
|
|
.B "int fstat (int filedes, struct stat_buf *buf);"
|
|
.B "int lstat (const char *file_name, struct stat_buf *buf);"
|
|
.fi
|
|
.SH DESCRIPTION
|
|
.B stat(), fstat(), and lstat()
|
|
return a stat_buf structure, which is declared as follows in sys/stat.h:
|
|
.br
|
|
.nf
|
|
struct stat {
|
|
.in 20
|
|
dev_t st_dev;
|
|
ino_t st_ino;
|
|
umode_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;
|
|
};
|
|
.in 10
|
|
.fi
|
|
.PP
|
|
The following flags are defined in the st_mode field :
|
|
.br
|
|
.nf
|
|
.B S_IFMT
|
|
.B S_IFLNK
|
|
.B S_IFREG
|
|
.B S_IFBLK
|
|
.B S_IFDIR
|
|
.B S_IFCHR
|
|
.B S_IFIFO
|
|
.B S_ISUID
|
|
.B S_ISGID
|
|
.B S_ISVTX
|
|
.fi
|
|
.PP
|
|
And the following macros are defined to utilize those fields :
|
|
.nf
|
|
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
|
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
|
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
|
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
|
|
|
#define S_IRWXU 00700
|
|
#define S_IRUSR 00400
|
|
#define S_IWUSR 00200
|
|
#define S_IXUSR 00100
|
|
|
|
#define S_IRWXG 00070
|
|
#define S_IRGRP 00040
|
|
#define S_IWGRP 00020
|
|
#define S_IXGRP 00010
|
|
|
|
#define S_IRWXO 00007
|
|
#define S_IROTH 00004
|
|
#define S_IWOTH 00002
|
|
#define S_IXOTH 00001
|
|
.fi
|
|
.PP
|
|
.B stat()
|
|
stats the file pointed to by
|
|
.I file_name
|
|
and fills in the
|
|
.B stat_buf
|
|
pointed to by
|
|
.I buf.
|
|
.PP
|
|
.B lstat()
|
|
is identical to stat, only the link itself is stated, not the file that is obtained
|
|
by tracing the links.
|
|
.PP
|
|
.B fstat()
|
|
is identical to stat, only the open file pointed to by
|
|
.I filedes
|
|
is stated in place of
|
|
.I file_name.
|
|
.PP
|
|
0 is returned on success, a negative value on error.
|
|
.ERRORS
|
|
.B -EBADF
|
|
is returned by
|
|
.B fstat()
|
|
on a bad file descriptor.
|
|
.PP
|
|
.B -ENOENT
|
|
is returned when you attempt to stat a non-existant file.
|
|
.SH FILES
|
|
linux/fs/stat.c, /usr/include/linux/sys.h, /usr/include/unistd.h
|
|
.SH BUGS
|
|
A user can stat files in directories where they have no permissions.
|
|
|