Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __COW_H__ |
| 2 | #define __COW_H__ |
| 3 | |
| 4 | #include <asm/types.h> |
| 5 | |
Paolo 'Blaisorblade' Giarrusso | 028c0cc | 2005-10-09 21:37:45 +0200 | [diff] [blame] | 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 | |
Paolo 'Blaisorblade' Giarrusso | 52a2d3e | 2005-10-09 21:37:53 +0200 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Paolo 'Blaisorblade' Giarrusso | 028c0cc | 2005-10-09 21:37:45 +0200 | [diff] [blame] | 36 | #else /* ! defined(__BYTE_ORDER) */ |
| 37 | # error "Could not determine byte order: __BYTE_ORDER not defined" |
| 38 | #endif |
| 39 | #endif /* ! defined(__KERNEL__) */ |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | extern int init_cow_file(int fd, char *cow_file, char *backing_file, |
| 42 | int sectorsize, int alignment, int *bitmap_offset_out, |
| 43 | unsigned long *bitmap_len_out, int *data_offset_out); |
| 44 | |
| 45 | extern int file_reader(__u64 offset, char *buf, int len, void *arg); |
| 46 | extern int read_cow_header(int (*reader)(__u64, char *, int, void *), |
| 47 | void *arg, __u32 *version_out, |
| 48 | char **backing_file_out, time_t *mtime_out, |
Paolo 'Blaisorblade' Giarrusso | 52c7378 | 2006-04-10 22:53:41 -0700 | [diff] [blame] | 49 | unsigned long long *size_out, int *sectorsize_out, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | __u32 *align_out, int *bitmap_offset_out); |
| 51 | |
| 52 | extern int write_cow_header(char *cow_file, int fd, char *backing_file, |
| 53 | int sectorsize, int alignment, |
| 54 | unsigned long long *size); |
| 55 | |
| 56 | extern void cow_sizes(int version, __u64 size, int sectorsize, int align, |
| 57 | int bitmap_offset, unsigned long *bitmap_len_out, |
| 58 | int *data_offset_out); |
| 59 | |
| 60 | #endif |
| 61 | |
| 62 | /* |
| 63 | * --------------------------------------------------------------------------- |
| 64 | * Local variables: |
| 65 | * c-file-style: "linux" |
| 66 | * End: |
| 67 | */ |