[PATCH 1/2] mkfs.minix: add sectorsize check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Minix filesystem until version 2 has a fixed blocksize of 1024 bytes.
If you try to create a filsystem on a device with a physical sectorsize
larger than 1024 bytes, this resulting minix fs cannot be mounted,
because the physical sectorsize must be smaller than the filesystem
blocksize.
This patch adds a check for this and will refuse to create a filesystem
if the sectorsize is bigger than the blocksize.

Signed-off-by: Matthias Koenig <mkoenig@xxxxxxx>
---

 disk-utils/Makefile.am  |    4 +++-
 disk-utils/mkfs.minix.c |   12 ++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am
index eadc89d..063a551 100644
--- a/disk-utils/Makefile.am
+++ b/disk-utils/Makefile.am
@@ -1,11 +1,13 @@
 include $(top_srcdir)/config/include-Makefile.am
 
+utils_common = ../lib/linux_version.c ../lib/blkdev.c
+
 man_MANS = blockdev.8 isosize.8 mkfs.8 mkswap.8 \
            fsck.minix.8 mkfs.minix.8 mkfs.bfs.8
 
 sbin_PROGRAMS = mkfs mkswap blockdev fsck.minix mkfs.minix mkfs.bfs
 fsck_minix_SOURCES = fsck.minix.c bitops.h minix.h
-mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h
+mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h $(utils_common)
 mkfs_bfs_SOURCES = mkfs.bfs.c
 mkswap_SOURCES = mkswap.c swapheader.h ../lib/linux_version.c ../lib/blkdev.c
 blockdev_SOURCES = blockdev.c ../lib/linux_version.c ../lib/blkdev.c
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index 7cd0958..6fc2893 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -72,6 +72,7 @@
 #include <mntent.h>
 #include <getopt.h>
 
+#include "blkdev.h"
 #include "minix.h"
 #include "nls.h"
 
@@ -710,9 +711,16 @@ main(int argc, char ** argv) {
     DEV = open(device_name,O_RDWR);
   if (DEV<0)
     die(_("unable to open %s"));
-  if (!S_ISBLK(statbuf.st_mode))
+  if (S_ISBLK(statbuf.st_mode)) {
+    int sectorsize;
+
+    if (blkdev_get_sector_size(DEV, &sectorsize) == -1)
+	    die(_("cannot determine sector size for %s"));
+    if (BLOCK_SIZE < sectorsize)
+	    die(_("block size smaller than physical sector size of %s"));
+  } else if (!S_ISBLK(statbuf.st_mode)) {
     check=0;
-  else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
+  } else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
     die(_("will not try to make filesystem on '%s'"));
   setup_tables();
   if (check)

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux