• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2 /*
3  * Special types used by various syscalls for NOLIBC
4  * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
5  */
6 
7 #ifndef _NOLIBC_TYPES_H
8 #define _NOLIBC_TYPES_H
9 
10 #include "std.h"
11 #include <linux/time.h>
12 
13 
14 /* Only the generic macros and types may be defined here. The arch-specific
15  * ones such as the O_RDONLY and related macros used by fcntl() and open(), or
16  * the layout of sys_stat_struct must not be defined here.
17  */
18 
19 /* stat flags (WARNING, octal here) */
20 #define S_IFDIR        0040000
21 #define S_IFCHR        0020000
22 #define S_IFBLK        0060000
23 #define S_IFREG        0100000
24 #define S_IFIFO        0010000
25 #define S_IFLNK        0120000
26 #define S_IFSOCK       0140000
27 #define S_IFMT         0170000
28 
29 #define S_ISDIR(mode)  (((mode) & S_IFDIR)  == S_IFDIR)
30 #define S_ISCHR(mode)  (((mode) & S_IFCHR)  == S_IFCHR)
31 #define S_ISBLK(mode)  (((mode) & S_IFBLK)  == S_IFBLK)
32 #define S_ISREG(mode)  (((mode) & S_IFREG)  == S_IFREG)
33 #define S_ISFIFO(mode) (((mode) & S_IFIFO)  == S_IFIFO)
34 #define S_ISLNK(mode)  (((mode) & S_IFLNK)  == S_IFLNK)
35 #define S_ISSOCK(mode) (((mode) & S_IFSOCK) == S_IFSOCK)
36 
37 /* dirent types */
38 #define DT_UNKNOWN     0x0
39 #define DT_FIFO        0x1
40 #define DT_CHR         0x2
41 #define DT_DIR         0x4
42 #define DT_BLK         0x6
43 #define DT_REG         0x8
44 #define DT_LNK         0xa
45 #define DT_SOCK        0xc
46 
47 /* commonly an fd_set represents 256 FDs */
48 #define FD_SETSIZE     256
49 
50 /* Special FD used by all the *at functions */
51 #ifndef AT_FDCWD
52 #define AT_FDCWD       (-100)
53 #endif
54 
55 /* whence values for lseek() */
56 #define SEEK_SET       0
57 #define SEEK_CUR       1
58 #define SEEK_END       2
59 
60 /* cmd for reboot() */
61 #define LINUX_REBOOT_MAGIC1         0xfee1dead
62 #define LINUX_REBOOT_MAGIC2         0x28121969
63 #define LINUX_REBOOT_CMD_HALT       0xcdef0123
64 #define LINUX_REBOOT_CMD_POWER_OFF  0x4321fedc
65 #define LINUX_REBOOT_CMD_RESTART    0x01234567
66 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xd000fce2
67 
68 /* Macros used on waitpid()'s return status */
69 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
70 #define WIFEXITED(status)   (((status) & 0x7f) == 0)
71 
72 
73 /* for select() */
74 typedef struct {
75 	uint32_t fd32[FD_SETSIZE / 32];
76 } fd_set;
77 
78 /* for poll() */
79 struct pollfd {
80 	int fd;
81 	short int events;
82 	short int revents;
83 };
84 
85 /* for getdents64() */
86 struct linux_dirent64 {
87 	uint64_t       d_ino;
88 	int64_t        d_off;
89 	unsigned short d_reclen;
90 	unsigned char  d_type;
91 	char           d_name[];
92 };
93 
94 /* needed by wait4() */
95 struct rusage {
96 	struct timeval ru_utime;
97 	struct timeval ru_stime;
98 	long   ru_maxrss;
99 	long   ru_ixrss;
100 	long   ru_idrss;
101 	long   ru_isrss;
102 	long   ru_minflt;
103 	long   ru_majflt;
104 	long   ru_nswap;
105 	long   ru_inblock;
106 	long   ru_oublock;
107 	long   ru_msgsnd;
108 	long   ru_msgrcv;
109 	long   ru_nsignals;
110 	long   ru_nvcsw;
111 	long   ru_nivcsw;
112 };
113 
114 /* The format of the struct as returned by the libc to the application, which
115  * significantly differs from the format returned by the stat() syscall flavours.
116  */
117 struct stat {
118 	dev_t     st_dev;     /* ID of device containing file */
119 	ino_t     st_ino;     /* inode number */
120 	mode_t    st_mode;    /* protection */
121 	nlink_t   st_nlink;   /* number of hard links */
122 	uid_t     st_uid;     /* user ID of owner */
123 	gid_t     st_gid;     /* group ID of owner */
124 	dev_t     st_rdev;    /* device ID (if special file) */
125 	off_t     st_size;    /* total size, in bytes */
126 	blksize_t st_blksize; /* blocksize for file system I/O */
127 	blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
128 	time_t    st_atime;   /* time of last access */
129 	time_t    st_mtime;   /* time of last modification */
130 	time_t    st_ctime;   /* time of last status change */
131 };
132 
133 #endif /* _NOLIBC_TYPES_H */
134