Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
file-types.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright 2015 Cloudius Systems
20 */
21
22#pragma once
23
24#ifndef SEASTAR_MODULE
25#include <fcntl.h>
26#include <sys/stat.h>
27#include <type_traits>
28#include <seastar/util/modules.hh>
29#endif
30
31namespace seastar {
32
33SEASTAR_MODULE_EXPORT_BEGIN
34
37
41enum class open_flags {
42 rw = O_RDWR,
43 ro = O_RDONLY,
44 wo = O_WRONLY,
45 create = O_CREAT,
46 truncate = O_TRUNC,
47 exclusive = O_EXCL,
48 dsync = O_DSYNC,
49};
50
51inline open_flags operator|(open_flags a, open_flags b) {
52 return open_flags(std::underlying_type_t<open_flags>(a) | std::underlying_type_t<open_flags>(b));
53}
54
55inline void operator|=(open_flags& a, open_flags b) {
56 a = (a | b);
57}
58
59inline open_flags operator&(open_flags a, open_flags b) {
60 return open_flags(std::underlying_type_t<open_flags>(a) & std::underlying_type_t<open_flags>(b));
61}
62
63inline void operator&=(open_flags& a, open_flags b) {
64 a = (a & b);
65}
66
71 unknown,
72 block_device,
73 char_device,
74 directory,
75 fifo,
76 link,
77 regular,
78 socket,
79};
80
81namespace internal::linux_abi {
82
83// From getdents(2):
84// check for 64-bit inode number
85static_assert(sizeof(ino_t) == 8, "large file support not enabled");
86static_assert(sizeof(off_t) == 8, "large file support not enabled");
87
88// From getdents(2):
89struct linux_dirent64 {
90 ino_t d_ino; /* 64-bit inode number */
91 off_t d_off; /* 64-bit offset to next structure */
92 unsigned short d_reclen; /* Size of this dirent */
93 unsigned char d_type; /* File type */
94 char d_name[]; /* Filename (null-terminated) */
95};
96
97} // internal::linux_abi namespace
98
100enum class fs_type {
101 other,
102 xfs,
103 ext2,
104 ext3,
105 ext4,
106 btrfs,
107 hfs,
108 tmpfs,
109};
110
111// Access flags for files/directories
112enum class access_flags {
113 exists = F_OK,
114 read = R_OK,
115 write = W_OK,
116 execute = X_OK,
117
118 // alias for directory access
119 lookup = execute,
120};
121
122inline access_flags operator|(access_flags a, access_flags b) {
123 return access_flags(std::underlying_type_t<access_flags>(a) | std::underlying_type_t<access_flags>(b));
124}
125
126inline access_flags operator&(access_flags a, access_flags b) {
127 return access_flags(std::underlying_type_t<access_flags>(a) & std::underlying_type_t<access_flags>(b));
128}
129
130// Permissions for files/directories
131enum class file_permissions {
132 user_read = S_IRUSR, // Read by owner
133 user_write = S_IWUSR, // Write by owner
134 user_execute = S_IXUSR, // Execute by owner
135
136 group_read = S_IRGRP, // Read by group
137 group_write = S_IWGRP, // Write by group
138 group_execute = S_IXGRP, // Execute by group
139
140 others_read = S_IROTH, // Read by others
141 others_write = S_IWOTH, // Write by others
142 others_execute = S_IXOTH, // Execute by others
143
144 user_permissions = user_read | user_write | user_execute,
145 group_permissions = group_read | group_write | group_execute,
146 others_permissions = others_read | others_write | others_execute,
147 all_permissions = user_permissions | group_permissions | others_permissions,
148
149 default_file_permissions = user_read | user_write | group_read | group_write | others_read | others_write, // 0666
150 default_dir_permissions = all_permissions, // 0777
151};
152
153inline constexpr file_permissions operator|(file_permissions a, file_permissions b) {
154 return file_permissions(std::underlying_type_t<file_permissions>(a) | std::underlying_type_t<file_permissions>(b));
155}
156
157inline constexpr file_permissions operator&(file_permissions a, file_permissions b) {
158 return file_permissions(std::underlying_type_t<file_permissions>(a) & std::underlying_type_t<file_permissions>(b));
159}
160
162
163SEASTAR_MODULE_EXPORT_END
164
165} // namespace seastar
Definition: api.hh:283
directory_entry_type
Definition: file-types.hh:70
fs_type
Enumeration describing the type of a particular filesystem.
Definition: file-types.hh:100
open_flags
Definition: file-types.hh:41
Seastar API namespace.
Definition: abort_on_ebadf.hh:26