blob: 0c1c847f992f7d154be29a5ce733cdc16dedd1e0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/init.h>
3#include <linux/posix_acl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5#define REISERFS_ACL_VERSION 0x0001
6
7typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07008 __le16 e_tag;
9 __le16 e_perm;
10 __le32 e_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011} reiserfs_acl_entry;
12
13typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070014 __le16 e_tag;
15 __le16 e_perm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016} reiserfs_acl_entry_short;
17
18typedef struct {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070019 __le32 a_version;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020} reiserfs_acl_header;
21
22static inline size_t reiserfs_acl_size(int count)
23{
24 if (count <= 4) {
25 return sizeof(reiserfs_acl_header) +
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070026 count * sizeof(reiserfs_acl_entry_short);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 } else {
28 return sizeof(reiserfs_acl_header) +
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070029 4 * sizeof(reiserfs_acl_entry_short) +
30 (count - 4) * sizeof(reiserfs_acl_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 }
32}
33
34static inline int reiserfs_acl_count(size_t size)
35{
36 ssize_t s;
37 size -= sizeof(reiserfs_acl_header);
38 s = size - 4 * sizeof(reiserfs_acl_entry_short);
39 if (s < 0) {
40 if (size % sizeof(reiserfs_acl_entry_short))
41 return -1;
42 return size / sizeof(reiserfs_acl_entry_short);
43 } else {
44 if (s % sizeof(reiserfs_acl_entry))
45 return -1;
46 return s / sizeof(reiserfs_acl_entry) + 4;
47 }
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#ifdef CONFIG_REISERFS_FS_POSIX_ACL
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070051struct posix_acl *reiserfs_get_acl(struct inode *inode, int type);
Christoph Hellwig47f70d02013-12-20 05:16:49 -080052int reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070053int reiserfs_acl_chmod(struct inode *inode);
Jeff Mahoney0ab26212009-03-30 14:02:39 -040054int reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
55 struct inode *dir, struct dentry *dentry,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070056 struct inode *inode);
57int reiserfs_cache_default_acl(struct inode *dir);
Alexey Dobriyancfe14672006-09-29 02:00:00 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#else
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define reiserfs_cache_default_acl(inode) 0
Christoph Hellwig4e34e712011-07-23 17:37:31 +020062#define reiserfs_get_acl NULL
Christoph Hellwig47f70d02013-12-20 05:16:49 -080063#define reiserfs_set_acl NULL
Andrew Mortonbc5e4832006-02-04 23:27:51 -080064
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070065static inline int reiserfs_acl_chmod(struct inode *inode)
66{
67 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
70static inline int
Alexander Beregalov77e46582009-03-31 00:32:40 +040071reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
72 const struct inode *dir, struct dentry *dentry,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070073 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070075 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#endif