Skip to content

Commit 7468511

Browse files
authored
Merge pull request #11 from namjaejeon/exfat-next
Exfat next
2 parents 23252f9 + b7bc67c commit 7468511

File tree

9 files changed

+131
-178
lines changed

9 files changed

+131
-178
lines changed

cache.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "exfat_raw.h"
1818
#include "exfat_fs.h"
1919

20-
#define EXFAT_CACHE_VALID 0
2120
#define EXFAT_MAX_CACHE 16
2221

2322
struct exfat_cache {
@@ -61,16 +60,6 @@ void exfat_cache_shutdown(void)
6160
kmem_cache_destroy(exfat_cachep);
6261
}
6362

64-
void exfat_cache_init_inode(struct inode *inode)
65-
{
66-
struct exfat_inode_info *ei = EXFAT_I(inode);
67-
68-
spin_lock_init(&ei->cache_lru_lock);
69-
ei->nr_caches = 0;
70-
ei->cache_valid_id = EXFAT_CACHE_VALID + 1;
71-
INIT_LIST_HEAD(&ei->cache_lru);
72-
}
73-
7463
static inline struct exfat_cache *exfat_cache_alloc(void)
7564
{
7665
return kmem_cache_alloc(exfat_cachep, GFP_NOFS);

dir.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ static void exfat_get_uniname_from_ext_entry(struct super_block *sb,
6060
}
6161

6262
/* read a directory entry from the opened directory */
63-
static int exfat_readdir(struct inode *inode, struct exfat_dir_entry *dir_entry)
63+
static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_entry *dir_entry)
6464
{
65-
int i, dentries_per_clu, dentries_per_clu_bits = 0;
65+
int i, dentries_per_clu, dentries_per_clu_bits = 0, num_ext;
6666
unsigned int type, clu_offset;
6767
sector_t sector;
6868
struct exfat_chain dir, clu;
@@ -71,7 +71,7 @@ static int exfat_readdir(struct inode *inode, struct exfat_dir_entry *dir_entry)
7171
struct super_block *sb = inode->i_sb;
7272
struct exfat_sb_info *sbi = EXFAT_SB(sb);
7373
struct exfat_inode_info *ei = EXFAT_I(inode);
74-
unsigned int dentry = ei->rwoffset & 0xFFFFFFFF;
74+
unsigned int dentry = EXFAT_B_TO_DEN(*cpos) & 0xFFFFFFFF;
7575
struct buffer_head *bh;
7676

7777
/* check if the given file ID is opened */
@@ -128,6 +128,7 @@ static int exfat_readdir(struct inode *inode, struct exfat_dir_entry *dir_entry)
128128
continue;
129129
}
130130

131+
num_ext = ep->dentry.file.num_ext;
131132
dir_entry->attr = le16_to_cpu(ep->dentry.file.attr);
132133
exfat_get_entry_time(sbi, &dir_entry->crtime,
133134
ep->dentry.file.create_tz,
@@ -158,12 +159,13 @@ static int exfat_readdir(struct inode *inode, struct exfat_dir_entry *dir_entry)
158159
return -EIO;
159160
dir_entry->size =
160161
le64_to_cpu(ep->dentry.stream.valid_size);
162+
dir_entry->entry = dentry;
161163
brelse(bh);
162164

163165
ei->hint_bmap.off = dentry >> dentries_per_clu_bits;
164166
ei->hint_bmap.clu = clu.dir;
165167

166-
ei->rwoffset = ++dentry;
168+
*cpos = EXFAT_DEN_TO_B(dentry + 1 + num_ext);
167169
return 0;
168170
}
169171

@@ -179,7 +181,7 @@ static int exfat_readdir(struct inode *inode, struct exfat_dir_entry *dir_entry)
179181
}
180182

181183
dir_entry->namebuf.lfn[0] = '\0';
182-
ei->rwoffset = dentry;
184+
*cpos = EXFAT_DEN_TO_B(dentry);
183185
return 0;
184186
}
185187

@@ -243,12 +245,10 @@ static int exfat_iterate(struct file *filp, struct dir_context *ctx)
243245
if (err)
244246
goto unlock;
245247
get_new:
246-
ei->rwoffset = EXFAT_B_TO_DEN(cpos);
247-
248248
if (cpos >= i_size_read(inode))
249249
goto end_of_dir;
250250

