From: Karel Zak Date: Thu, 4 Feb 2010 21:19:38 +0000 (+0100) Subject: libblkid: don't return error on empty files X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c9cd53708c0aca63d9a8f507cb2eddb0478bcc7;p=util-linux libblkid: don't return error on empty files 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 Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c index 154365d7..e8d03113 100644 --- a/shlibs/blkid/src/partitions/partitions.c +++ b/shlibs/blkid/src/partitions/partitions.c @@ -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; diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index 91366851..e7845816 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -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); diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c index 689f31bd..932701a8 100644 --- a/shlibs/blkid/src/superblocks/superblocks.c +++ b/shlibs/blkid/src/superblocks/superblocks.c @@ -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 */