The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
stat.h File Reference

file metadata: stat() and fstat(). More...

#include <sys/types.h>
#include <time.h>

Go to the source code of this file.

Data Structures

struct  stat

Macros

#define S_IFMT   0170000
#define S_IFIFO   0010000
#define S_IFSOCK   0140000
#define S_IFCHR   0020000
#define S_IFDIR   0040000
#define S_IFBLK   0060000
#define S_IFREG   0100000
#define S_IFLNK   0120000
#define S_ISFIFO(m)
#define S_ISCHR(m)
#define S_ISDIR(m)
#define S_ISBLK(m)
#define S_ISREG(m)
#define S_ISLNK(m)
#define S_ISSOCK(m)
#define S_IRWXU   0700
#define S_IRUSR   0400
#define S_IWUSR   0200
#define S_IXUSR   0100
#define S_IRWXG   0070
#define S_IRGRP   0040
#define S_IWGRP   0020
#define S_IXGRP   0010
#define S_IRWXO   0007
#define S_IROTH   0004
#define S_IWOTH   0002
#define S_IXOTH   0001
#define st_atime   st_atim.tv_sec
#define st_mtime   st_mtim.tv_sec
#define st_ctime   st_ctim.tv_sec
#define S_ISUID   04000
#define S_ISGID   02000
#define S_ISVTX   01000
#define UTIME_NOW   ((1l << 30) - 1)
#define UTIME_OMIT   ((1l << 30) - 2)

Functions

int stat (const char *path, struct stat *st)
 get a file's metadata by path.
int lstat (const char *path, struct stat *st)
 the metadata of a symbolic link itself (stat gives what it points at).
int fstat (int fd, struct stat *st)
 get an open file's metadata (pipes and the console too).
int mkdir (const char *path, mode_t mode)
 create a directory with a mode (taken through the umask).
int mkdirat (int dirfd, const char *path, mode_t mode)
int fstatat (int dirfd, const char *path, struct stat *st, int flags)
int fchmodat (int dirfd, const char *path, mode_t mode, int flags)
int chmod (const char *path, mode_t mode)
 change the permission bits of a file (owner or root only).
int fchmod (int fd, mode_t mode)
mode_t umask (mode_t mask)
 set the mask taken off the mode of new files.
int utimensat (int dirfd, const char *path, const struct timespec times[2], int flags)
 set a file's access and modification times (times[0], times[1]); with times NULL, both to the time now.
int futimens (int fd, const struct timespec times[2])
int mkfifo (const char *path, mode_t mode)
 make a named pipe (a FIFO): processes that open it share one pipe.
