Lines 37-75
Link Here
|
37 |
int major, minor; |
37 |
int major, minor; |
38 |
} *uuidCache = NULL; |
38 |
} *uuidCache = NULL; |
39 |
|
39 |
|
40 |
/* for now, only ext2, ext3 and xfs are supported */ |
40 |
typedef int (*GetLabelUuidProc)(int fd, char **label, char *uuid); |
41 |
static int |
|
|
42 |
get_label_uuid(const char *device, char **label, char *uuid) { |
43 |
|
41 |
|
44 |
/* start with ext2/3 and xfs tests, taken from mount_guess_fstype */ |
42 |
static int get_label_uuid_ext2(int fd, char **label, char *uuid); |
45 |
/* should merge these later */ |
43 |
static int get_label_uuid_xfs(int fd, char **label, char *uuid); |
46 |
int fd; |
44 |
static int get_label_uuid_reiserfs(int fd, char **label, char *uuid); |
47 |
int rv = 1; |
45 |
|
48 |
size_t namesize; |
46 |
/* for now, only ext2, ext3, reiserfs and xfs are supported */ |
|
|
47 |
static const |
48 |
GetLabelUuidProc get_label_uuid_proc_table[] = |
49 |
{ |
50 |
get_label_uuid_ext2, |
51 |
get_label_uuid_reiserfs, |
52 |
get_label_uuid_xfs, |
53 |
NULL |
54 |
}; |
55 |
|
56 |
static int |
57 |
get_label_uuid_ext2(int fd, char **label, char *uuid) |
58 |
{ |
49 |
struct ext2_super_block e2sb; |
59 |
struct ext2_super_block e2sb; |
50 |
struct xfs_super_block xfsb; |
60 |
if ( ( lseek(fd, 1024, SEEK_SET) == 1024 ) |
51 |
|
61 |
&& read(fd, (char *) &e2sb, sizeof(e2sb)) == sizeof(e2sb) |
52 |
fd = open(device, O_RDONLY); |
62 |
&& (ext2magic(e2sb) == EXT2_SUPER_MAGIC)) { |
53 |
if (fd < 0) |
63 |
size_t namesize; |
54 |
return rv; |
|
|
55 |
|
56 |
if (lseek(fd, 1024, SEEK_SET) == 1024 |
57 |
&& read(fd, (char *) &e2sb, sizeof(e2sb)) == sizeof(e2sb) |
58 |
&& (ext2magic(e2sb) == EXT2_SUPER_MAGIC)) { |
59 |
memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid)); |
64 |
memcpy(uuid, e2sb.s_uuid, sizeof(e2sb.s_uuid)); |
60 |
namesize = sizeof(e2sb.s_volume_name); |
65 |
namesize = sizeof(e2sb.s_volume_name); |
61 |
if ((*label = calloc(namesize + 1, 1)) != NULL) |
66 |
if ((*label = calloc(namesize + 1, 1)) != NULL) |
62 |
memcpy(*label, e2sb.s_volume_name, namesize); |
67 |
memcpy(*label, e2sb.s_volume_name, namesize); |
63 |
rv = 0; |
68 |
return 0; |
64 |
} |
69 |
} |
65 |
else if (lseek(fd, 0, SEEK_SET) == 0 |
70 |
return 1; |
66 |
&& read(fd, (char *) &xfsb, sizeof(xfsb)) == sizeof(xfsb) |
71 |
} |
67 |
&& (strncmp(xfsb.s_magic, XFS_SUPER_MAGIC, 4) == 0)) { |
72 |
|
|
|
73 |
static int |
74 |
get_label_uuid_xfs(int fd, char **label, char *uuid) |
75 |
{ |
76 |
struct xfs_super_block xfsb; |
77 |
if ( (lseek(fd, 0, SEEK_SET) == 0) |
78 |
&& (read(fd, (char *) &xfsb, sizeof(xfsb)) == sizeof(xfsb) ) |
79 |
&& (strncmp((const char*)xfsb.s_magic, XFS_SUPER_MAGIC, 4) == 0) ) { |
80 |
size_t namesize; |
68 |
memcpy(uuid, xfsb.s_uuid, sizeof(xfsb.s_uuid)); |
81 |
memcpy(uuid, xfsb.s_uuid, sizeof(xfsb.s_uuid)); |
69 |
namesize = sizeof(xfsb.s_fname); |
82 |
namesize = sizeof(xfsb.s_fname); |
70 |
if ((*label = calloc(namesize + 1, 1)) != NULL) |
83 |
if ((*label = calloc(namesize + 1, 1)) != NULL) |
71 |
memcpy(*label, xfsb.s_fname, namesize); |
84 |
memcpy(*label, xfsb.s_fname, namesize); |
72 |
rv = 0; |
85 |
return 0; |
|
|
86 |
} |
87 |
return 1; |
88 |
} |
89 |
|
90 |
static inline int reiserfs_magic_version(const char *magic) |
91 |
{ |
92 |
int rc = 0; |
93 |
if ( !strncmp(magic, REISERFS_SUPER_MAGIC_STRING, strlen(REISERFS_SUPER_MAGIC_STRING)) ) |
94 |
rc = 1; |
95 |
if ( !strncmp(magic, REISER2FS_SUPER_MAGIC_STRING, strlen(REISER2FS_SUPER_MAGIC_STRING)) ) |
96 |
rc = 2; |
97 |
if ( !strncmp(magic, REISER3FS_SUPER_MAGIC_STRING, strlen(REISER3FS_SUPER_MAGIC_STRING)) ) |
98 |
rc = 3; |
99 |
return rc; |
100 |
} |
101 |
|
102 |
static int |
103 |
get_label_uuid_reiserfs(int fd, char **label, char *uuid) |
104 |
{ |
105 |
struct reiserfs_super_block reiserfssb; |
106 |
if ( (lseek(fd, REISERFS_DISK_OFFSET_IN_BYTES, SEEK_SET) == REISERFS_DISK_OFFSET_IN_BYTES) |
107 |
&& ( read(fd, (char *) &reiserfssb, sizeof(reiserfssb)) == sizeof(reiserfssb) ) |
108 |
/* Only 3.6.x format supers have labels or uuids. |
109 |
Label and UUID can be set by reiserfstune -l/-u. */ |
110 |
&& (reiserfs_magic_version((const char*)reiserfssb.s_magic) > 1) ) { |
111 |
size_t namesize; |
112 |
memcpy(uuid, reiserfssb.s_uuid, sizeof(reiserfssb.s_uuid)); |
113 |
namesize = sizeof(reiserfssb.s_label); |
114 |
if ((*label = calloc(namesize + 1, 1)) != NULL) |
115 |
memcpy(*label, reiserfssb.s_label, namesize); |
116 |
return 0; |
117 |
} |
118 |
return 1; |
119 |
} |
120 |
|
121 |
static int |
122 |
get_label_uuid(const char *device, char **label, char *uuid) |
123 |
{ |
124 |
int fd; |
125 |
int rv = 1; |
126 |
const GetLabelUuidProc *proc = get_label_uuid_proc_table; |
127 |
|
128 |
fd = open(device, O_RDONLY); |
129 |
if (fd < 0) |
130 |
return rv; |
131 |
|
132 |
while(*proc) { |
133 |
rv = (*proc)(fd, label, uuid); |
134 |
if ( !rv ) |
135 |
break; |
136 |
++proc; |
73 |
} |
137 |
} |
74 |
|
138 |
|
75 |
close(fd); |
139 |
close(fd); |
Lines 265-271
Link Here
|
265 |
uuid[i] = ((fromhex(s[0])<<4) | fromhex(s[1])); |
329 |
uuid[i] = ((fromhex(s[0])<<4) | fromhex(s[1])); |
266 |
s += 2; |
330 |
s += 2; |
267 |
} |
331 |
} |
268 |
return get_spec_by_x(UUID, uuid, major, minor); |
332 |
return get_spec_by_x(UUID, (const char*)uuid, major, minor); |
269 |
|
333 |
|
270 |
bad_uuid: |
334 |
bad_uuid: |
271 |
fprintf(stderr, _("mount: bad UUID")); |
335 |
fprintf(stderr, _("mount: bad UUID")); |