]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/blkdev.h
Merge branch 'PR/libmount-exec-errors' of github.com:karelzak/util-linux-work
[thirdparty/util-linux.git] / include / blkdev.h
CommitLineData
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>
6be38dcc 18#include <stdint.h>
3738a48e 19
fbc333fe 20#ifdef HAVE_SYS_MKDEV_H
960f668f
KZ
21# include <sys/mkdev.h> /* major and minor on Solaris */
22#endif
23
3738a48e
SK
24#define DEFAULT_SECTOR_SIZE 512
25
9ef30d61 26#ifdef __linux__
a5c523a0 27/* very basic ioctls, should be available everywhere */
9ef30d61
KZ
28# ifndef BLKROSET
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 */
3738a48e 41
8505ff35 42/* ioctls introduced in 2.2.16, removed in 2.5.58 */
9ef30d61
KZ
43# define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
44# define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
3738a48e 45
9ef30d61
KZ
46# define BLKBSZGET _IOR(0x12,112,size_t)
47# define BLKBSZSET _IOW(0x12,113,size_t)
48# endif /* !BLKROSET */
3738a48e 49
9ef30d61
KZ
50# ifndef BLKGETSIZE64
51# define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
52# endif
30696241 53
9ef30d61
KZ
54/* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
55# ifndef BLKIOMIN
56# define BLKIOMIN _IO(0x12,120)
57# define BLKIOOPT _IO(0x12,121)
58# define BLKALIGNOFF _IO(0x12,122)
59# define BLKPBSZGET _IO(0x12,123)
60# endif
1519ab5f 61
9ef30d61
KZ
62/* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
63# ifndef BLKDISCARDZEROES
64# define BLKDISCARDZEROES _IO(0x12,124)
65# endif
ed98508a 66
c10adc20
TW
67/* disk sequence number, introduced in 5.15 (commit 7957d93b) */
68# ifndef BLKGETDISKSEQ
69# define BLKGETDISKSEQ _IOR(0x12, 128, uint64_t)
70# endif
71
9ef30d61
KZ
72/* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
73# ifndef FIFREEZE
74# define FIFREEZE _IOWR('X', 119, int) /* Freeze */
75# define FITHAW _IOWR('X', 120, int) /* Thaw */
76# endif
3738a48e 77
aa323539
KZ
78/* uniform CD-ROM information */
79# ifndef CDROM_GET_CAPABILITY
80# define CDROM_GET_CAPABILITY 0x5331
81# endif
82
9ef30d61 83#endif /* __linux */
1519ab5f 84
aa323539 85
9ef30d61
KZ
86#ifdef APPLE_DARWIN
87# define BLKGETSIZE DKIOCGETBLOCKCOUNT32
f0bef3ca
HT
88#endif
89
3738a48e 90#ifndef HDIO_GETGEO
268cefe6
ST
91# ifdef __linux__
92# define HDIO_GETGEO 0x0301
93# endif
3b622ddd 94
3738a48e
SK
95struct hd_geometry {
96 unsigned char heads;
97 unsigned char sectors;
98 unsigned short cylinders; /* truncated */
99 unsigned long start;
100};
aa323539
KZ
101#endif /* HDIO_GETGEO */
102
3738a48e 103
8150beac
DB
104/* are we working with block device? */
105int is_blkdev(int fd);
106
8fe1e638
SK
107/* open block device or file */
108int open_blkdev_or_file(const struct stat *st, const char *name, const int oflag);
109
268cefe6
ST
110/* Determine size in bytes */
111off_t blkdev_find_size (int fd);
112
3738a48e
SK
113/* get size in bytes */
114int blkdev_get_size(int fd, unsigned long long *bytes);
115
116/* get 512-byte sector count */
117int blkdev_get_sectors(int fd, unsigned long long *sectors);
118
119/* get hardware sector size */
120int blkdev_get_sector_size(int fd, int *sector_size);
121
ba326929
DB
122/* specifies whether or not the device is misaligned */
123int blkdev_is_misaligned(int fd);
124
0e75337c
DB
125/* get physical block device size */
126int blkdev_get_physector_size(int fd, int *sector_size);
127
3b622ddd
DB
128/* is the device cdrom capable? */
129int blkdev_is_cdrom(int fd);
130
64128b70
DB
131/* get device's geometry - legacy */
132int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s);
133
18608821
CAM
134/* SCSI device types. Copied almost as-is from kernel header
135 * (include/scsi/scsi_proto.h). */
aa323539
KZ
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
151
ba32a946 152/* convert scsi type code to name */
2fc4a256 153const char *blkdev_scsi_type_to_name(int type);
ba32a946 154
37b30204 155int blkdev_lock(int fd, const char *devname, const char *lockmode);
6be38dcc
NA
156#ifdef HAVE_LINUX_BLKZONED_H
157struct blk_zone_report *blkdev_get_zonereport(int fd, uint64_t sector, uint32_t nzones);
158#else
2dce92d0
TW
159static inline struct blk_zone_report *blkdev_get_zonereport(int fd __attribute__((unused)),
160 uint64_t sector __attribute__((unused)),
161 uint32_t nzones __attribute__((unused)))
6be38dcc
NA
162{
163 return NULL;
164}
165#endif
aa323539 166
3738a48e 167#endif /* BLKDEV_H */