|
Kmods SIG |
9e3ffb |
From 98d917047e8b7f4bb2ff61d81b0ccd94a00444f9 Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
9e3ffb |
From: Namjae Jeon <namjae.jeon@samsung.com>
|
|
Kmods SIG |
9e3ffb |
Date: Mon, 2 Mar 2020 15:21:36 +0900
|
|
Kmods SIG |
9e3ffb |
Subject: [Backport 98d917047e8b] exfat: add file operations
|
|
Kmods SIG |
9e3ffb |
MIME-Version: 1.0
|
|
Kmods SIG |
9e3ffb |
Content-Type: text/plain; charset=UTF-8
|
|
Kmods SIG |
9e3ffb |
Content-Transfer-Encoding: 8bit
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
This adds the implementation of file operations for exfat.
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Sungjong Seo <sj1557.seo@samsung.com>
|
|
Kmods SIG |
9e3ffb |
Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
|
|
Kmods SIG |
9e3ffb |
Reviewed-by: Christoph Hellwig <hch@lst.de>
|
|
Kmods SIG |
9e3ffb |
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
Kmods SIG |
9e3ffb |
---
|
|
Kmods SIG |
9e3ffb |
src/file.c | 360 ++++++++++++++++++++++++++++++++++++++++++++++++
|
|
Kmods SIG |
9e3ffb |
1 file changed, 360 insertions(+)
|
|
Kmods SIG |
9e3ffb |
create mode 100644 src/file.c
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
diff --git a/src/file.c b/src/file.c
|
|
Kmods SIG |
9e3ffb |
new file mode 100644
|
|
Kmods SIG |
9e3ffb |
index 0000000000000000000000000000000000000000..483f683757aa87420ba347afd3c9db9e94b8a14d
|
|
Kmods SIG |
9e3ffb |
--- /dev/null
|
|
Kmods SIG |
9e3ffb |
+++ b/src/file.c
|
|
Kmods SIG |
9e3ffb |
@@ -0,0 +1,360 @@
|
|
Kmods SIG |
9e3ffb |
+// SPDX-License-Identifier: GPL-2.0-or-later
|
|
Kmods SIG |
9e3ffb |
+/*
|
|
Kmods SIG |
9e3ffb |
+ * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+#include <linux/slab.h>
|
|
Kmods SIG |
9e3ffb |
+#include <linux/cred.h>
|
|
Kmods SIG |
9e3ffb |
+#include <linux/buffer_head.h>
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+#include "exfat_raw.h"
|
|
Kmods SIG |
9e3ffb |
+#include "exfat_fs.h"
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+static int exfat_cont_expand(struct inode *inode, loff_t size)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ struct address_space *mapping = inode->i_mapping;
|
|
Kmods SIG |
9e3ffb |
+ loff_t start = i_size_read(inode), count = size - i_size_read(inode);
|
|
Kmods SIG |
9e3ffb |
+ int err, err2;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ err = generic_cont_expand_simple(inode, size);
|
|
Kmods SIG |
9e3ffb |
+ if (err)
|
|
Kmods SIG |
9e3ffb |
+ return err;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ inode->i_ctime = inode->i_mtime = current_time(inode);
|
|
Kmods SIG |
9e3ffb |
+ mark_inode_dirty(inode);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (!IS_SYNC(inode))
|
|
Kmods SIG |
9e3ffb |
+ return 0;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ err = filemap_fdatawrite_range(mapping, start, start + count - 1);
|
|
Kmods SIG |
9e3ffb |
+ err2 = sync_mapping_buffers(mapping);
|
|
Kmods SIG |
9e3ffb |
+ if (!err)
|
|
Kmods SIG |
9e3ffb |
+ err = err2;
|
|
Kmods SIG |
9e3ffb |
+ err2 = write_inode_now(inode, 1);
|
|
Kmods SIG |
9e3ffb |
+ if (!err)
|
|
Kmods SIG |
9e3ffb |
+ err = err2;
|
|
Kmods SIG |
9e3ffb |
+ if (err)
|
|
Kmods SIG |
9e3ffb |
+ return err;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ return filemap_fdatawait_range(mapping, start, start + count - 1);
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+static bool exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ mode_t allow_utime = sbi->options.allow_utime;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (!uid_eq(current_fsuid(), inode->i_uid)) {
|
|
Kmods SIG |
9e3ffb |
+ if (in_group_p(inode->i_gid))
|
|
Kmods SIG |
9e3ffb |
+ allow_utime >>= 3;
|
|
Kmods SIG |
9e3ffb |
+ if (allow_utime & MAY_WRITE)
|
|
Kmods SIG |
9e3ffb |
+ return true;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* use a default check */
|
|
Kmods SIG |
9e3ffb |
+ return false;
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+static int exfat_sanitize_mode(const struct exfat_sb_info *sbi,
|
|
Kmods SIG |
9e3ffb |
+ struct inode *inode, umode_t *mode_ptr)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ mode_t i_mode, mask, perm;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ i_mode = inode->i_mode;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ mask = (S_ISREG(i_mode) || S_ISLNK(i_mode)) ?
|
|
Kmods SIG |
9e3ffb |
+ sbi->options.fs_fmask : sbi->options.fs_dmask;
|
|
Kmods SIG |
9e3ffb |
+ perm = *mode_ptr & ~(S_IFMT | mask);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* Of the r and x bits, all (subject to umask) must be present.*/
|
|
Kmods SIG |
9e3ffb |
+ if ((perm & 0555) != (i_mode & 0555))
|
|
Kmods SIG |
9e3ffb |
+ return -EPERM;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (exfat_mode_can_hold_ro(inode)) {
|
|
Kmods SIG |
9e3ffb |
+ /*
|
|
Kmods SIG |
9e3ffb |
+ * Of the w bits, either all (subject to umask) or none must
|
|
Kmods SIG |
9e3ffb |
+ * be present.
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+ if ((perm & 0222) && ((perm & 0222) != (0222 & ~mask)))
|
|
Kmods SIG |
9e3ffb |
+ return -EPERM;
|
|
Kmods SIG |
9e3ffb |
+ } else {
|
|
Kmods SIG |
9e3ffb |
+ /*
|
|
Kmods SIG |
9e3ffb |
+ * If exfat_mode_can_hold_ro(inode) is false, can't change
|
|
Kmods SIG |
9e3ffb |
+ * w bits.
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+ if ((perm & 0222) != (0222 & ~mask))
|
|
Kmods SIG |
9e3ffb |
+ return -EPERM;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ *mode_ptr &= S_IFMT | perm;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ return 0;
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+/* resize the file length */
|
|
Kmods SIG |
9e3ffb |
+int __exfat_truncate(struct inode *inode, loff_t new_size)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ unsigned int num_clusters_new, num_clusters_phys;
|
|
Kmods SIG |
9e3ffb |
+ unsigned int last_clu = EXFAT_FREE_CLUSTER;
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_chain clu;
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_dentry *ep, *ep2;
|
|
Kmods SIG |
9e3ffb |
+ struct super_block *sb = inode->i_sb;
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_entry_set_cache *es = NULL;
|
|
Kmods SIG |
9e3ffb |
+ int evict = (ei->dir.dir == DIR_DELETED) ? 1 : 0;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* check if the given file ID is opened */
|
|
Kmods SIG |
9e3ffb |
+ if (ei->type != TYPE_FILE && ei->type != TYPE_DIR)
|
|
Kmods SIG |
9e3ffb |
+ return -EPERM;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ num_clusters_new = EXFAT_B_TO_CLU_ROUND_UP(i_size_read(inode), sbi);
|
|
Kmods SIG |
9e3ffb |
+ num_clusters_phys =
|
|
Kmods SIG |
9e3ffb |
+ EXFAT_B_TO_CLU_ROUND_UP(EXFAT_I(inode)->i_size_ondisk, sbi);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ exfat_chain_set(&clu, ei->start_clu, num_clusters_phys, ei->flags);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (new_size > 0) {
|
|
Kmods SIG |
9e3ffb |
+ /*
|
|
Kmods SIG |
9e3ffb |
+ * Truncate FAT chain num_clusters after the first cluster
|
|
Kmods SIG |
9e3ffb |
+ * num_clusters = min(new, phys);
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+ unsigned int num_clusters =
|
|
Kmods SIG |
9e3ffb |
+ min(num_clusters_new, num_clusters_phys);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /*
|
|
Kmods SIG |
9e3ffb |
+ * Follow FAT chain
|
|
Kmods SIG |
9e3ffb |
+ * (defensive coding - works fine even with corrupted FAT table
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+ if (clu.flags == ALLOC_NO_FAT_CHAIN) {
|
|
Kmods SIG |
9e3ffb |
+ clu.dir += num_clusters;
|
|
Kmods SIG |
9e3ffb |
+ clu.size -= num_clusters;
|
|
Kmods SIG |
9e3ffb |
+ } else {
|
|
Kmods SIG |
9e3ffb |
+ while (num_clusters > 0) {
|
|
Kmods SIG |
9e3ffb |
+ last_clu = clu.dir;
|
|
Kmods SIG |
9e3ffb |
+ if (exfat_get_next_cluster(sb, &(clu.dir)))
|
|
Kmods SIG |
9e3ffb |
+ return -EIO;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ num_clusters--;
|
|
Kmods SIG |
9e3ffb |
+ clu.size--;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+ } else {
|
|
Kmods SIG |
9e3ffb |
+ ei->flags = ALLOC_NO_FAT_CHAIN;
|
|
Kmods SIG |
9e3ffb |
+ ei->start_clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ i_size_write(inode, new_size);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (ei->type == TYPE_FILE)
|
|
Kmods SIG |
9e3ffb |
+ ei->attr |= ATTR_ARCHIVE;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* update the directory entry */
|
|
Kmods SIG |
9e3ffb |
+ if (!evict) {
|
|
Kmods SIG |
9e3ffb |
+ struct timespec64 ts;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry,
|
|
Kmods SIG |
9e3ffb |
+ ES_ALL_ENTRIES, &ep);
|
|
Kmods SIG |
9e3ffb |
+ if (!es)
|
|
Kmods SIG |
9e3ffb |
+ return -EIO;
|
|
Kmods SIG |
9e3ffb |
+ ep2 = ep + 1;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ ts = current_time(inode);
|
|
Kmods SIG |
9e3ffb |
+ exfat_set_entry_time(sbi, &ts,
|
|
Kmods SIG |
9e3ffb |
+ &ep->dentry.file.modify_tz,
|
|
Kmods SIG |
9e3ffb |
+ &ep->dentry.file.modify_time,
|
|
Kmods SIG |
9e3ffb |
+ &ep->dentry.file.modify_date,
|
|
Kmods SIG |
9e3ffb |
+ &ep->dentry.file.modify_time_ms);
|
|
Kmods SIG |
9e3ffb |
+ ep->dentry.file.attr = cpu_to_le16(ei->attr);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* File size should be zero if there is no cluster allocated */
|
|
Kmods SIG |
9e3ffb |
+ if (ei->start_clu == EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
9e3ffb |
+ ep->dentry.stream.valid_size = 0;
|
|
Kmods SIG |
9e3ffb |
+ ep->dentry.stream.size = 0;
|
|
Kmods SIG |
9e3ffb |
+ } else {
|
|
Kmods SIG |
9e3ffb |
+ ep->dentry.stream.valid_size = cpu_to_le64(new_size);
|
|
Kmods SIG |
9e3ffb |
+ ep->dentry.stream.size = ep->dentry.stream.valid_size;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (new_size == 0) {
|
|
Kmods SIG |
9e3ffb |
+ /* Any directory can not be truncated to zero */
|
|
Kmods SIG |
9e3ffb |
+ WARN_ON(ei->type != TYPE_FILE);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ ep2->dentry.stream.flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
9e3ffb |
+ ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (exfat_update_dir_chksum_with_entry_set(sb, es,
|
|
Kmods SIG |
9e3ffb |
+ inode_needs_sync(inode)))
|
|
Kmods SIG |
9e3ffb |
+ return -EIO;
|
|
Kmods SIG |
9e3ffb |
+ kfree(es);
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* cut off from the FAT chain */
|
|
Kmods SIG |
9e3ffb |
+ if (ei->flags == ALLOC_FAT_CHAIN && last_clu != EXFAT_FREE_CLUSTER &&
|
|
Kmods SIG |
9e3ffb |
+ last_clu != EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
9e3ffb |
+ if (exfat_ent_set(sb, last_clu, EXFAT_EOF_CLUSTER))
|
|
Kmods SIG |
9e3ffb |
+ return -EIO;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* invalidate cache and free the clusters */
|
|
Kmods SIG |
9e3ffb |
+ /* clear exfat cache */
|
|
Kmods SIG |
9e3ffb |
+ exfat_cache_inval_inode(inode);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* hint information */
|
|
Kmods SIG |
9e3ffb |
+ ei->hint_bmap.off = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
9e3ffb |
+ ei->hint_bmap.clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
9e3ffb |
+ if (ei->rwoffset > new_size)
|
|
Kmods SIG |
9e3ffb |
+ ei->rwoffset = new_size;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* hint_stat will be used if this is directory. */
|
|
Kmods SIG |
9e3ffb |
+ ei->hint_stat.eidx = 0;
|
|
Kmods SIG |
9e3ffb |
+ ei->hint_stat.clu = ei->start_clu;
|
|
Kmods SIG |
9e3ffb |
+ ei->hint_femp.eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* free the clusters */
|
|
Kmods SIG |
9e3ffb |
+ if (exfat_free_cluster(inode, &clu))
|
|
Kmods SIG |
9e3ffb |
+ return -EIO;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ return 0;
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+void exfat_truncate(struct inode *inode, loff_t size)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ struct super_block *sb = inode->i_sb;
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
9e3ffb |
+ unsigned int blocksize = 1 << inode->i_blkbits;
|
|
Kmods SIG |
9e3ffb |
+ loff_t aligned_size;
|
|
Kmods SIG |
9e3ffb |
+ int err;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ mutex_lock(&sbi->s_lock);
|
|
Kmods SIG |
9e3ffb |
+ if (EXFAT_I(inode)->start_clu == 0) {
|
|
Kmods SIG |
9e3ffb |
+ /*
|
|
Kmods SIG |
9e3ffb |
+ * Empty start_clu != ~0 (not allocated)
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+ exfat_fs_error(sb, "tried to truncate zeroed cluster.");
|
|
Kmods SIG |
9e3ffb |
+ goto write_size;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ err = __exfat_truncate(inode, i_size_read(inode));
|
|
Kmods SIG |
9e3ffb |
+ if (err)
|
|
Kmods SIG |
9e3ffb |
+ goto write_size;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ inode->i_ctime = inode->i_mtime = current_time(inode);
|
|
Kmods SIG |
9e3ffb |
+ if (IS_DIRSYNC(inode))
|
|
Kmods SIG |
9e3ffb |
+ exfat_sync_inode(inode);
|
|
Kmods SIG |
9e3ffb |
+ else
|
|
Kmods SIG |
9e3ffb |
+ mark_inode_dirty(inode);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
|
|
Kmods SIG |
9e3ffb |
+ ~(sbi->cluster_size - 1)) >> inode->i_blkbits;
|
|
Kmods SIG |
9e3ffb |
+write_size:
|
|
Kmods SIG |
9e3ffb |
+ aligned_size = i_size_read(inode);
|
|
Kmods SIG |
9e3ffb |
+ if (aligned_size & (blocksize - 1)) {
|
|
Kmods SIG |
9e3ffb |
+ aligned_size |= (blocksize - 1);
|
|
Kmods SIG |
9e3ffb |
+ aligned_size++;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (EXFAT_I(inode)->i_size_ondisk > i_size_read(inode))
|
|
Kmods SIG |
9e3ffb |
+ EXFAT_I(inode)->i_size_ondisk = aligned_size;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (EXFAT_I(inode)->i_size_aligned > i_size_read(inode))
|
|
Kmods SIG |
9e3ffb |
+ EXFAT_I(inode)->i_size_aligned = aligned_size;
|
|
Kmods SIG |
9e3ffb |
+ mutex_unlock(&sbi->s_lock);
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+int exfat_getattr(const struct path *path, struct kstat *stat,
|
|
Kmods SIG |
9e3ffb |
+ unsigned int request_mask, unsigned int query_flags)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ struct inode *inode = d_backing_inode(path->dentry);
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ generic_fillattr(inode, stat);
|
|
Kmods SIG |
9e3ffb |
+ stat->result_mask |= STATX_BTIME;
|
|
Kmods SIG |
9e3ffb |
+ stat->btime.tv_sec = ei->i_crtime.tv_sec;
|
|
Kmods SIG |
9e3ffb |
+ stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
|
|
Kmods SIG |
9e3ffb |
+ stat->blksize = EXFAT_SB(inode->i_sb)->cluster_size;
|
|
Kmods SIG |
9e3ffb |
+ return 0;
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+int exfat_setattr(struct dentry *dentry, struct iattr *attr)
|
|
Kmods SIG |
9e3ffb |
+{
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_sb_info *sbi = EXFAT_SB(dentry->d_sb);
|
|
Kmods SIG |
9e3ffb |
+ struct inode *inode = dentry->d_inode;
|
|
Kmods SIG |
9e3ffb |
+ unsigned int ia_valid;
|
|
Kmods SIG |
9e3ffb |
+ int error;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if ((attr->ia_valid & ATTR_SIZE) &&
|
|
Kmods SIG |
9e3ffb |
+ attr->ia_size > i_size_read(inode)) {
|
|
Kmods SIG |
9e3ffb |
+ error = exfat_cont_expand(inode, attr->ia_size);
|
|
Kmods SIG |
9e3ffb |
+ if (error || attr->ia_valid == ATTR_SIZE)
|
|
Kmods SIG |
9e3ffb |
+ return error;
|
|
Kmods SIG |
9e3ffb |
+ attr->ia_valid &= ~ATTR_SIZE;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /* Check for setting the inode time. */
|
|
Kmods SIG |
9e3ffb |
+ ia_valid = attr->ia_valid;
|
|
Kmods SIG |
9e3ffb |
+ if ((ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) &&
|
|
Kmods SIG |
9e3ffb |
+ exfat_allow_set_time(sbi, inode)) {
|
|
Kmods SIG |
9e3ffb |
+ attr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET |
|
|
Kmods SIG |
9e3ffb |
+ ATTR_TIMES_SET);
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ error = setattr_prepare(dentry, attr);
|
|
Kmods SIG |
9e3ffb |
+ attr->ia_valid = ia_valid;
|
|
Kmods SIG |
9e3ffb |
+ if (error)
|
|
Kmods SIG |
9e3ffb |
+ goto out;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (((attr->ia_valid & ATTR_UID) &&
|
|
Kmods SIG |
9e3ffb |
+ !uid_eq(attr->ia_uid, sbi->options.fs_uid)) ||
|
|
Kmods SIG |
9e3ffb |
+ ((attr->ia_valid & ATTR_GID) &&
|
|
Kmods SIG |
9e3ffb |
+ !gid_eq(attr->ia_gid, sbi->options.fs_gid)) ||
|
|
Kmods SIG |
9e3ffb |
+ ((attr->ia_valid & ATTR_MODE) &&
|
|
Kmods SIG |
9e3ffb |
+ (attr->ia_mode & ~(S_IFREG | S_IFLNK | S_IFDIR | 0777)))) {
|
|
Kmods SIG |
9e3ffb |
+ error = -EPERM;
|
|
Kmods SIG |
9e3ffb |
+ goto out;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ /*
|
|
Kmods SIG |
9e3ffb |
+ * We don't return -EPERM here. Yes, strange, but this is too
|
|
Kmods SIG |
9e3ffb |
+ * old behavior.
|
|
Kmods SIG |
9e3ffb |
+ */
|
|
Kmods SIG |
9e3ffb |
+ if (attr->ia_valid & ATTR_MODE) {
|
|
Kmods SIG |
9e3ffb |
+ if (exfat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
|
|
Kmods SIG |
9e3ffb |
+ attr->ia_valid &= ~ATTR_MODE;
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ if (attr->ia_valid & ATTR_SIZE) {
|
|
Kmods SIG |
9e3ffb |
+ error = exfat_block_truncate_page(inode, attr->ia_size);
|
|
Kmods SIG |
9e3ffb |
+ if (error)
|
|
Kmods SIG |
9e3ffb |
+ goto out;
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ down_write(&EXFAT_I(inode)->truncate_lock);
|
|
Kmods SIG |
9e3ffb |
+ truncate_setsize(inode, attr->ia_size);
|
|
Kmods SIG |
9e3ffb |
+ exfat_truncate(inode, attr->ia_size);
|
|
Kmods SIG |
9e3ffb |
+ up_write(&EXFAT_I(inode)->truncate_lock);
|
|
Kmods SIG |
9e3ffb |
+ }
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+ setattr_copy(inode, attr);
|
|
Kmods SIG |
9e3ffb |
+ mark_inode_dirty(inode);
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+out:
|
|
Kmods SIG |
9e3ffb |
+ return error;
|
|
Kmods SIG |
9e3ffb |
+}
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+const struct file_operations exfat_file_operations = {
|
|
Kmods SIG |
9e3ffb |
+ .llseek = generic_file_llseek,
|
|
Kmods SIG |
9e3ffb |
+ .read_iter = generic_file_read_iter,
|
|
Kmods SIG |
9e3ffb |
+ .write_iter = generic_file_write_iter,
|
|
Kmods SIG |
9e3ffb |
+ .mmap = generic_file_mmap,
|
|
Kmods SIG |
9e3ffb |
+ .fsync = generic_file_fsync,
|
|
Kmods SIG |
9e3ffb |
+ .splice_read = generic_file_splice_read,
|
|
Kmods SIG |
9e3ffb |
+};
|
|
Kmods SIG |
9e3ffb |
+
|
|
Kmods SIG |
9e3ffb |
+const struct inode_operations exfat_file_inode_operations = {
|
|
Kmods SIG |
9e3ffb |
+ .setattr = exfat_setattr,
|
|
Kmods SIG |
9e3ffb |
+ .getattr = exfat_getattr,
|
|
Kmods SIG |
9e3ffb |
+};
|
|
Kmods SIG |
9e3ffb |
--
|
|
Kmods SIG |
9e3ffb |
2.31.1
|
|
Kmods SIG |
9e3ffb |
|