|
Kmods SIG |
50e2b3 |
From c35b6810c4952ae5776607e2c1d6a587425d5834 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:39 +0900
|
|
Kmods SIG |
50e2b3 |
Subject: [Backport c35b6810c495] exfat: add exfat cache
|
|
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 exfat cache.
|
|
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/cache.c | 325 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
Kmods SIG |
50e2b3 |
1 file changed, 325 insertions(+)
|
|
Kmods SIG |
50e2b3 |
create mode 100644 src/cache.c
|
|
Kmods SIG |
50e2b3 |
|
|
Kmods SIG |
50e2b3 |
diff --git a/src/cache.c b/src/cache.c
|
|
Kmods SIG |
50e2b3 |
new file mode 100644
|
|
Kmods SIG |
50e2b3 |
index 0000000000000000000000000000000000000000..03d0824fc368a5b10241082e271dd4bfefd26ada
|
|
Kmods SIG |
50e2b3 |
--- /dev/null
|
|
Kmods SIG |
50e2b3 |
+++ b/src/cache.c
|
|
Kmods SIG |
50e2b3 |
@@ -0,0 +1,325 @@
|
|
Kmods SIG |
50e2b3 |
+// SPDX-License-Identifier: GPL-2.0-or-later
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * linux/fs/fat/cache.c
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * Written 1992,1993 by Werner Almesberger
|
|
Kmods SIG |
50e2b3 |
+ *
|
|
Kmods SIG |
50e2b3 |
+ * Mar 1999. AV. Changed cache, so that it uses the starting cluster instead
|
|
Kmods SIG |
50e2b3 |
+ * of inode number.
|
|
Kmods SIG |
50e2b3 |
+ * May 1999. AV. Fixed the bogosity with FAT32 (read "FAT28"). Fscking lusers.
|
|
Kmods SIG |
50e2b3 |
+ * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+#include <linux/slab.h>
|
|
Kmods SIG |
50e2b3 |
+#include <asm/unaligned.h>
|
|
Kmods SIG |
50e2b3 |
+#include <linux/buffer_head.h>
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+#include "exfat_raw.h"
|
|
Kmods SIG |
50e2b3 |
+#include "exfat_fs.h"
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+#define EXFAT_CACHE_VALID 0
|
|
Kmods SIG |
50e2b3 |
+#define EXFAT_MAX_CACHE 16
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+struct exfat_cache {
|
|
Kmods SIG |
50e2b3 |
+ struct list_head cache_list;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int nr_contig; /* number of contiguous clusters */
|
|
Kmods SIG |
50e2b3 |
+ unsigned int fcluster; /* cluster number in the file. */
|
|
Kmods SIG |
50e2b3 |
+ unsigned int dcluster; /* cluster number on disk. */
|
|
Kmods SIG |
50e2b3 |
+};
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+struct exfat_cache_id {
|
|
Kmods SIG |
50e2b3 |
+ unsigned int id;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int nr_contig;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int fcluster;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int dcluster;
|
|
Kmods SIG |
50e2b3 |
+};
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static struct kmem_cache *exfat_cachep;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static void exfat_cache_init_once(void *c)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache *cache = (struct exfat_cache *)c;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ INIT_LIST_HEAD(&cache->cache_list);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+int exfat_cache_init(void)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ exfat_cachep = kmem_cache_create("exfat_cache",
|
|
Kmods SIG |
50e2b3 |
+ sizeof(struct exfat_cache),
|
|
Kmods SIG |
50e2b3 |
+ 0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_init_once);
|
|
Kmods SIG |
50e2b3 |
+ if (!exfat_cachep)
|
|
Kmods SIG |
50e2b3 |
+ return -ENOMEM;
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_cache_shutdown(void)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ if (!exfat_cachep)
|
|
Kmods SIG |
50e2b3 |
+ return;
|
|
Kmods SIG |
50e2b3 |
+ kmem_cache_destroy(exfat_cachep);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_cache_init_inode(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock_init(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ ei->nr_caches = 0;
|
|
Kmods SIG |
50e2b3 |
+ ei->cache_valid_id = EXFAT_CACHE_VALID + 1;
|
|
Kmods SIG |
50e2b3 |
+ INIT_LIST_HEAD(&ei->cache_lru);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline struct exfat_cache *exfat_cache_alloc(void)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ return kmem_cache_alloc(exfat_cachep, GFP_NOFS);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline void exfat_cache_free(struct exfat_cache *cache)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ WARN_ON(!list_empty(&cache->cache_list));
|
|
Kmods SIG |
50e2b3 |
+ kmem_cache_free(exfat_cachep, cache);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline void exfat_cache_update_lru(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache *cache)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->cache_lru.next != &cache->cache_list)
|
|
Kmods SIG |
50e2b3 |
+ list_move(&cache->cache_list, &ei->cache_lru);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static unsigned int exfat_cache_lookup(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int fclus, struct exfat_cache_id *cid,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int *cached_fclus, unsigned int *cached_dclus)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ static struct exfat_cache nohit = { .fcluster = 0, };
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache *hit = &nohit, *p;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int offset = EXFAT_EOF_CLUSTER;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ list_for_each_entry(p, &ei->cache_lru, cache_list) {
|
|
Kmods SIG |
50e2b3 |
+ /* Find the cache of "fclus" or nearest cache. */
|
|
Kmods SIG |
50e2b3 |
+ if (p->fcluster <= fclus && hit->fcluster < p->fcluster) {
|
|
Kmods SIG |
50e2b3 |
+ hit = p;
|
|
Kmods SIG |
50e2b3 |
+ if (hit->fcluster + hit->nr_contig < fclus) {
|
|
Kmods SIG |
50e2b3 |
+ offset = hit->nr_contig;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ offset = fclus - hit->fcluster;
|
|
Kmods SIG |
50e2b3 |
+ break;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ if (hit != &nohit) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_update_lru(inode, hit);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ cid->id = ei->cache_valid_id;
|
|
Kmods SIG |
50e2b3 |
+ cid->nr_contig = hit->nr_contig;
|
|
Kmods SIG |
50e2b3 |
+ cid->fcluster = hit->fcluster;
|
|
Kmods SIG |
50e2b3 |
+ cid->dcluster = hit->dcluster;
|
|
Kmods SIG |
50e2b3 |
+ *cached_fclus = cid->fcluster + offset;
|
|
Kmods SIG |
50e2b3 |
+ *cached_dclus = cid->dcluster + offset;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ return offset;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static struct exfat_cache *exfat_cache_merge(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache_id *new)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache *p;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ list_for_each_entry(p, &ei->cache_lru, cache_list) {
|
|
Kmods SIG |
50e2b3 |
+ /* Find the same part as "new" in cluster-chain. */
|
|
Kmods SIG |
50e2b3 |
+ if (p->fcluster == new->fcluster) {
|
|
Kmods SIG |
50e2b3 |
+ if (new->nr_contig > p->nr_contig)
|
|
Kmods SIG |
50e2b3 |
+ p->nr_contig = new->nr_contig;
|
|
Kmods SIG |
50e2b3 |
+ return p;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ return NULL;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static void exfat_cache_add(struct inode *inode,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache_id *new)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache *cache, *tmp;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (new->fcluster == EXFAT_EOF_CLUSTER) /* dummy cache */
|
|
Kmods SIG |
50e2b3 |
+ return;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ if (new->id != EXFAT_CACHE_VALID &&
|
|
Kmods SIG |
50e2b3 |
+ new->id != ei->cache_valid_id)
|
|
Kmods SIG |
50e2b3 |
+ goto unlock; /* this cache was invalidated */
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ cache = exfat_cache_merge(inode, new);
|
|
Kmods SIG |
50e2b3 |
+ if (cache == NULL) {
|
|
Kmods SIG |
50e2b3 |
+ if (ei->nr_caches < EXFAT_MAX_CACHE) {
|
|
Kmods SIG |
50e2b3 |
+ ei->nr_caches++;
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ tmp = exfat_cache_alloc();
|
|
Kmods SIG |
50e2b3 |
+ if (!tmp) {
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ ei->nr_caches--;
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ return;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ cache = exfat_cache_merge(inode, new);
|
|
Kmods SIG |
50e2b3 |
+ if (cache != NULL) {
|
|
Kmods SIG |
50e2b3 |
+ ei->nr_caches--;
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_free(tmp);
|
|
Kmods SIG |
50e2b3 |
+ goto out_update_lru;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ cache = tmp;
|
|
Kmods SIG |
50e2b3 |
+ } else {
|
|
Kmods SIG |
50e2b3 |
+ struct list_head *p = ei->cache_lru.prev;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ cache = list_entry(p,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache, cache_list);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ cache->fcluster = new->fcluster;
|
|
Kmods SIG |
50e2b3 |
+ cache->dcluster = new->dcluster;
|
|
Kmods SIG |
50e2b3 |
+ cache->nr_contig = new->nr_contig;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+out_update_lru:
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_update_lru(inode, cache);
|
|
Kmods SIG |
50e2b3 |
+unlock:
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+/*
|
|
Kmods SIG |
50e2b3 |
+ * Cache invalidation occurs rarely, thus the LRU chain is not updated. It
|
|
Kmods SIG |
50e2b3 |
+ * fixes itself after a while.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+static void __exfat_cache_inval_inode(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache *cache;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ while (!list_empty(&ei->cache_lru)) {
|
|
Kmods SIG |
50e2b3 |
+ cache = list_entry(ei->cache_lru.next,
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache, cache_list);
|
|
Kmods SIG |
50e2b3 |
+ list_del_init(&cache->cache_list);
|
|
Kmods SIG |
50e2b3 |
+ ei->nr_caches--;
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_free(cache);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+ /* Update. The copy of caches before this id is discarded. */
|
|
Kmods SIG |
50e2b3 |
+ ei->cache_valid_id++;
|
|
Kmods SIG |
50e2b3 |
+ if (ei->cache_valid_id == EXFAT_CACHE_VALID)
|
|
Kmods SIG |
50e2b3 |
+ ei->cache_valid_id++;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+void exfat_cache_inval_inode(struct inode *inode)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ spin_lock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+ __exfat_cache_inval_inode(inode);
|
|
Kmods SIG |
50e2b3 |
+ spin_unlock(&ei->cache_lru_lock);
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline int cache_contiguous(struct exfat_cache_id *cid,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int dclus)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ cid->nr_contig++;
|
|
Kmods SIG |
50e2b3 |
+ return cid->dcluster + cid->nr_contig == dclus;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+static inline void cache_init(struct exfat_cache_id *cid,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int fclus, unsigned int dclus)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ cid->id = EXFAT_CACHE_VALID;
|
|
Kmods SIG |
50e2b3 |
+ cid->fcluster = fclus;
|
|
Kmods SIG |
50e2b3 |
+ cid->dcluster = dclus;
|
|
Kmods SIG |
50e2b3 |
+ cid->nr_contig = 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+int exfat_get_cluster(struct inode *inode, unsigned int cluster,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int *fclus, unsigned int *dclus,
|
|
Kmods SIG |
50e2b3 |
+ unsigned int *last_dclus, int allow_eof)
|
|
Kmods SIG |
50e2b3 |
+{
|
|
Kmods SIG |
50e2b3 |
+ struct super_block *sb = inode->i_sb;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
50e2b3 |
+ unsigned int limit = sbi->num_clusters;
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_inode_info *ei = EXFAT_I(inode);
|
|
Kmods SIG |
50e2b3 |
+ struct exfat_cache_id cid;
|
|
Kmods SIG |
50e2b3 |
+ unsigned int content;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (ei->start_clu == EXFAT_FREE_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "invalid access to exfat cache (entry 0x%08x)",
|
|
Kmods SIG |
50e2b3 |
+ ei->start_clu);
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ *fclus = 0;
|
|
Kmods SIG |
50e2b3 |
+ *dclus = ei->start_clu;
|
|
Kmods SIG |
50e2b3 |
+ *last_dclus = *dclus;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * Don`t use exfat_cache if zero offset or non-cluster allocation
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ if (cluster == 0 || *dclus == EXFAT_EOF_CLUSTER)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ cache_init(&cid, EXFAT_EOF_CLUSTER, EXFAT_EOF_CLUSTER);
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_cache_lookup(inode, cluster, &cid, fclus, dclus) ==
|
|
Kmods SIG |
50e2b3 |
+ EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ /*
|
|
Kmods SIG |
50e2b3 |
+ * dummy, always not contiguous
|
|
Kmods SIG |
50e2b3 |
+ * This is reinitialized by cache_init(), later.
|
|
Kmods SIG |
50e2b3 |
+ */
|
|
Kmods SIG |
50e2b3 |
+ WARN_ON(cid.id != EXFAT_CACHE_VALID ||
|
|
Kmods SIG |
50e2b3 |
+ cid.fcluster != EXFAT_EOF_CLUSTER ||
|
|
Kmods SIG |
50e2b3 |
+ cid.dcluster != EXFAT_EOF_CLUSTER ||
|
|
Kmods SIG |
50e2b3 |
+ cid.nr_contig != 0);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (*fclus == cluster)
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ while (*fclus < cluster) {
|
|
Kmods SIG |
50e2b3 |
+ /* prevent the infinite loop of cluster chain */
|
|
Kmods SIG |
50e2b3 |
+ if (*fclus > limit) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "detected the cluster chain loop (i_pos %u)",
|
|
Kmods SIG |
50e2b3 |
+ (*fclus));
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (exfat_ent_get(sb, *dclus, &content))
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ *last_dclus = *dclus;
|
|
Kmods SIG |
50e2b3 |
+ *dclus = content;
|
|
Kmods SIG |
50e2b3 |
+ (*fclus)++;
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (content == EXFAT_EOF_CLUSTER) {
|
|
Kmods SIG |
50e2b3 |
+ if (!allow_eof) {
|
|
Kmods SIG |
50e2b3 |
+ exfat_fs_error(sb,
|
|
Kmods SIG |
50e2b3 |
+ "invalid cluster chain (i_pos %u, last_clus 0x%08x is EOF)",
|
|
Kmods SIG |
50e2b3 |
+ *fclus, (*last_dclus));
|
|
Kmods SIG |
50e2b3 |
+ return -EIO;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ break;
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ if (!cache_contiguous(&cid, *dclus))
|
|
Kmods SIG |
50e2b3 |
+ cache_init(&cid, *fclus, *dclus);
|
|
Kmods SIG |
50e2b3 |
+ }
|
|
Kmods SIG |
50e2b3 |
+
|
|
Kmods SIG |
50e2b3 |
+ exfat_cache_add(inode, &cid;;
|
|
Kmods SIG |
50e2b3 |
+ return 0;
|
|
Kmods SIG |
50e2b3 |
+}
|
|
Kmods SIG |
50e2b3 |
--
|
|
Kmods SIG |
50e2b3 |
2.31.1
|
|
Kmods SIG |
50e2b3 |
|