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>
21 #include "exfat_raw.h"
24 static char exfat_default_iocharset
[] = CONFIG_EXFAT_DEFAULT_IOCHARSET
;
25 static struct kmem_cache
*exfat_inode_cachep
;
27 static void exfat_free_iocharset(struct exfat_sb_info
*sbi
)
29 if (sbi
->options
.iocharset
!= exfat_default_iocharset
)
30 kfree(sbi
->options
.iocharset
);
33 static void exfat_delayed_free(struct rcu_head
*p
)
35 struct exfat_sb_info
*sbi
= container_of(p
, struct exfat_sb_info
, rcu
);
37 unload_nls(sbi
->nls_io
);
38 exfat_free_iocharset(sbi
);
39 exfat_free_upcase_table(sbi
);
43 static void exfat_put_super(struct super_block
*sb
)
45 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
47 mutex_lock(&sbi
->s_lock
);
48 exfat_free_bitmap(sbi
);
50 mutex_unlock(&sbi
->s_lock
);
52 call_rcu(&sbi
->rcu
, exfat_delayed_free
);
55 static int exfat_sync_fs(struct super_block
*sb
, int wait
)
57 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
63 /* If there are some dirty buffers in the bdev inode */
64 mutex_lock(&sbi
->s_lock
);
65 sync_blockdev(sb
->s_bdev
);
66 if (exfat_clear_volume_dirty(sb
))
68 mutex_unlock(&sbi
->s_lock
);
72 static int exfat_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
74 struct super_block
*sb
= dentry
->d_sb
;
75 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
76 unsigned long long id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
78 if (sbi
->used_clusters
== EXFAT_CLUSTERS_UNTRACKED
) {
79 mutex_lock(&sbi
->s_lock
);
80 if (exfat_count_used_clusters(sb
, &sbi
->used_clusters
)) {
81 mutex_unlock(&sbi
->s_lock
);
84 mutex_unlock(&sbi
->s_lock
);
87 buf
->f_type
= sb
->s_magic
;
88 buf
->f_bsize
= sbi
->cluster_size
;
89 buf
->f_blocks
= sbi
->num_clusters
- 2; /* clu 0 & 1 */
90 buf
->f_bfree
= buf
->f_blocks
- sbi
->used_clusters
;
91 buf
->f_bavail
= buf
->f_bfree
;
92 buf
->f_fsid
= u64_to_fsid(id
);
93 /* Unicode utf16 255 characters */
94 buf
->f_namelen
= EXFAT_MAX_FILE_LEN
* NLS_MAX_CHARSET_SIZE
;
98 static int exfat_set_vol_flags(struct super_block
*sb
, unsigned short new_flags
)
100 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
101 struct boot_sector
*p_boot
= (struct boot_sector
*)sbi
->boot_bh
->b_data
;
104 /* retain persistent-flags */
105 new_flags
|= sbi
->vol_flags_persistent
;
107 /* flags are not changed */
108 if (sbi
->vol_flags
== new_flags
)
111 sbi
->vol_flags
= new_flags
;
113 /* skip updating volume dirty flag,
114 * if this volume has been mounted with read-only
119 p_boot
->vol_flags
= cpu_to_le16(new_flags
);
121 if ((new_flags
& VOLUME_DIRTY
) && !buffer_dirty(sbi
->boot_bh
))
126 set_buffer_uptodate(sbi
->boot_bh
);
127 mark_buffer_dirty(sbi
->boot_bh
);
130 sync_dirty_buffer(sbi
->boot_bh
);
134 int exfat_set_volume_dirty(struct super_block
*sb
)
136 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
138 return exfat_set_vol_flags(sb
, sbi
->vol_flags
| VOLUME_DIRTY
);
141 int exfat_clear_volume_dirty(struct super_block
*sb
)
143 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
145 return exfat_set_vol_flags(sb
, sbi
->vol_flags
& ~VOLUME_DIRTY
);
148 static int exfat_show_options(struct seq_file
*m
, struct dentry
*root
)
150 struct super_block
*sb
= root
->d_sb
;
151 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
152 struct exfat_mount_options
*opts
= &sbi
->options
;
154 /* Show partition info */
155 if (!uid_eq(opts
->fs_uid
, GLOBAL_ROOT_UID
))
156 seq_printf(m
, ",uid=%u",
157 from_kuid_munged(&init_user_ns
, opts
->fs_uid
));
158 if (!gid_eq(opts
->fs_gid
, GLOBAL_ROOT_GID
))
159 seq_printf(m
, ",gid=%u",
160 from_kgid_munged(&init_user_ns
, opts
->fs_gid
));
161 seq_printf(m
, ",fmask=%04o,dmask=%04o", opts
->fs_fmask
, opts
->fs_dmask
);
162 if (opts
->allow_utime
)
163 seq_printf(m
, ",allow_utime=%04o", opts
->allow_utime
);
165 seq_puts(m
, ",iocharset=utf8");
166 else if (sbi
->nls_io
)
167 seq_printf(m
, ",iocharset=%s", sbi
->nls_io
->charset
);
168 if (opts
->errors
== EXFAT_ERRORS_CONT
)
169 seq_puts(m
, ",errors=continue");
170 else if (opts
->errors
== EXFAT_ERRORS_PANIC
)
171 seq_puts(m
, ",errors=panic");
173 seq_puts(m
, ",errors=remount-ro");
175 seq_puts(m
, ",discard");
176 if (opts
->time_offset
)
177 seq_printf(m
, ",time_offset=%d", opts
->time_offset
);
181 static struct inode
*exfat_alloc_inode(struct super_block
*sb
)
183 struct exfat_inode_info
*ei
;
185 ei
= kmem_cache_alloc(exfat_inode_cachep
, GFP_NOFS
);
189 init_rwsem(&ei
->truncate_lock
);
190 return &ei
->vfs_inode
;
193 static void exfat_free_inode(struct inode
*inode
)
195 kmem_cache_free(exfat_inode_cachep
, EXFAT_I(inode
));
198 static const struct super_operations exfat_sops
= {
199 .alloc_inode
= exfat_alloc_inode
,
200 .free_inode
= exfat_free_inode
,
201 .write_inode
= exfat_write_inode
,
202 .evict_inode
= exfat_evict_inode
,
203 .put_super
= exfat_put_super
,
204 .sync_fs
= exfat_sync_fs
,
205 .statfs
= exfat_statfs
,
206 .show_options
= exfat_show_options
,
221 /* Deprecated options */
228 static const struct constant_table exfat_param_enums
[] = {
229 { "continue", EXFAT_ERRORS_CONT
},
230 { "panic", EXFAT_ERRORS_PANIC
},
231 { "remount-ro", EXFAT_ERRORS_RO
},
235 static const struct fs_parameter_spec exfat_parameters
[] = {
236 fsparam_u32("uid", Opt_uid
),
237 fsparam_u32("gid", Opt_gid
),
238 fsparam_u32oct("umask", Opt_umask
),
239 fsparam_u32oct("dmask", Opt_dmask
),
240 fsparam_u32oct("fmask", Opt_fmask
),
241 fsparam_u32oct("allow_utime", Opt_allow_utime
),
242 fsparam_string("iocharset", Opt_charset
),
243 fsparam_enum("errors", Opt_errors
, exfat_param_enums
),
244 fsparam_flag("discard", Opt_discard
),
245 fsparam_s32("time_offset", Opt_time_offset
),
246 __fsparam(NULL
, "utf8", Opt_utf8
, fs_param_deprecated
,
248 __fsparam(NULL
, "debug", Opt_debug
, fs_param_deprecated
,
250 __fsparam(fs_param_is_u32
, "namecase", Opt_namecase
,
251 fs_param_deprecated
, NULL
),
252 __fsparam(fs_param_is_u32
, "codepage", Opt_codepage
,
253 fs_param_deprecated
, NULL
),
257 static int exfat_parse_param(struct fs_context
*fc
, struct fs_parameter
*param
)
259 struct exfat_sb_info
*sbi
= fc
->s_fs_info
;
260 struct exfat_mount_options
*opts
= &sbi
->options
;
261 struct fs_parse_result result
;
264 opt
= fs_parse(fc
, exfat_parameters
, param
, &result
);
270 opts
->fs_uid
= make_kuid(current_user_ns(), result
.uint_32
);
273 opts
->fs_gid
= make_kgid(current_user_ns(), result
.uint_32
);
276 opts
->fs_fmask
= result
.uint_32
;
277 opts
->fs_dmask
= result
.uint_32
;
280 opts
->fs_dmask
= result
.uint_32
;
283 opts
->fs_fmask
= result
.uint_32
;
285 case Opt_allow_utime
:
286 opts
->allow_utime
= result
.uint_32
& 0022;
289 exfat_free_iocharset(sbi
);
290 opts
->iocharset
= param
->string
;
291 param
->string
= NULL
;
294 opts
->errors
= result
.uint_32
;
299 case Opt_time_offset
:
301 * Make the limit 24 just in case someone invents something
304 if (result
.int_32
< -24 * 60 || result
.int_32
> 24 * 60)
306 opts
->time_offset
= result
.int_32
;
320 static void exfat_hash_init(struct super_block
*sb
)
322 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
325 spin_lock_init(&sbi
->inode_hash_lock
);
326 for (i
= 0; i
< EXFAT_HASH_SIZE
; i
++)
327 INIT_HLIST_HEAD(&sbi
->inode_hashtable
[i
]);
330 static int exfat_read_root(struct inode
*inode
)
332 struct super_block
*sb
= inode
->i_sb
;
333 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
334 struct exfat_inode_info
*ei
= EXFAT_I(inode
);
335 struct exfat_chain cdir
;
336 int num_subdirs
, num_clu
= 0;
338 exfat_chain_set(&ei
->dir
, sbi
->root_dir
, 0, ALLOC_FAT_CHAIN
);
340 ei
->start_clu
= sbi
->root_dir
;
341 ei
->flags
= ALLOC_FAT_CHAIN
;
344 ei
->hint_bmap
.off
= EXFAT_EOF_CLUSTER
;
345 ei
->hint_stat
.eidx
= 0;
346 ei
->hint_stat
.clu
= sbi
->root_dir
;
347 ei
->hint_femp
.eidx
= EXFAT_HINT_NONE
;
349 exfat_chain_set(&cdir
, sbi
->root_dir
, 0, ALLOC_FAT_CHAIN
);
350 if (exfat_count_num_clusters(sb
, &cdir
, &num_clu
))
352 i_size_write(inode
, num_clu
<< sbi
->cluster_size_bits
);
354 num_subdirs
= exfat_count_dir_entries(sb
, &cdir
);
357 set_nlink(inode
, num_subdirs
+ EXFAT_MIN_SUBDIR
);
359 inode
->i_uid
= sbi
->options
.fs_uid
;
360 inode
->i_gid
= sbi
->options
.fs_gid
;
361 inode_inc_iversion(inode
);
362 inode
->i_generation
= 0;
363 inode
->i_mode
= exfat_make_mode(sbi
, ATTR_SUBDIR
, 0777);
364 inode
->i_op
= &exfat_dir_inode_operations
;
365 inode
->i_fop
= &exfat_dir_operations
;
367 inode
->i_blocks
= ((i_size_read(inode
) + (sbi
->cluster_size
- 1))
368 & ~(sbi
->cluster_size
- 1)) >> inode
->i_blkbits
;
369 EXFAT_I(inode
)->i_pos
= ((loff_t
)sbi
->root_dir
<< 32) | 0xffffffff;
370 EXFAT_I(inode
)->i_size_aligned
= i_size_read(inode
);
371 EXFAT_I(inode
)->i_size_ondisk
= i_size_read(inode
);
373 exfat_save_attr(inode
, ATTR_SUBDIR
);
374 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= ei
->i_crtime
=
376 exfat_truncate_atime(&inode
->i_atime
);
380 static int exfat_calibrate_blocksize(struct super_block
*sb
, int logical_sect
)
382 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
384 if (!is_power_of_2(logical_sect
) ||
385 logical_sect
< 512 || logical_sect
> 4096) {
386 exfat_err(sb
, "bogus logical sector size %u", logical_sect
);
390 if (logical_sect
< sb
->s_blocksize
) {
391 exfat_err(sb
, "logical sector size too small for device (logical sector size = %u)",
396 if (logical_sect
> sb
->s_blocksize
) {
397 brelse(sbi
->boot_bh
);
400 if (!sb_set_blocksize(sb
, logical_sect
)) {
401 exfat_err(sb
, "unable to set blocksize %u",
405 sbi
->boot_bh
= sb_bread(sb
, 0);
407 exfat_err(sb
, "unable to read boot sector (logical sector size = %lu)",
415 static int exfat_read_boot_sector(struct super_block
*sb
)
417 struct boot_sector
*p_boot
;
418 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
420 /* set block size to read super block */
421 sb_min_blocksize(sb
, 512);
423 /* read boot sector */
424 sbi
->boot_bh
= sb_bread(sb
, 0);
426 exfat_err(sb
, "unable to read boot sector");
429 p_boot
= (struct boot_sector
*)sbi
->boot_bh
->b_data
;
431 /* check the validity of BOOT */
432 if (le16_to_cpu((p_boot
->signature
)) != BOOT_SIGNATURE
) {
433 exfat_err(sb
, "invalid boot record signature");
437 if (memcmp(p_boot
->fs_name
, STR_EXFAT
, BOOTSEC_FS_NAME_LEN
)) {
438 exfat_err(sb
, "invalid fs_name"); /* fs_name may unprintable */
443 * must_be_zero field must be filled with zero to prevent mounting
446 if (memchr_inv(p_boot
->must_be_zero
, 0, sizeof(p_boot
->must_be_zero
)))
449 if (p_boot
->num_fats
!= 1 && p_boot
->num_fats
!= 2) {
450 exfat_err(sb
, "bogus number of FAT structure");
454 sbi
->sect_per_clus
= 1 << p_boot
->sect_per_clus_bits
;
455 sbi
->sect_per_clus_bits
= p_boot
->sect_per_clus_bits
;
456 sbi
->cluster_size_bits
= p_boot
->sect_per_clus_bits
+
457 p_boot
->sect_size_bits
;
458 sbi
->cluster_size
= 1 << sbi
->cluster_size_bits
;
459 sbi
->num_FAT_sectors
= le32_to_cpu(p_boot
->fat_length
);
460 sbi
->FAT1_start_sector
= le32_to_cpu(p_boot
->fat_offset
);
461 sbi
->FAT2_start_sector
= le32_to_cpu(p_boot
->fat_offset
);
462 if (p_boot
->num_fats
== 2)
463 sbi
->FAT2_start_sector
+= sbi
->num_FAT_sectors
;
464 sbi
->data_start_sector
= le32_to_cpu(p_boot
->clu_offset
);
465 sbi
->num_sectors
= le64_to_cpu(p_boot
->vol_length
);
466 /* because the cluster index starts with 2 */
467 sbi
->num_clusters
= le32_to_cpu(p_boot
->clu_count
) +
468 EXFAT_RESERVED_CLUSTERS
;
470 sbi
->root_dir
= le32_to_cpu(p_boot
->root_cluster
);
471 sbi
->dentries_per_clu
= 1 <<
472 (sbi
->cluster_size_bits
- DENTRY_SIZE_BITS
);
474 sbi
->vol_flags
= le16_to_cpu(p_boot
->vol_flags
);
475 sbi
->vol_flags_persistent
= sbi
->vol_flags
& (VOLUME_DIRTY
| MEDIA_FAILURE
);
476 sbi
->clu_srch_ptr
= EXFAT_FIRST_CLUSTER
;
477 sbi
->used_clusters
= EXFAT_CLUSTERS_UNTRACKED
;
479 /* check consistencies */
480 if (sbi
->num_FAT_sectors
<< p_boot
->sect_size_bits
<
481 sbi
->num_clusters
* 4) {
482 exfat_err(sb
, "bogus fat length");
485 if (sbi
->data_start_sector
<
486 sbi
->FAT1_start_sector
+ sbi
->num_FAT_sectors
* p_boot
->num_fats
) {
487 exfat_err(sb
, "bogus data start sector");
490 if (sbi
->vol_flags
& VOLUME_DIRTY
)
491 exfat_warn(sb
, "Volume was not properly unmounted. Some data may be corrupt. Please run fsck.");
492 if (sbi
->vol_flags
& MEDIA_FAILURE
)
493 exfat_warn(sb
, "Medium has reported failures. Some data may be lost.");
495 /* exFAT file size is limited by a disk volume size */
496 sb
->s_maxbytes
= (u64
)(sbi
->num_clusters
- EXFAT_RESERVED_CLUSTERS
) <<
497 sbi
->cluster_size_bits
;
499 /* check logical sector size */
500 if (exfat_calibrate_blocksize(sb
, 1 << p_boot
->sect_size_bits
))
506 static int exfat_verify_boot_region(struct super_block
*sb
)
508 struct buffer_head
*bh
= NULL
;
510 __le32
*p_sig
, *p_chksum
;
513 /* read boot sector sub-regions */
514 for (sn
= 0; sn
< 11; sn
++) {
515 bh
= sb_bread(sb
, sn
);
519 if (sn
!= 0 && sn
<= 8) {
520 /* extended boot sector sub-regions */
521 p_sig
= (__le32
*)&bh
->b_data
[sb
->s_blocksize
- 4];
522 if (le32_to_cpu(*p_sig
) != EXBOOT_SIGNATURE
)
523 exfat_warn(sb
, "Invalid exboot-signature(sector = %d): 0x%08x",
524 sn
, le32_to_cpu(*p_sig
));
527 chksum
= exfat_calc_chksum32(bh
->b_data
, sb
->s_blocksize
,
528 chksum
, sn
? CS_DEFAULT
: CS_BOOT_SECTOR
);
532 /* boot checksum sub-regions */
533 bh
= sb_bread(sb
, sn
);
537 for (i
= 0; i
< sb
->s_blocksize
; i
+= sizeof(u32
)) {
538 p_chksum
= (__le32
*)&bh
->b_data
[i
];
539 if (le32_to_cpu(*p_chksum
) != chksum
) {
540 exfat_err(sb
, "Invalid boot checksum (boot checksum : 0x%08x, checksum : 0x%08x)",
541 le32_to_cpu(*p_chksum
), chksum
);
550 /* mount the file system volume */
551 static int __exfat_fill_super(struct super_block
*sb
)
554 struct exfat_sb_info
*sbi
= EXFAT_SB(sb
);
556 ret
= exfat_read_boot_sector(sb
);
558 exfat_err(sb
, "failed to read boot sector");
562 ret
= exfat_verify_boot_region(sb
);
564 exfat_err(sb
, "invalid boot region");
568 ret
= exfat_create_upcase_table(sb
);
570 exfat_err(sb
, "failed to load upcase table");
574 ret
= exfat_load_bitmap(sb
);
576 exfat_err(sb
, "failed to load alloc-bitmap");
577 goto free_upcase_table
;
580 ret
= exfat_count_used_clusters(sb
, &sbi
->used_clusters
);
582 exfat_err(sb
, "failed to scan clusters");
583 goto free_alloc_bitmap
;
589 exfat_free_bitmap(sbi
);
591 exfat_free_upcase_table(sbi
);
593 brelse(sbi
->boot_bh
);
597 static int exfat_fill_super(struct super_block
*sb
, struct fs_context
*fc
)
599 struct exfat_sb_info
*sbi
= sb
->s_fs_info
;
600 struct exfat_mount_options
*opts
= &sbi
->options
;
601 struct inode
*root_inode
;
604 if (opts
->allow_utime
== (unsigned short)-1)
605 opts
->allow_utime
= ~opts
->fs_dmask
& 0022;
608 struct request_queue
*q
= bdev_get_queue(sb
->s_bdev
);
610 if (!blk_queue_discard(q
)) {
611 exfat_warn(sb
, "mounting with \"discard\" option, but the device does not support discard");
616 sb
->s_flags
|= SB_NODIRATIME
;
617 sb
->s_magic
= EXFAT_SUPER_MAGIC
;
618 sb
->s_op
= &exfat_sops
;
620 sb
->s_time_gran
= 10 * NSEC_PER_MSEC
;
621 sb
->s_time_min
= EXFAT_MIN_TIMESTAMP_SECS
;
622 sb
->s_time_max
= EXFAT_MAX_TIMESTAMP_SECS
;
624 err
= __exfat_fill_super(sb
);
626 exfat_err(sb
, "failed to recognize exfat type");
630 /* set up enough so that it can read an inode */
633 if (!strcmp(sbi
->options
.iocharset
, "utf8"))
636 sbi
->nls_io
= load_nls(sbi
->options
.iocharset
);
638 exfat_err(sb
, "IO charset %s not found",
639 sbi
->options
.iocharset
);
645 if (sbi
->options
.utf8
)
646 sb
->s_d_op
= &exfat_utf8_dentry_ops
;
648 sb
->s_d_op
= &exfat_dentry_ops
;
650 root_inode
= new_inode(sb
);
652 exfat_err(sb
, "failed to allocate root inode");
657 root_inode
->i_ino
= EXFAT_ROOT_INO
;
658 inode_set_iversion(root_inode
, 1);
659 err
= exfat_read_root(root_inode
);
661 exfat_err(sb
, "failed to initialize root inode");
665 exfat_hash_inode(root_inode
, EXFAT_I(root_inode
)->i_pos
);
666 insert_inode_hash(root_inode
);
668 sb
->s_root
= d_make_root(root_inode
);
670 exfat_err(sb
, "failed to get the root dentry");
682 exfat_free_upcase_table(sbi
);
683 exfat_free_bitmap(sbi
);
684 brelse(sbi
->boot_bh
);
687 unload_nls(sbi
->nls_io
);
688 exfat_free_iocharset(sbi
);
689 sb
->s_fs_info
= NULL
;
694 static int exfat_get_tree(struct fs_context
*fc
)
696 return get_tree_bdev(fc
, exfat_fill_super
);
699 static void exfat_free(struct fs_context
*fc
)
701 struct exfat_sb_info
*sbi
= fc
->s_fs_info
;
704 exfat_free_iocharset(sbi
);
709 static int exfat_reconfigure(struct fs_context
*fc
)
711 fc
->sb_flags
|= SB_NODIRATIME
;
713 /* volume flag will be updated in exfat_sync_fs */
714 sync_filesystem(fc
->root
->d_sb
);
718 static const struct fs_context_operations exfat_context_ops
= {
719 .parse_param
= exfat_parse_param
,
720 .get_tree
= exfat_get_tree
,
722 .reconfigure
= exfat_reconfigure
,
725 static int exfat_init_fs_context(struct fs_context
*fc
)
727 struct exfat_sb_info
*sbi
;
729 sbi
= kzalloc(sizeof(struct exfat_sb_info
), GFP_KERNEL
);
733 mutex_init(&sbi
->s_lock
);
734 ratelimit_state_init(&sbi
->ratelimit
, DEFAULT_RATELIMIT_INTERVAL
,
735 DEFAULT_RATELIMIT_BURST
);
737 sbi
->options
.fs_uid
= current_uid();
738 sbi
->options
.fs_gid
= current_gid();
739 sbi
->options
.fs_fmask
= current
->fs
->umask
;
740 sbi
->options
.fs_dmask
= current
->fs
->umask
;
741 sbi
->options
.allow_utime
= -1;
742 sbi
->options
.iocharset
= exfat_default_iocharset
;
743 sbi
->options
.errors
= EXFAT_ERRORS_RO
;
746 fc
->ops
= &exfat_context_ops
;
750 static struct file_system_type exfat_fs_type
= {
751 .owner
= THIS_MODULE
,
753 .init_fs_context
= exfat_init_fs_context
,
754 .parameters
= exfat_parameters
,
755 .kill_sb
= kill_block_super
,
756 .fs_flags
= FS_REQUIRES_DEV
,
759 static void exfat_inode_init_once(void *foo
)
761 struct exfat_inode_info
*ei
= (struct exfat_inode_info
*)foo
;
763 spin_lock_init(&ei
->cache_lru_lock
);
765 ei
->cache_valid_id
= EXFAT_CACHE_VALID
+ 1;
766 INIT_LIST_HEAD(&ei
->cache_lru
);
767 INIT_HLIST_NODE(&ei
->i_hash_fat
);
768 inode_init_once(&ei
->vfs_inode
);
771 static int __init
init_exfat_fs(void)
775 err
= exfat_cache_init();
779 exfat_inode_cachep
= kmem_cache_create("exfat_inode_cache",
780 sizeof(struct exfat_inode_info
),
781 0, SLAB_RECLAIM_ACCOUNT
| SLAB_MEM_SPREAD
,
782 exfat_inode_init_once
);
783 if (!exfat_inode_cachep
) {
788 err
= register_filesystem(&exfat_fs_type
);
795 kmem_cache_destroy(exfat_inode_cachep
);
797 exfat_cache_shutdown();
801 static void __exit
exit_exfat_fs(void)
804 * Make sure all delayed rcu free inodes are flushed before we
808 kmem_cache_destroy(exfat_inode_cachep
);
809 unregister_filesystem(&exfat_fs_type
);
810 exfat_cache_shutdown();
813 module_init(init_exfat_fs
);
814 module_exit(exit_exfat_fs
);
816 MODULE_ALIAS_FS("exfat");
817 MODULE_LICENSE("GPL");
818 MODULE_DESCRIPTION("exFAT filesystem support");
819 MODULE_AUTHOR("Samsung Electronics Co., Ltd.");