xref: /DragonOS/kernel/src/common/fcntl.h (revision fae6e9ade46a52976ad5d099643d51cc20876448)
1 /**
2  * @file fcntl.h
3  * @author fslongjin (longjin@RinGoTek.cn)
4  * @brief
5  * @version 0.1
6  * @date 2022-04-26
7  *
8  * @copyright Copyright (c) 2022
9  *
10  */
11 #pragma once
12 
13 #define O_RDONLY 00000000  // Open Read-only
14 #define O_WRONLY 00000001  // Open Write-only
15 #define O_RDWR 00000002    // Open read/write
16 #define O_ACCMODE 00000003 // Mask for file access modes
17 
18 #define O_CREAT 00000100  // Create file if it does not exist
19 #define O_EXCL 00000200   // Fail if file already exists
20 #define O_NOCTTY 00000400 // Do not assign controlling terminal
21 
22 #define O_TRUNC 00001000 // 文件存在且是普通文件,并以O_RDWR或O_WRONLY打开,则它会被清空
23 
24 #define O_APPEND 00002000 // 文件指针会被移动到文件末尾
25 
26 #define O_NONBLOCK 00004000 // 非阻塞式IO模式
27 
28 #define O_DSYNC 00010000  // used to be O_SYNC, see below
29 #define FASYNC 00020000   // fcntl, for BSD compatibility
30 #define O_DIRECT 00040000 // direct disk access hint
31 #define O_LARGEFILE 00100000
32 #define O_DIRECTORY 00200000 // 打开的必须是一个目录
33 #define O_NOFOLLOW 00400000  // Do not follow symbolic links
34 #define O_NOATIME 01000000
35 #define O_CLOEXEC 02000000 // set close_on_exec
36 
37 /*
38  * The constants AT_REMOVEDIR and AT_EACCESS have the same value.  AT_EACCESS is
39  * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
40  * unlinkat.  The two functions do completely different things and therefore,
41  * the flags can be allowed to overlap.  For example, passing AT_REMOVEDIR to
42  * faccessat would be undefined behavior and thus treating it equivalent to
43  * AT_EACCESS is valid undefined behavior.
44  */
45 // 作为当前工作目录的文件描述符(用于指代cwd)
46 #define AT_FDCWD -100
47 #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links.  */
48 #define AT_EACCESS 0x200          /* Test access permitted for effective IDs, not real IDs.  */
49 #define AT_REMOVEDIR 0x200        /* Remove directory instead of unlinking file.  */
50 #define AT_SYMLINK_FOLLOW 0x400   /* Follow symbolic links.  */
51 #define AT_NO_AUTOMOUNT 0x800     /* Suppress terminal automount traversal */
52 #define AT_EMPTY_PATH 0x1000      /* Allow empty relative pathname */
53 
54 #define AT_STATX_SYNC_TYPE 0x6000    /* Type of synchronisation required from statx() */
55 #define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
56 #define AT_STATX_FORCE_SYNC 0x2000   /* - Force the attributes to be sync'd with the server */
57 #define AT_STATX_DONT_SYNC 0x4000    /* - Don't sync attributes with the server */
58 
59 #define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */