1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 #include "missing_fs.h"
11 /* The chattr() flags to apply when creating a new file *before* writing to it. In particular, flags such as
12 * FS_NOCOW_FL don't work if applied a-posteriori. All other flags are fine (or even necessary, think
13 * FS_IMMUTABLE_FL!) to apply after writing to the files. */
14 #define CHATTR_EARLY_FL \
21 #define CHATTR_ALL_FL \
30 FS_JOURNAL_DATA_FL | \
38 typedef enum ChattrApplyFlags
{
39 CHATTR_FALLBACK_BITWISE
= 1 << 0,
40 CHATTR_WARN_UNSUPPORTED_FLAGS
= 1 << 1,
43 int chattr_full(int dir_fd
, const char *path
, unsigned value
, unsigned mask
, unsigned *ret_previous
, unsigned *ret_final
, ChattrApplyFlags flags
);
44 static inline int chattr_at(int dir_fd
, const char *path
, unsigned value
, unsigned mask
, unsigned *previous
) {
45 return chattr_full(dir_fd
, path
, value
, mask
, previous
, NULL
, 0);
47 static inline int chattr_fd(int fd
, unsigned value
, unsigned mask
, unsigned *previous
) {
48 return chattr_full(fd
, NULL
, value
, mask
, previous
, NULL
, 0);
50 static inline int chattr_path(const char *path
, unsigned value
, unsigned mask
, unsigned *previous
) {
51 return chattr_full(AT_FDCWD
, path
, value
, mask
, previous
, NULL
, 0);
54 int read_attr_fd(int fd
, unsigned *ret
);
55 int read_attr_at(int dir_fd
, const char *path
, unsigned *ret
);
57 /* Combination of chattr flags, that should be appropriate for secrets stored on disk: Secure Remove +
58 * Exclusion from Dumping + Synchronous Writing (i.e. not caching in memory) + In-Place Updating (i.e. not
59 * spurious copies). */
60 #define CHATTR_SECRET_FLAGS (FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL)
62 static inline int chattr_secret(int fd
, ChattrApplyFlags flags
) {
63 return chattr_full(fd
, NULL
, CHATTR_SECRET_FLAGS
, CHATTR_SECRET_FLAGS
, NULL
, NULL
, flags
|CHATTR_FALLBACK_BITWISE
);