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 18 #ifdef HAVE_SYS_MKDEV_H 19 # include <sys/mkdev.h> /* major and minor on Solaris */ 20 #endif 21 22 #define DEFAULT_SECTOR_SIZE 512 23 24 #ifdef __linux__ 25 /* very basic ioctls, should be available everywhere */ 26 # ifndef BLKROSET 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 */ 39 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 */ 43 44 # define BLKBSZGET _IOR(0x12,112,size_t) 45 # define BLKBSZSET _IOW(0x12,113,size_t) 46 # endif /* !BLKROSET */ 47 48 # ifndef BLKGETSIZE64 49 # define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ 50 # endif 51 52 /* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */ 53 # ifndef BLKIOMIN 54 # define BLKIOMIN _IO(0x12,120) 55 # define BLKIOOPT _IO(0x12,121) 56 # define BLKALIGNOFF _IO(0x12,122) 57 # define BLKPBSZGET _IO(0x12,123) 58 # endif 59 60 /* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */ 61 # ifndef BLKDISCARDZEROES 62 # define BLKDISCARDZEROES _IO(0x12,124) 63 # endif 64 65 /* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */ 66 # ifndef FIFREEZE 67 # define FIFREEZE _IOWR('X', 119, int) /* Freeze */ 68 # define FITHAW _IOWR('X', 120, int) /* Thaw */ 69 # endif 70 71 /* uniform CD-ROM information */ 72 # ifndef CDROM_GET_CAPABILITY 73 # define CDROM_GET_CAPABILITY 0x5331 74 # endif 75 76 #endif /* __linux */ 77 78 79 #ifdef APPLE_DARWIN 80 # define BLKGETSIZE DKIOCGETBLOCKCOUNT32 81 #endif 82 83 #ifndef HDIO_GETGEO 84 # ifdef __linux__ 85 # define HDIO_GETGEO 0x0301 86 # endif 87 88 struct hd_geometry { 89 unsigned char heads; 90 unsigned char sectors; 91 unsigned short cylinders; /* truncated */ 92 unsigned long start; 93 }; 94 #endif /* HDIO_GETGEO */ 95 96 97 /* are we working with block device? */ 98 int is_blkdev(int fd); 99 100 /* Determine size in bytes */ 101 off_t blkdev_find_size (int fd); 102 103 /* get size in bytes */ 104 int blkdev_get_size(int fd, unsigned long long *bytes); 105 106 /* get 512-byte sector count */ 107 int blkdev_get_sectors(int fd, unsigned long long *sectors); 108 109 /* get hardware sector size */ 110 int blkdev_get_sector_size(int fd, int *sector_size); 111 112 /* specifies whether or not the device is misaligned */ 113 int blkdev_is_misaligned(int fd); 114 115 /* get physical block device size */ 116 int blkdev_get_physector_size(int fd, int *sector_size); 117 118 /* is the device cdrom capable? */ 119 int blkdev_is_cdrom(int fd); 120 121 /* get device's geometry - legacy */ 122 int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s); 123 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 141 142 /* convert scsi type code to name */ 143 const char *blkdev_scsi_type_to_name(int type); 144 145 146 #endif /* BLKDEV_H */ 147
This page was automatically generated by LXR 0.3.1. • OpenWrt