Lines Matching +full:ao +full:- +full:secure

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
32 * -----------------------------------------------------------------------------
34 * -----------------------------------------------------------------------------
37 * ----------------------------------------------------------|------------------
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()
127 spin_lock(&de->d_lock); in ntfs_inode_printk()
129 de->d_name.name); in ntfs_inode_printk()
130 spin_unlock(&de->d_lock); in ntfs_inode_printk()
144 sb->s_id, inode->i_ino, name ? name : "", &vaf); in ntfs_inode_printk()
157 * On-disk ntfs's upcase table is created by ntfs formatter.
161 * It is good idea to share in-memory 'upcase' table between different volumes.
176 * * @ptr - If pointer was saved in shared memory.
177 * * NULL - If pointer was not shared.
182 int i, j = -1; in ntfs_set_shared()
196 if (!ret && j != -1) { in ntfs_set_shared()
211 * * @ptr - If pointer is not shared anymore.
212 * * NULL - If pointer is still shared.
222 if (--s_shared[i].cnt) in ntfs_put_shared()
234 kfree(options->nls_name); in put_mount_options()
235 unload_nls(options->nls); in put_mount_options()
260 // clang-format off
281 // clang-format on
306 return ERR_PTR(-EINVAL); in ntfs_load_nls()
312 struct ntfs_mount_options *opts = fc->fs_private; in ntfs_fs_parse_param()
322 opts->fs_uid = make_kuid(current_user_ns(), result.uint_32); in ntfs_fs_parse_param()
323 if (!uid_valid(opts->fs_uid)) in ntfs_fs_parse_param()
327 opts->fs_gid = make_kgid(current_user_ns(), result.uint_32); in ntfs_fs_parse_param()
328 if (!gid_valid(opts->fs_gid)) in ntfs_fs_parse_param()
334 opts->fs_fmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
335 opts->fs_dmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
336 opts->fmask = 1; in ntfs_fs_parse_param()
337 opts->dmask = 1; in ntfs_fs_parse_param()
342 opts->fs_dmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
343 opts->dmask = 1; in ntfs_fs_parse_param()
348 opts->fs_fmask_inv = ~result.uint_32; in ntfs_fs_parse_param()
349 opts->fmask = 1; in ntfs_fs_parse_param()
352 opts->sys_immutable = result.negated ? 0 : 1; in ntfs_fs_parse_param()
355 opts->discard = result.negated ? 0 : 1; in ntfs_fs_parse_param()
358 opts->force = result.negated ? 0 : 1; in ntfs_fs_parse_param()
361 opts->sparse = result.negated ? 0 : 1; in ntfs_fs_parse_param()
364 opts->nohidden = result.negated ? 1 : 0; in ntfs_fs_parse_param()
367 opts->hide_dot_files = result.negated ? 0 : 1; in ntfs_fs_parse_param()
370 opts->windows_names = result.negated ? 0 : 1; in ntfs_fs_parse_param()
373 opts->showmeta = result.negated ? 0 : 1; in ntfs_fs_parse_param()
378 fc->sb_flags |= SB_POSIXACL; in ntfs_fs_parse_param()
384 fc->sb_flags &= ~SB_POSIXACL; in ntfs_fs_parse_param()
387 kfree(opts->nls_name); in ntfs_fs_parse_param()
388 opts->nls_name = param->string; in ntfs_fs_parse_param()
389 param->string = NULL; in ntfs_fs_parse_param()
392 opts->prealloc = result.negated ? 0 : 1; in ntfs_fs_parse_param()
395 opts->nocase = result.negated ? 1 : 0; in ntfs_fs_parse_param()
399 return -EINVAL; in ntfs_fs_parse_param()
406 struct super_block *sb = fc->root->d_sb; in ntfs_fs_reconfigure()
407 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_fs_reconfigure()
408 struct ntfs_mount_options *new_opts = fc->fs_private; in ntfs_fs_reconfigure()
411 ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY); in ntfs_fs_reconfigure()
412 if (ro_rw && (sbi->flags & NTFS_FLAGS_NEED_REPLAY)) { in ntfs_fs_reconfigure()
415 return -EINVAL; in ntfs_fs_reconfigure()
418 new_opts->nls = ntfs_load_nls(new_opts->nls_name); in ntfs_fs_reconfigure()
419 if (IS_ERR(new_opts->nls)) { in ntfs_fs_reconfigure()
420 new_opts->nls = NULL; in ntfs_fs_reconfigure()
422 new_opts->nls_name); in ntfs_fs_reconfigure()
423 return -EINVAL; in ntfs_fs_reconfigure()
425 if (new_opts->nls != sbi->options->nls) in ntfs_fs_reconfigure()
432 if (ro_rw && (sbi->volume.flags & VOLUME_FLAG_DIRTY) && in ntfs_fs_reconfigure()
433 !new_opts->force) { in ntfs_fs_reconfigure()
436 return -EINVAL; in ntfs_fs_reconfigure()
439 swap(sbi->options, fc->fs_private); in ntfs_fs_reconfigure()
462 struct super_block *sb = m->private; in ntfs3_volinfo()
463 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_volinfo()
466 sbi->volume.major_ver, sbi->volume.minor_ver, in ntfs3_volinfo()
467 sbi->cluster_size, sbi->used.bitmap.nbits, in ntfs3_volinfo()
468 sbi->mft.bitmap.nbits, in ntfs3_volinfo()
469 sbi->mft.bitmap.nbits - wnd_zeroes(&sbi->mft.bitmap), in ntfs3_volinfo()
470 sbi->volume.real_dirty ? "dirty" : "clean", in ntfs3_volinfo()
471 (sbi->volume.flags & VOLUME_FLAG_DIRTY) ? "dirty" : "clean"); in ntfs3_volinfo()
484 struct super_block *sb = m->private; in ntfs3_label_show()
485 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_label_show()
487 seq_printf(m, "%s\n", sbi->volume.label); in ntfs3_label_show()
502 return -EROFS; in ntfs3_label_write()
507 return -ENOMEM; in ntfs3_label_write()
510 ret = -EFAULT; in ntfs3_label_write()
513 while (ret > 0 && label[ret - 1] == '\n') in ntfs3_label_write()
514 ret -= 1; in ntfs3_label_write()
516 err = ntfs_set_label(sb->s_fs_info, label, ret); in ntfs3_label_write()
563 mutex_init(&ni->ni_lock); in ntfs_alloc_inode()
564 return &ni->vfs_inode; in ntfs_alloc_inode()
571 mutex_destroy(&ni->ni_lock); in ntfs_free_inode()
579 inode_init_once(&ni->vfs_inode); in init_once()
587 wnd_close(&sbi->mft.bitmap); in ntfs3_put_sbi()
588 wnd_close(&sbi->used.bitmap); in ntfs3_put_sbi()
590 if (sbi->mft.ni) { in ntfs3_put_sbi()
591 iput(&sbi->mft.ni->vfs_inode); in ntfs3_put_sbi()
592 sbi->mft.ni = NULL; in ntfs3_put_sbi()
595 if (sbi->security.ni) { in ntfs3_put_sbi()
596 iput(&sbi->security.ni->vfs_inode); in ntfs3_put_sbi()
597 sbi->security.ni = NULL; in ntfs3_put_sbi()
600 if (sbi->reparse.ni) { in ntfs3_put_sbi()
601 iput(&sbi->reparse.ni->vfs_inode); in ntfs3_put_sbi()
602 sbi->reparse.ni = NULL; in ntfs3_put_sbi()
605 if (sbi->objid.ni) { in ntfs3_put_sbi()
606 iput(&sbi->objid.ni->vfs_inode); in ntfs3_put_sbi()
607 sbi->objid.ni = NULL; in ntfs3_put_sbi()
610 if (sbi->volume.ni) { in ntfs3_put_sbi()
611 iput(&sbi->volume.ni->vfs_inode); in ntfs3_put_sbi()
612 sbi->volume.ni = NULL; in ntfs3_put_sbi()
617 indx_clear(&sbi->security.index_sii); in ntfs3_put_sbi()
618 indx_clear(&sbi->security.index_sdh); in ntfs3_put_sbi()
619 indx_clear(&sbi->reparse.index_r); in ntfs3_put_sbi()
620 indx_clear(&sbi->objid.index_o); in ntfs3_put_sbi()
625 kfree(sbi->new_rec); in ntfs3_free_sbi()
626 kvfree(ntfs_put_shared(sbi->upcase)); in ntfs3_free_sbi()
627 kvfree(sbi->def_table); in ntfs3_free_sbi()
628 kfree(sbi->compress.lznt); in ntfs3_free_sbi()
630 xpress_free_decompressor(sbi->compress.xpress); in ntfs3_free_sbi()
631 lzx_free_decompressor(sbi->compress.lzx); in ntfs3_free_sbi()
638 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_put_super()
642 if (sbi->procdir) { in ntfs_put_super()
643 remove_proc_entry("label", sbi->procdir); in ntfs_put_super()
644 remove_proc_entry("volinfo", sbi->procdir); in ntfs_put_super()
645 remove_proc_entry(sb->s_id, proc_info_root); in ntfs_put_super()
646 sbi->procdir = NULL; in ntfs_put_super()
657 struct super_block *sb = dentry->d_sb; in ntfs_statfs()
658 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_statfs()
659 struct wnd_bitmap *wnd = &sbi->used.bitmap; in ntfs_statfs()
661 buf->f_type = sb->s_magic; in ntfs_statfs()
662 buf->f_bsize = sbi->cluster_size; in ntfs_statfs()
663 buf->f_blocks = wnd->nbits; in ntfs_statfs()
665 buf->f_bfree = buf->f_bavail = wnd_zeroes(wnd); in ntfs_statfs()
666 buf->f_fsid.val[0] = sbi->volume.ser_num; in ntfs_statfs()
667 buf->f_fsid.val[1] = (sbi->volume.ser_num >> 32); in ntfs_statfs()
668 buf->f_namelen = NTFS_NAME_LEN; in ntfs_statfs()
675 struct super_block *sb = root->d_sb; in ntfs_show_options()
676 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_show_options()
677 struct ntfs_mount_options *opts = sbi->options; in ntfs_show_options()
680 seq_printf(m, ",uid=%u", from_kuid_munged(user_ns, opts->fs_uid)); in ntfs_show_options()
681 seq_printf(m, ",gid=%u", from_kgid_munged(user_ns, opts->fs_gid)); in ntfs_show_options()
682 if (opts->dmask) in ntfs_show_options()
683 seq_printf(m, ",dmask=%04o", opts->fs_dmask_inv ^ 0xffff); in ntfs_show_options()
684 if (opts->fmask) in ntfs_show_options()
685 seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff); in ntfs_show_options()
686 if (opts->sys_immutable) in ntfs_show_options()
688 if (opts->discard) in ntfs_show_options()
690 if (opts->force) in ntfs_show_options()
692 if (opts->sparse) in ntfs_show_options()
694 if (opts->nohidden) in ntfs_show_options()
696 if (opts->hide_dot_files) in ntfs_show_options()
698 if (opts->windows_names) in ntfs_show_options()
700 if (opts->showmeta) in ntfs_show_options()
702 if (sb->s_flags & SB_POSIXACL) in ntfs_show_options()
704 if (opts->nls) in ntfs_show_options()
705 seq_printf(m, ",iocharset=%s", opts->nls->charset); in ntfs_show_options()
708 if (opts->prealloc) in ntfs_show_options()
710 if (opts->nocase) in ntfs_show_options()
717 * ntfs_shutdown - super_operations::shutdown
721 set_bit(NTFS_FLAGS_SHUTDOWN_BIT, &ntfs_sb(sb)->flags); in ntfs_shutdown()
725 * ntfs_sync_fs - super_operations::sync_fs
730 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_sync_fs()
735 return -EIO; in ntfs_sync_fs()
737 ni = sbi->security.ni; in ntfs_sync_fs()
739 inode = &ni->vfs_inode; in ntfs_sync_fs()
745 ni = sbi->objid.ni; in ntfs_sync_fs()
747 inode = &ni->vfs_inode; in ntfs_sync_fs()
753 ni = sbi->reparse.ni; in ntfs_sync_fs()
755 inode = &ni->vfs_inode; in ntfs_sync_fs()
798 inode = ERR_PTR(-ESTALE); in ntfs_export_get_inode()
833 * format_size_gb - Return Gb,Mb to print with "%u.%02u Gb".
850 if (boot->sectors_per_clusters <= 0x80) in true_sectors_per_clst()
851 return boot->sectors_per_clusters; in true_sectors_per_clst()
852 if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */ in true_sectors_per_clst()
853 return 1U << (-(s8)boot->sectors_per_clusters); in true_sectors_per_clst()
854 return -EINVAL; in true_sectors_per_clst()
858 * ntfs_init_from_boot - Init internal info from on-disk boot sector.
860 * NTFS mount begins from boot - special formatted 512 bytes.
870 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_init_from_boot()
877 u16 fn, ao; in ntfs_init_from_boot() local
886 sbi->volume.blocks = dev_size >> PAGE_SHIFT; in ntfs_init_from_boot()
891 return boot_block ? -EINVAL : -EIO; in ntfs_init_from_boot()
893 err = -EINVAL; in ntfs_init_from_boot()
896 if (bh->b_size - sizeof(*boot) < boot_off) in ntfs_init_from_boot()
899 boot = (struct NTFS_BOOT *)Add2Ptr(bh->b_data, boot_off); in ntfs_init_from_boot()
901 if (memcmp(boot->system_id, "NTFS ", sizeof("NTFS ") - 1)) { in ntfs_init_from_boot()
907 /*if (0x55 != boot->boot_magic[0] || 0xAA != boot->boot_magic[1]) in ntfs_init_from_boot()
911 boot_sector_size = ((u32)boot->bytes_per_sector[1] << 8) | in ntfs_init_from_boot()
912 boot->bytes_per_sector[0]; in ntfs_init_from_boot()
928 sbi->cluster_size = boot_sector_size * sct_per_clst; in ntfs_init_from_boot()
929 sbi->cluster_bits = cluster_bits = blksize_bits(sbi->cluster_size); in ntfs_init_from_boot()
930 sbi->cluster_mask = sbi->cluster_size - 1; in ntfs_init_from_boot()
931 sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask; in ntfs_init_from_boot()
933 mlcn = le64_to_cpu(boot->mft_clst); in ntfs_init_from_boot()
934 mlcn2 = le64_to_cpu(boot->mft2_clst); in ntfs_init_from_boot()
935 sectors = le64_to_cpu(boot->sectors_per_volume); in ntfs_init_from_boot()
945 if (boot->record_size >= 0) { in ntfs_init_from_boot()
946 record_size = (u32)boot->record_size << cluster_bits; in ntfs_init_from_boot()
947 } else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) { in ntfs_init_from_boot()
948 record_size = 1u << (-boot->record_size); in ntfs_init_from_boot()
951 boot->record_size); in ntfs_init_from_boot()
955 sbi->record_size = record_size; in ntfs_init_from_boot()
956 sbi->record_bits = blksize_bits(record_size); in ntfs_init_from_boot()
957 sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes in ntfs_init_from_boot()
962 record_size, boot->record_size); in ntfs_init_from_boot()
972 if (boot->index_size >= 0) { in ntfs_init_from_boot()
973 sbi->index_size = (u32)boot->index_size << cluster_bits; in ntfs_init_from_boot()
974 } else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) { in ntfs_init_from_boot()
975 sbi->index_size = 1u << (-boot->index_size); in ntfs_init_from_boot()
978 boot->index_size); in ntfs_init_from_boot()
983 if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) { in ntfs_init_from_boot()
985 sbi->index_size, boot->index_size); in ntfs_init_from_boot()
989 if (sbi->index_size > MAXIMUM_BYTES_PER_INDEX) { in ntfs_init_from_boot()
991 sbi->index_size); in ntfs_init_from_boot()
995 sbi->volume.size = sectors * boot_sector_size; in ntfs_init_from_boot()
997 gb = format_size_gb(sbi->volume.size + boot_sector_size, &mb); in ntfs_init_from_boot()
1000 * - Volume formatted and mounted with the same sector size. in ntfs_init_from_boot()
1001 * - Volume formatted 4K and mounted as 512. in ntfs_init_from_boot()
1002 * - Volume formatted 512 and mounted as 4K. in ntfs_init_from_boot()
1009 dev_size += sector_size - 1; in ntfs_init_from_boot()
1012 sbi->mft.lbo = mlcn << cluster_bits; in ntfs_init_from_boot()
1013 sbi->mft.lbo2 = mlcn2 << cluster_bits; in ntfs_init_from_boot()
1016 if (sbi->cluster_size < boot_sector_size) { in ntfs_init_from_boot()
1018 sbi->cluster_size); in ntfs_init_from_boot()
1023 if (sbi->cluster_size < sector_size) { in ntfs_init_from_boot()
1028 sbi->cluster_size, sector_size); in ntfs_init_from_boot()
1032 sbi->max_bytes_per_attr = in ntfs_init_from_boot()
1033 record_size - ALIGN(MFTRECORD_FIXUP_OFFSET, 8) - in ntfs_init_from_boot()
1034 ALIGN(((record_size >> SECTOR_SHIFT) * sizeof(short)), 8) - in ntfs_init_from_boot()
1037 sbi->volume.ser_num = le64_to_cpu(boot->serial_num); in ntfs_init_from_boot()
1040 if (dev_size < sbi->volume.size + boot_sector_size) { in ntfs_init_from_boot()
1046 "RAW NTFS volume: Filesystem size %u.%02u Gb > volume size %u.%02u Gb. Mount in read-only.", in ntfs_init_from_boot()
1048 sb->s_flags |= SB_RDONLY; in ntfs_init_from_boot()
1051 clusters = sbi->volume.size >> cluster_bits; in ntfs_init_from_boot()
1065 sbi->used.bitmap.nbits = clusters; in ntfs_init_from_boot()
1069 err = -ENOMEM; in ntfs_init_from_boot()
1073 sbi->new_rec = rec; in ntfs_init_from_boot()
1074 rec->rhdr.sign = NTFS_FILE_SIGNATURE; in ntfs_init_from_boot()
1075 rec->rhdr.fix_off = cpu_to_le16(MFTRECORD_FIXUP_OFFSET); in ntfs_init_from_boot()
1076 fn = (sbi->record_size >> SECTOR_SHIFT) + 1; in ntfs_init_from_boot()
1077 rec->rhdr.fix_num = cpu_to_le16(fn); in ntfs_init_from_boot()
1078 ao = ALIGN(MFTRECORD_FIXUP_OFFSET + sizeof(short) * fn, 8); in ntfs_init_from_boot()
1079 rec->attr_off = cpu_to_le16(ao); in ntfs_init_from_boot()
1080 rec->used = cpu_to_le32(ao + ALIGN(sizeof(enum ATTR_TYPE), 8)); in ntfs_init_from_boot()
1081 rec->total = cpu_to_le32(sbi->record_size); in ntfs_init_from_boot()
1082 ((struct ATTRIB *)Add2Ptr(rec, ao))->type = ATTR_END; in ntfs_init_from_boot()
1084 sb_set_blocksize(sb, min_t(u32, sbi->cluster_size, PAGE_SIZE)); in ntfs_init_from_boot()
1086 sbi->block_mask = sb->s_blocksize - 1; in ntfs_init_from_boot()
1087 sbi->blocks_per_cluster = sbi->cluster_size >> sb->s_blocksize_bits; in ntfs_init_from_boot()
1088 sbi->volume.blocks = sbi->volume.size >> sb->s_blocksize_bits; in ntfs_init_from_boot()
1091 sbi->maxbytes = (clusters << cluster_bits) - 1; in ntfs_init_from_boot()
1094 if (clusters >= (1ull << (64 - cluster_bits))) in ntfs_init_from_boot()
1095 sbi->maxbytes = -1; in ntfs_init_from_boot()
1096 sbi->maxbytes_sparse = -1; in ntfs_init_from_boot()
1097 sb->s_maxbytes = MAX_LFS_FILESIZE; in ntfs_init_from_boot()
1100 sbi->maxbytes_sparse = (1ull << (cluster_bits + 32)) - 1; in ntfs_init_from_boot()
1101 sb->s_maxbytes = 0xFFFFFFFFull << cluster_bits; in ntfs_init_from_boot()
1109 sbi->zone_max = min_t(CLST, 0x20000000 >> cluster_bits, clusters >> 3); in ntfs_init_from_boot()
1113 if (bh->b_blocknr && !sb_rdonly(sb)) { in ntfs_init_from_boot()
1125 if (err == -EINVAL && !boot_block && dev_size0 > PAGE_SHIFT) { in ntfs_init_from_boot()
1127 u64 lbo = dev_size0 - sizeof(*boot); in ntfs_init_from_boot()
1130 boot_off = lbo & (block_size - 1); in ntfs_init_from_boot()
1146 * ntfs_fill_super - Try to mount.
1151 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_fill_super()
1152 struct block_device *bdev = sb->s_bdev; in ntfs_fill_super()
1169 sbi->sb = sb; in ntfs_fill_super()
1170 sbi->options = options = fc->fs_private; in ntfs_fill_super()
1171 fc->fs_private = NULL; in ntfs_fill_super()
1172 sb->s_flags |= SB_NODIRATIME; in ntfs_fill_super()
1173 sb->s_magic = 0x7366746e; // "ntfs" in ntfs_fill_super()
1174 sb->s_op = &ntfs_sops; in ntfs_fill_super()
1175 sb->s_export_op = &ntfs_export_ops; in ntfs_fill_super()
1176 sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec in ntfs_fill_super()
1177 sb->s_xattr = ntfs_xattr_handlers; in ntfs_fill_super()
1178 sb->s_d_op = options->nocase ? &ntfs_dentry_ops : NULL; in ntfs_fill_super()
1180 options->nls = ntfs_load_nls(options->nls_name); in ntfs_fill_super()
1181 if (IS_ERR(options->nls)) { in ntfs_fill_super()
1182 options->nls = NULL; in ntfs_fill_super()
1183 errorf(fc, "Cannot load nls %s", options->nls_name); in ntfs_fill_super()
1184 err = -EINVAL; in ntfs_fill_super()
1189 sbi->discard_granularity = bdev_discard_granularity(bdev); in ntfs_fill_super()
1190 sbi->discard_granularity_mask_inv = in ntfs_fill_super()
1191 ~(u64)(sbi->discard_granularity - 1); in ntfs_fill_super()
1202 * 'cause 'sbi->volume.ni' is used 'ntfs_set_state'. in ntfs_fill_super()
1220 } else if (!attr->non_res && !is_attr_ext(attr)) { in ntfs_fill_super()
1223 le32_to_cpu(attr->res.data_size) >> 1, in ntfs_fill_super()
1224 UTF16_LITTLE_ENDIAN, sbi->volume.label, in ntfs_fill_super()
1225 sizeof(sbi->volume.label)); in ntfs_fill_super()
1227 sbi->volume.label[0] = 0; in ntfs_fill_super()
1230 //err = -EINVAL; in ntfs_fill_super()
1238 err = -EINVAL; in ntfs_fill_super()
1242 sbi->volume.major_ver = info->major_ver; in ntfs_fill_super()
1243 sbi->volume.minor_ver = info->minor_ver; in ntfs_fill_super()
1244 sbi->volume.flags = info->flags; in ntfs_fill_super()
1245 sbi->volume.ni = ni; in ntfs_fill_super()
1246 if (info->flags & VOLUME_FLAG_DIRTY) { in ntfs_fill_super()
1247 sbi->volume.real_dirty = true; in ntfs_fill_super()
1261 sbi->mft.recs_mirr = ntfs_up_cluster(sbi, inode->i_size) >> in ntfs_fill_super()
1262 sbi->record_bits; in ntfs_fill_super()
1284 if ((sbi->flags & NTFS_FLAGS_NEED_REPLAY) && !ro) { in ntfs_fill_super()
1286 err = -EINVAL; in ntfs_fill_super()
1290 if ((sbi->volume.flags & VOLUME_FLAG_DIRTY) && !ro && !options->force) { in ntfs_fill_super()
1292 err = -EINVAL; in ntfs_fill_super()
1309 sbi->mft.used = ni->i_valid >> sbi->record_bits; in ntfs_fill_super()
1310 tt = inode->i_size >> sbi->record_bits; in ntfs_fill_super()
1311 sbi->mft.next_free = MFT_REC_USER; in ntfs_fill_super()
1313 err = wnd_init(&sbi->mft.bitmap, sb, tt); in ntfs_fill_super()
1323 sbi->mft.ni = ni; in ntfs_fill_super()
1336 if (inode->i_size >> 32) { in ntfs_fill_super()
1337 err = -EINVAL; in ntfs_fill_super()
1343 tt = sbi->used.bitmap.nbits; in ntfs_fill_super()
1344 if (inode->i_size < bitmap_size(tt)) { in ntfs_fill_super()
1346 err = -EINVAL; in ntfs_fill_super()
1350 err = wnd_init(&sbi->used.bitmap, sb, tt); in ntfs_fill_super()
1377 for (i = 0; run_get_entry(&ni->file.run, i, &vcn, &lcn, &len); i++) { in ntfs_fill_super()
1386 if (wnd_set_used_safe(&sbi->used.bitmap, lcn, len, &tt) || tt) { in ntfs_fill_super()
1417 if (inode->i_size < sizeof(struct ATTR_DEF_ENTRY) || in ntfs_fill_super()
1418 inode->i_size > 100 * sizeof(struct ATTR_DEF_ENTRY)) { in ntfs_fill_super()
1420 inode->i_size); in ntfs_fill_super()
1421 err = -EINVAL; in ntfs_fill_super()
1425 bytes = inode->i_size; in ntfs_fill_super()
1426 sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL); in ntfs_fill_super()
1428 err = -ENOMEM; in ntfs_fill_super()
1433 unsigned long tail = bytes - done; in ntfs_fill_super()
1434 struct page *page = ntfs_map_page(inode->i_mapping, idx); in ntfs_fill_super()
1445 if (!idx && ATTR_STD != t->type) { in ntfs_fill_super()
1447 err = -EINVAL; in ntfs_fill_super()
1453 sbi->def_entries = 1; in ntfs_fill_super()
1455 sbi->reparse.max_size = MAXIMUM_REPARSE_DATA_BUFFER_SIZE; in ntfs_fill_super()
1456 sbi->ea_max_size = 0x10000; /* default formatter value */ in ntfs_fill_super()
1459 u32 t32 = le32_to_cpu(t->type); in ntfs_fill_super()
1460 u64 sz = le64_to_cpu(t->max_sz); in ntfs_fill_super()
1462 if ((t32 & 0xF) || le32_to_cpu(t[-1].type) >= t32) in ntfs_fill_super()
1465 if (t->type == ATTR_REPARSE) in ntfs_fill_super()
1466 sbi->reparse.max_size = sz; in ntfs_fill_super()
1467 else if (t->type == ATTR_EA) in ntfs_fill_super()
1468 sbi->ea_max_size = sz; in ntfs_fill_super()
1472 sbi->def_entries += 1; in ntfs_fill_super()
1486 if (inode->i_size != 0x10000 * sizeof(short)) { in ntfs_fill_super()
1487 err = -EINVAL; in ntfs_fill_super()
1494 u16 *dst = Add2Ptr(sbi->upcase, idx << PAGE_SHIFT); in ntfs_fill_super()
1495 struct page *page = ntfs_map_page(inode->i_mapping, idx); in ntfs_fill_super()
1514 shared = ntfs_set_shared(sbi->upcase, 0x10000 * sizeof(short)); in ntfs_fill_super()
1515 if (shared && sbi->upcase != shared) { in ntfs_fill_super()
1516 kvfree(sbi->upcase); in ntfs_fill_super()
1517 sbi->upcase = shared; in ntfs_fill_super()
1523 /* Load $Secure. */ in ntfs_fill_super()
1526 ntfs_err(sb, "Failed to initialize $Secure (%d).", err); in ntfs_fill_super()
1566 if (!inode->i_op) { in ntfs_fill_super()
1567 err = -EINVAL; in ntfs_fill_super()
1572 sb->s_root = d_make_root(inode); in ntfs_fill_super()
1573 if (!sb->s_root) { in ntfs_fill_super()
1574 err = -ENOMEM; in ntfs_fill_super()
1589 memcpy(bh0->b_data, boot2, sizeof(*boot2)); in ntfs_fill_super()
1604 struct proc_dir_entry *e = proc_mkdir(sb->s_id, proc_info_root); in ntfs_fill_super()
1611 sbi->procdir = e; in ntfs_fill_super()
1629 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs_unmap_meta()
1630 struct block_device *bdev = sb->s_bdev; in ntfs_unmap_meta()
1631 sector_t devblock = (u64)lcn * sbi->blocks_per_cluster; in ntfs_unmap_meta()
1632 unsigned long blocks = (u64)len * sbi->blocks_per_cluster; in ntfs_unmap_meta()
1635 << (PAGE_SHIFT - sb->s_blocksize_bits); in ntfs_unmap_meta()
1638 limit -= 0x1000; in ntfs_unmap_meta()
1644 while (blocks--) { in ntfs_unmap_meta()
1654 * ntfs_discard - Issue a discard request (trim for SSD).
1662 if (sbi->used.next_free_lcn == lcn + len) in ntfs_discard()
1663 sbi->used.next_free_lcn = lcn; in ntfs_discard()
1665 if (sbi->flags & NTFS_FLAGS_NODISCARD) in ntfs_discard()
1666 return -EOPNOTSUPP; in ntfs_discard()
1668 if (!sbi->options->discard) in ntfs_discard()
1669 return -EOPNOTSUPP; in ntfs_discard()
1671 lbo = (u64)lcn << sbi->cluster_bits; in ntfs_discard()
1672 bytes = (u64)len << sbi->cluster_bits; in ntfs_discard()
1675 start = (lbo + sbi->discard_granularity - 1) & in ntfs_discard()
1676 sbi->discard_granularity_mask_inv; in ntfs_discard()
1678 end = (lbo + bytes) & sbi->discard_granularity_mask_inv; in ntfs_discard()
1680 sb = sbi->sb; in ntfs_discard()
1684 err = blkdev_issue_discard(sb->s_bdev, start >> 9, (end - start) >> 9, in ntfs_discard()
1687 if (err == -EOPNOTSUPP) in ntfs_discard()
1688 sbi->flags |= NTFS_FLAGS_NODISCARD; in ntfs_discard()
1699 * ntfs_fs_free - Free fs_context.
1706 struct ntfs_mount_options *opts = fc->fs_private; in ntfs_fs_free()
1707 struct ntfs_sb_info *sbi = fc->s_fs_info; in ntfs_fs_free()
1718 // clang-format off
1725 // clang-format on
1728 * ntfs_init_fs_context - Initialize sbi and opts
1740 return -ENOMEM; in ntfs_init_fs_context()
1743 opts->fs_uid = current_uid(); in ntfs_init_fs_context()
1744 opts->fs_gid = current_gid(); in ntfs_init_fs_context()
1745 opts->fs_fmask_inv = ~current_umask(); in ntfs_init_fs_context()
1746 opts->fs_dmask_inv = ~current_umask(); in ntfs_init_fs_context()
1748 if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) in ntfs_init_fs_context()
1755 sbi->upcase = kvmalloc(0x10000 * sizeof(short), GFP_KERNEL); in ntfs_init_fs_context()
1756 if (!sbi->upcase) in ntfs_init_fs_context()
1759 ratelimit_state_init(&sbi->msg_ratelimit, DEFAULT_RATELIMIT_INTERVAL, in ntfs_init_fs_context()
1762 mutex_init(&sbi->compress.mtx_lznt); in ntfs_init_fs_context()
1764 mutex_init(&sbi->compress.mtx_xpress); in ntfs_init_fs_context()
1765 mutex_init(&sbi->compress.mtx_lzx); in ntfs_init_fs_context()
1768 fc->s_fs_info = sbi; in ntfs_init_fs_context()
1770 fc->fs_private = opts; in ntfs_init_fs_context()
1771 fc->ops = &ntfs_context_ops; in ntfs_init_fs_context()
1778 return -ENOMEM; in ntfs_init_fs_context()
1783 struct ntfs_sb_info *sbi = sb->s_fs_info; in ntfs3_kill_sb()
1787 if (sbi->options) in ntfs3_kill_sb()
1788 put_mount_options(sbi->options); in ntfs3_kill_sb()
1792 // clang-format off
1801 // clang-format on
1815 pr_info("ntfs3: Read-only LZX/Xpress compression included\n"); in init_ntfs_fs()
1831 err = -ENOMEM; in init_ntfs_fs()
1871 MODULE_INFO(compression, "Read-only lzx/xpress compression included");