Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from namjaejeon/exfat-next
Browse files Browse the repository at this point in the history
Exfat next
  • Loading branch information
namjaejeon authored Jul 3, 2020
2 parents 90419f2 + 4460428 commit e758ac7
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ script:
- sudo ./check generic/448
- sudo ./check generic/450
- sudo ./check generic/451
# - sudo ./check generic/452
- sudo ./check generic/452
4 changes: 2 additions & 2 deletions balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int exfat_set_bitmap(struct inode *inode, unsigned int clu)
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);

set_bit_le(b, sbi->vol_amap[i]->b_data);
exfat_update_bh(sb, sbi->vol_amap[i], IS_DIRSYNC(inode));
exfat_update_bh(sbi->vol_amap[i], IS_DIRSYNC(inode));
return 0;
}

Expand All @@ -180,7 +180,7 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu)
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);

clear_bit_le(b, sbi->vol_amap[i]->b_data);
exfat_update_bh(sb, sbi->vol_amap[i], IS_DIRSYNC(inode));
exfat_update_bh(sbi->vol_amap[i], IS_DIRSYNC(inode));

if (opts->discard) {
int ret_discard;
Expand Down
48 changes: 29 additions & 19 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ const struct file_operations exfat_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.iterate = exfat_iterate,
.fsync = generic_file_fsync,
.fsync = exfat_file_fsync,
};

int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu)
Expand Down Expand Up @@ -441,15 +441,21 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
struct timespec64 ts = current_time(inode);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
struct timespec64 ts;
#else
struct timespec64 ts = CURRENT_TIME_SEC;
struct timespec ts;
#endif
sector_t sector;
struct exfat_dentry *ep;
struct buffer_head *bh;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
ts = current_time(inode);
#else
ts = CURRENT_TIME_SEC;
#endif

/*
* We cannot use exfat_get_dentry_set here because file ep is not
* initialized yet.
Expand All @@ -475,7 +481,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
&ep->dentry.file.access_date,
NULL);

exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
exfat_update_bh(bh, IS_DIRSYNC(inode));
brelse(bh);

ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh, &sector);
Expand All @@ -485,7 +491,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
exfat_init_stream_entry(ep,
(type == TYPE_FILE) ? ALLOC_FAT_CHAIN : ALLOC_NO_FAT_CHAIN,
start_clu, size);
exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
exfat_update_bh(bh, IS_DIRSYNC(inode));
brelse(bh);

return 0;
Expand Down Expand Up @@ -521,7 +527,7 @@ int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir,
}

fep->dentry.file.checksum = cpu_to_le16(chksum);
exfat_update_bh(sb, fbh, IS_DIRSYNC(inode));
exfat_update_bh(fbh, IS_DIRSYNC(inode));
release_fbh:
brelse(fbh);
return ret;
Expand All @@ -543,7 +549,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
return -EIO;

ep->dentry.file.num_ext = (unsigned char)(num_entries - 1);
exfat_update_bh(sb, bh, sync);
exfat_update_bh(bh, sync);
brelse(bh);

ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh, &sector);
Expand All @@ -552,7 +558,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,

ep->dentry.stream.name_len = p_uniname->name_len;
ep->dentry.stream.name_hash = cpu_to_le16(p_uniname->name_hash);
exfat_update_bh(sb, bh, sync);
exfat_update_bh(bh, sync);
brelse(bh);

for (i = EXFAT_FIRST_CLUSTER; i < num_entries; i++) {
Expand All @@ -561,7 +567,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
return -EIO;

exfat_init_name_entry(ep, uniname);
exfat_update_bh(sb, bh, sync);
exfat_update_bh(bh, sync);
brelse(bh);
uniname += EXFAT_FILE_NAME_LEN;
}
Expand All @@ -585,7 +591,7 @@ int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir,
return -EIO;

exfat_set_entry_type(ep, TYPE_DELETED);
exfat_update_bh(sb, bh, IS_DIRSYNC(inode));
exfat_update_bh(bh, IS_DIRSYNC(inode));
brelse(bh);
}

Expand All @@ -609,16 +615,20 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
es->modified = true;
}

void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
{
int i;
int i, err = 0;

for (i = 0; i < es->num_bh; i++) {
if (es->modified)
exfat_update_bh(es->sb, es->bh[i], sync);
brelse(es->bh[i]);
}
if (es->modified)
err = exfat_update_bhs(es->bh, es->num_bh, sync);

for (i = 0; i < es->num_bh; i++)
if (err)
bforget(es->bh[i]);
else
brelse(es->bh[i]);
kfree(es);
return err;
}

static int exfat_walk_fat_chain(struct super_block *sb,
Expand Down Expand Up @@ -1117,7 +1127,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
ret = exfat_get_next_cluster(sb, &clu.dir);
}

if (ret || clu.dir != EXFAT_EOF_CLUSTER) {
if (ret || clu.dir == EXFAT_EOF_CLUSTER) {
/* just initialized hint_stat */
hint_stat->clu = p_dir->dir;
hint_stat->eidx = 0;
Expand Down
31 changes: 24 additions & 7 deletions exfat_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
#include <linux/ratelimit.h>
#include <linux/nls.h>

