mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
Merge branch 'for-kernel-version-from-4.1.0' of https://github.com/namjaejeon/linux-exfat-oot
* 'for-kernel-version-from-4.1.0' of https://github.com/namjaejeon/linux-exfat-oot: (57 commits) exfat: fix ctime is not updated exfat: fix setting uninitialized time to ctime/atime exfat: convert to new timestamp accessors exfat: convert to ctime accessor functions exfat: fs: pass the request_mask to generic_fillattr exfat: convert to simple_rename_timestamp exfat: ensure that ctime is updated whenever the mtime is exfat: fs: add CONFIG_BUFFER_HEAD exfat: use fat ioctls definitions from include/uapi/linux/msdos_fs.h exfat: github action: remove liunx-4.1 source to get more disk space exfat: support create zero-size directory exfat: support handle zero-size directory exfat: add ioctls for accessing attributes exfat: vfs: get rid of old '->iterate' directory operation exfat: add necessary header for vmalloc exfat: release s_lock before calling dir_emit() exfat: check if filename entries exceeds max filename length exfat: github action: make space for running xfstests exfat: use kvmalloc_array/kvfree instead of kmalloc_array/kfree exfat: splice: Use filemap_splice_read() instead of generic_file_splice_read() ... Change-Id: I74986001151e68824d9d7d56f779b20a4cf6294f
This commit is contained in:
commit
a7124ec0f9
@ -1,96 +0,0 @@
|
||||
dist: bionic
|
||||
|
||||
language: c
|
||||
|
||||
notifications:
|
||||
- email: true
|
||||
|
||||
before_script:
|
||||
# Download the kernel
|
||||
- sudo apt-get install libelf-dev wget tar gzip python
|
||||
- wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.1.36.tar.gz
|
||||
- tar xf linux-4.1.36.tar.gz
|
||||
- mv linux-4.1.36 linux-stable
|
||||
- ./.travis_get_mainline_kernel
|
||||
- cp ./.travis_cmd_wrapper.pl ~/travis_cmd_wrapper.pl
|
||||
# Prerequisite for xfstests testing
|
||||
- sudo apt-get install linux-headers-$(uname -r)
|
||||
- sudo apt-get install autoconf libtool pkg-config libnl-3-dev libnl-genl-3-dev
|
||||
- sudo apt-get install xfslibs-dev uuid-dev libtool-bin xfsprogs libgdbm-dev gawk fio attr libattr1-dev libacl1-dev libaio-dev
|
||||
- git clone --branch=exfat-next https://github.com/exfat-utils/exfat-utils
|
||||
- git clone https://github.com/namjaejeon/exfat-testsuites
|
||||
- export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
|
||||
- export PATH=/usr/local/lib:$PATH
|
||||
- sudo useradd fsgqa
|
||||
- sudo useradd 123456-fsgqa
|
||||
|
||||
script:
|
||||
# Copy ksmbd source to kernel
|
||||
- mv linux-stable ../
|
||||
- mv linux ../
|
||||
- mkdir ../linux-stable/fs/exfat
|
||||
- cp -ar * ../linux-stable/fs/exfat/
|
||||
- cp -ar * ../linux/fs/exfat/
|
||||
|
||||
# Compile with 4.1 kernel
|
||||
- cd ../linux-stable
|
||||
- yes "" | make oldconfig > /dev/null
|
||||
- echo 'obj-$(CONFIG_EXFAT_FS) += exfat/' >> fs/Makefile
|
||||
- echo 'source "fs/exfat/Kconfig"' >> fs/Kconfig
|
||||
- echo 'CONFIG_EXFAT_FS=m' >> .config
|
||||
- echo 'CONFIG_EXFAT_DEFAULT_IOCHARSET="utf8"' >> .config
|
||||
- make -j$((`nproc`+1)) fs/exfat/exfat.ko
|
||||
|
||||
# Compile with latest Torvalds' kernel
|
||||
# - cd ../linux
|
||||
# - yes "" | make oldconfig > /dev/null
|
||||
# - echo 'obj-$(CONFIG_EXFAT) += exfat/' >> fs/Makefile
|
||||
# - echo 'source "fs/exfat/Kconfig"' >> fs/Kconfig
|
||||
# - echo 'CONFIG_EXFAT_FS=m' >> .config
|
||||
# - echo 'CONFIG_EXFAT_DEFAULT_IOCHARSET="utf8"' >> .config
|
||||
# - make -j$((`nproc`+1)) fs/exfat/exfat.ko
|
||||
|
||||
# Run xfstests testsuite
|
||||
- cd ../linux-exfat-oot
|
||||
- make > /dev/null
|
||||
- sudo make install > /dev/null
|
||||
- sudo modprobe exfat
|
||||
- cd exfat-utils
|
||||
- ./autogen.sh > /dev/null
|
||||
- ./configure > /dev/null
|
||||
- make -j$((`nproc`+1)) > /dev/null
|
||||
- sudo make install > /dev/null
|
||||
- sudo mkdir -p /mnt/scratch
|
||||
- sudo mkdir -p /mnt/test
|
||||
- sudo mkdir -p /mnt/full_test
|
||||
# create file/director test
|
||||
- truncate -s 10G full_test.img
|
||||
- sudo losetup /dev/loop22 full_test.img
|
||||
- sudo mkfs.exfat /dev/loop22
|
||||
- sudo mount -t exfat /dev/loop22 /mnt/full_test/
|
||||
- cd /mnt/full_test/
|
||||
- i=1;while [ $i -le 10000 ];do sudo touch file$i;if [ $? != 0 ]; then exit 1; fi; i=$(($i + 1));done
|
||||
- sync
|
||||
- sudo fsck.exfat /dev/loop22
|
||||
- sudo rm -rf *
|
||||
- i=1;while [ $i -le 10000 ];do sudo mkdir file$i;if [ $? != 0 ]; then exit 1; fi; i=$(($i + 1));done
|
||||
- sync
|
||||
- sudo rm -rf *
|
||||
- sudo fsck.exfat /dev/loop22
|
||||
- cd -
|
||||
- sudo umount /mnt/full_test/
|
||||
- sudo fsck.exfat /dev/loop22
|
||||
# run xfstests test
|
||||
- truncate -s 100G test.img
|
||||
- truncate -s 100G scratch.img
|
||||
- sudo losetup /dev/loop20 test.img
|
||||
- sudo losetup /dev/loop21 scratch.img
|
||||
- sudo mkfs.exfat /dev/loop20
|
||||
- sudo mkfs.exfat /dev/loop21
|
||||
- cd ..
|
||||
- cd exfat-testsuites/
|
||||
- tar xzvf xfstests-exfat.tgz > /dev/null
|
||||
- cd xfstests-exfat
|
||||
- make -j$((`nproc`+1)) > /dev/null
|
||||
- sudo ./check generic/001
|
||||
- sudo ./check generic/006
|
@ -2,7 +2,9 @@
|
||||
|
||||
config EXFAT_FS
|
||||
tristate "exFAT filesystem support"
|
||||
select BUFFER_HEAD
|
||||
select NLS
|
||||
select LEGACY_DIRECT_IO
|
||||
help
|
||||
This allows you to mount devices formatted with the exFAT file system.
|
||||
exFAT is typically used on SD-Cards or USB sticks.
|
||||
|
@ -12,6 +12,7 @@
|
||||
#else
|
||||
#include <linux/sched.h>
|
||||
#endif
|
||||
#include <linux/vmalloc.h>
|
||||
|
||||
#include "exfat_raw.h"
|
||||
#include "exfat_fs.h"
|
||||
@ -75,8 +76,12 @@ static int exfat_allocate_bitmap(struct super_block *sb,
|
||||
}
|
||||
sbi->map_sectors = ((need_map_size - 1) >>
|
||||
(sb->s_blocksize_bits)) + 1;
|
||||
sbi->vol_amap = kmalloc_array(sbi->map_sectors,
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
||||
sbi->vol_amap = kvmalloc_array(sbi->map_sectors,
|
||||
sizeof(struct buffer_head *), GFP_KERNEL);
|
||||
#else
|
||||
sbi->vol_amap = vmalloc(sbi->map_sectors * sizeof(struct buffer_head *));
|
||||
#endif
|
||||
if (!sbi->vol_amap)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -90,7 +95,7 @@ static int exfat_allocate_bitmap(struct super_block *sb,
|
||||
while (j < i)
|
||||
brelse(sbi->vol_amap[j++]);
|
||||
|
||||
kfree(sbi->vol_amap);
|
||||
kvfree(sbi->vol_amap);
|
||||
sbi->vol_amap = NULL;
|
||||
return -EIO;
|
||||
}
|
||||
@ -144,7 +149,7 @@ void exfat_free_bitmap(struct exfat_sb_info *sbi)
|
||||
for (i = 0; i < sbi->map_sectors; i++)
|
||||
__brelse(sbi->vol_amap[i]);
|
||||
|
||||
kfree(sbi->vol_amap);
|
||||
kvfree(sbi->vol_amap);
|
||||
}
|
||||
|
||||
int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync)
|
||||
|
333
fs/exfat/dir.c
333
fs/exfat/dir.c
@ -30,15 +30,16 @@ static int exfat_extract_uni_name(struct exfat_dentry *ep,
|
||||
|
||||
}
|
||||
|
||||
static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
|
||||
static int exfat_get_uniname_from_ext_entry(struct super_block *sb,
|
||||
struct exfat_chain *p_dir, int entry, unsigned short *uniname)
|
||||
{
|
||||
int i;
|
||||
struct exfat_entry_set_cache *es;
|
||||
int i, err;
|
||||
struct exfat_entry_set_cache es;
|
||||
unsigned int uni_len = 0, len;
|
||||
|
||||
es = exfat_get_dentry_set(sb, p_dir, entry, ES_ALL_ENTRIES);
|
||||
if (!es)
|
||||
return;
|
||||
err = exfat_get_dentry_set(&es, sb, p_dir, entry, ES_ALL_ENTRIES);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* First entry : file entry
|
||||
@ -46,24 +47,28 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
|
||||
* Third entry : first file-name entry
|
||||
* So, the index of first file-name dentry should start from 2.
|
||||
*/
|
||||
for (i = 2; i < es->num_entries; i++) {
|
||||
struct exfat_dentry *ep = exfat_get_dentry_cached(es, i);
|
||||
for (i = ES_IDX_FIRST_FILENAME; i < es.num_entries; i++) {
|
||||
struct exfat_dentry *ep = exfat_get_dentry_cached(&es, i);
|
||||
|
||||
/* end of name entry */
|
||||
if (exfat_get_entry_type(ep) != TYPE_EXTEND)
|
||||
break;
|
||||
|
||||
exfat_extract_uni_name(ep, uniname);
|
||||
len = exfat_extract_uni_name(ep, uniname);
|
||||
uni_len += len;
|
||||
if (len != EXFAT_FILE_NAME_LEN || uni_len >= MAX_NAME_LENGTH)
|
||||
break;
|
||||
uniname += EXFAT_FILE_NAME_LEN;
|
||||
}
|
||||
|
||||
exfat_free_dentry_set(es, false);
|
||||
exfat_put_dentry_set(&es, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read a directory entry from the opened directory */
|
||||
static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_entry *dir_entry)
|
||||
{
|
||||
int i, dentries_per_clu, dentries_per_clu_bits = 0, num_ext;
|
||||
int i, dentries_per_clu, num_ext, err;
|
||||
unsigned int type, clu_offset, max_dentries;
|
||||
struct exfat_chain dir, clu;
|
||||
struct exfat_uni_name uni_name;
|
||||
@ -85,11 +90,10 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
|
||||
EXFAT_B_TO_CLU(i_size_read(inode), sbi), ei->flags);
|
||||
|
||||
dentries_per_clu = sbi->dentries_per_clu;
|
||||
dentries_per_clu_bits = ilog2(dentries_per_clu);
|
||||
max_dentries = (unsigned int)min_t(u64, MAX_EXFAT_DENTRIES,
|
||||
(u64)sbi->num_clusters << dentries_per_clu_bits);
|
||||
(u64)EXFAT_CLU_TO_DEN(sbi->num_clusters, sbi));
|
||||
|
||||
clu_offset = dentry >> dentries_per_clu_bits;
|
||||
clu_offset = EXFAT_DEN_TO_CLU(dentry, sbi);
|
||||
exfat_chain_dup(&clu, &dir);
|
||||
|
||||
if (clu.flags == ALLOC_NO_FAT_CHAIN) {
|
||||
@ -103,7 +107,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
|
||||
clu.dir = ei->hint_bmap.clu;
|
||||
}
|
||||
|
||||
while (clu_offset > 0) {
|
||||
while (clu_offset > 0 && clu.dir != EXFAT_EOF_CLUSTER) {
|
||||
if (exfat_get_next_cluster(sb, &(clu.dir)))
|
||||
return -EIO;
|
||||
|
||||
@ -149,8 +153,12 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
|
||||
0);
|
||||
|
||||
*uni_name.name = 0x0;
|
||||
exfat_get_uniname_from_ext_entry(sb, &clu, i,
|
||||
err = exfat_get_uniname_from_ext_entry(sb, &clu, i,
|
||||
uni_name.name);
|
||||
if (err) {
|
||||
brelse(bh);
|
||||
continue;
|
||||
}
|
||||
exfat_utf16_to_nls(sb, &uni_name,
|
||||
dir_entry->namebuf.lfn,
|
||||
dir_entry->namebuf.lfnbuf_len);
|
||||
@ -164,7 +172,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
|
||||
dir_entry->entry = dentry;
|
||||
brelse(bh);
|
||||
|
||||
ei->hint_bmap.off = dentry >> dentries_per_clu_bits;
|
||||
ei->hint_bmap.off = EXFAT_DEN_TO_CLU(dentry, sbi);
|
||||
ei->hint_bmap.clu = clu.dir;
|
||||
|
||||
*cpos = EXFAT_DEN_TO_B(dentry + 1 + num_ext);
|
||||
@ -211,7 +219,10 @@ static void exfat_free_namebuf(struct exfat_dentry_namebuf *nb)
|
||||
exfat_init_namebuf(nb);
|
||||
}
|
||||
|
||||
/* skip iterating emit_dots when dir is empty */
|
||||
/*
|
||||
* Before calling dir_emit*(), sbi->s_lock should be released
|
||||
* because page fault can occur in dir_emit*().
|
||||
*/
|
||||
#define ITER_POS_FILLED_DOTS (2)
|
||||
static int exfat_iterate(struct file *filp, struct dir_context *ctx)
|
||||
{
|
||||
@ -226,35 +237,33 @@ static int exfat_iterate(struct file *filp, struct dir_context *ctx)
|
||||
int err = 0, fake_offset = 0;
|
||||
|
||||
exfat_init_namebuf(nb);
|
||||
mutex_lock(&EXFAT_SB(sb)->s_lock);
|
||||
|
||||
cpos = ctx->pos;
|
||||
if (!dir_emit_dots(filp, ctx))
|
||||
goto unlock;
|
||||
goto out;
|
||||
|
||||
if (ctx->pos == ITER_POS_FILLED_DOTS) {
|
||||
cpos = 0;
|
||||
fake_offset = 1;
|
||||
}
|
||||
|
||||
if (cpos & (DENTRY_SIZE - 1)) {
|
||||
err = -ENOENT;
|
||||
goto unlock;
|
||||
}
|
||||
cpos = round_up(cpos, DENTRY_SIZE);
|
||||
|
||||
/* name buffer should be allocated before use */
|
||||
err = exfat_alloc_namebuf(nb);
|
||||
if (err)
|
||||
goto unlock;
|
||||
goto out;
|
||||
get_new:
|
||||
mutex_lock(&EXFAT_SB(sb)->s_lock);
|
||||
|
||||
if (ei->flags == ALLOC_NO_FAT_CHAIN && cpos >= i_size_read(inode))
|
||||
goto end_of_dir;
|
||||
|
||||
err = exfat_readdir(inode, &cpos, &de);
|
||||
if (err) {
|
||||
/*
|
||||
* At least we tried to read a sector. Move cpos to next sector
|
||||
* position (should be aligned).
|
||||
* At least we tried to read a sector.
|
||||
* Move cpos to next sector position (should be aligned).
|
||||
*/
|
||||
if (err == -EIO) {
|
||||
cpos += 1 << (sb->s_blocksize_bits);
|
||||
@ -277,16 +286,10 @@ get_new:
|
||||
inum = iunique(sb, EXFAT_ROOT_INO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Before calling dir_emit(), sb_lock should be released.
|
||||
* Because page fault can occur in dir_emit() when the size
|
||||
* of buffer given from user is larger than one page size.
|
||||
*/
|
||||
mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
||||
if (!dir_emit(ctx, nb->lfn, strlen(nb->lfn), inum,
|
||||
(de.attr & ATTR_SUBDIR) ? DT_DIR : DT_REG))
|
||||
goto out_unlocked;
|
||||
mutex_lock(&EXFAT_SB(sb)->s_lock);
|
||||
(de.attr & EXFAT_ATTR_SUBDIR) ? DT_DIR : DT_REG))
|
||||
goto out;
|
||||
ctx->pos = cpos;
|
||||
goto get_new;
|
||||
|
||||
@ -294,9 +297,8 @@ end_of_dir:
|
||||
if (!cpos && fake_offset)
|
||||
cpos = ITER_POS_FILLED_DOTS;
|
||||
ctx->pos = cpos;
|
||||
unlock:
|
||||
mutex_unlock(&EXFAT_SB(sb)->s_lock);
|
||||
out_unlocked:
|
||||
out:
|
||||
/*
|
||||
* To improve performance, free namebuf after unlock sb_lock.
|
||||
* If namebuf is not allocated, this function do nothing
|
||||
@ -305,10 +307,17 @@ out_unlocked:
|
||||
return err;
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
|
||||
WRAP_DIR_ITER(exfat_iterate) // FIXME!
|
||||
#endif
|
||||
const struct file_operations exfat_dir_operations = {
|
||||
.llseek = generic_file_llseek,
|
||||
.read = generic_read_dir,
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
|
||||
.iterate_shared = shared_exfat_iterate,
|
||||
#else
|
||||
.iterate = exfat_iterate,
|
||||
#endif
|
||||
.unlocked_ioctl = exfat_ioctl,
|
||||
#ifdef CONFIG_COMPAT
|
||||
.compat_ioctl = exfat_compat_ioctl,
|
||||
@ -338,7 +347,7 @@ int exfat_calc_num_entries(struct exfat_uni_name *p_uniname)
|
||||
return -EINVAL;
|
||||
|
||||
/* 1 file entry + 1 stream entry + name entries */
|
||||
return ((len - 1) / EXFAT_FILE_NAME_LEN + 3);
|
||||
return ES_ENTRY_NUM(len);
|
||||
}
|
||||
|
||||
unsigned int exfat_get_entry_type(struct exfat_dentry *ep)
|
||||
@ -357,7 +366,7 @@ unsigned int exfat_get_entry_type(struct exfat_dentry *ep)
|
||||
if (ep->type == EXFAT_VOLUME)
|
||||
return TYPE_VOLUME;
|
||||
if (ep->type == EXFAT_FILE) {
|
||||
if (le16_to_cpu(ep->dentry.file.attr) & ATTR_SUBDIR)
|
||||
if (le16_to_cpu(ep->dentry.file.attr) & EXFAT_ATTR_SUBDIR)
|
||||
return TYPE_DIR;
|
||||
return TYPE_FILE;
|
||||
}
|
||||
@ -381,6 +390,12 @@ unsigned int exfat_get_entry_type(struct exfat_dentry *ep)
|
||||
return TYPE_ACL;
|
||||
return TYPE_CRITICAL_SEC;
|
||||
}
|
||||
|
||||
if (ep->type == EXFAT_VENDOR_EXT)
|
||||
return TYPE_VENDOR_EXT;
|
||||
if (ep->type == EXFAT_VENDOR_ALLOC)
|
||||
return TYPE_VENDOR_ALLOC;
|
||||
|
||||
return TYPE_BENIGN_SEC;
|
||||
}
|
||||
|
||||
@ -402,19 +417,21 @@ static void exfat_set_entry_type(struct exfat_dentry *ep, unsigned int type)
|
||||
ep->type = EXFAT_VOLUME;
|
||||
} else if (type == TYPE_DIR) {
|
||||
ep->type = EXFAT_FILE;
|
||||
ep->dentry.file.attr = cpu_to_le16(ATTR_SUBDIR);
|
||||
ep->dentry.file.attr = cpu_to_le16(EXFAT_ATTR_SUBDIR);
|
||||
} else if (type == TYPE_FILE) {
|
||||
ep->type = EXFAT_FILE;
|
||||
ep->dentry.file.attr = cpu_to_le16(ATTR_ARCHIVE);
|
||||
ep->dentry.file.attr = cpu_to_le16(EXFAT_ATTR_ARCHIVE);
|
||||
}
|
||||
}
|
||||
|
||||
static void exfat_init_stream_entry(struct exfat_dentry *ep,
|
||||
unsigned char flags, unsigned int start_clu,
|
||||
unsigned long long size)
|
||||
unsigned int start_clu, unsigned long long size)
|
||||
{
|
||||
exfat_set_entry_type(ep, TYPE_STREAM);
|
||||
ep->dentry.stream.flags = flags;
|
||||
if (size == 0)
|
||||
ep->dentry.stream.flags = ALLOC_FAT_CHAIN;
|
||||
else
|
||||
ep->dentry.stream.flags = ALLOC_NO_FAT_CHAIN;
|
||||
ep->dentry.stream.start_clu = cpu_to_le32(start_clu);
|
||||
ep->dentry.stream.valid_size = cpu_to_le64(size);
|
||||
ep->dentry.stream.size = cpu_to_le64(size);
|
||||
@ -490,9 +507,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
|
||||
if (!ep)
|
||||
return -EIO;
|
||||
|
||||
exfat_init_stream_entry(ep,
|
||||
(type == TYPE_FILE) ? ALLOC_FAT_CHAIN : ALLOC_NO_FAT_CHAIN,
|
||||
start_clu, size);
|
||||
exfat_init_stream_entry(ep, start_clu, size);
|
||||
exfat_update_bh(bh, IS_DIRSYNC(inode));
|
||||
brelse(bh);
|
||||
|
||||
@ -534,6 +549,25 @@ release_fbh:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void exfat_free_benign_secondary_clusters(struct inode *inode,
|
||||
struct exfat_dentry *ep)
|
||||
{
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct exfat_chain dir;
|
||||
unsigned int start_clu =
|
||||
le32_to_cpu(ep->dentry.generic_secondary.start_clu);
|
||||
u64 size = le64_to_cpu(ep->dentry.generic_secondary.size);
|
||||
unsigned char flags = ep->dentry.generic_secondary.flags;
|
||||
|
||||
if (!(flags & ALLOC_POSSIBLE) || !start_clu || !size)
|
||||
return;
|
||||
|
||||
exfat_chain_set(&dir, start_clu,
|
||||
EXFAT_B_TO_CLU_ROUND_UP(size, EXFAT_SB(sb)),
|
||||
flags);
|
||||
exfat_free_cluster(inode, &dir);
|
||||
}
|
||||
|
||||
int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
|
||||
int entry, int num_entries, struct exfat_uni_name *p_uniname)
|
||||
{
|
||||
@ -566,6 +600,9 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
|
||||
if (!ep)
|
||||
return -EIO;
|
||||
|
||||
if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC)
|
||||
exfat_free_benign_secondary_clusters(inode, ep);
|
||||
|
||||
exfat_init_name_entry(ep, uniname);
|
||||
exfat_update_bh(bh, sync);
|
||||
brelse(bh);
|
||||
@ -589,6 +626,9 @@ int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir,
|
||||
if (!ep)
|
||||
return -EIO;
|
||||
|
||||
if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC)
|
||||
exfat_free_benign_secondary_clusters(inode, ep);
|
||||
|
||||
exfat_set_entry_type(ep, TYPE_DELETED);
|
||||
exfat_update_bh(bh, IS_DIRSYNC(inode));
|
||||
brelse(bh);
|
||||
@ -603,18 +643,18 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
|
||||
unsigned short chksum = 0;
|
||||
struct exfat_dentry *ep;
|
||||
|
||||
for (i = 0; i < es->num_entries; i++) {
|
||||
for (i = ES_IDX_FILE; i < es->num_entries; i++) {
|
||||
ep = exfat_get_dentry_cached(es, i);
|
||||
chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, chksum,
|
||||
chksum_type);
|
||||
chksum_type = CS_DEFAULT;
|
||||
}
|
||||
ep = exfat_get_dentry_cached(es, 0);
|
||||
ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
|
||||
ep->dentry.file.checksum = cpu_to_le16(chksum);
|
||||
es->modified = true;
|
||||
}
|
||||
|
||||
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
|
||||
int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync)
|
||||
{
|
||||
int i, err = 0;
|
||||
|
||||
@ -626,7 +666,10 @@ int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
|
||||
bforget(es->bh[i]);
|
||||
else
|
||||
brelse(es->bh[i]);
|
||||
kfree(es);
|
||||
|
||||
if (IS_DYNAMIC_ES(es))
|
||||
kfree(es->bh);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -754,6 +797,7 @@ enum exfat_validate_dentry_mode {
|
||||
ES_MODE_GET_STRM_ENTRY,
|
||||
ES_MODE_GET_NAME_ENTRY,
|
||||
ES_MODE_GET_CRITICAL_SEC_ENTRY,
|
||||
ES_MODE_GET_BENIGN_SEC_ENTRY,
|
||||
};
|
||||
|
||||
static bool exfat_validate_entry(unsigned int type,
|
||||
@ -767,36 +811,33 @@ static bool exfat_validate_entry(unsigned int type,
|
||||
if (type != TYPE_FILE && type != TYPE_DIR)
|
||||
return false;
|
||||
*mode = ES_MODE_GET_FILE_ENTRY;
|
||||
return true;
|
||||
break;
|
||||
case ES_MODE_GET_FILE_ENTRY:
|
||||
if (type != TYPE_STREAM)
|
||||
return false;
|
||||
*mode = ES_MODE_GET_STRM_ENTRY;
|
||||
return true;
|
||||
break;
|
||||
case ES_MODE_GET_STRM_ENTRY:
|
||||
if (type != TYPE_EXTEND)
|
||||
return false;
|
||||
*mode = ES_MODE_GET_NAME_ENTRY;
|
||||
return true;
|
||||
break;
|
||||
case ES_MODE_GET_NAME_ENTRY:
|
||||
if (type == TYPE_STREAM)
|
||||
if (type & TYPE_BENIGN_SEC)
|
||||
*mode = ES_MODE_GET_BENIGN_SEC_ENTRY;
|
||||
else if (type != TYPE_EXTEND)
|
||||
return false;
|
||||
if (type != TYPE_EXTEND) {
|
||||
if (!(type & TYPE_CRITICAL_SEC))
|
||||
return false;
|
||||
*mode = ES_MODE_GET_CRITICAL_SEC_ENTRY;
|
||||
}
|
||||
return true;
|
||||
case ES_MODE_GET_CRITICAL_SEC_ENTRY:
|
||||
if (type == TYPE_EXTEND || type == TYPE_STREAM)
|
||||
break;
|
||||
case ES_MODE_GET_BENIGN_SEC_ENTRY:
|
||||
/* Assume unreconized benign secondary entry */
|
||||
if (!(type & TYPE_BENIGN_SEC))
|
||||
return false;
|
||||
if ((type & TYPE_CRITICAL_SEC) != TYPE_CRITICAL_SEC)
|
||||
return false;
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
WARN_ON_ONCE(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct exfat_dentry *exfat_get_dentry_cached(
|
||||
@ -823,14 +864,14 @@ struct exfat_dentry *exfat_get_dentry_cached(
|
||||
* pointer of entry set on success,
|
||||
* NULL on failure.
|
||||
*/
|
||||
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
|
||||
struct exfat_chain *p_dir, int entry, unsigned int type)
|
||||
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
|
||||
struct super_block *sb, struct exfat_chain *p_dir, int entry,
|
||||
unsigned int type)
|
||||
{
|
||||
int ret, i, num_bh;
|
||||
unsigned int off, byte_offset, clu = 0;
|
||||
unsigned int off;
|
||||
sector_t sec;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
struct exfat_entry_set_cache *es;
|
||||
struct exfat_dentry *ep;
|
||||
int num_entries;
|
||||
enum exfat_validate_dentry_mode mode = ES_MODE_STARTED;
|
||||
@ -838,52 +879,51 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
|
||||
|
||||
if (p_dir->dir == DIR_DELETED) {
|
||||
exfat_err(sb, "access to deleted dentry");
|
||||
return NULL;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
byte_offset = EXFAT_DEN_TO_B(entry);
|
||||
ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu);
|
||||
ret = exfat_find_location(sb, p_dir, entry, &sec, &off);
|
||||
if (ret)
|
||||
return NULL;
|
||||
return ret;
|
||||
|
||||
es = kzalloc(sizeof(*es), GFP_KERNEL);
|
||||
if (!es)
|
||||
return NULL;
|
||||
memset(es, 0, sizeof(*es));
|
||||
es->sb = sb;
|
||||
es->modified = false;
|
||||
|
||||
/* byte offset in cluster */
|
||||
byte_offset = EXFAT_CLU_OFFSET(byte_offset, sbi);
|
||||
|
||||
/* byte offset in sector */
|
||||
off = EXFAT_BLK_OFFSET(byte_offset, sb);
|
||||
es->start_off = off;
|
||||
|
||||
/* sector offset in cluster */
|
||||
sec = EXFAT_B_TO_BLK(byte_offset, sb);
|
||||
sec += exfat_cluster_to_sector(sbi, clu);
|
||||
es->bh = es->__bh;
|
||||
|
||||
bh = sb_bread(sb, sec);
|
||||
if (!bh)
|
||||
goto free_es;
|
||||
return -EIO;
|
||||
es->bh[es->num_bh++] = bh;
|
||||
|
||||
ep = exfat_get_dentry_cached(es, 0);
|
||||
ep = exfat_get_dentry_cached(es, ES_IDX_FILE);
|
||||
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
|
||||
goto free_es;
|
||||
goto put_es;
|
||||
|
||||
num_entries = type == ES_ALL_ENTRIES ?
|
||||
ep->dentry.file.num_ext + 1 : type;
|
||||
es->num_entries = num_entries;
|
||||
|
||||
num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb);
|
||||
if (num_bh > ARRAY_SIZE(es->__bh)) {
|
||||
es->bh = kmalloc_array(num_bh, sizeof(*es->bh), GFP_KERNEL);
|
||||
if (!es->bh) {
|
||||
brelse(bh);
|
||||
return -ENOMEM;
|
||||
}
|
||||
es->bh[0] = bh;
|
||||
}
|
||||
|
||||
for (i = 1; i < num_bh; i++) {
|
||||
/* get the next sector */
|
||||
if (exfat_is_last_sector_in_cluster(sbi, sec)) {
|
||||
unsigned int clu = exfat_sector_to_cluster(sbi, sec);
|
||||
|
||||
if (p_dir->flags == ALLOC_NO_FAT_CHAIN)
|
||||
clu++;
|
||||
else if (exfat_get_next_cluster(sb, &clu))
|
||||
goto free_es;
|
||||
goto put_es;
|
||||
sec = exfat_cluster_to_sector(sbi, clu);
|
||||
} else {
|
||||
sec++;
|
||||
@ -891,21 +931,51 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
|
||||
|
||||
bh = sb_bread(sb, sec);
|
||||
if (!bh)
|
||||
goto free_es;
|
||||
goto put_es;
|
||||
es->bh[es->num_bh++] = bh;
|
||||
}
|
||||
|
||||
/* validate cached dentries */
|
||||
for (i = 1; i < num_entries; i++) {
|
||||
for (i = ES_IDX_STREAM; i < num_entries; i++) {
|
||||
ep = exfat_get_dentry_cached(es, i);
|
||||
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
|
||||
goto free_es;
|
||||
goto put_es;
|
||||
}
|
||||
return es;
|
||||
return 0;
|
||||
|
||||
free_es:
|
||||
exfat_free_dentry_set(es, false);
|
||||
return NULL;
|
||||
put_es:
|
||||
exfat_put_dentry_set(es, false);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp)
|
||||
{
|
||||
hint_femp->eidx = EXFAT_HINT_NONE;
|
||||
hint_femp->count = 0;
|
||||
}
|
||||
|
||||
static inline void exfat_set_empty_hint(struct exfat_inode_info *ei,
|
||||
struct exfat_hint_femp *candi_empty, struct exfat_chain *clu,
|
||||
int dentry, int num_entries, int entry_type)
|
||||
{
|
||||
if (ei->hint_femp.eidx == EXFAT_HINT_NONE ||
|
||||
ei->hint_femp.eidx > dentry) {
|
||||
int total_entries = EXFAT_B_TO_DEN(i_size_read(&ei->vfs_inode));
|
||||
|
||||
if (candi_empty->count == 0) {
|
||||
candi_empty->cur = *clu;
|
||||
candi_empty->eidx = dentry;
|
||||
}
|
||||
|
||||
if (entry_type == TYPE_UNUSED)
|
||||
candi_empty->count += total_entries - dentry;
|
||||
else
|
||||
candi_empty->count++;
|
||||
|
||||
if (candi_empty->count == num_entries ||
|
||||
candi_empty->count + candi_empty->eidx == total_entries)
|
||||
ei->hint_femp = *candi_empty;
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
@ -928,17 +998,21 @@ enum {
|
||||
*/
|
||||
int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
||||
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
||||
int num_entries, unsigned int type, struct exfat_hint *hint_opt)
|
||||
struct exfat_hint *hint_opt)
|
||||
{
|
||||
int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
|
||||
int order, step, name_len = 0;
|
||||
int dentries_per_clu, num_empty = 0;
|
||||
int dentries_per_clu;
|
||||
unsigned int entry_type;
|
||||
unsigned short *uniname = NULL;
|
||||
struct exfat_chain clu;
|
||||
struct exfat_hint *hint_stat = &ei->hint_stat;
|
||||
struct exfat_hint_femp candi_empty;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
int num_entries = exfat_calc_num_entries(p_uniname);
|
||||
|
||||
if (num_entries < 0)
|
||||
return num_entries;
|
||||
|
||||
dentries_per_clu = sbi->dentries_per_clu;
|
||||
|
||||
@ -950,10 +1024,13 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
||||
end_eidx = dentry;
|
||||
}
|
||||
|
||||
candi_empty.eidx = EXFAT_HINT_NONE;
|
||||
exfat_reset_empty_hint(&ei->hint_femp);
|
||||
|
||||
rewind:
|
||||
order = 0;
|
||||
step = DIRENT_STEP_FILE;
|
||||
exfat_reset_empty_hint(&candi_empty);
|
||||
|
||||
while (clu.dir != EXFAT_EOF_CLUSTER) {
|
||||
i = dentry & (dentries_per_clu - 1);
|
||||
for (; i < dentries_per_clu; i++, dentry++) {
|
||||
@ -973,26 +1050,9 @@ rewind:
|
||||
entry_type == TYPE_DELETED) {
|
||||
step = DIRENT_STEP_FILE;
|
||||
|
||||
num_empty++;
|
||||
if (candi_empty.eidx == EXFAT_HINT_NONE &&
|
||||
num_empty == 1) {
|
||||
exfat_chain_set(&candi_empty.cur,
|
||||
clu.dir, clu.size, clu.flags);
|
||||
}
|
||||
|
||||
if (candi_empty.eidx == EXFAT_HINT_NONE &&
|
||||
num_empty >= num_entries) {
|
||||
candi_empty.eidx =
|
||||
dentry - (num_empty - 1);
|
||||
WARN_ON(candi_empty.eidx < 0);
|
||||
candi_empty.count = num_empty;
|
||||
|
||||
if (ei->hint_femp.eidx ==
|
||||
EXFAT_HINT_NONE ||
|
||||
candi_empty.eidx <=
|
||||
ei->hint_femp.eidx)
|
||||
ei->hint_femp = candi_empty;
|
||||
}
|
||||
exfat_set_empty_hint(ei, &candi_empty, &clu,
|
||||
dentry, num_entries,
|
||||
entry_type);
|
||||
|
||||
brelse(bh);
|
||||
if (entry_type == TYPE_UNUSED)
|
||||
@ -1000,17 +1060,14 @@ rewind:
|
||||
continue;
|
||||
}
|
||||
|
||||
num_empty = 0;
|
||||
candi_empty.eidx = EXFAT_HINT_NONE;
|
||||
exfat_reset_empty_hint(&candi_empty);
|
||||
|
||||
if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) {
|
||||
step = DIRENT_STEP_FILE;
|
||||
hint_opt->clu = clu.dir;
|
||||
hint_opt->eidx = i;
|
||||
if (type == TYPE_ALL || type == entry_type) {
|
||||
num_ext = ep->dentry.file.num_ext;
|
||||
step = DIRENT_STEP_STRM;
|
||||
}
|
||||
num_ext = ep->dentry.file.num_ext;
|
||||
step = DIRENT_STEP_STRM;
|
||||
brelse(bh);
|
||||
continue;
|
||||
}
|
||||
@ -1041,7 +1098,8 @@ rewind:
|
||||
if (entry_type == TYPE_EXTEND) {
|
||||
unsigned short entry_uniname[16], unichar;
|
||||
|
||||
if (step != DIRENT_STEP_NAME) {
|
||||
if (step != DIRENT_STEP_NAME ||
|
||||
name_len >= MAX_NAME_LENGTH) {
|
||||
step = DIRENT_STEP_FILE;
|
||||
continue;
|
||||
}
|
||||
@ -1101,12 +1159,19 @@ not_found:
|
||||
rewind = 1;
|
||||
dentry = 0;
|
||||
clu.dir = p_dir->dir;
|
||||
/* reset empty hint */
|
||||
num_empty = 0;
|
||||
candi_empty.eidx = EXFAT_HINT_NONE;
|
||||
goto rewind;
|
||||
}
|
||||
|
||||
/*
|
||||
* set the EXFAT_EOF_CLUSTER flag to avoid search
|
||||
* from the beginning again when allocated a new cluster
|
||||
*/
|
||||
if (ei->hint_femp.eidx == EXFAT_HINT_NONE) {
|
||||
ei->hint_femp.cur.dir = EXFAT_EOF_CLUSTER;
|
||||
ei->hint_femp.eidx = p_dir->size * dentries_per_clu;
|
||||
ei->hint_femp.count = 0;
|
||||
}
|
||||
|
||||
/* initialized hint_stat */
|
||||
hint_stat->clu = p_dir->dir;
|
||||
hint_stat->eidx = 0;
|
||||
@ -1154,10 +1219,8 @@ int exfat_count_ext_entries(struct super_block *sb, struct exfat_chain *p_dir,
|
||||
|
||||
type = exfat_get_entry_type(ext_ep);
|
||||
brelse(bh);
|
||||
if (type == TYPE_EXTEND || type == TYPE_STREAM)
|
||||
if (type & TYPE_CRITICAL_SEC || type & TYPE_BENIGN_SEC)
|
||||
count++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -10,6 +10,11 @@
|
||||
#include <linux/fs.h>
|
||||
#include <linux/ratelimit.h>
|
||||
#include <linux/nls.h>
|
||||
#include <linux/blkdev.h>
|
||||
|
||||
#ifndef SECTOR_SIZE
|
||||
#define SECTOR_SIZE 512
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0)
|
||||
#include <linux/magic.h>
|
||||
@ -17,7 +22,7 @@
|
||||
#define EXFAT_SUPER_MAGIC 0x2011BAB0UL
|
||||
#endif
|
||||
|
||||
#define EXFAT_VERSION "5.19.1"
|
||||
#define EXFAT_VERSION "6.0.0"
|
||||
|
||||
#define EXFAT_ROOT_INO 1
|
||||
|
||||
@ -50,7 +55,15 @@ enum {
|
||||
#define ES_2_ENTRIES 2
|
||||
#define ES_ALL_ENTRIES 0
|
||||
|
||||
#define DIR_DELETED 0xFFFF0321
|
||||
#define ES_IDX_FILE 0
|
||||
#define ES_IDX_STREAM 1
|
||||
#define ES_IDX_FIRST_FILENAME 2
|
||||
#define EXFAT_FILENAME_ENTRY_NUM(name_len) \
|
||||
DIV_ROUND_UP(name_len, EXFAT_FILE_NAME_LEN)
|
||||
#define ES_IDX_LAST_FILENAME(name_len) \
|
||||
(ES_IDX_FIRST_FILENAME + EXFAT_FILENAME_ENTRY_NUM(name_len) - 1)
|
||||
|
||||
#define DIR_DELETED 0xFFFFFFF7
|
||||
|
||||
/* type values */
|
||||
#define TYPE_UNUSED 0x0000
|
||||
@ -71,15 +84,13 @@ enum {
|
||||
#define TYPE_PADDING 0x0402
|
||||
#define TYPE_ACLTAB 0x0403
|
||||
#define TYPE_BENIGN_SEC 0x0800
|
||||
#define TYPE_ALL 0x0FFF
|
||||
#define TYPE_VENDOR_EXT 0x0801
|
||||
#define TYPE_VENDOR_ALLOC 0x0802
|
||||
|
||||
#define MAX_CHARSET_SIZE 6 /* max size of multi-byte character */
|
||||
#define MAX_NAME_LENGTH 255 /* max len of file name excluding NULL */
|
||||
#define MAX_VFSNAME_BUF_SIZE ((MAX_NAME_LENGTH + 1) * MAX_CHARSET_SIZE)
|
||||
|
||||
/* Enough size to hold 256 dentry (even 512 Byte sector) */
|
||||
#define DIR_CACHE_SIZE (256*sizeof(struct exfat_dentry)/512+1)
|
||||
|
||||
#define EXFAT_HINT_NONE -1
|
||||
#define EXFAT_MIN_SUBDIR 2
|
||||
|
||||
@ -104,11 +115,17 @@ enum {
|
||||
/*
|
||||
* helpers for block size to dentry size conversion.
|
||||
*/
|
||||
#define EXFAT_B_TO_DEN_IDX(b, sbi) \
|
||||
((b) << ((sbi)->cluster_size_bits - DENTRY_SIZE_BITS))
|
||||
#define EXFAT_B_TO_DEN(b) ((b) >> DENTRY_SIZE_BITS)
|
||||
#define EXFAT_DEN_TO_B(b) ((b) << DENTRY_SIZE_BITS)
|
||||
|
||||
/*
|
||||
* helpers for cluster size to dentry size conversion.
|
||||
*/
|
||||
#define EXFAT_CLU_TO_DEN(clu, sbi) \
|
||||
((clu) << ((sbi)->cluster_size_bits - DENTRY_SIZE_BITS))
|
||||
#define EXFAT_DEN_TO_CLU(dentry, sbi) \
|
||||
((dentry) >> ((sbi)->cluster_size_bits - DENTRY_SIZE_BITS))
|
||||
|
||||
/*
|
||||
* helpers for fat entry.
|
||||
*/
|
||||
@ -134,6 +151,17 @@ enum {
|
||||
#define BITS_PER_BYTE_MASK 0x7
|
||||
#define IGNORED_BITS_REMAINED(clu, clu_base) ((1 << ((clu) - (clu_base))) - 1)
|
||||
|
||||
#define ES_ENTRY_NUM(name_len) (ES_IDX_LAST_FILENAME(name_len) + 1)
|
||||
/* 19 entries = 1 file entry + 1 stream entry + 17 filename entries */
|
||||
#define ES_MAX_ENTRY_NUM ES_ENTRY_NUM(MAX_NAME_LENGTH)
|
||||
|
||||
/*
|
||||
* 19 entries x 32 bytes/entry = 608 bytes.
|
||||
* The 608 bytes are in 3 sectors at most (even 512 Byte sector).
|
||||
*/
|
||||
#define DIR_CACHE_SIZE \
|
||||
(DIV_ROUND_UP(EXFAT_DEN_TO_B(ES_MAX_ENTRY_NUM), SECTOR_SIZE) + 1)
|
||||
|
||||
struct exfat_dentry_namebuf {
|
||||
char *lfn;
|
||||
int lfnbuf_len; /* usually MAX_UNINAME_BUF_SIZE */
|
||||
@ -175,13 +203,16 @@ struct exfat_hint {
|
||||
|
||||
struct exfat_entry_set_cache {
|
||||
struct super_block *sb;
|
||||
bool modified;
|
||||
unsigned int start_off;
|
||||
int num_bh;
|
||||
struct buffer_head *bh[DIR_CACHE_SIZE];
|
||||
struct buffer_head *__bh[DIR_CACHE_SIZE];
|
||||
struct buffer_head **bh;
|
||||
unsigned int num_entries;
|
||||
bool modified;
|
||||
};
|
||||
|
||||
#define IS_DYNAMIC_ES(es) ((es)->__bh != (es)->bh)
|
||||
|
||||
struct exfat_dir_entry {
|
||||
struct exfat_chain dir;
|
||||
int entry;
|
||||
@ -222,6 +253,8 @@ struct exfat_mount_options {
|
||||
discard:1, /* Issue discard requests on deletions */
|
||||
keep_last_dots:1; /* Keep trailing periods in paths */
|
||||
int time_offset; /* Offset of timestamps from UTC (in minutes) */
|
||||
/* Support creating zero-size directory, default: false */
|
||||
bool zero_size_dir;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -351,10 +384,10 @@ static inline int exfat_mode_can_hold_ro(struct inode *inode)
|
||||
static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi,
|
||||
unsigned short attr, mode_t mode)
|
||||
{
|
||||
if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR))
|
||||
if ((attr & EXFAT_ATTR_READONLY) && !(attr & EXFAT_ATTR_SUBDIR))
|
||||
mode &= ~0222;
|
||||
|
||||
if (attr & ATTR_SUBDIR)
|
||||
if (attr & EXFAT_ATTR_SUBDIR)
|
||||
return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
|
||||
|
||||
return (mode & ~sbi->options.fs_fmask) | S_IFREG;
|
||||
@ -366,18 +399,18 @@ static inline unsigned short exfat_make_attr(struct inode *inode)
|
||||
unsigned short attr = EXFAT_I(inode)->attr;
|
||||
|
||||
if (S_ISDIR(inode->i_mode))
|
||||
attr |= ATTR_SUBDIR;
|
||||
attr |= EXFAT_ATTR_SUBDIR;
|
||||
if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & 0222))
|
||||
attr |= ATTR_READONLY;
|
||||
attr |= EXFAT_ATTR_READONLY;
|
||||
return attr;
|
||||
}
|
||||
|
||||
static inline void exfat_save_attr(struct inode *inode, unsigned short attr)
|
||||
{
|
||||
if (exfat_mode_can_hold_ro(inode))
|
||||
EXFAT_I(inode)->attr = attr & (ATTR_RWMASK | ATTR_READONLY);
|
||||
EXFAT_I(inode)->attr = attr & (EXFAT_ATTR_RWMASK | EXFAT_ATTR_READONLY);
|
||||
else
|
||||
EXFAT_I(inode)->attr = attr & ATTR_RWMASK;
|
||||
EXFAT_I(inode)->attr = attr & EXFAT_ATTR_RWMASK;
|
||||
}
|
||||
|
||||
static inline bool exfat_is_last_sector_in_cluster(struct exfat_sb_info *sbi,
|
||||
@ -394,7 +427,7 @@ static inline sector_t exfat_cluster_to_sector(struct exfat_sb_info *sbi,
|
||||
sbi->data_start_sector;
|
||||
}
|
||||
|
||||
static inline int exfat_sector_to_cluster(struct exfat_sb_info *sbi,
|
||||
static inline unsigned int exfat_sector_to_cluster(struct exfat_sb_info *sbi,
|
||||
sector_t sec)
|
||||
{
|
||||
return ((sec - sbi->data_start_sector) >> sbi->sect_per_clus_bits) +
|
||||
@ -442,15 +475,23 @@ int exfat_trim_fs(struct inode *inode, struct fstrim_range *range);
|
||||
|
||||
/* file.c */
|
||||
extern const struct file_operations exfat_file_operations;
|
||||
int __exfat_truncate(struct inode *inode, loff_t new_size);
|
||||
void exfat_truncate(struct inode *inode, loff_t size);
|
||||
int __exfat_truncate(struct inode *inode);
|
||||
void exfat_truncate(struct inode *inode);
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
struct iattr *attr);
|
||||
int exfat_getattr(struct mnt_idmap *idmap, const struct path *path,
|
||||
struct kstat *stat, unsigned int request_mask,
|
||||
unsigned int query_flags);
|
||||
#else
|
||||
int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
||||
struct iattr *attr);
|
||||
int exfat_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
||||
struct kstat *stat, unsigned int request_mask,
|
||||
unsigned int query_flags);
|
||||
#endif
|
||||
#else
|
||||
int exfat_setattr(struct dentry *dentry, struct iattr *attr);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
||||
@ -496,15 +537,16 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es);
|
||||
int exfat_calc_num_entries(struct exfat_uni_name *p_uniname);
|
||||
int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
|
||||
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
|
||||
int num_entries, unsigned int type, struct exfat_hint *hint_opt);
|
||||
struct exfat_hint *hint_opt);
|
||||
int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu);
|
||||
struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
|
||||
struct exfat_chain *p_dir, int entry, struct buffer_head **bh);
|
||||
struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
|
||||
int num);
|
||||
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
|
||||
struct exfat_chain *p_dir, int entry, unsigned int type);
|
||||
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
|
||||
int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
|
||||
struct super_block *sb, struct exfat_chain *p_dir, int entry,
|
||||
unsigned int type);
|
||||
int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync);
|
||||
int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
|
||||
|
||||
/* inode.c */
|
||||
@ -556,6 +598,9 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
|
||||
void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
|
||||
u8 tz, __le16 time, __le16 date, u8 time_cs);
|
||||
void exfat_truncate_atime(struct timespec64 *ts);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
void exfat_truncate_inode_atime(struct inode *inode);
|
||||
#endif
|
||||
void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
|
||||
u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
|
||||
#else
|
||||
|
@ -27,6 +27,7 @@
|
||||
((sbi)->num_clusters - EXFAT_RESERVED_CLUSTERS)
|
||||
|
||||
/* AllocationPossible and NoFatChain field in GeneralSecondaryFlags Field */
|
||||
#define ALLOC_POSSIBLE 0x01
|
||||
#define ALLOC_FAT_CHAIN 0x01
|
||||
#define ALLOC_NO_FAT_CHAIN 0x03
|
||||
|
||||
@ -50,6 +51,8 @@
|
||||
#define EXFAT_STREAM 0xC0 /* stream entry */
|
||||
#define EXFAT_NAME 0xC1 /* file name entry */
|
||||
#define EXFAT_ACL 0xC2 /* stream entry */
|
||||
#define EXFAT_VENDOR_EXT 0xE0 /* vendor extension entry */
|
||||
#define EXFAT_VENDOR_ALLOC 0xE1 /* vendor allocation entry */
|
||||
|
||||
#define IS_EXFAT_CRITICAL_PRI(x) (x < 0xA0)
|
||||
#define IS_EXFAT_BENIGN_PRI(x) (x < 0xC0)
|
||||
@ -61,15 +64,16 @@
|
||||
#define CS_DEFAULT 2
|
||||
|
||||
/* file attributes */
|
||||
#define ATTR_READONLY 0x0001
|
||||
#define ATTR_HIDDEN 0x0002
|
||||
#define ATTR_SYSTEM 0x0004
|
||||
#define ATTR_VOLUME 0x0008
|
||||
#define ATTR_SUBDIR 0x0010
|
||||
#define ATTR_ARCHIVE 0x0020
|
||||
#define EXFAT_ATTR_READONLY 0x0001
|
||||
#define EXFAT_ATTR_HIDDEN 0x0002
|
||||
#define EXFAT_ATTR_SYSTEM 0x0004
|
||||
#define EXFAT_ATTR_VOLUME 0x0008
|
||||
#define EXFAT_ATTR_SUBDIR 0x0010
|
||||
#define EXFAT_ATTR_ARCHIVE 0x0020
|
||||
|
||||
#define ATTR_RWMASK (ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME | \
|
||||
ATTR_SUBDIR | ATTR_ARCHIVE)
|
||||
#define EXFAT_ATTR_RWMASK (EXFAT_ATTR_HIDDEN | EXFAT_ATTR_SYSTEM | \
|
||||
EXFAT_ATTR_VOLUME | EXFAT_ATTR_SUBDIR | \
|
||||
EXFAT_ATTR_ARCHIVE)
|
||||
|
||||
#define BOOTSEC_JUMP_BOOT_LEN 3
|
||||
#define BOOTSEC_FS_NAME_LEN 8
|
||||
@ -155,6 +159,24 @@ struct exfat_dentry {
|
||||
__le32 start_clu;
|
||||
__le64 size;
|
||||
} __packed upcase; /* up-case table directory entry */
|
||||
struct {
|
||||
__u8 flags;
|
||||
__u8 vendor_guid[16];
|
||||
__u8 vendor_defined[14];
|
||||
} __packed vendor_ext; /* vendor extension directory entry */
|
||||
struct {
|
||||
__u8 flags;
|
||||
__u8 vendor_guid[16];
|
||||
__u8 vendor_defined[2];
|
||||
__le32 start_clu;
|
||||
__le64 size;
|
||||
} __packed vendor_alloc; /* vendor allocation directory entry */
|
||||
struct {
|
||||
__u8 flags;
|
||||
__u8 custom_defined[18];
|
||||
__le32 start_clu;
|
||||
__le64 size;
|
||||
} __packed generic_secondary; /* generic secondary directory entry */
|
||||
} __packed dentry;
|
||||
} __packed;
|
||||
|
||||
|
@ -322,7 +322,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
struct exfat_chain *p_chain, bool sync_bmap)
|
||||
{
|
||||
int ret = -ENOSPC;
|
||||
unsigned int num_clusters = 0, total_cnt;
|
||||
unsigned int total_cnt;
|
||||
unsigned int hint_clu, new_clu, last_clu = EXFAT_EOF_CLUSTER;
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
@ -359,17 +359,11 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
|
||||
/* check cluster validation */
|
||||
if (!is_valid_cluster(sbi, hint_clu)) {
|
||||
exfat_err(sb, "hint_cluster is invalid (%u)",
|
||||
hint_clu);
|
||||
if (hint_clu != sbi->num_clusters)
|
||||
exfat_err(sb, "hint_cluster is invalid (%u), rewind to the first cluster",
|
||||
hint_clu);
|
||||
hint_clu = EXFAT_FIRST_CLUSTER;
|
||||
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
||||
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
||||
num_clusters)) {
|
||||
ret = -EIO;
|
||||
goto unlock;
|
||||
}
|
||||
p_chain->flags = ALLOC_FAT_CHAIN;
|
||||
}
|
||||
p_chain->flags = ALLOC_FAT_CHAIN;
|
||||
}
|
||||
|
||||
p_chain->dir = EXFAT_EOF_CLUSTER;
|
||||
@ -379,7 +373,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
if (new_clu != hint_clu &&
|
||||
p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
||||
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
||||
num_clusters)) {
|
||||
p_chain->size)) {
|
||||
ret = -EIO;
|
||||
goto free_cluster;
|
||||
}
|
||||
@ -392,8 +386,6 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
goto free_cluster;
|
||||
}
|
||||
|
||||
num_clusters++;
|
||||
|
||||
/* update FAT table */
|
||||
if (p_chain->flags == ALLOC_FAT_CHAIN) {
|
||||
if (exfat_ent_set(sb, new_clu, EXFAT_EOF_CLUSTER)) {
|
||||
@ -410,13 +402,14 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
goto free_cluster;
|
||||
}
|
||||
}
|
||||
p_chain->size++;
|
||||
|
||||
last_clu = new_clu;
|
||||
|
||||
if (--num_alloc == 0) {
|
||||
if (p_chain->size == num_alloc) {
|
||||
sbi->clu_srch_ptr = hint_clu;
|
||||
sbi->used_clusters += num_clusters;
|
||||
sbi->used_clusters += num_alloc;
|
||||
|
||||
p_chain->size += num_clusters;
|
||||
mutex_unlock(&sbi->bitmap_lock);
|
||||
return 0;
|
||||
}
|
||||
@ -427,7 +420,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
|
||||
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
|
||||
if (exfat_chain_cont_cluster(sb, p_chain->dir,
|
||||
num_clusters)) {
|
||||
p_chain->size)) {
|
||||
ret = -EIO;
|
||||
goto free_cluster;
|
||||
}
|
||||
@ -436,8 +429,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
|
||||
}
|
||||
}
|
||||
free_cluster:
|
||||
if (num_clusters)
|
||||
__exfat_free_cluster(inode, p_chain);
|
||||
__exfat_free_cluster(inode, p_chain);
|
||||
unlock:
|
||||
mutex_unlock(&sbi->bitmap_lock);
|
||||
return ret;
|
||||
|
203
fs/exfat/file.c
203
fs/exfat/file.c
@ -9,8 +9,12 @@
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
||||
#include <linux/cred.h>
|
||||
#endif
|
||||
#include <linux/mount.h>
|
||||
#include <linux/compat.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/fsnotify.h>
|
||||
#include <linux/security.h>
|
||||
#include <linux/msdos_fs.h>
|
||||
|
||||
#include "exfat_raw.h"
|
||||
#include "exfat_fs.h"
|
||||
@ -26,7 +30,15 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
|
||||
return err;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
|
||||
#else
|
||||
inode->i_mtime = inode_set_ctime_current(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_ctime = inode->i_mtime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
@ -100,7 +112,7 @@ static int exfat_sanitize_mode(const struct exfat_sb_info *sbi,
|
||||
}
|
||||
|
||||
/* resize the file length */
|
||||
int __exfat_truncate(struct inode *inode, loff_t new_size)
|
||||
int __exfat_truncate(struct inode *inode)
|
||||
{
|
||||
unsigned int num_clusters_new, num_clusters_phys;
|
||||
unsigned int last_clu = EXFAT_FREE_CLUSTER;
|
||||
@ -120,7 +132,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
|
||||
|
||||
exfat_chain_set(&clu, ei->start_clu, num_clusters_phys, ei->flags);
|
||||
|
||||
if (new_size > 0) {
|
||||
if (i_size_read(inode) > 0) {
|
||||
/*
|
||||
* Truncate FAT chain num_clusters after the first cluster
|
||||
* num_clusters = min(new, phys);
|
||||
@ -150,10 +162,8 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
|
||||
ei->start_clu = EXFAT_EOF_CLUSTER;
|
||||
}
|
||||
|
||||
i_size_write(inode, new_size);
|
||||
|
||||
if (ei->type == TYPE_FILE)
|
||||
ei->attr |= ATTR_ARCHIVE;
|
||||
ei->attr |= EXFAT_ATTR_ARCHIVE;
|
||||
|
||||
/*
|
||||
* update the directory entry
|
||||
@ -196,7 +206,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void exfat_truncate(struct inode *inode, loff_t size)
|
||||
void exfat_truncate(struct inode *inode)
|
||||
{
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
@ -218,12 +228,11 @@ void exfat_truncate(struct inode *inode, loff_t size)
|
||||
goto write_size;
|
||||
}
|
||||
|
||||
err = __exfat_truncate(inode, i_size_read(inode));
|
||||
err = __exfat_truncate(inode);
|
||||
if (err)
|
||||
goto write_size;
|
||||
|
||||
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
|
||||
inode->i_blkbits;
|
||||
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
|
||||
write_size:
|
||||
aligned_size = i_size_read(inode);
|
||||
if (aligned_size & (blocksize - 1)) {
|
||||
@ -240,9 +249,15 @@ write_size:
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
int exfat_getattr(struct mnt_idmap *idmap, const struct path *path,
|
||||
struct kstat *stat, unsigned int request_mask,
|
||||
unsigned int query_flags)
|
||||
#else
|
||||
int exfat_getattr(struct user_namespace *mnt_uerns, const struct path *path,
|
||||
struct kstat *stat, unsigned int request_mask,
|
||||
unsigned int query_flags)
|
||||
#endif
|
||||
#else
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
||||
int exfat_getattr(const struct path *path, struct kstat *stat,
|
||||
@ -261,7 +276,15 @@ int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
|
||||
#else
|
||||
generic_fillattr(&nop_mnt_idmap, inode, stat);
|
||||
#endif
|
||||
#else
|
||||
generic_fillattr(&init_user_ns, inode, stat);
|
||||
#endif
|
||||
#else
|
||||
generic_fillattr(inode, stat);
|
||||
#endif
|
||||
@ -276,8 +299,13 @@ int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
int exfat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
struct iattr *attr)
|
||||
#else
|
||||
int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
||||
struct iattr *attr)
|
||||
#endif
|
||||
#else
|
||||
int exfat_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
#endif
|
||||
@ -307,7 +335,11 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 37))) || \
|
||||
(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
error = setattr_prepare(&nop_mnt_idmap, dentry, attr);
|
||||
#else
|
||||
error = setattr_prepare(&init_user_ns, dentry, attr);
|
||||
#endif
|
||||
#else
|
||||
error = setattr_prepare(dentry, attr);
|
||||
#endif
|
||||
@ -339,17 +371,34 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
|
||||
if (attr->ia_valid & ATTR_SIZE)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
|
||||
#else
|
||||
inode->i_mtime = inode_set_ctime_current(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_ctime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
setattr_copy(&nop_mnt_idmap, inode, attr);
|
||||
exfat_truncate_inode_atime(inode);
|
||||
#else
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
setattr_copy(&nop_mnt_idmap, inode, attr);
|
||||
#else
|
||||
setattr_copy(&init_user_ns, inode, attr);
|
||||
#endif
|
||||
#else
|
||||
setattr_copy(inode, attr);
|
||||
#endif
|
||||
exfat_truncate_atime(&inode->i_atime);
|
||||
#endif
|
||||
|
||||
if (attr->ia_valid & ATTR_SIZE) {
|
||||
error = exfat_block_truncate_page(inode, attr->ia_size);
|
||||
@ -362,7 +411,7 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
* __exfat_write_inode() is called from exfat_truncate(), inode
|
||||
* is already written by it, so mark_inode_dirty() is unneeded.
|
||||
*/
|
||||
exfat_truncate(inode, attr->ia_size);
|
||||
exfat_truncate(inode);
|
||||
up_write(&EXFAT_I(inode)->truncate_lock);
|
||||
} else
|
||||
mark_inode_dirty(inode);
|
||||
@ -370,6 +419,131 @@ out:
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* modified ioctls from fat/file.c by Welmer Almesberger
|
||||
*/
|
||||
static int exfat_ioctl_get_attributes(struct inode *inode, u32 __user *user_attr)
|
||||
{
|
||||
u32 attr;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
|
||||
inode_lock_shared(inode);
|
||||
#else
|
||||
mutex_lock(&inode->i_mutex);
|
||||
#endif
|
||||
attr = exfat_make_attr(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
|
||||
inode_unlock_shared(inode);
|
||||
#else
|
||||
mutex_unlock(&inode->i_mutex);
|
||||
#endif
|
||||
|
||||
return put_user(attr, user_attr);
|
||||
}
|
||||
|
||||
static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
|
||||
{
|
||||
struct inode *inode = file_inode(file);
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
|
||||
int is_dir = S_ISDIR(inode->i_mode);
|
||||
u32 attr, oldattr;
|
||||
struct iattr ia;
|
||||
int err;
|
||||
|
||||
err = get_user(attr, user_attr);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = mnt_want_write_file(file);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
|
||||
inode_lock(inode);
|
||||
#else
|
||||
mutex_lock(&inode->i_mutex);
|
||||
#endif
|
||||
|
||||
oldattr = exfat_make_attr(inode);
|
||||
|
||||
/*
|
||||
* Mask attributes so we don't set reserved fields.
|
||||
*/
|
||||
attr &= (EXFAT_ATTR_READONLY | EXFAT_ATTR_HIDDEN | EXFAT_ATTR_SYSTEM |
|
||||
EXFAT_ATTR_ARCHIVE);
|
||||
attr |= (is_dir ? EXFAT_ATTR_SUBDIR : 0);
|
||||
|
||||
/* Equivalent to a chmod() */
|
||||
ia.ia_valid = ATTR_MODE | ATTR_CTIME;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
||||
ia.ia_ctime = current_time(inode);
|
||||
#else
|
||||
ia.ia_ctime = current_fs_time(inode->i_sb);
|
||||
#endif
|
||||
if (is_dir)
|
||||
ia.ia_mode = exfat_make_mode(sbi, attr, 0777);
|
||||
else
|
||||
ia.ia_mode = exfat_make_mode(sbi, attr, 0666 | (inode->i_mode & 0111));
|
||||
|
||||
/* The root directory has no attributes */
|
||||
if (inode->i_ino == EXFAT_ROOT_INO && attr != EXFAT_ATTR_SUBDIR) {
|
||||
err = -EINVAL;
|
||||
goto out_unlock_inode;
|
||||
}
|
||||
|
||||
if (((attr | oldattr) & EXFAT_ATTR_SYSTEM) &&
|
||||
!capable(CAP_LINUX_IMMUTABLE)) {
|
||||
err = -EPERM;
|
||||
goto out_unlock_inode;
|
||||
}
|
||||
|
||||
/*
|
||||
* The security check is questionable... We single
|
||||
* out the RO attribute for checking by the security
|
||||
* module, just because it maps to a file mode.
|
||||
*/
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
err = security_inode_setattr(file_mnt_idmap(file),
|
||||
file->f_path.dentry, &ia);
|
||||
#else
|
||||
err = security_inode_setattr(file_mnt_user_ns(file),
|
||||
file->f_path.dentry, &ia);
|
||||
#endif
|
||||
#else
|
||||
err = security_inode_setattr(file->f_path.dentry, &ia);
|
||||
#endif
|
||||
if (err)
|
||||
goto out_unlock_inode;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
/* This MUST be done before doing anything irreversible... */
|
||||
err = exfat_setattr(file_mnt_idmap(file), file->f_path.dentry, &ia);
|
||||
#else
|
||||
err = exfat_setattr(file_mnt_user_ns(file), file->f_path.dentry, &ia);
|
||||
#endif
|
||||
#else
|
||||
err = exfat_setattr(file->f_path.dentry, &ia);
|
||||
#endif
|
||||
if (err)
|
||||
goto out_unlock_inode;
|
||||
|
||||
fsnotify_change(file->f_path.dentry, ia.ia_valid);
|
||||
|
||||
exfat_save_attr(inode, attr);
|
||||
mark_inode_dirty(inode);
|
||||
out_unlock_inode:
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
|
||||
inode_unlock(inode);
|
||||
#else
|
||||
mutex_unlock(&inode->i_mutex);
|
||||
#endif
|
||||
mnt_drop_write_file(file);
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
|
||||
{
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0)
|
||||
@ -412,8 +586,13 @@ static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
|
||||
long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
u32 __user *user_attr = (u32 __user *)arg;
|
||||
|
||||
switch (cmd) {
|
||||
case FAT_IOCTL_GET_ATTRIBUTES:
|
||||
return exfat_ioctl_get_attributes(inode, user_attr);
|
||||
case FAT_IOCTL_SET_ATTRIBUTES:
|
||||
return exfat_ioctl_set_attributes(filp, user_attr);
|
||||
case FITRIM:
|
||||
return exfat_ioctl_fitrim(inode, arg);
|
||||
default:
|
||||
@ -463,7 +642,11 @@ const struct file_operations exfat_file_operations = {
|
||||
#endif
|
||||
.mmap = generic_file_mmap,
|
||||
.fsync = exfat_file_fsync,
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
|
||||
.splice_read = filemap_splice_read,
|
||||
#else
|
||||
.splice_read = generic_file_splice_read,
|
||||
#endif
|
||||
.splice_write = iter_file_splice_write,
|
||||
};
|
||||
|
||||
|
@ -23,11 +23,14 @@ int __exfat_write_inode(struct inode *inode, int sync)
|
||||
{
|
||||
unsigned long long on_disk_size;
|
||||
struct exfat_dentry *ep, *ep2;
|
||||
struct exfat_entry_set_cache *es = NULL;
|
||||
struct exfat_entry_set_cache es;
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
struct exfat_inode_info *ei = EXFAT_I(inode);
|
||||
bool is_dir = (ei->type == TYPE_DIR) ? true : false;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
struct timespec64 ts;
|
||||
#endif
|
||||
|
||||
if (inode->i_ino == EXFAT_ROOT_INO)
|
||||
return 0;
|
||||
@ -44,11 +47,10 @@ int __exfat_write_inode(struct inode *inode, int sync)
|
||||
exfat_set_volume_dirty(sb);
|
||||
|
||||
/* get the directory entry of given file or directory */
|
||||
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES);
|
||||
if (!es)
|
||||
if (exfat_get_dentry_set(&es, sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES))
|
||||
return -EIO;
|
||||
ep = exfat_get_dentry_cached(es, 0);
|
||||
ep2 = exfat_get_dentry_cached(es, 1);
|
||||
ep = exfat_get_dentry_cached(&es, ES_IDX_FILE);
|
||||
ep2 = exfat_get_dentry_cached(&es, ES_IDX_STREAM);
|
||||
|
||||
ep->dentry.file.attr = cpu_to_le16(exfat_make_attr(inode));
|
||||
|
||||
@ -58,6 +60,20 @@ int __exfat_write_inode(struct inode *inode, int sync)
|
||||
&ep->dentry.file.create_time,
|
||||
&ep->dentry.file.create_date,
|
||||
&ep->dentry.file.create_time_cs);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
ts = inode_get_mtime(inode);
|
||||
exfat_set_entry_time(sbi, &ts,
|
||||
&ep->dentry.file.modify_tz,
|
||||
&ep->dentry.file.modify_time,
|
||||
&ep->dentry.file.modify_date,
|
||||
&ep->dentry.file.modify_time_cs);
|
||||
ts = inode_get_atime(inode);
|
||||
exfat_set_entry_time(sbi, &ts,
|
||||
&ep->dentry.file.access_tz,
|
||||
&ep->dentry.file.access_time,
|
||||
&ep->dentry.file.access_date,
|
||||
NULL);
|
||||
#else
|
||||
exfat_set_entry_time(sbi, &inode->i_mtime,
|
||||
&ep->dentry.file.modify_tz,
|
||||
&ep->dentry.file.modify_time,
|
||||
@ -68,6 +84,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
|
||||
&ep->dentry.file.access_time,
|
||||
&ep->dentry.file.access_date,
|
||||
NULL);
|
||||
#endif
|
||||
|
||||
/* File size should be zero if there is no cluster allocated */
|
||||
on_disk_size = i_size_read(inode);
|
||||
@ -85,8 +102,8 @@ int __exfat_write_inode(struct inode *inode, int sync)
|
||||
ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER;
|
||||
}
|
||||
|
||||
exfat_update_dir_chksum_with_entry_set(es);
|
||||
return exfat_free_dentry_set(es, sync);
|
||||
exfat_update_dir_chksum_with_entry_set(&es);
|
||||
return exfat_put_dentry_set(&es, sync);
|
||||
}
|
||||
|
||||
int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
|
||||
@ -223,8 +240,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
|
||||
num_clusters += num_to_be_allocated;
|
||||
*clu = new_clu.dir;
|
||||
|
||||
inode->i_blocks +=
|
||||
num_to_be_allocated << sbi->sect_per_clus_bits;
|
||||
inode->i_blocks += EXFAT_CLU_TO_B(num_to_be_allocated, sbi) >> 9;
|
||||
|
||||
/*
|
||||
* Move *clu pointer along FAT chains (hole care) because the
|
||||
@ -362,10 +378,12 @@ static int exfat_readpages(struct file *file, struct address_space *mapping,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)
|
||||
static int exfat_writepage(struct page *page, struct writeback_control *wbc)
|
||||
{
|
||||
return block_write_full_page(page, exfat_get_block, wbc);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int exfat_writepages(struct address_space *mapping,
|
||||
struct writeback_control *wbc)
|
||||
@ -380,11 +398,19 @@ static void exfat_write_failed(struct address_space *mapping, loff_t to)
|
||||
if (to > i_size_read(inode)) {
|
||||
truncate_pagecache(inode, i_size_read(inode));
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
|
||||
#else
|
||||
inode->i_mtime = inode_set_ctime_current(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_ctime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate(inode, EXFAT_I(inode)->i_size_aligned);
|
||||
exfat_truncate(inode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -436,13 +462,21 @@ static int exfat_write_end(struct file *file, struct address_space *mapping,
|
||||
if (err < len)
|
||||
exfat_write_failed(mapping, pos+len);
|
||||
|
||||
if (!(err < 0) && !(ei->attr & ATTR_ARCHIVE)) {
|
||||
if (!(err < 0) && !(ei->attr & EXFAT_ATTR_ARCHIVE)) {
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
|
||||
#else
|
||||
inode->i_mtime = inode_set_ctime_current(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_ctime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
ei->attr |= ATTR_ARCHIVE;
|
||||
ei->attr |= EXFAT_ATTR_ARCHIVE;
|
||||
mark_inode_dirty(inode);
|
||||
}
|
||||
|
||||
@ -533,12 +567,19 @@ static const struct address_space_operations exfat_aops = {
|
||||
#else
|
||||
.readpages = exfat_readpages,
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)
|
||||
.writepage = exfat_writepage,
|
||||
#endif
|
||||
.writepages = exfat_writepages,
|
||||
.write_begin = exfat_write_begin,
|
||||
.write_end = exfat_write_end,
|
||||
.direct_IO = exfat_direct_IO,
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)
|
||||
.bmap = exfat_aop_bmap
|
||||
#else
|
||||
.bmap = exfat_aop_bmap,
|
||||
.migrate_folio = buffer_migrate_folio,
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline unsigned long exfat_hash(loff_t i_pos)
|
||||
@ -616,9 +657,13 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
|
||||
#else
|
||||
inode->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
|
||||
inode->i_generation = get_random_u32();
|
||||
#else
|
||||
inode->i_generation = prandom_u32();
|
||||
#endif
|
||||
|
||||
if (info->attr & ATTR_SUBDIR) { /* directory */
|
||||
if (info->attr & EXFAT_ATTR_SUBDIR) { /* directory */
|
||||
inode->i_generation &= ~1;
|
||||
inode->i_mode = exfat_make_mode(sbi, info->attr, 0777);
|
||||
inode->i_op = &exfat_dir_inode_operations;
|
||||
@ -646,12 +691,23 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
|
||||
|
||||
exfat_save_attr(inode, info->attr);
|
||||
|
||||
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
|
||||
inode->i_blkbits;
|
||||
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(inode, info->mtime);
|
||||
#else
|
||||
inode->i_mtime = info->mtime;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
inode_set_ctime_to_ts(inode, info->mtime);
|
||||
#else
|
||||
inode->i_ctime = info->mtime;
|
||||
#endif
|
||||
ei->i_crtime = info->crtime;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_atime_to_ts(inode, info->atime);
|
||||
#else
|
||||
inode->i_atime = info->atime;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -695,7 +751,7 @@ void exfat_evict_inode(struct inode *inode)
|
||||
if (!inode->i_nlink) {
|
||||
i_size_write(inode, 0);
|
||||
mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock);
|
||||
__exfat_truncate(inode, 0);
|
||||
__exfat_truncate(inode);
|
||||
mutex_unlock(&EXFAT_SB(inode->i_sb)->s_lock);
|
||||
}
|
||||
|
||||
|
@ -163,6 +163,16 @@ void exfat_truncate_atime(struct timespec *ts)
|
||||
ts->tv_nsec = 0;
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
void exfat_truncate_inode_atime(struct inode *inode)
|
||||
{
|
||||
struct timespec64 atime = inode_get_atime(inode);
|
||||
|
||||
exfat_truncate_atime(&atime);
|
||||
inode_set_atime_to_ts(inode, atime);
|
||||
}
|
||||
#endif
|
||||
|
||||
u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type)
|
||||
{
|
||||
int i;
|
||||
|
244
fs/exfat/namei.c
244
fs/exfat/namei.c
@ -251,11 +251,18 @@ static int exfat_search_empty_slot(struct super_block *sb,
|
||||
|
||||
if (hint_femp->eidx != EXFAT_HINT_NONE) {
|
||||
dentry = hint_femp->eidx;
|
||||
if (num_entries <= hint_femp->count) {
|
||||
hint_femp->eidx = EXFAT_HINT_NONE;
|
||||
return dentry;
|
||||
}
|
||||
|
||||
/*
|
||||
* If hint_femp->count is enough, it is needed to check if
|
||||
* there are actual empty entries.
|
||||
* Otherwise, and if "dentry + hint_famp->count" is also equal
|
||||
* to "p_dir->size * dentries_per_clu", it means ENOSPC.
|
||||
*/
|
||||
if (dentry + hint_femp->count == p_dir->size * dentries_per_clu &&
|
||||
num_entries > hint_femp->count)
|
||||
return -ENOSPC;
|
||||
|
||||
hint_femp->eidx = EXFAT_HINT_NONE;
|
||||
exfat_chain_dup(&clu, &hint_femp->cur);
|
||||
} else {
|
||||
exfat_chain_dup(&clu, p_dir);
|
||||
@ -320,6 +327,12 @@ static int exfat_search_empty_slot(struct super_block *sb,
|
||||
}
|
||||
}
|
||||
|
||||
hint_femp->eidx = p_dir->size * dentries_per_clu - num_empty;
|
||||
hint_femp->count = num_empty;
|
||||
if (num_empty == 0)
|
||||
exfat_chain_set(&hint_femp->cur, EXFAT_EOF_CLUSTER, 0,
|
||||
clu.flags);
|
||||
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
@ -365,14 +378,20 @@ static int exfat_find_empty_entry(struct inode *inode,
|
||||
if (exfat_check_max_dentries(inode))
|
||||
return -ENOSPC;
|
||||
|
||||
/* we trust p_dir->size regardless of FAT type */
|
||||
if (exfat_find_last_cluster(sb, p_dir, &last_clu))
|
||||
return -EIO;
|
||||
|
||||
/*
|
||||
* Allocate new cluster to this directory
|
||||
*/
|
||||
exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags);
|
||||
if (ei->start_clu != EXFAT_EOF_CLUSTER) {
|
||||
/* we trust p_dir->size regardless of FAT type */
|
||||
if (exfat_find_last_cluster(sb, p_dir, &last_clu))
|
||||
return -EIO;
|
||||
|
||||
exfat_chain_set(&clu, last_clu + 1, 0, p_dir->flags);
|
||||
} else {
|
||||
/* This directory is empty */
|
||||
exfat_chain_set(&clu, EXFAT_EOF_CLUSTER, 0,
|
||||
ALLOC_NO_FAT_CHAIN);
|
||||
}
|
||||
|
||||
/* allocate a cluster */
|
||||
ret = exfat_alloc_cluster(inode, 1, &clu, IS_DIRSYNC(inode));
|
||||
@ -382,6 +401,11 @@ static int exfat_find_empty_entry(struct inode *inode,
|
||||
if (exfat_zeroed_cluster(inode, clu.dir))
|
||||
return -EIO;
|
||||
|
||||
if (ei->start_clu == EXFAT_EOF_CLUSTER) {
|
||||
ei->start_clu = clu.dir;
|
||||
p_dir->dir = clu.dir;
|
||||
}
|
||||
|
||||
/* append to the FAT chain */
|
||||
if (clu.flags != p_dir->flags) {
|
||||
/* no-fat-chain bit is disabled,
|
||||
@ -396,15 +420,11 @@ static int exfat_find_empty_entry(struct inode *inode,
|
||||
if (exfat_ent_set(sb, last_clu, clu.dir))
|
||||
return -EIO;
|
||||
|
||||
if (hint_femp.eidx == EXFAT_HINT_NONE) {
|
||||
/* the special case that new dentry
|
||||
* should be allocated from the start of new cluster
|
||||
*/
|
||||
hint_femp.eidx = EXFAT_B_TO_DEN_IDX(p_dir->size, sbi);
|
||||
hint_femp.count = sbi->dentries_per_clu;
|
||||
|
||||
if (hint_femp.cur.dir == EXFAT_EOF_CLUSTER)
|
||||
exfat_chain_set(&hint_femp.cur, clu.dir, 0, clu.flags);
|
||||
}
|
||||
|
||||
hint_femp.count += sbi->dentries_per_clu;
|
||||
|
||||
hint_femp.cur.size++;
|
||||
p_dir->size++;
|
||||
size = EXFAT_CLU_TO_B(p_dir->size, sbi);
|
||||
@ -414,7 +434,7 @@ static int exfat_find_empty_entry(struct inode *inode,
|
||||
ei->i_size_ondisk += sbi->cluster_size;
|
||||
ei->i_size_aligned += sbi->cluster_size;
|
||||
ei->flags = p_dir->flags;
|
||||
inode->i_blocks += 1 << sbi->sect_per_clus_bits;
|
||||
inode->i_blocks += sbi->cluster_size >> 9;
|
||||
}
|
||||
|
||||
return dentry;
|
||||
@ -525,7 +545,7 @@ static int exfat_add_entry(struct inode *inode, const char *path,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (type == TYPE_DIR) {
|
||||
if (type == TYPE_DIR && !sbi->options.zero_size_dir) {
|
||||
ret = exfat_alloc_new_dir(inode, &clu);
|
||||
if (ret)
|
||||
goto out;
|
||||
@ -552,13 +572,16 @@ static int exfat_add_entry(struct inode *inode, const char *path,
|
||||
info->type = type;
|
||||
|
||||
if (type == TYPE_FILE) {
|
||||
info->attr = ATTR_ARCHIVE;
|
||||
info->attr = EXFAT_ATTR_ARCHIVE;
|
||||
info->start_clu = EXFAT_EOF_CLUSTER;
|
||||
info->size = 0;
|
||||
info->num_subdirs = 0;
|
||||
} else {
|
||||
info->attr = ATTR_SUBDIR;
|
||||
info->start_clu = start_clu;
|
||||
info->attr = EXFAT_ATTR_SUBDIR;
|
||||
if (sbi->options.zero_size_dir)
|
||||
info->start_clu = EXFAT_EOF_CLUSTER;
|
||||
else
|
||||
info->start_clu = start_clu;
|
||||
info->size = clu_size;
|
||||
info->num_subdirs = EXFAT_MIN_SUBDIR;
|
||||
}
|
||||
@ -570,8 +593,13 @@ out:
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
static int exfat_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, bool excl)
|
||||
#else
|
||||
static int exfat_create(struct user_namespace *mnt_userns, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, bool excl)
|
||||
#endif
|
||||
#else
|
||||
static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
||||
bool excl)
|
||||
@ -597,7 +625,15 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
||||
dir->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
|
||||
#else
|
||||
dir->i_mtime = inode_set_ctime_current(dir);
|
||||
#endif
|
||||
#else
|
||||
dir->i_ctime = dir->i_mtime = current_time(dir);
|
||||
#endif
|
||||
#else
|
||||
dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
@ -618,14 +654,23 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
||||
inode->i_version++;
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode);
|
||||
exfat_truncate_inode_atime(inode);
|
||||
#else
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
inode->i_mtime = inode->i_atime = EXFAT_I(inode)->i_crtime = inode_set_ctime_current(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime =
|
||||
EXFAT_I(inode)->i_crtime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime =
|
||||
EXFAT_I(inode)->i_crtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&inode->i_atime);
|
||||
#endif
|
||||
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
|
||||
|
||||
d_instantiate(dentry, inode);
|
||||
@ -638,14 +683,14 @@ unlock:
|
||||
static int exfat_find(struct inode *dir, struct qstr *qname,
|
||||
struct exfat_dir_entry *info)
|
||||
{
|
||||
int ret, dentry, num_entries, count;
|
||||
int ret, dentry, count;
|
||||
struct exfat_chain cdir;
|
||||
struct exfat_uni_name uni_name;
|
||||
struct super_block *sb = dir->i_sb;
|
||||
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
||||
struct exfat_inode_info *ei = EXFAT_I(dir);
|
||||
struct exfat_dentry *ep, *ep2;
|
||||
struct exfat_entry_set_cache *es;
|
||||
struct exfat_entry_set_cache es;
|
||||
/* for optimized dir & entry to prevent long traverse of cluster chain */
|
||||
struct exfat_hint hint_opt;
|
||||
|
||||
@ -657,10 +702,6 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
num_entries = exfat_calc_num_entries(&uni_name);
|
||||
if (num_entries < 0)
|
||||
return num_entries;
|
||||
|
||||
/* check the validation of hint_stat and initialize it if required */
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
|
||||
if (ei->version != (inode_peek_iversion_raw(dir) & 0xffffffff)) {
|
||||
@ -678,9 +719,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
||||
}
|
||||
|
||||
/* search the file name for directories */
|
||||
dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name,
|
||||
num_entries, TYPE_ALL, &hint_opt);
|
||||
|
||||
dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name, &hint_opt);
|
||||
if (dentry < 0)
|
||||
return dentry; /* -error value */
|
||||
|
||||
@ -693,16 +732,15 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
||||
if (cdir.flags & ALLOC_NO_FAT_CHAIN)
|
||||
cdir.size -= dentry / sbi->dentries_per_clu;
|
||||
dentry = hint_opt.eidx;
|
||||
es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES);
|
||||
if (!es)
|
||||
if (exfat_get_dentry_set(&es, sb, &cdir, dentry, ES_2_ENTRIES))
|
||||
return -EIO;
|
||||
ep = exfat_get_dentry_cached(es, 0);
|
||||
ep2 = exfat_get_dentry_cached(es, 1);
|
||||
ep = exfat_get_dentry_cached(&es, ES_IDX_FILE);
|
||||
ep2 = exfat_get_dentry_cached(&es, ES_IDX_STREAM);
|
||||
|
||||
info->type = exfat_get_entry_type(ep);
|
||||
info->attr = le16_to_cpu(ep->dentry.file.attr);
|
||||
info->size = le64_to_cpu(ep2->dentry.stream.valid_size);
|
||||
if ((info->type == TYPE_FILE) && (info->size == 0)) {
|
||||
if (info->size == 0) {
|
||||
info->flags = ALLOC_NO_FAT_CHAIN;
|
||||
info->start_clu = EXFAT_EOF_CLUSTER;
|
||||
} else {
|
||||
@ -726,7 +764,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
|
||||
ep->dentry.file.access_time,
|
||||
ep->dentry.file.access_date,
|
||||
0);
|
||||
exfat_free_dentry_set(es, false);
|
||||
exfat_put_dentry_set(&es, false);
|
||||
|
||||
if (ei->start_clu == EXFAT_FREE_CLUSTER) {
|
||||
exfat_fs_error(sb,
|
||||
@ -881,24 +919,43 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
|
||||
#else
|
||||
dir->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
dir->i_mtime = dir->i_atime = current_time(dir);
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
simple_inode_init_ts(dir);
|
||||
exfat_truncate_inode_atime(dir);
|
||||
#else
|
||||
dir->i_mtime = dir->i_atime = CURRENT_TIME_SEC;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
dir->i_mtime = dir->i_atime = inode_set_ctime_current(dir);
|
||||
#else
|
||||
dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
|
||||
#endif
|
||||
#else
|
||||
dir->i_mtime = dir->i_atime = dir->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&dir->i_atime);
|
||||
#endif
|
||||
if (IS_DIRSYNC(dir))
|
||||
exfat_sync_inode(dir);
|
||||
else
|
||||
mark_inode_dirty(dir);
|
||||
|
||||
clear_nlink(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
inode->i_mtime = inode->i_atime = current_time(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
simple_inode_init_ts(inode);
|
||||
exfat_truncate_inode_atime(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = dir->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&inode->i_atime);
|
||||
#endif
|
||||
exfat_unhash_inode(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
|
||||
exfat_d_version_set(dentry, inode_query_iversion(dir));
|
||||
@ -911,8 +968,13 @@ unlock:
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
static int exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode)
|
||||
#else
|
||||
static int exfat_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode)
|
||||
#endif
|
||||
#else
|
||||
static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
#endif
|
||||
@ -938,7 +1000,15 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
|
||||
#else
|
||||
dir->i_mtime = inode_set_ctime_current(dir);
|
||||
#endif
|
||||
#else
|
||||
dir->i_ctime = dir->i_mtime = current_time(dir);
|
||||
#endif
|
||||
#else
|
||||
dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
@ -959,14 +1029,23 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
#else
|
||||
inode->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode);
|
||||
exfat_truncate_inode_atime(inode);
|
||||
#else
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
inode->i_mtime = inode->i_atime = EXFAT_I(inode)->i_crtime = inode_set_ctime_current(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime =
|
||||
EXFAT_I(inode)->i_crtime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime =
|
||||
EXFAT_I(inode)->i_crtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&inode->i_atime);
|
||||
#endif
|
||||
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
|
||||
|
||||
d_instantiate(dentry, inode);
|
||||
@ -988,6 +1067,9 @@ static int exfat_check_dir_empty(struct super_block *sb,
|
||||
|
||||
dentries_per_clu = sbi->dentries_per_clu;
|
||||
|
||||
if (p_dir->dir == EXFAT_EOF_CLUSTER)
|
||||
return 0;
|
||||
|
||||
exfat_chain_dup(&clu, p_dir);
|
||||
|
||||
while (clu.dir != EXFAT_EOF_CLUSTER) {
|
||||
@ -1081,12 +1163,21 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
|
||||
#else
|
||||
dir->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
dir->i_mtime = dir->i_atime = current_time(dir);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
simple_inode_init_ts(dir);
|
||||
exfat_truncate_inode_atime(dir);
|
||||
#else
|
||||
dir->i_mtime = dir->i_atime = CURRENT_TIME_SEC;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
dir->i_mtime = dir->i_atime = inode_set_ctime_current(dir);
|
||||
#else
|
||||
dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
|
||||
#endif
|
||||
#else
|
||||
dir->i_mtime = dir->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&dir->i_atime);
|
||||
#endif
|
||||
if (IS_DIRSYNC(dir))
|
||||
exfat_sync_inode(dir);
|
||||
else
|
||||
@ -1094,12 +1185,21 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
|
||||
drop_nlink(dir);
|
||||
|
||||
clear_nlink(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
inode->i_mtime = inode->i_atime = current_time(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
simple_inode_init_ts(inode);
|
||||
exfat_truncate_inode_atime(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&inode->i_atime);
|
||||
#endif
|
||||
exfat_unhash_inode(inode);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
|
||||
exfat_d_version_set(dentry, inode_query_iversion(dir));
|
||||
@ -1148,8 +1248,8 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
|
||||
|
||||
*epnew = *epold;
|
||||
if (exfat_get_entry_type(epnew) == TYPE_FILE) {
|
||||
epnew->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE);
|
||||
ei->attr |= ATTR_ARCHIVE;
|
||||
epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE);
|
||||
ei->attr |= EXFAT_ATTR_ARCHIVE;
|
||||
}
|
||||
exfat_update_bh(new_bh, sync);
|
||||
brelse(old_bh);
|
||||
@ -1180,8 +1280,8 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
|
||||
ei->entry = newentry;
|
||||
} else {
|
||||
if (exfat_get_entry_type(epold) == TYPE_FILE) {
|
||||
epold->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE);
|
||||
ei->attr |= ATTR_ARCHIVE;
|
||||
epold->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE);
|
||||
ei->attr |= EXFAT_ATTR_ARCHIVE;
|
||||
}
|
||||
exfat_update_bh(old_bh, sync);
|
||||
brelse(old_bh);
|
||||
@ -1229,8 +1329,8 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
|
||||
|
||||
*epnew = *epmov;
|
||||
if (exfat_get_entry_type(epnew) == TYPE_FILE) {
|
||||
epnew->dentry.file.attr |= cpu_to_le16(ATTR_ARCHIVE);
|
||||
ei->attr |= ATTR_ARCHIVE;
|
||||
epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE);
|
||||
ei->attr |= EXFAT_ATTR_ARCHIVE;
|
||||
}
|
||||
exfat_update_bh(new_bh, IS_DIRSYNC(inode));
|
||||
brelse(mov_bh);
|
||||
@ -1283,7 +1383,7 @@ static int __exfat_rename(struct inode *old_parent_inode,
|
||||
struct exfat_inode_info *new_ei = NULL;
|
||||
unsigned int new_entry_type = TYPE_UNUSED;
|
||||
int new_entry = 0;
|
||||
struct buffer_head *old_bh, *new_bh = NULL;
|
||||
struct buffer_head *new_bh = NULL;
|
||||
|
||||
/* check the validity of pointer parameters */
|
||||
if (new_path == NULL || strlen(new_path) == 0)
|
||||
@ -1299,13 +1399,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
|
||||
EXFAT_I(old_parent_inode)->flags);
|
||||
dentry = ei->entry;
|
||||
|
||||
ep = exfat_get_dentry(sb, &olddir, dentry, &old_bh);
|
||||
if (!ep) {
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
brelse(old_bh);
|
||||
|
||||
/* check whether new dir is existing directory and empty */
|
||||
if (new_inode) {
|
||||
ret = -EIO;
|
||||
@ -1378,7 +1471,8 @@ static int __exfat_rename(struct inode *old_parent_inode,
|
||||
}
|
||||
|
||||
/* Free the clusters if new_inode is a dir(as if exfat_rmdir) */
|
||||
if (new_entry_type == TYPE_DIR) {
|
||||
if (new_entry_type == TYPE_DIR &&
|
||||
new_ei->start_clu != EXFAT_EOF_CLUSTER) {
|
||||
/* new_ei, new_clu_to_free */
|
||||
struct exfat_chain new_clu_to_free;
|
||||
|
||||
@ -1407,10 +1501,17 @@ out:
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
|
||||
static int exfat_rename(struct mnt_idmap *idmap,
|
||||
struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry,
|
||||
unsigned int flags)
|
||||
#else
|
||||
static int exfat_rename(struct user_namespace *mnt_userns,
|
||||
struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry,
|
||||
unsigned int flags)
|
||||
#endif
|
||||
#else
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
|
||||
static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
@ -1451,13 +1552,22 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
new_dir->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry);
|
||||
EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
|
||||
#else
|
||||
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
|
||||
EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
|
||||
#endif
|
||||
#else
|
||||
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
|
||||
EXFAT_I(new_dir)->i_crtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
exfat_truncate_inode_atime(new_dir);
|
||||
#else
|
||||
exfat_truncate_atime(&new_dir->i_atime);
|
||||
#endif
|
||||
if (IS_DIRSYNC(new_dir))
|
||||
exfat_sync_inode(new_dir);
|
||||
else
|
||||
@ -1484,7 +1594,9 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
old_dir->i_version++;
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6, 6, 0)
|
||||
old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
|
||||
#endif
|
||||
#else
|
||||
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
|
||||
#endif
|
||||
@ -1506,8 +1618,12 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
WARN_ON(new_inode->i_nlink == 0);
|
||||
}
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
EXFAT_I(new_inode)->i_crtime = current_time(new_inode);
|
||||
#else
|
||||
new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime =
|
||||
current_time(new_inode);
|
||||
#endif
|
||||
#else
|
||||
new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime =
|
||||
CURRENT_TIME_SEC;
|
||||
|
@ -195,6 +195,8 @@ static int exfat_show_options(struct seq_file *m, struct dentry *root)
|
||||
seq_puts(m, ",sys_tz");
|
||||
else if (opts->time_offset)
|
||||
seq_printf(m, ",time_offset=%d", opts->time_offset);
|
||||
if (opts->zero_size_dir)
|
||||
seq_puts(m, ",zero_size_dir");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -278,6 +280,7 @@ enum {
|
||||
Opt_keep_last_dots,
|
||||
Opt_sys_tz,
|
||||
Opt_time_offset,
|
||||
Opt_zero_size_dir,
|
||||
|
||||
/* Deprecated options */
|
||||
Opt_utf8,
|
||||
@ -323,6 +326,7 @@ static const struct fs_parameter_spec exfat_param_specs[] = {
|
||||
fsparam_flag("keep_last_dots", Opt_keep_last_dots),
|
||||
fsparam_flag("sys_tz", Opt_sys_tz),
|
||||
fsparam_s32("time_offset", Opt_time_offset),
|
||||
fsparam_flag("zero_size_dir", Opt_zero_size_dir),
|
||||
__fsparam(NULL, "utf8", Opt_utf8, fs_param_deprecated,
|
||||
NULL),
|
||||
__fsparam(NULL, "debug", Opt_debug, fs_param_deprecated,
|
||||
@ -403,6 +407,9 @@ static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
||||
return -EINVAL;
|
||||
opts->time_offset = result.int_32;
|
||||
break;
|
||||
case Opt_zero_size_dir:
|
||||
opts->zero_size_dir = true;
|
||||
break;
|
||||
case Opt_utf8:
|
||||
case Opt_debug:
|
||||
case Opt_namecase:
|
||||
@ -435,6 +442,7 @@ enum {
|
||||
Opt_debug,
|
||||
Opt_namecase,
|
||||
Opt_codepage,
|
||||
Opt_zero_size_dir,
|
||||
Opt_fs,
|
||||
};
|
||||
|
||||
@ -454,6 +462,7 @@ static const match_table_t exfat_tokens = {
|
||||
{Opt_namecase, "namecase=%u"},
|
||||
{Opt_debug, "debug"},
|
||||
{Opt_utf8, "utf8"},
|
||||
{Opt_zero_size_dir, "zero_size_dir"},
|
||||
{Opt_err, NULL}
|
||||
};
|
||||
|
||||
@ -545,6 +554,9 @@ static int parse_options(struct super_block *sb, char *options, int silent,
|
||||
case Opt_namecase:
|
||||
case Opt_codepage:
|
||||
break;
|
||||
case Opt_zero_size_dir:
|
||||
opts->zero_size_dir = true;
|
||||
break;
|
||||
default:
|
||||
if (!silent) {
|
||||
exfat_err(sb,
|
||||
@ -628,25 +640,33 @@ static int exfat_read_root(struct inode *inode)
|
||||
inode->i_version++;
|
||||
#endif
|
||||
inode->i_generation = 0;
|
||||
inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, 0777);
|
||||
inode->i_mode = exfat_make_mode(sbi, EXFAT_ATTR_SUBDIR, 0777);
|
||||
inode->i_op = &exfat_dir_inode_operations;
|
||||
inode->i_fop = &exfat_dir_operations;
|
||||
|
||||
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
|
||||
inode->i_blkbits;
|
||||
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
|
||||
ei->i_pos = ((loff_t)sbi->root_dir << 32) | 0xffffffff;
|
||||
ei->i_size_aligned = i_size_read(inode);
|
||||
ei->i_size_ondisk = i_size_read(inode);
|
||||
|
||||
exfat_save_attr(inode, ATTR_SUBDIR);
|
||||
exfat_save_attr(inode, EXFAT_ATTR_SUBDIR);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
|
||||
ei->i_crtime = simple_inode_init_ts(inode);
|
||||
exfat_truncate_inode_atime(inode);
|
||||
#else
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
|
||||
inode->i_mtime = inode->i_atime = ei->i_crtime = inode_set_ctime_current(inode);
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
|
||||
current_time(inode);
|
||||
#endif
|
||||
#else
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
|
||||
CURRENT_TIME_SEC;
|
||||
#endif
|
||||
exfat_truncate_atime(&inode->i_atime);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user