summaryrefslogtreecommitdiff
path: root/inode.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2016-08-19 16:13:05 +0800
committerDavid Sterba <dsterba@suse.com>2016-08-19 13:52:43 +0200
commitbdadea75e47f21682b745678c9b685e491c5e8a3 (patch)
tree8bd80719e08007a1e44793ea1968392944194b5e /inode.c
parent55aa862ea21c733cbc0444955006856321e9e957 (diff)
btrfs-progs: convert: Fix a regression that ext2_save/image is not readonly
The new convert treats the convert image as a normal file, without any special flags and permissions. This is different from original code: 1) Permission changed from 0400 to 0600 2) Inode lacks READONLY flag This makes we can read-write mount the ext2 image and cause rollback failure. Follow old code behavior, use 0400 permission and add back READONLY flag to fix it. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'inode.c')
-rw-r--r--inode.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/inode.c b/inode.c
index ed6d5292..991b8ddb 100644
--- a/inode.c
+++ b/inode.c
@@ -472,6 +472,42 @@ int btrfs_new_inode(struct btrfs_trans_handle *trans, struct btrfs_root *root,
}
/*
+ * Change inode flags to given value
+ */
+int btrfs_change_inode_flags(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root, u64 ino, u64 flags)
+{
+ struct btrfs_inode_item *item;
+ struct btrfs_path *path;
+ struct btrfs_key key;
+ int ret;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ key.objectid = ino;
+ key.type = BTRFS_INODE_ITEM_KEY;
+ key.offset = 0;
+
+ ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
+ if (ret > 0) {
+ ret = -ENOENT;
+ goto out;
+ }
+ if (ret < 0)
+ goto out;
+
+ item = btrfs_item_ptr(path->nodes[0], path->slots[0],
+ struct btrfs_inode_item);
+ btrfs_set_inode_flags(path->nodes[0], item, flags);
+ btrfs_mark_buffer_dirty(path->nodes[0]);
+out:
+ btrfs_free_path(path);
+ return ret;
+}
+
+/*
* Make a dir under the parent inode 'parent_ino' with 'name'
* and 'mode', The owner will be root/root.
*/