[kpartx] bug fixes for dos extended partition [3/4]
[platform/upstream/multipath-tools.git] / kpartx / kpartx.h
1 #ifndef _KPARTX_H
2 #define _KPARTX_H
3
4 /*
5  * For each partition type there is a routine that takes
6  * a block device and a range, and returns the list of
7  * slices found there in the supplied array SP that can
8  * hold NS entries. The return value is the number of
9  * entries stored, or -1 if the appropriate type is not
10  * present.
11  */
12
13 #define likely(x)       __builtin_expect(!!(x), 1)
14 #define unlikely(x)     __builtin_expect(!!(x), 0)
15
16 #define safe_sprintf(var, format, args...)      \
17         snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
18
19 /*
20  * units: 512 byte sectors
21  */
22 struct slice {
23         unsigned long start;
24         unsigned long size;
25 };
26
27 typedef int (ptreader)(int fd, struct slice all, struct slice *sp, int ns);
28
29 extern ptreader read_dos_pt;
30 extern ptreader read_bsd_pt;
31 extern ptreader read_solaris_pt;
32 extern ptreader read_unixware_pt;
33 extern ptreader read_gpt_pt;
34
35 char *getblock(int fd, unsigned int secnr);
36
37 static inline int
38 four2int(unsigned char *p) {
39         return p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24);
40 }
41
42 #endif /* _KPARTX_H */