blob: d9052b8ce6dd9425e093938eff0ad6a487521dac [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
Miklos Szeredi0cad6242021-08-18 22:08:24 +020051struct posix_acl *reiserfs_get_acl(struct inode *inode, int type, bool rcu);
Christian Brauner549c7292021-01-21 14:19:43 +010052int reiserfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
53 struct posix_acl *acl, int type);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070054int reiserfs_acl_chmod(struct inode *inode);
Jeff Mahoney0ab26212009-03-30 14:02:39 -040055int reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
56 struct inode *dir, struct dentry *dentry,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070057 struct inode *inode);
58int reiserfs_cache_default_acl(struct inode *dir);
Alexey Dobriyancfe14672006-09-29 02:00:00 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#else
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define reiserfs_cache_default_acl(inode) 0
Christoph Hellwig4e34e712011-07-23 17:37:31 +020063#define reiserfs_get_acl NULL
Christoph Hellwig47f70d02013-12-20 05:16:49 -080064#define reiserfs_set_acl NULL
Andrew Mortonbc5e4832006-02-04 23:27:51 -080065
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070066static inline int reiserfs_acl_chmod(struct inode *inode)
67{
68 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71static inline int
Alexander Beregalov77e46582009-03-31 00:32:40 +040072reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
73 const struct inode *dir, struct dentry *dentry,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070074 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070076 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#endif