Imported Upstream version 0.6.3
[platform/upstream/multipath-tools.git] / kpartx / kpartx.h
1 #ifndef _KPARTX_H
2 #define _KPARTX_H
3
4 #include <stdint.h>
5 #include <sys/ioctl.h>
6
7 /*
8  * For each partition type there is a routine that takes
9  * a block device and a range, and returns the list of
10  * slices found there in the supplied array SP that can
11  * hold NS entries. The return value is the number of
12  * entries stored, or -1 if the appropriate type is not
13  * present.
14  */
15
16 #define likely(x)       __builtin_expect(!!(x), 1)
17 #define unlikely(x)     __builtin_expect(!!(x), 0)
18
19 #define safe_sprintf(var, format, args...)      \
20         snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
21
22 #ifndef BLKSSZGET
23 #define BLKSSZGET  _IO(0x12,104)        /* get block device sector size */
24 #endif
25
26 int
27 get_sector_size(int filedes);
28
29 /*
30  * units: 512 byte sectors
31  */
32 struct slice {
33         uint64_t start;
34         uint64_t size;
35         int container;
36         int major;
37         int minor;
38 };
39
40 typedef int (ptreader)(int fd, struct slice all, struct slice *sp, int ns);
41
42 extern ptreader read_dos_pt;
43 extern ptreader read_bsd_pt;
44 extern ptreader read_solaris_pt;
45 extern ptreader read_unixware_pt;
46 extern ptreader read_gpt_pt;
47 extern ptreader read_dasd_pt;
48 extern ptreader read_mac_pt;
49 extern ptreader read_sun_pt;
50 extern ptreader read_ps3_pt;
51
52 char *getblock(int fd, unsigned int secnr);
53
54 static inline int
55 four2int(unsigned char *p) {
56         return p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24);
57 }
58
59 #endif /* _KPARTX_H */