#define EXFAT_VERSION "5.8.1"
#define EXFAT_VERSION "5.8.4"

#define EXFAT_SUPER_MAGIC 0x2011BAB0UL
#define EXFAT_ROOT_INO 1

#define EXFAT_SB_DIRTY 0

#define EXFAT_CLUSTERS_UNTRACKED (~0u)

/*
Expand Down Expand Up @@ -188,9 +186,15 @@ struct exfat_dir_entry {
unsigned short attr;
loff_t size;
unsigned int num_subdirs;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
struct timespec64 atime;
struct timespec64 mtime;
struct timespec64 crtime;
#else
struct timespec atime;
struct timespec mtime;
struct timespec crtime;
#endif
struct exfat_dentry_namebuf namebuf;
};

Expand Down Expand Up @@ -241,7 +245,6 @@ struct exfat_sb_info {
unsigned int clu_srch_ptr; /* cluster search pointer */
unsigned int used_clusters; /* number of used clusters */

unsigned long s_state;
struct mutex s_lock; /* superblock lock */
struct exfat_mount_options options;
struct nls_table *nls_io; /* Charset used for input and display */
Expand Down Expand Up @@ -299,7 +302,11 @@ struct exfat_inode_info {
struct rw_semaphore truncate_lock;
struct inode vfs_inode;
/* File creation time */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
struct timespec64 i_crtime;
#else
struct timespec i_crtime;
#endif
};

static inline struct exfat_sb_info *EXFAT_SB(struct super_block *sb)
Expand Down Expand Up @@ -374,7 +381,7 @@ static inline bool exfat_is_last_sector_in_cluster(struct exfat_sb_info *sbi,
static inline sector_t exfat_cluster_to_sector(struct exfat_sb_info *sbi,
unsigned int clus)
{
return ((clus - EXFAT_RESERVED_CLUSTERS) << sbi->sect_per_clus_bits) +
return ((sector_t)(clus - EXFAT_RESERVED_CLUSTERS) << sbi->sect_per_clus_bits) +
sbi->data_start_sector;
}

Expand Down Expand Up @@ -428,6 +435,7 @@ int exfat_getattr(const struct path *path, struct kstat *stat,
int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat);
#endif
int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);


