]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
isosize: inform if file does not look like iso file system
authorSami Kerola <kerolasa@iki.fi>
Sun, 16 Dec 2012 10:43:54 +0000 (10:43 +0000)
committerKarel Zak <kzak@redhat.com>
Wed, 19 Dec 2012 10:05:04 +0000 (11:05 +0100)
$ isosize /dev/urandom
isosize: /dev/urandom: might not be iso file system
-67690643227260

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/isosize.c

index 625dd427e7baaf1fc5ff9ff5f884891d0395d5ca..5f1a2971cec085dca14727772f5b4433f6228f1d 100644 (file)
 
 #define ISODCL(from, to) (to - from + 1)
 
+static int is_iso(int fd)
+{
+       char label[8];
+       if (pread(fd, &label, 8, 0x8000) == -1)
+               return 1;
+       return memcmp(&label, &"\1CD001\1", 8);
+}
+
 static int isonum_721(unsigned char *p)
 {
        return ((p[0] & 0xff)
@@ -124,6 +132,8 @@ static void isosize(char *filenamep, int xflag, long divisor)
 
        if ((fd = open(filenamep, O_RDONLY)) < 0)
                err(EXIT_FAILURE, _("cannot open %s"), filenamep);
+       if (is_iso(fd))
+               warnx(_("%s: might not be iso file system"), filenamep);
 
        if (lseek(fd, 16 << 11, 0) == (off_t) - 1)
                err(EXIT_FAILURE, _("seek error on %s"), filenamep);