]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: refuse to initialize a misaligned device if not forced using libblkid
authorCarlos Maiolino <cmaiolino@redhat.com>
Tue, 6 Dec 2011 16:45:18 +0000 (14:45 -0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 8 Dec 2011 17:08:52 +0000 (17:08 +0000)
This is a new version of a patch to fix the problem about the usage of 4k
sector devices when the device is not properly aligned. It makes mkfs to
refuse to initialize a xfs filesystem if the -f option is not passed at the
command line, and forces a 512b sector size if the user chooses to force
the device initialization.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
mkfs/xfs_mkfs.c

index f527f3d52ee1af4c21f385746aa09372bec4944c..140837a64ce1fedc0b423d2fc07137a465fb3854 100644 (file)
@@ -369,8 +369,14 @@ out:
        return ret;
 }
 
-static void blkid_get_topology(const char *device, int *sunit, int *swidth, int *sectorsize)
+static void blkid_get_topology(
+       const char      *device,
+       int             *sunit,
+       int             *swidth,
+       int             *sectorsize,
+       int             force_overwrite)
 {
+
        blkid_topology tp;
        blkid_probe pr;
        unsigned long val;
@@ -409,6 +415,15 @@ static void blkid_get_topology(const char *device, int *sunit, int *swidth, int
                fprintf(stderr,
                        _("warning: device is not properly aligned %s\n"),
                        device);
+
+               if (!force_overwrite) {
+                       fprintf(stderr,
+                               _("Use -f to force usage of a misaligned device\n"));
+
+                       exit(EXIT_FAILURE);
+               }
+               /* force a 512b sector size if the device is misaligned */
+               *sectorsize = BBSIZE;
        }
 
        blkid_free_probe(pr);
@@ -421,19 +436,23 @@ out_free_probe:
                device);
 }
 
-static void get_topology(libxfs_init_t *xi, struct fs_topology *ft)
+static void get_topology(
+       libxfs_init_t           *xi,
+       struct fs_topology      *ft,
+       int                     force_overwrite)
 {
        if (!xi->disfile) {
                const char *dfile = xi->volname ? xi->volname : xi->dname;
 
                blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth,
-                                  &ft->sectorsize);
+                                  &ft->sectorsize, force_overwrite);
        }
 
        if (xi->rtname && !xi->risfile) {
                int dummy;
 
-               blkid_get_topology(xi->rtname, &dummy, &ft->rtswidth, &dummy);
+               blkid_get_topology(xi->rtname, &dummy, &ft->rtswidth,
+                                  &dummy, force_overwrite);
        }
 }
 #else /* ENABLE_BLKID */
@@ -460,8 +479,12 @@ check_overwrite(
        return 0;
 }
 
-static void get_topology(libxfs_init_t *xi, struct fs_topology *ft)
+static void get_topology(
+       libxfs_init_t           *xi,
+       struct fs_topology      *ft,
+       int                     force_overwrite)
 {
+
        char *dfile = xi->volname ? xi->volname : xi->dname;
        int bsz = BBSIZE;
 
@@ -1625,7 +1648,7 @@ main(
        }
 
        memset(&ft, 0, sizeof(ft));
-       get_topology(&xi, &ft);
+       get_topology(&xi, &ft, force_overwrite);
 
        if (ft.sectoralign) {
                /*