xref: /freebsd/sys/sys/disk.h (revision 2f513db7)
1 /*-
2  * SPDX-License-Identifier: Beerware
3  *
4  * ----------------------------------------------------------------------------
5  * "THE BEER-WARE LICENSE" (Revision 42):
6  * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
7  * can do whatever you want with this stuff. If we meet some day, and you think
8  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
9  * ----------------------------------------------------------------------------
10  *
11  * $FreeBSD$
12  *
13  */
14 
15 #ifndef _SYS_DISK_H_
16 #define	_SYS_DISK_H_
17 
18 #include <sys/ioccom.h>
19 #include <sys/kerneldump.h>
20 #include <sys/types.h>
21 #include <sys/disk_zone.h>
22 #include <sys/socket.h>
23 
24 #ifdef _KERNEL
25 
26 #ifndef _SYS_CONF_H_
27 #include <sys/conf.h>	/* XXX: temporary to avoid breakage */
28 #endif
29 
30 void disk_err(struct bio *bp, const char *what, int blkdone, int nl);
31 
32 #endif
33 
34 #define	DIOCGSECTORSIZE	_IOR('d', 128, u_int)
35 	/*
36 	 * Get the sector size of the device in bytes.  The sector size is the
37 	 * smallest unit of data which can be transferred from this device.
38 	 * Usually this is a power of 2 but it might not be (i.e. CDROM audio).
39 	 */
40 
41 #define	DIOCGMEDIASIZE	_IOR('d', 129, off_t)	/* Get media size in bytes */
42 	/*
43 	 * Get the size of the entire device in bytes.  This should be a
44 	 * multiple of the sector size.
45 	 */
46 
47 #define	DIOCGFWSECTORS	_IOR('d', 130, u_int)	/* Get firmware's sectorcount */
48 	/*
49 	 * Get the firmware's notion of number of sectors per track.  This
50 	 * value is mostly used for compatibility with various ill designed
51 	 * disk label formats.  Don't use it unless you have to.
52 	 */
53 
54 #define	DIOCGFWHEADS	_IOR('d', 131, u_int)	/* Get firmware's headcount */
55 	/*
56 	 * Get the firmwares notion of number of heads per cylinder.  This
57 	 * value is mostly used for compatibility with various ill designed
58 	 * disk label formats.  Don't use it unless you have to.
59 	 */
60 
61 #define	DIOCSKERNELDUMP_FREEBSD11 _IOW('d', 133, u_int)
62 	/*
63 	 * Enable/Disable (the argument is boolean) the device for kernel
64 	 * core dumps.
65 	 */
66 
67 #define	DIOCGFRONTSTUFF _IOR('d', 134, off_t)
68 	/*
69 	 * Many disk formats have some amount of space reserved at the
70 	 * start of the disk to hold bootblocks, various disklabels and
71 	 * similar stuff.  This ioctl returns the number of such bytes
72 	 * which may apply to the device.
73 	 */
74 
75 #define	DIOCGFLUSH _IO('d', 135)		/* Flush write cache */
76 	/*
77 	 * Flush write cache of the device.
78 	 */
79 
80 #define	DIOCGDELETE _IOW('d', 136, off_t[2])	/* Delete data */
81 	/*
82 	 * Mark data on the device as unused.
83 	 */
84 
85 #define	DISK_IDENT_SIZE	256
86 #define	DIOCGIDENT _IOR('d', 137, char[DISK_IDENT_SIZE])
87 	/*-
88 	 * Get the ident of the given provider. Ident is (most of the time)
89 	 * a uniqe and fixed provider's identifier. Ident's properties are as
90 	 * follow:
91 	 * - ident value is preserved between reboots,
92 	 * - provider can be detached/attached and ident is preserved,
93 	 * - provider's name can change - ident can't,
94 	 * - ident value should not be based on on-disk metadata; in other
95 	 *   words copying whole data from one disk to another should not
96 	 *   yield the same ident for the other disk,
97 	 * - there could be more than one provider with the same ident, but
98 	 *   only if they point at exactly the same physical storage, this is
99 	 *   the case for multipathing for example,
100 	 * - GEOM classes that consumes single providers and provide single
101 	 *   providers, like geli, gbde, should just attach class name to the
102 	 *   ident of the underlying provider,
103 	 * - ident is an ASCII string (is printable),
104 	 * - ident is optional and applications can't relay on its presence.
105 	 */
106 
107 #define	DIOCGPROVIDERNAME _IOR('d', 138, char[MAXPATHLEN])
108 	/*
109 	 * Store the provider name, given a device path, in a buffer. The buffer
110 	 * must be at least MAXPATHLEN bytes long.
111 	 */
112 
113 #define	DIOCGSTRIPESIZE	_IOR('d', 139, off_t)	/* Get stripe size in bytes */
114 	/*
115 	 * Get the size of the device's optimal access block in bytes.
116 	 * This should be a multiple of the sector size.
117 	 */
118 
119 #define	DIOCGSTRIPEOFFSET _IOR('d', 140, off_t)	/* Get stripe offset in bytes */
120 	/*
121 	 * Get the offset of the first device's optimal access block in bytes.
122 	 * This should be a multiple of the sector size.
123 	 */
124 
125 #define	DIOCGPHYSPATH _IOR('d', 141, char[MAXPATHLEN])
126 	/*
127 	 * Get a string defining the physical path for a given provider.
128 	 * This has similar rules to ident, but is intended to uniquely
129 	 * identify the physical location of the device, not the current
130 	 * occupant of that location.
131 	 */
132 
133 struct diocgattr_arg {
134 	char name[64];
135 	int len;
136 	union {
137 		char str[DISK_IDENT_SIZE];
138 		off_t off;
139 		int i;
140 		uint16_t u16;
141 	} value;
142 };
143 #define	DIOCGATTR _IOWR('d', 142, struct diocgattr_arg)
144 
145 #define	DIOCZONECMD	_IOWR('d', 143, struct disk_zone_args)
146 
147 struct diocskerneldump_arg_freebsd12 {
148 	uint8_t		 kda12_enable;
149 	uint8_t		 kda12_compression;
150 	uint8_t		 kda12_encryption;
151 	uint8_t		 kda12_key[KERNELDUMP_KEY_MAX_SIZE];
152 	uint32_t	 kda12_encryptedkeysize;
153 	uint8_t		*kda12_encryptedkey;
154 };
155 #define	DIOCSKERNELDUMP_FREEBSD12 \
156 	_IOW('d', 144, struct diocskerneldump_arg_freebsd12)
157 
158 #ifndef WITHOUT_NETDUMP
159 #include <net/if.h>
160 #include <netinet/in.h>
161 
162 union kd_ip {
163 	struct in_addr	in4;
164 	struct in6_addr	in6;
165 };
166 
167 /*
168  * Sentinel values for kda_index.
169  *
170  * If kda_index is KDA_REMOVE_ALL, all dump configurations are cleared.
171  *
172  * If kda_index is KDA_REMOVE_DEV, all dump configurations for the specified
173  * device are cleared.
174  *
175  * If kda_index is KDA_REMOVE, only the specified dump configuration for the
176  * given device is removed from the list of fallback dump configurations.
177  *
178  * If kda_index is KDA_APPEND, the dump configuration is added after all
179  * existing dump configurations.
180  *
181  * Otherwise, the new configuration is inserted into the fallback dump list at
182  * index 'kda_index'.
183  */
184 #define	KDA_REMOVE		UINT8_MAX
185 #define	KDA_REMOVE_ALL		(UINT8_MAX - 1)
186 #define	KDA_REMOVE_DEV		(UINT8_MAX - 2)
187 #define	KDA_APPEND		(UINT8_MAX - 3)
188 struct diocskerneldump_arg {
189 	uint8_t		 kda_index;
190 	uint8_t		 kda_compression;
191 	uint8_t		 kda_encryption;
192 	uint8_t		 kda_key[KERNELDUMP_KEY_MAX_SIZE];
193 	uint32_t	 kda_encryptedkeysize;
194 	uint8_t		*kda_encryptedkey;
195 	char		 kda_iface[IFNAMSIZ];
196 	union kd_ip	 kda_server;
197 	union kd_ip	 kda_client;
198 	union kd_ip	 kda_gateway;
199 	uint8_t		 kda_af;
200 };
201 _Static_assert(__offsetof(struct diocskerneldump_arg, kda_iface) ==
202     sizeof(struct diocskerneldump_arg_freebsd12), "simplifying assumption");
203 #define	DIOCSKERNELDUMP _IOW('d', 145, struct diocskerneldump_arg)
204 	/*
205 	 * Enable/Disable the device for kernel core dumps.
206 	 */
207 
208 #define	DIOCGKERNELDUMP _IOWR('d', 146, struct diocskerneldump_arg)
209 	/*
210 	 * Get current kernel netdump configuration details for a given index.
211 	 */
212 #endif
213 
214 #endif /* _SYS_DISK_H_ */
215