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