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.
#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;
/* 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);
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];
return NULL;
}
-static u_char
+static unsigned char
fromhex(char c) {
if (isdigit(c))
return (c - '0');
char *
get_spec_by_uuid(const char *s0) {
- u_char uuid[16];
+ unsigned char uuid[16];
int i;
const char *s = s0;