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()
570 mutex_init(&ni->ni_lock); in ntfs_alloc_inode()
571 return &ni->vfs_inode; in ntfs_alloc_inode()
578 mutex_destroy(&ni->ni_lock); in ntfs_free_inode()
586 inode_init_once(&ni->vfs_inode); in init_once()
594 wnd_close(&sbi->mft.bitmap); in ntfs3_put_sbi()
595 wnd_close(&sbi->used.bitmap); in ntfs3_put_sbi()
597 if (sbi->mft.ni) { in ntfs3_put_sbi()
598 iput(&sbi->mft.ni->vfs_inode); in ntfs3_put_sbi()
599 sbi->mft.ni = NULL; in ntfs3_put_sbi()
602 if (sbi->security.ni) { in ntfs3_put_sbi()
603 iput(&sbi->security.ni->vfs_inode); in ntfs3_put_sbi()
604 sbi->security.ni = NULL; in ntfs3_put_sbi()
607 if (sbi->reparse.ni) { in ntfs3_put_sbi()
608 iput(&sbi->reparse.ni->vfs_inode); in ntfs3_put_sbi()
609 sbi->reparse.ni = NULL; in ntfs3_put_sbi()
612 if (sbi->objid.ni) { in ntfs3_put_sbi()
613 iput(&sbi->objid.ni->vfs_inode); in ntfs3_put_sbi()
614 sbi->objid.ni = NULL; in ntfs3_put_sbi()
617 if (sbi->volume.ni) { in ntfs3_put_sbi()
618 iput(&sbi->volume.ni->vfs_inode); in ntfs3_put_sbi()
619 sbi->volume.ni = NULL; in ntfs3_put_sbi()
624 indx_clear(&sbi->security.index_sii); in ntfs3_put_sbi()
625 indx_clear(&sbi->security.index_sdh); in ntfs3_put_sbi()
626 indx_clear(&sbi->reparse.index_r); in ntfs3_put_sbi()
627 indx_clear(&sbi->objid.index_o); in ntfs3_put_sbi()
632 kfree(sbi->new_rec); in ntfs3_free_sbi()
633 kvfree(ntfs_put_shared(sbi->upcase)); in ntfs3_free_sbi()
634 kvfree(sbi->def_table); in ntfs3_free_sbi()
635 kfree(sbi->compress.lznt); in ntfs3_free_sbi()
637 xpress_free_decompressor(sbi->compress.xpress); in ntfs3_free_sbi()
638 lzx_free_decompressor(sbi->compress.lzx); in ntfs3_free_sbi()
645 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_put_super()
649 if (sbi->procdir) { in ntfs_put_super()
650 remove_proc_entry("label", sbi->procdir); in ntfs_put_super()
651 remove_proc_entry("volinfo", sbi->procdir); in ntfs_put_super()
652 remove_proc_entry(sb->s_id, proc_info_root); in ntfs_put_super()
653 sbi->procdir = NULL; in ntfs_put_super()
664 struct super_block *sb = dentry->d_sb; in ntfs_statfs()
665 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_statfs()
666 struct wnd_bitmap *wnd = &sbi->used.bitmap; in ntfs_statfs()
668 buf->f_type = sb->s_magic; in ntfs_statfs()
669 buf->f_bsize = sbi->cluster_size; in ntfs_statfs()
670 buf->f_blocks = wnd->nbits; in ntfs_statfs()
672 buf->f_bfree = buf->f_bavail = wnd_zeroes(wnd); in ntfs_statfs()
673 buf->f_fsid.val[0] = sbi->volume.ser_num; in ntfs_statfs()
674 buf->f_fsid.val[1] = (sbi->volume.ser_num >> 32); in ntfs_statfs()
675 buf->f_namelen = NTFS_NAME_LEN; in ntfs_statfs()
682 struct super_block *sb = root->d_sb; in ntfs_show_options()
683 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_show_options()
684 struct ntfs_mount_options *opts = sbi->options; in ntfs_show_options()
687 seq_printf(m, ",uid=%u", from_kuid_munged(user_ns, opts->fs_uid)); in ntfs_show_options()
688 seq_printf(m, ",gid=%u", from_kgid_munged(user_ns, opts->fs_gid)); in ntfs_show_options()
689 if (opts->dmask) in ntfs_show_options()
690 seq_printf(m, ",dmask=%04o", opts->fs_dmask_inv ^ 0xffff); in ntfs_show_options()
691 if (opts->fmask) in ntfs_show_options()
692 seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff); in ntfs_show_options()
693 if (opts->sys_immutable) in ntfs_show_options()
695 if (opts->discard) in ntfs_show_options()
697 if (opts->force) in ntfs_show_options()
699 if (opts->sparse) in ntfs_show_options()
701 if (opts->nohidden) in ntfs_show_options()
703 if (opts->hide_dot_files) in ntfs_show_options()
705 if (opts->windows_names) in ntfs_show_options()
707 if (opts->showmeta) in ntfs_show_options()
709 if (sb->s_flags & SB_POSIXACL) in ntfs_show_options()
711 if (opts->nls) in ntfs_show_options()
712 seq_printf(m, ",iocharset=%s", opts->nls->charset); in ntfs_show_options()
715 if (opts->prealloc) in ntfs_show_options()
717 if (opts->nocase) in ntfs_show_options()
724 * ntfs_shutdown - super_operations::shutdown
728 set_bit(NTFS_FLAGS_SHUTDOWN_BIT, &ntfs_sb(sb)->flags); in ntfs_shutdown()
732 * ntfs_sync_fs - super_operations::sync_fs
737 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_sync_fs()
742 return -EIO; in ntfs_sync_fs()
744 ni = sbi->security.ni; in ntfs_sync_fs()
746 inode = &ni->vfs_inode; in ntfs_sync_fs()
752 ni = sbi->objid.ni; in ntfs_sync_fs()
754 inode = &ni->vfs_inode; in ntfs_sync_fs()
760 ni = sbi->reparse.ni; in ntfs_sync_fs()
762 inode = &ni->vfs_inode; in ntfs_sync_fs()
805 inode = ERR_PTR(-ESTALE); in ntfs_export_get_inode()
840 * format_size_gb - Return Gb,Mb to print with "%u.%02u Gb".
857 if (boot->sectors_per_clusters <= 0x80) in true_sectors_per_clst()
858 return boot->sectors_per_clusters; in true_sectors_per_clst()
859 if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */ in true_sectors_per_clst()
860 return 1U << (-(s8)boot->sectors_per_clusters); in true_sectors_per_clst()
861 return -EINVAL; in true_sectors_per_clst()
865 * ntfs_init_from_boot - Init internal info from on-disk boot sector.
867 * NTFS mount begins from boot - special formatted 512 bytes.
868 * There are two boots: the first and the last 512 bytes of volume.
877 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_init_from_boot()
893 sbi->volume.blocks = dev_size >> PAGE_SHIFT; in ntfs_init_from_boot()
898 return boot_block ? -EINVAL : -EIO; in ntfs_init_from_boot()
900 err = -EINVAL; in ntfs_init_from_boot()
903 if (bh->b_size - sizeof(*boot) < boot_off) in ntfs_init_from_boot()
904 goto out; in ntfs_init_from_boot()
906 boot = (struct NTFS_BOOT *)Add2Ptr(bh->b_data, boot_off); in ntfs_init_from_boot()
908 if (memcmp(boot->system_id, "NTFS ", sizeof("NTFS ") - 1)) { in ntfs_init_from_boot()
910 goto out; in ntfs_init_from_boot()
914 /*if (0x55 != boot->boot_magic[0] || 0xAA != boot->boot_magic[1]) in ntfs_init_from_boot()
915 * goto out; in ntfs_init_from_boot()
918 boot_sector_size = ((u32)boot->bytes_per_sector[1] << 8) | in ntfs_init_from_boot()
919 boot->bytes_per_sector[0]; in ntfs_init_from_boot()
924 goto out; in ntfs_init_from_boot()
932 goto out; in ntfs_init_from_boot()
935 sbi->cluster_size = boot_sector_size * sct_per_clst; in ntfs_init_from_boot()
936 sbi->cluster_bits = cluster_bits = blksize_bits(sbi->cluster_size); in ntfs_init_from_boot()
937 sbi->cluster_mask = sbi->cluster_size - 1; in ntfs_init_from_boot()
938 sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask; in ntfs_init_from_boot()
940 mlcn = le64_to_cpu(boot->mft_clst); in ntfs_init_from_boot()
941 mlcn2 = le64_to_cpu(boot->mft2_clst); in ntfs_init_from_boot()
942 sectors = le64_to_cpu(boot->sectors_per_volume); in ntfs_init_from_boot()
947 "%s: start of MFT 0x%llx (0x%llx) is out of volume 0x%llx.", in ntfs_init_from_boot()
949 goto out; in ntfs_init_from_boot()
952 if (boot->record_size >= 0) { in ntfs_init_from_boot()
953 record_size = (u32)boot->record_size << cluster_bits; in ntfs_init_from_boot()
954 } else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) { in ntfs_init_from_boot()
955 record_size = 1u << (-boot->record_size); in ntfs_init_from_boot()
958 boot->record_size); in ntfs_init_from_boot()
959 goto out; in ntfs_init_from_boot()
962 sbi->record_size = record_size; in ntfs_init_from_boot()
963 sbi->record_bits = blksize_bits(record_size); in ntfs_init_from_boot()
964 sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes in ntfs_init_from_boot()
969 record_size, boot->record_size); in ntfs_init_from_boot()
970 goto out; in ntfs_init_from_boot()
976 goto out; in ntfs_init_from_boot()
979 if (boot->index_size >= 0) { in ntfs_init_from_boot()
980 sbi->index_size = (u32)boot->index_size << cluster_bits; in ntfs_init_from_boot()
981 } else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) { in ntfs_init_from_boot()
982 sbi->index_size = 1u << (-boot->index_size); in ntfs_init_from_boot()
985 boot->index_size); in ntfs_init_from_boot()
986 goto out; in ntfs_init_from_boot()
990 if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) { in ntfs_init_from_boot()
992 sbi->index_size, boot->index_size); in ntfs_init_from_boot()
993 goto out; in ntfs_init_from_boot()
996 if (sbi->index_size > MAXIMUM_BYTES_PER_INDEX) { in ntfs_init_from_boot()
998 sbi->index_size); in ntfs_init_from_boot()
999 goto out; in ntfs_init_from_boot()
1002 sbi->volume.size = sectors * boot_sector_size; in ntfs_init_from_boot()
1004 gb = format_size_gb(sbi->volume.size + boot_sector_size, &mb); in ntfs_init_from_boot()
1007 * - Volume formatted and mounted with the same sector size. in ntfs_init_from_boot()
1008 * - Volume formatted 4K and mounted as 512. in ntfs_init_from_boot()
1009 * - Volume formatted 512 and mounted as 4K. in ntfs_init_from_boot()
1016 dev_size += sector_size - 1; in ntfs_init_from_boot()
1019 sbi->mft.lbo = mlcn << cluster_bits; in ntfs_init_from_boot()
1020 sbi->mft.lbo2 = mlcn2 << cluster_bits; in ntfs_init_from_boot()
1023 if (sbi->cluster_size < boot_sector_size) { in ntfs_init_from_boot()
1025 sbi->cluster_size); in ntfs_init_from_boot()
1026 goto out; in ntfs_init_from_boot()
1030 if (sbi->cluster_size < sector_size) { in ntfs_init_from_boot()
1035 sbi->cluster_size, sector_size); in ntfs_init_from_boot()
1036 goto out; in ntfs_init_from_boot()
1039 sbi->max_bytes_per_attr = in ntfs_init_from_boot()
1040 record_size - ALIGN(MFTRECORD_FIXUP_OFFSET, 8) - in ntfs_init_from_boot()
1041 ALIGN(((record_size >> SECTOR_SHIFT) * sizeof(short)), 8) - in ntfs_init_from_boot()
1044 sbi->volume.ser_num = le64_to_cpu(boot->serial_num); in ntfs_init_from_boot()
1046 /* Warning if RAW volume. */ in ntfs_init_from_boot()
1047 if (dev_size < sbi->volume.size + boot_sector_size) { in ntfs_init_from_boot()
1053 "RAW NTFS volume: Filesystem size %u.%02u Gb > volume size %u.%02u Gb. Mount in read-only.", in ntfs_init_from_boot()
1055 sb->s_flags |= SB_RDONLY; in ntfs_init_from_boot()
1058 clusters = sbi->volume.size >> cluster_bits; in ntfs_init_from_boot()
1066 goto out; in ntfs_init_from_boot()
1072 sbi->used.bitmap.nbits = clusters; in ntfs_init_from_boot()
1076 err = -ENOMEM; in ntfs_init_from_boot()
1077 goto out; in ntfs_init_from_boot()
1080 sbi->new_rec = rec; in ntfs_init_from_boot()
1081 rec->rhdr.sign = NTFS_FILE_SIGNATURE; in ntfs_init_from_boot()
1082 rec->rhdr.fix_off = cpu_to_le16(MFTRECORD_FIXUP_OFFSET); in ntfs_init_from_boot()
1083 fn = (sbi->record_size >> SECTOR_SHIFT) + 1; in ntfs_init_from_boot()
1084 rec->rhdr.fix_num = cpu_to_le16(fn); in ntfs_init_from_boot()
1086 rec->attr_off = cpu_to_le16(ao); in ntfs_init_from_boot()
1087 rec->used = cpu_to_le32(ao + ALIGN(sizeof(enum ATTR_TYPE), 8)); in ntfs_init_from_boot()
1088 rec->total = cpu_to_le32(sbi->record_size); in ntfs_init_from_boot()
1089 ((struct ATTRIB *)Add2Ptr(rec, ao))->type = ATTR_END; in ntfs_init_from_boot()
1091 sb_set_blocksize(sb, min_t(u32, sbi->cluster_size, PAGE_SIZE)); in ntfs_init_from_boot()
1093 sbi->block_mask = sb->s_blocksize - 1; in ntfs_init_from_boot()
1094 sbi->blocks_per_cluster = sbi->cluster_size >> sb->s_blocksize_bits; in ntfs_init_from_boot()
1095 sbi->volume.blocks = sbi->volume.size >> sb->s_blocksize_bits; in ntfs_init_from_boot()
1098 sbi->maxbytes = (clusters << cluster_bits) - 1; in ntfs_init_from_boot()
1101 if (clusters >= (1ull << (64 - cluster_bits))) in ntfs_init_from_boot()
1102 sbi->maxbytes = -1; in ntfs_init_from_boot()
1103 sbi->maxbytes_sparse = -1; in ntfs_init_from_boot()
1104 sb->s_maxbytes = MAX_LFS_FILESIZE; in ntfs_init_from_boot()
1107 sbi->maxbytes_sparse = (1ull << (cluster_bits + 32)) - 1; in ntfs_init_from_boot()
1108 sb->s_maxbytes = 0xFFFFFFFFull << cluster_bits; in ntfs_init_from_boot()
1116 sbi->zone_max = min_t(CLST, 0x20000000 >> cluster_bits, clusters >> 3); in ntfs_init_from_boot()
1120 if (bh->b_blocknr && !sb_rdonly(sb)) { in ntfs_init_from_boot()
1129 out: in ntfs_init_from_boot()
1132 if (err == -EINVAL && !boot_block && dev_size0 > PAGE_SHIFT) { in ntfs_init_from_boot()
1134 u64 lbo = dev_size0 - sizeof(*boot); in ntfs_init_from_boot()
1137 boot_off = lbo & (block_size - 1); in ntfs_init_from_boot()
1153 * ntfs_fill_super - Try to mount.
1158 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_fill_super()
1159 struct block_device *bdev = sb->s_bdev; in ntfs_fill_super()
1176 sbi->sb = sb; in ntfs_fill_super()
1177 sbi->options = options = fc->fs_private; in ntfs_fill_super()
1178 fc->fs_private = NULL; in ntfs_fill_super()
1179 sb->s_flags |= SB_NODIRATIME; in ntfs_fill_super()
1180 sb->s_magic = 0x7366746e; // "ntfs" in ntfs_fill_super()
1181 sb->s_op = &ntfs_sops; in ntfs_fill_super()
1182 sb->s_export_op = &ntfs_export_ops; in ntfs_fill_super()
1183 sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec in ntfs_fill_super()
1184 sb->s_xattr = ntfs_xattr_handlers; in ntfs_fill_super()
1185 sb->s_d_op = options->nocase ? &ntfs_dentry_ops : NULL; in ntfs_fill_super()
1187 options->nls = ntfs_load_nls(options->nls_name); in ntfs_fill_super()
1188 if (IS_ERR(options->nls)) { in ntfs_fill_super()
1189 options->nls = NULL; in ntfs_fill_super()
1190 errorf(fc, "Cannot load nls %s", options->nls_name); in ntfs_fill_super()
1191 err = -EINVAL; in ntfs_fill_super()
1192 goto out; in ntfs_fill_super()
1196 sbi->discard_granularity = bdev_discard_granularity(bdev); in ntfs_fill_super()
1197 sbi->discard_granularity_mask_inv = in ntfs_fill_super()
1198 ~(u64)(sbi->discard_granularity - 1); in ntfs_fill_super()
1205 goto out; in ntfs_fill_super()
1208 * Load $Volume. This should be done before $LogFile in ntfs_fill_super()
1209 * 'cause 'sbi->volume.ni' is used in 'ntfs_set_state'. in ntfs_fill_super()
1216 ntfs_err(sb, "Failed to load $Volume (%d).", err); in ntfs_fill_super()
1217 goto out; in ntfs_fill_super()
1227 } else if (!attr->non_res && !is_attr_ext(attr)) { in ntfs_fill_super()
1230 le32_to_cpu(attr->res.data_size) >> 1, in ntfs_fill_super()
1231 UTF16_LITTLE_ENDIAN, sbi->volume.label, in ntfs_fill_super()
1232 sizeof(sbi->volume.label)); in ntfs_fill_super()
1234 sbi->volume.label[0] = 0; in ntfs_fill_super()
1237 //err = -EINVAL; in ntfs_fill_super()
1244 ntfs_err(sb, "$Volume is corrupted."); in ntfs_fill_super()
1245 err = -EINVAL; in ntfs_fill_super()
1249 sbi->volume.major_ver = info->major_ver; in ntfs_fill_super()
1250 sbi->volume.minor_ver = info->minor_ver; in ntfs_fill_super()
1251 sbi->volume.flags = info->flags; in ntfs_fill_super()
1252 sbi->volume.ni = ni; in ntfs_fill_super()
1253 if (info->flags & VOLUME_FLAG_DIRTY) { in ntfs_fill_super()
1254 sbi->volume.real_dirty = true; in ntfs_fill_super()
1265 goto out; in ntfs_fill_super()
1268 sbi->mft.recs_mirr = ntfs_up_cluster(sbi, inode->i_size) >> in ntfs_fill_super()
1269 sbi->record_bits; in ntfs_fill_super()
1280 goto out; in ntfs_fill_super()
1291 if ((sbi->flags & NTFS_FLAGS_NEED_REPLAY) && !ro) { in ntfs_fill_super()
1293 err = -EINVAL; in ntfs_fill_super()
1294 goto out; in ntfs_fill_super()
1297 if ((sbi->volume.flags & VOLUME_FLAG_DIRTY) && !ro && !options->force) { in ntfs_fill_super()
1298 ntfs_warn(sb, "volume is dirty and \"force\" flag is not set!"); in ntfs_fill_super()
1299 err = -EINVAL; in ntfs_fill_super()
1300 goto out; in ntfs_fill_super()
1311 goto out; in ntfs_fill_super()
1316 sbi->mft.used = ni->i_valid >> sbi->record_bits; in ntfs_fill_super()
1317 tt = inode->i_size >> sbi->record_bits; in ntfs_fill_super()
1318 sbi->mft.next_free = MFT_REC_USER; in ntfs_fill_super()
1320 err = wnd_init(&sbi->mft.bitmap, sb, tt); in ntfs_fill_super()
1330 sbi->mft.ni = ni; in ntfs_fill_super()
1339 goto out; in ntfs_fill_super()
1343 if (inode->i_size >> 32) { in ntfs_fill_super()
1344 err = -EINVAL; in ntfs_fill_super()
1350 tt = sbi->used.bitmap.nbits; in ntfs_fill_super()
1351 if (inode->i_size < ntfs3_bitmap_size(tt)) { in ntfs_fill_super()
1353 err = -EINVAL; in ntfs_fill_super()
1357 err = wnd_init(&sbi->used.bitmap, sb, tt); in ntfs_fill_super()
1369 goto out; in ntfs_fill_super()
1379 goto out; in ntfs_fill_super()
1384 for (i = 0; run_get_entry(&ni->file.run, i, &vcn, &lcn, &len); i++) { in ntfs_fill_super()
1393 if (wnd_set_used_safe(&sbi->used.bitmap, lcn, len, &tt) || tt) { in ntfs_fill_super()
1405 "Volume contains %zu bad blocks in %zu fragments.", in ntfs_fill_super()
1417 goto out; in ntfs_fill_super()
1424 if (inode->i_size < sizeof(struct ATTR_DEF_ENTRY) || in ntfs_fill_super()
1425 inode->i_size > 100 * sizeof(struct ATTR_DEF_ENTRY)) { in ntfs_fill_super()
1427 inode->i_size); in ntfs_fill_super()
1428 err = -EINVAL; in ntfs_fill_super()
1432 bytes = inode->i_size; in ntfs_fill_super()
1433 sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL); in ntfs_fill_super()
1435 err = -ENOMEM; in ntfs_fill_super()
1440 err = inode_read_data(inode, sbi->def_table, bytes); in ntfs_fill_super()
1446 if (ATTR_STD != t->type) { in ntfs_fill_super()
1448 err = -EINVAL; in ntfs_fill_super()
1453 sbi->def_entries = 1; in ntfs_fill_super()
1457 u32 t32 = le32_to_cpu(t->type); in ntfs_fill_super()
1458 u64 sz = le64_to_cpu(t->max_sz); in ntfs_fill_super()
1460 if ((t32 & 0xF) || le32_to_cpu(t[-1].type) >= t32) in ntfs_fill_super()
1463 if (t->type == ATTR_REPARSE) in ntfs_fill_super()
1464 sbi->reparse.max_size = sz; in ntfs_fill_super()
1465 else if (t->type == ATTR_EA) in ntfs_fill_super()
1466 sbi->ea_max_size = sz; in ntfs_fill_super()
1470 sbi->def_entries += 1; in ntfs_fill_super()
1481 goto out; in ntfs_fill_super()
1484 if (inode->i_size != 0x10000 * sizeof(short)) { in ntfs_fill_super()
1485 err = -EINVAL; in ntfs_fill_super()
1491 err = inode_read_data(inode, sbi->upcase, 0x10000 * sizeof(short)); in ntfs_fill_super()
1499 u16 *dst = sbi->upcase; in ntfs_fill_super()
1506 shared = ntfs_set_shared(sbi->upcase, 0x10000 * sizeof(short)); in ntfs_fill_super()
1507 if (shared && sbi->upcase != shared) { in ntfs_fill_super()
1508 kvfree(sbi->upcase); in ntfs_fill_super()
1509 sbi->upcase = shared; in ntfs_fill_super()
1519 goto out; in ntfs_fill_super()
1552 goto out; in ntfs_fill_super()
1558 if (!inode->i_op) { in ntfs_fill_super()
1559 err = -EINVAL; in ntfs_fill_super()
1564 sb->s_root = d_make_root(inode); in ntfs_fill_super()
1565 if (!sb->s_root) { in ntfs_fill_super()
1566 err = -ENOMEM; in ntfs_fill_super()
1573 * Volume is recognized as NTFS. Update primary boot. in ntfs_fill_super()
1581 memcpy(bh0->b_data, boot2, sizeof(*boot2)); in ntfs_fill_super()
1596 struct proc_dir_entry *e = proc_mkdir(sb->s_id, proc_info_root); in ntfs_fill_super()
1603 sbi->procdir = e; in ntfs_fill_super()
1609 sb->s_flags |= SB_RDONLY; in ntfs_fill_super()
1614 out: in ntfs_fill_super()
1623 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_unmap_meta()
1624 struct block_device *bdev = sb->s_bdev; in ntfs_unmap_meta()
1625 sector_t devblock = (u64)lcn * sbi->blocks_per_cluster; in ntfs_unmap_meta()
1626 unsigned long blocks = (u64)len * sbi->blocks_per_cluster; in ntfs_unmap_meta()
1628 unsigned long limit = global_zone_page_state(NR_FREE_PAGES) in ntfs_unmap_meta() local
1629 << (PAGE_SHIFT - sb->s_blocksize_bits); in ntfs_unmap_meta()
1631 if (limit >= 0x2000) in ntfs_unmap_meta()
1632 limit -= 0x1000; in ntfs_unmap_meta()
1633 else if (limit < 32) in ntfs_unmap_meta()
1634 limit = 32; in ntfs_unmap_meta()
1636 limit >>= 1; in ntfs_unmap_meta()
1638 while (blocks--) { in ntfs_unmap_meta()
1640 if (cnt++ >= limit) { in ntfs_unmap_meta()
1648 * ntfs_discard - Issue a discard request (trim for SSD).
1656 if (sbi->used.next_free_lcn == lcn + len) in ntfs_discard()
1657 sbi->used.next_free_lcn = lcn; in ntfs_discard()
1659 if (sbi->flags & NTFS_FLAGS_NODISCARD) in ntfs_discard()
1660 return -EOPNOTSUPP; in ntfs_discard()
1662 if (!sbi->options->discard) in ntfs_discard()
1663 return -EOPNOTSUPP; in ntfs_discard()
1665 lbo = (u64)lcn << sbi->cluster_bits; in ntfs_discard()
1666 bytes = (u64)len << sbi->cluster_bits; in ntfs_discard()
1669 start = (lbo + sbi->discard_granularity - 1) & in ntfs_discard()
1670 sbi->discard_granularity_mask_inv; in ntfs_discard()
1672 end = (lbo + bytes) & sbi->discard_granularity_mask_inv; in ntfs_discard()
1674 sb = sbi->sb; in ntfs_discard()
1678 err = blkdev_issue_discard(sb->s_bdev, start >> 9, (end - start) >> 9, in ntfs_discard()
1681 if (err == -EOPNOTSUPP) in ntfs_discard()
1682 sbi->flags |= NTFS_FLAGS_NODISCARD; in ntfs_discard()
1693 * ntfs_fs_free - Free fs_context.
1700 struct ntfs_mount_options *opts = fc->fs_private; in ntfs_fs_free()
1701 struct ntfs_sb_info *sbi = fc->s_fs_info; in ntfs_fs_free()
1712 // clang-format off
1719 // clang-format on
1722 * ntfs_init_fs_context - Initialize sbi and opts
1734 return -ENOMEM; in __ntfs_init_fs_context()
1737 opts->fs_uid = current_uid(); in __ntfs_init_fs_context()
1738 opts->fs_gid = current_gid(); in __ntfs_init_fs_context()
1739 opts->fs_fmask_inv = ~current_umask(); in __ntfs_init_fs_context()
1740 opts->fs_dmask_inv = ~current_umask(); in __ntfs_init_fs_context()
1742 if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) in __ntfs_init_fs_context()
1749 sbi->upcase = kvmalloc(0x10000 * sizeof(short), GFP_KERNEL); in __ntfs_init_fs_context()
1750 if (!sbi->upcase) in __ntfs_init_fs_context()
1753 ratelimit_state_init(&sbi->msg_ratelimit, DEFAULT_RATELIMIT_INTERVAL, in __ntfs_init_fs_context()
1756 mutex_init(&sbi->compress.mtx_lznt); in __ntfs_init_fs_context()
1758 mutex_init(&sbi->compress.mtx_xpress); in __ntfs_init_fs_context()
1759 mutex_init(&sbi->compress.mtx_lzx); in __ntfs_init_fs_context()
1762 fc->s_fs_info = sbi; in __ntfs_init_fs_context()
1764 fc->fs_private = opts; in __ntfs_init_fs_context()
1765 fc->ops = &ntfs_context_ops; in __ntfs_init_fs_context()
1772 return -ENOMEM; in __ntfs_init_fs_context()
1782 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_kill_sb()
1786 if (sbi->options) in ntfs3_kill_sb()
1787 put_mount_options(sbi->options); in ntfs3_kill_sb()
1791 // clang-format off
1807 /* If ntfs3 is used as legacy ntfs enforce read-only mode. */ in ntfs_legacy_init_fs_context()
1808 fc->sb_flags |= SB_RDONLY; in ntfs_legacy_init_fs_context()
1835 return sb->s_type == &ntfs_legacy_fs_type; in is_legacy_ntfs()
1842 // clang-format on
1854 pr_info("ntfs3: Read-only LZX/Xpress compression included\n"); in init_ntfs_fs()
1869 err = -ENOMEM; in init_ntfs_fs()
1876 goto out; in init_ntfs_fs()
1879 out: in init_ntfs_fs()
1911 MODULE_INFO(compression, "Read-only lzx/xpress compression included");