blob: cd2b855a07d669988f817f6e7415088b8dcefed6 [file] [log] [blame]
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001/*
Mingming Cao617ba132006-10-11 01:20:53 -07002 File: fs/ext4/acl.h
Dave Kleikampac27a0e2006-10-11 01:20:50 -07003
4 (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5*/
6
7#include <linux/posix_acl_xattr.h>
8
Mingming Cao617ba132006-10-11 01:20:53 -07009#define EXT4_ACL_VERSION 0x0001
Dave Kleikampac27a0e2006-10-11 01:20:50 -070010
11typedef struct {
12 __le16 e_tag;
13 __le16 e_perm;
14 __le32 e_id;
Mingming Cao617ba132006-10-11 01:20:53 -070015} ext4_acl_entry;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070016
17typedef struct {
18 __le16 e_tag;
19 __le16 e_perm;
Mingming Cao617ba132006-10-11 01:20:53 -070020} ext4_acl_entry_short;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070021
22typedef struct {
23 __le32 a_version;
Mingming Cao617ba132006-10-11 01:20:53 -070024} ext4_acl_header;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070025
Mingming Cao617ba132006-10-11 01:20:53 -070026static inline size_t ext4_acl_size(int count)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070027{
28 if (count <= 4) {
Mingming Cao617ba132006-10-11 01:20:53 -070029 return sizeof(ext4_acl_header) +
30 count * sizeof(ext4_acl_entry_short);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070031 } else {
Mingming Cao617ba132006-10-11 01:20:53 -070032 return sizeof(ext4_acl_header) +
33 4 * sizeof(ext4_acl_entry_short) +
34 (count - 4) * sizeof(ext4_acl_entry);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070035 }
36}
37
Mingming Cao617ba132006-10-11 01:20:53 -070038static inline int ext4_acl_count(size_t size)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070039{
40 ssize_t s;
Mingming Cao617ba132006-10-11 01:20:53 -070041 size -= sizeof(ext4_acl_header);
42 s = size - 4 * sizeof(ext4_acl_entry_short);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070043 if (s < 0) {
Mingming Cao617ba132006-10-11 01:20:53 -070044 if (size % sizeof(ext4_acl_entry_short))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070045 return -1;
Mingming Cao617ba132006-10-11 01:20:53 -070046 return size / sizeof(ext4_acl_entry_short);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070047 } else {
Mingming Cao617ba132006-10-11 01:20:53 -070048 if (s % sizeof(ext4_acl_entry))
Dave Kleikampac27a0e2006-10-11 01:20:50 -070049 return -1;
Mingming Cao617ba132006-10-11 01:20:53 -070050 return s / sizeof(ext4_acl_entry) + 4;
Dave Kleikampac27a0e2006-10-11 01:20:50 -070051 }
52}
53
Mingming Cao617ba132006-10-11 01:20:53 -070054#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
Dave Kleikampac27a0e2006-10-11 01:20:50 -070055
Mingming Cao617ba132006-10-11 01:20:53 -070056/* Value for inode->u.ext4_i.i_acl and inode->u.ext4_i.i_default_acl
Dave Kleikampac27a0e2006-10-11 01:20:50 -070057 if the ACL has not been cached */
Mingming Cao617ba132006-10-11 01:20:53 -070058#define EXT4_ACL_NOT_CACHED ((void *)-1)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070059
60/* acl.c */
Al Viroe6305c42008-07-15 21:03:57 -040061extern int ext4_permission (struct inode *, int);
Mingming Cao617ba132006-10-11 01:20:53 -070062extern int ext4_acl_chmod (struct inode *);
63extern int ext4_init_acl (handle_t *, struct inode *, struct inode *);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070064
Mingming Cao617ba132006-10-11 01:20:53 -070065#else /* CONFIG_EXT4DEV_FS_POSIX_ACL */
Dave Kleikampac27a0e2006-10-11 01:20:50 -070066#include <linux/sched.h>
Mingming Cao617ba132006-10-11 01:20:53 -070067#define ext4_permission NULL
Dave Kleikampac27a0e2006-10-11 01:20:50 -070068
69static inline int
Mingming Cao617ba132006-10-11 01:20:53 -070070ext4_acl_chmod(struct inode *inode)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070071{
72 return 0;
73}
74
75static inline int
Mingming Cao617ba132006-10-11 01:20:53 -070076ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070077{
78 return 0;
79}
Mingming Cao617ba132006-10-11 01:20:53 -070080#endif /* CONFIG_EXT4DEV_FS_POSIX_ACL */
Dave Kleikampac27a0e2006-10-11 01:20:50 -070081