xref: /xnu-12377.1.9/bsd/sys/disk_private.h (revision f6217f891ac0bb64f3d375211650a4c1ff8ca1ea)
1 /*
2  * Copyright (c) 2025 Apple Computer, Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #ifndef _SYS_DISK_PRIVATE_H_
30 #define _SYS_DISK_PRIVATE_H_
31 
32 #include <sys/disk.h>
33 
34 #ifdef XNU_KERNEL_PRIVATE
35 #include <mach/boolean.h>
36 #endif /* XNU_KERNEL_PRIVATE */
37 
38 #ifdef KERNEL
39 
40 /* Definitions of option bits for dk_unmap_t */
41 #define _DK_UNMAP_INITIALIZE                   0x00000100
42 
43 #ifdef XNU_KERNEL_PRIVATE
44 typedef struct{
45 	boolean_t mi_mdev; /* Is this a memdev device? */
46 	boolean_t mi_phys; /* Physical memory? */
47 	uint32_t mi_base; /* Base page number of the device? */
48 	uint64_t mi_size; /* Size of the device (in ) */
49 } dk_memdev_info_t;
50 
51 typedef dk_memdev_info_t memdev_info_t;
52 
53 #define DKIOCGETMEMDEVINFO                    _IOR('d', 90, dk_memdev_info_t)
54 #endif /* XNU_KERNEL_PRIVATE */
55 typedef struct _dk_cs_pin {
56 	dk_extent_t     cp_extent;
57 	int64_t         cp_flags;
58 } _dk_cs_pin_t;
59 /* The following are modifiers to _DKIOCCSPINEXTENT/cp_flags operation */
60 #define _DKIOCCSPINTOFASTMEDIA          (0)                     /* Pin extent to the fast (SSD) media             */
61 #define _DKIOCCSPINFORHIBERNATION       (1 << 0)        /* Pin of hibernation file, content not preserved */
62 #define _DKIOCCSPINDISCARDDENYLIST      (1 << 1)        /* Hibernation complete/error, stop denylist-ing  */
63 #define _DKIOCCSPINTOSLOWMEDIA          (1 << 2)        /* Pin extent to the slow (HDD) media             */
64 #define _DKIOCCSTEMPORARYPIN            (1 << 3)        /* Relocate, but do not pin, to indicated media   */
65 #define _DKIOCCSHIBERNATEIMGSIZE        (1 << 4)        /* Anticipate/Max size of the upcoming hibernate  */
66 #define _DKIOCCSPINFORSWAPFILE          (1 << 5)        /* Pin of swap file, content not preserved        */
67 
68 #define _DKIOCCSSETLVNAME                     _IOW('d', 198, char[256])
69 #define _DKIOCCSPINEXTENT                     _IOW('d', 199, _dk_cs_pin_t)
70 #define _DKIOCCSUNPINEXTENT                   _IOW('d', 200, _dk_cs_pin_t)
71 #define _DKIOCGETMIGRATIONUNITBYTESIZE        _IOR('d', 201, uint32_t)
72 
73 typedef struct _dk_cs_map {
74 	dk_extent_t     cm_extent;
75 	uint64_t        cm_bytes_mapped;
76 } _dk_cs_map_t;
77 
78 typedef struct _dk_cs_unmap {
79 	dk_extent_t                  *extents;
80 	uint32_t                     extentsCount;
81 	uint32_t                     options;
82 } _dk_cs_unmap_t;
83 
84 #define _DKIOCCSMAP                           _IOWR('d', 202, _dk_cs_map_t)
85 // No longer used: _DKIOCCSSETFSVNODE (203) & _DKIOCCSGETFREEBYTES (204)
86 #define _DKIOCCSUNMAP                         _IOWR('d', 205, _dk_cs_unmap_t)
87 
88 typedef enum {
89 	DK_APFS_ONE_DEVICE = 1,
90 	DK_APFS_FUSION
91 } dk_apfs_flavour_t;
92 
93 #define DKIOCGETAPFSFLAVOUR     _IOR('d', 91, dk_apfs_flavour_t)
94 
95 // Extent's offset and length returned in bytes
96 typedef struct dk_apfs_wbc_range {
97 	dev_t dev;              // Physical device for extents
98 	uint32_t count;         // Number of extents
99 	dk_extent_t extents[2]; // Addresses are relative to device we return
100 } dk_apfs_wbc_range_t;
101 
102 #define DKIOCAPFSGETWBCRANGE           _IOR('d', 92, dk_apfs_wbc_range_t)
103 #define DKIOCAPFSRELEASEWBCRANGE       _IO('d', 93)
104 
105 #define DKIOCGETMAXSWAPWRITE           _IOR('d', 94, uint64_t)
106 
107 #endif /* KERNEL */
108 
109 #define _DKIOCSETSTATIC                       _IO('d', 84)
110 
111 #endif  /* _SYS_DISK_PRIVATE_H_ */
112