Changeset d5309df7 in mainline
- Timestamp:
- 2021-09-14T06:37:21Z (3 years ago)
- Children:
- 2ce943a
- Parents:
- bdad846
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/qcow_bd/qcow_bd.c
rbdad846 rd5309df7 48 48 static bd_srvs_t bd_srvs; 49 49 static fibril_mutex_t dev_lock; 50 static bool isLittleEndian(); 50 51 static void print_usage(void); 51 52 static errno_t qcow_bd_init(const char *fname); … … 176 177 } 177 178 179 /* Return 0 for if this system uses big endian, 1 for little endian. */ 180 static bool isLittleEndian() { 181 volatile uint32_t i = 0x01234567; 182 return (*((uint8_t*)(&i))) == 0x67; 183 } 184 178 185 static errno_t qcow_bd_init(const char *fname) 179 186 { … … 219 226 220 227 /* Swap values to big-endian */ 221 header.magic = __builtin_bswap32(header.magic); 222 header.version = __builtin_bswap32(header.version); 223 header.backing_file_offset = __builtin_bswap64(header.backing_file_offset); 224 header.backing_file_size = __builtin_bswap32(header.backing_file_size); 225 header.mtime = __builtin_bswap32(header.mtime); 226 header.size = __builtin_bswap64(header.size); 227 header.crypt_method = __builtin_bswap32(header.crypt_method); 228 header.l1_table_offset = __builtin_bswap64(header.l1_table_offset); 228 if (isLittleEndian()) { 229 header.magic = __builtin_bswap32(header.magic); 230 header.version = __builtin_bswap32(header.version); 231 header.backing_file_offset = __builtin_bswap64(header.backing_file_offset); 232 header.backing_file_size = __builtin_bswap32(header.backing_file_size); 233 header.mtime = __builtin_bswap32(header.mtime); 234 header.size = __builtin_bswap64(header.size); 235 header.crypt_method = __builtin_bswap32(header.crypt_method); 236 header.l1_table_offset = __builtin_bswap64(header.l1_table_offset); 237 } 229 238 230 239 if (ferror(img)) { … … 234 243 235 244 /* Verify all values from file header */ 236 if (header.magic == QCOW_MAGIC) 237 initialize_state(); 245 if (header.magic != QCOW_MAGIC) { 246 fprintf(stderr, "File is not in QCOW format!\n"); 247 fclose(img); 248 return ENOTSUP; 249 } 250 251 initialize_state(); 238 252 239 253 if (header.version != QCOW_VERSION) { … … 295 309 } 296 310 297 l2_table_reference = __builtin_bswap64(l2_table_reference); 311 if (isLittleEndian()) 312 l2_table_reference = __builtin_bswap64(l2_table_reference); 298 313 299 314 if (l2_table_reference & QCOW_OFLAG_COMPRESSED) { … … 325 340 } 326 341 327 cluster_reference = __builtin_bswap64(cluster_reference); 342 if (isLittleEndian()) 343 cluster_reference = __builtin_bswap64(cluster_reference); 328 344 329 345 if (cluster_reference & QCOW_OFLAG_COMPRESSED) {
Note:
See TracChangeset
for help on using the changeset viewer.