Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

um: switch cow_user.h to htobe{32,64}/betoh{32,64}

... rather than open-coding the 64bit versions. endian.h has those guys.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Al Viro and committed by
Richard Weinberger
d824d063 f21a7c19

+21 -57
-35
arch/um/drivers/cow.h
··· 3 3 4 4 #include <asm/types.h> 5 5 6 - #if defined(__KERNEL__) 7 - 8 - # include <asm/byteorder.h> 9 - 10 - # if defined(__BIG_ENDIAN) 11 - # define ntohll(x) (x) 12 - # define htonll(x) (x) 13 - # elif defined(__LITTLE_ENDIAN) 14 - # define ntohll(x) be64_to_cpu(x) 15 - # define htonll(x) cpu_to_be64(x) 16 - # else 17 - # error "Could not determine byte order" 18 - # endif 19 - 20 - #else 21 - /* For the definition of ntohl, htonl and __BYTE_ORDER */ 22 - #include <endian.h> 23 - #include <netinet/in.h> 24 - #if defined(__BYTE_ORDER) 25 - 26 - # if __BYTE_ORDER == __BIG_ENDIAN 27 - # define ntohll(x) (x) 28 - # define htonll(x) (x) 29 - # elif __BYTE_ORDER == __LITTLE_ENDIAN 30 - # define ntohll(x) bswap_64(x) 31 - # define htonll(x) bswap_64(x) 32 - # else 33 - # error "Could not determine byte order: __BYTE_ORDER uncorrectly defined" 34 - # endif 35 - 36 - #else /* ! defined(__BYTE_ORDER) */ 37 - # error "Could not determine byte order: __BYTE_ORDER not defined" 38 - #endif 39 - #endif /* ! defined(__KERNEL__) */ 40 - 41 6 extern int init_cow_file(int fd, char *cow_file, char *backing_file, 42 7 int sectorsize, int alignment, int *bitmap_offset_out, 43 8 unsigned long *bitmap_len_out, int *data_offset_out);
+21 -22
arch/um/drivers/cow_user.c
··· 8 8 * that. 9 9 */ 10 10 #include <unistd.h> 11 - #include <byteswap.h> 12 11 #include <errno.h> 13 12 #include <string.h> 14 13 #include <arpa/inet.h> 15 - #include <asm/types.h> 14 + #include <endian.h> 16 15 #include "cow.h" 17 16 #include "cow_sys.h" 18 17 ··· 213 214 "header\n"); 214 215 goto out; 215 216 } 216 - header->magic = htonl(COW_MAGIC); 217 - header->version = htonl(COW_VERSION); 217 + header->magic = htobe32(COW_MAGIC); 218 + header->version = htobe32(COW_VERSION); 218 219 219 220 err = -EINVAL; 220 221 if (strlen(backing_file) > sizeof(header->backing_file) - 1) { ··· 245 246 goto out_free; 246 247 } 247 248 248 - header->mtime = htonl(modtime); 249 - header->size = htonll(*size); 250 - header->sectorsize = htonl(sectorsize); 251 - header->alignment = htonl(alignment); 249 + header->mtime = htobe32(modtime); 250 + header->size = htobe64(*size); 251 + header->sectorsize = htobe32(sectorsize); 252 + header->alignment = htobe32(alignment); 252 253 header->cow_format = COW_BITMAP; 253 254 254 255 err = cow_write_file(fd, header, sizeof(*header)); ··· 300 301 magic = header->v1.magic; 301 302 if (magic == COW_MAGIC) 302 303 version = header->v1.version; 303 - else if (magic == ntohl(COW_MAGIC)) 304 - version = ntohl(header->v1.version); 304 + else if (magic == be32toh(COW_MAGIC)) 305 + version = be32toh(header->v1.version); 305 306 /* No error printed because the non-COW case comes through here */ 306 307 else goto out; 307 308 ··· 326 327 "header\n"); 327 328 goto out; 328 329 } 329 - *mtime_out = ntohl(header->v2.mtime); 330 - *size_out = ntohll(header->v2.size); 331 - *sectorsize_out = ntohl(header->v2.sectorsize); 330 + *mtime_out = be32toh(header->v2.mtime); 331 + *size_out = be64toh(header->v2.size); 332 + *sectorsize_out = be32toh(header->v2.sectorsize); 332 333 *bitmap_offset_out = sizeof(header->v2); 333 334 *align_out = *sectorsize_out; 334 335 file = header->v2.backing_file; ··· 340 341 "header\n"); 341 342 goto out; 342 343 } 343 - *mtime_out = ntohl(header->v3.mtime); 344 - *size_out = ntohll(header->v3.size); 345 - *sectorsize_out = ntohl(header->v3.sectorsize); 346 - *align_out = ntohl(header->v3.alignment); 344 + *mtime_out = be32toh(header->v3.mtime); 345 + *size_out = be64toh(header->v3.size); 346 + *sectorsize_out = be32toh(header->v3.sectorsize); 347 + *align_out = be32toh(header->v3.alignment); 347 348 if (*align_out == 0) { 348 349 cow_printf("read_cow_header - invalid COW header, " 349 350 "align == 0\n"); ··· 365 366 * this was used until Dec2005 - 64bits are needed to represent 366 367 * 2038+. I.e. we can safely do this truncating cast. 367 368 * 368 - * Additionally, we must use ntohl() instead of ntohll(), since 369 + * Additionally, we must use be32toh() instead of be64toh(), since 369 370 * the program used to use the former (tested - I got mtime 370 371 * mismatch "0 vs whatever"). 371 372 * 372 373 * Ever heard about bug-to-bug-compatibility ? ;-) */ 373 - *mtime_out = (time32_t) ntohl(header->v3_b.mtime); 374 + *mtime_out = (time32_t) be32toh(header->v3_b.mtime); 374 375 375 - *size_out = ntohll(header->v3_b.size); 376 - *sectorsize_out = ntohl(header->v3_b.sectorsize); 377 - *align_out = ntohl(header->v3_b.alignment); 376 + *size_out = be64toh(header->v3_b.size); 377 + *sectorsize_out = be32toh(header->v3_b.sectorsize); 378 + *align_out = be32toh(header->v3_b.alignment); 378 379 if (*align_out == 0) { 379 380 cow_printf("read_cow_header - invalid COW header, " 380 381 "align == 0\n");