50
49
#include "volumes.h"
51
50
#include "locking.h"
52
/* Mask out flags that are inappropriate for the given type of inode. */
53
static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
57
else if (S_ISREG(mode))
58
return flags & ~FS_DIRSYNC_FL;
60
return flags & (FS_NODUMP_FL | FS_NOATIME_FL);
64
* Export inode flags to the format expected by the FS_IOC_GETFLAGS ioctl.
66
static unsigned int btrfs_flags_to_ioctl(unsigned int flags)
68
unsigned int iflags = 0;
70
if (flags & BTRFS_INODE_SYNC)
72
if (flags & BTRFS_INODE_IMMUTABLE)
73
iflags |= FS_IMMUTABLE_FL;
74
if (flags & BTRFS_INODE_APPEND)
75
iflags |= FS_APPEND_FL;
76
if (flags & BTRFS_INODE_NODUMP)
77
iflags |= FS_NODUMP_FL;
78
if (flags & BTRFS_INODE_NOATIME)
79
iflags |= FS_NOATIME_FL;
80
if (flags & BTRFS_INODE_DIRSYNC)
81
iflags |= FS_DIRSYNC_FL;
87
* Update inode->i_flags based on the btrfs internal flags.
89
void btrfs_update_iflags(struct inode *inode)
91
struct btrfs_inode *ip = BTRFS_I(inode);
93
inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
95
if (ip->flags & BTRFS_INODE_SYNC)
96
inode->i_flags |= S_SYNC;
97
if (ip->flags & BTRFS_INODE_IMMUTABLE)
98
inode->i_flags |= S_IMMUTABLE;
99
if (ip->flags & BTRFS_INODE_APPEND)
100
inode->i_flags |= S_APPEND;
101
if (ip->flags & BTRFS_INODE_NOATIME)
102
inode->i_flags |= S_NOATIME;
103
if (ip->flags & BTRFS_INODE_DIRSYNC)
104
inode->i_flags |= S_DIRSYNC;
108
* Inherit flags from the parent inode.
110
* Unlike extN we don't have any flags we don't want to inherit currently.
112
void btrfs_inherit_iflags(struct inode *inode, struct inode *dir)
119
flags = BTRFS_I(dir)->flags;
121
if (S_ISREG(inode->i_mode))
122
flags &= ~BTRFS_INODE_DIRSYNC;
123
else if (!S_ISDIR(inode->i_mode))
124
flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
126
BTRFS_I(inode)->flags = flags;
127
btrfs_update_iflags(inode);
130
static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
132
struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
133
unsigned int flags = btrfs_flags_to_ioctl(ip->flags);
135
if (copy_to_user(arg, &flags, sizeof(flags)))
140
static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
142
struct inode *inode = file->f_path.dentry->d_inode;
143
struct btrfs_inode *ip = BTRFS_I(inode);
144
struct btrfs_root *root = ip->root;
145
struct btrfs_trans_handle *trans;
146
unsigned int flags, oldflags;
149
if (copy_from_user(&flags, arg, sizeof(flags)))
152
if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
153
FS_NOATIME_FL | FS_NODUMP_FL | \
154
FS_SYNC_FL | FS_DIRSYNC_FL))
157
if (!is_owner_or_cap(inode))
160
mutex_lock(&inode->i_mutex);
162
flags = btrfs_mask_flags(inode->i_mode, flags);
163
oldflags = btrfs_flags_to_ioctl(ip->flags);
164
if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
165
if (!capable(CAP_LINUX_IMMUTABLE)) {
171
ret = mnt_want_write(file->f_path.mnt);
175
if (flags & FS_SYNC_FL)
176
ip->flags |= BTRFS_INODE_SYNC;
178
ip->flags &= ~BTRFS_INODE_SYNC;
179
if (flags & FS_IMMUTABLE_FL)
180
ip->flags |= BTRFS_INODE_IMMUTABLE;
182
ip->flags &= ~BTRFS_INODE_IMMUTABLE;
183
if (flags & FS_APPEND_FL)
184
ip->flags |= BTRFS_INODE_APPEND;
186
ip->flags &= ~BTRFS_INODE_APPEND;
187
if (flags & FS_NODUMP_FL)
188
ip->flags |= BTRFS_INODE_NODUMP;
190
ip->flags &= ~BTRFS_INODE_NODUMP;
191
if (flags & FS_NOATIME_FL)
192
ip->flags |= BTRFS_INODE_NOATIME;
194
ip->flags &= ~BTRFS_INODE_NOATIME;
195
if (flags & FS_DIRSYNC_FL)
196
ip->flags |= BTRFS_INODE_DIRSYNC;
198
ip->flags &= ~BTRFS_INODE_DIRSYNC;
201
trans = btrfs_join_transaction(root, 1);
204
ret = btrfs_update_inode(trans, root, inode);
207
btrfs_update_iflags(inode);
208
inode->i_ctime = CURRENT_TIME;
209
btrfs_end_transaction(trans, root);
211
mnt_drop_write(file->f_path.mnt);
213
mutex_unlock(&inode->i_mutex);
217
static int btrfs_ioctl_getversion(struct file *file, int __user *arg)
219
struct inode *inode = file->f_path.dentry->d_inode;
221
return put_user(inode->i_generation, arg);
55
224
static noinline int create_subvol(struct btrfs_root *root,
56
225
struct dentry *dentry,
85
leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0,
86
objectid, trans->transid, 0, 0, 0);
254
leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
255
0, objectid, NULL, 0, 0, 0);
87
256
if (IS_ERR(leaf)) {
88
257
ret = PTR_ERR(leaf);
92
btrfs_set_header_nritems(leaf, 0);
93
btrfs_set_header_level(leaf, 0);
261
memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header));
94
262
btrfs_set_header_bytenr(leaf, leaf->start);
95
263
btrfs_set_header_generation(leaf, trans->transid);
264
btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV);
96
265
btrfs_set_header_owner(leaf, objectid);
98
267
write_extent_buffer(leaf, root->fs_info->fsid,
99
268
(unsigned long)btrfs_header_fsid(leaf),
100
269
BTRFS_FSID_SIZE);
270
write_extent_buffer(leaf, root->fs_info->chunk_tree_uuid,
271
(unsigned long)btrfs_header_chunk_tree_uuid(leaf),
101
273
btrfs_mark_buffer_dirty(leaf);
103
275
inode_item = &root_item.inode;