]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/blkdev.h
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 */
20 #ifdef HAVE_SYS_MKDEV_H
21 # include <sys/mkdev.h> /* major and minor on Solaris */
24 #define DEFAULT_SECTOR_SIZE 512
27 /* very basic ioctls, should be available everywhere */
29 # define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
30 # define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
31 # define BLKRRPART _IO(0x12,95) /* re-read partition table */
32 # define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
33 # define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
34 # define BLKRASET _IO(0x12,98) /* set read ahead for block device */
35 # define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
36 # define BLKFRASET _IO(0x12,100) /* set filesystem (mm/filemap.c) read-ahead */
37 # define BLKFRAGET _IO(0x12,101) /* get filesystem (mm/filemap.c) read-ahead */
38 # define BLKSECTSET _IO(0x12,102) /* set max sectors per request (ll_rw_blk.c) */
39 # define BLKSECTGET _IO(0x12,103) /* get max sectors per request (ll_rw_blk.c) */
40 # define BLKSSZGET _IO(0x12,104) /* get block device sector size */
42 /* ioctls introduced in 2.2.16, removed in 2.5.58 */
43 # define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
44 # define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
46 # define BLKBSZGET _IOR(0x12,112,size_t)
47 # define BLKBSZSET _IOW(0x12,113,size_t)
48 # endif /* !BLKROSET */
51 # define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
54 /* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
56 # define BLKIOMIN _IO(0x12,120)
57 # define BLKIOOPT _IO(0x12,121)
58 # define BLKALIGNOFF _IO(0x12,122)
59 # define BLKPBSZGET _IO(0x12,123)
62 /* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
63 # ifndef BLKDISCARDZEROES
64 # define BLKDISCARDZEROES _IO(0x12,124)
67 /* disk sequence number, introduced in 5.15 (commit 7957d93b) */
68 # ifndef BLKGETDISKSEQ
69 # define BLKGETDISKSEQ _IOR(0x12, 128, uint64_t)
72 /* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
74 # define FIFREEZE _IOWR('X', 119, int) /* Freeze */
75 # define FITHAW _IOWR('X', 120, int) /* Thaw */
78 /* uniform CD-ROM information */
79 # ifndef CDROM_GET_CAPABILITY
80 # define CDROM_GET_CAPABILITY 0x5331
87 # define BLKGETSIZE DKIOCGETBLOCKCOUNT32
92 # define HDIO_GETGEO 0x0301
97 unsigned char sectors
;
98 unsigned short cylinders
; /* truncated */
101 #endif /* HDIO_GETGEO */
104 /* are we working with block device? */
105 int is_blkdev(int fd
);
107 /* open block device or file */
108 int open_blkdev_or_file(const struct stat
*st
, const char *name
, const int oflag
);
110 /* Determine size in bytes */
111 off_t
blkdev_find_size (int fd
);
113 /* get size in bytes */
114 int blkdev_get_size(int fd
, unsigned long long *bytes
);
116 /* get 512-byte sector count */
117 int blkdev_get_sectors(int fd
, unsigned long long *sectors
);
119 /* get hardware sector size */
120 int blkdev_get_sector_size(int fd
, int *sector_size
);
122 /* specifies whether or not the device is misaligned */
123 int blkdev_is_misaligned(int fd
);
125 /* get physical block device size */
126 int blkdev_get_physector_size(int fd
, int *sector_size
);
128 /* is the device cdrom capable? */
129 int blkdev_is_cdrom(int fd
);
131 /* get device's geometry - legacy */
132 int blkdev_get_geometry(int fd
, unsigned int *h
, unsigned int *s
);
134 /* SCSI device types. Copied almost as-is from kernel header.
135 * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */
136 #define SCSI_TYPE_DISK 0x00
137 #define SCSI_TYPE_TAPE 0x01
138 #define SCSI_TYPE_PRINTER 0x02
139 #define SCSI_TYPE_PROCESSOR 0x03 /* HP scanners use this */
140 #define SCSI_TYPE_WORM 0x04 /* Treated as ROM by our system */
141 #define SCSI_TYPE_ROM 0x05
142 #define SCSI_TYPE_SCANNER 0x06
143 #define SCSI_TYPE_MOD 0x07 /* Magneto-optical disk - treated as SCSI_TYPE_DISK */
144 #define SCSI_TYPE_MEDIUM_CHANGER 0x08
145 #define SCSI_TYPE_COMM 0x09 /* Communications device */
146 #define SCSI_TYPE_RAID 0x0c
147 #define SCSI_TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
148 #define SCSI_TYPE_RBC 0x0e
149 #define SCSI_TYPE_OSD 0x11
150 #define SCSI_TYPE_NO_LUN 0x7f
152 /* convert scsi type code to name */
153 const char *blkdev_scsi_type_to_name(int type
);
155 int blkdev_lock(int fd
, const char *devname
, const char *lockmode
);
156 #ifdef HAVE_LINUX_BLKZONED_H
157 struct blk_zone_report
*blkdev_get_zonereport(int fd
, uint64_t sector
, uint32_t nzones
);
159 static inline struct blk_zone_report
*blkdev_get_zonereport(int fd
, uint64_t sector
, uint32_t nzones
)
165 #endif /* BLKDEV_H */