9 #include <linux/capability.h>
10 #include <linux/module.h>
13 #include <linux/time.h>
22 static int fat_ioctl_get_attributes(
struct inode *
inode,
u32 __user *user_attr)
27 attr = fat_make_attrs(inode);
33 static int fat_ioctl_set_attributes(
struct file *
file,
u32 __user *user_attr)
61 oldattr = fat_make_attrs(inode);
67 ia.ia_mode = fat_make_mode(sbi, attr,
S_IRWXUGO);
69 ia.ia_mode = fat_make_mode(sbi, attr,
76 goto out_unlock_inode;
79 if (sbi->
options.sys_immutable &&
83 goto out_unlock_inode;
93 goto out_unlock_inode;
98 goto out_unlock_inode;
100 fsnotify_change(file->
f_path.dentry, ia.ia_valid);
101 if (sbi->
options.sys_immutable) {
108 fat_save_attrs(inode, attr);
109 mark_inode_dirty(inode);
119 struct inode *inode = filp->
f_path.dentry->d_inode;
124 return fat_ioctl_get_attributes(inode, user_attr);
126 return fat_ioctl_set_attributes(filp, user_attr);
133 static long fat_generic_compat_ioctl(
struct file *filp,
unsigned int cmd,
141 static int fat_file_release(
struct inode *inode,
struct file *filp)
144 MSDOS_SB(inode->
i_sb)->options.flush) {
153 struct inode *inode = filp->
f_mapping->host;
159 return res ? res :
err;
170 .release = fat_file_release,
173 .compat_ioctl = fat_generic_compat_ioctl,
179 static int fat_cont_expand(
struct inode *inode, loff_t
size)
190 mark_inode_dirty(inode);
216 static int fat_free(
struct inode *inode,
int skip)
219 int err,
wait, free_start, i_start, i_logstart;
221 if (MSDOS_I(inode)->i_start == 0)
227 i_start = free_start = MSDOS_I(inode)->i_start;
228 i_logstart = MSDOS_I(inode)->i_logstart;
232 MSDOS_I(inode)->i_start = 0;
233 MSDOS_I(inode)->i_logstart = 0;
240 MSDOS_I(inode)->i_start = i_start;
241 MSDOS_I(inode)->i_logstart = i_logstart;
245 mark_inode_dirty(inode);
250 int ret, fclus, dclus;
258 fatent_init(&fatent);
261 fatent_brelse(&fatent);
265 "%s: invalid cluster chain (i_pos %lld)",
266 __func__, MSDOS_I(inode)->i_pos);
268 }
else if (ret > 0) {
273 fatent_brelse(&fatent);
279 inode->
i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
295 if (MSDOS_I(inode)->mmu_private > offset)
296 MSDOS_I(inode)->mmu_private =
offset;
298 nr_clusters = (offset + (cluster_size - 1)) >> sbi->
cluster_bits;
300 fat_free(inode, nr_clusters);
306 struct inode *inode = dentry->
d_inode;
308 stat->
blksize = MSDOS_SB(inode->
i_sb)->cluster_size;
313 static int fat_sanitize_mode(
const struct msdos_sb_info *sbi,
314 struct inode *inode,
umode_t *mode_ptr)
338 if (fat_mode_can_hold_ro(inode)) {
342 if ((perm & S_IWUGO) != (S_IWUGO & ~mask))
351 static int fat_allow_set_time(
struct msdos_sb_info *sbi,
struct inode *inode)
366 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
368 #define FAT_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXUGO)
373 struct inode *inode = dentry->
d_inode;
374 unsigned int ia_valid;
380 if (fat_allow_set_time(sbi, inode))
402 error = fat_cont_expand(inode, attr->
ia_size);
428 if (fat_sanitize_mode(sbi, inode, &attr->
ia_mode) < 0)
436 up_write(&MSDOS_I(inode)->truncate_lock);
440 mark_inode_dirty(inode);