Commit fdebe2bd authored by Yan's avatar Yan Committed by Chris Mason

Btrfs: Add readonly inode flag

This patch adds readonly inode flag support.  A file with this flag
can't be modified, but can be deleted.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 744f52f9
...@@ -451,9 +451,9 @@ struct btrfs_root { ...@@ -451,9 +451,9 @@ struct btrfs_root {
/* /*
* Inode flags * Inode flags
*/ */
#define BTRFS_INODE_NODATASUM 0x1 #define BTRFS_INODE_NODATASUM (1 << 0)
#define BTRFS_INODE_NODATACOW 0x2 #define BTRFS_INODE_NODATACOW (1 << 1)
#define BTRFS_INODE_READONLY (1 << 2)
#define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \ #define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
~BTRFS_INODE_##flag) ~BTRFS_INODE_##flag)
#define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \ #define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
......
...@@ -2850,6 +2850,13 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -2850,6 +2850,13 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
btrfs_throttle(root); btrfs_throttle(root);
return err; return err;
} }
static int btrfs_permission(struct inode *inode, int mask,
struct nameidata *nd)
{
if (btrfs_test_flag(inode, READONLY) && (mask & MAY_WRITE))
return -EACCES;
return generic_permission(inode, mask, NULL);
}
static struct inode_operations btrfs_dir_inode_operations = { static struct inode_operations btrfs_dir_inode_operations = {
.lookup = btrfs_lookup, .lookup = btrfs_lookup,
...@@ -2866,12 +2873,12 @@ static struct inode_operations btrfs_dir_inode_operations = { ...@@ -2866,12 +2873,12 @@ static struct inode_operations btrfs_dir_inode_operations = {
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = btrfs_listxattr, .listxattr = btrfs_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
.permission = btrfs_permission,
}; };
static struct inode_operations btrfs_dir_ro_inode_operations = { static struct inode_operations btrfs_dir_ro_inode_operations = {
.lookup = btrfs_lookup, .lookup = btrfs_lookup,
.permission = btrfs_permission,
}; };
static struct file_operations btrfs_dir_file_operations = { static struct file_operations btrfs_dir_file_operations = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read = generic_read_dir, .read = generic_read_dir,
...@@ -2916,15 +2923,16 @@ static struct inode_operations btrfs_file_inode_operations = { ...@@ -2916,15 +2923,16 @@ static struct inode_operations btrfs_file_inode_operations = {
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = btrfs_listxattr, .listxattr = btrfs_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
.permission = btrfs_permission,
}; };
static struct inode_operations btrfs_special_inode_operations = { static struct inode_operations btrfs_special_inode_operations = {
.getattr = btrfs_getattr, .getattr = btrfs_getattr,
.setattr = btrfs_setattr, .setattr = btrfs_setattr,
.permission = btrfs_permission,
}; };
static struct inode_operations btrfs_symlink_inode_operations = { static struct inode_operations btrfs_symlink_inode_operations = {
.readlink = generic_readlink, .readlink = generic_readlink,
.follow_link = page_follow_link_light, .follow_link = page_follow_link_light,
.put_link = page_put_link, .put_link = page_put_link,
.permission = btrfs_permission,
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment