aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorYan <yanzheng@21cn.com>2008-01-14 13:26:08 -0500
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:59 -0400
commitfdebe2bd70047e057827cba85ba31b2545e31900 (patch)
tree7daee1b3fc0060d4ae84925a6f8358b4ff95d7b4 /fs
parent744f52f997b21de2a01931f79cf6c198bf688120 (diff)
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: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.h6
-rw-r--r--fs/btrfs/inode.c16
2 files changed, 15 insertions, 7 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0c0edacbc14c..245952cf7650 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -451,9 +451,9 @@ struct btrfs_root {
451/* 451/*
452 * Inode flags 452 * Inode flags
453 */ 453 */
454#define BTRFS_INODE_NODATASUM 0x1 454#define BTRFS_INODE_NODATASUM (1 << 0)
455#define BTRFS_INODE_NODATACOW 0x2 455#define BTRFS_INODE_NODATACOW (1 << 1)
456 456#define BTRFS_INODE_READONLY (1 << 2)
457#define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \ 457#define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
458 ~BTRFS_INODE_##flag) 458 ~BTRFS_INODE_##flag)
459#define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \ 459#define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index fba0478a95f4..fd0e0d80333b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2850,6 +2850,13 @@ out_fail:
2850 btrfs_throttle(root); 2850 btrfs_throttle(root);
2851 return err; 2851 return err;
2852} 2852}
2853static int btrfs_permission(struct inode *inode, int mask,
2854 struct nameidata *nd)
2855{
2856 if (btrfs_test_flag(inode, READONLY) && (mask & MAY_WRITE))
2857 return -EACCES;
2858 return generic_permission(inode, mask, NULL);
2859}
2853 2860
2854static struct inode_operations btrfs_dir_inode_operations = { 2861static struct inode_operations btrfs_dir_inode_operations = {
2855 .lookup = btrfs_lookup, 2862 .lookup = btrfs_lookup,
@@ -2866,12 +2873,12 @@ static struct inode_operations btrfs_dir_inode_operations = {
2866 .getxattr = generic_getxattr, 2873 .getxattr = generic_getxattr,
2867 .listxattr = btrfs_listxattr, 2874 .listxattr = btrfs_listxattr,
2868 .removexattr = generic_removexattr, 2875 .removexattr = generic_removexattr,
2876 .permission = btrfs_permission,
2869}; 2877};
2870
2871static struct inode_operations btrfs_dir_ro_inode_operations = { 2878static struct inode_operations btrfs_dir_ro_inode_operations = {
2872 .lookup = btrfs_lookup, 2879 .lookup = btrfs_lookup,
2880 .permission = btrfs_permission,
2873}; 2881};
2874
2875static struct file_operations btrfs_dir_file_operations = { 2882static struct file_operations btrfs_dir_file_operations = {
2876 .llseek = generic_file_llseek, 2883 .llseek = generic_file_llseek,
2877 .read = generic_read_dir, 2884 .read = generic_read_dir,
@@ -2916,15 +2923,16 @@ static struct inode_operations btrfs_file_inode_operations = {
2916 .getxattr = generic_getxattr, 2923 .getxattr = generic_getxattr,
2917 .listxattr = btrfs_listxattr, 2924 .listxattr = btrfs_listxattr,
2918 .removexattr = generic_removexattr, 2925 .removexattr = generic_removexattr,
2926 .permission = btrfs_permission,
2919}; 2927};
2920
2921static struct inode_operations btrfs_special_inode_operations = { 2928static struct inode_operations btrfs_special_inode_operations = {
2922 .getattr = btrfs_getattr, 2929 .getattr = btrfs_getattr,
2923 .setattr = btrfs_setattr, 2930 .setattr = btrfs_setattr,
2931 .permission = btrfs_permission,
2924}; 2932};
2925
2926static struct inode_operations btrfs_symlink_inode_operations = { 2933static struct inode_operations btrfs_symlink_inode_operations = {
2927 .readlink = generic_readlink, 2934 .readlink = generic_readlink,
2928 .follow_link = page_follow_link_light, 2935 .follow_link = page_follow_link_light,
2929 .put_link = page_put_link, 2936 .put_link = page_put_link,
2937 .permission = btrfs_permission,
2930}; 2938};