OSDN Git Service

tests: add FS-resize test driver
authorChristoph Hellwig <hch@lst.de>
Fri, 3 Feb 2012 16:57:45 +0000 (17:57 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 10 Feb 2012 19:05:49 +0000 (20:05 +0100)
* tests/fs-resize.c: New file, to test FAT/HFS resizing.

tests/fs-resize.c [new file with mode: 0644]

diff --git a/tests/fs-resize.c b/tests/fs-resize.c
new file mode 100644 (file)
index 0000000..90bb4c3
--- /dev/null
@@ -0,0 +1,76 @@
+
+#include <config.h>
+#include <stdbool.h>
+
+#include "closeout.h"
+#include "configmake.h"
+
+#include <parted/parted.h>
+#include <parted/debug.h>
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include "xalloc.h"
+
+int main(int argc, char **argv)
+{
+       PedSector start = 0, len = 0;
+       PedGeometry geom, new_geom;
+       PedDevice *dev;
+       PedFileSystem *fs;
+       PedTimer *g_timer = NULL;
+
+       if (argc != 2 && argc != 4) {
+               fprintf(stderr, "usage: %s <device>\n"
+                               "       %s <device> <start> <length>\n",
+                               argv[0], argv[0]);
+               return 1;
+       }
+
+       dev = ped_device_get(argv[1]);
+       if (!dev) {
+               fprintf(stderr, "cannot create device %s\n", argv[1]);
+               return 1;
+       }
+
+       if (!ped_device_open(dev)) {
+               fprintf(stderr, "cannot open device %s\n", argv[1]);
+               return 1;
+       }
+
+       if (!ped_geometry_init(&geom, dev, 0, dev->length)) {
+               fprintf(stderr, "cannot initialize geometry\n");
+               return 1;
+       }
+
+       if (argc > 2) {
+               start = strtoll(argv[2], NULL, 0);
+               len = strtoll(argv[3], NULL, 0);
+       } else {
+               start = 0;
+               len = dev->length;
+       }
+
+       if (!ped_geometry_init(&new_geom, dev, start, len)) {
+               fprintf(stderr, "cannot initialize new geometry\n");
+               return 1;
+       }
+
+       fs = ped_file_system_open(&geom);
+       if (!fs) {
+               fprintf(stderr, "cannot read fs\n");
+               return 1;
+       }
+
+       if (!ped_file_system_resize(fs, &new_geom, g_timer)) {
+               fprintf(stderr, "cannot resize filesystem\n");
+               return 1;
+       }
+
+       ped_file_system_close(fs);
+       return 0;
+}