logd: fix time passed via unix fd
[project/ubox.git] / libblkid-tiny / blkdev.h
1 #ifndef BLKDEV_H
2 #define BLKDEV_H
3
4 #include <sys/types.h>
5 #include <sys/ioctl.h>
6 #ifdef HAVE_SYS_IOCCOM_H
7 # include <sys/ioccom.h> /* for _IO macro on e.g. Solaris */
8 #endif
9 #include <fcntl.h>
10 #include <unistd.h>
11
12 #ifdef HAVE_SYS_MKDEV_H
13 # include <sys/mkdev.h> /* major and minor on Solaris */
14 #endif
15
16 #define DEFAULT_SECTOR_SIZE 512
17
18 #ifdef __linux__
19 /* very basic ioclts, should be available everywhere */
20 # ifndef BLKROSET
21 # define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
22 # define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
23 # define BLKRRPART _IO(0x12,95) /* re-read partition table */
24 # define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
25 # define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
26 # define BLKRASET _IO(0x12,98) /* set read ahead for block device */
27 # define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
28 # define BLKFRASET _IO(0x12,100) /* set filesystem (mm/filemap.c) read-ahead */
29 # define BLKFRAGET _IO(0x12,101) /* get filesystem (mm/filemap.c) read-ahead */
30 # define BLKSECTSET _IO(0x12,102) /* set max sectors per request (ll_rw_blk.c) */
31 # define BLKSECTGET _IO(0x12,103) /* get max sectors per request (ll_rw_blk.c) */
32 # define BLKSSZGET _IO(0x12,104) /* get block device sector size */
33
34 /* ioctls introduced in 2.2.16, removed in 2.5.58 */
35 # define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
36 # define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
37
38 # define BLKBSZGET _IOR(0x12,112,size_t)
39 # define BLKBSZSET _IOW(0x12,113,size_t)
40 # endif /* !BLKROSET */
41
42 # ifndef BLKGETSIZE64
43 # define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
44 # endif
45
46 /* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
47 # ifndef BLKIOMIN
48 # define BLKIOMIN _IO(0x12,120)
49 # define BLKIOOPT _IO(0x12,121)
50 # define BLKALIGNOFF _IO(0x12,122)
51 # define BLKPBSZGET _IO(0x12,123)
52 # endif
53
54 /* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
55 # ifndef BLKDISCARDZEROES
56 # define BLKDISCARDZEROES _IO(0x12,124)
57 # endif
58
59 /* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
60 # ifndef FIFREEZE
61 # define FIFREEZE _IOWR('X', 119, int) /* Freeze */
62 # define FITHAW _IOWR('X', 120, int) /* Thaw */
63 # endif
64
65 #endif /* __linux */
66
67 #ifdef APPLE_DARWIN
68 # define BLKGETSIZE DKIOCGETBLOCKCOUNT32
69 #endif
70
71 #ifndef HDIO_GETGEO
72 # ifdef __linux__
73 # define HDIO_GETGEO 0x0301
74 # endif
75
76 /* uniform CD-ROM information */
77 #ifndef CDROM_GET_CAPABILITY
78 # define CDROM_GET_CAPABILITY 0x5331
79 #endif
80
81 struct hd_geometry {
82 unsigned char heads;
83 unsigned char sectors;
84 unsigned short cylinders; /* truncated */
85 unsigned long start;
86 };
87 #endif
88
89 /* are we working with block device? */
90 int is_blkdev(int fd);
91
92 /* Determine size in bytes */
93 off_t blkdev_find_size (int fd);
94
95 /* get size in bytes */
96 int blkdev_get_size(int fd, unsigned long long *bytes);
97
98 /* get 512-byte sector count */
99 int blkdev_get_sectors(int fd, unsigned long long *sectors);
100
101 /* get hardware sector size */
102 int blkdev_get_sector_size(int fd, int *sector_size);
103
104 /* specifies whether or not the device is misaligned */
105 int blkdev_is_misaligned(int fd);
106
107 /* get physical block device size */
108 int blkdev_get_physector_size(int fd, int *sector_size);
109
110 /* is the device cdrom capable? */
111 int blkdev_is_cdrom(int fd);
112
113 #endif /* BLKDEV_H */