extlinux: early check for ext2/ext3-ness of filesystem syslinux-3.61-pre5
authorH. Peter Anvin <hpa@zytor.com>
Thu, 24 Jan 2008 22:22:29 +0000 (14:22 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 24 Jan 2008 22:22:29 +0000 (14:22 -0800)
Verify that we have an ext2 or ext3 filesystem early on.

extlinux/extlinux.c

index 58261b4..742859a 100644 (file)
@@ -36,6 +36,7 @@ typedef uint64_t u64;
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/mount.h>
+#include <sys/vfs.h>
 
 #include <linux/fd.h>          /* Floppy geometry */
 #include <linux/hdreg.h>       /* Hard disk geometry */
@@ -804,6 +805,7 @@ install_loader(const char *path, int update_only)
   struct stat st, fst;
   int devfd, rv;
   const char *devname = NULL;
+  struct statfs sfs;
 #ifndef __KLIBC__
   struct mntent *mnt = NULL;
   struct stat dst;
@@ -815,6 +817,16 @@ install_loader(const char *path, int update_only)
     return 1;
   }
 
+  if ( statfs(path, &sfs) ) {
+    fprintf(stderr, "%s: statfs %s: %s\n", program, path, strerror(errno));
+    return 1;
+  }
+
+  if ( sfs.f_type != EXT2_SUPER_MAGIC ) {
+    fprintf(stderr, "%s: not an ext2/ext3 filesystem: %s\n", program, path);
+    return 1;
+  }
+
   devfd = -1;
 
 #ifdef __KLIBC__