int mkfifoat (int dirfd, const char *path, mode_t mode)
int mknod (const char *path, mode_t mode, dev_t dev)
 make a named pipe (S_IFIFO), an empty file (S_IFREG) or, as root, a device node (S_IFCHR, S_IFBLK with makedev's number).
int mknodat (int dirfd, const char *path, mode_t mode, dev_t dev)

Detailed Description

file metadata: stat() and fstat().

struct stat and the S_ bits are ABI and must match the kernel side in src/kernel/vfs/stat.h exactly.

Macro Definition Documentation

◆ S_IFMT

#define S_IFMT   0170000

◆ S_IFIFO

#define S_IFIFO   0010000

◆ S_IFSOCK

#define S_IFSOCK   0140000

◆ S_IFCHR

#define S_IFCHR   0020000

◆ S_IFDIR

#define S_IFDIR   0040000

◆ S_IFBLK

#define S_IFBLK   0060000

◆ S_IFREG

#define S_IFREG   0100000

◆ S_IFLNK

#define S_IFLNK   0120000

◆ S_ISFIFO

#define S_ISFIFO ( m)
Value:
(((m) & S_IFMT) == S_IFIFO)
#define S_IFIFO
Definition stat.h:15
#define S_IFMT
Definition stat.h:14

◆ S_ISCHR

#define S_ISCHR ( m)
Value:
(((m) & S_IFMT) == S_IFCHR)
#define S_IFCHR
Definition stat.h:17

◆ S_ISDIR

#define S_ISDIR ( m)
Value:
(((m) & S_IFMT) == S_IFDIR)
#define S_IFDIR
Definition stat.h:18

◆ S_ISBLK

#define S_ISBLK ( m)
Value:
(((m) & S_IFMT) == S_IFBLK)
#define S_IFBLK
Definition stat.h:19

◆ S_ISREG

#define S_ISREG ( m)
Value:
(((m) & S_IFMT) == S_IFREG)
#define S_IFREG
Definition stat.h:20

◆ S_ISLNK

#define S_ISLNK ( m)
Value:
(((m) & S_IFMT) == S_IFLNK)
#define S_IFLNK
Definition stat.h:21

◆ S_ISSOCK

#define S_ISSOCK ( m)
Value:
(((m) & S_IFMT) == S_IFSOCK)
#define S_IFSOCK
Definition stat.h:16

◆ S_IRWXU

#define S_IRWXU   0700

◆ S_IRUSR

#define S_IRUSR   0400

◆ S_IWUSR

#define S_IWUSR   0200

◆ S_IXUSR

#define S_IXUSR   0100

◆ S_IRWXG

#define S_IRWXG   0070

◆ S_IRGRP

#define S_IRGRP   0040

◆ S_IWGRP

#define S_IWGRP   0020

◆ S_IXGRP

#define S_IXGRP   0010

◆ S_IRWXO

#define S_IRWXO   0007

◆ S_IROTH

#define S_IROTH   0004

◆ S_IWOTH

#define S_IWOTH   0002

◆ S_IXOTH

#define S_IXOTH   0001

◆ st_atime

#define st_atime   st_atim.tv_sec

◆ st_mtime

#define st_mtime   st_mtim.tv_sec

◆ st_ctime

#define st_ctime   st_ctim.tv_sec

◆ S_ISUID

#define S_ISUID   04000

◆ S_ISGID

#define S_ISGID   02000

◆ S_ISVTX

#define S_ISVTX   01000

◆ UTIME_NOW

#define UTIME_NOW   ((1l << 30) - 1)

◆ UTIME_OMIT

#define UTIME_OMIT   ((1l << 30) - 2)

Function Documentation

◆ stat()

int stat ( const char * path,
struct stat * st )

get a file's metadata by path.

Returns
0, or -1 (errno set).

◆ lstat()

int lstat ( const char * path,
struct stat * st )

the metadata of a symbolic link itself (stat gives what it points at).

◆ fstat()

int fstat ( int fd,
struct stat * st )

get an open file's metadata (pipes and the console too).

Returns
0, or -1 (errno set).

◆ mkdir()

int mkdir ( const char * path,
mode_t mode )

create a directory with a mode (taken through the umask).

◆ mkdirat()

int mkdirat ( int dirfd,
const char * path,
mode_t mode )

◆ fstatat()

int fstatat ( int dirfd,
const char * path,
struct stat * st,
int flags )

◆ fchmodat()

int fchmodat ( int dirfd,
const char * path,
mode_t mode,
int flags )

◆ chmod()

int chmod ( const char * path,
mode_t mode )

change the permission bits of a file (owner or root only).

◆ fchmod()

int fchmod ( int fd,
mode_t mode )

◆ umask()

mode_t umask ( mode_t mask)

set the mask taken off the mode of new files.

Returns
the old mask.

◆ utimensat()

int utimensat ( int dirfd,
const char * path,
const struct timespec times[2],
int flags )

set a file's access and modification times (times[0], times[1]); with times NULL, both to the time now.

Parameters
flagsAT_SYMLINK_NOFOLLOW: the link itself.
Returns
0, or -1 (errno set).

◆ futimens()

int futimens ( int fd,
const struct timespec times[2] )

◆ mkfifo()

int mkfifo ( const char * path,
mode_t mode )

make a named pipe (a FIFO): processes that open it share one pipe.

Returns
0, or -1 (errno set).

◆ mkfifoat()

int mkfifoat ( int dirfd,
const char * path,
mode_t mode )

◆ mknod()

int mknod ( const char * path,
mode_t mode,
dev_t dev )

make a named pipe (S_IFIFO), an empty file (S_IFREG) or, as root, a device node (S_IFCHR, S_IFBLK with makedev's number).

a device node outside /dev opens with ENXIO: ginnOS's devices are in /dev.

Returns
0, or -1 (errno set).

◆ mknodat()

int mknodat ( int dirfd,
const char * path,
mode_t mode,
dev_t dev )