251-
err = exfat_readdir(inode, &de);
251+
err = exfat_readdir(inode, &cpos, &de);
252252
if (err) {
253253
/*
254254
* At least we tried to read a sector. Move cpos to next sector
@@ -263,13 +263,10 @@ static int exfat_iterate(struct file *filp, struct dir_context *ctx)
263263
goto end_of_dir;
264264
}
265265

266-
cpos = EXFAT_DEN_TO_B(ei->rwoffset);
267-
268266
if (!nb->lfn[0])
269267
goto end_of_dir;
270268

271-
i_pos = ((loff_t)ei->start_clu << 32) |
272-
((ei->rwoffset - 1) & 0xffffffff);
269+
i_pos = ((loff_t)ei->start_clu << 32) | (de.entry & 0xffffffff);
273270
tmp = exfat_iget(sb, i_pos);
274271
if (tmp) {
275272
inum = tmp->i_ino;
@@ -922,7 +919,6 @@ enum {
922919
/*
923920
* return values:
924921
* >= 0 : return dir entiry position with the name in dir
925-
* -EEXIST : (root dir, ".") it is the root dir itself
926922
* -ENOENT : entry with the name does not exist
927923
* -EIO : I/O error
928924
*/
@@ -990,11 +986,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
990986
if (ei->hint_femp.eidx ==
991987
EXFAT_HINT_NONE ||
992988
candi_empty.eidx <=
993-
ei->hint_femp.eidx) {
994-
memcpy(&ei->hint_femp,
995-
&candi_empty,
996-
sizeof(candi_empty));
997-
}
989+
ei->hint_femp.eidx)
990+
ei->hint_femp = candi_empty;
998991
}
999992

1000993
brelse(bh);

exfat_fs.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/ratelimit.h>
1212
#include <linux/nls.h>
1313

14-
#define EXFAT_VERSION "5.8.7"
14+
#define EXFAT_VERSION "5.10.1"
1515

