blob: 9b63f5416a2f057d1dd7000b41d43e1b56e32b49 [file] [log] [blame]
Theodore Ts'of5166762017-12-17 22:00:59 -05001// SPDX-License-Identifier: GPL-2.0
Dave Kleikampac27a0e2006-10-11 01:20:50 -07002/*
Mingming Cao617ba132006-10-11 01:20:53 -07003 File: fs/ext4/acl.h
Dave Kleikampac27a0e2006-10-11 01:20:50 -07004
5 (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
6*/
7
8#include <linux/posix_acl_xattr.h>
9
Mingming Cao617ba132006-10-11 01:20:53 -070010#define EXT4_ACL_VERSION 0x0001
Dave Kleikampac27a0e2006-10-11 01:20:50 -070011
12typedef struct {
13 __le16 e_tag;
14 __le16 e_perm;
15 __le32 e_id;
Mingming Cao617ba132006-10-11 01:20:53 -070016} ext4_acl_entry;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070017
18typedef struct {
19 __le16 e_tag;
20 __le16 e_perm;
Mingming Cao617ba132006-10-11 01:20:53 -070021} ext4_acl_entry_short;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070022
23typedef struct {
24 __le32 a_version;
Mingming Cao617ba132006-10-11 01:20:53 -070025} ext4_acl_header;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070026
Mingming Cao617ba132006-10-11 01:20:53 -070027static inline size_t ext4_acl_size(int count)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070028{
29 if (count <= 4) {
Mingming Cao617ba132006-10-11 01:20:53 -070030 return sizeof(ext4_acl_header) +
31 count * sizeof(ext4_acl_entry_short);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070032 } else {
Mingming Cao617ba132006-10-11 01:20:53 -070033 return sizeof(ext4_acl_header) +
34 4 * sizeof(ext4_acl_entry_short) +
35 (count - 4) * sizeof(ext4_acl_entry);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070036 }
37}
38
Mingming Cao617ba132006-10-11 01:20:53 -070039static inline int ext4_acl_count(size_t size)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070040{
41 ssize_t s;
Mingming Cao617ba132006-10-11 01:20:53 -070042 size -= sizeof(ext4_acl_header);
43 s = size - 4 * sizeof(ext4_acl_entry_short);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070044 if (s < 0) {
Mingming Cao617ba132006-10-11 01:20:53 -070045 if (size % sizeof(ext4_acl_entry_short))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070046 return -1;
Mingming Cao617ba132006-10-11 01:20:53 -070047 return size / sizeof(ext4_acl_entry_short);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070048 } else {
Mingming Cao617ba132006-10-11 01:20:53 -070049 if (s % sizeof(ext4_acl_entry))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070050 return -1;
Mingming Cao617ba132006-10-11 01:20:53 -070051 return s / sizeof(ext4_acl_entry) + 4;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070052 }
53}
54
Theodore Ts'o03010a32008-10-10 20:02:48 -040055#ifdef CONFIG_EXT4_FS_POSIX_ACL
Dave Kleikampac27a0e2006-10-11 01:20:50 -070056
Dave Kleikampac27a0e2006-10-11 01:20:50 -070057/* acl.c */
Christoph Hellwig4e34e712011-07-23 17:37:31 +020058struct posix_acl *ext4_get_acl(struct inode *inode, int type);
Christoph Hellwig64e178a2013-12-20 05:16:44 -080059int ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type);
Theodore Ts'oaf5bc922008-09-08 22:25:24 -040060extern int ext4_init_acl(handle_t *, struct inode *, struct inode *);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070061
Theodore Ts'o03010a32008-10-10 20:02:48 -040062#else /* CONFIG_EXT4_FS_POSIX_ACL */
Dave Kleikampac27a0e2006-10-11 01:20:50 -070063#include <linux/sched.h>
Christoph Hellwig4e34e712011-07-23 17:37:31 +020064#define ext4_get_acl NULL
Christoph Hellwig64e178a2013-12-20 05:16:44 -080065#define ext4_set_acl NULL
Dave Kleikampac27a0e2006-10-11 01:20:50 -070066
67static inline int
Mingming Cao617ba132006-10-11 01:20:53 -070068ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070069{
70 return 0;
71}
Theodore Ts'o03010a32008-10-10 20:02:48 -040072#endif /* CONFIG_EXT4_FS_POSIX_ACL */
Dave Kleikampac27a0e2006-10-11 01:20:50 -070073