|
Kmods SIG |
50e2b3 |
From 5f2aa075070cf5b2e6aae011d5a3390408d7d913 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:34 +0900
|
|
Kmods SIG |
50e2b3 |
Subject: [Backport 5f2aa075070c] exfat: add inode 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 inode 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 |
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
Kmods SIG |
50e2b3 |
---
|
|
Kmods SIG |
50e2b3 |
src/inode.c | 671 +++++++++++++++++++++
|
|
Kmods SIG |
50e2b3 |
src/namei.c | 1448 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
Kmods SIG |
50e2b3 |
2 files changed, 2119 insertions(+)
|
|
Kmods SIG |
50e2b3 |
create mode 100644 src/inode.c
|
|
Kmods SIG |
50e2b3 |
create mode 100644 src/namei.c
|
|
Kmods SIG |
50e2b3 |
|
|
Kmods SIG |
50e2b3 |
diff --git a/src/inode.c b/src/inode.c
|
|
Kmods SIG |
50e2b3 |
new file mode 100644
|
|
Kmods SIG |
50e2b3 |
index 0000000000000000000000000000000000000000..06887492f54b791506d2f7c76eb3ef073b72026d
|
|
Kmods SIG |
50e2b3 |
--- /dev/null
|
|
Kmods SIG |
50e2b3 |
+++ b/src/inode.c
|
|
Kmods SIG |
50e2b3 |
@@ -0,0 +1,671 @@
|
|
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/init.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/buffer_head.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/mpage.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/bio.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/blkdev.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/time.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/writeback.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/uio.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/random.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/iversion.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_write_inode(struct inode *inode, int sync)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ unsigned long long on_disk_size;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep, *ep2;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_entry_set_cache *es = NULL;
|
|
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 |
+ bool is_dir = (ei->type == TYPE_DIR) ? true : false;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (inode->i_ino == EXFAT_ROOT_INO)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * If the indode is already unlinked, there is no need for updating it.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (ei->dir.dir == DIR_DELETED)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (is_dir && ei->dir.dir == sbi->root_dir && ei->entry == -1)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* get the directory entry of given file or directory */
|
|
Kmods SIG |
50e2b3 |
+ es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES,
|
|
Kmods SIG |
50e2b3 |
+ &ep);
|
|
Kmods SIG |
50e2b3 |
+ if (!es)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ ep2 = ep + 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode));
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* set FILE_INFO structure using the acquired struct exfat_dentry */
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_entry_time(sbi, &ei->i_crtime,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.create_tz,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.create_time,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.create_date,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.create_time_ms);
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_entry_time(sbi, &inode->i_mtime,
|
|
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 |
+ exfat_set_entry_time(sbi, &inode->i_atime,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.access_tz,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.access_time,
|
|
Kmods SIG |
50e2b3 |
+ &ep->dentry.file.access_date,
|
|
Kmods SIG |
50e2b3 |
+ NULL);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* File size should be zero if there is no cluster allocated */
|
|
Kmods SIG |
50e2b3 |
+ on_disk_size = i_size_read(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->start_clu == EXFAT_EOF_CLUSTER)
|
|
Kmods SIG |
50e2b3 |
+ on_disk_size = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep2->dentry.stream.valid_size = cpu_to_le64(on_disk_size);
|
|
Kmods SIG |
50e2b3 |
+ ep2->dentry.stream.size = ep2->dentry.stream.valid_size;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_update_dir_chksum_with_entry_set(sb, es, sync);
|
|
Kmods SIG |
50e2b3 |
+ kfree(es);
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ ret = __exfat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_sync_inode(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ lockdep_assert_held(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ __exfat_write_inode(inode, 1);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * Input: inode, (logical) clu_offset, target allocation area
|
|
Kmods SIG |
50e2b3 |
+ * Output: errcode, cluster number
|
|
Kmods SIG |
50e2b3 |
+ * *clu = (~0), if it's unable to allocate a new cluster
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int *clu, int create)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret, modified = false;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int last_clu;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain new_clu;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_entry_set_cache *es = NULL;
|
|
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 |
+ unsigned int local_clu_offset = clu_offset;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int num_to_be_allocated = 0, num_clusters = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ei->rwoffset = EXFAT_CLU_TO_B(clu_offset, sbi);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (EXFAT_I(inode)->i_size_ondisk > 0)
|
|
Kmods SIG |
50e2b3 |
+ num_clusters =
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU_ROUND_UP(EXFAT_I(inode)->i_size_ondisk,
|
|
Kmods SIG |
50e2b3 |
+ sbi);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (clu_offset >= num_clusters)
|
|
Kmods SIG |
50e2b3 |
+ num_to_be_allocated = clu_offset - num_clusters + 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (!create && (num_to_be_allocated > 0)) {
|
|
Kmods SIG |
50e2b3 |
+ *clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ *clu = last_clu = ei->start_clu;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->flags == ALLOC_NO_FAT_CHAIN) {
|
|
Kmods SIG |
50e2b3 |
+ if (clu_offset > 0 && *clu != EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ last_clu += clu_offset - 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (clu_offset == num_clusters)
|
|
Kmods SIG |
50e2b3 |
+ *clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ *clu += clu_offset;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ } else if (ei->type == TYPE_FILE) {
|
|
Kmods SIG |
50e2b3 |
+ unsigned int fclus = 0;
|
|
Kmods SIG |
50e2b3 |
+ int err = exfat_get_cluster(inode, clu_offset,
|
|
Kmods SIG |
50e2b3 |
+ &fclus, clu, &last_clu, 1);
|
|
Kmods SIG |
50e2b3 |
+ if (err)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ clu_offset -= fclus;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ /* hint information */
|
|
Kmods SIG |
50e2b3 |
+ if (clu_offset > 0 && ei->hint_bmap.off != EXFAT_EOF_CLUSTER &&
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_bmap.off > 0 && clu_offset >= ei->hint_bmap.off) {
|
|
Kmods SIG |
50e2b3 |
+ clu_offset -= ei->hint_bmap.off;
|
|
Kmods SIG |
50e2b3 |
+ /* hint_bmap.clu should be valid */
|
|
Kmods SIG |
50e2b3 |
+ WARN_ON(ei->hint_bmap.clu < 2);
|
|
Kmods SIG |
50e2b3 |
+ *clu = ei->hint_bmap.clu;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ while (clu_offset > 0 && *clu != EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ last_clu = *clu;
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_next_cluster(sb, clu))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ clu_offset--;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (*clu == EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ new_clu.dir = (last_clu == EXFAT_EOF_CLUSTER) ?
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_EOF_CLUSTER : last_clu + 1;
|
|
Kmods SIG |
50e2b3 |
+ new_clu.size = 0;
|
|
Kmods SIG |
50e2b3 |
+ new_clu.flags = ei->flags;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* allocate a cluster */
|
|
Kmods SIG |
50e2b3 |
+ if (num_to_be_allocated < 1) {
|
|
Kmods SIG |
50e2b3 |
+ /* Broken FAT (i_sze > allocated FAT) */
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb, "broken FAT chain.");
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_alloc_cluster(inode, num_to_be_allocated, &new_clu);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (new_clu.dir == EXFAT_EOF_CLUSTER ||
|
|
Kmods SIG |
50e2b3 |
+ new_clu.dir == EXFAT_FREE_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "bogus cluster new allocated (last_clu : %u, new_clu : %u)",
|
|
Kmods SIG |
50e2b3 |
+ last_clu, new_clu.dir);
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* append to the FAT chain */
|
|
Kmods SIG |
50e2b3 |
+ if (last_clu == EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ if (new_clu.flags == ALLOC_FAT_CHAIN)
|
|
Kmods SIG |
50e2b3 |
+ ei->flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ ei->start_clu = new_clu.dir;
|
|
Kmods SIG |
50e2b3 |
+ modified = true;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ if (new_clu.flags != ei->flags) {
|
|
Kmods SIG |
50e2b3 |
+ /* no-fat-chain bit is disabled,
|
|
Kmods SIG |
50e2b3 |
+ * so fat-chain should be synced with
|
|
Kmods SIG |
50e2b3 |
+ * alloc-bitmap
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_cont_cluster(sb, ei->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ num_clusters);
|
|
Kmods SIG |
50e2b3 |
+ ei->flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ modified = true;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ if (new_clu.flags == ALLOC_FAT_CHAIN)
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_ent_set(sb, last_clu, new_clu.dir))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_clusters += num_to_be_allocated;
|
|
Kmods SIG |
50e2b3 |
+ *clu = new_clu.dir;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->dir.dir != DIR_DELETED) {
|
|
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 |
+ /* get stream entry */
|
|
Kmods SIG |
50e2b3 |
+ ep++;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* update directory entry */
|
|
Kmods SIG |
50e2b3 |
+ if (modified) {
|
|
Kmods SIG |
50e2b3 |
+ if (ep->dentry.stream.flags != ei->flags)
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.flags = ei->flags;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (le32_to_cpu(ep->dentry.stream.start_clu) !=
|
|
Kmods SIG |
50e2b3 |
+ ei->start_clu)
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.start_clu =
|
|
Kmods SIG |
50e2b3 |
+ cpu_to_le32(ei->start_clu);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.valid_size =
|
|
Kmods SIG |
50e2b3 |
+ cpu_to_le64(i_size_read(inode));
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.size =
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.valid_size;
|
|
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 |
+ } /* end of if != DIR_DELETED */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode->i_blocks +=
|
|
Kmods SIG |
50e2b3 |
+ num_to_be_allocated << sbi->sect_per_clus_bits;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Move *clu pointer along FAT chains (hole care) because the
|
|
Kmods SIG |
50e2b3 |
+ * caller of this function expect *clu to be the last cluster.
|
|
Kmods SIG |
50e2b3 |
+ * This only works when num_to_be_allocated >= 2,
|
|
Kmods SIG |
50e2b3 |
+ * *clu = (the first cluster of the allocated chain) =>
|
|
Kmods SIG |
50e2b3 |
+ * (the last cluster of ...)
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (ei->flags == ALLOC_NO_FAT_CHAIN) {
|
|
Kmods SIG |
50e2b3 |
+ *clu += num_to_be_allocated - 1;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ while (num_to_be_allocated > 1) {
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_next_cluster(sb, clu))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ num_to_be_allocated--;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* hint information */
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_bmap.off = local_clu_offset;
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_bmap.clu = *clu;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_map_new_buffer(struct exfat_inode_info *ei,
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *bh, loff_t pos)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ if (buffer_delay(bh) && pos > ei->i_size_aligned)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ set_buffer_new(bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Adjust i_size_aligned if i_size_ondisk is bigger than it.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (ei->i_size_ondisk > ei->i_size_aligned)
|
|
Kmods SIG |
50e2b3 |
+ ei->i_size_aligned = ei->i_size_ondisk;
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_get_block(struct inode *inode, sector_t iblock,
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *bh_result, int create)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
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 long max_blocks = bh_result->b_size >> inode->i_blkbits;
|
|
Kmods SIG |
50e2b3 |
+ int err = 0;
|
|
Kmods SIG |
50e2b3 |
+ unsigned long mapped_blocks = 0;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int cluster, sec_offset;
|
|
Kmods SIG |
50e2b3 |
+ sector_t last_block;
|
|
Kmods SIG |
50e2b3 |
+ sector_t phys = 0;
|
|
Kmods SIG |
50e2b3 |
+ loff_t pos;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&sbi->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ last_block = EXFAT_B_TO_BLK_ROUND_UP(i_size_read(inode), sb);
|
|
Kmods SIG |
50e2b3 |
+ if (iblock >= last_block && !create)
|
|
Kmods SIG |
50e2b3 |
+ goto done;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* Is this block already allocated? */
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_map_cluster(inode, iblock >> sbi->sect_per_clus_bits,
|
|
Kmods SIG |
50e2b3 |
+ &cluster, create);
|
|
Kmods SIG |
50e2b3 |
+ if (err) {
|
|
Kmods SIG |
50e2b3 |
+ if (err != -ENOSPC)
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error_ratelimit(sb,
|
|
Kmods SIG |
50e2b3 |
+ "failed to bmap (inode : %p iblock : %llu, err : %d)",
|
|
Kmods SIG |
50e2b3 |
+ inode, (unsigned long long)iblock, err);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock_ret;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (cluster == EXFAT_EOF_CLUSTER)
|
|
Kmods SIG |
50e2b3 |
+ goto done;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* sector offset in cluster */
|
|
Kmods SIG |
50e2b3 |
+ sec_offset = iblock & (sbi->sect_per_clus - 1);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ phys = exfat_cluster_to_sector(sbi, cluster) + sec_offset;
|
|
Kmods SIG |
50e2b3 |
+ mapped_blocks = sbi->sect_per_clus - sec_offset;
|
|
Kmods SIG |
50e2b3 |
+ max_blocks = min(mapped_blocks, max_blocks);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* Treat newly added block / cluster */
|
|
Kmods SIG |
50e2b3 |
+ if (iblock < last_block)
|
|
Kmods SIG |
50e2b3 |
+ create = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (create || buffer_delay(bh_result)) {
|
|
Kmods SIG |
50e2b3 |
+ pos = EXFAT_BLK_TO_B((iblock + 1), sb);
|
|
Kmods SIG |
50e2b3 |
+ if (ei->i_size_ondisk < pos)
|
|
Kmods SIG |
50e2b3 |
+ ei->i_size_ondisk = pos;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (create) {
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_map_new_buffer(ei, bh_result, pos);
|
|
Kmods SIG |
50e2b3 |
+ if (err) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "requested for bmap out of range(pos : (%llu) > i_size_aligned(%llu)\n",
|
|
Kmods SIG |
50e2b3 |
+ pos, ei->i_size_aligned);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock_ret;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (buffer_delay(bh_result))
|
|
Kmods SIG |
50e2b3 |
+ clear_buffer_delay(bh_result);
|
|
Kmods SIG |
50e2b3 |
+ map_bh(bh_result, sb, phys);
|
|
Kmods SIG |
50e2b3 |
+done:
|
|
Kmods SIG |
50e2b3 |
+ bh_result->b_size = EXFAT_BLK_TO_B(max_blocks, sb);
|
|
Kmods SIG |
50e2b3 |
+unlock_ret:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&sbi->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_readpage(struct file *file, struct page *page)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return mpage_readpage(page, exfat_get_block);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_readpages(struct file *file, struct address_space *mapping,
|
|
Kmods SIG |
50e2b3 |
+ struct list_head *pages, unsigned int nr_pages)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return mpage_readpages(mapping, pages, nr_pages, exfat_get_block);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_writepage(struct page *page, struct writeback_control *wbc)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return block_write_full_page(page, exfat_get_block, wbc);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_writepages(struct address_space *mapping,
|
|
Kmods SIG |
50e2b3 |
+ struct writeback_control *wbc)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return mpage_writepages(mapping, wbc, exfat_get_block);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static void exfat_write_failed(struct address_space *mapping, loff_t to)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode = mapping->host;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (to > i_size_read(inode)) {
|
|
Kmods SIG |
50e2b3 |
+ truncate_pagecache(inode, i_size_read(inode));
|
|
Kmods SIG |
50e2b3 |
+ exfat_truncate(inode, EXFAT_I(inode)->i_size_aligned);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_write_begin(struct file *file, struct address_space *mapping,
|
|
Kmods SIG |
50e2b3 |
+ loff_t pos, unsigned int len, unsigned int flags,
|
|
Kmods SIG |
50e2b3 |
+ struct page **pagep, void **fsdata)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ *pagep = NULL;
|
|
Kmods SIG |
50e2b3 |
+ ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
|
|
Kmods SIG |
50e2b3 |
+ exfat_get_block,
|
|
Kmods SIG |
50e2b3 |
+ &EXFAT_I(mapping->host)->i_size_ondisk);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ret < 0)
|
|
Kmods SIG |
50e2b3 |
+ exfat_write_failed(mapping, pos+len);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_write_end(struct file *file, struct address_space *mapping,
|
|
Kmods SIG |
50e2b3 |
+ loff_t pos, unsigned int len, unsigned int copied,
|
|
Kmods SIG |
50e2b3 |
+ struct page *pagep, void *fsdata)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode = mapping->host;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ int err;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (EXFAT_I(inode)->i_size_aligned < i_size_read(inode)) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(inode->i_sb,
|
|
Kmods SIG |
50e2b3 |
+ "invalid size(size(%llu) > aligned(%llu)\n",
|
|
Kmods SIG |
50e2b3 |
+ i_size_read(inode), EXFAT_I(inode)->i_size_aligned);
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (err < len)
|
|
Kmods SIG |
50e2b3 |
+ exfat_write_failed(mapping, pos+len);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (!(err < 0) && !(ei->attr & ATTR_ARCHIVE)) {
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mtime = inode->i_ctime = current_time(inode);
|
|
Kmods SIG |
50e2b3 |
+ ei->attr |= ATTR_ARCHIVE;
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(inode);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct address_space *mapping = iocb->ki_filp->f_mapping;
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode = mapping->host;
|
|
Kmods SIG |
50e2b3 |
+ loff_t size = iocb->ki_pos + iov_iter_count(iter);
|
|
Kmods SIG |
50e2b3 |
+ int rw = iov_iter_rw(iter);
|
|
Kmods SIG |
50e2b3 |
+ ssize_t ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (rw == WRITE) {
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * FIXME: blockdev_direct_IO() doesn't use ->write_begin(),
|
|
Kmods SIG |
50e2b3 |
+ * so we need to update the ->i_size_aligned to block boundary.
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * But we must fill the remaining area or hole by nul for
|
|
Kmods SIG |
50e2b3 |
+ * updating ->i_size_aligned
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * Return 0, and fallback to normal buffered write.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (EXFAT_I(inode)->i_size_aligned < size)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Need to use the DIO_LOCKING for avoiding the race
|
|
Kmods SIG |
50e2b3 |
+ * condition of exfat_get_block() and ->truncate().
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ ret = blockdev_direct_IO(iocb, inode, iter, exfat_get_block);
|
|
Kmods SIG |
50e2b3 |
+ if (ret < 0 && (rw & WRITE))
|
|
Kmods SIG |
50e2b3 |
+ exfat_write_failed(mapping, size);
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static sector_t exfat_aop_bmap(struct address_space *mapping, sector_t block)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ sector_t blocknr;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* exfat_get_cluster() assumes the requested blocknr isn't truncated. */
|
|
Kmods SIG |
50e2b3 |
+ down_read(&EXFAT_I(mapping->host)->truncate_lock);
|
|
Kmods SIG |
50e2b3 |
+ blocknr = generic_block_bmap(mapping, block, exfat_get_block);
|
|
Kmods SIG |
50e2b3 |
+ up_read(&EXFAT_I(mapping->host)->truncate_lock);
|
|
Kmods SIG |
50e2b3 |
+ return blocknr;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * exfat_block_truncate_page() zeroes out a mapping from file offset `from'
|
|
Kmods SIG |
50e2b3 |
+ * up to the end of the block which corresponds to `from'.
|
|
Kmods SIG |
50e2b3 |
+ * This is required during truncate to physically zeroout the tail end
|
|
Kmods SIG |
50e2b3 |
+ * of that block so it doesn't yield old data if the file is later grown.
|
|
Kmods SIG |
50e2b3 |
+ * Also, avoid causing failure from fsx for cases of "data past EOF"
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+int exfat_block_truncate_page(struct inode *inode, loff_t from)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return block_truncate_page(inode->i_mapping, from, exfat_get_block);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static const struct address_space_operations exfat_aops = {
|
|
Kmods SIG |
50e2b3 |
+ .readpage = exfat_readpage,
|
|
Kmods SIG |
50e2b3 |
+ .readpages = exfat_readpages,
|
|
Kmods SIG |
50e2b3 |
+ .writepage = exfat_writepage,
|
|
Kmods SIG |
50e2b3 |
+ .writepages = exfat_writepages,
|
|
Kmods SIG |
50e2b3 |
+ .write_begin = exfat_write_begin,
|
|
Kmods SIG |
50e2b3 |
+ .write_end = exfat_write_end,
|
|
Kmods SIG |
50e2b3 |
+ .direct_IO = exfat_direct_IO,
|
|
Kmods SIG |
50e2b3 |
+ .bmap = exfat_aop_bmap
|
|
Kmods SIG |
50e2b3 |
+};
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline unsigned long exfat_hash(loff_t i_pos)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return hash_32(i_pos, EXFAT_HASH_BITS);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_hash_inode(struct inode *inode, loff_t i_pos)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
|
|
Kmods SIG |
50e2b3 |
+ struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&sbi->inode_hash_lock);
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->i_pos = i_pos;
|
|
Kmods SIG |
50e2b3 |
+ hlist_add_head(&EXFAT_I(inode)->i_hash_fat, head);
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&sbi->inode_hash_lock);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_unhash_inode(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&sbi->inode_hash_lock);
|
|
Kmods SIG |
50e2b3 |
+ hlist_del_init(&EXFAT_I(inode)->i_hash_fat);
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->i_pos = 0;
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&sbi->inode_hash_lock);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+struct inode *exfat_iget(struct super_block *sb, loff_t i_pos)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *info;
|
|
Kmods SIG |
50e2b3 |
+ struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode = NULL;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&sbi->inode_hash_lock);
|
|
Kmods SIG |
50e2b3 |
+ hlist_for_each_entry(info, head, i_hash_fat) {
|
|
Kmods SIG |
50e2b3 |
+ WARN_ON(info->vfs_inode.i_sb != sb);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (i_pos != info->i_pos)
|
|
Kmods SIG |
50e2b3 |
+ continue;
|
|
Kmods SIG |
50e2b3 |
+ inode = igrab(&info->vfs_inode);
|
|
Kmods SIG |
50e2b3 |
+ if (inode)
|
|
Kmods SIG |
50e2b3 |
+ break;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&sbi->inode_hash_lock);
|
|
Kmods SIG |
50e2b3 |
+ return inode;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* doesn't deal with root inode */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ loff_t size = info->size;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(&ei->dir, &info->dir, sizeof(struct exfat_chain));
|
|
Kmods SIG |
50e2b3 |
+ ei->entry = info->entry;
|
|
Kmods SIG |
50e2b3 |
+ ei->attr = info->attr;
|
|
Kmods SIG |
50e2b3 |
+ ei->start_clu = info->start_clu;
|
|
Kmods SIG |
50e2b3 |
+ ei->flags = info->flags;
|
|
Kmods SIG |
50e2b3 |
+ ei->type = info->type;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ei->version = 0;
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_stat.eidx = 0;
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_stat.clu = info->start_clu;
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_femp.eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+ ei->rwoffset = 0;
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_bmap.off = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ ei->i_pos = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode->i_uid = sbi->options.fs_uid;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_gid = sbi->options.fs_gid;
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(inode);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_generation = prandom_u32();
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (info->attr & ATTR_SUBDIR) { /* directory */
|
|
Kmods SIG |
50e2b3 |
+ inode->i_generation &= ~1;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mode = exfat_make_mode(sbi, info->attr, 0777);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_op = &exfat_dir_inode_operations;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_fop = &exfat_dir_operations;
|
|
Kmods SIG |
50e2b3 |
+ set_nlink(inode, info->num_subdirs);
|
|
Kmods SIG |
50e2b3 |
+ } else { /* regular file */
|
|
Kmods SIG |
50e2b3 |
+ inode->i_generation |= 1;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mode = exfat_make_mode(sbi, info->attr, 0777);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_op = &exfat_file_inode_operations;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_fop = &exfat_file_operations;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mapping->a_ops = &exfat_aops;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mapping->nrpages = 0;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_size_write(inode, size);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* ondisk and aligned size should be aligned with block size */
|
|
Kmods SIG |
50e2b3 |
+ if (size & (inode->i_sb->s_blocksize - 1)) {
|
|
Kmods SIG |
50e2b3 |
+ size |= (inode->i_sb->s_blocksize - 1);
|
|
Kmods SIG |
50e2b3 |
+ size++;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ei->i_size_aligned = size;
|
|
Kmods SIG |
50e2b3 |
+ ei->i_size_ondisk = size;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_save_attr(inode, info->attr);
|
|
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 |
+ inode->i_mtime = info->mtime;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_ctime = info->mtime;
|
|
Kmods SIG |
50e2b3 |
+ ei->i_crtime = info->crtime;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_atime = info->atime;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_init_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+struct inode *exfat_build_inode(struct super_block *sb,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dir_entry *info, loff_t i_pos)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode;
|
|
Kmods SIG |
50e2b3 |
+ int err;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode = exfat_iget(sb, i_pos);
|
|
Kmods SIG |
50e2b3 |
+ if (inode)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ inode = new_inode(sb);
|
|
Kmods SIG |
50e2b3 |
+ if (!inode) {
|
|
Kmods SIG |
50e2b3 |
+ inode = ERR_PTR(-ENOMEM);
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ inode->i_ino = iunique(sb, EXFAT_ROOT_INO);
|
|
Kmods SIG |
50e2b3 |
+ inode_set_iversion(inode, 1);
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_fill_inode(inode, info);
|
|
Kmods SIG |
50e2b3 |
+ if (err) {
|
|
Kmods SIG |
50e2b3 |
+ iput(inode);
|
|
Kmods SIG |
50e2b3 |
+ inode = ERR_PTR(err);
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ exfat_hash_inode(inode, i_pos);
|
|
Kmods SIG |
50e2b3 |
+ insert_inode_hash(inode);
|
|
Kmods SIG |
50e2b3 |
+out:
|
|
Kmods SIG |
50e2b3 |
+ return inode;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_evict_inode(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ truncate_inode_pages(&inode->i_data, 0);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (!inode->i_nlink) {
|
|
Kmods SIG |
50e2b3 |
+ i_size_write(inode, 0);
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ __exfat_truncate(inode, 0);
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ invalidate_inode_buffers(inode);
|
|
Kmods SIG |
50e2b3 |
+ clear_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_inval_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_unhash_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
diff --git a/src/namei.c b/src/namei.c
|
|
Kmods SIG |
50e2b3 |
new file mode 100644
|
|
Kmods SIG |
50e2b3 |
index 0000000000000000000000000000000000000000..a8681d91f56900107ea3df90e2b6dd986045a7bc
|
|
Kmods SIG |
50e2b3 |
--- /dev/null
|
|
Kmods SIG |
50e2b3 |
+++ b/src/namei.c
|
|
Kmods SIG |
50e2b3 |
@@ -0,0 +1,1448 @@
|
|
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/iversion.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/namei.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/slab.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/buffer_head.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/nls.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 inline unsigned long exfat_d_version(struct dentry *dentry)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return (unsigned long) dentry->d_fsdata;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline void exfat_d_version_set(struct dentry *dentry,
|
|
Kmods SIG |
50e2b3 |
+ unsigned long version)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ dentry->d_fsdata = (void *) version;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * If new entry was created in the parent, it could create the 8.3 alias (the
|
|
Kmods SIG |
50e2b3 |
+ * shortname of logname). So, the parent may have the negative-dentry which
|
|
Kmods SIG |
50e2b3 |
+ * matches the created 8.3 alias.
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * If it happened, the negative dentry isn't actually negative anymore. So,
|
|
Kmods SIG |
50e2b3 |
+ * drop it.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_d_revalidate(struct dentry *dentry, unsigned int flags)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (flags & LOOKUP_RCU)
|
|
Kmods SIG |
50e2b3 |
+ return -ECHILD;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * This is not negative dentry. Always valid.
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * Note, rename() to existing directory entry will have ->d_inode, and
|
|
Kmods SIG |
50e2b3 |
+ * will use existing name which isn't specified name by user.
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * We may be able to drop this positive dentry here. But dropping
|
|
Kmods SIG |
50e2b3 |
+ * positive dentry isn't good idea. So it's unsupported like
|
|
Kmods SIG |
50e2b3 |
+ * rename("filename", "FILENAME") for now.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (d_really_is_positive(dentry))
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Drop the negative dentry, in order to make sure to use the case
|
|
Kmods SIG |
50e2b3 |
+ * sensitive name which is specified by user if this is for creation.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&dentry->d_lock);
|
|
Kmods SIG |
50e2b3 |
+ ret = inode_eq_iversion(d_inode(dentry->d_parent),
|
|
Kmods SIG |
50e2b3 |
+ exfat_d_version(dentry));
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&dentry->d_lock);
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* returns the length of a struct qstr, ignoring trailing dots */
|
|
Kmods SIG |
50e2b3 |
+static unsigned int exfat_striptail_len(unsigned int len, const char *name)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ while (len && name[len - 1] == '.')
|
|
Kmods SIG |
50e2b3 |
+ len--;
|
|
Kmods SIG |
50e2b3 |
+ return len;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * Compute the hash for the exfat name corresponding to the dentry. If the name
|
|
Kmods SIG |
50e2b3 |
+ * is invalid, we leave the hash code unchanged so that the existing dentry can
|
|
Kmods SIG |
50e2b3 |
+ * be used. The exfat fs routines will return ENOENT or EINVAL as appropriate.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dentry->d_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct nls_table *t = EXFAT_SB(sb)->nls_io;
|
|
Kmods SIG |
50e2b3 |
+ const unsigned char *name = qstr->name;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int len = exfat_striptail_len(qstr->len, qstr->name);
|
|
Kmods SIG |
50e2b3 |
+ unsigned long hash = init_name_hash(dentry);
|
|
Kmods SIG |
50e2b3 |
+ int i, charlen;
|
|
Kmods SIG |
50e2b3 |
+ wchar_t c;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ for (i = 0; i < len; i += charlen) {
|
|
Kmods SIG |
50e2b3 |
+ charlen = t->char2uni(&name[i], len - i, &c);
|
|
Kmods SIG |
50e2b3 |
+ if (charlen < 0)
|
|
Kmods SIG |
50e2b3 |
+ return charlen;
|
|
Kmods SIG |
50e2b3 |
+ hash = partial_name_hash(exfat_toupper(sb, c), hash);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ qstr->hash = end_name_hash(hash);
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_d_cmp(const struct dentry *dentry, unsigned int len,
|
|
Kmods SIG |
50e2b3 |
+ const char *str, const struct qstr *name)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dentry->d_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct nls_table *t = EXFAT_SB(sb)->nls_io;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int alen = exfat_striptail_len(name->len, name->name);
|
|
Kmods SIG |
50e2b3 |
+ unsigned int blen = exfat_striptail_len(len, str);
|
|
Kmods SIG |
50e2b3 |
+ wchar_t c1, c2;
|
|
Kmods SIG |
50e2b3 |
+ int charlen, i;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (alen != blen)
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ for (i = 0; i < len; i += charlen) {
|
|
Kmods SIG |
50e2b3 |
+ charlen = t->char2uni(&name->name[i], alen - i, &c1;;
|
|
Kmods SIG |
50e2b3 |
+ if (charlen < 0)
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+ if (charlen != t->char2uni(&str[i], blen - i, &c2))
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_toupper(sb, c1) != exfat_toupper(sb, c2))
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+const struct dentry_operations exfat_dentry_ops = {
|
|
Kmods SIG |
50e2b3 |
+ .d_revalidate = exfat_d_revalidate,
|
|
Kmods SIG |
50e2b3 |
+ .d_hash = exfat_d_hash,
|
|
Kmods SIG |
50e2b3 |
+ .d_compare = exfat_d_cmp,
|
|
Kmods SIG |
50e2b3 |
+};
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_utf8_d_hash(const struct dentry *dentry, struct qstr *qstr)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dentry->d_sb;
|
|
Kmods SIG |
50e2b3 |
+ const unsigned char *name = qstr->name;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int len = exfat_striptail_len(qstr->len, qstr->name);
|
|
Kmods SIG |
50e2b3 |
+ unsigned long hash = init_name_hash(dentry);
|
|
Kmods SIG |
50e2b3 |
+ int i, charlen;
|
|
Kmods SIG |
50e2b3 |
+ unicode_t u;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ for (i = 0; i < len; i += charlen) {
|
|
Kmods SIG |
50e2b3 |
+ charlen = utf8_to_utf32(&name[i], len - i, &u);
|
|
Kmods SIG |
50e2b3 |
+ if (charlen < 0)
|
|
Kmods SIG |
50e2b3 |
+ return charlen;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Convert to UTF-16: code points above U+FFFF are encoded as
|
|
Kmods SIG |
50e2b3 |
+ * surrogate pairs.
|
|
Kmods SIG |
50e2b3 |
+ * exfat_toupper() works only for code points up to the U+FFFF.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (u > 0xFFFF) {
|
|
Kmods SIG |
50e2b3 |
+ hash = partial_name_hash(exfat_high_surrogate(u), hash);
|
|
Kmods SIG |
50e2b3 |
+ hash = partial_name_hash(exfat_low_surrogate(u), hash);
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ hash = partial_name_hash(exfat_toupper(sb, u), hash);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ qstr->hash = end_name_hash(hash);
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_utf8_d_cmp(const struct dentry *dentry, unsigned int len,
|
|
Kmods SIG |
50e2b3 |
+ const char *str, const struct qstr *name)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dentry->d_sb;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int alen = exfat_striptail_len(name->len, name->name);
|
|
Kmods SIG |
50e2b3 |
+ unsigned int blen = exfat_striptail_len(len, str);
|
|
Kmods SIG |
50e2b3 |
+ unicode_t u_a, u_b;
|
|
Kmods SIG |
50e2b3 |
+ int charlen, i;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (alen != blen)
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ for (i = 0; i < alen; i += charlen) {
|
|
Kmods SIG |
50e2b3 |
+ charlen = utf8_to_utf32(&name->name[i], alen - i, &u_a);
|
|
Kmods SIG |
50e2b3 |
+ if (charlen < 0)
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+ if (charlen != utf8_to_utf32(&str[i], blen - i, &u_b))
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (u_a <= 0xFFFF && u_b <= 0xFFFF) {
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_toupper(sb, u_a) != exfat_toupper(sb, u_b))
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+ } else if (u_a > 0xFFFF && u_b > 0xFFFF) {
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_low_surrogate(u_a) !=
|
|
Kmods SIG |
50e2b3 |
+ exfat_low_surrogate(u_b) ||
|
|
Kmods SIG |
50e2b3 |
+ exfat_high_surrogate(u_a) !=
|
|
Kmods SIG |
50e2b3 |
+ exfat_high_surrogate(u_b))
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ return 1;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+const struct dentry_operations exfat_utf8_dentry_ops = {
|
|
Kmods SIG |
50e2b3 |
+ .d_revalidate = exfat_d_revalidate,
|
|
Kmods SIG |
50e2b3 |
+ .d_hash = exfat_utf8_d_hash,
|
|
Kmods SIG |
50e2b3 |
+ .d_compare = exfat_utf8_d_cmp,
|
|
Kmods SIG |
50e2b3 |
+};
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* used only in search empty_slot() */
|
|
Kmods SIG |
50e2b3 |
+#define CNT_UNUSED_NOHIT (-1)
|
|
Kmods SIG |
50e2b3 |
+#define CNT_UNUSED_HIT (-2)
|
|
Kmods SIG |
50e2b3 |
+/* search EMPTY CONTINUOUS "num_entries" entries */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_search_empty_slot(struct super_block *sb,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_hint_femp *hint_femp, struct exfat_chain *p_dir,
|
|
Kmods SIG |
50e2b3 |
+ int num_entries)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int i, dentry, num_empty = 0;
|
|
Kmods SIG |
50e2b3 |
+ int dentries_per_clu;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int type;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain clu;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *bh;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ dentries_per_clu = sbi->dentries_per_clu;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (hint_femp->eidx != EXFAT_HINT_NONE) {
|
|
Kmods SIG |
50e2b3 |
+ dentry = hint_femp->eidx;
|
|
Kmods SIG |
50e2b3 |
+ if (num_entries <= hint_femp->count) {
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+ return dentry;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_dup(&clu, &hint_femp->cur);
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_dup(&clu, p_dir);
|
|
Kmods SIG |
50e2b3 |
+ dentry = 0;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ while (clu.dir != EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ i = dentry & (dentries_per_clu - 1);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ for (; i < dentries_per_clu; i++, dentry++) {
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, &clu, i, &bh, NULL);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ type = exfat_get_entry_type(ep);
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (type == TYPE_UNUSED || type == TYPE_DELETED) {
|
|
Kmods SIG |
50e2b3 |
+ num_empty++;
|
|
Kmods SIG |
50e2b3 |
+ if (hint_femp->eidx == EXFAT_HINT_NONE) {
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->eidx = dentry;
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->count = CNT_UNUSED_NOHIT;
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&hint_femp->cur,
|
|
Kmods SIG |
50e2b3 |
+ clu.dir, clu.size, clu.flags);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (type == TYPE_UNUSED &&
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->count != CNT_UNUSED_HIT)
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->count = CNT_UNUSED_HIT;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ if (hint_femp->eidx != EXFAT_HINT_NONE &&
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->count == CNT_UNUSED_HIT) {
|
|
Kmods SIG |
50e2b3 |
+ /* unused empty group means
|
|
Kmods SIG |
50e2b3 |
+ * an empty group which includes
|
|
Kmods SIG |
50e2b3 |
+ * unused dentry
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "found bogus dentry(%d) beyond unused empty group(%d) (start_clu : %u, cur_clu : %u)",
|
|
Kmods SIG |
50e2b3 |
+ dentry, hint_femp->eidx,
|
|
Kmods SIG |
50e2b3 |
+ p_dir->dir, clu.dir);
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_empty = 0;
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (num_empty >= num_entries) {
|
|
Kmods SIG |
50e2b3 |
+ /* found and invalidate hint_femp */
|
|
Kmods SIG |
50e2b3 |
+ hint_femp->eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+ return (dentry - (num_entries - 1));
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (clu.flags == ALLOC_NO_FAT_CHAIN) {
|
|
Kmods SIG |
50e2b3 |
+ if (--clu.size > 0)
|
|
Kmods SIG |
50e2b3 |
+ clu.dir++;
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ clu.dir = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_next_cluster(sb, &clu.dir))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return -ENOSPC;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_check_max_dentries(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ if (EXFAT_B_TO_DEN(i_size_read(inode)) >= MAX_EXFAT_DENTRIES) {
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * exFAT spec allows a dir to grow upto 8388608(256MB)
|
|
Kmods SIG |
50e2b3 |
+ * dentries
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ return -ENOSPC;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* find empty directory entry.
|
|
Kmods SIG |
50e2b3 |
+ * if there isn't any empty slot, expand cluster chain.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_find_empty_entry(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain *p_dir, int num_entries)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int dentry;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int ret, last_clu;
|
|
Kmods SIG |
50e2b3 |
+ sector_t sector;
|
|
Kmods SIG |
50e2b3 |
+ loff_t size = 0;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain clu;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep = NULL;
|
|
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_hint_femp hint_femp;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ hint_femp.eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->hint_femp.eidx != EXFAT_HINT_NONE) {
|
|
Kmods SIG |
50e2b3 |
+ memcpy(&hint_femp, &ei->hint_femp,
|
|
Kmods SIG |
50e2b3 |
+ sizeof(struct exfat_hint_femp));
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_femp.eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir,
|
|
Kmods SIG |
50e2b3 |
+ num_entries)) < 0) {
|
|
Kmods SIG |
50e2b3 |
+ if (dentry == -EIO)
|
|
Kmods SIG |
50e2b3 |
+ break;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_check_max_dentries(inode))
|
|
Kmods SIG |
50e2b3 |
+ return -ENOSPC;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* we trust p_dir->size regardless of FAT type */
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_find_last_cluster(sb, p_dir, &last_clu))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Allocate new cluster to this directory
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* allocate a cluster */
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_alloc_cluster(inode, 1, &clu);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_zeroed_cluster(inode, clu.dir))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* append to the FAT chain */
|
|
Kmods SIG |
50e2b3 |
+ if (clu.flags != p_dir->flags) {
|
|
Kmods SIG |
50e2b3 |
+ /* no-fat-chain bit is disabled,
|
|
Kmods SIG |
50e2b3 |
+ * so fat-chain should be synced with alloc-bitmap
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size);
|
|
Kmods SIG |
50e2b3 |
+ p_dir->flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ hint_femp.cur.flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (clu.flags == ALLOC_FAT_CHAIN)
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_ent_set(sb, last_clu, clu.dir))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (hint_femp.eidx == EXFAT_HINT_NONE) {
|
|
Kmods SIG |
50e2b3 |
+ /* the special case that new dentry
|
|
Kmods SIG |
50e2b3 |
+ * should be allocated from the start of new cluster
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ hint_femp.eidx = EXFAT_B_TO_DEN_IDX(p_dir->size, sbi);
|
|
Kmods SIG |
50e2b3 |
+ hint_femp.count = sbi->dentries_per_clu;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&hint_femp.cur, clu.dir, 0, clu.flags);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ hint_femp.cur.size++;
|
|
Kmods SIG |
50e2b3 |
+ p_dir->size++;
|
|
Kmods SIG |
50e2b3 |
+ size = EXFAT_CLU_TO_B(p_dir->size, sbi);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* update the directory entry */
|
|
Kmods SIG |
50e2b3 |
+ if (p_dir->dir != sbi->root_dir) {
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *bh;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb,
|
|
Kmods SIG |
50e2b3 |
+ &(ei->dir), ei->entry + 1, &bh, §or);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.valid_size = cpu_to_le64(size);
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.size = ep->dentry.stream.valid_size;
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.stream.flags = p_dir->flags;
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_update_dir_chksum(inode, &(ei->dir),
|
|
Kmods SIG |
50e2b3 |
+ ei->entry))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* directory inode should be updated in here */
|
|
Kmods SIG |
50e2b3 |
+ i_size_write(inode, size);
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->i_size_ondisk += sbi->cluster_size;
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->i_size_aligned += sbi->cluster_size;
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->flags = p_dir->flags;
|
|
Kmods SIG |
50e2b3 |
+ inode->i_blocks += 1 << sbi->sect_per_clus_bits;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return dentry;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * Name Resolution Functions :
|
|
Kmods SIG |
50e2b3 |
+ * Zero if it was successful; otherwise nonzero.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+static int __exfat_resolve_path(struct inode *inode, const unsigned char *path,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
|
Kmods SIG |
50e2b3 |
+ int lookup)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int namelen;
|
|
Kmods SIG |
50e2b3 |
+ int lossy = NLS_NAME_NO_LOSSY;
|
|
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 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* strip all trailing periods */
|
|
Kmods SIG |
50e2b3 |
+ namelen = exfat_striptail_len(strlen(path), path);
|
|
Kmods SIG |
50e2b3 |
+ if (!namelen)
|
|
Kmods SIG |
50e2b3 |
+ return -ENOENT;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (strlen(path) > (MAX_NAME_LENGTH * MAX_CHARSET_SIZE))
|
|
Kmods SIG |
50e2b3 |
+ return -ENAMETOOLONG;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * strip all leading spaces :
|
|
Kmods SIG |
50e2b3 |
+ * "MS windows 7" supports leading spaces.
|
|
Kmods SIG |
50e2b3 |
+ * So we should skip this preprocessing for compatibility.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* file name conversion :
|
|
Kmods SIG |
50e2b3 |
+ * If lookup case, we allow bad-name for compatibility.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ namelen = exfat_nls_to_utf16(sb, path, namelen, p_uniname,
|
|
Kmods SIG |
50e2b3 |
+ &lossy);
|
|
Kmods SIG |
50e2b3 |
+ if (namelen < 0)
|
|
Kmods SIG |
50e2b3 |
+ return namelen; /* return error value */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if ((lossy && !lookup) || !namelen)
|
|
Kmods SIG |
50e2b3 |
+ return -EINVAL;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(p_dir, ei->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU(i_size_read(inode), sbi), ei->flags);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline int exfat_resolve_path(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ const unsigned char *path, struct exfat_chain *dir,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_uni_name *uni)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return __exfat_resolve_path(inode, path, dir, uni, 0);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline int exfat_resolve_path_for_lookup(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ const unsigned char *path, struct exfat_chain *dir,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_uni_name *uni)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return __exfat_resolve_path(inode, path, dir, uni, 1);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline loff_t exfat_make_i_pos(struct exfat_dir_entry *info)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return ((loff_t) info->dir.dir << 32) | (info->entry & 0xffffffff);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_add_entry(struct inode *inode, const char *path,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain *p_dir, unsigned int type,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dir_entry *info)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret, dentry, num_entries;
|
|
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_uni_name uniname;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain clu;
|
|
Kmods SIG |
50e2b3 |
+ int clu_size = 0;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int start_clu = EXFAT_FREE_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_resolve_path(inode, path, p_dir, &uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_entries = exfat_calc_num_entries(&uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (num_entries < 0) {
|
|
Kmods SIG |
50e2b3 |
+ ret = num_entries;
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* exfat_find_empty_entry must be called before alloc_cluster() */
|
|
Kmods SIG |
50e2b3 |
+ dentry = exfat_find_empty_entry(inode, p_dir, num_entries);
|
|
Kmods SIG |
50e2b3 |
+ if (dentry < 0) {
|
|
Kmods SIG |
50e2b3 |
+ ret = dentry; /* -EIO or -ENOSPC */
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (type == TYPE_DIR) {
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_alloc_new_dir(inode, &clu);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ start_clu = clu.dir;
|
|
Kmods SIG |
50e2b3 |
+ clu_size = sbi->cluster_size;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* update the directory entry */
|
|
Kmods SIG |
50e2b3 |
+ /* fill the dos name directory entry information of the created file.
|
|
Kmods SIG |
50e2b3 |
+ * the first cluster is not determined yet. (0)
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_init_dir_entry(inode, p_dir, dentry, type,
|
|
Kmods SIG |
50e2b3 |
+ start_clu, clu_size);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_init_ext_entry(inode, p_dir, dentry, num_entries, &uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(&info->dir, p_dir, sizeof(struct exfat_chain));
|
|
Kmods SIG |
50e2b3 |
+ info->entry = dentry;
|
|
Kmods SIG |
50e2b3 |
+ info->flags = ALLOC_NO_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ info->type = type;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (type == TYPE_FILE) {
|
|
Kmods SIG |
50e2b3 |
+ info->attr = ATTR_ARCHIVE;
|
|
Kmods SIG |
50e2b3 |
+ info->start_clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ info->size = 0;
|
|
Kmods SIG |
50e2b3 |
+ info->num_subdirs = 0;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ int count;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain cdir;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ info->attr = ATTR_SUBDIR;
|
|
Kmods SIG |
50e2b3 |
+ info->start_clu = start_clu;
|
|
Kmods SIG |
50e2b3 |
+ info->size = clu_size;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&cdir, info->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU(info->size, sbi), info->flags);
|
|
Kmods SIG |
50e2b3 |
+ count = exfat_count_dir_entries(sb, &cdir);
|
|
Kmods SIG |
50e2b3 |
+ if (count < 0)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ info->num_subdirs = count + EXFAT_MIN_SUBDIR;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ memset(&info->crtime, 0, sizeof(info->crtime));
|
|
Kmods SIG |
50e2b3 |
+ memset(&info->mtime, 0, sizeof(info->mtime));
|
|
Kmods SIG |
50e2b3 |
+ memset(&info->atime, 0, sizeof(info->atime));
|
|
Kmods SIG |
50e2b3 |
+out:
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
|
Kmods SIG |
50e2b3 |
+ bool excl)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dir->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain cdir;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dir_entry info;
|
|
Kmods SIG |
50e2b3 |
+ loff_t i_pos;
|
|
Kmods SIG |
50e2b3 |
+ int err;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_add_entry(dir, dentry->d_name.name, &cdir, TYPE_FILE,
|
|
Kmods SIG |
50e2b3 |
+ &info;;
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
50e2b3 |
+ if (err)
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(dir);
|
|
Kmods SIG |
50e2b3 |
+ dir->i_ctime = dir->i_mtime = current_time(dir);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(dir);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_pos = exfat_make_i_pos(&info;;
|
|
Kmods SIG |
50e2b3 |
+ inode = exfat_build_inode(sb, &info, i_pos);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_ERR(inode))
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(inode);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mtime = inode->i_atime = inode->i_ctime =
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->i_crtime = current_time(inode);
|
|
Kmods SIG |
50e2b3 |
+ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ d_instantiate(dentry, inode);
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* lookup a file */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_find(struct inode *dir, struct qstr *qname,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dir_entry *info)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret, dentry, num_entries, count;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain cdir;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_uni_name uni_name;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep, *ep2;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_entry_set_cache *es = NULL;
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dir->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (qname->len == 0)
|
|
Kmods SIG |
50e2b3 |
+ return -ENOENT;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* check the validity of directory name in the given pathname */
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_resolve_path_for_lookup(dir, qname->name, &cdir, &uni_name);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_entries = exfat_calc_num_entries(&uni_name);
|
|
Kmods SIG |
50e2b3 |
+ if (num_entries < 0)
|
|
Kmods SIG |
50e2b3 |
+ return num_entries;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* check the validation of hint_stat and initialize it if required */
|
|
Kmods SIG |
50e2b3 |
+ if (ei->version != (inode_peek_iversion_raw(dir) & 0xffffffff)) {
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_stat.clu = cdir.dir;
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_stat.eidx = 0;
|
|
Kmods SIG |
50e2b3 |
+ ei->version = (inode_peek_iversion_raw(dir) & 0xffffffff);
|
|
Kmods SIG |
50e2b3 |
+ ei->hint_femp.eidx = EXFAT_HINT_NONE;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* search the file name for directories */
|
|
Kmods SIG |
50e2b3 |
+ dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name,
|
|
Kmods SIG |
50e2b3 |
+ num_entries, TYPE_ALL);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if ((dentry < 0) && (dentry != -EEXIST))
|
|
Kmods SIG |
50e2b3 |
+ return dentry; /* -error value */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(&info->dir, &cdir.dir, sizeof(struct exfat_chain));
|
|
Kmods SIG |
50e2b3 |
+ info->entry = dentry;
|
|
Kmods SIG |
50e2b3 |
+ info->num_subdirs = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* root directory itself */
|
|
Kmods SIG |
50e2b3 |
+ if (unlikely(dentry == -EEXIST)) {
|
|
Kmods SIG |
50e2b3 |
+ int num_clu = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ info->type = TYPE_DIR;
|
|
Kmods SIG |
50e2b3 |
+ info->attr = ATTR_SUBDIR;
|
|
Kmods SIG |
50e2b3 |
+ info->flags = ALLOC_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ info->start_clu = sbi->root_dir;
|
|
Kmods SIG |
50e2b3 |
+ memset(&info->crtime, 0, sizeof(info->crtime));
|
|
Kmods SIG |
50e2b3 |
+ memset(&info->mtime, 0, sizeof(info->mtime));
|
|
Kmods SIG |
50e2b3 |
+ memset(&info->atime, 0, sizeof(info->atime));
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&cdir, sbi->root_dir, 0, ALLOC_FAT_CHAIN);
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_count_num_clusters(sb, &cdir, &num_clu))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ info->size = num_clu << sbi->cluster_size_bits;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ count = exfat_count_dir_entries(sb, &cdir);
|
|
Kmods SIG |
50e2b3 |
+ if (count < 0)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ info->num_subdirs = count;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES, &ep);
|
|
Kmods SIG |
50e2b3 |
+ if (!es)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ ep2 = ep + 1;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ info->type = exfat_get_entry_type(ep);
|
|
Kmods SIG |
50e2b3 |
+ info->attr = le16_to_cpu(ep->dentry.file.attr);
|
|
Kmods SIG |
50e2b3 |
+ info->size = le64_to_cpu(ep2->dentry.stream.valid_size);
|
|
Kmods SIG |
50e2b3 |
+ if ((info->type == TYPE_FILE) && (info->size == 0)) {
|
|
Kmods SIG |
50e2b3 |
+ info->flags = ALLOC_NO_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ info->start_clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ info->flags = ep2->dentry.stream.flags;
|
|
Kmods SIG |
50e2b3 |
+ info->start_clu =
|
|
Kmods SIG |
50e2b3 |
+ le32_to_cpu(ep2->dentry.stream.start_clu);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->start_clu == EXFAT_FREE_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "non-zero size file starts with zero cluster (size : %llu, p_dir : %u, entry : 0x%08x)",
|
|
Kmods SIG |
50e2b3 |
+ i_size_read(dir), ei->dir.dir, ei->entry);
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_get_entry_time(sbi, &info->crtime,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.create_tz,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.create_time,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.create_date,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.create_time_ms);
|
|
Kmods SIG |
50e2b3 |
+ exfat_get_entry_time(sbi, &info->mtime,
|
|
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 |
+ exfat_get_entry_time(sbi, &info->atime,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.access_tz,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.access_time,
|
|
Kmods SIG |
50e2b3 |
+ ep->dentry.file.access_date,
|
|
Kmods SIG |
50e2b3 |
+ 0);
|
|
Kmods SIG |
50e2b3 |
+ kfree(es);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (info->type == TYPE_DIR) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&cdir, info->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU(info->size, sbi), info->flags);
|
|
Kmods SIG |
50e2b3 |
+ count = exfat_count_dir_entries(sb, &cdir);
|
|
Kmods SIG |
50e2b3 |
+ if (count < 0)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ info->num_subdirs = count + EXFAT_MIN_SUBDIR;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_d_anon_disconn(struct dentry *dentry)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return IS_ROOT(dentry) && (dentry->d_flags & DCACHE_DISCONNECTED);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int flags)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dir->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode;
|
|
Kmods SIG |
50e2b3 |
+ struct dentry *alias;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dir_entry info;
|
|
Kmods SIG |
50e2b3 |
+ int err;
|
|
Kmods SIG |
50e2b3 |
+ loff_t i_pos;
|
|
Kmods SIG |
50e2b3 |
+ mode_t i_mode;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_find(dir, &dentry->d_name, &info;;
|
|
Kmods SIG |
50e2b3 |
+ if (err) {
|
|
Kmods SIG |
50e2b3 |
+ if (err == -ENOENT) {
|
|
Kmods SIG |
50e2b3 |
+ inode = NULL;
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_pos = exfat_make_i_pos(&info;;
|
|
Kmods SIG |
50e2b3 |
+ inode = exfat_build_inode(sb, &info, i_pos);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_ERR(inode)) {
|
|
Kmods SIG |
50e2b3 |
+ err = PTR_ERR(inode);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_mode = inode->i_mode;
|
|
Kmods SIG |
50e2b3 |
+ alias = d_find_alias(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Checking "alias->d_parent == dentry->d_parent" to make sure
|
|
Kmods SIG |
50e2b3 |
+ * FS is not corrupted (especially double linked dir).
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (alias && alias->d_parent == dentry->d_parent &&
|
|
Kmods SIG |
50e2b3 |
+ !exfat_d_anon_disconn(alias)) {
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Unhashed alias is able to exist because of revalidate()
|
|
Kmods SIG |
50e2b3 |
+ * called by lookup_fast. You can easily make this status
|
|
Kmods SIG |
50e2b3 |
+ * by calling create and lookup concurrently
|
|
Kmods SIG |
50e2b3 |
+ * In such case, we reuse an alias instead of new dentry
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (d_unhashed(alias)) {
|
|
Kmods SIG |
50e2b3 |
+ WARN_ON(alias->d_name.hash_len !=
|
|
Kmods SIG |
50e2b3 |
+ dentry->d_name.hash_len);
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_INFO,
|
|
Kmods SIG |
50e2b3 |
+ "rehashed a dentry(%p) in read lookup", alias);
|
|
Kmods SIG |
50e2b3 |
+ d_drop(dentry);
|
|
Kmods SIG |
50e2b3 |
+ d_rehash(alias);
|
|
Kmods SIG |
50e2b3 |
+ } else if (!S_ISDIR(i_mode)) {
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * This inode has non anonymous-DCACHE_DISCONNECTED
|
|
Kmods SIG |
50e2b3 |
+ * dentry. This means, the user did ->lookup() by an
|
|
Kmods SIG |
50e2b3 |
+ * another name (longname vs 8.3 alias of it) in past.
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * Switch to new one for reason of locality if possible.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ d_move(alias, dentry);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ iput(inode);
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return alias;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ dput(alias);
|
|
Kmods SIG |
50e2b3 |
+out:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ if (!inode)
|
|
Kmods SIG |
50e2b3 |
+ exfat_d_version_set(dentry, inode_query_iversion(dir));
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return d_splice_alias(inode, dentry);
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return ERR_PTR(err);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* remove an entry, BUT don't truncate */
|
|
Kmods SIG |
50e2b3 |
+static int exfat_unlink(struct inode *dir, struct dentry *dentry)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain cdir;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep;
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dir->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode = dentry->d_inode;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *bh;
|
|
Kmods SIG |
50e2b3 |
+ sector_t sector;
|
|
Kmods SIG |
50e2b3 |
+ int num_entries, entry, err = 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_dup(&cdir, &ei->dir);
|
|
Kmods SIG |
50e2b3 |
+ entry = ei->entry;
|
|
Kmods SIG |
50e2b3 |
+ if (ei->dir.dir == DIR_DELETED) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR, "abnormal access to deleted dentry");
|
|
Kmods SIG |
50e2b3 |
+ err = -ENOENT;
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, &cdir, entry, &bh, §or);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep) {
|
|
Kmods SIG |
50e2b3 |
+ err = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep);
|
|
Kmods SIG |
50e2b3 |
+ if (num_entries < 0) {
|
|
Kmods SIG |
50e2b3 |
+ err = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ num_entries++;
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+ /* update the directory entry */
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_remove_entries(dir, &cdir, entry, 0, num_entries)) {
|
|
Kmods SIG |
50e2b3 |
+ err = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* This doesn't modify ei */
|
|
Kmods SIG |
50e2b3 |
+ ei->dir.dir = DIR_DELETED;
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(dir);
|
|
Kmods SIG |
50e2b3 |
+ dir->i_mtime = dir->i_atime = current_time(dir);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(dir);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ clear_nlink(inode);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mtime = inode->i_atime = current_time(inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_unhash_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_d_version_set(dentry, inode_query_iversion(dir));
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = dir->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dir_entry info;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain cdir;
|
|
Kmods SIG |
50e2b3 |
+ loff_t i_pos;
|
|
Kmods SIG |
50e2b3 |
+ int err;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_add_entry(dir, dentry->d_name.name, &cdir, TYPE_DIR,
|
|
Kmods SIG |
50e2b3 |
+ &info;;
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
50e2b3 |
+ if (err)
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(dir);
|
|
Kmods SIG |
50e2b3 |
+ dir->i_ctime = dir->i_mtime = current_time(dir);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(dir);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(dir);
|
|
Kmods SIG |
50e2b3 |
+ inc_nlink(dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_pos = exfat_make_i_pos(&info;;
|
|
Kmods SIG |
50e2b3 |
+ inode = exfat_build_inode(sb, &info, i_pos);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_ERR(inode)) {
|
|
Kmods SIG |
50e2b3 |
+ err = PTR_ERR(inode);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(inode);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mtime = inode->i_atime = inode->i_ctime =
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(inode)->i_crtime = current_time(inode);
|
|
Kmods SIG |
50e2b3 |
+ /* timestamp is already written, so mark_inode_dirty() is unneeded. */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ d_instantiate(dentry, inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_check_dir_empty(struct super_block *sb,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain *p_dir)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int i, dentries_per_clu;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int type;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain clu;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *bh;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ dentries_per_clu = sbi->dentries_per_clu;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_dup(&clu, p_dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ while (clu.dir != EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ for (i = 0; i < dentries_per_clu; i++) {
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, &clu, i, &bh, NULL);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ type = exfat_get_entry_type(ep);
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+ if (type == TYPE_UNUSED)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (type != TYPE_FILE && type != TYPE_DIR)
|
|
Kmods SIG |
50e2b3 |
+ continue;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return -ENOTEMPTY;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (clu.flags == ALLOC_NO_FAT_CHAIN) {
|
|
Kmods SIG |
50e2b3 |
+ if (--clu.size > 0)
|
|
Kmods SIG |
50e2b3 |
+ clu.dir++;
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ clu.dir = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_next_cluster(sb, &(clu.dir)))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct inode *inode = dentry->d_inode;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain cdir, clu_to_free;
|
|
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 buffer_head *bh;
|
|
Kmods SIG |
50e2b3 |
+ sector_t sector;
|
|
Kmods SIG |
50e2b3 |
+ int num_entries, entry, err;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_dup(&cdir, &ei->dir);
|
|
Kmods SIG |
50e2b3 |
+ entry = ei->entry;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->dir.dir == DIR_DELETED) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR, "abnormal access to deleted dentry");
|
|
Kmods SIG |
50e2b3 |
+ err = -ENOENT;
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&clu_to_free, ei->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU_ROUND_UP(i_size_read(inode), sbi), ei->flags);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_check_dir_empty(sb, &clu_to_free);
|
|
Kmods SIG |
50e2b3 |
+ if (err) {
|
|
Kmods SIG |
50e2b3 |
+ if (err == -EIO)
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR,
|
|
Kmods SIG |
50e2b3 |
+ "failed to exfat_check_dir_empty : err(%d)",
|
|
Kmods SIG |
50e2b3 |
+ err);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, &cdir, entry, &bh, §or);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep) {
|
|
Kmods SIG |
50e2b3 |
+ err = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep);
|
|
Kmods SIG |
50e2b3 |
+ if (num_entries < 0) {
|
|
Kmods SIG |
50e2b3 |
+ err = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ num_entries++;
|
|
Kmods SIG |
50e2b3 |
+ brelse(bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ err = exfat_remove_entries(dir, &cdir, entry, 0, num_entries);
|
|
Kmods SIG |
50e2b3 |
+ if (err) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR,
|
|
Kmods SIG |
50e2b3 |
+ "failed to exfat_remove_entries : err(%d)",
|
|
Kmods SIG |
50e2b3 |
+ err);
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ ei->dir.dir = DIR_DELETED;
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(dir);
|
|
Kmods SIG |
50e2b3 |
+ dir->i_mtime = dir->i_atime = current_time(dir);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(dir);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(dir);
|
|
Kmods SIG |
50e2b3 |
+ drop_nlink(dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ clear_nlink(inode);
|
|
Kmods SIG |
50e2b3 |
+ inode->i_mtime = inode->i_atime = current_time(inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_unhash_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_d_version_set(dentry, inode_query_iversion(dir));
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(inode->i_sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
|
|
Kmods SIG |
50e2b3 |
+ int oldentry, struct exfat_uni_name *p_uniname,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret, num_old_entries, num_new_entries;
|
|
Kmods SIG |
50e2b3 |
+ sector_t sector_old, sector_new;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *epold, *epnew;
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = inode->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *new_bh, *old_bh;
|
|
Kmods SIG |
50e2b3 |
+ int sync = IS_DIRSYNC(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ epold = exfat_get_dentry(sb, p_dir, oldentry, &old_bh, §or_old);
|
|
Kmods SIG |
50e2b3 |
+ if (!epold)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_old_entries = exfat_count_ext_entries(sb, p_dir, oldentry, epold);
|
|
Kmods SIG |
50e2b3 |
+ if (num_old_entries < 0)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ num_old_entries++;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_new_entries = exfat_calc_num_entries(p_uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (num_new_entries < 0)
|
|
Kmods SIG |
50e2b3 |
+ return num_new_entries;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (num_old_entries < num_new_entries) {
|
|
Kmods SIG |
50e2b3 |
+ int newentry;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ newentry =
|
|
Kmods SIG |
50e2b3 |
+ exfat_find_empty_entry(inode, p_dir, num_new_entries);
|
|
Kmods SIG |
50e2b3 |
+ if (newentry < 0)
|
|
Kmods SIG |
50e2b3 |
+ return newentry; /* -EIO or -ENOSPC */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ epnew = exfat_get_dentry(sb, p_dir, newentry, &new_bh,
|
|
Kmods SIG |
50e2b3 |
+ §or_new);
|
|
Kmods SIG |
50e2b3 |
+ if (!epnew)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(epnew, epold, DENTRY_SIZE);
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_entry_type(epnew) == TYPE_FILE) {
|
|
Kmods SIG |
50e2b3 |
+ epnew->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE);
|
|
Kmods SIG |
50e2b3 |
+ ei->attr |= ATTR_ARCHIVE;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_bh(sb, new_bh, sync);
|
|
Kmods SIG |
50e2b3 |
+ brelse(old_bh);
|
|
Kmods SIG |
50e2b3 |
+ brelse(new_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh,
|
|
Kmods SIG |
50e2b3 |
+ §or_old);
|
|
Kmods SIG |
50e2b3 |
+ epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh,
|
|
Kmods SIG |
50e2b3 |
+ §or_new);
|
|
Kmods SIG |
50e2b3 |
+ if (!epold || !epnew)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(epnew, epold, DENTRY_SIZE);
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_bh(sb, new_bh, sync);
|
|
Kmods SIG |
50e2b3 |
+ brelse(old_bh);
|
|
Kmods SIG |
50e2b3 |
+ brelse(new_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_init_ext_entry(inode, p_dir, newentry,
|
|
Kmods SIG |
50e2b3 |
+ num_new_entries, p_uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_remove_entries(inode, p_dir, oldentry, 0,
|
|
Kmods SIG |
50e2b3 |
+ num_old_entries);
|
|
Kmods SIG |
50e2b3 |
+ ei->entry = newentry;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_entry_type(epold) == TYPE_FILE) {
|
|
Kmods SIG |
50e2b3 |
+ epold->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE);
|
|
Kmods SIG |
50e2b3 |
+ ei->attr |= ATTR_ARCHIVE;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_bh(sb, old_bh, sync);
|
|
Kmods SIG |
50e2b3 |
+ brelse(old_bh);
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_init_ext_entry(inode, p_dir, oldentry,
|
|
Kmods SIG |
50e2b3 |
+ num_new_entries, p_uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_remove_entries(inode, p_dir, oldentry, num_new_entries,
|
|
Kmods SIG |
50e2b3 |
+ num_old_entries);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
|
|
Kmods SIG |
50e2b3 |
+ int oldentry, struct exfat_chain *p_newdir,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret, newentry, num_new_entries, num_old_entries;
|
|
Kmods SIG |
50e2b3 |
+ sector_t sector_mov, sector_new;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *epmov, *epnew;
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = inode->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *mov_bh, *new_bh;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ epmov = exfat_get_dentry(sb, p_olddir, oldentry, &mov_bh, §or_mov);
|
|
Kmods SIG |
50e2b3 |
+ if (!epmov)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* check if the source and target directory is the same */
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_entry_type(epmov) == TYPE_DIR &&
|
|
Kmods SIG |
50e2b3 |
+ le32_to_cpu(epmov->dentry.stream.start_clu) == p_newdir->dir)
|
|
Kmods SIG |
50e2b3 |
+ return -EINVAL;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_old_entries = exfat_count_ext_entries(sb, p_olddir, oldentry,
|
|
Kmods SIG |
50e2b3 |
+ epmov);
|
|
Kmods SIG |
50e2b3 |
+ if (num_old_entries < 0)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ num_old_entries++;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_new_entries = exfat_calc_num_entries(p_uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (num_new_entries < 0)
|
|
Kmods SIG |
50e2b3 |
+ return num_new_entries;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries);
|
|
Kmods SIG |
50e2b3 |
+ if (newentry < 0)
|
|
Kmods SIG |
50e2b3 |
+ return newentry; /* -EIO or -ENOSPC */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh, §or_new);
|
|
Kmods SIG |
50e2b3 |
+ if (!epnew)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(epnew, epmov, DENTRY_SIZE);
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_get_entry_type(epnew) == TYPE_FILE) {
|
|
Kmods SIG |
50e2b3 |
+ epnew->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE);
|
|
Kmods SIG |
50e2b3 |
+ ei->attr |= ATTR_ARCHIVE;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_bh(sb, new_bh, IS_DIRSYNC(inode));
|
|
Kmods SIG |
50e2b3 |
+ brelse(mov_bh);
|
|
Kmods SIG |
50e2b3 |
+ brelse(new_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ epmov = exfat_get_dentry(sb, p_olddir, oldentry + 1, &mov_bh,
|
|
Kmods SIG |
50e2b3 |
+ §or_mov);
|
|
Kmods SIG |
50e2b3 |
+ epnew = exfat_get_dentry(sb, p_newdir, newentry + 1, &new_bh,
|
|
Kmods SIG |
50e2b3 |
+ §or_new);
|
|
Kmods SIG |
50e2b3 |
+ if (!epmov || !epnew)
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ memcpy(epnew, epmov, DENTRY_SIZE);
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_bh(sb, new_bh, IS_DIRSYNC(inode));
|
|
Kmods SIG |
50e2b3 |
+ brelse(mov_bh);
|
|
Kmods SIG |
50e2b3 |
+ brelse(new_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_init_ext_entry(inode, p_newdir, newentry, num_new_entries,
|
|
Kmods SIG |
50e2b3 |
+ p_uniname);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_remove_entries(inode, p_olddir, oldentry, 0, num_old_entries);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&ei->dir, p_newdir->dir, p_newdir->size,
|
|
Kmods SIG |
50e2b3 |
+ p_newdir->flags);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ei->entry = newentry;
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static void exfat_update_parent_info(struct exfat_inode_info *ei,
|
|
Kmods SIG |
50e2b3 |
+ struct inode *parent_inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(parent_inode->i_sb);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *parent_ei = EXFAT_I(parent_inode);
|
|
Kmods SIG |
50e2b3 |
+ loff_t parent_isize = i_size_read(parent_inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * the problem that struct exfat_inode_info caches wrong parent info.
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * because of flag-mismatch of ei->dir,
|
|
Kmods SIG |
50e2b3 |
+ * there is abnormal traversing cluster chain.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (unlikely(parent_ei->flags != ei->dir.flags ||
|
|
Kmods SIG |
50e2b3 |
+ parent_isize != EXFAT_CLU_TO_B(ei->dir.size, sbi) ||
|
|
Kmods SIG |
50e2b3 |
+ parent_ei->start_clu != ei->dir.dir)) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&ei->dir, parent_ei->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU_ROUND_UP(parent_isize, sbi),
|
|
Kmods SIG |
50e2b3 |
+ parent_ei->flags);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/* rename or move a old file into a new file */
|
|
Kmods SIG |
50e2b3 |
+static int __exfat_rename(struct inode *old_parent_inode,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei, struct inode *new_parent_inode,
|
|
Kmods SIG |
50e2b3 |
+ struct dentry *new_dentry)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ int ret;
|
|
Kmods SIG |
50e2b3 |
+ int dentry;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain olddir, newdir;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain *p_dir = NULL;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_uni_name uni_name;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_dentry *ep;
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = old_parent_inode->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
50e2b3 |
+ const unsigned char *new_path = new_dentry->d_name.name;
|
|
Kmods SIG |
50e2b3 |
+ struct inode *new_inode = new_dentry->d_inode;
|
|
Kmods SIG |
50e2b3 |
+ int num_entries;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *new_ei = NULL;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int new_entry_type = TYPE_UNUSED;
|
|
Kmods SIG |
50e2b3 |
+ int new_entry = 0;
|
|
Kmods SIG |
50e2b3 |
+ struct buffer_head *old_bh, *new_bh = NULL;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* check the validity of pointer parameters */
|
|
Kmods SIG |
50e2b3 |
+ if (new_path == NULL || strlen(new_path) == 0)
|
|
Kmods SIG |
50e2b3 |
+ return -EINVAL;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->dir.dir == DIR_DELETED) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR,
|
|
Kmods SIG |
50e2b3 |
+ "abnormal access to deleted source dentry");
|
|
Kmods SIG |
50e2b3 |
+ return -ENOENT;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_parent_info(ei, old_parent_inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_dup(&olddir, &ei->dir);
|
|
Kmods SIG |
50e2b3 |
+ dentry = ei->entry;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, &olddir, dentry, &old_bh, NULL);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep) {
|
|
Kmods SIG |
50e2b3 |
+ ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ brelse(old_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* check whether new dir is existing directory and empty */
|
|
Kmods SIG |
50e2b3 |
+ if (new_inode) {
|
|
Kmods SIG |
50e2b3 |
+ ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ new_ei = EXFAT_I(new_inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (new_ei->dir.dir == DIR_DELETED) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_ERR,
|
|
Kmods SIG |
50e2b3 |
+ "abnormal access to deleted target dentry");
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_update_parent_info(new_ei, new_parent_inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ p_dir = &(new_ei->dir);
|
|
Kmods SIG |
50e2b3 |
+ new_entry = new_ei->entry;
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh, NULL);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ new_entry_type = exfat_get_entry_type(ep);
|
|
Kmods SIG |
50e2b3 |
+ brelse(new_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* if new_inode exists, update ei */
|
|
Kmods SIG |
50e2b3 |
+ if (new_entry_type == TYPE_DIR) {
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain new_clu;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ new_clu.dir = new_ei->start_clu;
|
|
Kmods SIG |
50e2b3 |
+ new_clu.size =
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU_ROUND_UP(i_size_read(new_inode),
|
|
Kmods SIG |
50e2b3 |
+ sbi);
|
|
Kmods SIG |
50e2b3 |
+ new_clu.flags = new_ei->flags;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_check_dir_empty(sb, &new_clu);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* check the validity of directory name in the given new pathname */
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_resolve_path(new_parent_inode, new_path, &newdir,
|
|
Kmods SIG |
50e2b3 |
+ &uni_name);
|
|
Kmods SIG |
50e2b3 |
+ if (ret)
|
|
Kmods SIG |
50e2b3 |
+ goto out;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_DIRTY);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (olddir.dir == newdir.dir)
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_rename_file(new_parent_inode, &olddir, dentry,
|
|
Kmods SIG |
50e2b3 |
+ &uni_name, ei);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ ret = exfat_move_file(new_parent_inode, &olddir, dentry,
|
|
Kmods SIG |
50e2b3 |
+ &newdir, &uni_name, ei);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (!ret && new_inode) {
|
|
Kmods SIG |
50e2b3 |
+ /* delete entries of new_dir */
|
|
Kmods SIG |
50e2b3 |
+ ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh, NULL);
|
|
Kmods SIG |
50e2b3 |
+ if (!ep) {
|
|
Kmods SIG |
50e2b3 |
+ ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto del_out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ num_entries = exfat_count_ext_entries(sb, p_dir, new_entry, ep);
|
|
Kmods SIG |
50e2b3 |
+ if (num_entries < 0) {
|
|
Kmods SIG |
50e2b3 |
+ ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto del_out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ brelse(new_bh);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_remove_entries(new_inode, p_dir, new_entry, 0,
|
|
Kmods SIG |
50e2b3 |
+ num_entries + 1)) {
|
|
Kmods SIG |
50e2b3 |
+ ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ goto del_out;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* Free the clusters if new_inode is a dir(as if exfat_rmdir) */
|
|
Kmods SIG |
50e2b3 |
+ if (new_entry_type == TYPE_DIR) {
|
|
Kmods SIG |
50e2b3 |
+ /* new_ei, new_clu_to_free */
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_chain new_clu_to_free;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_chain_set(&new_clu_to_free, new_ei->start_clu,
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_B_TO_CLU_ROUND_UP(i_size_read(new_inode),
|
|
Kmods SIG |
50e2b3 |
+ sbi), new_ei->flags);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_free_cluster(new_inode, &new_clu_to_free)) {
|
|
Kmods SIG |
50e2b3 |
+ /* just set I/O error only */
|
|
Kmods SIG |
50e2b3 |
+ ret = -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_size_write(new_inode, 0);
|
|
Kmods SIG |
50e2b3 |
+ new_ei->start_clu = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+ new_ei->flags = ALLOC_NO_FAT_CHAIN;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+del_out:
|
|
Kmods SIG |
50e2b3 |
+ /* Update new_inode ei
|
|
Kmods SIG |
50e2b3 |
+ * Prevent syncing removed new_inode
|
|
Kmods SIG |
50e2b3 |
+ * (new_ei is already initialized above code ("if (new_inode)")
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ new_ei->dir.dir = DIR_DELETED;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
50e2b3 |
+out:
|
|
Kmods SIG |
50e2b3 |
+ return ret;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|
Kmods SIG |
50e2b3 |
+ struct inode *new_dir, struct dentry *new_dentry,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int flags)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct inode *old_inode, *new_inode;
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = old_dir->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ loff_t i_pos;
|
|
Kmods SIG |
50e2b3 |
+ int err;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * The VFS already checks for existence, so for local filesystems
|
|
Kmods SIG |
50e2b3 |
+ * the RENAME_NOREPLACE implementation is equivalent to plain rename.
|
|
Kmods SIG |
50e2b3 |
+ * Don't support any other flags
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (flags & ~RENAME_NOREPLACE)
|
|
Kmods SIG |
50e2b3 |
+ return -EINVAL;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ mutex_lock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ old_inode = old_dentry->d_inode;
|
|
Kmods SIG |
50e2b3 |
+ new_inode = new_dentry->d_inode;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ err = __exfat_rename(old_dir, EXFAT_I(old_inode), new_dir, new_dentry);
|
|
Kmods SIG |
50e2b3 |
+ if (err)
|
|
Kmods SIG |
50e2b3 |
+ goto unlock;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(new_dir);
|
|
Kmods SIG |
50e2b3 |
+ new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(new_dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(new_dir);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(new_dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ i_pos = ((loff_t)EXFAT_I(old_inode)->dir.dir << 32) |
|
|
Kmods SIG |
50e2b3 |
+ (EXFAT_I(old_inode)->entry & 0xffffffff);
|
|
Kmods SIG |
50e2b3 |
+ exfat_unhash_inode(old_inode);
|
|
Kmods SIG |
50e2b3 |
+ exfat_hash_inode(old_inode, i_pos);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(new_dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(old_inode);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(old_inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
|
|
Kmods SIG |
50e2b3 |
+ drop_nlink(old_dir);
|
|
Kmods SIG |
50e2b3 |
+ if (!new_inode)
|
|
Kmods SIG |
50e2b3 |
+ inc_nlink(new_dir);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ inode_inc_iversion(old_dir);
|
|
Kmods SIG |
50e2b3 |
+ old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
|
|
Kmods SIG |
50e2b3 |
+ if (IS_DIRSYNC(old_dir))
|
|
Kmods SIG |
50e2b3 |
+ exfat_sync_inode(old_dir);
|
|
Kmods SIG |
50e2b3 |
+ else
|
|
Kmods SIG |
50e2b3 |
+ mark_inode_dirty(old_dir);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (new_inode) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_unhash_inode(new_inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /* skip drop_nlink if new_inode already has been dropped */
|
|
Kmods SIG |
50e2b3 |
+ if (new_inode->i_nlink) {
|
|
Kmods SIG |
50e2b3 |
+ drop_nlink(new_inode);
|
|
Kmods SIG |
50e2b3 |
+ if (S_ISDIR(new_inode->i_mode))
|
|
Kmods SIG |
50e2b3 |
+ drop_nlink(new_inode);
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ exfat_msg(sb, KERN_WARNING,
|
|
Kmods SIG |
50e2b3 |
+ "abnormal access to an inode dropped");
|
|
Kmods SIG |
50e2b3 |
+ WARN_ON(new_inode->i_nlink == 0);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime =
|
|
Kmods SIG |
50e2b3 |
+ current_time(new_inode);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
|
Kmods SIG |
50e2b3 |
+ return err;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+const struct inode_operations exfat_dir_inode_operations = {
|
|
Kmods SIG |
50e2b3 |
+ .create = exfat_create,
|
|
Kmods SIG |
50e2b3 |
+ .lookup = exfat_lookup,
|
|
Kmods SIG |
50e2b3 |
+ .unlink = exfat_unlink,
|
|
Kmods SIG |
50e2b3 |
+ .mkdir = exfat_mkdir,
|
|
Kmods SIG |
50e2b3 |
+ .rmdir = exfat_rmdir,
|
|
Kmods SIG |
50e2b3 |
+ .rename = exfat_rename,
|
|
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 |
|