dosfstools  4.2
About: dosfstools are utilities to create, check and label (MS-DOS) FAT filesystems.
  Fossies Dox: dosfstools-4.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

blkdev.h
Go to the documentation of this file.
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 */
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 /* get partition devices start offset */
125 int blkdev_get_start(int fd, dev_t rdev, unsigned long long *s);
126 
127 /* SCSI device types. Copied almost as-is from kernel header.
128  * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */
129 #define SCSI_TYPE_DISK 0x00
130 #define SCSI_TYPE_TAPE 0x01
131 #define SCSI_TYPE_PRINTER 0x02
132 #define SCSI_TYPE_PROCESSOR 0x03 /* HP scanners use this */
133 #define SCSI_TYPE_WORM 0x04 /* Treated as ROM by our system */
134 #define SCSI_TYPE_ROM 0x05
135 #define SCSI_TYPE_SCANNER 0x06
136 #define SCSI_TYPE_MOD 0x07 /* Magneto-optical disk - treated as SCSI_TYPE_DISK */
137 #define SCSI_TYPE_MEDIUM_CHANGER 0x08
138 #define SCSI_TYPE_COMM 0x09 /* Communications device */
139 #define SCSI_TYPE_RAID 0x0c
140 #define SCSI_TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
141 #define SCSI_TYPE_RBC 0x0e
142 #define SCSI_TYPE_OSD 0x11
143 #define SCSI_TYPE_NO_LUN 0x7f
144 
145 /* convert scsi type code to name */
146 const char *blkdev_scsi_type_to_name(int type);
147 
148 
149 #endif /* BLKDEV_H */
off_t blkdev_find_size(int fd)
Definition: blkdev.c:56
int is_blkdev(int fd)
Definition: blkdev.c:49
const char * blkdev_scsi_type_to_name(int type)
Definition: blkdev.c:362
int blkdev_get_sectors(int fd, unsigned long long *sectors)
Definition: blkdev.c:186
int blkdev_get_size(int fd, unsigned long long *bytes)
Definition: blkdev.c:86
int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s)
Definition: blkdev.c:288
int blkdev_get_sector_size(int fd, int *sector_size)
Definition: blkdev.c:204
int blkdev_get_start(int fd, dev_t rdev, unsigned long long *s)
Definition: blkdev.c:323
int blkdev_is_misaligned(int fd)
Definition: blkdev.c:247
int blkdev_get_physector_size(int fd, int *sector_size)
Definition: blkdev.c:231
int blkdev_is_cdrom(int fd)
Definition: blkdev.c:265
static int fd
Definition: io.c:56
static unsigned sector_size
Definition: mkfs.fat.c:240
unsigned long start
Definition: blkdev.h:92
unsigned char heads
Definition: blkdev.h:89
unsigned char sectors
Definition: blkdev.h:90
unsigned short cylinders
Definition: blkdev.h:91