Lines Matching refs:vol
206 ntfs_volume *vol;
617 static void print_advise(ntfs_volume *vol, s64 supp_lcn)
621 old_b = vol->nr_clusters * vol->cluster_size;
628 if (supp_lcn > vol->nr_clusters) {
635 new_b = supp_lcn * vol->cluster_size;
637 freed_b = (vol->nr_clusters - supp_lcn + 1) * vol->cluster_size;
802 print_advise(resize->vol, lcn + lcn_length - 1);
827 static void build_lcn_usage_bitmap(ntfs_volume *vol, ntfsck_t *fsck)
841 if (!(rl = ntfs_mapping_pairs_decompress(vol, a, NULL))) {
868 if (k >= (u64)vol->nr_clusters) {
912 static int walk_attributes(ntfs_volume *vol, ntfsck_t *fsck)
920 build_lcn_usage_bitmap(vol, fsck);
933 static void compare_bitmaps(ntfs_volume *vol, struct bitmap *a)
945 count = ntfs_attr_pread(vol->lcnbmp_na, pos, NTFS_BUF_SIZE, bm);
974 cl == vol->nr_clusters / 2) {
1057 static int build_allocation_bitmap(ntfs_volume *vol, ntfsck_t *fsck)
1071 nr_mft_records = vol->mft_na->initialized_size >>
1072 vol->mft_record_size_bits;
1080 if ((ni = ntfs_inode_open(vol, (MFT_REF)inode)) == NULL) {
1094 if (walk_attributes(vol, fsck) != 0) {
1113 if (!(rl = ntfs_mapping_pairs_decompress(resize->vol,
1151 nr_mft_records = resize->vol->mft_na->initialized_size >>
1152 resize->vol->mft_record_size_bits;
1156 ni = ntfs_inode_open(resize->vol, (MFT_REF)inode);
1318 static void expand_attribute_runlist(ntfs_volume *vol, struct DELAYED *delayed)
1337 ni = vol->mft_ni;
1339 ni = ntfs_inode_open(vol,mref);
1342 na = (type == AT_DATA ? vol->mft_na : vol->mftbmp_na);
1402 ni = resize->vol->mft_ni;
1403 if (!ntfs_file_record_read(resize->vol, FILE_MFT, &ni->mrec, NULL)) {
1404 for (xi=0; !r && xi<resize->vol->mft_ni->nr_extents; xi++) {
1405 r = ntfs_file_record_read(resize->vol,
1411 /* reopen the MFT bitmap, and swap vol->mftbmp_na */
1412 na = ntfs_attr_open(resize->vol->mft_ni,
1415 ntfs_attr_close(resize->vol->mftbmp_na);
1416 resize->vol->mftbmp_na = na;
1422 /* reopen the MFT data, and swap vol->mft_na */
1423 na = ntfs_attr_open(resize->vol->mft_ni,
1426 ntfs_attr_close(resize->vol->mft_na);
1427 resize->vol->mft_na = na;
1451 ni = resize->vol->mft_ni;
1452 for (xi=0; !r && xi<resize->vol->mft_ni->nr_extents; xi++) {
1453 r = ntfs_bitmap_set_run(resize->vol->mftbmp_na,
1469 if (ntfs_volume_get_free_space(resize->vol))
1507 expand_attribute_runlist(resize->vol, delayed);
1522 expand_attribute_runlist(resize->vol, delayed_mft_data);
1530 nr_extents = resize->vol->mft_ni->nr_extents;
1613 ntfs_volume *vol;
1617 vol = resize->vol;
1623 if ((mp_size = ntfs_get_size_for_mapping_pairs(vol, rl, 0, INT_MAX)) == -1)
1686 if (ntfs_mapping_pairs_build(vol, (u8*)mp, mp_size, rl, 0, NULL))
1882 static void lseek_to_cluster(ntfs_volume *vol, s64 lcn)
1886 pos = (off_t)(lcn * vol->cluster_size);
1888 if (vol->dev->d_ops->seek(vol->dev, pos, SEEK_SET) == (off_t)-1)
1896 ntfs_volume *vol = resize->vol;
1898 buff = (char*)ntfs_malloc(vol->cluster_size);
1904 lseek_to_cluster(vol, src + i);
1906 if (read_all(vol->dev, buff, vol->cluster_size) == -1) {
1913 lseek_to_cluster(vol, dest + i);
1915 if (write_all(vol->dev, buff, vol->cluster_size) == -1) {
2076 if (!(rl = ntfs_mapping_pairs_decompress(resize->vol, a, NULL)))
2204 ntfs_volume *vol = resize->vol;
2206 if (ntfs_file_record_read(vol, mref, &resize->mrec, NULL)) {
2222 // if (vol->dev->d_ops->sync(vol->dev) == -1)
2230 << vol->cluster_size_bits)
2231 + (FILE_MFT << vol->mft_record_size_bits);
2233 && (ntfs_mst_pwrite(vol->dev, pos, 1,
2234 vol->mft_record_size, resize->mrec) != 1))
2238 && write_mft_record(vol, mref, resize->mrec)) {
2257 resize->mrec = ntfs_malloc(resize->vol->mft_record_size);
2261 nr_mft_records = resize->vol->mft_na->initialized_size >>
2262 resize->vol->mft_record_size_bits;
2272 if (!resize->vol->mft_na->rl)
2275 if ((resize->vol->mft_na->rl->lcn + resize->vol->mft_na->rl->length)
2285 length = resize->vol->mft_na->rl->length;
2286 if (ntfs_file_record_read(resize->vol, FILE_MFT,
2308 << resize->vol->cluster_size_bits)
2309 >> resize->vol->mft_record_size_bits) < 16)) {
2336 static void print_hint(ntfs_volume *vol, const char *s, struct llcn_t llcn)
2343 runs_b = llcn.lcn * vol->cluster_size;
2358 ntfs_volume *vol = resize->vol;
2363 print_hint(vol, "$MFT", resize->last_mft);
2364 print_hint(vol, "Multi-Record", resize->last_multi_mft);
2365 print_hint(vol, "$MFTMirr", resize->last_mftmir);
2366 print_hint(vol, "Compressed", resize->last_compressed);
2367 print_hint(vol, "Sparse", resize->last_sparse);
2368 print_hint(vol, "Ordinary", resize->last_lcn);
2371 print_advise(vol, resize->last_unsupp);
2431 ntfs_volume *vol = resize->vol;
2439 if (ntfs_attr_truncate(na,nr_clusters << vol->cluster_size_bits)) {
2470 ntfs_volume *vol = resize->vol;
2475 if (!(*rl = ntfs_mapping_pairs_decompress(vol, a, NULL)))
2481 for (i = vol->nr_clusters; i < new_size; i++)
2511 ntfs_volume *vol = resize->vol;
2519 nr_bm_clusters = rounded_up_division(bm_bsize, vol->cluster_size);
2533 lcnbmp_na = resize->vol->lcnbmp_na;
2536 lcnbmp_na->allocated_size = nr_bm_clusters << vol->cluster_size_bits;
2537 vol->lcnbmp_ni->data_size = bm_bsize;
2538 vol->lcnbmp_ni->allocated_size = lcnbmp_na->allocated_size;
2540 a->allocated_size = cpu_to_sle64(nr_bm_clusters * vol->cluster_size);
2551 size = ntfs_rl_pwrite(vol, rl, 0, 0, bm_bsize, resize->lcn_bitmap.bm);
2572 static void lookup_data_attr(ntfs_volume *vol,
2581 if (!(ni = ntfs_inode_open(vol, mref)))
2611 static int check_bad_sectors(ntfs_volume *vol)
2620 lookup_data_attr(vol, FILE_BadClus, "$Bad", &ctx);
2672 lookup_data_attr(resize->vol, FILE_BadClus, "$Bad", &resize->ctx);
2687 ntfs_volume *vol = resize->vol;
2691 lookup_data_attr(resize->vol, FILE_Bitmap, NULL, &resize->ctx);
2699 pos = (resize->new_mft_start->lcn << vol->cluster_size_bits)
2700 + (FILE_Bitmap << vol->mft_record_size_bits);
2702 && (ntfs_mst_pwrite(vol->dev, pos, 1,
2703 vol->mft_record_size, resize->ctx->mrec) != 1))
2706 if (write_mft_record(vol, resize->ctx->ntfs_ino->mft_no,
2712 memcpy(vol->lcnbmp_ni->mrec,resize->ctx->mrec,vol->mft_record_size);
2713 ntfs_inode_mark_dirty(vol->lcnbmp_ni);
2714 NInoFileNameSetDirty(vol->lcnbmp_ni);
2715 ntfs_inode_sync(vol->lcnbmp_ni);
2752 ntfs_volume *vol = r->vol;
2753 s64 bs_size = vol->sector_size;
2757 bs = (NTFS_BOOT_SECTOR*)ntfs_malloc(vol->sector_size);
2761 if (vol->dev->d_ops->seek(vol->dev, 0, SEEK_SET) == (off_t)-1)
2764 if (vol->dev->d_ops->read(vol->dev, bs, bs_size) == -1)
2780 ntfs_inode_sync(vol->mft_ni);
2782 vol->mft_na->rl->lcn, r->mftmir_rl.length);
2805 if (vol->dev->d_ops->seek(vol->dev, 0, SEEK_SET) == (off_t)-1)
2809 if (vol->dev->d_ops->write(vol->dev, bs, bs_size) == -1)
2820 && !(opt.bytes % vol->sector_size)) {
2821 if (vol->dev->d_ops->seek(vol->dev, opt.bytes
2822 - vol->sector_size, SEEK_SET) == (off_t)-1)
2824 if (vol->dev->d_ops->write(vol->dev, bs, bs_size) == -1)
2855 static void print_disk_usage(ntfs_volume *vol, s64 nr_used_clusters)
2859 total = vol->nr_clusters * vol->cluster_size;
2860 used = nr_used_clusters * vol->cluster_size;
2872 s64 relocations = resize->relocations * resize->vol->cluster_size;
2928 ntfs_volume *vol = NULL;
2944 vol = check_volume();
2946 if (vol->flags & VOLUME_IS_DIRTY)
2951 if (NTFS_MAX_CLUSTER_SIZE < vol->cluster_size)
2953 (unsigned int)vol->cluster_size);
2955 if (ntfs_volume_get_free_space(vol))
2961 vol->major_ver, vol->minor_ver);
2963 if (ntfs_version_is_supported(vol))
2968 (unsigned int)vol->cluster_size);
2970 vol_size(vol, vol->nr_clusters));
2973 return vol;
2983 static void prepare_volume_fixup(ntfs_volume *vol)
2987 vol->flags |= VOLUME_IS_DIRTY;
2988 if (ntfs_volume_write_flags(vol, vol->flags))
2994 /* NVolSetWasDirty(vol); */
2996 if (vol->dev->d_ops->sync(vol->dev) == -1)
2999 if (ntfs_logfile_reset(vol))
3001 if (vol->dev->d_ops->sync(vol->dev) == -1)
3022 if (resize->inuse == resize->vol->nr_clusters)
3044 static void check_cluster_allocation(ntfs_volume *vol, ntfsck_t *fsck)
3051 if (setup_lcn_bitmap(&fsck->lcn_bitmap, vol->nr_clusters) != 0)
3053 if (build_allocation_bitmap(vol, fsck) != 0)
3067 compare_bitmaps(vol, &fsck->lcn_bitmap);
3095 ntfs_volume *vol;
3158 ntfs_volume *vol;
3168 vol = expand->vol;
3169 pos = (vol->mft_lcn << vol->cluster_size_bits)
3170 + (inum << vol->mft_record_size_bits)
3172 got = ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size, mrec);
3195 ntfs_volume *vol;
3203 vol = expand->vol;
3204 pos = (vol->mft_lcn << vol->cluster_size_bits)
3205 + (inum << vol->mft_record_size_bits)
3207 got = ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size, mrec);
3250 ntfs_volume *vol;
3257 vol = expand->vol;
3264 && ((bitmap_size << (vol->mft_record_size_bits + 3))
3267 rl = ntfs_mapping_pairs_decompress(expand->vol, a,
3272 lseek_to_cluster(vol,
3274 ok = !read_all(vol->dev, expand->mft_bitmap
3275 + (prl->vcn << vol->cluster_size_bits),
3276 prl->length << vol->cluster_size_bits);
3318 rl = ntfs_mapping_pairs_decompress(expand->vol, a, NULL);
3388 rl = ntfs_mapping_pairs_decompress(expand->vol, a, NULL);
3398 rl = ntfs_mapping_pairs_decompress(expand->vol, a, NULL);
3445 static BOOL can_expand(expand_t *expand, ntfs_volume *vol)
3457 old_sector_count = vol->nr_clusters
3458 << (vol->cluster_size_bits - vol->sector_size_bits);
3461 >> (vol->cluster_size_bits - vol->sector_size_bits))
3462 - vol->nr_clusters;
3464 << vol->cluster_size_bits;
3466 >> vol->sector_size_bits;
3472 (long long)vol->nr_clusters,
3473 (long long)(vol->nr_clusters
3483 got = ntfs_pread(expand->vol->dev, expand->byte_increment,
3484 vol->sector_size, expand->mrec);
3485 if ((got != vol->sector_size)
3486 || memcmp(expand->bootsector,expand->mrec,vol->sector_size)) {
3507 << vol->sector_size_bits)
3510 >> vol->cluster_size_bits;
3512 << vol->cluster_size_bits)
3513 / (vol->cluster_size + 1);
3516 >> (vol->cluster_size_bits
3517 - vol->sector_size_bits);
3522 | (vol->cluster_size - 1)) + 1;
3525 >> vol->cluster_size_bits;
3532 >> vol->sector_size_bits;
3547 if (expand->byte_increment & (vol->cluster_size - 1)) {
3550 (int)(vol->cluster_size/vol->sector_size));
3552 (int)(vol->cluster_size/vol->sector_size));
3553 advice = expand->byte_increment & ~vol->cluster_size;
3559 >> vol->sector_size_bits));
3565 << vol->sector_size_bits)
3571 (long long)(minimum_size + vol->sector_size));
3573 (long)vol->cluster_size);
3593 <= (expand->vol->nr_clusters + expand->cluster_increment))) {
3635 ntfs_volume *vol;
3640 vol = expand->vol;
3644 bw = vol->sector_size;
3646 bw = ntfs_pwrite(vol->dev,
3647 expand->new_sectors*vol->sector_size,
3648 vol->sector_size, expand->bootsector);
3649 if (bw == vol->sector_size)
3668 ntfs_volume *vol;
3674 vol = expand->vol;
3675 cluster = vol->nr_clusters + expand->cluster_increment;
3686 bw = ntfs_pwrite(vol->dev, expand->boot_size,
3713 ntfs_volume *vol;
3723 vol = expand->vol;
3727 pos = (expand->mft_lcn << vol->cluster_size_bits)
3728 + (inum << vol->mft_record_size_bits);
3729 if (ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size,
3732 pos = (vol->mftmirr_lcn << vol->cluster_size_bits)
3733 + (inum << vol->mft_record_size_bits)
3742 && (ntfs_mst_pwrite(vol->dev, pos, 1,
3743 vol->mft_record_size, expand->mrec) != 1)) {
3768 ntfs_volume *vol;
3778 vol = expand->vol;
3780 buf = (char*)ntfs_malloc(vol->cluster_size);
3786 mftmirr_lcn = vol->mftmirr_lcn + expand->cluster_increment;
3801 boot_cnt = expand->boot_size >> vol->cluster_size_bits;
3803 lseek_to_cluster(vol, expand->cluster_increment + written);
3804 if (!read_all(vol->dev, buf, vol->cluster_size)) {
3806 memcpy(buf, expand->bootsector, vol->sector_size);
3807 lseek_to_cluster(vol, written);
3809 && write_all(vol->dev, buf, vol->cluster_size)) {
3834 static void delayed_expand(ntfs_volume *vol, struct DELAYED *delayed,
3855 expand_attribute_runlist(vol, delayed);
3884 ni = ntfs_inode_open(expand->vol, FILE_Bitmap);
3906 ntfs_volume *vol;
3914 vol = expand->vol;
3918 if ((mp_size = ntfs_get_size_for_mapping_pairs(vol, rl,
3988 if (ntfs_mapping_pairs_build(vol, (u8*)mp, mp_size, rl, 0, NULL))
4007 memset(mrec,0,expand->vol->mft_record_size);
4010 usa_count = expand->vol->mft_record_size / NTFS_BLOCK_SIZE + 1;
4016 mrec->bytes_allocated = cpu_to_le32(expand->vol->mft_record_size);
4042 rl = ntfs_mapping_pairs_decompress(expand->vol, a,
4078 ntfs_volume *vol;
4093 vol = expand->vol;
4098 lth = expand->boot_size >> vol->cluster_size_bits;
4102 lcn = expand->boot_size >> vol->cluster_size_bits;
4103 lth = expand->bitmap_allocated >> vol->cluster_size_bits;
4108 >> vol->cluster_size_bits;
4109 lth = expand->mft_size >> vol->cluster_size_bits;
4114 lth = vol->nr_clusters + expand->cluster_increment;
4115 data_size = lth << vol->cluster_size_bits;
4121 allocated_size = lth << vol->cluster_size_bits;
4128 rl = ntfs_mapping_pairs_decompress(vol, a,
4212 ntfs_volume *vol;
4217 vol = expand->vol;
4220 pos = (prl->lcn << vol->cluster_size_bits)
4221 + ((inum - jnum) << vol->mft_record_size_bits);
4222 if ((ntfs_mst_pread(vol->dev, pos, 1,
4223 vol->mft_record_size, mrec) == 1)
4252 pos = (expand->mft_lcn << vol->cluster_size_bits)
4253 + (inum << vol->mft_record_size_bits);
4257 (long long)(pos >> vol->cluster_size_bits));
4259 && (ntfs_mst_pwrite(vol->dev, pos, 1,
4260 vol->mft_record_size, mrec) != 1)) {
4278 ntfs_volume *vol;
4291 vol = expand->vol;
4294 pos = (vol->mft_lcn + expand->cluster_increment)
4295 << vol->cluster_size_bits;
4296 got = ntfs_mst_pread(vol->dev, pos, 1,
4297 vol->mft_record_size, mrec);
4299 pos = expand->mft_lcn << vol->cluster_size_bits;
4303 (long long)(pos >> vol->cluster_size_bits));
4307 && (ntfs_mst_pwrite(vol->dev, pos, 1,
4308 vol->mft_record_size, mrec) != 1)))
4312 inodecnt = (prl->vcn << vol->cluster_size_bits)
4313 >> vol->mft_record_size_bits;
4321 && ((inum << vol->mft_record_size_bits)
4323 << vol->cluster_size_bits))) {
4353 ntfs_volume *vol;
4359 vol = (ntfs_volume*)ntfs_malloc(sizeof(ntfs_volume));
4361 if (vol && expand->bootsector) {
4362 expand->vol = vol;
4363 vol->dev = dev;
4380 && !ntfs_boot_sector_parse(vol, bs)) {
4384 ntfs_malloc(vol->mft_record_size);
4386 && can_expand(expand,vol)) {
4395 free(vol);
4399 return (ok ? vol : (ntfs_volume*)NULL);
4404 ntfs_volume *vol;
4430 free(expand->vol);
4431 expand->vol = (ntfs_volume*)NULL;
4437 vol = mount_volume();
4438 if (vol) {
4439 dev = vol->dev;
4441 expand->vol = vol;
4443 delayed_expand(vol, expand->delayed_runlists,
4454 ntfs_umount(vol,0);
4460 delayed_expand(expand->vol,
4490 ntfs_volume *vol;
4519 vol = get_volume_data(&expand,dev,sector_size);
4520 if (vol) {
4521 expand.vol = vol;
4541 ntfs_volume *vol = NULL;
4559 vol = check_volume();
4561 if (vol)
4562 ntfs_umount(vol,0);
4579 if (!(vol = mount_volume()))
4582 device_size = ntfs_device_size_get(vol->dev, vol->sector_size);
4583 device_size *= vol->sector_size;
4591 if (device_size < vol->nr_clusters * vol->cluster_size)
4603 if (opt.bytes > vol->sector_size)
4604 new_size = (opt.bytes - vol->sector_size) / vol->cluster_size;
4609 print_vol_size("New volume size ", vol_size(vol, new_size));
4616 if (!opt.info && !opt.infombonly && (new_size == vol->nr_clusters ||
4618 new_size == vol->nr_clusters - 1))) {
4624 resize.vol = vol;
4627 if (new_size < vol->nr_clusters)
4636 resize.badclusters = check_bad_sectors(vol);
4638 NVolSetNoFixupWarn(vol);
4639 check_cluster_allocation(vol, &fsck);
4641 print_disk_usage(vol, fsck.inuse);
4662 prepare_volume_fixup(vol);
4682 if (vol->dev->d_ops->sync(vol->dev) == -1)
4685 printf("Successfully resized NTFS on device '%s'.\n", vol->dev->d_name);
4690 if (vol)
4691 ntfs_umount(vol,0);