[haiku-commits] haiku: hrev53387 - src/bin build/jam/images/definitions

  • From: Adrien Destugues <pulkomandy@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 20 Aug 2019 05:48:55 -0400 (EDT)

hrev53387 adds 1 changeset to branch 'master'
old head: a7536efa8b5eb96d1754fc1e7843ce280ed0251a
new head: 03867a467ec64d63c33301dad12fdae4ad746099
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=03867a467ec6+%5Ea7536efa8b5e

----------------------------------------------------------------------------

03867a467ec6: Add resizefs utility
  
  Change-Id: I5f503cf07216df64dcc33081f24cd083d003e581
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/943
  Reviewed-by: Jérôme Duval <jerome.duval@xxxxxxxxx>
  Reviewed-by: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
  Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

                                      [ ahenriksson <sausageboy@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53387
Commit:      03867a467ec64d63c33301dad12fdae4ad746099
URL:         https://git.haiku-os.org/haiku/commit/?id=03867a467ec6
Author:      ahenriksson <sausageboy@xxxxxxxxx>
Date:        Tue Jul 31 10:24:42 2012 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Tue Aug 20 09:48:51 2019 UTC

----------------------------------------------------------------------------

3 files changed, 131 insertions(+), 1 deletion(-)
build/jam/images/definitions/minimum |   3 +-
src/bin/Jamfile                      |   1 +
src/bin/resizefs.cpp                 | 128 +++++++++++++++++++++++++++++++

----------------------------------------------------------------------------

diff --git a/build/jam/images/definitions/minimum 
b/build/jam/images/definitions/minimum
index c9e7102593..3cd4b385dc 100644
--- a/build/jam/images/definitions/minimum
+++ b/build/jam/images/definitions/minimum
@@ -21,7 +21,8 @@ SYSTEM_BIN = [ FFilterByBuildFeatures
        open
        package package_repo passwd pc ping ping6 pkgman prio profile ps
        query quit
-       ramdisk rc reindex release renice resattr rmattr rmindex roster route
+       ramdisk rc reindex release renice resattr resizefs rmattr rmindex roster
+       route
        safemode screen_blanker screeninfo screenmode setarch setmime settype
        setversion setvolume shutdown
        strace su sysinfo system_time
diff --git a/src/bin/Jamfile b/src/bin/Jamfile
index 5bc5effa24..fe5c085315 100644
--- a/src/bin/Jamfile
+++ b/src/bin/Jamfile
@@ -128,6 +128,7 @@ StdBinCommands
 # standard commands that need libbe.so, libsupc++.so, and libshared.a
 StdBinCommands
        ramdisk.cpp
+       resizefs.cpp
        : shared be [ TargetLibsupc++ ] : $(haiku-utils_rsrc) ;
 
 # standard commands that need libbe.so, libbnetapi.so, libsupc++.so
diff --git a/src/bin/resizefs.cpp b/src/bin/resizefs.cpp
new file mode 100644
index 0000000000..59b325f167
--- /dev/null
+++ b/src/bin/resizefs.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2012, Andreas Henriksson, sausageboy@xxxxxxxxx.
+ * Copyright 2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <stdio.h>
+
+#include <DiskDevice.h>
+#include <DiskDeviceRoster.h>
+#include <DiskSystem.h>
+#include <StringForSize.h>
+
+
+extern "C" const char* __progname;
+static const char* kProgramName = __progname;
+
+
+int
+main(int argc, char** argv)
+{
+       if (argc != 3) {
+               fprintf(stderr, "Usage: %s <device> <size>\n",
+                       "Resize volume on <device> to new size <size> (in 
bytes, suffixes "
+                       "'k', 'm', 'g', 't' are interpreted as KiB, Mib, GiB, 
TiB).\n"
+                       kProgramName);
+               return 1;
+       }
+
+       int64 size = parse_size(argv[2]);
+       if (size <= 0) {
+               fprintf(stderr, "%s: The new size \"%s\" is not a number\n",
+                       kProgramName, argv[2]);
+               return 1;
+       }
+
+       BDiskDeviceRoster roster;
+       BPartition* partition;
+       BDiskDevice device;
+
+       status_t status = roster.GetPartitionForPath(argv[1], &device,
+               &partition);
+       if (status != B_OK) {
+               if (strncmp(argv[1], "/dev", 4)) {
+                       // try mounted volume
+                       status = roster.FindPartitionByMountPoint(argv[1], 
&device,
+                               &partition) ? B_OK : B_BAD_VALUE;
+               }
+
+               // TODO: try to register file device
+
+               if (status != B_OK) {
+                       fprintf(stderr, "%s: Failed to get disk device for path 
\"%s\": "
+                               "%s\n", kProgramName, argv[1], 
strerror(status));
+                       return 1;
+               }
+       }
+
+       // Prepare the device for modifications
+
+       status = device.PrepareModifications();
+       if (status != B_OK) {
+               fprintf(stderr, "%s: Could not prepare the device for 
modifications: "
+                       "%s\n", kProgramName, strerror(status));
+               return false;
+       }
+
+       // Check if the partition supports resizing
+
+       bool canResizeWhileMounted;
+       bool canResize = partition->CanResize(NULL, &canResizeWhileMounted);
+
+       if (!canResize && !canResizeWhileMounted) {
+               fprintf(stderr, "%s: The disk system does not support 
resizing.\n",
+                       kProgramName);
+               return 1;
+       }
+
+       if (partition->IsMounted() && !canResizeWhileMounted) {
+               fprintf(stderr, "%s: The disk system does not support resizing 
a "
+                       "mounted volume.\n", kProgramName);
+               return 1;
+       }
+       if (!partition->IsMounted() && !canResize) {
+               fprintf(stderr, "%s: The disk system does not support resizing 
a "
+                       "volume that is not mounted.\n", kProgramName);
+               return 1;
+       }
+
+       // Validate the requested size
+
+       off_t validatedSize = size;
+       status = partition->ValidateResize(&validatedSize);
+       if (status != B_OK) {
+               fprintf(stderr, "%s: Failed to validate the size: %s\n", 
kProgramName,
+                       strerror(status));
+               return 1;
+       }
+
+       if (validatedSize != size) {
+               printf("The requested size (%" B_PRId64 " bytes) was not 
accepted.\n"
+                       "Resize to %" B_PRId64 " bytes instead? (y/N): ", size,
+                       (int64)validatedSize);
+
+               int c = getchar();
+               if (c != 'y')
+                       return 0;
+       }
+
+       // Resize the volume
+
+       status = partition->Resize(validatedSize);
+       if (status != B_OK) {
+               fprintf(stderr, "%s: Resizing failed: %s\n", kProgramName,
+                       strerror(status));
+               return 1;
+       }
+
+       status = device.CommitModifications();
+       if (status != B_OK) {
+               fprintf(stderr, "%s: Failed to commit modifications: %s\n",
+                       kProgramName, strerror(status));
+               return 1;
+       }
+
+       return 0;
+}


Other related posts:

  • » [haiku-commits] haiku: hrev53387 - src/bin build/jam/images/definitions - Adrien Destugues