Lines Matching refs:resize

10  * This utility will resize an NTFS volume without data loss.
130 "* run 'chkdsk /f /r' on Windows and rebooot it TWICE! Then you can resize *\n"
344 " -c, --check Check to ensure that the device is ready for resize\n"
642 printf("You might resize at %lld bytes ", (long long)new_b);
709 static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl)
719 inode = resize->ni->mft_no;
720 flags = resize->ctx->attr->flags;
721 atype = resize->ctx->attr->type;
723 if ((ret = ntfs_inode_badclus_bad(inode, resize->ctx->attr)) != 0) {
730 llcn = &resize->last_lcn;
731 if (atype == AT_DATA && NInoAttrList(resize->ni))
736 } else if (NInoAttrList(resize->ni)) {
737 llcn = &resize->last_multi_mft;
743 llcn = &resize->last_sparse;
747 llcn = &resize->last_compressed;
751 llcn = &resize->last_mftmir;
759 llcn = &resize->last_lcn;
771 if (resize->last_unsupp < last_lcn)
772 resize->last_unsupp = last_lcn;
776 static void collect_relocation_info(ntfs_resize_t *resize, runlist *rl)
783 inode = resize->ni->mft_no;
784 new_vol_size = resize->new_volume_size;
789 if (inode == FILE_Bitmap && resize->ctx->attr->type == AT_DATA)
802 print_advise(resize->vol, lcn + lcn_length - 1);
807 resize->relocations += len;
809 if ((!opt.info && !opt.infombonly) || !resize->new_volume_size)
814 (unsigned int)le32_to_cpu(resize->ctx->attr->type),
1105 static void build_resize_constraints(ntfs_resize_t *resize)
1110 if (!resize->ctx->attr->non_resident)
1113 if (!(rl = ntfs_mapping_pairs_decompress(resize->vol,
1114 resize->ctx->attr, NULL)))
1122 collect_resize_constraints(resize, rl + i);
1123 if (resize->shrink)
1124 collect_relocation_info(resize, rl + i);
1129 static void resize_constraints_by_attributes(ntfs_resize_t *resize)
1131 if (!(resize->ctx = attr_get_search_ctx(resize->ni, NULL)))
1134 while (!ntfs_attrs_walk(resize->ctx)) {
1135 if (resize->ctx->attr->type == AT_END)
1137 build_resize_constraints(resize);
1140 ntfs_attr_put_search_ctx(resize->ctx);
1143 static void set_resize_constraints(ntfs_resize_t *resize)
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);
1167 resize->ni = ni;
1168 resize_constraints_by_attributes(resize);
1393 static int reload_mft(ntfs_resize_t *resize)
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,
1412 na = ntfs_attr_open(resize->vol->mft_ni,
1415 ntfs_attr_close(resize->vol->mftbmp_na);
1416 resize->vol->mftbmp_na = na;
1423 na = ntfs_attr_open(resize->vol->mft_ni,
1426 ntfs_attr_close(resize->vol->mft_na);
1427 resize->vol->mft_na = na;
1443 static int record_mft_in_bitmap(ntfs_resize_t *resize)
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,
1463 static void delayed_updates(ntfs_resize_t *resize)
1469 if (ntfs_volume_get_free_space(resize->vol))
1473 if (resize->delayed_runlists && reload_mft(resize))
1497 && resize->delayed_runlists
1498 && (resize->delayed_runlists->mref == FILE_MFT)
1499 && (resize->delayed_runlists->type == AT_DATA)) {
1501 delayed_mft_data = resize->delayed_runlists;
1502 resize->delayed_runlists = resize->delayed_runlists->next;
1505 while (resize->delayed_runlists) {
1506 delayed = resize->delayed_runlists;
1507 expand_attribute_runlist(resize->vol, delayed);
1510 record_mft_in_bitmap(resize);
1512 resize->mirr_from = MIRR_MFT;
1514 resize->delayed_runlists = resize->delayed_runlists->next;
1522 expand_attribute_runlist(resize->vol, delayed_mft_data);
1523 resize->mirr_from = MIRR_MFT;
1530 nr_extents = resize->vol->mft_ni->nr_extents;
1543 static void replace_later(ntfs_resize_t *resize, runlist *rl, runlist *head_rl)
1554 a = resize->ctx->attr;
1565 lemref = resize->ctx->mrec->base_mft_record;
1569 mref = resize->mref;
1579 || !resize->delayed_runlists
1580 || (resize->delayed_runlists->mref != FILE_MFT)) {
1581 delayed->next = resize->delayed_runlists;
1582 resize->delayed_runlists = delayed;
1585 previous = resize->delayed_runlists;
1607 static int replace_attribute_runlist(ntfs_resize_t *resize, runlist *rl)
1617 vol = resize->vol;
1618 ctx = resize->ctx;
1672 replace_later(resize,rl,head_rl);
1892 static void copy_clusters(ntfs_resize_t *resize, s64 dest, s64 src, s64 len)
1896 ntfs_volume *vol = resize->vol;
1922 resize->relocations++;
1923 progress_update(&resize->progress, resize->relocations);
2008 static void relocate_run(ntfs_resize_t *resize, runlist **rl, int run)
2017 new_vol_size = resize->new_volume_size;
2027 hint = (resize->mref == FILE_MFTMirr) ? 1 : 0;
2028 if ((resize->mref == FILE_MFT)
2029 && (resize->ctx->attr->type == AT_DATA)
2031 && resize->new_mft_start) {
2032 relocate_rl = resize->new_mft_start;
2034 if (!(relocate_rl = alloc_cluster(&resize->lcn_bitmap,
2037 (unsigned long long)resize->mref,
2042 "--> 0x%08llx\n", (unsigned long long)resize->mref,
2043 (unsigned int)le32_to_cpu(resize->ctx->attr->type),
2049 relocate_clusters(resize, relocate_rl, lcn);
2056 if ((resize->mref != FILE_MFT)
2057 || (resize->ctx->attr->type != AT_DATA)
2059 || !resize->new_mft_start)
2062 resize->dirty_inode = DIRTY_ATTRIB;
2065 static void relocate_attribute(ntfs_resize_t *resize)
2071 a = resize->ctx->attr;
2076 if (!(rl = ntfs_mapping_pairs_decompress(resize->vol, a, NULL)))
2090 (unsigned long long)resize->mref,
2094 relocate_run(resize, &rl, i);
2097 if (resize->dirty_inode == DIRTY_ATTRIB) {
2098 if (!replace_attribute_runlist(resize, rl))
2100 resize->dirty_inode = DIRTY_INODE;
2105 static int is_mftdata(ntfs_resize_t *resize)
2113 if (resize->ctx->attr->type != AT_DATA)
2116 if (resize->mref == 0)
2119 if (MREF_LE(resize->mrec->base_mft_record) == 0 &&
2120 MSEQNO_LE(resize->mrec->base_mft_record) != 0)
2126 static int handle_mftdata(ntfs_resize_t *resize, int do_mftdata)
2128 ATTR_RECORD *attr = resize->ctx->attr;
2133 if (!is_mftdata(resize))
2139 if (resize->mft_highest_vcn != highest_vcn)
2143 resize->mft_highest_vcn = lowest_vcn;
2145 resize->mft_highest_vcn = lowest_vcn - 1;
2147 } else if (is_mftdata(resize)) {
2151 if (resize->mft_highest_vcn < highest_vcn)
2152 resize->mft_highest_vcn = highest_vcn;
2160 static void relocate_attributes(ntfs_resize_t *resize, int do_mftdata)
2166 if (!(resize->ctx = attr_get_search_ctx(NULL, resize->mrec)))
2169 lemref = resize->mrec->base_mft_record;
2173 base_mref = resize->mref;
2174 while (!ntfs_attrs_walk(resize->ctx)) {
2175 if (resize->ctx->attr->type == AT_END)
2178 if (handle_mftdata(resize, do_mftdata) == 0)
2181 ret = ntfs_inode_badclus_bad(resize->mref, resize->ctx->attr);
2187 if (resize->mref == FILE_Bitmap &&
2188 resize->ctx->attr->type == AT_DATA)
2193 && (resize->ctx->attr->type == AT_DATA))
2196 relocate_attribute(resize);
2199 ntfs_attr_put_search_ctx(resize->ctx);
2202 static void relocate_inode(ntfs_resize_t *resize, MFT_REF mref, int do_mftdata)
2204 ntfs_volume *vol = resize->vol;
2206 if (ntfs_file_record_read(vol, mref, &resize->mrec, NULL)) {
2214 if (!(resize->mrec->flags & MFT_RECORD_IN_USE))
2217 resize->mref = mref;
2218 resize->dirty_inode = DIRTY_NONE;
2220 relocate_attributes(resize, do_mftdata);
2225 if ((mref == FILE_MFT) && do_mftdata && resize->new_mft_start) {
2229 pos = (resize->new_mft_start->lcn
2234 vol->mft_record_size, resize->mrec) != 1))
2237 if ((resize->dirty_inode == DIRTY_INODE)
2238 && write_mft_record(vol, mref, resize->mrec)) {
2245 static void relocate_inodes(ntfs_resize_t *resize)
2254 progress_init(&resize->progress, 0, resize->relocations, resize->progress.flags);
2255 resize->relocations = 0;
2257 resize->mrec = ntfs_malloc(resize->vol->mft_record_size);
2258 if (!resize->mrec)
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)
2276 >= resize->new_volume_size) {
2285 length = resize->vol->mft_na->rl->length;
2286 if (ntfs_file_record_read(resize->vol, FILE_MFT,
2287 &resize->mrec, NULL)
2288 || !(resize->ctx = attr_get_search_ctx(NULL,
2289 resize->mrec))) {
2292 while (!ntfs_attrs_walk(resize->ctx)
2293 && (resize->ctx->attr->type != AT_DATA)) { }
2294 if (resize->ctx->attr->type == AT_DATA) {
2297 high_le = resize->ctx->attr->highest_vcn;
2303 ntfs_attr_put_search_ctx(resize->ctx);
2304 resize->new_mft_start = alloc_cluster(&resize->lcn_bitmap,
2305 length, resize->new_volume_size, 0);
2306 if (!resize->new_mft_start
2307 || (((resize->new_mft_start->length
2308 << resize->vol->cluster_size_bits)
2309 >> resize->vol->mft_record_size_bits) < 16)) {
2313 resize->mirr_from = MIRR_NEWMFT;
2317 relocate_inode(resize, mref, 0);
2320 highest_vcn = resize->mft_highest_vcn;
2323 relocate_inode(resize, --mref, 1);
2324 if (resize->mft_highest_vcn == 0)
2328 if (highest_vcn == resize->mft_highest_vcn)
2333 free(resize->mrec);
2356 static void advise_on_resize(ntfs_resize_t *resize)
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);
2425 static void truncate_badclust_bad_attr(ntfs_resize_t *resize)
2430 s64 nr_clusters = resize->new_volume_size;
2431 ntfs_volume *vol = resize->vol;
2433 na = open_badclust_bad_attr(resize->ctx);
2446 ctx = resize->ctx;
2465 static void realloc_bitmap_data_attr(ntfs_resize_t *resize,
2470 ntfs_volume *vol = resize->vol;
2471 ATTR_RECORD *a = resize->ctx->attr;
2472 s64 new_size = resize->new_volume_size;
2473 struct bitmap *bm = &resize->lcn_bitmap;
2488 static void realloc_lcn_bitmap(ntfs_resize_t *resize, s64 bm_bsize)
2492 if (!(tmp = realloc(resize->lcn_bitmap.bm, bm_bsize)))
2495 resize->lcn_bitmap.bm = tmp;
2496 resize->lcn_bitmap.size = bm_bsize;
2497 bitmap_file_data_fixup(resize->new_volume_size, &resize->lcn_bitmap);
2503 static void truncate_bitmap_data_attr(ntfs_resize_t *resize)
2511 ntfs_volume *vol = resize->vol;
2513 a = resize->ctx->attr;
2518 bm_bsize = nr_clusters_to_bitmap_byte_size(resize->new_volume_size);
2521 if (resize->shrink) {
2522 realloc_bitmap_data_attr(resize, &rl, nr_bm_clusters);
2523 realloc_lcn_bitmap(resize, bm_bsize);
2525 realloc_lcn_bitmap(resize, bm_bsize);
2526 realloc_bitmap_data_attr(resize, &rl, nr_bm_clusters);
2533 lcnbmp_na = resize->vol->lcnbmp_na;
2544 truncated = !replace_attribute_runlist(resize, rl);
2551 size = ntfs_rl_pwrite(vol, rl, 0, 0, bm_bsize, resize->lcn_bitmap.bm);
2668 static void truncate_badclust_file(ntfs_resize_t *resize)
2672 lookup_data_attr(resize->vol, FILE_BadClus, "$Bad", &resize->ctx);
2674 resize->mref = FILE_BadClus;
2675 truncate_badclust_bad_attr(resize);
2677 close_inode_and_context(resize->ctx);
2685 static void truncate_bitmap_file(ntfs_resize_t *resize)
2687 ntfs_volume *vol = resize->vol;
2691 lookup_data_attr(resize->vol, FILE_Bitmap, NULL, &resize->ctx);
2692 resize->mref = FILE_Bitmap;
2693 truncate_bitmap_data_attr(resize);
2695 if (resize->new_mft_start) {
2699 pos = (resize->new_mft_start->lcn << vol->cluster_size_bits)
2703 vol->mft_record_size, resize->ctx->mrec) != 1))
2706 if (write_mft_record(vol, resize->ctx->ntfs_ino->mft_no,
2707 resize->ctx->mrec))
2712 memcpy(vol->lcnbmp_ni->mrec,resize->ctx->mrec,vol->mft_record_size);
2718 close_inode_and_context(resize->ctx);
2720 ntfs_attr_put_search_ctx(resize->ctx);
2870 static void print_num_of_relocations(ntfs_resize_t *resize)
2872 s64 relocations = resize->relocations * resize->vol->cluster_size;
2875 (long long)resize->relocations, (long long)
3005 static void set_disk_usage_constraint(ntfs_resize_t *resize)
3008 s64 last = resize->inuse - 1;
3010 if (resize->last_unsupp < last)
3011 resize->last_unsupp = last;
3014 static void check_resize_constraints(ntfs_resize_t *resize)
3016 s64 new_size = resize->new_volume_size;
3018 /* FIXME: resize.shrink true also if only -i is used */
3019 if (!resize->shrink)
3022 if (resize->inuse == resize->vol->nr_clusters)
3030 if (new_size < resize->inuse)
3035 if (new_size <= resize->last_unsupp)
3041 print_num_of_relocations(resize);
3904 ntfs_resize_t resize;
3966 resize.ctx = &ctx;
3969 resize.mref = inum;
3970 resize.delayed_runlists = expand->delayed_runlists;
3971 resize.mirr_from = MIRR_OLD;
3973 replace_later(&resize,rl,head_rl);
3974 expand->delayed_runlists = resize.delayed_runlists;
4538 ntfs_resize_t resize;
4623 memset(&resize, 0, sizeof(resize));
4624 resize.vol = vol;
4625 resize.new_volume_size = new_size;
4628 resize.shrink = 1;
4630 resize.progress.flags |= NTFS_PROGBAR;
4636 resize.badclusters = check_bad_sectors(vol);
4643 resize.inuse = fsck.inuse;
4644 resize.lcn_bitmap = fsck.lcn_bitmap;
4645 resize.mirr_from = MIRR_OLD;
4647 set_resize_constraints(&resize);
4648 set_disk_usage_constraint(&resize);
4649 check_resize_constraints(&resize);
4652 advise_on_resize(&resize);
4664 if (resize.relocations)
4665 relocate_inodes(&resize);
4667 truncate_badclust_file(&resize);
4668 truncate_bitmap_file(&resize);
4669 delayed_updates(&resize);
4670 update_bootsector(&resize);
4686 if (resize.shrink)
4688 if (resize.lcn_bitmap.bm)
4689 free(resize.lcn_bitmap.bm);