Lines Matching defs:resize

9  * This utility will resize an NTFS volume without data loss.
125 "* run 'chkdsk /f /r' on Windows and rebooot it TWICE! Then you can resize *\n"
587 printf("You might resize at %lld bytes ", (long long)new_b);
648 static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl)
658 inode = resize->ni->mft_no;
659 flags = resize->ctx->attr->flags;
660 atype = resize->ctx->attr->type;
662 if ((ret = ntfs_inode_badclus_bad(inode, resize->ctx->attr)) != 0) {
669 llcn = &resize->last_lcn;
670 if (atype == AT_DATA && NInoAttrList(resize->ni))
676 llcn = &resize->last_mft;
683 } else if (NInoAttrList(resize->ni)) {
684 llcn = &resize->last_multi_mft;
690 llcn = &resize->last_sparse;
694 llcn = &resize->last_compressed;
698 llcn = &resize->last_mftmir;
706 llcn = &resize->last_lcn;
718 if (resize->last_unsupp < last_lcn)
719 resize->last_unsupp = last_lcn;
723 static void collect_relocation_info(ntfs_resize_t *resize, runlist *rl)
730 inode = resize->ni->mft_no;
731 new_vol_size = resize->new_volume_size;
736 if (inode == FILE_Bitmap && resize->ctx->attr->type == AT_DATA)
749 print_advise(resize->vol, lcn + lcn_length - 1);
754 resize->relocations += len;
756 if (!opt.info || !resize->new_volume_size)
761 (unsigned int)le32_to_cpu(resize->ctx->attr->type),
1046 static void build_resize_constraints(ntfs_resize_t *resize)
1051 if (!resize->ctx->attr->non_resident)
1054 if (!(rl = ntfs_mapping_pairs_decompress(resize->vol,
1055 resize->ctx->attr, NULL)))
1063 collect_resize_constraints(resize, rl + i);
1064 if (resize->shrink)
1065 collect_relocation_info(resize, rl + i);
1070 static void resize_constraints_by_attributes(ntfs_resize_t *resize)
1072 if (!(resize->ctx = attr_get_search_ctx(resize->ni, NULL)))
1075 while (!ntfs_attrs_walk(resize->ctx)) {
1076 if (resize->ctx->attr->type == AT_END)
1078 build_resize_constraints(resize);
1081 ntfs_attr_put_search_ctx(resize->ctx);
1084 static void set_resize_constraints(ntfs_resize_t *resize)
1091 nr_mft_records = resize->vol->mft_na->initialized_size >>
1092 resize->vol->mft_record_size_bits;
1096 ni = ntfs_inode_open(resize->vol, (MFT_REF)inode);
1106 resize->ni = ni;
1107 resize_constraints_by_attributes(resize);
1417 static void copy_clusters(ntfs_resize_t *resize, s64 dest, s64 src, s64 len)
1421 ntfs_volume *vol = resize->vol;
1443 resize->relocations++;
1444 progress_update(&resize->progress, resize->relocations);
1528 static void relocate_run(ntfs_resize_t *resize, runlist **rl, int run)
1537 new_vol_size = resize->new_volume_size;
1547 hint = (resize->mref == FILE_MFTMirr) ? 1 : 0;
1548 if (!(relocate_rl = alloc_cluster(&resize->lcn_bitmap, lcn_length,
1551 resize->mref, lcn_length);
1555 "--> 0x%08llx\n", (unsigned long long)resize->mref,
1556 (unsigned int)le32_to_cpu(resize->ctx->attr->type),
1562 relocate_clusters(resize, relocate_rl, lcn);
1569 resize->dirty_inode = DIRTY_ATTRIB;
1572 static void relocate_attribute(ntfs_resize_t *resize)
1578 a = resize->ctx->attr;
1583 if (!(rl = ntfs_mapping_pairs_decompress(resize->vol, a, NULL)))
1596 "%llx length %llx\n", resize->mref,
1600 relocate_run(resize, &rl, i);
1603 if (resize->dirty_inode == DIRTY_ATTRIB) {
1604 replace_attribute_runlist(resize->vol, resize->ctx, rl);
1605 resize->dirty_inode = DIRTY_INODE;
1611 static int is_mftdata(ntfs_resize_t *resize)
1613 if (resize->ctx->attr->type != AT_DATA)
1616 if (resize->mref == 0)
1619 if (MREF_LE(resize->mrec->base_mft_record) == 0 &&
1620 MSEQNO_LE(resize->mrec->base_mft_record) != 0)
1626 static int handle_mftdata(ntfs_resize_t *resize, int do_mftdata)
1628 ATTR_RECORD *attr = resize->ctx->attr;
1633 if (!is_mftdata(resize))
1639 if (resize->mft_highest_vcn != highest_vcn)
1643 resize->mft_highest_vcn = lowest_vcn;
1645 resize->mft_highest_vcn = lowest_vcn - 1;
1647 } else if (is_mftdata(resize)) {
1651 if (resize->mft_highest_vcn < highest_vcn)
1652 resize->mft_highest_vcn = highest_vcn;
1660 static void relocate_attributes(ntfs_resize_t *resize, int do_mftdata)
1664 if (!(resize->ctx = attr_get_search_ctx(NULL, resize->mrec)))
1667 while (!ntfs_attrs_walk(resize->ctx)) {
1668 if (resize->ctx->attr->type == AT_END)
1671 if (handle_mftdata(resize, do_mftdata) == 0)
1674 ret = ntfs_inode_badclus_bad(resize->mref, resize->ctx->attr);
1680 if (resize->mref == FILE_Bitmap &&
1681 resize->ctx->attr->type == AT_DATA)
1684 relocate_attribute(resize);
1687 ntfs_attr_put_search_ctx(resize->ctx);
1690 static void relocate_inode(ntfs_resize_t *resize, MFT_REF mref, int do_mftdata)
1692 if (ntfs_file_record_read(resize->vol, mref, &resize->mrec, NULL)) {
1700 if (!(resize->mrec->flags & MFT_RECORD_IN_USE))
1703 resize->mref = mref;
1704 resize->dirty_inode = DIRTY_NONE;
1706 relocate_attributes(resize, do_mftdata);
1708 if (resize->dirty_inode == DIRTY_INODE) {
1711 if (write_mft_record(resize->vol, mref, resize->mrec))
1716 static void relocate_inodes(ntfs_resize_t *resize)
1724 progress_init(&resize->progress, 0, resize->relocations, resize->progress.flags);
1725 resize->relocations = 0;
1727 resize->mrec = ntfs_malloc(resize->vol->mft_record_size);
1728 if (!resize->mrec)
1731 nr_mft_records = resize->vol->mft_na->initialized_size >>
1732 resize->vol->mft_record_size_bits;
1735 relocate_inode(resize, mref, 0);
1738 highest_vcn = resize->mft_highest_vcn;
1741 relocate_inode(resize, --mref, 1);
1742 if (resize->mft_highest_vcn == 0)
1746 if (highest_vcn == resize->mft_highest_vcn)
1751 free(resize->mrec);
1774 static void advise_on_resize(ntfs_resize_t *resize)
1776 ntfs_volume *vol = resize->vol;
1781 print_hint(vol, "$MFT", resize->last_mft);
1782 print_hint(vol, "Multi-Record", resize->last_multi_mft);
1783 print_hint(vol, "$MFTMirr", resize->last_mftmir);
1784 print_hint(vol, "Compressed", resize->last_compressed);
1785 print_hint(vol, "Sparse", resize->last_sparse);
1786 print_hint(vol, "Ordinary", resize->last_lcn);
1789 print_advise(vol, resize->last_unsupp);
1865 static void truncate_badclust_bad_attr(ntfs_resize_t *resize)
1869 s64 nr_clusters = resize->new_volume_size;
1870 ntfs_volume *vol = resize->vol;
1872 a = resize->ctx->attr;
1886 replace_attribute_runlist(vol, resize->ctx, rl_bad);
1897 static void realloc_bitmap_data_attr(ntfs_resize_t *resize,
1902 ntfs_volume *vol = resize->vol;
1903 ATTR_RECORD *a = resize->ctx->attr;
1904 s64 new_size = resize->new_volume_size;
1905 struct bitmap *bm = &resize->lcn_bitmap;
1920 static void realloc_lcn_bitmap(ntfs_resize_t *resize, s64 bm_bsize)
1924 if (!(tmp = realloc(resize->lcn_bitmap.bm, bm_bsize)))
1927 resize->lcn_bitmap.bm = tmp;
1928 resize->lcn_bitmap.size = bm_bsize;
1929 bitmap_file_data_fixup(resize->new_volume_size, &resize->lcn_bitmap);
1935 static void truncate_bitmap_data_attr(ntfs_resize_t *resize)
1941 ntfs_volume *vol = resize->vol;
1943 a = resize->ctx->attr;
1948 bm_bsize = nr_clusters_to_bitmap_byte_size(resize->new_volume_size);
1951 if (resize->shrink) {
1952 realloc_bitmap_data_attr(resize, &rl, nr_bm_clusters);
1953 realloc_lcn_bitmap(resize, bm_bsize);
1955 realloc_lcn_bitmap(resize, bm_bsize);
1956 realloc_bitmap_data_attr(resize, &rl, nr_bm_clusters);
1964 replace_attribute_runlist(vol, resize->ctx, rl);
1971 size = ntfs_rl_pwrite(vol, rl, 0, bm_bsize, resize->lcn_bitmap.bm);
2081 static void truncate_badclust_file(ntfs_resize_t *resize)
2085 lookup_data_attr(resize->vol, FILE_BadClus, "$Bad", &resize->ctx);
2087 truncate_badclust_bad_attr(resize);
2089 if (write_mft_record(resize->vol, resize->ctx->ntfs_ino->mft_no,
2090 resize->ctx->mrec))
2093 ntfs_attr_put_search_ctx(resize->ctx);
2101 static void truncate_bitmap_file(ntfs_resize_t *resize)
2105 lookup_data_attr(resize->vol, FILE_Bitmap, NULL, &resize->ctx);
2106 truncate_bitmap_data_attr(resize);
2108 if (write_mft_record(resize->vol, resize->ctx->ntfs_ino->mft_no,
2109 resize->ctx->mrec))
2112 ntfs_attr_put_search_ctx(resize->ctx);
2211 static void print_num_of_relocations(ntfs_resize_t *resize)
2213 s64 relocations = resize->relocations * resize->vol->cluster_size;
2216 (long long)resize->relocations, (long long)
2313 static void set_disk_usage_constraint(ntfs_resize_t *resize)
2316 s64 last = resize->inuse - 1;
2318 if (resize->last_unsupp < last)
2319 resize->last_unsupp = last;
2322 static void check_resize_constraints(ntfs_resize_t *resize)
2324 s64 new_size = resize->new_volume_size;
2326 /* FIXME: resize.shrink true also if only -i is used */
2327 if (!resize->shrink)
2330 if (resize->inuse == resize->vol->nr_clusters)
2338 if (new_size < resize->inuse)
2343 if (new_size <= resize->last_unsupp)
2349 print_num_of_relocations(resize);
2381 ntfs_resize_t resize;
2437 memset(&resize, 0, sizeof(resize));
2438 resize.vol = vol;
2439 resize.new_volume_size = new_size;
2442 resize.shrink = 1;
2444 resize.progress.flags |= NTFS_PROGBAR;
2450 resize.badclusters = check_bad_sectors(vol);
2456 resize.inuse = fsck.inuse;
2457 resize.lcn_bitmap = fsck.lcn_bitmap;
2459 set_resize_constraints(&resize);
2460 set_disk_usage_constraint(&resize);
2461 check_resize_constraints(&resize);
2464 advise_on_resize(&resize);
2476 if (resize.relocations)
2477 relocate_inodes(&resize);
2479 truncate_badclust_file(&resize);
2480 truncate_bitmap_file(&resize);
2481 update_bootsector(&resize);
2497 if (resize.shrink)