Lines Matching refs:vol

234  * @vol:	ntfs_volume of device to read the boot sector from
257 static errno_t ntfs_boot_sector_read(ntfs_volume *vol, kauth_cred_t cred,
260 daddr64_t nr_blocks = vol->nr_blocks;
263 mount_t mp = vol->mp;
264 vnode_t dev_vn = vol->dev_vn;
294 if (!(vol->on_errors & ON_ERRORS_RECOVER)) {
367 if (bs1 && !NVolReadOnly(vol)) {
397 * ntfs_boot_sector_parse - parse the boot sector and store the data in @vol
398 * @vol: volume structure to initialise with data from boot sector
402 * the ntfs_volume @vol.
409 static errno_t ntfs_boot_sector_parse(ntfs_volume *vol,
413 mount_t mp = vol->mp;
418 vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector);
419 vol->sector_size_mask = vol->sector_size - 1;
420 vol->sector_size_shift = ffs(vol->sector_size) - 1;
421 ntfs_debug("vol->sector_size = %u (0x%x)", vol->sector_size,
422 vol->sector_size);
423 ntfs_debug("vol->sector_size_shift = %u", vol->sector_size_shift);
424 if (vol->sector_size < (u32)vfs_devblocksize(mp)) {
427 "Sorry.", vol->sector_size,
436 vol->cluster_size = vol->sector_size << sectors_per_cluster_shift;
437 vol->cluster_size_mask = vol->cluster_size - 1;
438 vol->cluster_size_shift = ffs(vol->cluster_size) - 1;
439 ntfs_debug("vol->cluster_size = %u (0x%x)", vol->cluster_size,
440 vol->cluster_size);
441 ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask);
442 ntfs_debug("vol->cluster_size_shift = %u", vol->cluster_size_shift);
443 if (vol->cluster_size < vol->sector_size) {
446 vol->cluster_size, vol->sector_size);
453 vol->mft_record_size = vol->cluster_size *
461 vol->mft_record_size = 1 << -clusters_per_mft_record;
462 vol->mft_record_size_mask = vol->mft_record_size - 1;
463 vol->mft_record_size_shift = ffs(vol->mft_record_size) - 1;
464 ntfs_debug("vol->mft_record_size = %u (0x%x)", vol->mft_record_size,
465 vol->mft_record_size);
466 ntfs_debug("vol->mft_record_size_mask = 0x%x",
467 vol->mft_record_size_mask);
468 ntfs_debug("vol->mft_record_size_shift = %u)",
469 vol->mft_record_size_shift);
475 if (vol->mft_record_size > PAGE_SIZE) {
478 "Sorry.", vol->mft_record_size, PAGE_SIZE);
482 if (vol->mft_record_size < vol->sector_size) {
485 "Sorry.", vol->mft_record_size,
486 vol->sector_size);
493 vol->index_block_size = vol->cluster_size *
495 vol->blocks_per_index_block = clusters_per_index_block;
503 vol->index_block_size = 1 << -clusters_per_index_block;
504 vol->blocks_per_index_block = vol->index_block_size /
505 vol->sector_size;
507 vol->index_block_size_mask = vol->index_block_size - 1;
508 vol->index_block_size_shift = ffs(vol->index_block_size) - 1;
509 ntfs_debug("vol->index_block_size = %u (0x%x)",
510 vol->index_block_size, vol->index_block_size);
511 ntfs_debug("vol->index_block_size_mask = 0x%x",
512 vol->index_block_size_mask);
513 ntfs_debug("vol->index_block_size_shift = %u",
514 vol->index_block_size_shift);
515 ntfs_debug("vol->blocks_per_index_block = %u",
516 vol->blocks_per_index_block);
518 if (vol->index_block_size < vol->sector_size) {
521 "Sorry.", vol->index_block_size,
522 vol->sector_size);
539 vol->nr_clusters = ll;
540 ntfs_debug("vol->nr_clusters = 0x%llx",
541 (unsigned long long)vol->nr_clusters);
543 if (ll >= vol->nr_clusters) {
549 vol->mft_lcn = ll;
550 ntfs_debug("vol->mft_lcn = 0x%llx", (unsigned long long)vol->mft_lcn);
552 if (ll >= vol->nr_clusters) {
558 vol->mftmirr_lcn = ll;
559 ntfs_debug("vol->mftmirr_lcn = 0x%llx",
560 (unsigned long long)vol->mftmirr_lcn);
573 if (vol->cluster_size <= ((u32)4 << vol->mft_record_size_shift))
574 vol->mftmirr_size = 4;
576 vol->mftmirr_size = vol->cluster_size >>
577 vol->mft_record_size_shift;
579 vol->mftmirr_size = 4;
581 ntfs_debug("vol->mftmirr_size = 0x%x", vol->mftmirr_size);
582 vol->serial_no = le64_to_cpu(b->volume_serial_number);
583 ntfs_debug("vol->serial_no = 0x%llx",
584 (unsigned long long)vol->serial_no);
591 * @vol: volume structure for which to setup the allocators
595 static void ntfs_setup_allocators(ntfs_volume *vol)
600 ntfs_debug("vol->mft_zone_multiplier = 0x%x",
601 vol->mft_zone_multiplier);
603 mft_zone_size = vol->nr_clusters;
604 switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */
621 vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn;
622 ntfs_debug("vol->mft_zone_pos = 0x%llx",
623 (unsigned long long)vol->mft_zone_pos);
633 mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size;
634 if (mft_lcn * vol->cluster_size < 16 * 1024)
635 mft_lcn = (16 * 1024 + vol->cluster_size - 1) /
636 vol->cluster_size;
637 if (vol->mft_zone_start <= mft_lcn)
638 vol->mft_zone_start = 0;
639 ntfs_debug("vol->mft_zone_start = 0x%llx",
640 (unsigned long long)vol->mft_zone_start);
646 vol->mft_zone_end = vol->mft_lcn + mft_zone_size;
647 while (vol->mft_zone_end >= vol->nr_clusters) {
649 vol->mft_zone_end = vol->mft_lcn + mft_zone_size;
651 ntfs_debug("vol->mft_zone_end = 0x%llx",
652 (unsigned long long)vol->mft_zone_end);
657 vol->data1_zone_pos = vol->mft_zone_end;
658 ntfs_debug("vol->data1_zone_pos = 0x%llx",
659 (unsigned long long)vol->data1_zone_pos);
660 vol->data2_zone_pos = 0;
661 ntfs_debug("vol->data2_zone_pos = 0x%llx",
662 (unsigned long long)vol->data2_zone_pos);
665 vol->mft_data_pos = 24;
666 ntfs_debug("vol->mft_data_pos = 0x%llx",
667 (unsigned long long)vol->mft_data_pos);
673 * @vol: ntfs volume being mounted
687 static errno_t ntfs_mft_inode_get(ntfs_volume *vol)
693 vnode_t dev_vn = vol->dev_vn;
699 const int block_size = vol->sector_size;
703 const u8 block_size_shift = vol->sector_size_shift;
711 ni = ntfs_inode_hash_get(vol, &na);
713 ntfs_error(vol->mp, "Failed to allocate new inode.");
717 ntfs_error(vol->mp, "Failed (found stale inode in cache).");
729 ni->block_size = vol->mft_record_size;
730 ni->block_size_shift = vol->mft_record_size_shift;
736 m = OSMalloc(vol->mft_record_size, ntfs_malloc_tag);
738 ntfs_error(vol->mp, "Failed to allocate buffer for $MFT "
744 block = vol->mft_lcn << (vol->cluster_size_shift - block_size_shift);
745 nr_blocks = vol->mft_record_size >> block_size_shift;
761 ntfs_error(vol->mp, "Failed to read $MFT record 0 "
770 ntfs_error(vol->mp, "Failed to map buffer of mft "
780 ntfs_error(vol->mp, "Failed to unmap buffer of mft "
785 err = ntfs_mst_fixup_post_read((NTFS_RECORD*)m, vol->mft_record_size);
788 ntfs_error(vol->mp, "MST fixup failed.%s", es);
820 ntfs_error(vol->mp, "Standard information "
823 ntfs_error(vol->mp, "Failed to lookup "
828 ntfs_error(vol->mp, "Standard information attribute "
840 vol->mft_record_size)
856 ntfs_error(vol->mp, "Failed to lookup attribute list "
869 ntfs_error(vol->mp, "Attribute list attribute is "
875 ntfs_error(vol->mp, "Non-resident attribute "
880 ntfs_warning(vol->mp, "Resident attribute list "
895 ntfs_error(vol->mp, "Not enough memory to allocate "
903 ntfs_error(vol->mp, "Attribute list has non-"
908 err = ntfs_mapping_pairs_decompress(vol, a,
911 ntfs_error(vol->mp, "Mapping pairs "
917 err = ntfs_rl_read(vol, &ni->attr_list_rl,
921 ntfs_error(vol->mp, "Failed to load attribute "
931 vol->mft_record_size) {
932 ntfs_error(vol->mp, "Corrupt attribute list "
984 ntfs_error(vol->mp, "BUG: The first $DATA "
1008 ntfs_error(vol->mp, "$MFT must be non-resident but a "
1016 ntfs_error(vol->mp, "$MFT must be uncompressed, "
1028 err = ntfs_mapping_pairs_decompress(vol, a, &ni->rl);
1030 ntfs_error(vol->mp, "Mapping pairs decompression "
1043 ntfs_error(vol->mp, "First extent of $DATA "
1050 >> vol->cluster_size_shift;
1065 if (ni->allocated_size & vol->cluster_size_mask ||
1067 vol->mft_record_size_mask ||
1069 vol->mft_record_size_mask) {
1070 ntfs_error(vol->mp, "$DATA attribute contains "
1078 if (ni->data_size >> vol->mft_record_size_shift >=
1080 ntfs_error(vol->mp, "$MFT is too big. "
1087 ntfs_error(vol->mp, "Failed to create a "
1098 * extent mft records which requires vol->mft_ni to be
1103 ntfs_error(vol->mp, "vnode_ref() failed!");
1105 vol->mft_ni = ni;
1120 ntfs_error(vol->mp, "Invalid highest vcn in attribute "
1126 ntfs_error(vol->mp, "Corrupt attribute extent would "
1132 ntfs_error(vol->mp, "Failed to lookup $MFT/$DATA attribute "
1137 ntfs_error(vol->mp, "$MFT/$DATA attribute not found.%s", es);
1142 ntfs_error(vol->mp, "Failed to load the complete runlist for "
1151 OSFree(m, vol->mft_record_size, ntfs_malloc_tag);
1155 ntfs_error(vol->mp, "Could not find first extent of $DATA attribute "
1163 OSFree(m, vol->mft_record_size, ntfs_malloc_tag);
1164 /* vol->mft_ni will be cleaned up by the caller. */
1165 if (!vol->mft_ni)
1172 * @vol: ntfs volume to which the inode to load belongs
1177 * Load the ntfs inode @mft_no from the mounted ntfs volume @vol, attach it by
1188 static errno_t ntfs_inode_attach(ntfs_volume *vol, const ino64_t mft_no,
1195 err = ntfs_inode_get(vol, mft_no, TRUE, LCK_RW_TYPE_SHARED, ni,
1198 ntfs_error(vol->mp, "Failed to load inode 0x%llx.",
1212 ntfs_error(vol->mp, "vnode_ref() failed!");
1251 ntfs_error(base_ni->vol->mp, "Failed to load attribute inode "
1268 ntfs_error(base_ni->vol->mp, "vnode_ref() failed!");
1304 ntfs_error(base_ni->vol->mp, "Failed to load index inode "
1320 ntfs_error(base_ni->vol->mp, "vnode_ref() failed!");
1329 * @vol: ntfs volume describing device whose mft mirror to load
1333 static errno_t ntfs_mft_mirror_load(ntfs_volume *vol)
1340 err = ntfs_inode_get(vol, FILE_MFTMirr, TRUE, LCK_RW_TYPE_SHARED, &ni,
1341 vol->root_ni->vn, NULL);
1343 ntfs_error(vol->mp, "Failed to load inode 0x%llx.",
1364 ni->block_size = vol->mft_record_size;
1365 ni->block_size_shift = vol->mft_record_size_shift;
1374 if (ni->allocated_size & vol->cluster_size_mask ||
1375 ni->data_size & vol->mft_record_size_mask ||
1376 ni->initialized_size & vol->mft_record_size_mask) {
1377 ntfs_error(vol->mp, "$DATA attribute contains invalid size. "
1383 OSIncrementAtomic(&vol->root_ni->nr_refs);
1386 ntfs_error(vol->mp, "vnode_ref() failed!");
1390 vol->mftmirr_ni = ni;
1397 * @vol: ntfs volume describing device whose mft mirror to check
1405 static errno_t ntfs_mft_mirror_check(ntfs_volume *vol)
1415 if (!vol->mftmirr_size)
1416 panic("%s(): !vol->mftmirr_size\n", __FUNCTION__);
1417 nr_mirr_recs = vol->mftmirr_size;
1420 rec_size = vol->mft_record_size;
1422 alloc_size = nr_mirr_recs << vol->mft_record_size_shift;
1425 ntfs_error(vol->mp, "Failed to allocate temporary mft mirror "
1430 ni = vol->mftmirr_ni;
1433 ntfs_error(vol->mp, "Failed to get vnode for $MFTMirr.");
1441 ntfs_error(vol->mp, "Failed to read $MFTMirr record "
1447 ntfs_error(vol->mp, "Failed to map buffer of $MFTMirr "
1458 ntfs_error(vol->mp, "Failed to unmap buffer of "
1468 ntfs_error(vol->mp, "Incomplete multi sector "
1488 if (ni->rl.rl->lcn != vol->mftmirr_lcn ||
1489 ni->rl.rl->length < (((s64)vol->mftmirr_size <<
1490 vol->mft_record_size_shift) +
1491 vol->cluster_size_mask) >> vol->cluster_size_shift) {
1492 ntfs_error(vol->mp, "$MFTMirr location mismatch. Run "
1504 ni = vol->mft_ni;
1507 ntfs_error(vol->mp, "Failed to get vnode for $MFT.");
1518 ntfs_error(vol->mp, "Failed to read $MFT record %d "
1524 ntfs_error(vol->mp, "Failed to map buffer of $MFT "
1532 ntfs_error(vol->mp, "Incomplete multi sector "
1551 ntfs_error(vol->mp, "$MFT and $MFTMirr (record %d) do "
1559 ntfs_error(vol->mp, "Failed to unmap buffer of $MFT "
1574 ntfs_error(vol->mp, "Failed to unmap buffer of mft record %d "
1583 * @vol: ntfs volume whose upcase to load
1585 * Read the upcase table and setup @vol->upcase and @vol->upcase_len.
1589 static errno_t ntfs_upcase_load(ntfs_volume *vol)
1600 err = ntfs_inode_get(vol, FILE_UpCase, TRUE, LCK_RW_TYPE_SHARED, &ni,
1601 vol->root_ni->vn, NULL);
1619 vol->upcase = OSMalloc(data_size, ntfs_malloc_tag);
1620 if (!vol->upcase) {
1635 memcpy((u8*)vol->upcase + ofs, kaddr, u);
1641 vol->upcase_len = data_size >> NTFSCHAR_SIZE_SHIFT;
1652 if (max_size > vol->upcase_len)
1653 max_size = vol->upcase_len;
1655 if (vol->upcase[u] != ntfs_default_upcase[u])
1658 OSFree(vol->upcase, data_size, ntfs_malloc_tag);
1659 vol->upcase = ntfs_default_upcase;
1660 vol->upcase_len = ntfs_default_upcase_size >>
1673 if (vol->upcase) {
1674 OSFree(vol->upcase, data_size, ntfs_malloc_tag);
1675 vol->upcase = NULL;
1676 vol->upcase_len = 0;
1685 vol->upcase = ntfs_default_upcase;
1686 vol->upcase_len = ntfs_default_upcase_size >>
1689 ntfs_error(vol->mp, "Failed to load $UpCase from the volume "
1694 ntfs_error(vol->mp, "Failed to initialize upcase table.");
1701 * @vol: ntfs volume whose attrdef to load
1703 * Read the attribute definitions table and setup @vol->attrdef and
1704 * @vol->attrdef_size.
1708 static errno_t ntfs_attrdef_load(ntfs_volume *vol)
1719 err = ntfs_inode_get(vol, FILE_AttrDef, TRUE, LCK_RW_TYPE_SHARED, &ni,
1720 vol->root_ni->vn, NULL);
1736 vol->attrdef = OSMalloc(data_size, ntfs_malloc_tag);
1737 if (!vol->attrdef) {
1752 memcpy((u8*)vol->attrdef + ofs, kaddr, u);
1758 vol->attrdef_size = data_size;
1763 if (vol->attrdef) {
1764 OSFree(vol->attrdef, data_size, ntfs_malloc_tag);
1765 vol->attrdef = NULL;
1772 ntfs_error(vol->mp, "Failed to initialize attribute definitions "
1779 * @vol: ntfs volume whose $Volume to load
1781 * Load the $Volume system file and setup the volume flags (@vol->flags), the
1782 * volume major and minor version (@vol->major_ver and @vol->minor_ver,
1783 * respectively), and the volume name converted to decomposed utf-8 (@vol->name
1784 * and @vol->name_size).
1788 static errno_t ntfs_volume_load(ntfs_volume *vol)
1798 err = ntfs_inode_attach(vol, FILE_Volume, &ni, vol->root_ni->vn);
1800 ntfs_error(vol->mp, "Failed to load $Volume.");
1803 vol->vol_ni = ni;
1806 ntfs_error(vol->mp, "Failed to get vnode for $Volume.");
1811 ntfs_error(vol->mp, "Failed to map mft record for $Volume.");
1816 ntfs_error(vol->mp, "Failed to get attribute search context "
1826 ntfs_error(vol->mp, "Failed to lookup volume "
1830 ntfs_error(vol->mp, "Volume information attribute in "
1840 vol->mft_record_size)
1843 vol->vol_flags = vi->flags;
1844 vol->major_ver = vi->major_ver;
1845 vol->minor_ver = vi->minor_ver;
1852 vol->name = OSMalloc(sizeof(char), ntfs_malloc_tag);
1853 if (!vol->name) {
1854 ntfs_error(vol->mp, "Failed to allocate memory for "
1859 vol->name[0] = '\0';
1869 ntfs_error(vol->mp, "Failed to lookup volume "
1873 ntfs_error(vol->mp, "Volume name attribute in "
1894 vol->mft_record_size)
1898 res_size = ntfs_to_utf8(vol, ntfs_name, ntfs_size, &utf8_name,
1902 ntfs_error(vol->mp, "Failed to convert volume name to "
1907 vol->name = (char*)utf8_name;
1908 vol->name_size = utf8_size;
1929 bcopy(&guid, vol->uuid, sizeof(guid));
1930 NVolSetHasGUID(vol);
1949 * @vol: ntfs volume to check
1952 * Check if Windows is hibernated on the ntfs volume @vol. This is done by
1977 static errno_t ntfs_windows_hibernation_status_check(ntfs_volume *vol,
2002 lck_rw_lock_shared(&vol->root_ni->lock);
2003 err = ntfs_lookup_inode_by_name(vol->root_ni, hiberfil, 12, &mref,
2005 lck_rw_unlock_shared(&vol->root_ni->lock);
2014 ntfs_error(vol->mp, "Failed to find inode number for "
2022 err = ntfs_inode_get(vol, MREF(mref), FALSE, LCK_RW_TYPE_SHARED, &ni,
2023 vol->root_ni->vn, NULL);
2025 ntfs_error(vol->mp, "Failed to load hiberfil.sys.");
2041 ntfs_error(vol->mp, "Failed to read from hiberfil.sys.");
2079 * @vol: ntfs volume on which to modify the flags
2085 * Replace the volume information flags on the volume @vol with the value
2092 static errno_t ntfs_volume_flags_write(ntfs_volume *vol,
2102 le16_to_cpu(vol->vol_flags), le16_to_cpu(flags));
2103 if (vol->vol_flags == flags)
2105 ni = vol->vol_ni;
2122 vol->vol_flags = vi->flags = flags;
2135 ntfs_error(vol->mp, "Failed with error code %d.", err);
2141 * @vol: ntfs volume on which to modify the flags
2144 * Set the bits in @flags in the volume information flags on the volume @vol.
2148 static inline errno_t ntfs_volume_flags_set(ntfs_volume *vol,
2152 return ntfs_volume_flags_write(vol, vol->vol_flags | flags);
2157 * @vol: ntfs volume on which to modify the flags
2160 * Clear the bits in @flags in the volume information flags on the volume @vol.
2164 static inline errno_t ntfs_volume_flags_clear(ntfs_volume *vol,
2168 return ntfs_volume_flags_write(vol, vol->vol_flags & ~flags);
2173 * @vol: ntfs volume whose security file to load
2177 static errno_t ntfs_secure_load(ntfs_volume *vol)
2200 err = ntfs_inode_attach(vol, FILE_Secure, &ni, vol->root_ni->vn);
2202 ntfs_error(vol->mp, "Failed to load $Secure.");
2205 vol->secure_ni = ni;
2212 ntfs_error(vol->mp, "Failed to map mft record for $Secure.");
2219 NVolSetUseSDAttr(vol);
2224 ntfs_error(vol->mp, "Failed to allocate search context for "
2231 ntfs_error(vol->mp, "Failed to look up filename attribute in "
2239 Secure, 7, NVolCaseSensitive(vol), NULL, 0)) {
2247 err = ntfs_attr_inode_attach(vol->secure_ni, AT_DATA, SDS, 4,
2248 &vol->secure_sds_ni);
2250 ntfs_error(vol->mp, "Failed to load $Secure/$SDS data "
2255 err = ntfs_index_inode_attach(vol->secure_ni, SDH, 4,
2256 &vol->secure_sdh_ni);
2258 ntfs_error(vol->mp, "Failed to load $Secure/$SDH index "
2263 err = ntfs_index_inode_attach(vol->secure_ni, SII, 4,
2264 &vol->secure_sii_ni);
2266 ntfs_error(vol->mp, "Failed to load $Secure/$SII index "
2275 err = ntfs_next_security_id_init(vol, &vol->next_security_id);
2277 ntfs_error(vol->mp, "Failed to determine next security_id "
2298 NVolSetUseSDAttr(vol);
2305 * @vol: ntfs volume whose object id file to load
2308 * vol->objid_ni as NULL and return success.
2310 static errno_t ntfs_objid_load(ntfs_volume *vol)
2328 lck_rw_lock_shared(&vol->extend_ni->lock);
2329 err = ntfs_lookup_inode_by_name(vol->extend_ni, ObjId, 6, &mref,
2331 lck_rw_unlock_shared(&vol->extend_ni->lock);
2343 ntfs_error(vol->mp, "Failed to find inode number for $ObjId.");
2350 err = ntfs_inode_attach(vol, MREF(mref), &ni, vol->extend_ni->vn);
2352 ntfs_error(vol->mp, "Failed to load $ObjId.");
2355 vol->objid_ni = ni;
2357 err = ntfs_index_inode_attach(vol->objid_ni, O, 2, &vol->objid_o_ni);
2359 ntfs_error(vol->mp, "Failed to load $ObjId/$O index (error "
2369 * @vol: ntfs volume whose quota file to load
2372 * vol->quota_ni as NULL and return success.
2374 static errno_t ntfs_quota_load(ntfs_volume *vol)
2391 lck_rw_lock_shared(&vol->extend_ni->lock);
2392 err = ntfs_lookup_inode_by_name(vol->extend_ni, Quota, 6, &mref,
2394 lck_rw_unlock_shared(&vol->extend_ni->lock);
2407 NVolSetQuotaOutOfDate(vol);
2411 ntfs_error(vol->mp, "Failed to find inode number for $Quota.");
2418 err = ntfs_inode_attach(vol, MREF(mref), &vol->quota_ni,
2419 vol->extend_ni->vn);
2421 ntfs_error(vol->mp, "Failed to load $Quota.");
2425 err = ntfs_index_inode_attach(vol->quota_ni, Q, 2, &vol->quota_q_ni);
2427 ntfs_error(vol->mp, "Failed to load $Quota/$Q index (error "
2437 * @vol: ntfs volume whose usnjrnl file to load
2447 static errno_t ntfs_usnjrnl_load(ntfs_volume *vol)
2473 lck_rw_lock_shared(&vol->extend_ni->lock);
2474 err = ntfs_lookup_inode_by_name(vol->extend_ni, UsnJrnl, 8, &mref,
2476 lck_rw_unlock_shared(&vol->extend_ni->lock);
2490 NVolSetUsnJrnlStamped(vol);
2494 ntfs_error(vol->mp, "Failed to find inode number for "
2502 err = ntfs_inode_attach(vol, MREF(mref), &ni, vol->extend_ni->vn);
2504 ntfs_error(vol->mp, "Failed to load $UsnJrnl.");
2507 vol->usnjrnl_ni = ni;
2512 if (vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY) {
2519 err = ntfs_attr_inode_attach(vol->usnjrnl_ni, AT_DATA, Max, 4, &max_ni);
2521 ntfs_error(vol->mp, "Failed to load $UsnJrnl/$DATA/$Max "
2525 vol->usnjrnl_max_ni = max_ni;
2530 ntfs_error(vol->mp, "Found corrupt $UsnJrnl/$DATA/$Max "
2539 ntfs_error(vol->mp, "Failed to get vnode for "
2547 ntfs_error(vol->mp, "Failed to read from $UsnJrnl/$DATA/$Max "
2554 ntfs_error(vol->mp, "Allocation delta (0x%llx) exceeds "
2564 err = ntfs_attr_inode_attach(vol->usnjrnl_ni, AT_DATA, J, 2, &ni);
2566 ntfs_error(vol->mp, "Failed to load $UsnJrnl/$DATA/$J "
2570 vol->usnjrnl_j_ni = ni;
2573 ntfs_error(vol->mp, "$UsnJrnl/$DATA/$J attribute is resident "
2597 ntfs_error(vol->mp, "$UsnJrnl has lowest valid usn (0x%llx) "
2616 * @vol: ntfs volume being mounted
2629 static errno_t ntfs_system_inodes_get(ntfs_volume *vol)
2642 err = ntfs_inode_attach(vol, FILE_root, &root_ni, NULL);
2644 ntfs_error(vol->mp, "Failed to load root directory.");
2647 vol->root_ni = root_ni;
2655 vnode_update_identity(vol->mft_ni->vn, root_vn, NULL, 0, 0,
2662 err = ntfs_mft_mirror_load(vol);
2664 err = ntfs_mft_mirror_check(vol);
2671 es1 = !vol->mftmirr_ni ? es1a : es1b;
2673 if (!NVolReadOnly(vol)) {
2674 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
2675 ntfs_error(vol->mp, "%s%s", es1, es2);
2679 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2681 ntfs_error(vol->mp, "%s and neither on_errors="
2688 vfs_setflags(vol->mp, MNT_RDONLY);
2689 NVolSetReadOnly(vol);
2690 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
2693 ntfs_warning(vol->mp, "%s. Will not be able to "
2696 NVolSetErrors(vol);
2706 err = ntfs_attr_inode_attach(vol->mft_ni, AT_BITMAP, NULL, 0,
2707 &vol->mftbmp_ni);
2709 ntfs_error(vol->mp, "Failed to load $MFT/$BITMAP attribute.");
2712 NInoSetSparseDisabled(vol->mftbmp_ni);
2719 err = ntfs_attr_map_runlist(vol->mftbmp_ni);
2721 ntfs_error(vol->mp, "Failed to map runlist of $MFT/$BITMAP "
2725 /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */
2726 err = ntfs_upcase_load(vol);
2730 * Read attribute definitions table and setup @vol->attrdef and
2731 * @vol->attrdef_size.
2733 err = ntfs_attrdef_load(vol);
2737 err = ntfs_inode_attach(vol, FILE_Bitmap, &ni, root_vn);
2739 ntfs_error(vol->mp, "Failed to load $Bitmap.");
2743 vol->lcnbmp_ni = ni;
2747 if ((vol->nr_clusters + 7) >> 3 > size) {
2748 ntfs_error(vol->mp, "$Bitmap (%lld) is shorter than required "
2751 (long long)(vol->nr_clusters + 7) >> 3);
2763 ntfs_error(vol->mp, "Failed to map runlist of $Bitmap/$DATA "
2771 err = ntfs_volume_load(vol);
2774 printf("NTFS volume name %s, version %u.%u.\n", vol->name,
2775 (unsigned)vol->major_ver, (unsigned)vol->minor_ver);
2776 if (vol->major_ver < 3 && NVolSparseEnabled(vol)) {
2777 ntfs_warning(vol->mp, "Disabling sparse support due to NTFS "
2779 "version 3.0).", (unsigned)vol->major_ver,
2780 (unsigned)vol->minor_ver);
2781 NVolClearSparseEnabled(vol);
2783 if (vol->vol_flags & VOLUME_IS_DIRTY) {
2784 ntfs_warning(vol->mp, "NTFS volume is dirty. You should "
2786 NVolSetErrors(vol);
2789 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
2797 ntfs_warning(vol->mp, "Unsupported volume flags 0x%x "
2799 (unsigned)le16_to_cpu(vol->vol_flags));
2801 if (!NVolReadOnly(vol)) {
2802 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
2803 ntfs_error(vol->mp, "%s%s", es1, es2);
2807 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2809 ntfs_error(vol->mp, "%s and neither on_errors="
2816 vfs_setflags(vol->mp, MNT_RDONLY);
2817 NVolSetReadOnly(vol);
2818 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
2821 ntfs_warning(vol->mp, "%s. Will not be able to "
2832 err = ntfs_inode_attach(vol, FILE_LogFile, &ni, root_vn);
2837 vol->logfile_ni = ni;
2853 es1 = !vol->logfile_ni ? es1a : es1b;
2855 if (!NVolReadOnly(vol)) {
2856 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
2857 ntfs_error(vol->mp, "%s%s", es1, es2);
2861 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2863 ntfs_error(vol->mp, "%s and neither on_errors="
2869 vfs_setflags(vol->mp, MNT_RDONLY);
2870 NVolSetReadOnly(vol);
2871 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
2874 ntfs_warning(vol->mp, "%s. Will not be able to "
2876 NVolSetErrors(vol);
2885 err = ntfs_windows_hibernation_status_check(vol, &is_hibernated);
2895 if (!NVolReadOnly(vol)) {
2896 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
2897 ntfs_error(vol->mp, "%s%s", es1, es2);
2901 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2903 ntfs_error(vol->mp, "%s and neither on_errors="
2911 vfs_setflags(vol->mp, MNT_RDONLY);
2912 NVolSetReadOnly(vol);
2913 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
2916 ntfs_warning(vol->mp, "%s. Will not be able to "
2918 NVolSetErrors(vol);
2921 if (!NVolReadOnly(vol) &&
2922 (err = ntfs_volume_flags_set(vol, VOLUME_IS_DIRTY))) {
2928 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
2929 ntfs_error(vol->mp, "%s%s", es1, es2);
2933 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2935 ntfs_error(vol->mp, "%s and neither on_errors="
2940 vfs_setflags(vol->mp, MNT_RDONLY);
2941 NVolSetReadOnly(vol);
2942 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1, es2);
2949 if (!NVolReadOnly(vol) &&
2950 (err = ntfs_logfile_empty(vol->logfile_ni))) {
2954 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
2955 ntfs_error(vol->mp, "%s%s", es1, es2);
2960 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2962 ntfs_error(vol->mp, "%s and neither on_errors="
2967 vfs_setflags(vol->mp, MNT_RDONLY);
2968 NVolSetReadOnly(vol);
2969 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1, es2);
2970 NVolSetErrors(vol);
2973 if (vol->major_ver < 3) {
2978 NVolSetUseSDAttr(vol);
2987 err = ntfs_secure_load(vol);
2991 err = ntfs_inode_attach(vol, FILE_Extend, &vol->extend_ni, root_vn);
2993 ntfs_error(vol->mp, "Failed to load $Extend directory.");
2997 err = ntfs_objid_load(vol);
3003 if (!NVolReadOnly(vol)) {
3004 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
3005 ntfs_error(vol->mp, "%s%s", es1, es2);
3009 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
3011 ntfs_error(vol->mp, "%s and neither on_errors="
3017 vfs_setflags(vol->mp, MNT_RDONLY);
3018 NVolSetReadOnly(vol);
3019 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
3022 ntfs_warning(vol->mp, "%s. Will not be able to "
3024 NVolSetErrors(vol);
3027 err = ntfs_quota_load(vol);
3033 if (!NVolReadOnly(vol)) {
3034 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
3035 ntfs_error(vol->mp, "%s%s", es1, es2);
3039 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
3041 ntfs_error(vol->mp, "%s and neither on_errors="
3047 vfs_setflags(vol->mp, MNT_RDONLY);
3048 NVolSetReadOnly(vol);
3049 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
3052 ntfs_warning(vol->mp, "%s. Will not be able to "
3054 NVolSetErrors(vol);
3057 if (!NVolReadOnly(vol) && (err = ntfs_quotas_mark_out_of_date(vol))) {
3062 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
3063 ntfs_error(vol->mp, "%s%s", es1, es2);
3067 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
3069 ntfs_error(vol->mp, "%s and neither on_errors="
3074 vfs_setflags(vol->mp, MNT_RDONLY);
3075 NVolSetReadOnly(vol);
3076 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1, es2);
3077 NVolSetErrors(vol);
3083 err = ntfs_usnjrnl_load(vol);
3089 if (!NVolReadOnly(vol)) {
3090 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
3091 ntfs_error(vol->mp, "%s%s", es1, es2);
3095 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
3097 ntfs_error(vol->mp, "%s and neither on_errors="
3103 vfs_setflags(vol->mp, MNT_RDONLY);
3104 NVolSetReadOnly(vol);
3105 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1,
3108 ntfs_warning(vol->mp, "%s. Will not be able to "
3110 NVolSetErrors(vol);
3113 if (!NVolReadOnly(vol) && (err = ntfs_usnjrnl_stamp(vol))) {
3118 if (vol->on_errors & ON_ERRORS_FAIL_DIRTY) {
3119 ntfs_error(vol->mp, "%s%s", es1, es2);
3124 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
3126 ntfs_error(vol->mp, "%s and neither on_errors="
3131 vfs_setflags(vol->mp, MNT_RDONLY);
3132 NVolSetReadOnly(vol);
3133 ntfs_error(vol->mp, "%s. Mounting read-only%s", es1, es2);
3134 NVolSetErrors(vol);
3240 * @vol: ntfs volume for which to set the number of free clusters
3242 * Calculate the number of free clusters on the mounted ntfs volume @vol and
3243 * cache the result in the @vol->nr_free_clusters.
3258 static errno_t ntfs_set_nr_free_clusters(ntfs_volume *vol)
3264 lck_rw_lock_exclusive(&vol->lcnbmp_lock);
3265 err = ntfs_get_nr_set_bits(vol->lcnbmp_ni->vn, vol->nr_clusters,
3268 ntfs_error(vol->mp, "Failed to get vnode for $Bitmap.");
3269 lck_rw_unlock_exclusive(&vol->lcnbmp_lock);
3273 nr_free = vol->nr_clusters - nr_free;
3278 if (vol->nr_clusters & 63)
3279 nr_free += 64 - (vol->nr_clusters & 63);
3283 vol->nr_free_clusters = nr_free;
3285 (long long)vol->nr_clusters, (long long)nr_free);
3286 lck_rw_unlock_exclusive(&vol->lcnbmp_lock);
3292 * @vol: volume for which to set the number of total/free mft records
3295 * mft records on the mounted ntfs volume @vol and cache the results in
3296 * @vol->nr_mft_records and @vol->nr_free_mft_records, respectively.
3306 static errno_t ntfs_set_nr_mft_records(ntfs_volume *vol)
3316 lck_rw_lock_exclusive(&vol->mftbmp_lock);
3317 lck_spin_lock(&vol->mft_ni->size_lock);
3318 vol->nr_mft_records = vol->mft_ni->data_size >>
3319 vol->mft_record_size_shift;
3320 lck_spin_unlock(&vol->mft_ni->size_lock);
3321 err = ntfs_get_nr_set_bits(vol->mftbmp_ni->vn,
3322 vol->mft_ni->initialized_size >>
3323 vol->mft_record_size_shift, &nr_free);
3325 ntfs_error(vol->mp, "Failed to get vnode for $MFT/$BITMAP.");
3326 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
3330 nr_free = vol->nr_mft_records - nr_free;
3334 vol->nr_free_mft_records = nr_free;
3336 (long long)vol->nr_mft_records, (long long)nr_free);
3337 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
3343 * @vol: ntfs volume about which to return information
3346 * Return information about the mounted ntfs volume @vol in the vfsstatfs
3364 static void ntfs_statfs(ntfs_volume *vol, struct vfsstatfs *sfs)
3372 sfs->f_bsize = vol->cluster_size;
3376 sfs->f_blocks = (u64)vol->nr_clusters;
3378 sfs->f_bfree = (u64)vol->nr_free_clusters;
3386 * @vol->nr_free_clusters and return the result in @sfs->f_bavail
3390 sfs->f_bavail = (u64)vol->nr_free_clusters;
3392 sfs->f_bused = (u64)(vol->nr_clusters - vol->nr_free_clusters);
3394 sfs->f_files = (u64)vol->nr_mft_records;
3396 sfs->f_ffree = (u64)vol->nr_free_mft_records;
3403 sfs->f_fssubtype = (u32)vol->major_ver << 8 | vol->minor_ver;
3437 * inode *@pni from the mounted ntfs volume @vol by dropping the reference on
3465 * inode *@pni from the mounted ntfs volume @vol by dropping the reference on
3493 * @vol: ntfs volume to release
3495 * Release resources used by the ntfs volume @vol.
3498 * then it is called when the last inode is freed. This ensures the @vol
3501 void ntfs_do_postponed_release(ntfs_volume *vol)
3505 if (vol->upcase && vol->upcase == ntfs_default_upcase) {
3506 vol->upcase = NULL;
3517 if (NVolCompressionEnabled(vol)) {
3531 if (vol->attrdef)
3532 OSFree(vol->attrdef, vol->attrdef_size, ntfs_malloc_tag);
3534 if (vol->upcase)
3535 OSFree(vol->upcase, vol->upcase_len << NTFSCHAR_SIZE_SHIFT,
3538 if (vol->name)
3539 OSFree(vol->name, vol->name_size, ntfs_malloc_tag);
3541 lck_rw_destroy(&vol->mftbmp_lock, ntfs_lock_grp);
3542 lck_rw_destroy(&vol->lcnbmp_lock, ntfs_lock_grp);
3543 lck_mtx_destroy(&vol->rename_lock, ntfs_lock_grp);
3544 lck_rw_destroy(&vol->secure_lock, ntfs_lock_grp);
3545 lck_spin_destroy(&vol->security_id_lock, ntfs_lock_grp);
3546 lck_mtx_destroy(&vol->inodes_lock, ntfs_lock_grp);
3548 OSFree(vol, sizeof(ntfs_volume), ntfs_malloc_tag);
3574 ntfs_volume *vol;
3579 vol = NTFS_MP(mp);
3580 if (!vol)
3582 if (!vol->mft_ni) {
3593 if (!vol->root_ni)
3620 if (!NVolReadOnly(vol) && vol->vol_ni) {
3621 if (!NVolErrors(vol)) {
3622 if (ntfs_volume_flags_clear(vol, VOLUME_IS_DIRTY))
3631 if (vol->vol_ni && vol->major_ver >= 3) {
3632 ntfs_unmount_attr_inode_detach(&vol->usnjrnl_j_ni);
3633 ntfs_unmount_attr_inode_detach(&vol->usnjrnl_max_ni);
3634 ntfs_unmount_inode_detach(&vol->usnjrnl_ni, vol->extend_ni);
3635 ntfs_unmount_attr_inode_detach(&vol->quota_q_ni);
3636 ntfs_unmount_inode_detach(&vol->quota_ni, vol->extend_ni);
3637 ntfs_unmount_attr_inode_detach(&vol->objid_o_ni);
3638 ntfs_unmount_inode_detach(&vol->objid_ni, vol->extend_ni);
3639 ntfs_unmount_inode_detach(&vol->extend_ni, vol->root_ni);
3640 ntfs_unmount_attr_inode_detach(&vol->secure_sds_ni);
3641 ntfs_unmount_attr_inode_detach(&vol->secure_sdh_ni);
3642 ntfs_unmount_attr_inode_detach(&vol->secure_sii_ni);
3643 ntfs_unmount_inode_detach(&vol->secure_ni, vol->root_ni);
3645 ntfs_unmount_inode_detach(&vol->vol_ni, vol->root_ni);
3646 ntfs_unmount_inode_detach(&vol->lcnbmp_ni, vol->root_ni);
3647 ntfs_unmount_attr_inode_detach(&vol->mftbmp_ni);
3648 ntfs_unmount_inode_detach(&vol->logfile_ni, vol->root_ni);
3661 if (vol->mftmirr_ni && vol->mftmirr_ni->vn) {
3663 if (vol->root_ni)
3664 OSDecrementAtomic(&vol->root_ni->nr_refs);
3665 vnode_update_identity(vol->mftmirr_ni->vn, NULL, NULL, 0, 0,
3668 if (vol->mft_ni && vol->mft_ni->vn) {
3670 if (vol->root_ni)
3671 OSDecrementAtomic(&vol->root_ni->nr_refs);
3672 vnode_update_identity(vol->mft_ni->vn, NULL, NULL, 0, 0,
3681 ntfs_unmount_inode_detach(&vol->root_ni, NULL);
3689 ntfs_unmount_inode_detach(&vol->mftmirr_ni, NULL);
3691 if (vol->mft_ni) {
3692 if (vol->mft_ni->vn)
3693 ntfs_unmount_inode_detach(&vol->mft_ni, NULL);
3699 ntfs_inode_reclaim(vol->mft_ni);
3700 vol->mft_ni = NULL;
3722 vol->mp = NULL;
3725 lck_mtx_lock(&vol->inodes_lock);
3726 if (!LIST_EMPTY(&vol->inodes)) {
3727 NVolSetPostponedRelease(vol);
3728 lck_mtx_unlock(&vol->inodes_lock);
3732 lck_mtx_unlock(&vol->inodes_lock);
3733 ntfs_do_postponed_release(vol);
3738 lck_rw_destroy(&vol->mftbmp_lock, ntfs_lock_grp);
3739 lck_rw_destroy(&vol->lcnbmp_lock, ntfs_lock_grp);
3740 lck_mtx_destroy(&vol->rename_lock, ntfs_lock_grp);
3741 lck_rw_destroy(&vol->secure_lock, ntfs_lock_grp);
3742 lck_spin_destroy(&vol->security_id_lock, ntfs_lock_grp);
3743 lck_mtx_destroy(&vol->inodes_lock, ntfs_lock_grp);
3745 OSFree(vol, sizeof(ntfs_volume), ntfs_malloc_tag);
3784 ntfs_volume *vol = ni->vol;
3791 if (ni != vol->mft_ni && ni != vol->mftmirr_ni) {
3831 ntfs_error(ni->vol->mp, "Failed to get vnode for $MFT%s "
3833 (ni == ni->vol->mft_ni) ? "" : "Mirr",
3841 ntfs_error(ni->vol->mp, "Failed to sync $MFT%s (error %d).",
3842 (ni == ni->vol->mft_ni) ? "" : "Mirr",
3871 ntfs_volume *vol = NTFS_MP(mp);
3875 if (NVolReadOnly(vol))
3887 ntfs_sync_helper(vol->mftmirr_ni, &args, TRUE);
3888 ntfs_sync_helper(vol->mft_ni, &args, TRUE);
3889 ntfs_sync_helper(vol->mftmirr_ni, &args, FALSE);
3890 ntfs_sync_helper(vol->mft_ni, &args, FALSE);
3918 ntfs_volume *vol = NTFS_MP(mp);
3928 !NVolCaseSensitive(vol)) ||
3930 NVolCaseSensitive(vol))) {
3961 if (NVolErrors(vol)) {
3966 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
3969 (unsigned)le16_to_cpu(vol->vol_flags),
3973 if (ntfs_volume_flags_set(vol, VOLUME_IS_DIRTY)) {
3978 if (ntfs_logfile_empty(vol->logfile_ni)) {
3981 NVolSetErrors(vol);
3984 if (ntfs_quotas_mark_out_of_date(vol)) {
3987 NVolSetErrors(vol);
3990 if (ntfs_usnjrnl_stamp(vol)) {
3993 NVolSetErrors(vol);
3996 NVolClearReadOnly(vol);
3998 } else if (!NVolReadOnly(vol) && vfs_isrdonly(mp)) {
4007 if (!NVolErrors(vol)) {
4008 if (ntfs_volume_flags_clear(vol, VOLUME_IS_DIRTY))
4024 (void)ntfs_volume_flags_set(vol,
4031 NVolSetReadOnly(vol);
4036 // TODO: Copy mount options from @opts to @vol.
4069 ntfs_volume *vol;
4186 vol = OSMalloc(sizeof(ntfs_volume), ntfs_malloc_tag);
4187 if (!vol) {
4192 *vol = (ntfs_volume) {
4214 lck_rw_init(&vol->mftbmp_lock, ntfs_lock_grp, ntfs_lock_attr);
4215 lck_rw_init(&vol->lcnbmp_lock, ntfs_lock_grp, ntfs_lock_attr);
4216 lck_mtx_init(&vol->rename_lock, ntfs_lock_grp, ntfs_lock_attr);
4217 lck_rw_init(&vol->secure_lock, ntfs_lock_grp, ntfs_lock_attr);
4218 lck_spin_init(&vol->security_id_lock, ntfs_lock_grp, ntfs_lock_attr);
4219 lck_mtx_init(&vol->inodes_lock, ntfs_lock_grp, ntfs_lock_attr);
4220 vfs_setfsprivate(mp, vol);
4222 NVolSetReadOnly(vol);
4226 NVolSetCaseSensitive(vol);
4231 NVolSetSparseEnabled(vol);
4234 NVolSetCompressionEnabled(vol);
4272 vol->nr_blocks = nr_blocks;
4308 err = ntfs_boot_sector_read(vol, cred, &buf, &bs);
4317 err = ntfs_boot_sector_parse(vol, bs);
4337 * vol->sector_size* to the current blocksize or add vol->blocksize*...
4339 * to move to using vol->blocksize* instead of vol->sector_size in most
4340 * places and stick with vol->sector_size where we really want its
4343 if (vol->sector_size > blocksize) {
4345 err = ntfs_blocksize_set(mp, dev_vn, vol->sector_size, context);
4350 "error %d).", vol->sector_size, err);
4353 blocksize = vol->sector_size;
4356 ntfs_setup_allocators(vol);
4361 err = ntfs_mft_inode_get(vol);
4365 if (NVolCompressionEnabled(vol)) {
4370 if (vol->cluster_size <= 4096) {
4383 NVolClearCompressionEnabled(vol);
4393 (unsigned)vol->cluster_size);
4394 NVolClearCompressionEnabled(vol);
4421 err = ntfs_system_inodes_get(vol);
4443 * @vol->nr_free_clusters).
4445 err = ntfs_set_nr_free_clusters(vol);
4450 * them in the volume (in @vol->nr_mft_records and
4451 * @vol->nr_free_mft_records, respectively).
4453 err = ntfs_set_nr_mft_records(vol);
4460 ntfs_statfs(vol, sfs);
4499 ntfs_volume *vol = NTFS_MP(mp);
4504 if (!vol || !vol->root_ni || !vol->root_ni->vn)
4507 vn = vol->root_ni->vn;
4630 ntfs_volume *vol = NTFS_MP(mp);
4636 lck_rw_lock_shared(&vol->mftbmp_lock);
4637 lck_rw_lock_shared(&vol->lcnbmp_lock);
4638 nr_clusters = vol->nr_clusters;
4639 nr_free_clusters = vol->nr_free_clusters;
4640 lck_rw_unlock_shared(&vol->lcnbmp_lock);
4641 nr_free_mft_records = vol->nr_free_mft_records;
4642 nr_used_mft_records = vol->nr_mft_records - nr_free_mft_records;
4643 lck_rw_unlock_shared(&vol->mftbmp_lock);
4683 VFSATTR_RETURN(fsa, f_bsize, vol->cluster_size);
4705 nr_free_mft_records += (nr_free_clusters << vol->cluster_size_shift) >>
4706 vol->mft_record_size_shift;
4753 (NVolCaseSensitive(vol) ?
5065 ni = vol->root_ni;
5098 ntfs_error(vol->mp, "Failed to obtain AfpInfo "
5124 VFSATTR_RETURN(fsa, f_fssubtype, (u32)vol->major_ver << 8 |
5125 vol->minor_ver);
5129 (void)strlcpy(fsa->f_vol_name, vol->name, MAXPATHLEN - 1);
5147 if (VFSATTR_IS_ACTIVE(fsa, f_uuid) && NVolHasGUID(vol)) {
5148 bcopy(vol->uuid, fsa->f_uuid, sizeof(uuid_t));
5157 * @vol: ntfs volume to rename
5160 * Rename the ntfs volume @vol to @name which is a decomposed, NUL-terminated,
5165 static errno_t ntfs_volume_rename(ntfs_volume *vol, char *name)
5167 ntfs_inode *ni = vol->vol_ni;
5177 ntfs_debug("Entering (old name: %s, new name: %s).", vol->name, name);
5183 if (utf8_name_size == vol->name_size &&
5184 !strncmp(vol->name, name, vol->name_size)) {
5198 ntfs_name_len = utf8_to_ntfs(vol, (u8*)name, utf8_name_size,
5202 ntfs_error(vol->mp, "Failed to convert volume name to "
5213 err = ntfs_attr_size_bounds_check(vol, AT_VOLUME_NAME,
5217 ntfs_error(vol->mp, "Specified name is too "
5225 ntfs_error(vol->mp, "$VOLUME_NAME attribute "
5235 /* Make a copy of the new volume name to be placed in @vol->name. */
5238 ntfs_error(vol->mp, "Not enough memory to make a copy of the "
5247 ntfs_error(vol->mp, "Failed to get vnode for $Volume.");
5252 ntfs_error(vol->mp, "Failed to map mft record for $Volume "
5260 ntfs_error(vol->mp, "Not enough memory to get attribute "
5273 ntfs_error(vol->mp, "Failed to lookup volume name "
5289 ntfs_error(vol->mp, "Failed to %s $Volume (error %d).",
5301 (u8*)m + vol->mft_record_size)
5313 ntfs_warning(vol->mp, "Failed to delete volume name "
5332 ntfs_error(vol->mp, "Failed to %s "
5381 ntfs_error(vol->mp, "Failed to move volume "
5419 name = vol->name;
5420 ntfs_name_size = vol->name_size;
5421 if (utf8_name_size < vol->name_size)
5422 vol->name_size = utf8_name_size;
5423 vol->name = (char*)utf8_name;
5424 vol->name_size = utf8_name_size;
5432 ntfs_error(vol->mp, "Volume name attribute is corrupt. Run chkdsk.");
5433 NVolSetErrors(vol);