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