Changes in 4.9.183 rapidio: fix a NULL pointer dereference when create_workqueue() fails fs/fat/file.c: issue flush after the writeback of FAT sysctl: return -EINVAL if val violates minmax ipc: prevent lockup on alloc_msg and free_msg ARM: prevent tracing IPI_CPU_BACKTRACE hugetlbfs: on restore reserve error path retain subpool reservation mem-hotplug: fix node spanned pages when we have a node with only ZONE_MOVABLE mm/cma.c: fix crash on CMA allocation if bitmap allocation fails mm/cma_debug.c: fix the break condition in cma_maxchunk_get() mm/slab.c: fix an infinite loop in leaks_show() kernel/sys.c: prctl: fix false positive in validate_prctl_map() drivers: thermal: tsens: Don't print error message on -EPROBE_DEFER mfd: tps65912-spi: Add missing of table registration mfd: intel-lpss: Set the device in reset state when init mfd: twl6040: Fix device init errors for ACCCTL register perf/x86/intel: Allow PEBS multi-entry in watermark mode drm/bridge: adv7511: Fix low refresh rate selection objtool: Don't use ignore flag for fake jumps pwm: meson: Use the spin-lock only to protect register modifications ntp: Allow TAI-UTC offset to be set to zero f2fs: fix to avoid panic in do_recover_data() f2fs: fix to clear dirty inode in error path of f2fs_iget() f2fs: fix to do sanity check on valid block count of segment configfs: fix possible use-after-free in configfs_register_group uml: fix a boot splat wrt use of cpu_all_mask watchdog: imx2_wdt: Fix set_timeout for big timeout values watchdog: fix compile time error of pretimeout governors iommu/vt-d: Set intel_iommu_gfx_mapped correctly ALSA: hda - Register irq handler after the chip initialization nvmem: core: fix read buffer in place fuse: retrieve: cap requested size to negotiated max_write nfsd: allow fh_want_write to be called twice x86/PCI: Fix PCI IRQ routing table memory leak platform/chrome: cros_ec_proto: check for NULL transfer function soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher clk: rockchip: Turn on "aclk_dmac1" for suspend on rk3288 ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ahb" clock to SDMA ARM: dts: imx7d: Specify IMX7D_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx6ul: Specify IMX6UL_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ipg" clock to SDMA ARM: dts: imx6qdl: Specify IMX6QDL_CLK_IPG as "ipg" clock to SDMA PCI: rpadlpar: Fix leaked device_node references in add/remove paths platform/x86: intel_pmc_ipc: adding error handling PCI: rcar: Fix a potential NULL pointer dereference PCI: rcar: Fix 64bit MSI message address handling video: hgafb: fix potential NULL pointer dereference video: imsttfb: fix potential NULL pointer dereferences PCI: xilinx: Check for __get_free_pages() failure gpio: gpio-omap: add check for off wake capable gpios dmaengine: idma64: Use actual device for DMA transfers pwm: tiehrpwm: Update shadow register for disabling PWMs ARM: dts: exynos: Always enable necessary APIO_1V8 and ABB_1V8 regulators on Arndale Octa pwm: Fix deadlock warning when removing PWM device ARM: exynos: Fix undefined instruction during Exynos5422 resume Revert "Bluetooth: Align minimum encryption key size for LE and BR/EDR connections" ALSA: seq: Cover unsubscribe_port() in list_mutex ALSA: oxfw: allow PCM capture for Stanton SCS.1m libata: Extend quirks for the ST1000LM024 drives with NOLPM quirk mm/list_lru.c: fix memory leak in __memcg_init_list_lru_node fs/ocfs2: fix race in ocfs2_dentry_attach_lock() signal/ptrace: Don't leak unitialized kernel memory with PTRACE_PEEK_SIGINFO ptrace: restore smp_rmb() in __ptrace_may_access() media: v4l2-ioctl: clear fields in s_parm i2c: acorn: fix i2c warning bcache: fix stack corruption by PRECEDING_KEY() cgroup: Use css_tryget() instead of css_tryget_online() in task_get_css() ASoC: cs42xx8: Add regcache mask dirty ASoC: fsl_asrc: Fix the issue about unsupported rate x86/uaccess, kcov: Disable stack protector ALSA: seq: Protect in-kernel ioctl calls with mutex ALSA: seq: Fix race of get-subscription call vs port-delete ioctls Revert "ALSA: seq: Protect in-kernel ioctl calls with mutex" Drivers: misc: fix out-of-bounds access in function param_set_kgdbts_var scsi: lpfc: add check for loss of ndlp when sending RRQ arm64/mm: Inhibit huge-vmap with ptdump scsi: bnx2fc: fix incorrect cast to u64 on shift operation selftests/timers: Add missing fflush(stdout) calls usbnet: ipheth: fix racing condition KVM: x86/pmu: do not mask the value that is written to fixed PMUs KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION drm/vmwgfx: integer underflow in vmw_cmd_dx_set_shader() leading to an invalid read drm/vmwgfx: NULL pointer dereference from vmw_cmd_dx_view_define() usb: dwc2: Fix DMA cache alignment issues USB: Fix chipmunk-like voice when using Logitech C270 for recording audio. USB: usb-storage: Add new ID to ums-realtek USB: serial: pl2303: add Allied Telesis VT-Kit3 USB: serial: option: add support for Simcom SIM7500/SIM7600 RNDIS mode USB: serial: option: add Telit 0x1260 and 0x1261 compositions rtc: pcf8523: don't return invalid date when battery is low ax25: fix inconsistent lock state in ax25_destroy_timer be2net: Fix number of Rx queues used for flow hashing ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero lapb: fixed leak of control-blocks. neigh: fix use-after-free read in pneigh_get_next sunhv: Fix device naming inconsistency between sunhv_console and sunhv_reg Revert "staging: vc04_services: prevent integer overflow in create_pagelist()" perf/x86/intel/ds: Fix EVENT vs. UEVENT PEBS constraints selftests: netfilter: missing error check when setting up veth interface mISDN: make sure device name is NUL terminated x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor perf/ring_buffer: Fix exposing a temporarily decreased data_head perf/ring_buffer: Add ordering to rb->nest increment gpio: fix gpio-adp5588 build errors net: tulip: de4x5: Drop redundant MODULE_DEVICE_TABLE() i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr configfs: Fix use-after-free when accessing sd->s_dentry perf data: Fix 'strncat may truncate' build failure with recent gcc perf record: Fix s390 missing module symbol and warning for non-root users ia64: fix build errors by exporting paddr_to_nid() KVM: PPC: Book3S: Use new mutex to synchronize access to rtas token list KVM: PPC: Book3S HV: Don't take kvm->lock around kvm_for_each_vcpu net: sh_eth: fix mdio access in sh_eth_close() for R-Car Gen2 and RZ/A1 SoCs scsi: libcxgbi: add a check for NULL pointer in cxgbi_check_route() scsi: smartpqi: properly set both the DMA mask and the coherent DMA mask scsi: libsas: delete sas port if expander discover failed mlxsw: spectrum: Prevent force of 56G Abort file_remove_privs() for non-reg. files Linux 4.9.183 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
527 lines
13 KiB
C
527 lines
13 KiB
C
/*
|
|
* linux/fs/fat/file.c
|
|
*
|
|
* Written 1992,1993 by Werner Almesberger
|
|
*
|
|
* regular file handling primitives for fat-based filesystems
|
|
*/
|
|
|
|
#include <linux/capability.h>
|
|
#include <linux/module.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/backing-dev.h>
|
|
#include <linux/fsnotify.h>
|
|
#include <linux/security.h>
|
|
#include <linux/falloc.h>
|
|
#include "fat.h"
|
|
|
|
static long fat_fallocate(struct file *file, int mode,
|
|
loff_t offset, loff_t len);
|
|
|
|
static int fat_ioctl_get_attributes(struct inode *inode, u32 __user *user_attr)
|
|
{
|
|
u32 attr;
|
|
|
|
inode_lock(inode);
|
|
attr = fat_make_attrs(inode);
|
|
inode_unlock(inode);
|
|
|
|
return put_user(attr, user_attr);
|
|
}
|
|
|
|
static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
|
|
{
|
|
struct inode *inode = file_inode(file);
|
|
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
|
|
int is_dir = S_ISDIR(inode->i_mode);
|
|
u32 attr, oldattr;
|
|
struct iattr ia;
|
|
int err;
|
|
|
|
err = get_user(attr, user_attr);
|
|
if (err)
|
|
goto out;
|
|
|
|
err = mnt_want_write_file(file);
|
|
if (err)
|
|
goto out;
|
|
inode_lock(inode);
|
|
|
|
/*
|
|
* ATTR_VOLUME and ATTR_DIR cannot be changed; this also
|
|
* prevents the user from turning us into a VFAT
|
|
* longname entry. Also, we obviously can't set
|
|
* any of the NTFS attributes in the high 24 bits.
|
|
*/
|
|
attr &= 0xff & ~(ATTR_VOLUME | ATTR_DIR);
|
|
/* Merge in ATTR_VOLUME and ATTR_DIR */
|
|
attr |= (MSDOS_I(inode)->i_attrs & ATTR_VOLUME) |
|
|
(is_dir ? ATTR_DIR : 0);
|
|
oldattr = fat_make_attrs(inode);
|
|
|
|
/* Equivalent to a chmod() */
|
|
ia.ia_valid = ATTR_MODE | ATTR_CTIME;
|
|
ia.ia_ctime = current_time(inode);
|
|
if (is_dir)
|
|
ia.ia_mode = fat_make_mode(sbi, attr, S_IRWXUGO);
|
|
else {
|
|
ia.ia_mode = fat_make_mode(sbi, attr,
|
|
S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO));
|
|
}
|
|
|
|
/* The root directory has no attributes */
|
|
if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) {
|
|
err = -EINVAL;
|
|
goto out_unlock_inode;
|
|
}
|
|
|
|
if (sbi->options.sys_immutable &&
|
|
((attr | oldattr) & ATTR_SYS) &&
|
|
!capable(CAP_LINUX_IMMUTABLE)) {
|
|
err = -EPERM;
|
|
goto out_unlock_inode;
|
|
}
|
|
|
|
/*
|
|
* The security check is questionable... We single
|
|
* out the RO attribute for checking by the security
|
|
* module, just because it maps to a file mode.
|
|
*/
|
|
err = security_inode_setattr(file->f_path.dentry, &ia);
|
|
if (err)
|
|
goto out_unlock_inode;
|
|
|
|
/* This MUST be done before doing anything irreversible... */
|
|
err = fat_setattr(file->f_path.dentry, &ia);
|
|
if (err)
|
|
goto out_unlock_inode;
|
|
|
|
fsnotify_change(file->f_path.dentry, ia.ia_valid);
|
|
if (sbi->options.sys_immutable) {
|
|
if (attr & ATTR_SYS)
|
|
inode->i_flags |= S_IMMUTABLE;
|
|
else
|
|
inode->i_flags &= ~S_IMMUTABLE;
|
|
}
|
|
|
|
fat_save_attrs(inode, attr);
|
|
mark_inode_dirty(inode);
|
|
out_unlock_inode:
|
|
inode_unlock(inode);
|
|
mnt_drop_write_file(file);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
static int fat_ioctl_get_volume_id(struct inode *inode, u32 __user *user_attr)
|
|
{
|
|
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
|
|
return put_user(sbi->vol_id, user_attr);
|
|
}
|
|
|
|
long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|
{
|
|
struct inode *inode = file_inode(filp);
|
|
u32 __user *user_attr = (u32 __user *)arg;
|
|
|
|
switch (cmd) {
|
|
case FAT_IOCTL_GET_ATTRIBUTES:
|
|
return fat_ioctl_get_attributes(inode, user_attr);
|
|
case FAT_IOCTL_SET_ATTRIBUTES:
|
|
return fat_ioctl_set_attributes(filp, user_attr);
|
|
case FAT_IOCTL_GET_VOLUME_ID:
|
|
return fat_ioctl_get_volume_id(inode, user_attr);
|
|
default:
|
|
return -ENOTTY; /* Inappropriate ioctl for device */
|
|
}
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
static long fat_generic_compat_ioctl(struct file *filp, unsigned int cmd,
|
|
unsigned long arg)
|
|
|
|
{
|
|
return fat_generic_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
|
|
}
|
|
#endif
|
|
|
|
static int fat_file_release(struct inode *inode, struct file *filp)
|
|
{
|
|
if ((filp->f_mode & FMODE_WRITE) &&
|
|
MSDOS_SB(inode->i_sb)->options.flush) {
|
|
fat_flush_inodes(inode->i_sb, inode, NULL);
|
|
congestion_wait(BLK_RW_ASYNC, HZ/10);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int fat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
|
|
{
|
|
struct inode *inode = filp->f_mapping->host;
|
|
int err;
|
|
|
|
err = __generic_file_fsync(filp, start, end, datasync);
|
|
if (err)
|
|
return err;
|
|
|
|
err = sync_mapping_buffers(MSDOS_SB(inode->i_sb)->fat_inode->i_mapping);
|
|
if (err)
|
|
return err;
|
|
|
|
return blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
|
|
}
|
|
|
|
|
|
const struct file_operations fat_file_operations = {
|
|
.llseek = generic_file_llseek,
|
|
.read_iter = generic_file_read_iter,
|
|
.write_iter = generic_file_write_iter,
|
|
.mmap = generic_file_mmap,
|
|
.release = fat_file_release,
|
|
.unlocked_ioctl = fat_generic_ioctl,
|
|
#ifdef CONFIG_COMPAT
|
|
.compat_ioctl = fat_generic_compat_ioctl,
|
|
#endif
|
|
.fsync = fat_file_fsync,
|
|
.splice_read = generic_file_splice_read,
|
|
.fallocate = fat_fallocate,
|
|
};
|
|
|
|
static int fat_cont_expand(struct inode *inode, loff_t size)
|
|
{
|
|
struct address_space *mapping = inode->i_mapping;
|
|
loff_t start = inode->i_size, count = size - inode->i_size;
|
|
int err;
|
|
|
|
err = generic_cont_expand_simple(inode, size);
|
|
if (err)
|
|
goto out;
|
|
|
|
inode->i_ctime = inode->i_mtime = current_time(inode);
|
|
mark_inode_dirty(inode);
|
|
if (IS_SYNC(inode)) {
|
|
int err2;
|
|
|
|
/*
|
|
* Opencode syncing since we don't have a file open to use
|
|
* standard fsync path.
|
|
*/
|
|
err = filemap_fdatawrite_range(mapping, start,
|
|
start + count - 1);
|
|
err2 = sync_mapping_buffers(mapping);
|
|
if (!err)
|
|
err = err2;
|
|
err2 = write_inode_now(inode, 1);
|
|
if (!err)
|
|
err = err2;
|
|
if (!err) {
|
|
err = filemap_fdatawait_range(mapping, start,
|
|
start + count - 1);
|
|
}
|
|
}
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Preallocate space for a file. This implements fat's fallocate file
|
|
* operation, which gets called from sys_fallocate system call. User
|
|
* space requests len bytes at offset. If FALLOC_FL_KEEP_SIZE is set
|
|
* we just allocate clusters without zeroing them out. Otherwise we
|
|
* allocate and zero out clusters via an expanding truncate.
|
|
*/
|
|
static long fat_fallocate(struct file *file, int mode,
|
|
loff_t offset, loff_t len)
|
|
{
|
|
int nr_cluster; /* Number of clusters to be allocated */
|
|
loff_t mm_bytes; /* Number of bytes to be allocated for file */
|
|
loff_t ondisksize; /* block aligned on-disk size in bytes*/
|
|
struct inode *inode = file->f_mapping->host;
|
|
struct super_block *sb = inode->i_sb;
|
|
struct msdos_sb_info *sbi = MSDOS_SB(sb);
|
|
int err = 0;
|
|
|
|
/* No support for hole punch or other fallocate flags. */
|
|
if (mode & ~FALLOC_FL_KEEP_SIZE)
|
|
return -EOPNOTSUPP;
|
|
|
|
/* No support for dir */
|
|
if (!S_ISREG(inode->i_mode))
|
|
return -EOPNOTSUPP;
|
|
|
|
inode_lock(inode);
|
|
if (mode & FALLOC_FL_KEEP_SIZE) {
|
|
ondisksize = inode->i_blocks << 9;
|
|
if ((offset + len) <= ondisksize)
|
|
goto error;
|
|
|
|
/* First compute the number of clusters to be allocated */
|
|
mm_bytes = offset + len - ondisksize;
|
|
nr_cluster = (mm_bytes + (sbi->cluster_size - 1)) >>
|
|
sbi->cluster_bits;
|
|
|
|
/* Start the allocation.We are not zeroing out the clusters */
|
|
while (nr_cluster-- > 0) {
|
|
err = fat_add_cluster(inode);
|
|
if (err)
|
|
goto error;
|
|
}
|
|
} else {
|
|
if ((offset + len) <= i_size_read(inode))
|
|
goto error;
|
|
|
|
/* This is just an expanding truncate */
|
|
err = fat_cont_expand(inode, (offset + len));
|
|
}
|
|
|
|
error:
|
|
inode_unlock(inode);
|
|
return err;
|
|
}
|
|
|
|
/* Free all clusters after the skip'th cluster. */
|
|
static int fat_free(struct inode *inode, int skip)
|
|
{
|
|
struct super_block *sb = inode->i_sb;
|
|
int err, wait, free_start, i_start, i_logstart;
|
|
|
|
if (MSDOS_I(inode)->i_start == 0)
|
|
return 0;
|
|
|
|
fat_cache_inval_inode(inode);
|
|
|
|
wait = IS_DIRSYNC(inode);
|
|
i_start = free_start = MSDOS_I(inode)->i_start;
|
|
i_logstart = MSDOS_I(inode)->i_logstart;
|
|
|
|
/* First, we write the new file size. */
|
|
if (!skip) {
|
|
MSDOS_I(inode)->i_start = 0;
|
|
MSDOS_I(inode)->i_logstart = 0;
|
|
}
|
|
MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
|
|
inode->i_ctime = inode->i_mtime = current_time(inode);
|
|
if (wait) {
|
|
err = fat_sync_inode(inode);
|
|
if (err) {
|
|
MSDOS_I(inode)->i_start = i_start;
|
|
MSDOS_I(inode)->i_logstart = i_logstart;
|
|
return err;
|
|
}
|
|
} else
|
|
mark_inode_dirty(inode);
|
|
|
|
/* Write a new EOF, and get the remaining cluster chain for freeing. */
|
|
if (skip) {
|
|
struct fat_entry fatent;
|
|
int ret, fclus, dclus;
|
|
|
|
ret = fat_get_cluster(inode, skip - 1, &fclus, &dclus);
|
|
if (ret < 0)
|
|
return ret;
|
|
else if (ret == FAT_ENT_EOF)
|
|
return 0;
|
|
|
|
fatent_init(&fatent);
|
|
ret = fat_ent_read(inode, &fatent, dclus);
|
|
if (ret == FAT_ENT_EOF) {
|
|
fatent_brelse(&fatent);
|
|
return 0;
|
|
} else if (ret == FAT_ENT_FREE) {
|
|
fat_fs_error(sb,
|
|
"%s: invalid cluster chain (i_pos %lld)",
|
|
__func__, MSDOS_I(inode)->i_pos);
|
|
ret = -EIO;
|
|
} else if (ret > 0) {
|
|
err = fat_ent_write(inode, &fatent, FAT_ENT_EOF, wait);
|
|
if (err)
|
|
ret = err;
|
|
}
|
|
fatent_brelse(&fatent);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
free_start = ret;
|
|
}
|
|
inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9);
|
|
|
|
/* Freeing the remained cluster chain */
|
|
return fat_free_clusters(inode, free_start);
|
|
}
|
|
|
|
void fat_truncate_blocks(struct inode *inode, loff_t offset)
|
|
{
|
|
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
|
|
const unsigned int cluster_size = sbi->cluster_size;
|
|
int nr_clusters;
|
|
|
|
/*
|
|
* This protects against truncating a file bigger than it was then
|
|
* trying to write into the hole.
|
|
*/
|
|
if (MSDOS_I(inode)->mmu_private > offset)
|
|
MSDOS_I(inode)->mmu_private = offset;
|
|
|
|
nr_clusters = (offset + (cluster_size - 1)) >> sbi->cluster_bits;
|
|
|
|
fat_free(inode, nr_clusters);
|
|
fat_flush_inodes(inode->i_sb, inode, NULL);
|
|
}
|
|
|
|
int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
|
|
{
|
|
struct inode *inode = d_inode(dentry);
|
|
generic_fillattr(inode, stat);
|
|
stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
|
|
|
|
if (MSDOS_SB(inode->i_sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
|
|
/* Use i_pos for ino. This is used as fileid of nfs. */
|
|
stat->ino = fat_i_pos_read(MSDOS_SB(inode->i_sb), inode);
|
|
}
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fat_getattr);
|
|
|
|
static int fat_sanitize_mode(const struct msdos_sb_info *sbi,
|
|
struct inode *inode, umode_t *mode_ptr)
|
|
{
|
|
umode_t mask, perm;
|
|
|
|
/*
|
|
* Note, the basic check is already done by a caller of
|
|
* (attr->ia_mode & ~FAT_VALID_MODE)
|
|
*/
|
|
|
|
if (S_ISREG(inode->i_mode))
|
|
mask = sbi->options.fs_fmask;
|
|
else
|
|
mask = sbi->options.fs_dmask;
|
|
|
|
perm = *mode_ptr & ~(S_IFMT | mask);
|
|
|
|
/*
|
|
* Of the r and x bits, all (subject to umask) must be present. Of the
|
|
* w bits, either all (subject to umask) or none must be present.
|
|
*
|
|
* If fat_mode_can_hold_ro(inode) is false, can't change w bits.
|
|
*/
|
|
if ((perm & (S_IRUGO | S_IXUGO)) != (inode->i_mode & (S_IRUGO|S_IXUGO)))
|
|
return -EPERM;
|
|
if (fat_mode_can_hold_ro(inode)) {
|
|
if ((perm & S_IWUGO) && ((perm & S_IWUGO) != (S_IWUGO & ~mask)))
|
|
return -EPERM;
|
|
} else {
|
|
if ((perm & S_IWUGO) != (S_IWUGO & ~mask))
|
|
return -EPERM;
|
|
}
|
|
|
|
*mode_ptr &= S_IFMT | perm;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int fat_allow_set_time(struct msdos_sb_info *sbi, struct inode *inode)
|
|
{
|
|
umode_t allow_utime = sbi->options.allow_utime;
|
|
|
|
if (!uid_eq(current_fsuid(), inode->i_uid)) {
|
|
if (in_group_p(inode->i_gid))
|
|
allow_utime >>= 3;
|
|
if (allow_utime & MAY_WRITE)
|
|
return 1;
|
|
}
|
|
|
|
/* use a default check */
|
|
return 0;
|
|
}
|
|
|
|
#define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
|
|
/* valid file mode bits */
|
|
#define FAT_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXUGO)
|
|
|
|
int fat_setattr(struct dentry *dentry, struct iattr *attr)
|
|
{
|
|
struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
|
|
struct inode *inode = d_inode(dentry);
|
|
unsigned int ia_valid;
|
|
int error;
|
|
|
|
/* Check for setting the inode time. */
|
|
ia_valid = attr->ia_valid;
|
|
if (ia_valid & TIMES_SET_FLAGS) {
|
|
if (fat_allow_set_time(sbi, inode))
|
|
attr->ia_valid &= ~TIMES_SET_FLAGS;
|
|
}
|
|
|
|
error = setattr_prepare(dentry, attr);
|
|
attr->ia_valid = ia_valid;
|
|
if (error) {
|
|
if (sbi->options.quiet)
|
|
error = 0;
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* Expand the file. Since inode_setattr() updates ->i_size
|
|
* before calling the ->truncate(), but FAT needs to fill the
|
|
* hole before it. XXX: this is no longer true with new truncate
|
|
* sequence.
|
|
*/
|
|
if (attr->ia_valid & ATTR_SIZE) {
|
|
inode_dio_wait(inode);
|
|
|
|
if (attr->ia_size > inode->i_size) {
|
|
error = fat_cont_expand(inode, attr->ia_size);
|
|
if (error || attr->ia_valid == ATTR_SIZE)
|
|
goto out;
|
|
attr->ia_valid &= ~ATTR_SIZE;
|
|
}
|
|
}
|
|
|
|
if (((attr->ia_valid & ATTR_UID) &&
|
|
(!uid_eq(attr->ia_uid, sbi->options.fs_uid))) ||
|
|
((attr->ia_valid & ATTR_GID) &&
|
|
(!gid_eq(attr->ia_gid, sbi->options.fs_gid))) ||
|
|
((attr->ia_valid & ATTR_MODE) &&
|
|
(attr->ia_mode & ~FAT_VALID_MODE)))
|
|
error = -EPERM;
|
|
|
|
if (error) {
|
|
if (sbi->options.quiet)
|
|
error = 0;
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* We don't return -EPERM here. Yes, strange, but this is too
|
|
* old behavior.
|
|
*/
|
|
if (attr->ia_valid & ATTR_MODE) {
|
|
if (fat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
|
|
attr->ia_valid &= ~ATTR_MODE;
|
|
}
|
|
|
|
if (attr->ia_valid & ATTR_SIZE) {
|
|
error = fat_block_truncate_page(inode, attr->ia_size);
|
|
if (error)
|
|
goto out;
|
|
down_write(&MSDOS_I(inode)->truncate_lock);
|
|
truncate_setsize(inode, attr->ia_size);
|
|
fat_truncate_blocks(inode, attr->ia_size);
|
|
up_write(&MSDOS_I(inode)->truncate_lock);
|
|
}
|
|
|
|
setattr_copy(inode, attr);
|
|
mark_inode_dirty(inode);
|
|
out:
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fat_setattr);
|
|
|
|
const struct inode_operations fat_file_inode_operations = {
|
|
.setattr = fat_setattr,
|
|
.getattr = fat_getattr,
|
|
};
|