]> err.no Git - util-linux/commitdiff
libblkid: don't return error on empty files
authorKarel Zak <kzak@redhat.com>
Thu, 4 Feb 2010 21:19:38 +0000 (22:19 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 16 Feb 2010 08:58:57 +0000 (09:58 +0100)
Currently, the library does not allow to initialize blkid_probe if the
file (or block device) is empty. The empty file is reported as an
error. That's wrong. The empty file should be interpreted as a file
without any FS or PT. It means that

blkid_do_{probe,safeprobe,fullprobe}()

have to return 1 ("nothing").

Reported-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/partitions/partitions.c
shlibs/blkid/src/probe.c
shlibs/blkid/src/superblocks/superblocks.c

index 154365d79d63829674fab720f83112ef9f055a1f..e8d0311371dc1d3b6fc45007037dd4c473f2210f 100644 (file)
@@ -505,7 +505,7 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id)
        int hasmag = 0;
        int rc = 1;             /* = nothing detected */
 
-       if (id->minsz && id->minsz > pr->size)
+       if (pr->size <= 0 || (id->minsz && id->minsz > pr->size))
                goto nothing;   /* the device is too small */
 
        mag = id->magics ? &id->magics[0] : NULL;
index 91366851e34ee7ed6936565787742a695cbc4ce7..e78458162cad4899be4a1f6e53477dd057385f05 100644 (file)
@@ -289,7 +289,7 @@ void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn)
 {
        int rc;
 
-       if (!pr && !chn)
+       if (!pr || !chn)
                return NULL;
 
        pr->cur_chain = chn;
@@ -465,6 +465,9 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr,
        struct list_head *p;
        struct blkid_bufinfo *bf = NULL;
 
+       if (pr->size <= 0)
+               return NULL;
+
        list_for_each(p, &pr->buffers) {
                struct blkid_bufinfo *x =
                                list_entry(p, struct blkid_bufinfo, bufs);
@@ -605,8 +608,6 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
                pr->size -= pr->off;
        }
 
-       if (!pr->size)
-               goto err;
        DBG(DEBUG_LOWPROBE, printf("ready for low-probing, offset=%zd, size=%zd\n",
                                pr->off, pr->size));
 
@@ -648,6 +649,10 @@ int blkid_probe_set_dimension(blkid_probe pr,
 
        pr->off = off;
        pr->size = size;
+       pr->flags &= ~BLKID_TINY_DEV;
+
+       if (pr->size <= 1440 * 1024 && !S_ISCHR(pr->mode))
+               pr->flags |= BLKID_TINY_DEV;
 
        blkid_probe_reset_buffer(pr);
 
index 689f31bd7b85dbd86a7b73dcb2afd595f5c035ef..932701a8aa0e54197ff97e96fb856beebdcca9cb 100644 (file)
@@ -310,7 +310,7 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                printf("--> starting probing loop [SUBLKS idx=%d]\n",
                chn->idx));
 
-       if (pr->size <= 1024 && !S_ISCHR(pr->mode))
+       if (pr->size <= 0 || (pr->size <= 1024 && !S_ISCHR(pr->mode)))
                /* Ignore very very small block devices or regular files (e.g.
                 * extended partitions). Note that size of the UBI char devices
                 * is 1 byte */