1616
#define EXFAT_SUPER_MAGIC 0x2011BAB0UL
1717
#define EXFAT_ROOT_INO 1
@@ -131,7 +131,7 @@ enum {
131131

132132
struct exfat_dentry_namebuf {
133133
char *lfn;
134-
int lfnbuf_len; /* usally MAX_UNINAME_BUF_SIZE */
134+
int lfnbuf_len; /* usually MAX_UNINAME_BUF_SIZE */
135135
};
136136

137137
/* unicode name structure */
@@ -233,7 +233,8 @@ struct exfat_sb_info {
233233
unsigned int num_FAT_sectors; /* num of FAT sectors */
234234
unsigned int root_dir; /* root dir cluster */
235235
unsigned int dentries_per_clu; /* num of dentries per cluster */
236-
unsigned int vol_flag; /* volume dirty flag */
236+
unsigned int vol_flags; /* volume flags */
237+
unsigned int vol_flags_persistent; /* volume flags to retain */
237238
struct buffer_head *boot_bh; /* buffer_head of BOOT sector */
238239

239240
unsigned int map_clu; /* allocation bitmap start cluster */
@@ -256,6 +257,8 @@ struct exfat_sb_info {
256257
struct rcu_head rcu;
257258
};
258259

260+
#define EXFAT_CACHE_VALID 0
261+
259262
/*
260263
* EXFAT file system inode in-memory data
261264
*/
@@ -271,8 +274,6 @@ struct exfat_inode_info {
271274
* the validation of hint_stat.
272275
*/
273276
unsigned int version;
274-
/* file offset or dentry index for readdir */
275-
loff_t rwoffset;
276277

277278
/* hint for cluster last accessed */
278279
struct exfat_hint hint_bmap;
@@ -393,7 +394,8 @@ static inline int exfat_sector_to_cluster(struct exfat_sb_info *sbi,
393394
}
394395

395396
/* super.c */
396-
int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flag);
397+
int exfat_set_volume_dirty(struct super_block *sb);
398+
int exfat_clear_volume_dirty(struct super_block *sb);
397399

398400
/* fatent.c */
399401
#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu)
@@ -445,7 +447,6 @@ extern const struct dentry_operations exfat_utf8_dentry_ops;
445447
/* cache.c */
446448
int exfat_cache_init(void);
447449
void exfat_cache_shutdown(void);
448-
void exfat_cache_init_inode(struct inode *inode);
449450
void exfat_cache_inval_inode(struct inode *inode);
450451
int exfat_get_cluster(struct inode *inode, unsigned int cluster,
451452
unsigned int *fclus, unsigned int *dclus,

exfat_raw.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
#define EXFAT_MAX_FILE_LEN 255
1616

17-
#define VOL_CLEAN 0x0000
18-
#define VOL_DIRTY 0x0002
19-
#define ERR_MEDIUM 0x0004
17+
#define VOLUME_DIRTY 0x0002
18+
#define MEDIA_FAILURE 0x0004
2019

2120
#define EXFAT_EOF_CLUSTER 0xFFFFFFFFu
2221
#define EXFAT_BAD_CLUSTER 0xFFFFFFF7u

file.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
115115
if (ei->type != TYPE_FILE && ei->type != TYPE_DIR)
116116
return -EPERM;
117117

118-
exfat_set_vol_flags(sb, VOL_DIRTY);
118+
exfat_set_volume_dirty(sb);
119119

120120
num_clusters_new = EXFAT_B_TO_CLU_ROUND_UP(i_size_read(inode), sbi);
121121
num_clusters_phys =
@@ -225,8 +225,6 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
225225
/* hint information */
226226
ei->hint_bmap.off = EXFAT_EOF_CLUSTER;
227227
ei->hint_bmap.clu = EXFAT_EOF_CLUSTER;
228-
if (ei->rwoffset > new_size)
229-
ei->rwoffset = new_size;
230228

231229
/* hint_stat will be used if this is directory. */
232230
ei->hint_stat.eidx = 0;
@@ -237,7 +235,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
237235
if (exfat_free_cluster(inode, &clu))
238236
return -EIO;
239237

240-
exfat_set_vol_flags(sb, VOL_CLEAN);
238+
exfat_clear_volume_dirty(sb);
241239

242240
return 0;
243241
}
@@ -246,7 +244,7 @@ void exfat_truncate(struct inode *inode, loff_t size)
246244
{
247245
struct super_block *sb = inode->i_sb;
248246
struct exfat_sb_info *sbi = EXFAT_SB(sb);
249-
unsigned int blocksize = 1 << inode->i_blkbits;
247+
unsigned int blocksize = i_blocksize(inode);
250248
loff_t aligned_size;
251249
int err;
252250

inode.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int __exfat_write_inode(struct inode *inode, int sync)
4141
if (is_dir && ei->dir.dir == sbi->root_dir && ei->entry == -1)
4242
return 0;
4343

44-
exfat_set_vol_flags(sb, VOL_DIRTY);
44+
exfat_set_volume_dirty(sb);
4545

4646
/* get the directory entry of given file or directory */
4747
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry, ES_ALL_ENTRIES);
@@ -116,8 +116,6 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
116116
unsigned int local_clu_offset = clu_offset;
117117
unsigned int num_to_be_allocated = 0, num_clusters = 0;
118118

119-
ei->rwoffset = EXFAT_CLU_TO_B(clu_offset, sbi);
120-
121119
if (EXFAT_I(inode)->i_size_ondisk > 0)
122120
num_clusters =
123121
EXFAT_B_TO_CLU_ROUND_UP(EXFAT_I(inode)->i_size_ondisk,
@@ -169,7 +167,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
169167
}
170168

171169
if (*clu == EXFAT_EOF_CLUSTER) {
172-
exfat_set_vol_flags(sb, VOL_DIRTY);
170+
exfat_set_volume_dirty(sb);
173171

174172
new_clu.dir = (last_clu == EXFAT_EOF_CLUSTER) ?
175173
EXFAT_EOF_CLUSTER : last_clu + 1;
@@ -584,7 +582,7 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
584582
struct exfat_inode_info *ei = EXFAT_I(inode);
585583
loff_t size = info->size;
586584

587-
memcpy(&ei->dir, &info->dir, sizeof(struct exfat_chain));
585+
ei->dir = info->dir;
588586
ei->entry = info->entry;
589587
ei->attr = info->attr;
590588
ei->start_clu = info->start_clu;
@@ -595,7 +593,6 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
595593
ei->hint_stat.eidx = 0;
596594
ei->hint_stat.clu = info->start_clu;
597595
ei->hint_femp.eidx = EXFAT_HINT_NONE;
598-
ei->rwoffset = 0;
599596
ei->hint_bmap.off = EXFAT_EOF_CLUSTER;
600597
ei->i_pos = 0;
601598

@@ -643,8 +640,6 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
643640
ei->i_crtime = info->crtime;
644641
inode->i_atime = info->atime;
645642

646-
exfat_cache_init_inode(inode);
647-
648643
return 0;
649644
}
650645

0 commit comments

Comments
 (0)