]> git.wh0rd.org - dump.git/blobdiff - compat/lib/bylabel.c
Make configure understand CPPFLAGS=, CFLAGS=, LDFLAGS=...
[dump.git] / compat / lib / bylabel.c
index 065d52985c5629ec810e53f2ae46953bf045b4c1..7f710ed7655e7196cef4a528cb5c92a242dc48e9 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <config.h>
+#include <compatlfs.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <string.h>
 #define EXT2_SUPER_SIZE                sizeof(struct ext2_super_block)
 #define EXT2_SUPER_MAGIC       0xEF53
 
+#define VOLNAMSZ       16
+
 struct ext2_super_block {
        unsigned char   s_dummy1[56];
        unsigned char   s_magic[2];
        unsigned char   s_dummy2[46];
        unsigned char   s_uuid[16];
-       unsigned char   s_volume_name[16];
+       unsigned char   s_volume_name[VOLNAMSZ];
 };
 #define ext2magic(s)   ((unsigned int) s.s_magic[0] + (((unsigned int) s.s_magic[1]) << 8))
 
@@ -55,11 +58,11 @@ get_label_uuid(const char *device, char **label, char *uuid) {
        int fd;
        struct ext2_super_block e2sb;
 
-       fd = open(device, O_RDONLY);
+       fd = OPEN(device, O_RDONLY);
        if (fd < 0)
                return 1;
 
-       if (lseek(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET ||
+       if (LSEEK(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET ||
            read(fd, (char *) &e2sb, EXT2_SUPER_SIZE) != EXT2_SUPER_SIZE ||
            ext2magic(e2sb) != EXT2_SUPER_MAGIC) {
                close(fd);
@@ -70,7 +73,9 @@ get_label_uuid(const char *device, char **label, char *uuid) {
 
        /* superblock is ext2 - now what is its label? */
        memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid));
-       *label = strdup(e2sb.s_volume_name);
+       *label = malloc(VOLNAMSZ + 1);
+       strncpy(*label, e2sb.s_volume_name, VOLNAMSZ);
+       (*label)[VOLNAMSZ] = 0;
 
        return 0;
 }