Lines Matching defs:vol

96 	ntfs_volume *vol;
107 vol = ni->vol;
108 mft_ni = vol->mft_ni;
110 * If the volume is in the process of being unmounted then @vol->mft_ni
115 * @vol->mp may be NULL now which is ok. ntfs_error() deals
118 ntfs_error(vol->mp, "The volume is being unmounted, bailing "
126 ntfs_error(vol->mp, "Failed to get vnode for $MFT.");
137 vol->mft_record_size_shift)) {
139 ntfs_error(vol->mp, "Attempt to read mft record 0x%llx, which "
161 err = buf_meta_bread(mft_ni->vn, ni->mft_no, vol->mft_record_size,
165 ntfs_error(vol->mp, "Failed to read buffer of mft record "
172 ntfs_error(vol->mp, "Failed to map buffer of mft record "
193 ntfs_error(vol->mp, "Mft record 0x%llx is corrupt. Run chkdsk.",
195 NVolSetErrors(vol);
199 ntfs_error(vol->mp, "Failed to unmap buffer of mft record "
240 ntfs_error(ni->vol->mp, "Failed to unmap buffer of mft record "
246 ntfs_error(ni->vol->mp, "Failed to write buffer of "
250 NVolSetErrors(ni->vol);
333 ntfs_error(base_ni->vol->mp, "Found stale extent mft "
339 ntfs_error(base_ni->vol->mp, "Failed to map extent mft "
360 ntfs_error(base_ni->vol->mp, "Found stale extent mft "
384 ntfs_error(base_ni->vol->mp, "Failed to allocate "
439 ntfs_volume *vol;
449 vol = ni->vol;
450 mft_ni = vol->mft_ni;
452 ntfs_warning(vol->mp, "$MFT inode is missing from volume.");
458 ntfs_error(vol->mp, "Failed to get vnode for $MFT.");
466 buf = buf_getblk(mft_ni->vn, ni->mft_no, vol->mft_record_size, 0, 0,
476 if (buf_size(buf) != vol->mft_record_size)
480 buf_size(buf), vol->mft_record_size);
494 ntfs_error(vol->mp, "Failed to write mft record 0x%llx (error "
501 * @vol: ntfs volume on which the mft record to synchronize resides
507 * @m to the mft mirror ($MFTMirr) of the ntfs volume @vol.
510 * in the ntfs volume @vol.
512 errno_t ntfs_mft_mirror_sync(ntfs_volume *vol, const s64 rec_no,
523 mirr_ni = vol->mftmirr_ni;
526 ntfs_error(vol->mp, "Umount time mft mirror syncing is not "
536 if (rec_no >= vol->mftmirr_size)
537 panic("%s(): rec_no >= vol->mftmirr_size\n", __FUNCTION__);
540 ntfs_error(vol->mp, "Failed to get vnode for mft mirror.");
548 if ((rec_no << vol->mft_record_size_shift) + vol->mft_record_size >
551 ntfs_error(vol->mp, "Write past the initialized size of mft "
563 buf = buf_getblk(mirr_vn, rec_no, vol->mft_record_size, 0, 0, BLK_META);
568 ntfs_error(vol->mp, "Failed to map buffer of mft mirror "
574 memcpy(mirr, m, vol->mft_record_size);
577 ntfs_error(vol->mp, "Failed to unmap buffer of mft mirror "
598 ntfs_error(vol->mp, "Failed to write buffer of mft mirror "
608 ntfs_error(vol->mp, "Failed to synchronize mft mirror (error "
611 NVolSetErrors(vol);
618 * @vol: volume on which to search for a free mft record
623 * @vol and return the allocated mft record number in *@mft_no.
633 * Locking: - Caller must hold @vol->mftbmp_lock for writing.
634 * - Caller must hold @vol->mftbmp_ni->lock.
636 static errno_t ntfs_mft_bitmap_find_and_alloc_free_rec_nolock(ntfs_volume *vol,
649 mftbmp_ni = vol->mftbmp_ni;
656 if (!vol->mft_ni)
658 lck_spin_lock(&vol->mft_ni->size_lock);
659 pass_end = vol->mft_ni->allocated_size >> vol->mft_record_size_shift;
660 lck_spin_unlock(&vol->mft_ni->size_lock);
668 data_pos = vol->mft_data_pos;
706 ntfs_error(vol->mp, "Failed to read mft "
787 * @vol: volume on which to extend the mft bitmap attribute
789 * Extend the mft bitmap attribute allocation on the ntfs volume @vol by one
797 * Locking: - Caller must hold @vol->mftbmp_lock for writing.
798 * - Caller must hold @vol->mftbmp_ni->lock for writing.
799 * - This function takes @vol->mftbmp_ni->rl.lock for writing and
801 * - This function takes @vol->lcnbmp_lock for writing and releases it
804 static errno_t ntfs_mft_bitmap_extend_allocation_nolock(ntfs_volume *vol)
823 mft_ni = vol->mft_ni;
824 mftbmp_ni = vol->mftbmp_ni;
825 lcnbmp_ni = vol->lcnbmp_ni;
835 vcn = (allocated_size - 1) >> vol->cluster_size_shift;
840 ntfs_error(vol->mp, "Failed to determine last allocated "
849 lck_rw_lock_exclusive(&vol->lcnbmp_lock);
852 ntfs_error(vol->mp, "Failed to get vnode for $Bitmap.");
853 lck_rw_unlock_exclusive(&vol->lcnbmp_lock);
869 lck_rw_unlock_exclusive(&vol->lcnbmp_lock);
871 ntfs_error(vol->mp, "Failed to read from lcn bitmap.");
879 vol->nr_free_clusters--;
880 if (vol->nr_free_clusters < 0)
881 vol->nr_free_clusters = 0;
885 lck_rw_unlock_exclusive(&vol->lcnbmp_lock);
896 lck_rw_unlock_exclusive(&vol->lcnbmp_lock);
900 err = ntfs_cluster_alloc(vol, vcn + 1, 1, lcn, DATA_ZONE,
904 ntfs_error(vol->mp, "Failed to allocate a cluster for "
913 ntfs_error(vol->mp, "Failed to merge runlists for mft "
917 err2 = ntfs_cluster_free_from_rl(vol, runlist.rl, 0,
920 ntfs_error(vol->mp, "Failed to release "
923 NVolSetErrors(vol);
933 ntfs_error(vol->mp, "Failed to map mft record.");
940 ntfs_error(vol->mp, "Failed to get search context.");
947 ntfs_error(vol->mp, "Failed to find last attribute extent of "
965 err = ntfs_get_size_for_mapping_pairs(vol, rl, lowest_vcn, -1,
968 ntfs_error(vol->mp, "Get size for mapping pairs failed for "
978 ntfs_error(vol->mp, "Failed to resize attribute "
987 ntfs_error(vol->mp, "Not enough space in this mft record to "
995 err = ntfs_mapping_pairs_build(vol, (s8*)a +
999 ntfs_error(vol->mp, "Failed to build mapping pairs array for "
1025 mftbmp_ni->allocated_size += vol->cluster_size;
1036 ntfs_error(vol->mp, "Failed to find first attribute extent of mft "
1044 ntfs_error(vol->mp, "Failed to find last attribute extent of "
1047 mftbmp_ni->allocated_size += vol->cluster_size;
1056 NVolSetErrors(vol);
1069 ntfs_error(vol->mp, "Failed to release allocated cluster in "
1072 NVolSetErrors(vol);
1080 err2 = ntfs_rl_truncate_nolock(vol, &mftbmp_ni->rl, vcn + 1);
1082 ntfs_error(vol->mp, "Failed to truncate attribute runlist s "
1084 NVolSetErrors(vol);
1089 ntfs_error(vol->mp, "Failed to restore attribute "
1092 NVolSetErrors(vol);
1095 err2 = ntfs_mapping_pairs_build(vol, (s8*)a + mp_ofs,
1099 ntfs_error(vol->mp, "Failed to restore "
1103 NVolSetErrors(vol);
1118 * @vol: volume on which to extend the mft bitmap attribute
1121 * volume @vol by 8 bytes.
1128 * Locking: - Caller must hold @vol->mftbmp_lock for writing.
1129 * - Caller must hold @vol->mftbmp_ni->lock for writing.
1131 static errno_t ntfs_mft_bitmap_extend_initialized_nolock(ntfs_volume *vol)
1141 mft_ni = vol->mft_ni;
1142 mftbmp_ni = vol->mftbmp_ni;
1146 ntfs_error(vol->mp, "Failed to map mft record.");
1151 ntfs_error(vol->mp, "Failed to get search context.");
1158 ntfs_error(vol->mp, "Failed to find first attribute extent of "
1196 ntfs_error(vol->mp, "Failed to write to mft bitmap.");
1200 ntfs_error(vol->mp, "Failed to map mft record in error code "
1202 NVolSetErrors(vol);
1207 ntfs_error(vol->mp, "Failed to get search context.%s", es);
1208 NVolSetErrors(vol);
1214 ntfs_error(vol->mp, "Failed to find first attribute extent of "
1217 NVolSetErrors(vol);
1229 ntfs_error(vol->mp, "Failed to restore UBC size. "
1253 * @vol: volume on which to extend the mft data attribute
1255 * Extend the mft data attribute on the ntfs volume @vol by 16 mft records
1264 * Locking: - Caller must hold @vol->mftbmp_lock for writing.
1265 * - Caller must hold @vol->mft_ni->lock for writing.
1266 * - This function takes @vol->mft_ni->rl.lock for writing and
1268 * - This function calls functions which take @vol->lcnbmp_lock for
1271 static errno_t ntfs_mft_data_extend_allocation_nolock(ntfs_volume *vol)
1287 mft_ni = vol->mft_ni;
1291 vcn = (allocated_size - 1) >> vol->cluster_size_shift;
1303 ntfs_error(vol->mp, "Failed to determine last allocated "
1312 min_nr = vol->mft_record_size >> vol->cluster_size_shift;
1316 nr = (vol->mft_record_size * 16) / vol->cluster_size;
1323 if ((allocated_size + (nr << vol->cluster_size_shift)) >>
1324 vol->mft_record_size_shift >= (1LL << 32)) {
1326 if ((allocated_size + (nr << vol->cluster_size_shift)) >>
1327 vol->mft_record_size_shift >= (1LL << 32)) {
1328 ntfs_warning(vol->mp, "Cannot allocate mft record "
1343 * from the cluster bitmap (vol->lcnbmp_ni) and we have mapped
1348 err = ntfs_cluster_alloc(vol, vcn + 1, nr, lcn, MFT_ZONE,
1355 ntfs_error(vol->mp, "Failed to allocate the minimal "
1377 ntfs_error(vol->mp, "Failed to merge runlists for mft data "
1381 err2 = ntfs_cluster_free_from_rl(vol, runlist.rl, 0, -1, NULL);
1383 ntfs_error(vol->mp, "Failed to release allocated "
1385 NVolSetErrors(vol);
1392 mft_ni->allocated_size += nr << vol->cluster_size_shift;
1411 ntfs_error(vol->mp, "Failed to map mft record.");
1418 ntfs_error(vol->mp, "Failed to get search context.");
1432 ntfs_error(vol->mp, "Failed to find last attribute extent of "
1450 err = ntfs_get_size_for_mapping_pairs(vol, rl, lowest_vcn, -1,
1453 ntfs_error(vol->mp, "Get size for mapping pairs failed for "
1463 ntfs_error(vol->mp, "Failed to resize attribute "
1477 ntfs_error(vol->mp, "Not enough space in this mft record to "
1485 err = ntfs_mapping_pairs_build(vol, (s8*)a +
1489 ntfs_error(vol->mp, "Failed to build mapping pairs array of "
1532 ntfs_error(vol->mp, "Failed to find first attribute extent of mft "
1544 ntfs_error(vol->mp, "Failed to find last attribute extent of "
1552 NVolSetErrors(vol);
1565 ntfs_error(vol->mp, "Failed to release allocated cluster(s) "
1568 NVolSetErrors(vol);
1581 mft_ni->allocated_size -= nr << vol->cluster_size_shift;
1583 err2 = ntfs_rl_truncate_nolock(vol, &mft_ni->rl, vcn + 1);
1586 ntfs_error(vol->mp, "Failed to truncate attribute runlist s "
1588 NVolSetErrors(vol);
1593 ntfs_error(vol->mp, "Failed to restore attribute "
1596 NVolSetErrors(vol);
1599 err2 = ntfs_mapping_pairs_build(vol, (s8*)a + mp_ofs,
1603 ntfs_error(vol->mp, "Failed to restore "
1607 NVolSetErrors(vol);
1621 * @vol: volume to which the mft record will belong
1623 * @m: destination buffer of size >= @vol->mft_record_size bytes
1626 * the buffer @m. The volume @vol is needed because the mft record structure
1632 static errno_t ntfs_mft_record_lay_out(const ntfs_volume *vol,
1640 ntfs_error(vol->mp, "Mft record number 0x%llx exceeds "
1645 if (vol->mft_record_size < NTFS_BLOCK_SIZE)
1646 panic("%s(): vol->mft_record_size < NTFS_BLOCK_SIZE\n",
1649 bzero(m, vol->mft_record_size);
1651 if (vol->major_ver < 3 || (vol->major_ver == 3 && !vol->minor_ver))
1663 m->usa_count = cpu_to_le16(1 + vol->mft_record_size / NTFS_BLOCK_SIZE);
1682 m->bytes_allocated = cpu_to_le32(vol->mft_record_size);
1695 * @vol: volume on which to format the mft record
1697 * @new_initialized_size: new initialized size to assign to @vol->mft_ni
1703 * Once the mft record is layed out the initialized size of @vol->mft_ni is
1709 * Locking: Caller must hold @vol->mft_ni->lock.
1711 static errno_t ntfs_mft_record_format(ntfs_volume *vol, const s64 mft_no,
1721 mft_ni = vol->mft_ni;
1723 if ((mft_no << vol->mft_record_size_shift) + vol->mft_record_size >
1725 ntfs_error(vol->mp, "Tried to format non-existing mft "
1730 err = buf_meta_bread(mft_ni->vn, mft_no, vol->mft_record_size, NOCRED,
1733 ntfs_error(vol->mp, "Failed to read buffer of mft record "
1740 ntfs_error(vol->mp, "Failed to map buffer of mft record "
1745 err = ntfs_mft_record_lay_out(vol, mft_no, m);
1747 ntfs_error(vol->mp, "Failed to lay out mft record 0x%llx "
1753 ntfs_error(vol->mp, "Failed to unmap buffer of mft record "
1771 ntfs_error(vol->mp, "Failed to write buffer of mft record 0x%llx "
1774 NVolSetErrors(vol);
1779 ntfs_error(vol->mp, "Failed to unmap buffer of mft record "
1838 * @vol: volume to which the mft record belongs
1846 * @vol is the volume the mft record @m belongs to and is used to determine
1856 static void ntfs_sd_attribute_insert(ntfs_volume *vol, MFT_RECORD *m,
1863 if (vol->major_ver > 1) {
1891 * @vol: volume to which the mft record belongs
1898 * @vol is the volume the mft record @m belongs to and is used to determine the
1903 static void ntfs_index_root_attribute_insert(ntfs_volume *vol, MFT_RECORD *m,
1923 ir->index_block_size = cpu_to_le32(vol->index_block_size);
1924 ir->blocks_per_index_block = vol->blocks_per_index_block;
1938 * @vol: [IN] volume on which to allocate the mft record
1946 * Allocate an mft record in $MFT/$DATA of an open ntfs volume @vol and return
2052 errno_t ntfs_mft_record_alloc(ntfs_volume *vol, struct vnode_attr *va,
2077 lck_rw_lock_exclusive(&vol->mftbmp_lock);
2086 mft_ni = vol->mft_ni;
2090 ntfs_error(vol->mp, "Failed to get vnode for $MFT.");
2091 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
2095 mftbmp_ni = vol->mftbmp_ni;
2098 ntfs_error(vol->mp, "Failed to get vnode for $MFT/$Bitmap.");
2101 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
2107 err = ntfs_mft_bitmap_find_and_alloc_free_rec_nolock(vol,
2126 ll = mft_ni->initialized_size >> vol->mft_record_size_shift;
2169 err = ntfs_mft_bitmap_extend_allocation_nolock(vol);
2189 err = ntfs_mft_bitmap_extend_initialized_nolock(vol);
2209 ntfs_error(vol->mp, "Failed to allocate bit in mft bitmap.");
2227 ll = (bit + 1) << vol->mft_record_size_shift;
2258 err = ntfs_mft_data_extend_allocation_nolock(vol);
2260 ntfs_error(vol->mp, "Failed to extend mft data "
2293 vol->mft_record_size;
2294 mft_no = mft_ni->initialized_size >> vol->mft_record_size_shift;
2305 vol->mft_record_size_shift;
2323 err = ntfs_mft_record_format(vol, mft_no, new_initialized_size);
2325 ntfs_error(vol->mp, "Failed to format mft record.");
2341 ntfs_error(vol->mp, "Failed to map mft record.");
2346 ntfs_error(vol->mp, "Failed to get search context.");
2361 ntfs_error(vol->mp, "Failed to find first attribute extent of "
2375 vol->nr_mft_records = mft_ni->data_size >> vol->mft_record_size_shift;
2376 vol->nr_free_mft_records += nr_mft_records_added;
2377 if (vol->nr_free_mft_records >= vol->nr_mft_records)
2378 panic("%s(): vol->nr_free_mft_records > vol->nr_mft_records\n",
2414 * about to drop the mftbmp_lock so we cannot touch vol->mft_data_pos
2417 old_mft_data_pos = vol->mft_data_pos;
2418 vol->mft_data_pos = bit + 1;
2423 vol->nr_free_mft_records--;
2424 if (vol->nr_free_mft_records < 0)
2425 vol->nr_free_mft_records = 0;
2435 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
2441 err = buf_meta_bread(mft_ni->vn, bit, vol->mft_record_size, NOCRED,
2444 ntfs_error(vol->mp, "Failed to read buffer of mft record "
2451 ntfs_error(vol->mp, "Failed to map buffer of mft record "
2479 ntfs_warning(vol->mp, "Mft record 0x%llx was marked "
2487 ntfs_error(vol->mp, "Failed to unmap buffer "
2493 lck_rw_lock_exclusive(&vol->mftbmp_lock);
2494 NVolSetErrors(vol);
2508 err = ntfs_mft_record_lay_out(vol, bit, m);
2510 ntfs_error(vol->mp, "Failed to lay out allocated mft "
2556 ntfs_error(vol->mp, "Failed to unmap buffer of mft "
2561 ntfs_error(vol->mp, "Failed to write buffer of mft "
2565 NVolSetErrors(vol);
2573 ntfs_error(vol->mp, "Failed to map allocated mft "
2638 if (NVolUseSDAttr(vol))
2643 lck_spin_lock(&vol->security_id_lock);
2645 security_id = vol->default_dir_security_id;
2647 security_id = vol->default_file_security_id;
2648 lck_spin_unlock(&vol->security_id_lock);
2656 if (!ntfs_default_security_id_init(vol, va)) {
2675 ntfs_sd_attribute_insert(vol, m, a, va);
2680 ntfs_index_root_attribute_insert(vol, m, a);
2760 ni = ntfs_inode_hash_get(vol, &na);
2762 ntfs_error(vol->mp, "Failed to allocate ntfs inode "
2784 ni->mode &= ~vol->dmask;
2820 ni->mode &= ~vol->fmask;
2885 ntfs_error(vol->mp, "Failed to unmap buffer of mft "
2890 ntfs_error(vol->mp, "Failed to write buffer of mft "
2894 NVolSetErrors(vol);
2953 err2 = buf_meta_bread(mft_ni->vn, bit, vol->mft_record_size, NOCRED,
2956 ntfs_error(vol->mp, "Failed to re-read buffer of mft record "
2959 NVolSetErrors(vol);
2964 ntfs_error(vol->mp, "Failed to re-map buffer of mft record "
2967 NVolSetErrors(vol);
2976 ntfs_error(vol->mp, "Failed to unmap buffer of mft record "
2983 ntfs_error(vol->mp, "Failed to write buffer of mft "
2990 lck_rw_lock_exclusive(&vol->mftbmp_lock);
2996 vol->nr_free_mft_records++;
3001 if (old_mft_data_pos < vol->mft_data_pos)
3002 vol->mft_data_pos = old_mft_data_pos;
3006 ntfs_error(vol->mp, "Failed to clear bit in mft bitmap.%s", es);
3007 NVolSetErrors(vol);
3014 vol->nr_free_mft_records--;
3015 if (vol->nr_free_mft_records < 0)
3016 vol->nr_free_mft_records = 0;
3020 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
3026 ntfs_warning(vol->mp, "Cannot allocate mft record because the maximum "
3061 ntfs_volume *vol = ni->vol;
3141 lck_rw_lock_exclusive(&vol->mftbmp_lock);
3142 err = vnode_get(vol->mftbmp_ni->vn);
3144 ntfs_error(vol->mp, "Failed to get vnode for $MFT/$BITMAP.");
3146 lck_rw_lock_shared(&vol->mftbmp_ni->lock);
3147 err = ntfs_bitmap_clear_bit(vol->mftbmp_ni, mft_no);
3148 lck_rw_unlock_shared(&vol->mftbmp_ni->lock);
3149 (void)vnode_put(vol->mftbmp_ni->vn);
3156 vol->nr_free_mft_records++;
3157 if (vol->nr_free_mft_records >= vol->nr_mft_records)
3158 panic("%s(): vol->nr_free_mft_records > "
3159 "vol->nr_mft_records\n",
3163 lck_rw_unlock_exclusive(&vol->mftbmp_lock);
3170 ntfs_error(vol->mp, "Failed to mark extent mft record as "
3172 NVolSetErrors(vol);