]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/blkdev.h
mount: add verity example to man page
[thirdparty/util-linux.git] / include / blkdev.h
1 /*
2 * No copyright is claimed. This code is in the public domain; do with
3 * it what you wish.
4 *
5 * Written by Karel Zak <kzak@redhat.com>
6 */
7 #ifndef BLKDEV_H
8 #define BLKDEV_H
9
10 #include <sys/types.h>
11 #include <sys/ioctl.h>
12 #ifdef HAVE_SYS_IOCCOM_H
13 # include <sys/ioccom.h> /* for _IO macro on e.g. Solaris */
14 #endif
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <sys/stat.h>
18
19 #ifdef HAVE_SYS_MKDEV_H
20 # include <sys/mkdev.h> /* major and minor on Solaris */
21 #endif
22
23 #define DEFAULT_SECTOR_SIZE 512
24
25 #ifdef __linux__
26 /* very basic ioctls, should be available everywhere */
27 # ifndef BLKROSET
28 # define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
29 # define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
30 # define BLKRRPART _IO(0x12,95) /* re-read partition table */
31 # define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
32 # define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
33 # define BLKRASET _IO(0x12,98) /* set read ahead for block device */
34 # define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
35 # define BLKFRASET _IO(0x12,100) /* set filesystem (mm/filemap.c) read-ahead */
36 # define BLKFRAGET _IO(0x12,101) /* get filesystem (mm/filemap.c) read-ahead */
37 # define BLKSECTSET _IO(0x12,102) /* set max sectors per request (ll_rw_blk.c) */
38 # define BLKSECTGET _IO(0x12,103) /* get max sectors per request (ll_rw_blk.c) */
39 # define BLKSSZGET _IO(0x12,104) /* get block device sector size */
40
41 /* ioctls introduced in 2.2.16, removed in 2.5.58 */
42 # define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
43 # define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
44
45 # define BLKBSZGET _IOR(0x12,112,size_t)
46 # define BLKBSZSET _IOW(0x12,113,size_t)
47 # endif /* !BLKROSET */
48
49 # ifndef BLKGETSIZE64
50 # define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
51 # endif
52
53 /* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
54 # ifndef BLKIOMIN
55 # define BLKIOMIN _IO(0x12,120)
56 # define BLKIOOPT _IO(0x12,121)
57 # define BLKALIGNOFF _IO(0x12,122)
58 # define BLKPBSZGET _IO(0x12,123)
59 # endif
60
61 /* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
62 # ifndef BLKDISCARDZEROES
63 # define BLKDISCARDZEROES _IO(0x12,124)
64 # endif
65
66 /* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
67 # ifndef FIFREEZE
68 # define FIFREEZE _IOWR('X', 119, int) /* Freeze */
69 # define FITHAW _IOWR('X', 120, int) /* Thaw */
70 # endif
71
72 /* uniform CD-ROM information */
73 # ifndef CDROM_GET_CAPABILITY
74 # define CDROM_GET_CAPABILITY 0x5331
75 # endif
76
77 #endif /* __linux */
78
79
80 #ifdef APPLE_DARWIN
81 # define BLKGETSIZE DKIOCGETBLOCKCOUNT32
82 #endif
83
84 #ifndef HDIO_GETGEO
85 # ifdef __linux__
86 # define HDIO_GETGEO 0x0301
87 # endif
88
89 struct hd_geometry {
90 unsigned char heads;
91 unsigned char sectors;
92 unsigned short cylinders; /* truncated */
93 unsigned long start;
94 };
95 #endif /* HDIO_GETGEO */
96
97
98 /* are we working with block device? */
99 int is_blkdev(int fd);
100
101 /* open block device or file */
102 int open_blkdev_or_file(const struct stat *st, const char *name, const int oflag);
103
104 /* Determine size in bytes */
105 off_t blkdev_find_size (int fd);
106
107 /* get size in bytes */
108 int blkdev_get_size(int fd, unsigned long long *bytes);
109
110 /* get 512-byte sector count */
111 int blkdev_get_sectors(int fd, unsigned long long *sectors);
112
113 /* get hardware sector size */
114 int blkdev_get_sector_size(int fd, int *sector_size);
115
116 /* specifies whether or not the device is misaligned */
117 int blkdev_is_misaligned(int fd);
118
119 /* get physical block device size */
120 int blkdev_get_physector_size(int fd, int *sector_size);
121
122 /* is the device cdrom capable? */
123 int blkdev_is_cdrom(int fd);
124
125 /* get device's geometry - legacy */
126 int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s);
127
128 /* SCSI device types. Copied almost as-is from kernel header.
129 * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */
130 #define SCSI_TYPE_DISK 0x00
131 #define SCSI_TYPE_TAPE 0x01
132 #define SCSI_TYPE_PRINTER 0x02
133 #define SCSI_TYPE_PROCESSOR 0x03 /* HP scanners use this */
134 #define SCSI_TYPE_WORM 0x04 /* Treated as ROM by our system */
135 #define SCSI_TYPE_ROM 0x05
136 #define SCSI_TYPE_SCANNER 0x06
137 #define SCSI_TYPE_MOD 0x07 /* Magneto-optical disk - treated as SCSI_TYPE_DISK */
138 #define SCSI_TYPE_MEDIUM_CHANGER 0x08
139 #define SCSI_TYPE_COMM 0x09 /* Communications device */
140 #define SCSI_TYPE_RAID 0x0c
141 #define SCSI_TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
142 #define SCSI_TYPE_RBC 0x0e
143 #define SCSI_TYPE_OSD 0x11
144 #define SCSI_TYPE_NO_LUN 0x7f
145
146 /* convert scsi type code to name */
147 const char *blkdev_scsi_type_to_name(int type);
148
149
150 #endif /* BLKDEV_H */