1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
6 #include <linux/fs_context.h>
7 #include <linux/fs_parser.h>
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/time.h>
11 #include <linux/mount.h>
12 #include <linux/cred.h>
13 #include <linux/statfs.h>
14 #include <linux/seq_file.h>
15 #include <linux/blkdev.h>
16 #include <linux/fs_struct.h>
17 #include <linux/iversion.h>
18 #include <linux/nls.h>
19 #include <linux/buffer_head.h>
20 #include <linux/magic.h>
22 #include "exfat_raw.h"
25 static char exfat_default_iocharset
[] = CONFIG_EXFAT_DEFAULT_IOCHARSET
;
26 static struct kmem_cache
*exfat_inode_cachep
;
28 static void exfat_free_iocharset(struct exfat_sb_info
*sbi
)
30 if (sbi
->options
.iocharset
!= exfat_default_iocharset
)
31 kfree(sbi
->options
.iocharset
);
34 static void exfat_put_super(struct super_block
*sb
)
36 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
38 mutex_lock(&sbi
->s_lock
);
39 exfat_free_bitmap(sbi
);
41 mutex_unlock(&sbi
->s_lock
);
44 static int exfat_sync_fs(struct super_block
*sb
, int wait
)
46 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
49 if (unlikely(exfat_forced_shutdown(sb
)))
55 /* If there are some dirty buffers in the bdev inode */
56 mutex_lock(&sbi
->s_lock
);
57 sync_blockdev(sb
->s_bdev
);
58 if (exfat_clear_volume_dirty(sb
))
60 mutex_unlock(&sbi
->s_lock
);
64 static int exfat_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
66 struct super_block
*sb
= dentry
->d_sb
;
67 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
68 unsigned long long id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
70 if (sbi
->used_clusters
== EXFAT_CLUSTERS_UNTRACKED
) {
71 mutex_lock(&sbi
->s_lock
);
72 if (exfat_count_used_clusters(sb
, &sbi
->used_clusters
)) {
73 mutex_unlock(&sbi
->s_lock
);
76 mutex_unlock(&sbi
->s_lock
);
79 buf
->f_type
= sb
->s_magic
;
80 buf
->f_bsize
= sbi
->cluster_size
;
81 buf
->f_blocks
= sbi
->num_clusters
- 2; /* clu 0 & 1 */
82 buf
->f_bfree
= buf
->f_blocks
- sbi
->used_clusters
;
83 buf
->f_bavail
= buf
->f_bfree
;
84 buf
->f_fsid
= u64_to_fsid(id
);
85 /* Unicode utf16 255 characters */
86 buf
->f_namelen
= EXFAT_MAX_FILE_LEN
* NLS_MAX_CHARSET_SIZE
;
90 static int exfat_set_vol_flags(struct super_block
*sb
, unsigned short new_flags
)
92 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
93 struct boot_sector
*p_boot
= (struct boot_sector
*)sbi
->boot_bh
->b_data
;
95 /* retain persistent-flags */
96 new_flags
|= sbi
->vol_flags_persistent
;
98 /* flags are not changed */
99 if (sbi
->vol_flags
== new_flags
)
102 sbi
->vol_flags
= new_flags
;
104 /* skip updating volume dirty flag,
105 * if this volume has been mounted with read-only
110 p_boot
->vol_flags
= cpu_to_le16(new_flags
);
112 set_buffer_uptodate(sbi
->boot_bh
);
113 mark_buffer_dirty(sbi
->boot_bh
);
115 __sync_dirty_buffer(sbi
->boot_bh
, REQ_SYNC
| REQ_FUA
| REQ_PREFLUSH
);
120 int exfat_set_volume_dirty(struct super_block
*sb
)
122 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
124 return exfat_set_vol_flags(sb
, sbi
->vol_flags
| VOLUME_DIRTY
);
127 int exfat_clear_volume_dirty(struct super_block
*sb
)
129 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
131 return exfat_set_vol_flags(sb
, sbi
->vol_flags
& ~VOLUME_DIRTY
);
134 static int exfat_show_options(struct seq_file
*m
, struct dentry
*root
)
136 struct super_block
*sb
= root
->d_sb
;
137 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
138 struct exfat_mount_options
*opts
= &sbi
->options
;
140 /* Show partition info */
141 if (!uid_eq(opts
->fs_uid
, GLOBAL_ROOT_UID
))
142 seq_printf(m
, ",uid=%u",
143 from_kuid_munged(&init_user_ns
, opts
->fs_uid
));
144 if (!gid_eq(opts
->fs_gid
, GLOBAL_ROOT_GID
))
145 seq_printf(m
, ",gid=%u",
146 from_kgid_munged(&init_user_ns
, opts
->fs_gid
));
147 seq_printf(m
, ",fmask=%04o,dmask=%04o", opts
->fs_fmask
, opts
->fs_dmask
);
148 if (opts
->allow_utime
)
149 seq_printf(m
, ",allow_utime=%04o", opts
->allow_utime
);
151 seq_puts(m
, ",iocharset=utf8");
152 else if (sbi
->nls_io
)
153 seq_printf(m
, ",iocharset=%s", sbi
->nls_io
->charset
);
154 if (opts
->errors
== EXFAT_ERRORS_CONT
)
155 seq_puts(m
, ",errors=continue");
156 else if (opts
->errors
== EXFAT_ERRORS_PANIC
)
157 seq_puts(m
, ",errors=panic");
159 seq_puts(m
, ",errors=remount-ro");
161 seq_puts(m
, ",discard");
162 if (opts
->keep_last_dots
)
163 seq_puts(m
, ",keep_last_dots");
165 seq_puts(m
, ",sys_tz");
166 else if (opts
->time_offset
)
167 seq_printf(m
, ",time_offset=%d", opts
->time_offset
);
168 if (opts
->zero_size_dir
)
169 seq_puts(m
, ",zero_size_dir");
173 int exfat_force_shutdown(struct super_block
*sb
, u32 flags
)
176 struct exfat_sb_info
*sbi
= sb
->s_fs_info
;
177 struct exfat_mount_options
*opts
= &sbi
->options
;
179 if (exfat_forced_shutdown(sb
))
183 case EXFAT_GOING_DOWN_DEFAULT
:
184 case EXFAT_GOING_DOWN_FULLSYNC
:
185 ret
= bdev_freeze(sb
->s_bdev
);
188 bdev_thaw(sb
->s_bdev
);
189 set_bit(EXFAT_FLAGS_SHUTDOWN
, &sbi
->s_exfat_flags
);
191 case EXFAT_GOING_DOWN_NOSYNC
:
192 set_bit(EXFAT_FLAGS_SHUTDOWN
, &sbi
->s_exfat_flags
);
203 static void exfat_shutdown(struct super_block
*sb
)
205 exfat_force_shutdown(sb
, EXFAT_GOING_DOWN_NOSYNC
);
208 static struct inode
*exfat_alloc_inode(struct super_block
*sb
)
210 struct exfat_inode_info
*ei
;
212 ei
= alloc_inode_sb(sb
, exfat_inode_cachep
, GFP_NOFS
);
216 init_rwsem(&ei
->truncate_lock
);
217 return &ei
->vfs_inode
;
220 static void exfat_free_inode(struct inode
*inode
)
222 kmem_cache_free(exfat_inode_cachep
, EXFAT_I(inode
));
225 static const struct super_operations exfat_sops
= {
226 .alloc_inode
= exfat_alloc_inode
,
227 .free_inode
= exfat_free_inode
,
228 .write_inode
= exfat_write_inode
,
229 .evict_inode
= exfat_evict_inode
,
230 .put_super
= exfat_put_super
,
231 .sync_fs
= exfat_sync_fs
,
232 .statfs
= exfat_statfs
,
233 .show_options
= exfat_show_options
,
234 .shutdown
= exfat_shutdown
,
252 /* Deprecated options */
259 static const struct constant_table exfat_param_enums
[] = {
260 { "continue", EXFAT_ERRORS_CONT
},
261 { "panic", EXFAT_ERRORS_PANIC
},
262 { "remount-ro", EXFAT_ERRORS_RO
},
266 static const struct fs_parameter_spec exfat_parameters
[] = {
267 fsparam_uid("uid", Opt_uid
),
268 fsparam_gid("gid", Opt_gid
),
269 fsparam_u32oct("umask", Opt_umask
),
270 fsparam_u32oct("dmask", Opt_dmask
),
271 fsparam_u32oct("fmask", Opt_fmask
),
272 fsparam_u32oct("allow_utime", Opt_allow_utime
),
273 fsparam_string("iocharset", Opt_charset
),
274 fsparam_enum("errors", Opt_errors
, exfat_param_enums
),
275 fsparam_flag("discard", Opt_discard
),
276 fsparam_flag("keep_last_dots", Opt_keep_last_dots
),
277 fsparam_flag("sys_tz", Opt_sys_tz
),
278 fsparam_s32("time_offset", Opt_time_offset
),
279 fsparam_flag("zero_size_dir", Opt_zero_size_dir
),
280 __fsparam(NULL
, "utf8", Opt_utf8
, fs_param_deprecated
,
282 __fsparam(NULL
, "debug", Opt_debug
, fs_param_deprecated
,
284 __fsparam(fs_param_is_u32
, "namecase", Opt_namecase
,
285 fs_param_deprecated
, NULL
),
286 __fsparam(fs_param_is_u32
, "codepage", Opt_codepage
,
287 fs_param_deprecated
, NULL
),
291 static int exfat_parse_param(struct fs_context
*fc
, struct fs_parameter
*param
)
293 struct exfat_sb_info
*sbi
= fc
->s_fs_info
;
294 struct exfat_mount_options
*opts
= &sbi
->options
;
295 struct fs_parse_result result
;
298 opt
= fs_parse(fc
, exfat_parameters
, param
, &result
);
304 opts
->fs_uid
= result
.uid
;
307 opts
->fs_gid
= result
.gid
;
310 opts
->fs_fmask
= result
.uint_32
;
311 opts
->fs_dmask
= result
.uint_32
;
314 opts
->fs_dmask
= result
.uint_32
;
317 opts
->fs_fmask
= result
.uint_32
;
319 case Opt_allow_utime
:
320 opts
->allow_utime
= result
.uint_32
& 0022;
323 exfat_free_iocharset(sbi
);
324 opts
->iocharset
= param
->string
;
325 param
->string
= NULL
;
328 opts
->errors
= result
.uint_32
;
333 case Opt_keep_last_dots
:
334 opts
->keep_last_dots
= 1;
339 case Opt_time_offset
:
341 * Make the limit 24 just in case someone invents something
344 if (result
.int_32
< -24 * 60 || result
.int_32
> 24 * 60)
346 opts
->time_offset
= result
.int_32
;
348 case Opt_zero_size_dir
:
349 opts
->zero_size_dir
= true;
363 static void exfat_hash_init(struct super_block
*sb
)
365 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
368 spin_lock_init(&sbi
->inode_hash_lock
);
369 for (i
= 0; i
< EXFAT_HASH_SIZE
; i
++)
370 INIT_HLIST_HEAD(&sbi
->inode_hashtable
[i
]);
373 static int exfat_read_root(struct inode
*inode
)
375 struct super_block
*sb
= inode
->i_sb
;
376 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
377 struct exfat_inode_info
*ei
= EXFAT_I(inode
);
378 struct exfat_chain cdir
;
379 int num_subdirs
, num_clu
= 0;
381 exfat_chain_set(&ei
->dir
, sbi
->root_dir
, 0, ALLOC_FAT_CHAIN
);
383 ei
->start_clu
= sbi
->root_dir
;
384 ei
->flags
= ALLOC_FAT_CHAIN
;
387 ei
->hint_bmap
.off
= EXFAT_EOF_CLUSTER
;
388 ei
->hint_stat
.eidx
= 0;
389 ei
->hint_stat
.clu
= sbi
->root_dir
;
390 ei
->hint_femp
.eidx
= EXFAT_HINT_NONE
;
392 exfat_chain_set(&cdir
, sbi
->root_dir
, 0, ALLOC_FAT_CHAIN
);
393 if (exfat_count_num_clusters(sb
, &cdir
, &num_clu
))
395 i_size_write(inode
, num_clu
<< sbi
->cluster_size_bits
);
397 num_subdirs
= exfat_count_dir_entries(sb
, &cdir
);
400 set_nlink(inode
, num_subdirs
+ EXFAT_MIN_SUBDIR
);
402 inode
->i_uid
= sbi
->options
.fs_uid
;
403 inode
->i_gid
= sbi
->options
.fs_gid
;
404 inode_inc_iversion(inode
);
405 inode
->i_generation
= 0;
406 inode
->i_mode
= exfat_make_mode(sbi
, EXFAT_ATTR_SUBDIR
, 0777);
407 inode
->i_op
= &exfat_dir_inode_operations
;
408 inode
->i_fop
= &exfat_dir_operations
;
410 inode
->i_blocks
= round_up(i_size_read(inode
), sbi
->cluster_size
) >> 9;
411 ei
->i_pos
= ((loff_t
)sbi
->root_dir
<< 32) | 0xffffffff;
413 exfat_save_attr(inode
, EXFAT_ATTR_SUBDIR
);
414 ei
->i_crtime
= simple_inode_init_ts(inode
);
415 exfat_truncate_inode_atime(inode
);
419 static int exfat_calibrate_blocksize(struct super_block
*sb
, int logical_sect
)
421 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
423 if (!is_power_of_2(logical_sect
)) {
424 exfat_err(sb
, "bogus logical sector size %u", logical_sect
);
428 if (logical_sect
< sb
->s_blocksize
) {
429 exfat_err(sb
, "logical sector size too small for device (logical sector size = %u)",
434 if (logical_sect
> sb
->s_blocksize
) {
435 brelse(sbi
->boot_bh
);
438 if (!sb_set_blocksize(sb
, logical_sect
)) {
439 exfat_err(sb
, "unable to set blocksize %u",
443 sbi
->boot_bh
= sb_bread(sb
, 0);
445 exfat_err(sb
, "unable to read boot sector (logical sector size = %lu)",
453 static int exfat_read_boot_sector(struct super_block
*sb
)
455 struct boot_sector
*p_boot
;
456 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
458 /* set block size to read super block */
459 sb_min_blocksize(sb
, 512);
461 /* read boot sector */
462 sbi
->boot_bh
= sb_bread(sb
, 0);
464 exfat_err(sb
, "unable to read boot sector");
467 p_boot
= (struct boot_sector
*)sbi
->boot_bh
->b_data
;
469 /* check the validity of BOOT */
470 if (le16_to_cpu((p_boot
->signature
)) != BOOT_SIGNATURE
) {
471 exfat_err(sb
, "invalid boot record signature");
475 if (memcmp(p_boot
->fs_name
, STR_EXFAT
, BOOTSEC_FS_NAME_LEN
)) {
476 exfat_err(sb
, "invalid fs_name"); /* fs_name may unprintable */
481 * must_be_zero field must be filled with zero to prevent mounting
484 if (memchr_inv(p_boot
->must_be_zero
, 0, sizeof(p_boot
->must_be_zero
)))
487 if (p_boot
->num_fats
!= 1 && p_boot
->num_fats
!= 2) {
488 exfat_err(sb
, "bogus number of FAT structure");
493 * sect_size_bits could be at least 9 and at most 12.
495 if (p_boot
->sect_size_bits
< EXFAT_MIN_SECT_SIZE_BITS
||
496 p_boot
->sect_size_bits
> EXFAT_MAX_SECT_SIZE_BITS
) {
497 exfat_err(sb
, "bogus sector size bits : %u",
498 p_boot
->sect_size_bits
);
503 * sect_per_clus_bits could be at least 0 and at most 25 - sect_size_bits.
505 if (p_boot
->sect_per_clus_bits
> EXFAT_MAX_SECT_PER_CLUS_BITS(p_boot
)) {
506 exfat_err(sb
, "bogus sectors bits per cluster : %u",
507 p_boot
->sect_per_clus_bits
);
511 sbi
->sect_per_clus
= 1 << p_boot
->sect_per_clus_bits
;
512 sbi
->sect_per_clus_bits
= p_boot
->sect_per_clus_bits
;
513 sbi
->cluster_size_bits
= p_boot
->sect_per_clus_bits
+
514 p_boot
->sect_size_bits
;
515 sbi
->cluster_size
= 1 << sbi
->cluster_size_bits
;
516 sbi
->num_FAT_sectors
= le32_to_cpu(p_boot
->fat_length
);
517 sbi
->FAT1_start_sector
= le32_to_cpu(p_boot
->fat_offset
);
518 sbi
->FAT2_start_sector
= le32_to_cpu(p_boot
->fat_offset
);
519 if (p_boot
->num_fats
== 2)
520 sbi
->FAT2_start_sector
+= sbi
->num_FAT_sectors
;
521 sbi
->data_start_sector
= le32_to_cpu(p_boot
->clu_offset
);
522 sbi
->num_sectors
= le64_to_cpu(p_boot
->vol_length
);
523 /* because the cluster index starts with 2 */
524 sbi
->num_clusters
= le32_to_cpu(p_boot
->clu_count
) +
525 EXFAT_RESERVED_CLUSTERS
;
527 sbi
->root_dir
= le32_to_cpu(p_boot
->root_cluster
);
528 sbi
->dentries_per_clu
= 1 <<
529 (sbi
->cluster_size_bits
- DENTRY_SIZE_BITS
);
531 sbi
->vol_flags
= le16_to_cpu(p_boot
->vol_flags
);
532 sbi
->vol_flags_persistent
= sbi
->vol_flags
& (VOLUME_DIRTY
| MEDIA_FAILURE
);
533 sbi
->clu_srch_ptr
= EXFAT_FIRST_CLUSTER
;
534 sbi
->used_clusters
= EXFAT_CLUSTERS_UNTRACKED
;
536 /* check consistencies */
537 if ((u64
)sbi
->num_FAT_sectors
<< p_boot
->sect_size_bits
<
538 (u64
)sbi
->num_clusters
* 4) {
539 exfat_err(sb
, "bogus fat length");
543 if (sbi
->data_start_sector
<
544 (u64
)sbi
->FAT1_start_sector
+
545 (u64
)sbi
->num_FAT_sectors
* p_boot
->num_fats
) {
546 exfat_err(sb
, "bogus data start sector");
550 if (sbi
->vol_flags
& VOLUME_DIRTY
)
551 exfat_warn(sb
, "Volume was not properly unmounted. Some data may be corrupt. Please run fsck.");
552 if (sbi
->vol_flags
& MEDIA_FAILURE
)
553 exfat_warn(sb
, "Medium has reported failures. Some data may be lost.");
555 /* exFAT file size is limited by a disk volume size */
556 sb
->s_maxbytes
= (u64
)(sbi
->num_clusters
- EXFAT_RESERVED_CLUSTERS
) <<
557 sbi
->cluster_size_bits
;
559 /* check logical sector size */
560 if (exfat_calibrate_blocksize(sb
, 1 << p_boot
->sect_size_bits
))
566 static int exfat_verify_boot_region(struct super_block
*sb
)
568 struct buffer_head
*bh
= NULL
;
570 __le32
*p_sig
, *p_chksum
;
573 /* read boot sector sub-regions */
574 for (sn
= 0; sn
< 11; sn
++) {
575 bh
= sb_bread(sb
, sn
);
579 if (sn
!= 0 && sn
<= 8) {
580 /* extended boot sector sub-regions */
581 p_sig
= (__le32
*)&bh
->b_data
[sb
->s_blocksize
- 4];
582 if (le32_to_cpu(*p_sig
) != EXBOOT_SIGNATURE
)
583 exfat_warn(sb
, "Invalid exboot-signature(sector = %d): 0x%08x",
584 sn
, le32_to_cpu(*p_sig
));
587 chksum
= exfat_calc_chksum32(bh
->b_data
, sb
->s_blocksize
,
588 chksum
, sn
? CS_DEFAULT
: CS_BOOT_SECTOR
);
592 /* boot checksum sub-regions */
593 bh
= sb_bread(sb
, sn
);
597 for (i
= 0; i
< sb
->s_blocksize
; i
+= sizeof(u32
)) {
598 p_chksum
= (__le32
*)&bh
->b_data
[i
];
599 if (le32_to_cpu(*p_chksum
) != chksum
) {
600 exfat_err(sb
, "Invalid boot checksum (boot checksum : 0x%08x, checksum : 0x%08x)",
601 le32_to_cpu(*p_chksum
), chksum
);
610 /* mount the file system volume */
611 static int __exfat_fill_super(struct super_block
*sb
)
614 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
616 ret
= exfat_read_boot_sector(sb
);
618 exfat_err(sb
, "failed to read boot sector");
622 ret
= exfat_verify_boot_region(sb
);
624 exfat_err(sb
, "invalid boot region");
628 ret
= exfat_create_upcase_table(sb
);
630 exfat_err(sb
, "failed to load upcase table");
634 ret
= exfat_load_bitmap(sb
);
636 exfat_err(sb
, "failed to load alloc-bitmap");
640 ret
= exfat_count_used_clusters(sb
, &sbi
->used_clusters
);
642 exfat_err(sb
, "failed to scan clusters");
643 goto free_alloc_bitmap
;
649 exfat_free_bitmap(sbi
);
651 brelse(sbi
->boot_bh
);
655 static int exfat_fill_super(struct super_block
*sb
, struct fs_context
*fc
)
657 struct exfat_sb_info
*sbi
= sb
->s_fs_info
;
658 struct exfat_mount_options
*opts
= &sbi
->options
;
659 struct inode
*root_inode
;
662 if (opts
->allow_utime
== (unsigned short)-1)
663 opts
->allow_utime
= ~opts
->fs_dmask
& 0022;
665 if (opts
->discard
&& !bdev_max_discard_sectors(sb
->s_bdev
)) {
666 exfat_warn(sb
, "mounting with \"discard\" option, but the device does not support discard");
670 sb
->s_flags
|= SB_NODIRATIME
;
671 sb
->s_magic
= EXFAT_SUPER_MAGIC
;
672 sb
->s_op
= &exfat_sops
;
674 sb
->s_time_gran
= 10 * NSEC_PER_MSEC
;
675 sb
->s_time_min
= EXFAT_MIN_TIMESTAMP_SECS
;
676 sb
->s_time_max
= EXFAT_MAX_TIMESTAMP_SECS
;
678 err
= __exfat_fill_super(sb
);
680 exfat_err(sb
, "failed to recognize exfat type");
684 /* set up enough so that it can read an inode */
687 if (!strcmp(sbi
->options
.iocharset
, "utf8"))
690 sbi
->nls_io
= load_nls(sbi
->options
.iocharset
);
692 exfat_err(sb
, "IO charset %s not found",
693 sbi
->options
.iocharset
);
699 if (sbi
->options
.utf8
)
700 sb
->s_d_op
= &exfat_utf8_dentry_ops
;
702 sb
->s_d_op
= &exfat_dentry_ops
;
704 root_inode
= new_inode(sb
);
706 exfat_err(sb
, "failed to allocate root inode");
711 root_inode
->i_ino
= EXFAT_ROOT_INO
;
712 inode_set_iversion(root_inode
, 1);
713 err
= exfat_read_root(root_inode
);
715 exfat_err(sb
, "failed to initialize root inode");
719 exfat_hash_inode(root_inode
, EXFAT_I(root_inode
)->i_pos
);
720 insert_inode_hash(root_inode
);
722 sb
->s_root
= d_make_root(root_inode
);
724 exfat_err(sb
, "failed to get the root dentry");
736 exfat_free_bitmap(sbi
);
737 brelse(sbi
->boot_bh
);
743 static int exfat_get_tree(struct fs_context
*fc
)
745 return get_tree_bdev(fc
, exfat_fill_super
);
748 static void exfat_free_sbi(struct exfat_sb_info
*sbi
)
750 exfat_free_iocharset(sbi
);
754 static void exfat_free(struct fs_context
*fc
)
756 struct exfat_sb_info
*sbi
= fc
->s_fs_info
;
762 static int exfat_reconfigure(struct fs_context
*fc
)
764 fc
->sb_flags
|= SB_NODIRATIME
;
766 /* volume flag will be updated in exfat_sync_fs */
767 sync_filesystem(fc
->root
->d_sb
);
771 static const struct fs_context_operations exfat_context_ops
= {
772 .parse_param
= exfat_parse_param
,
773 .get_tree
= exfat_get_tree
,
775 .reconfigure
= exfat_reconfigure
,
778 static int exfat_init_fs_context(struct fs_context
*fc
)
780 struct exfat_sb_info
*sbi
;
782 sbi
= kzalloc(sizeof(struct exfat_sb_info
), GFP_KERNEL
);
786 mutex_init(&sbi
->s_lock
);
787 mutex_init(&sbi
->bitmap_lock
);
788 ratelimit_state_init(&sbi
->ratelimit
, DEFAULT_RATELIMIT_INTERVAL
,
789 DEFAULT_RATELIMIT_BURST
);
791 sbi
->options
.fs_uid
= current_uid();
792 sbi
->options
.fs_gid
= current_gid();
793 sbi
->options
.fs_fmask
= current
->fs
->umask
;
794 sbi
->options
.fs_dmask
= current
->fs
->umask
;
795 sbi
->options
.allow_utime
= -1;
796 sbi
->options
.iocharset
= exfat_default_iocharset
;
797 sbi
->options
.errors
= EXFAT_ERRORS_RO
;
800 fc
->ops
= &exfat_context_ops
;
804 static void delayed_free(struct rcu_head
*p
)
806 struct exfat_sb_info
*sbi
= container_of(p
, struct exfat_sb_info
, rcu
);
808 unload_nls(sbi
->nls_io
);
809 exfat_free_upcase_table(sbi
);
813 static void exfat_kill_sb(struct super_block
*sb
)
815 struct exfat_sb_info
*sbi
= sb
->s_fs_info
;
817 kill_block_super(sb
);
819 call_rcu(&sbi
->rcu
, delayed_free
);
822 static struct file_system_type exfat_fs_type
= {
823 .owner
= THIS_MODULE
,
825 .init_fs_context
= exfat_init_fs_context
,
826 .parameters
= exfat_parameters
,
827 .kill_sb
= exfat_kill_sb
,
828 .fs_flags
= FS_REQUIRES_DEV
| FS_ALLOW_IDMAP
,
831 static void exfat_inode_init_once(void *foo
)
833 struct exfat_inode_info
*ei
= (struct exfat_inode_info
*)foo
;
835 spin_lock_init(&ei
->cache_lru_lock
);
837 ei
->cache_valid_id
= EXFAT_CACHE_VALID
+ 1;
838 INIT_LIST_HEAD(&ei
->cache_lru
);
839 INIT_HLIST_NODE(&ei
->i_hash_fat
);
840 inode_init_once(&ei
->vfs_inode
);
843 static int __init
init_exfat_fs(void)
847 err
= exfat_cache_init();
851 exfat_inode_cachep
= kmem_cache_create("exfat_inode_cache",
852 sizeof(struct exfat_inode_info
),
853 0, SLAB_RECLAIM_ACCOUNT
,
854 exfat_inode_init_once
);
855 if (!exfat_inode_cachep
) {
860 err
= register_filesystem(&exfat_fs_type
);
867 kmem_cache_destroy(exfat_inode_cachep
);
869 exfat_cache_shutdown();
873 static void __exit
exit_exfat_fs(void)
876 * Make sure all delayed rcu free inodes are flushed before we
880 kmem_cache_destroy(exfat_inode_cachep
);
881 unregister_filesystem(&exfat_fs_type
);
882 exfat_cache_shutdown();
885 module_init(init_exfat_fs
);
886 module_exit(exit_exfat_fs
);
888 MODULE_ALIAS_FS("exfat");
889 MODULE_LICENSE("GPL");
890 MODULE_DESCRIPTION("exFAT filesystem support");
891 MODULE_AUTHOR("Samsung Electronics Co., Ltd.");