]> err.no Git - util-linux/commitdiff
libblkid: read whole SB buffer (69kB) on large disks
authorKarel Zak <kzak@redhat.com>
Tue, 19 Jan 2010 12:43:39 +0000 (13:43 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 19 Jan 2010 13:48:22 +0000 (14:48 +0100)
 - on large disks read whole SB buffer
 - new blkid_probe_is_tiny() version based on flags

Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/probe.c

index 55850349a7878508718f778c68d29b615cb4eb84..fb40505beaaa39693165e931ebfbc7dc0f7b3ff4 100644 (file)
@@ -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,
index b2c96a6b2477432c3aaf0c7d4d93ef72dff5323c..1bd98b55da722c5240ab0867cc6165e21e8aa500 100644 (file)
@@ -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,