]>
Commit | Line | Data |
---|---|---|
0f23ee0c KZ |
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 | */ | |
3738a48e SK |
7 | #ifndef BLKDEV_H |
8 | #define BLKDEV_H | |
9 | ||
10 | #include <sys/types.h> | |
11 | #include <sys/ioctl.h> | |
3edaa201 FG |
12 | #ifdef HAVE_SYS_IOCCOM_H |
13 | # include <sys/ioccom.h> /* for _IO macro on e.g. Solaris */ | |
14 | #endif | |
929f243f KZ |
15 | #include <fcntl.h> |
16 | #include <unistd.h> | |
e210cfc8 | 17 | #include <sys/stat.h> |
3738a48e | 18 | |
fbc333fe | 19 | #ifdef HAVE_SYS_MKDEV_H |
960f668f KZ |
20 | # include <sys/mkdev.h> /* major and minor on Solaris */ |
21 | #endif | |
22 | ||
3738a48e SK |
23 | #define DEFAULT_SECTOR_SIZE 512 |
24 | ||
9ef30d61 | 25 | #ifdef __linux__ |
a5c523a0 | 26 | /* very basic ioctls, should be available everywhere */ |
9ef30d61 KZ |
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 */ | |
3738a48e | 40 | |
8505ff35 | 41 | /* ioctls introduced in 2.2.16, removed in 2.5.58 */ |
9ef30d61 KZ |
42 | # define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */ |
43 | # define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */ | |
3738a48e | 44 | |
9ef30d61 KZ |
45 | # define BLKBSZGET _IOR(0x12,112,size_t) |
46 | # define BLKBSZSET _IOW(0x12,113,size_t) | |
47 | # endif /* !BLKROSET */ | |
3738a48e | 48 | |
9ef30d61 KZ |
49 | # ifndef BLKGETSIZE64 |
50 | # define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ | |
51 | # endif | |
30696241 | 52 | |
9ef30d61 KZ |
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 | |
1519ab5f | 60 | |
9ef30d61 KZ |
61 | /* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */ |
62 | # ifndef BLKDISCARDZEROES | |
63 | # define BLKDISCARDZEROES _IO(0x12,124) | |
64 | # endif | |
ed98508a | 65 | |
9ef30d61 KZ |
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 | |
3738a48e | 71 | |
aa323539 KZ |
72 | /* uniform CD-ROM information */ |
73 | # ifndef CDROM_GET_CAPABILITY | |
74 | # define CDROM_GET_CAPABILITY 0x5331 | |
75 | # endif | |
76 | ||
9ef30d61 | 77 | #endif /* __linux */ |
1519ab5f | 78 | |
aa323539 | 79 | |
9ef30d61 KZ |
80 | #ifdef APPLE_DARWIN |
81 | # define BLKGETSIZE DKIOCGETBLOCKCOUNT32 | |
f0bef3ca HT |
82 | #endif |
83 | ||
3738a48e | 84 | #ifndef HDIO_GETGEO |
268cefe6 ST |
85 | # ifdef __linux__ |
86 | # define HDIO_GETGEO 0x0301 | |
87 | # endif | |
3b622ddd | 88 | |
3738a48e SK |
89 | struct hd_geometry { |
90 | unsigned char heads; | |
91 | unsigned char sectors; | |
92 | unsigned short cylinders; /* truncated */ | |
93 | unsigned long start; | |
94 | }; | |
aa323539 KZ |
95 | #endif /* HDIO_GETGEO */ |
96 | ||
3738a48e | 97 | |
8150beac DB |
98 | /* are we working with block device? */ |
99 | int is_blkdev(int fd); | |
100 | ||
8fe1e638 SK |
101 | /* open block device or file */ |
102 | int open_blkdev_or_file(const struct stat *st, const char *name, const int oflag); | |
103 | ||
268cefe6 ST |
104 | /* Determine size in bytes */ |
105 | off_t blkdev_find_size (int fd); | |
106 | ||
3738a48e SK |
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 | ||
ba326929 DB |
116 | /* specifies whether or not the device is misaligned */ |
117 | int blkdev_is_misaligned(int fd); | |
118 | ||
0e75337c DB |
119 | /* get physical block device size */ |
120 | int blkdev_get_physector_size(int fd, int *sector_size); | |
121 | ||
3b622ddd DB |
122 | /* is the device cdrom capable? */ |
123 | int blkdev_is_cdrom(int fd); | |
124 | ||
64128b70 DB |
125 | /* get device's geometry - legacy */ |
126 | int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s); | |
127 | ||
aa323539 | 128 | /* SCSI device types. Copied almost as-is from kernel header. |
d8a9b907 | 129 | * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */ |
aa323539 KZ |
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 | ||
ba32a946 | 146 | /* convert scsi type code to name */ |
2fc4a256 | 147 | const char *blkdev_scsi_type_to_name(int type); |
ba32a946 | 148 | |
aa323539 | 149 | |
3738a48e | 150 | #endif /* BLKDEV_H */ |