xref: /linux/arch/um/drivers/cow.h (revision 52c7378236103ce5fbfb7b3e6ac46aa9de9f970d)
11da177e4SLinus Torvalds #ifndef __COW_H__
21da177e4SLinus Torvalds #define __COW_H__
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds #include <asm/types.h>
51da177e4SLinus Torvalds 
6028c0cc1SPaolo 'Blaisorblade' Giarrusso #if defined(__KERNEL__)
7028c0cc1SPaolo 'Blaisorblade' Giarrusso 
8028c0cc1SPaolo 'Blaisorblade' Giarrusso # include <asm/byteorder.h>
9028c0cc1SPaolo 'Blaisorblade' Giarrusso 
10028c0cc1SPaolo 'Blaisorblade' Giarrusso # if defined(__BIG_ENDIAN)
11028c0cc1SPaolo 'Blaisorblade' Giarrusso #	define ntohll(x) (x)
12028c0cc1SPaolo 'Blaisorblade' Giarrusso #	define htonll(x) (x)
13028c0cc1SPaolo 'Blaisorblade' Giarrusso # elif defined(__LITTLE_ENDIAN)
14028c0cc1SPaolo 'Blaisorblade' Giarrusso #	define ntohll(x)  be64_to_cpu(x)
15028c0cc1SPaolo 'Blaisorblade' Giarrusso #	define htonll(x)  cpu_to_be64(x)
16028c0cc1SPaolo 'Blaisorblade' Giarrusso # else
17028c0cc1SPaolo 'Blaisorblade' Giarrusso #	error "Could not determine byte order"
18028c0cc1SPaolo 'Blaisorblade' Giarrusso # endif
19028c0cc1SPaolo 'Blaisorblade' Giarrusso 
20028c0cc1SPaolo 'Blaisorblade' Giarrusso #else
21028c0cc1SPaolo 'Blaisorblade' Giarrusso /* For the definition of ntohl, htonl and __BYTE_ORDER */
22028c0cc1SPaolo 'Blaisorblade' Giarrusso #include <endian.h>
23028c0cc1SPaolo 'Blaisorblade' Giarrusso #include <netinet/in.h>
24028c0cc1SPaolo 'Blaisorblade' Giarrusso #if defined(__BYTE_ORDER)
25028c0cc1SPaolo 'Blaisorblade' Giarrusso 
26855ec613SPaolo 'Blaisorblade' Giarrusso #  if __BYTE_ORDER == __BIG_ENDIAN
271da177e4SLinus Torvalds #	define ntohll(x) (x)
281da177e4SLinus Torvalds #	define htonll(x) (x)
29855ec613SPaolo 'Blaisorblade' Giarrusso #  elif __BYTE_ORDER == __LITTLE_ENDIAN
301da177e4SLinus Torvalds #	define ntohll(x)  bswap_64(x)
311da177e4SLinus Torvalds #	define htonll(x)  bswap_64(x)
321da177e4SLinus Torvalds #  else
33028c0cc1SPaolo 'Blaisorblade' Giarrusso #	error "Could not determine byte order: __BYTE_ORDER uncorrectly defined"
341da177e4SLinus Torvalds #  endif
351da177e4SLinus Torvalds 
36028c0cc1SPaolo 'Blaisorblade' Giarrusso #else  /* ! defined(__BYTE_ORDER) */
37028c0cc1SPaolo 'Blaisorblade' Giarrusso #	error "Could not determine byte order: __BYTE_ORDER not defined"
38028c0cc1SPaolo 'Blaisorblade' Giarrusso #endif
39028c0cc1SPaolo 'Blaisorblade' Giarrusso #endif /* ! defined(__KERNEL__) */
40028c0cc1SPaolo 'Blaisorblade' Giarrusso 
411da177e4SLinus Torvalds extern int init_cow_file(int fd, char *cow_file, char *backing_file,
421da177e4SLinus Torvalds 			 int sectorsize, int alignment, int *bitmap_offset_out,
431da177e4SLinus Torvalds 			 unsigned long *bitmap_len_out, int *data_offset_out);
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds extern int file_reader(__u64 offset, char *buf, int len, void *arg);
461da177e4SLinus Torvalds extern int read_cow_header(int (*reader)(__u64, char *, int, void *),
471da177e4SLinus Torvalds 			   void *arg, __u32 *version_out,
481da177e4SLinus Torvalds 			   char **backing_file_out, time_t *mtime_out,
49*52c73782SPaolo 'Blaisorblade' Giarrusso 			   unsigned long long *size_out, int *sectorsize_out,
501da177e4SLinus Torvalds 			   __u32 *align_out, int *bitmap_offset_out);
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds extern int write_cow_header(char *cow_file, int fd, char *backing_file,
531da177e4SLinus Torvalds 			    int sectorsize, int alignment,
541da177e4SLinus Torvalds 			    unsigned long long *size);
551da177e4SLinus Torvalds 
561da177e4SLinus Torvalds extern void cow_sizes(int version, __u64 size, int sectorsize, int align,
571da177e4SLinus Torvalds 		      int bitmap_offset, unsigned long *bitmap_len_out,
581da177e4SLinus Torvalds 		      int *data_offset_out);
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds #endif
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds /*
631da177e4SLinus Torvalds  * ---------------------------------------------------------------------------
641da177e4SLinus Torvalds  * Local variables:
651da177e4SLinus Torvalds  * c-file-style: "linux"
661da177e4SLinus Torvalds  * End:
671da177e4SLinus Torvalds  */
68