^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) File: fs/ext4/acl.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define EXT4_ACL_VERSION 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) __le16 e_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) __le16 e_perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) __le32 e_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) } ext4_acl_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) __le16 e_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) __le16 e_perm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) } ext4_acl_entry_short;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) __le32 a_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) } ext4_acl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static inline size_t ext4_acl_size(int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (count <= 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return sizeof(ext4_acl_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) count * sizeof(ext4_acl_entry_short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return sizeof(ext4_acl_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 4 * sizeof(ext4_acl_entry_short) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) (count - 4) * sizeof(ext4_acl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static inline int ext4_acl_count(size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ssize_t s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) size -= sizeof(ext4_acl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) s = size - 4 * sizeof(ext4_acl_entry_short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (s < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (size % sizeof(ext4_acl_entry_short))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return size / sizeof(ext4_acl_entry_short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (s % sizeof(ext4_acl_entry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return s / sizeof(ext4_acl_entry) + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifdef CONFIG_EXT4_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* acl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct posix_acl *ext4_get_acl(struct inode *inode, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) extern int ext4_init_acl(handle_t *, struct inode *, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #else /* CONFIG_EXT4_FS_POSIX_ACL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define ext4_get_acl NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define ext4_set_acl NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #endif /* CONFIG_EXT4_FS_POSIX_ACL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)