Whamcloud - gitweb
ChangeLog, get_device_by_label.c:
authorTheodore Ts'o <tytso@mit.edu>
Tue, 26 Oct 1999 14:38:36 +0000 (14:38 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 26 Oct 1999 14:38:36 +0000 (14:38 +0000)
  get_device_by_label.c (has_right_label): Fixed bug where code used a
   strncmp to compare a binary UUID value which may contain a NULL.
   Fixed GCC warnings; added const to char * typed variables.  Eliminated
   non-portable use of u_char.

misc/ChangeLog
misc/get_device_by_label.c

index 4a936fa..6133fb3 100644 (file)
@@ -1,5 +1,10 @@
 1999-10-26    <tytso@valinux.com>
 
+       * get_device_by_label.c (has_right_label): Fixed bug where code
+               used a strncmp to compare a binary UUID value which may
+               contain a NULL.  Fixed GCC warnings; added const to char *
+               typed variables.  Eliminated non-portable use of u_char.
+
        * mke2fs.c (PRS): Fix gcc warnings; add const to some char *
                variables, including in struct mke2fs_defaults.
 
index 64bda02..cfb49f5 100644 (file)
 
 #define EXT2_SUPER_MAGIC    0xEF53
 struct ext2_super_block {
-        u_char   s_dummy1[56];
-        u_char   s_magic[2];
-        u_char   s_dummy2[46];
-        u_char   s_uuid[16];
-        u_char   s_volume_name[16];
+        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];
 };
-#define ext2magic(s)    ((uint) s.s_magic[0] + (((uint) s.s_magic[1]) << 8))
+#define ext2magic(s)    ((unsigned int) s.s_magic[0] + (((unsigned int) s.s_magic[1]) << 8))
 
 
 static FILE *procpt;
@@ -73,11 +73,10 @@ procptnext(void) {
 
 /* for now, only ext2 is supported */
 static int
-has_right_label(const char *device, int n, const char *label) {
+has_right_label(const char *device, int n, const void *label) {
 
        /* start with a test for ext2, taken from mount_guess_fstype */
        int fd;
-       char *s;
        struct ext2_super_block e2sb;
 
        fd = open(device, O_RDONLY);
@@ -94,12 +93,15 @@ has_right_label(const char *device, int n, const char *label) {
        close(fd);
 
        /* superblock is ext2 - now what is its label? */
-       s = ((n == UUID) ? e2sb.s_uuid : e2sb.s_volume_name);
-       return (strncmp(s, label, 16) == 0);
+       if (n == UUID)
+               return (memcmp(e2sb.s_uuid, label, 16) == 0);
+       else
+               return (strncmp(e2sb.s_volume_name,
+                               (const char *) label, 16) == 0);
 }
 
 static char *
-get_spec_by_x(int n, const char *t) {
+get_spec_by_x(int n, const void *t) {
        char *pt;
        char device[110];
 
@@ -124,7 +126,7 @@ get_spec_by_x(int n, const char *t) {
        return NULL;
 }
 
-static u_char
+static unsigned char
 fromhex(char c) {
        if (isdigit(c))
                return (c - '0');
@@ -136,7 +138,7 @@ fromhex(char c) {
 
 char *
 get_spec_by_uuid(const char *s0) {
-       u_char uuid[16];
+       unsigned char uuid[16];
        int i;
        const char *s = s0;