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