Changes by: szaka
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv17139/ntfstools
Modified Files:
ntfsresize.c
Log Message:
"Calculate the smallest shrinked volume size supported" option added
Index: ntfsresize.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsresize.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -U2 -r1.16 -r1.17
--- ntfsresize.c 16 Jul 2002 10:17:05 -0000 1.16
+++ ntfsresize.c 16 Jul 2002 13:26:42 -0000 1.17
@@ -50,4 +50,5 @@
int ro_flag;
int force;
+ int info;
s64 size;
char *volume;
@@ -109,11 +110,12 @@
void usage(char *s)
{
- printf ("Usage: %s [-fhnv] [-c clusters] device\n", s);
- printf (" -c clusters New NTFS size in clusters\n");
- Dprintf(" -d Show debug information\n");
- printf (" -f Force to progress (DANGEROUS)\n");
- printf (" -h This help text\n");
- printf (" -n No write operations (read-only mode)\n");
- printf (" -v Verbose operation\n");
+ printf ("Usage: %s [-fhinv] [-c clusters] device\n", s);
+ printf (" -c clusters Shrink volume to new size given in clusters\n");
+ Dprintf(" -d Show debug information\n");
+ printf (" -f Force to progress (DANGEROUS)\n");
+ printf (" -h This help text\n");
+ printf (" -i Calculate the smallest shrinked volume size\n");
+ printf (" -n No write operations (read-only mode)\n");
+ printf (" -v Verbose operation\n");
exit(1);
}
@@ -127,5 +129,5 @@
memset(&opt, 0, sizeof(opt));
- while ((i = getopt(argc, argv, "c:dfhnv")) != EOF)
+ while ((i = getopt(argc, argv, "c:dfhinv")) != EOF)
switch (i) {
case 'c':
@@ -142,4 +144,7 @@
case 'h':
usage(argv[0]);
+ case 'i':
+ opt.info = 1;
+ break;
case 'n':
opt.ro_flag = MS_RDONLY;
@@ -162,8 +167,16 @@
perr_exit("Couldn't open /dev/null");
- /* If '-c clusters' isn't given then we mount read-only. opt.size = 0
- basically means "give advice where volume could be resized. */
+ /* If no '-c clusters' then estimate smallest shrinked volume size */
if (!opt.size)
+ opt.info = 1;
+
+ if (opt.info) {
+ if (opt.size) {
+ printf(NERR_PREFIX "It makes no sense to use both "
+ "-i and -c at the same time.\n");
+ usage(argv[0]);
+ }
opt.ro_flag = MS_RDONLY;
+ }
}
@@ -329,15 +342,22 @@
u64 i;
- printf(NERR_PREFIX "Fragmented volume not yet supported. "
- "Defragment it before resize.\n");
-
for (i = vol->nr_clusters - 1; i > 0; i--)
if (ntfs_get_bit(lcn_bitmap.bm, i))
break;
+
i += 2; /* first free + we reserve one for the backup boot sector */
- if (i >= vol->nr_clusters)
+ if (i >= vol->nr_clusters) {
+ if (opt.info)
+ printf("The volume end is fragmented. "
+ "This case isn't yet supported.\n");
exit(1);
- err_exit("However, you could resize at cluster %lld gaining %lld MB.\n",
+ }
+
+ if (!opt.info)
+ printf(NERR_PREFIX "However, ");
+
+ printf("You could resize at cluster %lld gaining %lld MB.\n",
i, ((vol->nr_clusters - i) * vol->cluster_size) >> 20);
+ exit(1);
}
@@ -698,8 +718,14 @@
exit(0);
+ if (opt.info)
+ advise_on_resize();
+
for (i = new_volume_size; i < vol->nr_clusters; i++)
- if (ntfs_get_bit(lcn_bitmap.bm, (u64)i))
+ if (ntfs_get_bit(lcn_bitmap.bm, (u64)i)) {
/* FIXME: relocate cluster */
+ printf(NERR_PREFIX "Fragmented volume not yet "
+ "supported. Defragment it before resize.\n");
advise_on_resize();
+ }
/* FIXME: first do all checks before any write attempt */
|