Lines Matching +full:out +full:- +full:volume +full:- +full:limit

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
9 * cluster - allocation unit - 512,1K,2K,4K,...,2M
10 * vcn - virtual cluster number - Offset inside the file in clusters.
11 * vbo - virtual byte offset - Offset inside the file in bytes.
12 * lcn - logical cluster number - 0 based cluster in clusters heap.
13 * lbo - logical byte offset - Absolute position inside volume.
14 * run - maps VCN to LCN - Stored in attributes in packed form.
15 * attr - attribute segment - std/name/data etc records inside MFT.
16 * mi - MFT inode - One MFT record(usually 1024 bytes or 4K), consists of attributes.
17 * ni - NTFS inode - Extends linux inode. consists of one or more mft inodes.
18 * index - unit inside directory - 2K, 4K, <=page size, does not depend on cluster size.
20 * WSL - Windows Subsystem for Linux
21 * https://docs.microsoft.com/en-us/windows/wsl/file-permissions
24 * ntfs allows up to 2^64 clusters per volume.
32 * -----------------------------------------------------------------------------
33 * | Volume size | Clusters | ntfs.sys | ntfs3 | ntfs3_64 | mkntfs | chkdsk |
34 * -----------------------------------------------------------------------------
37 * ----------------------------------------------------------|------------------
40 * The maximum volume size in this case is 2^32 * 2^21 = 2^53 = 8P
43 * -----------------------------------------------------------------------------
46 * ----------------------------------------------------------|------------------
73 * ntfs_printk - Trace warnings/notices/errors.
82 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_printk()
85 if (!___ratelimit(&sbi->msg_ratelimit, "ntfs3")) in ntfs_printk()
93 printk("%c%cntfs3(%s): %pV\n", KERN_SOH_ASCII, level, sb->s_id, &vaf); in ntfs_printk()
108 struct super_block *sb = inode->i_sb; in ntfs_inode_printk()
109 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_inode_printk()
115 if (!___ratelimit(&sbi->msg_ratelimit, "ntfs3")) in ntfs_inode_printk()
128 spin_lock(&de->d_lock); in ntfs_inode_printk()
130 de->d_name.name); in ntfs_inode_printk()
131 spin_unlock(&de->d_lock); in ntfs_inode_printk()
135 name[sizeof(s_name_buf) - 1] = 0; in ntfs_inode_printk()
149 sb->s_id, inode->i_ino, name ? name : "", &vaf); in ntfs_inode_printk()
162 * On-disk ntfs's upcase table is created by ntfs formatter.
166 * It is good idea to share in-memory 'upcase' table between different volumes.
181 * * @ptr - If pointer was saved in shared memory.
182 * * NULL - If pointer was not shared.
187 int i, j = -1; in ntfs_set_shared()
201 if (!ret && j != -1) { in ntfs_set_shared()
216 * * @ptr - If pointer is not shared anymore.
217 * * NULL - If pointer is still shared.
227 if (--s_shared[i].cnt) in ntfs_put_shared()
239 kfree(options->nls_name); in put_mount_options()
240 unload_nls(options->nls); in put_mount_options()
265 // clang-format off
286 // clang-format on
311 return ERR_PTR(-EINVAL); in ntfs_load_nls()
317 struct ntfs_mount_options *opts = fc->fs_private; in ntfs_fs_parse_param()
327 opts->fs_uid = result.uid; in ntfs_fs_parse_param()
330 opts->fs_gid = result.gid; in ntfs_fs_parse_param()
335 opts->fs_fmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
336 opts->fs_dmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
337 opts->fmask = 1; in ntfs_fs_parse_param()
338 opts->dmask = 1; in ntfs_fs_parse_param()
343 opts->fs_dmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
344 opts->dmask = 1; in ntfs_fs_parse_param()
349 opts->fs_fmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
350 opts->fmask = 1; in ntfs_fs_parse_param()
353 opts->sys_immutable = 1; in ntfs_fs_parse_param()
356 opts->discard = 1; in ntfs_fs_parse_param()
359 opts->force = 1; in ntfs_fs_parse_param()
362 opts->sparse = 1; in ntfs_fs_parse_param()
365 opts->nohidden = 1; in ntfs_fs_parse_param()
368 opts->hide_dot_files = 1; in ntfs_fs_parse_param()
371 opts->windows_names = 1; in ntfs_fs_parse_param()
374 opts->showmeta = 1; in ntfs_fs_parse_param()
379 fc->sb_flags |= SB_POSIXACL; in ntfs_fs_parse_param()
385 fc->sb_flags &= ~SB_POSIXACL; in ntfs_fs_parse_param()
388 kfree(opts->nls_name); in ntfs_fs_parse_param()
389 opts->nls_name = param->string; in ntfs_fs_parse_param()
390 param->string = NULL; in ntfs_fs_parse_param()
393 opts->prealloc = 1; in ntfs_fs_parse_param()
396 opts->nocase = 1; in ntfs_fs_parse_param()
400 return -EINVAL; in ntfs_fs_parse_param()
407 struct super_block *sb = fc->root->d_sb; in ntfs_fs_reconfigure()
408 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_fs_reconfigure()
409 struct ntfs_mount_options *new_opts = fc->fs_private; in ntfs_fs_reconfigure()
412 /* If ntfs3 is used as legacy ntfs enforce read-only mode. */ in ntfs_fs_reconfigure()
414 fc->sb_flags |= SB_RDONLY; in ntfs_fs_reconfigure()
415 goto out; in ntfs_fs_reconfigure()
418 ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY); in ntfs_fs_reconfigure()
419 if (ro_rw && (sbi->flags & NTFS_FLAGS_NEED_REPLAY)) { in ntfs_fs_reconfigure()
422 return -EINVAL; in ntfs_fs_reconfigure()
425 new_opts->nls = ntfs_load_nls(new_opts->nls_name); in ntfs_fs_reconfigure()
426 if (IS_ERR(new_opts->nls)) { in ntfs_fs_reconfigure()
427 new_opts->nls = NULL; in ntfs_fs_reconfigure()
429 new_opts->nls_name); in ntfs_fs_reconfigure()
430 return -EINVAL; in ntfs_fs_reconfigure()
432 if (new_opts->nls != sbi->options->nls) in ntfs_fs_reconfigure()
437 if (ro_rw && (sbi->volume.flags & VOLUME_FLAG_DIRTY) && in ntfs_fs_reconfigure()
438 !new_opts->force) { in ntfs_fs_reconfigure()
440 "ntfs3: Volume is dirty and \"force\" flag is not set!"); in ntfs_fs_reconfigure()
441 return -EINVAL; in ntfs_fs_reconfigure()
444 out: in ntfs_fs_reconfigure()
446 swap(sbi->options, fc->fs_private); in ntfs_fs_reconfigure()
469 struct super_block *sb = m->private; in ntfs3_volinfo()
470 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_volinfo()
473 sbi->volume.major_ver, sbi->volume.minor_ver, in ntfs3_volinfo()
474 sbi->cluster_size, sbi->used.bitmap.nbits, in ntfs3_volinfo()
475 sbi->mft.bitmap.nbits, in ntfs3_volinfo()
476 sbi->mft.bitmap.nbits - wnd_zeroes(&sbi->mft.bitmap), in ntfs3_volinfo()
477 sbi->volume.real_dirty ? "dirty" : "clean", in ntfs3_volinfo()
478 (sbi->volume.flags & VOLUME_FLAG_DIRTY) ? "dirty" : "clean"); in ntfs3_volinfo()
491 struct super_block *sb = m->private; in ntfs3_label_show()
492 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_label_show()
494 seq_printf(m, "%s\n", sbi->volume.label); in ntfs3_label_show()
509 return -EROFS; in ntfs3_label_write()
514 return -ENOMEM; in ntfs3_label_write()
517 ret = -EFAULT; in ntfs3_label_write()
518 goto out; in ntfs3_label_write()
520 while (ret > 0 && label[ret - 1] == '\n') in ntfs3_label_write()
521 ret -= 1; in ntfs3_label_write()
523 err = ntfs_set_label(sb->s_fs_info, label, ret); in ntfs3_label_write()
528 goto out; in ntfs3_label_write()
533 out: in ntfs3_label_write()
565 e = proc_mkdir(sb->s_id, proc_info_root); in ntfs_create_procdir()
567 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_create_procdir()
573 sbi->procdir = e; in ntfs_create_procdir()
579 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_remove_procdir()
581 if (!sbi->procdir) in ntfs_remove_procdir()
584 remove_proc_entry("label", sbi->procdir); in ntfs_remove_procdir()
585 remove_proc_entry("volinfo", sbi->procdir); in ntfs_remove_procdir()
586 remove_proc_entry(sb->s_id, proc_info_root); in ntfs_remove_procdir()
587 sbi->procdir = NULL; in ntfs_remove_procdir()
619 mutex_init(&ni->ni_lock); in ntfs_alloc_inode()
620 return &ni->vfs_inode; in ntfs_alloc_inode()
627 mutex_destroy(&ni->ni_lock); in ntfs_free_inode()
635 inode_init_once(&ni->vfs_inode); in init_once()
643 wnd_close(&sbi->mft.bitmap); in ntfs3_put_sbi()
644 wnd_close(&sbi->used.bitmap); in ntfs3_put_sbi()
646 if (sbi->mft.ni) { in ntfs3_put_sbi()
647 iput(&sbi->mft.ni->vfs_inode); in ntfs3_put_sbi()
648 sbi->mft.ni = NULL; in ntfs3_put_sbi()
651 if (sbi->security.ni) { in ntfs3_put_sbi()
652 iput(&sbi->security.ni->vfs_inode); in ntfs3_put_sbi()
653 sbi->security.ni = NULL; in ntfs3_put_sbi()
656 if (sbi->reparse.ni) { in ntfs3_put_sbi()
657 iput(&sbi->reparse.ni->vfs_inode); in ntfs3_put_sbi()
658 sbi->reparse.ni = NULL; in ntfs3_put_sbi()
661 if (sbi->objid.ni) { in ntfs3_put_sbi()
662 iput(&sbi->objid.ni->vfs_inode); in ntfs3_put_sbi()
663 sbi->objid.ni = NULL; in ntfs3_put_sbi()
666 if (sbi->volume.ni) { in ntfs3_put_sbi()
667 iput(&sbi->volume.ni->vfs_inode); in ntfs3_put_sbi()
668 sbi->volume.ni = NULL; in ntfs3_put_sbi()
673 indx_clear(&sbi->security.index_sii); in ntfs3_put_sbi()
674 indx_clear(&sbi->security.index_sdh); in ntfs3_put_sbi()
675 indx_clear(&sbi->reparse.index_r); in ntfs3_put_sbi()
676 indx_clear(&sbi->objid.index_o); in ntfs3_put_sbi()
681 kfree(sbi->new_rec); in ntfs3_free_sbi()
682 kvfree(ntfs_put_shared(sbi->upcase)); in ntfs3_free_sbi()
683 kvfree(sbi->def_table); in ntfs3_free_sbi()
684 kfree(sbi->compress.lznt); in ntfs3_free_sbi()
686 xpress_free_decompressor(sbi->compress.xpress); in ntfs3_free_sbi()
687 lzx_free_decompressor(sbi->compress.lzx); in ntfs3_free_sbi()
694 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_put_super()
705 struct super_block *sb = dentry->d_sb; in ntfs_statfs()
706 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_statfs()
707 struct wnd_bitmap *wnd = &sbi->used.bitmap; in ntfs_statfs()
709 buf->f_type = sb->s_magic; in ntfs_statfs()
710 buf->f_bsize = sbi->cluster_size; in ntfs_statfs()
711 buf->f_blocks = wnd->nbits; in ntfs_statfs()
713 buf->f_bfree = buf->f_bavail = wnd_zeroes(wnd); in ntfs_statfs()
714 buf->f_fsid.val[0] = sbi->volume.ser_num; in ntfs_statfs()
715 buf->f_fsid.val[1] = (sbi->volume.ser_num >> 32); in ntfs_statfs()
716 buf->f_namelen = NTFS_NAME_LEN; in ntfs_statfs()
723 struct super_block *sb = root->d_sb; in ntfs_show_options()
724 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_show_options()
725 struct ntfs_mount_options *opts = sbi->options; in ntfs_show_options()
728 seq_printf(m, ",uid=%u", from_kuid_munged(user_ns, opts->fs_uid)); in ntfs_show_options()
729 seq_printf(m, ",gid=%u", from_kgid_munged(user_ns, opts->fs_gid)); in ntfs_show_options()
730 if (opts->dmask) in ntfs_show_options()
731 seq_printf(m, ",dmask=%04o", opts->fs_dmask_inv ^ 0xffff); in ntfs_show_options()
732 if (opts->fmask) in ntfs_show_options()
733 seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff); in ntfs_show_options()
734 if (opts->sys_immutable) in ntfs_show_options()
736 if (opts->discard) in ntfs_show_options()
738 if (opts->force) in ntfs_show_options()
740 if (opts->sparse) in ntfs_show_options()
742 if (opts->nohidden) in ntfs_show_options()
744 if (opts->hide_dot_files) in ntfs_show_options()
746 if (opts->windows_names) in ntfs_show_options()
748 if (opts->showmeta) in ntfs_show_options()
750 if (sb->s_flags & SB_POSIXACL) in ntfs_show_options()
752 if (opts->nls) in ntfs_show_options()
753 seq_printf(m, ",iocharset=%s", opts->nls->charset); in ntfs_show_options()
756 if (opts->prealloc) in ntfs_show_options()
758 if (opts->nocase) in ntfs_show_options()
765 * ntfs_shutdown - super_operations::shutdown
769 set_bit(NTFS_FLAGS_SHUTDOWN_BIT, &ntfs_sb(sb)->flags); in ntfs_shutdown()
773 * ntfs_sync_fs - super_operations::sync_fs
778 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_sync_fs()
783 return -EIO; in ntfs_sync_fs()
785 ni = sbi->security.ni; in ntfs_sync_fs()
787 inode = &ni->vfs_inode; in ntfs_sync_fs()
793 ni = sbi->objid.ni; in ntfs_sync_fs()
795 inode = &ni->vfs_inode; in ntfs_sync_fs()
801 ni = sbi->reparse.ni; in ntfs_sync_fs()
803 inode = &ni->vfs_inode; in ntfs_sync_fs()
846 inode = ERR_PTR(-ESTALE); in ntfs_export_get_inode()
881 * format_size_gb - Return Gb,Mb to print with "%u.%02u Gb".
898 if (boot->sectors_per_clusters <= 0x80) in true_sectors_per_clst()
899 return boot->sectors_per_clusters; in true_sectors_per_clst()
900 if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */ in true_sectors_per_clst()
901 return 1U << (-(s8)boot->sectors_per_clusters); in true_sectors_per_clst()
902 return -EINVAL; in true_sectors_per_clst()
906 * ntfs_init_from_boot - Init internal info from on-disk boot sector.
908 * NTFS mount begins from boot - special formatted 512 bytes.
909 * There are two boots: the first and the last 512 bytes of volume.
918 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_init_from_boot()
934 sbi->volume.blocks = dev_size >> PAGE_SHIFT; in ntfs_init_from_boot()
939 return boot_block ? -EINVAL : -EIO; in ntfs_init_from_boot()
941 err = -EINVAL; in ntfs_init_from_boot()
944 if (bh->b_size - sizeof(*boot) < boot_off) in ntfs_init_from_boot()
945 goto out; in ntfs_init_from_boot()
947 boot = (struct NTFS_BOOT *)Add2Ptr(bh->b_data, boot_off); in ntfs_init_from_boot()
949 if (memcmp(boot->system_id, "NTFS ", sizeof("NTFS ") - 1)) { in ntfs_init_from_boot()
951 goto out; in ntfs_init_from_boot()
955 /*if (0x55 != boot->boot_magic[0] || 0xAA != boot->boot_magic[1]) in ntfs_init_from_boot()
956 * goto out; in ntfs_init_from_boot()
959 boot_sector_size = ((u32)boot->bytes_per_sector[1] << 8) | in ntfs_init_from_boot()
960 boot->bytes_per_sector[0]; in ntfs_init_from_boot()
965 goto out; in ntfs_init_from_boot()
973 goto out; in ntfs_init_from_boot()
976 sbi->cluster_size = boot_sector_size * sct_per_clst; in ntfs_init_from_boot()
977 sbi->cluster_bits = cluster_bits = blksize_bits(sbi->cluster_size); in ntfs_init_from_boot()
978 sbi->cluster_mask = sbi->cluster_size - 1; in ntfs_init_from_boot()
979 sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask; in ntfs_init_from_boot()
981 mlcn = le64_to_cpu(boot->mft_clst); in ntfs_init_from_boot()
982 mlcn2 = le64_to_cpu(boot->mft2_clst); in ntfs_init_from_boot()
983 sectors = le64_to_cpu(boot->sectors_per_volume); in ntfs_init_from_boot()
988 "%s: start of MFT 0x%llx (0x%llx) is out of volume 0x%llx.", in ntfs_init_from_boot()
990 goto out; in ntfs_init_from_boot()
993 if (boot->record_size >= 0) { in ntfs_init_from_boot()
994 record_size = (u32)boot->record_size << cluster_bits; in ntfs_init_from_boot()
995 } else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) { in ntfs_init_from_boot()
996 record_size = 1u << (-boot->record_size); in ntfs_init_from_boot()
999 boot->record_size); in ntfs_init_from_boot()
1000 goto out; in ntfs_init_from_boot()
1003 sbi->record_size = record_size; in ntfs_init_from_boot()
1004 sbi->record_bits = blksize_bits(record_size); in ntfs_init_from_boot()
1005 sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes in ntfs_init_from_boot()
1010 record_size, boot->record_size); in ntfs_init_from_boot()
1011 goto out; in ntfs_init_from_boot()
1017 goto out; in ntfs_init_from_boot()
1020 if (boot->index_size >= 0) { in ntfs_init_from_boot()
1021 sbi->index_size = (u32)boot->index_size << cluster_bits; in ntfs_init_from_boot()
1022 } else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) { in ntfs_init_from_boot()
1023 sbi->index_size = 1u << (-boot->index_size); in ntfs_init_from_boot()
1026 boot->index_size); in ntfs_init_from_boot()
1027 goto out; in ntfs_init_from_boot()
1031 if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) { in ntfs_init_from_boot()
1033 sbi->index_size, boot->index_size); in ntfs_init_from_boot()
1034 goto out; in ntfs_init_from_boot()
1037 if (sbi->index_size > MAXIMUM_BYTES_PER_INDEX) { in ntfs_init_from_boot()
1039 sbi->index_size); in ntfs_init_from_boot()
1040 goto out; in ntfs_init_from_boot()
1043 sbi->volume.size = sectors * boot_sector_size; in ntfs_init_from_boot()
1045 gb = format_size_gb(sbi->volume.size + boot_sector_size, &mb); in ntfs_init_from_boot()
1048 * - Volume formatted and mounted with the same sector size. in ntfs_init_from_boot()
1049 * - Volume formatted 4K and mounted as 512. in ntfs_init_from_boot()
1050 * - Volume formatted 512 and mounted as 4K. in ntfs_init_from_boot()
1057 dev_size += sector_size - 1; in ntfs_init_from_boot()
1060 sbi->mft.lbo = mlcn << cluster_bits; in ntfs_init_from_boot()
1061 sbi->mft.lbo2 = mlcn2 << cluster_bits; in ntfs_init_from_boot()
1064 if (sbi->cluster_size < boot_sector_size) { in ntfs_init_from_boot()
1066 sbi->cluster_size); in ntfs_init_from_boot()
1067 goto out; in ntfs_init_from_boot()
1071 if (sbi->cluster_size < sector_size) { in ntfs_init_from_boot()
1076 sbi->cluster_size, sector_size); in ntfs_init_from_boot()
1077 goto out; in ntfs_init_from_boot()
1080 sbi->max_bytes_per_attr = in ntfs_init_from_boot()
1081 record_size - ALIGN(MFTRECORD_FIXUP_OFFSET, 8) - in ntfs_init_from_boot()
1082 ALIGN(((record_size >> SECTOR_SHIFT) * sizeof(short)), 8) - in ntfs_init_from_boot()
1085 sbi->volume.ser_num = le64_to_cpu(boot->serial_num); in ntfs_init_from_boot()
1087 /* Warning if RAW volume. */ in ntfs_init_from_boot()
1088 if (dev_size < sbi->volume.size + boot_sector_size) { in ntfs_init_from_boot()
1094 "RAW NTFS volume: Filesystem size %u.%02u Gb > volume size %u.%02u Gb. Mount in read-only.", in ntfs_init_from_boot()
1096 sb->s_flags |= SB_RDONLY; in ntfs_init_from_boot()
1099 clusters = sbi->volume.size >> cluster_bits; in ntfs_init_from_boot()
1107 goto out; in ntfs_init_from_boot()
1113 sbi->used.bitmap.nbits = clusters; in ntfs_init_from_boot()
1117 err = -ENOMEM; in ntfs_init_from_boot()
1118 goto out; in ntfs_init_from_boot()
1121 sbi->new_rec = rec; in ntfs_init_from_boot()
1122 rec->rhdr.sign = NTFS_FILE_SIGNATURE; in ntfs_init_from_boot()
1123 rec->rhdr.fix_off = cpu_to_le16(MFTRECORD_FIXUP_OFFSET); in ntfs_init_from_boot()
1124 fn = (sbi->record_size >> SECTOR_SHIFT) + 1; in ntfs_init_from_boot()
1125 rec->rhdr.fix_num = cpu_to_le16(fn); in ntfs_init_from_boot()
1127 rec->attr_off = cpu_to_le16(ao); in ntfs_init_from_boot()
1128 rec->used = cpu_to_le32(ao + ALIGN(sizeof(enum ATTR_TYPE), 8)); in ntfs_init_from_boot()
1129 rec->total = cpu_to_le32(sbi->record_size); in ntfs_init_from_boot()
1130 ((struct ATTRIB *)Add2Ptr(rec, ao))->type = ATTR_END; in ntfs_init_from_boot()
1132 sb_set_blocksize(sb, min_t(u32, sbi->cluster_size, PAGE_SIZE)); in ntfs_init_from_boot()
1134 sbi->block_mask = sb->s_blocksize - 1; in ntfs_init_from_boot()
1135 sbi->blocks_per_cluster = sbi->cluster_size >> sb->s_blocksize_bits; in ntfs_init_from_boot()
1136 sbi->volume.blocks = sbi->volume.size >> sb->s_blocksize_bits; in ntfs_init_from_boot()
1139 sbi->maxbytes = (clusters << cluster_bits) - 1; in ntfs_init_from_boot()
1142 if (clusters >= (1ull << (64 - cluster_bits))) in ntfs_init_from_boot()
1143 sbi->maxbytes = -1; in ntfs_init_from_boot()
1144 sbi->maxbytes_sparse = -1; in ntfs_init_from_boot()
1145 sb->s_maxbytes = MAX_LFS_FILESIZE; in ntfs_init_from_boot()
1148 sbi->maxbytes_sparse = (1ull << (cluster_bits + 32)) - 1; in ntfs_init_from_boot()
1149 sb->s_maxbytes = 0xFFFFFFFFull << cluster_bits; in ntfs_init_from_boot()
1157 sbi->zone_max = min_t(CLST, 0x20000000 >> cluster_bits, clusters >> 3); in ntfs_init_from_boot()
1161 if (bh->b_blocknr && !sb_rdonly(sb)) { in ntfs_init_from_boot()
1170 out: in ntfs_init_from_boot()
1173 if (err == -EINVAL && !boot_block && dev_size0 > PAGE_SHIFT) { in ntfs_init_from_boot()
1175 u64 lbo = dev_size0 - sizeof(*boot); in ntfs_init_from_boot()
1178 boot_off = lbo & (block_size - 1); in ntfs_init_from_boot()
1194 * ntfs_fill_super - Try to mount.
1199 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_fill_super()
1200 struct block_device *bdev = sb->s_bdev; in ntfs_fill_super()
1217 sbi->sb = sb; in ntfs_fill_super()
1218 sbi->options = options = fc->fs_private; in ntfs_fill_super()
1219 fc->fs_private = NULL; in ntfs_fill_super()
1220 sb->s_flags |= SB_NODIRATIME; in ntfs_fill_super()
1221 sb->s_magic = 0x7366746e; // "ntfs" in ntfs_fill_super()
1222 sb->s_op = &ntfs_sops; in ntfs_fill_super()
1223 sb->s_export_op = &ntfs_export_ops; in ntfs_fill_super()
1224 sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec in ntfs_fill_super()
1225 sb->s_xattr = ntfs_xattr_handlers; in ntfs_fill_super()
1226 sb->s_d_op = options->nocase ? &ntfs_dentry_ops : NULL; in ntfs_fill_super()
1228 options->nls = ntfs_load_nls(options->nls_name); in ntfs_fill_super()
1229 if (IS_ERR(options->nls)) { in ntfs_fill_super()
1230 options->nls = NULL; in ntfs_fill_super()
1231 errorf(fc, "Cannot load nls %s", options->nls_name); in ntfs_fill_super()
1232 err = -EINVAL; in ntfs_fill_super()
1233 goto out; in ntfs_fill_super()
1237 sbi->discard_granularity = bdev_discard_granularity(bdev); in ntfs_fill_super()
1238 sbi->discard_granularity_mask_inv = in ntfs_fill_super()
1239 ~(u64)(sbi->discard_granularity - 1); in ntfs_fill_super()
1246 goto out; in ntfs_fill_super()
1249 * Load $Volume. This should be done before $LogFile in ntfs_fill_super()
1250 * 'cause 'sbi->volume.ni' is used in 'ntfs_set_state'. in ntfs_fill_super()
1257 ntfs_err(sb, "Failed to load $Volume (%d).", err); in ntfs_fill_super()
1258 goto out; in ntfs_fill_super()
1268 } else if (!attr->non_res && !is_attr_ext(attr)) { in ntfs_fill_super()
1271 le32_to_cpu(attr->res.data_size) >> 1, in ntfs_fill_super()
1272 UTF16_LITTLE_ENDIAN, sbi->volume.label, in ntfs_fill_super()
1273 sizeof(sbi->volume.label)); in ntfs_fill_super()
1275 sbi->volume.label[0] = 0; in ntfs_fill_super()
1278 //err = -EINVAL; in ntfs_fill_super()
1285 ntfs_err(sb, "$Volume is corrupted."); in ntfs_fill_super()
1286 err = -EINVAL; in ntfs_fill_super()
1290 sbi->volume.major_ver = info->major_ver; in ntfs_fill_super()
1291 sbi->volume.minor_ver = info->minor_ver; in ntfs_fill_super()
1292 sbi->volume.flags = info->flags; in ntfs_fill_super()
1293 sbi->volume.ni = ni; in ntfs_fill_super()
1294 if (info->flags & VOLUME_FLAG_DIRTY) { in ntfs_fill_super()
1295 sbi->volume.real_dirty = true; in ntfs_fill_super()
1306 goto out; in ntfs_fill_super()
1309 sbi->mft.recs_mirr = ntfs_up_cluster(sbi, inode->i_size) >> in ntfs_fill_super()
1310 sbi->record_bits; in ntfs_fill_super()
1321 goto out; in ntfs_fill_super()
1332 if ((sbi->flags & NTFS_FLAGS_NEED_REPLAY) && !ro) { in ntfs_fill_super()
1334 err = -EINVAL; in ntfs_fill_super()
1335 goto out; in ntfs_fill_super()
1338 if ((sbi->volume.flags & VOLUME_FLAG_DIRTY) && !ro && !options->force) { in ntfs_fill_super()
1339 ntfs_warn(sb, "volume is dirty and \"force\" flag is not set!"); in ntfs_fill_super()
1340 err = -EINVAL; in ntfs_fill_super()
1341 goto out; in ntfs_fill_super()
1352 goto out; in ntfs_fill_super()
1357 sbi->mft.used = ni->i_valid >> sbi->record_bits; in ntfs_fill_super()
1358 tt = inode->i_size >> sbi->record_bits; in ntfs_fill_super()
1359 sbi->mft.next_free = MFT_REC_USER; in ntfs_fill_super()
1361 err = wnd_init(&sbi->mft.bitmap, sb, tt); in ntfs_fill_super()
1371 sbi->mft.ni = ni; in ntfs_fill_super()
1380 goto out; in ntfs_fill_super()
1384 if (inode->i_size >> 32) { in ntfs_fill_super()
1385 err = -EINVAL; in ntfs_fill_super()
1391 tt = sbi->used.bitmap.nbits; in ntfs_fill_super()
1392 if (inode->i_size < ntfs3_bitmap_size(tt)) { in ntfs_fill_super()
1394 err = -EINVAL; in ntfs_fill_super()
1398 err = wnd_init(&sbi->used.bitmap, sb, tt); in ntfs_fill_super()
1410 goto out; in ntfs_fill_super()
1420 goto out; in ntfs_fill_super()
1425 for (i = 0; run_get_entry(&ni->file.run, i, &vcn, &lcn, &len); i++) { in ntfs_fill_super()
1434 if (wnd_set_used_safe(&sbi->used.bitmap, lcn, len, &tt) || tt) { in ntfs_fill_super()
1446 "Volume contains %zu bad blocks in %zu fragments.", in ntfs_fill_super()
1458 goto out; in ntfs_fill_super()
1465 if (inode->i_size < sizeof(struct ATTR_DEF_ENTRY) || in ntfs_fill_super()
1466 inode->i_size > 100 * sizeof(struct ATTR_DEF_ENTRY)) { in ntfs_fill_super()
1468 inode->i_size); in ntfs_fill_super()
1469 err = -EINVAL; in ntfs_fill_super()
1473 bytes = inode->i_size; in ntfs_fill_super()
1474 sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL); in ntfs_fill_super()
1476 err = -ENOMEM; in ntfs_fill_super()
1481 err = inode_read_data(inode, sbi->def_table, bytes); in ntfs_fill_super()
1487 if (ATTR_STD != t->type) { in ntfs_fill_super()
1489 err = -EINVAL; in ntfs_fill_super()
1494 sbi->def_entries = 1; in ntfs_fill_super()
1498 u32 t32 = le32_to_cpu(t->type); in ntfs_fill_super()
1499 u64 sz = le64_to_cpu(t->max_sz); in ntfs_fill_super()
1501 if ((t32 & 0xF) || le32_to_cpu(t[-1].type) >= t32) in ntfs_fill_super()
1504 if (t->type == ATTR_REPARSE) in ntfs_fill_super()
1505 sbi->reparse.max_size = sz; in ntfs_fill_super()
1506 else if (t->type == ATTR_EA) in ntfs_fill_super()
1507 sbi->ea_max_size = sz; in ntfs_fill_super()
1511 sbi->def_entries += 1; in ntfs_fill_super()
1522 goto out; in ntfs_fill_super()
1525 if (inode->i_size != 0x10000 * sizeof(short)) { in ntfs_fill_super()
1526 err = -EINVAL; in ntfs_fill_super()
1532 err = inode_read_data(inode, sbi->upcase, 0x10000 * sizeof(short)); in ntfs_fill_super()
1540 u16 *dst = sbi->upcase; in ntfs_fill_super()
1547 shared = ntfs_set_shared(sbi->upcase, 0x10000 * sizeof(short)); in ntfs_fill_super()
1548 if (shared && sbi->upcase != shared) { in ntfs_fill_super()
1549 kvfree(sbi->upcase); in ntfs_fill_super()
1550 sbi->upcase = shared; in ntfs_fill_super()
1560 goto out; in ntfs_fill_super()
1593 goto out; in ntfs_fill_super()
1599 if (!inode->i_op) { in ntfs_fill_super()
1600 err = -EINVAL; in ntfs_fill_super()
1605 sb->s_root = d_make_root(inode); in ntfs_fill_super()
1606 if (!sb->s_root) { in ntfs_fill_super()
1607 err = -ENOMEM; in ntfs_fill_super()
1614 * Volume is recognized as NTFS. Update primary boot. in ntfs_fill_super()
1622 memcpy(bh0->b_data, boot2, sizeof(*boot2)); in ntfs_fill_super()
1637 sb->s_flags |= SB_RDONLY; in ntfs_fill_super()
1642 out: in ntfs_fill_super()
1651 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_unmap_meta()
1652 struct block_device *bdev = sb->s_bdev; in ntfs_unmap_meta()
1653 sector_t devblock = (u64)lcn * sbi->blocks_per_cluster; in ntfs_unmap_meta()
1654 unsigned long blocks = (u64)len * sbi->blocks_per_cluster; in ntfs_unmap_meta()
1656 unsigned long limit = global_zone_page_state(NR_FREE_PAGES) in ntfs_unmap_meta() local
1657 << (PAGE_SHIFT - sb->s_blocksize_bits); in ntfs_unmap_meta()
1659 if (limit >= 0x2000) in ntfs_unmap_meta()
1660 limit -= 0x1000; in ntfs_unmap_meta()
1661 else if (limit < 32) in ntfs_unmap_meta()
1662 limit = 32; in ntfs_unmap_meta()
1664 limit >>= 1; in ntfs_unmap_meta()
1666 while (blocks--) { in ntfs_unmap_meta()
1668 if (cnt++ >= limit) { in ntfs_unmap_meta()
1676 * ntfs_discard - Issue a discard request (trim for SSD).
1684 if (sbi->used.next_free_lcn == lcn + len) in ntfs_discard()
1685 sbi->used.next_free_lcn = lcn; in ntfs_discard()
1687 if (sbi->flags & NTFS_FLAGS_NODISCARD) in ntfs_discard()
1688 return -EOPNOTSUPP; in ntfs_discard()
1690 if (!sbi->options->discard) in ntfs_discard()
1691 return -EOPNOTSUPP; in ntfs_discard()
1693 lbo = (u64)lcn << sbi->cluster_bits; in ntfs_discard()
1694 bytes = (u64)len << sbi->cluster_bits; in ntfs_discard()
1697 start = (lbo + sbi->discard_granularity - 1) & in ntfs_discard()
1698 sbi->discard_granularity_mask_inv; in ntfs_discard()
1700 end = (lbo + bytes) & sbi->discard_granularity_mask_inv; in ntfs_discard()
1702 sb = sbi->sb; in ntfs_discard()
1706 err = blkdev_issue_discard(sb->s_bdev, start >> 9, (end - start) >> 9, in ntfs_discard()
1709 if (err == -EOPNOTSUPP) in ntfs_discard()
1710 sbi->flags |= NTFS_FLAGS_NODISCARD; in ntfs_discard()
1721 * ntfs_fs_free - Free fs_context.
1728 struct ntfs_mount_options *opts = fc->fs_private; in ntfs_fs_free()
1729 struct ntfs_sb_info *sbi = fc->s_fs_info; in ntfs_fs_free()
1740 // clang-format off
1747 // clang-format on
1750 * ntfs_init_fs_context - Initialize sbi and opts
1762 return -ENOMEM; in __ntfs_init_fs_context()
1765 opts->fs_uid = current_uid(); in __ntfs_init_fs_context()
1766 opts->fs_gid = current_gid(); in __ntfs_init_fs_context()
1767 opts->fs_fmask_inv = ~current_umask(); in __ntfs_init_fs_context()
1768 opts->fs_dmask_inv = ~current_umask(); in __ntfs_init_fs_context()
1770 if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) in __ntfs_init_fs_context()
1777 sbi->upcase = kvmalloc(0x10000 * sizeof(short), GFP_KERNEL); in __ntfs_init_fs_context()
1778 if (!sbi->upcase) in __ntfs_init_fs_context()
1781 ratelimit_state_init(&sbi->msg_ratelimit, DEFAULT_RATELIMIT_INTERVAL, in __ntfs_init_fs_context()
1784 mutex_init(&sbi->compress.mtx_lznt); in __ntfs_init_fs_context()
1786 mutex_init(&sbi->compress.mtx_xpress); in __ntfs_init_fs_context()
1787 mutex_init(&sbi->compress.mtx_lzx); in __ntfs_init_fs_context()
1790 fc->s_fs_info = sbi; in __ntfs_init_fs_context()
1792 fc->fs_private = opts; in __ntfs_init_fs_context()
1793 fc->ops = &ntfs_context_ops; in __ntfs_init_fs_context()
1800 return -ENOMEM; in __ntfs_init_fs_context()
1810 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_kill_sb()
1814 if (sbi->options) in ntfs3_kill_sb()
1815 put_mount_options(sbi->options); in ntfs3_kill_sb()
1819 // clang-format off
1835 /* If ntfs3 is used as legacy ntfs enforce read-only mode. */ in ntfs_legacy_init_fs_context()
1836 fc->sb_flags |= SB_RDONLY; in ntfs_legacy_init_fs_context()
1863 return sb->s_type == &ntfs_legacy_fs_type; in is_legacy_ntfs()
1870 // clang-format on
1882 pr_info("ntfs3: Read-only LZX/Xpress compression included\n"); in init_ntfs_fs()
1894 err = -ENOMEM; in init_ntfs_fs()
1901 goto out; in init_ntfs_fs()
1904 out: in init_ntfs_fs()
1934 MODULE_INFO(compression, "Read-only lzx/xpress compression included");