c994795a2ac1e2ab4b7eab70b42cf7e85b0b0012
2 * No copyright is claimed. This code is in the public domain; do with
5 * Written by Karel Zak <kzak@redhat.com>
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 */
18 #ifdef HAVE_SYS_MKDEV_H
19 # include <sys/mkdev.h> /* major and minor on Solaris */
22 #define DEFAULT_SECTOR_SIZE 512
25 /* very basic ioctls, should be available everywhere */
27 # define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
28 # define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
29 # define BLKRRPART _IO(0x12,95) /* re-read partition table */
30 # define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
31 # define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
32 # define BLKRASET _IO(0x12,98) /* set read ahead for block device */
33 # define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
34 # define BLKFRASET _IO(0x12,100) /* set filesystem (mm/filemap.c) read-ahead */
35 # define BLKFRAGET _IO(0x12,101) /* get filesystem (mm/filemap.c) read-ahead */
36 # define BLKSECTSET _IO(0x12,102) /* set max sectors per request (ll_rw_blk.c) */
37 # define BLKSECTGET _IO(0x12,103) /* get max sectors per request (ll_rw_blk.c) */
38 # define BLKSSZGET _IO(0x12,104) /* get block device sector size */
40 /* ioctls introduced in 2.2.16, removed in 2.5.58 */
41 # define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
42 # define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
44 # define BLKBSZGET _IOR(0x12,112,size_t)
45 # define BLKBSZSET _IOW(0x12,113,size_t)
46 # endif /* !BLKROSET */
49 # define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
52 /* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
54 # define BLKIOMIN _IO(0x12,120)
55 # define BLKIOOPT _IO(0x12,121)
56 # define BLKALIGNOFF _IO(0x12,122)
57 # define BLKPBSZGET _IO(0x12,123)
60 /* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
61 # ifndef BLKDISCARDZEROES
62 # define BLKDISCARDZEROES _IO(0x12,124)
65 /* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
67 # define FIFREEZE _IOWR('X', 119, int) /* Freeze */
68 # define FITHAW _IOWR('X', 120, int) /* Thaw */
71 /* uniform CD-ROM information */
72 # ifndef CDROM_GET_CAPABILITY
73 # define CDROM_GET_CAPABILITY 0x5331
80 # define BLKGETSIZE DKIOCGETBLOCKCOUNT32
85 # define HDIO_GETGEO 0x0301
90 unsigned char sectors
;
91 unsigned short cylinders
; /* truncated */
94 #endif /* HDIO_GETGEO */
97 /* are we working with block device? */
98 int is_blkdev(int fd
);
100 /* Determine size in bytes */
101 off_t
blkdev_find_size (int fd
);
103 /* get size in bytes */
104 int blkdev_get_size(int fd
, unsigned long long *bytes
);
106 /* get 512-byte sector count */
107 int blkdev_get_sectors(int fd
, unsigned long long *sectors
);
109 /* get hardware sector size */
110 int blkdev_get_sector_size(int fd
, int *sector_size
);
112 /* specifies whether or not the device is misaligned */
113 int blkdev_is_misaligned(int fd
);
115 /* get physical block device size */
116 int blkdev_get_physector_size(int fd
, int *sector_size
);
118 /* is the device cdrom capable? */
119 int blkdev_is_cdrom(int fd
);
121 /* get device's geometry - legacy */
122 int blkdev_get_geometry(int fd
, unsigned int *h
, unsigned int *s
);
124 /* SCSI device types. Copied almost as-is from kernel header.
125 * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */
126 #define SCSI_TYPE_DISK 0x00
127 #define SCSI_TYPE_TAPE 0x01
128 #define SCSI_TYPE_PRINTER 0x02
129 #define SCSI_TYPE_PROCESSOR 0x03 /* HP scanners use this */
130 #define SCSI_TYPE_WORM 0x04 /* Treated as ROM by our system */
131 #define SCSI_TYPE_ROM 0x05
132 #define SCSI_TYPE_SCANNER 0x06
133 #define SCSI_TYPE_MOD 0x07 /* Magneto-optical disk - treated as SCSI_TYPE_DISK */
134 #define SCSI_TYPE_MEDIUM_CHANGER 0x08
135 #define SCSI_TYPE_COMM 0x09 /* Communications device */
136 #define SCSI_TYPE_RAID 0x0c
137 #define SCSI_TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
138 #define SCSI_TYPE_RBC 0x0e
139 #define SCSI_TYPE_OSD 0x11
140 #define SCSI_TYPE_NO_LUN 0x7f
142 /* convert scsi type code to name */
143 const char *blkdev_scsi_type_to_name(int type
);
146 #endif /* BLKDEV_H */