OSDN Git Service

fix >512-byte sector label/disk-test failure
authorJim Meyering <meyering@redhat.com>
Tue, 15 Jul 2008 10:51:25 +0000 (12:51 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 24 Jul 2009 13:04:41 +0000 (15:04 +0200)
* libparted/tests/disk.c: Include xstrtol.h.
(get_sector_size): New function: get sector size from the environment.
(create_disk): Use the new function to calculate a usable size,
rather than hard-coding the 512-byte-sector-specific size of 20MB.
* libparted/tests/common.c (_create_disk): Change meaning (and name)
of parameter to be size in bytes, not MiB.
Adjust callers.
* po/POTFILES.in: Add lib/xstrtol-error.c.

libparted/tests/common.c
libparted/tests/disk.c
libparted/tests/label.c
po/POTFILES.in

index f759745..b892ee3 100644 (file)
@@ -19,7 +19,7 @@ _test_exception_handler (PedException* e)
 }
 
 char*
-_create_disk (const off_t size)
+_create_disk (const off_t n_bytes)
 {
         char* filename = strdup ("parted-test-XXXXXX");
 
@@ -37,9 +37,7 @@ _create_disk (const off_t size)
         if (disk == NULL)
                 goto free_filename;
 
-        off_t total_size = size * 1024 * 1024; /* Mb */
-
-        int fail = (fseek (disk, total_size, SEEK_SET) != 0
+        int fail = (fseek (disk, n_bytes, SEEK_SET) != 0
                     || fwrite ("", sizeof (char), 1, disk) != 1);
 
         if (fclose (disk) != 0 || fail)
index 6e6d483..48561b9 100644 (file)
@@ -7,13 +7,28 @@
 
 #include "common.h"
 #include "progname.h"
+#include "xstrtol.h"
 
 static char* temporary_disk;
 
+static
+size_t get_sector_size (void)
+{
+  char *p = getenv ("PARTED_SECTOR_SIZE");
+  size_t ss = 512;
+  unsigned long val;
+  if (p
+      && xstrtoul (p, NULL, 10, &val, NULL) == LONGINT_OK
+      && val % 512 == 0)
+    ss = val;
+
+  return ss;
+}
+
 static void
 create_disk (void)
 {
-        temporary_disk = _create_disk (20);
+        temporary_disk = _create_disk (get_sector_size () * 4 * 10 * 1024);
         fail_if (temporary_disk == NULL, "Failed to create temporary disk");
 }
 
index fb61e2e..a1991e4 100644 (file)
@@ -15,7 +15,7 @@ static char* temporary_disk;
 static void
 create_disk (void)
 {
-        temporary_disk = _create_disk (20);
+        temporary_disk = _create_disk (20 * 1024 * 1024);
         fail_if (temporary_disk == NULL, "Failed to create temporary disk");
 }
 
index 8b2a9e2..33f4979 100644 (file)
@@ -1,5 +1,5 @@
 # libparted
-# Copyright (C) 1999-2001, 2006-2007, 2009  Free Software Foundation, Inc.
+# Copyright (C) 1999-2001, 2006-2009  Free Software Foundation, Inc.
 # This file may be modified and/or copied without restriction.
 
 # list of files containing translatable strings