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