From d0465c3c00f75d7247cbbf02c1b3ff879c3f7bd3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 19 Jan 2010 13:43:39 +0100 Subject: [PATCH] libblkid: read whole SB buffer (69kB) on large disks - on large disks read whole SB buffer - new blkid_probe_is_tiny() version based on flags Signed-off-by: Karel Zak --- shlibs/blkid/src/blkidP.h | 3 +++ shlibs/blkid/src/probe.c | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h index 55850349..fb40505b 100644 --- a/shlibs/blkid/src/blkidP.h +++ b/shlibs/blkid/src/blkidP.h @@ -204,6 +204,7 @@ struct blkid_struct_probe /* flags */ #define BLKID_PRIVATE_FD (1 << 1) /* see blkid_new_probe_from_filename() */ +#define BLKID_TINY_DEV (1 << 2) /* <= 1.47MiB (floppy or so) */ /* * Evaluation methods (for blkid_eval_* API) @@ -359,6 +360,8 @@ extern void blkid_free_dev(blkid_dev dev); /* probe.c */ extern int blkid_probe_is_tiny(blkid_probe pr); +extern int blkid_probe_has_buffer(blkid_probe pr, + blkid_loff_t off, blkid_loff_t len); extern unsigned char *blkid_probe_get_buffer(blkid_probe pr, blkid_loff_t off, blkid_loff_t len); extern unsigned char *blkid_probe_get_extra_buffer(blkid_probe pr, diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index b2c96a6b..1bd98b55 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -470,7 +470,7 @@ int __blkid_probe_filter_types(blkid_probe pr, int chain, int flag, char *names[ return 0; } -static int blkid_probe_has_buffer(blkid_probe pr, +int blkid_probe_has_buffer(blkid_probe pr, blkid_loff_t off, blkid_loff_t len) { return pr && (off + len <= pr->sbbuf_len || @@ -494,14 +494,20 @@ static unsigned char *blkid_probe_get_sb_buffer(blkid_probe pr, /* * The sbbuf is not completely in memory. * - * We don't read whole BLKID_SB_BUFSIZ by one read(), it's too - * aggresive to small devices (floppies). We read necessary - * data to complete the current request (off + len) only. */ ssize_t ret_read; - - blkid_loff_t have = pr->sbbuf_len, - want = off + len - have; + blkid_loff_t want, have = pr->sbbuf_len; + + if (blkid_probe_is_tiny(pr)) + /* We don't read whole BLKID_SB_BUFSIZ by one read(), + * it's too aggresive to small devices (floppies). We + * read necessary data to complete the current request + * (off + len) only. + */ + want = off + len - have; + else + /* large disk -- read all SB */ + want = BLKID_SB_BUFSIZ - have; DBG(DEBUG_LOWPROBE, printf("\tsb-buffer read() off=%jd len=%jd\n", have, want)); @@ -606,7 +612,7 @@ unsigned char *blkid_probe_get_buffer(blkid_probe pr, */ int blkid_probe_is_tiny(blkid_probe pr) { - return (pr && pr->size <= 1440 * 1024 && !S_ISCHR(pr->mode)); + return pr && (pr->flags & BLKID_TINY_DEV); } /** @@ -676,6 +682,10 @@ int blkid_probe_set_device(blkid_probe pr, int fd, goto err; DBG(DEBUG_LOWPROBE, printf("ready for low-probing, offset=%zd, size=%zd\n", pr->off, pr->size)); + + if (pr->size <= 1440 * 1024 && !S_ISCHR(pr->mode)) + pr->flags |= BLKID_TINY_DEV; + return 0; err: DBG(DEBUG_LOWPROBE, -- 2.39.5