提交 d824d063 编写于 作者: A Al Viro 提交者: Richard Weinberger

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: NAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: NRichard Weinberger <richard@nod.at>
上级 f21a7c19
...@@ -3,41 +3,6 @@ ...@@ -3,41 +3,6 @@
#include <asm/types.h> #include <asm/types.h>
#if defined(__KERNEL__)
# include <asm/byteorder.h>
# if defined(__BIG_ENDIAN)
# define ntohll(x) (x)
# define htonll(x) (x)
# elif defined(__LITTLE_ENDIAN)
# define ntohll(x) be64_to_cpu(x)
# define htonll(x) cpu_to_be64(x)
# else
# error "Could not determine byte order"
# endif
#else
/* For the definition of ntohl, htonl and __BYTE_ORDER */
#include <endian.h>
#include <netinet/in.h>
#if defined(__BYTE_ORDER)
# if __BYTE_ORDER == __BIG_ENDIAN
# define ntohll(x) (x)
# define htonll(x) (x)
# elif __BYTE_ORDER == __LITTLE_ENDIAN
# define ntohll(x) bswap_64(x)
# define htonll(x) bswap_64(x)
# else
# error "Could not determine byte order: __BYTE_ORDER uncorrectly defined"
# endif
#else /* ! defined(__BYTE_ORDER) */
# error "Could not determine byte order: __BYTE_ORDER not defined"
#endif
#endif /* ! defined(__KERNEL__) */
extern int init_cow_file(int fd, char *cow_file, char *backing_file, extern int init_cow_file(int fd, char *cow_file, char *backing_file,
int sectorsize, int alignment, int *bitmap_offset_out, int sectorsize, int alignment, int *bitmap_offset_out,
unsigned long *bitmap_len_out, int *data_offset_out); unsigned long *bitmap_len_out, int *data_offset_out);
......
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
* that. * that.
*/ */
#include <unistd.h> #include <unistd.h>
#include <byteswap.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <asm/types.h> #include <endian.h>
#include "cow.h" #include "cow.h"
#include "cow_sys.h" #include "cow_sys.h"
...@@ -214,8 +213,8 @@ int write_cow_header(char *cow_file, int fd, char *backing_file, ...@@ -214,8 +213,8 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
"header\n"); "header\n");
goto out; goto out;
} }
header->magic = htonl(COW_MAGIC); header->magic = htobe32(COW_MAGIC);
header->version = htonl(COW_VERSION); header->version = htobe32(COW_VERSION);
err = -EINVAL; err = -EINVAL;
if (strlen(backing_file) > sizeof(header->backing_file) - 1) { if (strlen(backing_file) > sizeof(header->backing_file) - 1) {
...@@ -246,10 +245,10 @@ int write_cow_header(char *cow_file, int fd, char *backing_file, ...@@ -246,10 +245,10 @@ int write_cow_header(char *cow_file, int fd, char *backing_file,
goto out_free; goto out_free;
} }
header->mtime = htonl(modtime); header->mtime = htobe32(modtime);
header->size = htonll(*size); header->size = htobe64(*size);
header->sectorsize = htonl(sectorsize); header->sectorsize = htobe32(sectorsize);
header->alignment = htonl(alignment); header->alignment = htobe32(alignment);
header->cow_format = COW_BITMAP; header->cow_format = COW_BITMAP;
err = cow_write_file(fd, header, sizeof(*header)); err = cow_write_file(fd, header, sizeof(*header));
...@@ -301,8 +300,8 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, ...@@ -301,8 +300,8 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
magic = header->v1.magic; magic = header->v1.magic;
if (magic == COW_MAGIC) if (magic == COW_MAGIC)
version = header->v1.version; version = header->v1.version;
else if (magic == ntohl(COW_MAGIC)) else if (magic == be32toh(COW_MAGIC))
version = ntohl(header->v1.version); version = be32toh(header->v1.version);
/* No error printed because the non-COW case comes through here */ /* No error printed because the non-COW case comes through here */
else goto out; else goto out;
...@@ -327,9 +326,9 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, ...@@ -327,9 +326,9 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
"header\n"); "header\n");
goto out; goto out;
} }
*mtime_out = ntohl(header->v2.mtime); *mtime_out = be32toh(header->v2.mtime);
*size_out = ntohll(header->v2.size); *size_out = be64toh(header->v2.size);
*sectorsize_out = ntohl(header->v2.sectorsize); *sectorsize_out = be32toh(header->v2.sectorsize);
*bitmap_offset_out = sizeof(header->v2); *bitmap_offset_out = sizeof(header->v2);
*align_out = *sectorsize_out; *align_out = *sectorsize_out;
file = header->v2.backing_file; file = header->v2.backing_file;
...@@ -341,10 +340,10 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, ...@@ -341,10 +340,10 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
"header\n"); "header\n");
goto out; goto out;
} }
*mtime_out = ntohl(header->v3.mtime); *mtime_out = be32toh(header->v3.mtime);
*size_out = ntohll(header->v3.size); *size_out = be64toh(header->v3.size);
*sectorsize_out = ntohl(header->v3.sectorsize); *sectorsize_out = be32toh(header->v3.sectorsize);
*align_out = ntohl(header->v3.alignment); *align_out = be32toh(header->v3.alignment);
if (*align_out == 0) { if (*align_out == 0) {
cow_printf("read_cow_header - invalid COW header, " cow_printf("read_cow_header - invalid COW header, "
"align == 0\n"); "align == 0\n");
...@@ -366,16 +365,16 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, ...@@ -366,16 +365,16 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg,
* this was used until Dec2005 - 64bits are needed to represent * this was used until Dec2005 - 64bits are needed to represent
* 2038+. I.e. we can safely do this truncating cast. * 2038+. I.e. we can safely do this truncating cast.
* *
* Additionally, we must use ntohl() instead of ntohll(), since * Additionally, we must use be32toh() instead of be64toh(), since
* the program used to use the former (tested - I got mtime * the program used to use the former (tested - I got mtime
* mismatch "0 vs whatever"). * mismatch "0 vs whatever").
* *
* Ever heard about bug-to-bug-compatibility ? ;-) */ * Ever heard about bug-to-bug-compatibility ? ;-) */
*mtime_out = (time32_t) ntohl(header->v3_b.mtime); *mtime_out = (time32_t) be32toh(header->v3_b.mtime);
*size_out = ntohll(header->v3_b.size); *size_out = be64toh(header->v3_b.size);
*sectorsize_out = ntohl(header->v3_b.sectorsize); *sectorsize_out = be32toh(header->v3_b.sectorsize);
*align_out = ntohl(header->v3_b.alignment); *align_out = be32toh(header->v3_b.alignment);
if (*align_out == 0) { if (*align_out == 0) {
cow_printf("read_cow_header - invalid COW header, " cow_printf("read_cow_header - invalid COW header, "
"align == 0\n"); "align == 0\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册