/* namei.c */
Expand Down Expand Up @@ -471,7 +479,7 @@ 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);
void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
int exfat_free_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 */
Expand Down Expand Up @@ -516,14 +524,23 @@ void exfat_msg(struct super_block *sb, const char *lv, const char *fmt, ...)
#define exfat_info(sb, fmt, ...) \
exfat_msg(sb, KERN_INFO, fmt, ##__VA_ARGS__)

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
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);
void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
#else
void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec *ts,
u8 tz, __le16 time, __le16 date, u8 time_cs);
void exfat_truncate_atime(struct timespec *ts);
void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec *ts,
u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
#endif
u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type);
u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type);
void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int sync);
void exfat_update_bh(struct buffer_head *bh, int sync);
int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync);
void exfat_chain_set(struct exfat_chain *ec, unsigned int dir,
unsigned int size, unsigned char flags);
void exfat_chain_dup(struct exfat_chain *dup, struct exfat_chain *ec);
Expand Down
60 changes: 12 additions & 48 deletions fatent.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ int exfat_ent_set(struct super_block *sb, unsigned int loc,
fat_entry = (__le32 *)&(bh->b_data[off]);
*fat_entry = cpu_to_le32(content);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
exfat_update_bh(sb, bh, sb->s_flags & SB_SYNCHRONOUS);
exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS);
#else
exfat_update_bh(sb, bh, sb->s_flags & MS_SYNCHRONOUS);
exfat_update_bh(bh, sb->s_flags & MS_SYNCHRONOUS);
#endif
exfat_mirror_bh(sb, sec, bh);
brelse(bh);
Expand Down Expand Up @@ -182,7 +182,6 @@ int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
return -EIO;
}

set_bit(EXFAT_SB_DIRTY, &sbi->s_state);
clu = p_chain->dir;

if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
Expand Down Expand Up @@ -238,21 +237,6 @@ int exfat_find_last_cluster(struct super_block *sb, struct exfat_chain *p_chain,
return 0;
}

static inline int exfat_sync_bhs(struct buffer_head **bhs, int nr_bhs)
{
int i, err = 0;

for (i = 0; i < nr_bhs; i++)
write_dirty_buffer(bhs[i], 0);

for (i = 0; i < nr_bhs; i++) {
wait_on_buffer(bhs[i]);
if (!err && !buffer_uptodate(bhs[i]))
err = -EIO;
}
return err;
}

int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
{
struct super_block *sb = dir->i_sb;
Expand All @@ -274,41 +258,23 @@ int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
}

/* Zeroing the unused blocks on this cluster */
n = 0;
while (blknr < last_blknr) {
bhs[n] = sb_getblk(sb, blknr);
if (!bhs[n]) {
err = -ENOMEM;
goto release_bhs;
}
memset(bhs[n]->b_data, 0, sb->s_blocksize);
exfat_update_bh(sb, bhs[n], 0);

n++;
blknr++;

if (n == nr_bhs) {
if (IS_DIRSYNC(dir)) {
err = exfat_sync_bhs(bhs, n);
if (err)
goto release_bhs;
for (n = 0; n < nr_bhs && blknr < last_blknr; n++, blknr++) {
bhs[n] = sb_getblk(sb, blknr);
if (!bhs[n]) {
err = -ENOMEM;
goto release_bhs;
}

for (i = 0; i < n; i++)
brelse(bhs[i]);
n = 0;
memset(bhs[n]->b_data, 0, sb->s_blocksize);
}
}

if (IS_DIRSYNC(dir)) {
err = exfat_sync_bhs(bhs, n);
err = exfat_update_bhs(bhs, n, IS_DIRSYNC(dir));
if (err)
goto release_bhs;
}

for (i = 0; i < n; i++)
brelse(bhs[i]);

for (i = 0; i < n; i++)
brelse(bhs[i]);
}
return 0;

release_bhs:
Expand Down Expand Up @@ -366,8 +332,6 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
}
}

set_bit(EXFAT_SB_DIRTY, &sbi->s_state);

p_chain->dir = EXFAT_EOF_CLUSTER;

while ((new_clu = exfat_find_free_bitmap(sb, hint_clu)) !=
Expand Down
Loading

0 comments on commit e758ac7

Please sign in to comment.