2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
17 /* You can define a particular architecture here if you are debugging. */
18 /* #define P_DEBUG p_sparc64 */
20 #define MAX_NO_DISKS 32
21 /* Max # of disks Disk_Names() will return */
23 #define MAX_SEC_SIZE 2048 /* maximum sector size that is supported */
24 #define MIN_SEC_SIZE 512 /* the sector size to end sensing at */
27 p_any
, /* for debugging ! */
38 extern const enum platform platform
;
77 #if defined(__i386__) || defined(__amd64__) /* the i386 needs extra help... */
81 u_long sector_size
; /* media sector size, a power of 2 */
91 u_int gpt_size
; /* Number of entries */
102 char *sname
; /* PC98 field */
105 /* Used during Fixup_Names() to avoid renaming more than
111 void (*private_free
)(void*);
112 void *(*private_clone
)(void*);
114 /* For data private to the application, and the management
115 * thereof. If the functions are not provided, no storage
116 * management is done, Cloning will just copy the pointer
117 * and freeing will just forget it.
124 * ALIGN - This chunk should be aligned
125 * IS_ROOT - This 'part' is a rootfs, allocate 'a'
126 * ACTIVE - This is the active slice in the MBR
127 * FORCE_ALL - Force a dedicated disk for FreeBSD, bypassing
128 * all BIOS geometry considerations
129 * AUTO_SIZE - This chunk was auto-sized and can fill-out a
130 * following chunk if the following chunk is deleted.
131 * NEWFS - newfs pending, used to enable auto-resizing on
132 * delete (along with AUTO_SIZE).
135 #define CHUNK_ALIGN 0x0008
136 #define CHUNK_IS_ROOT 0x0010
137 #define CHUNK_ACTIVE 0x0020
138 #define CHUNK_FORCE_ALL 0x0040
139 #define CHUNK_AUTO_SIZE 0x0080
140 #define CHUNK_NEWFS 0x0100
141 #define CHUNK_HAS_INDEX 0x0200
142 #define CHUNK_ITOF(i) ((i & 0xFFFF) << 16)
143 #define CHUNK_FTOI(f) ((f >> 16) & 0xFFFF)
145 #define DELCHUNK_NORMAL 0x0000
146 #define DELCHUNK_RECOVER 0x0001
148 const char *chunk_name(chunk_e
);
151 slice_type_name(int, int);
152 /* "chunk_n" for subtypes too */
155 Open_Disk(const char *);
156 /* Will open the named disk, and return populated tree. */
159 Free_Disk(struct disk
*);
160 /* Free a tree made with Open_Disk() or Clone_Disk() */
163 Debug_Disk(struct disk
*);
164 /* Print the content of the tree to stdout */
167 Set_Bios_Geom(struct disk
*, u_long
, u_long
, u_long
);
168 /* Set the geometry the bios uses. */
171 Sanitize_Bios_Geom(struct disk
*);
172 /* Set the bios geometry to something sane */
175 Insert_Chunk(struct chunk
*, daddr_t
, daddr_t
, const char *, chunk_e
, int,
176 u_long
, const char *);
179 Delete_Chunk2(struct disk
*, struct chunk
*, int);
180 /* Free a chunk of disk_space modified by the passed flags. */
183 Delete_Chunk(struct disk
*, struct chunk
*);
184 /* Free a chunk of disk_space */
187 Collapse_Disk(struct disk
*);
188 /* Experimental, do not use. */
191 Collapse_Chunk(struct disk
*, struct chunk
*);
192 /* Experimental, do not use. */
195 Create_Chunk(struct disk
*, daddr_t
, daddr_t
, chunk_e
, int, u_long
, const char *);
196 /* Create a chunk with the specified paramters */
199 All_FreeBSD(struct disk
*, int);
201 * Make one FreeBSD chunk covering the entire disk;
202 * if force_all is set, bypass all BIOS geometry
207 CheckRules(const struct disk
*);
208 /* Return char* to warnings about broken design rules in this disklayout */
213 * Return char** with all disk's names (wd0, wd1 ...). You must free
214 * each pointer, as well as the array by hand
219 Set_Boot_Mgr(struct disk
*, const u_char
*, const size_t, const u_char
*,
223 Set_Boot_Mgr(struct disk
*, const u_char
*, const size_t);
226 * Use this boot-manager on this disk. Gets written when Write_Disk()
231 Set_Boot_Blocks(struct disk
*, const u_char
*, const u_char
*);
233 * Use these boot-blocks on this disk. Gets written when Write_Disk()
234 * is called. Returns nonzero upon failure.
238 Write_Disk(const struct disk
*);
239 /* Write all the MBRs, disklabels, bootblocks and boot managers */
242 Next_Cyl_Aligned(const struct disk
*, daddr_t
);
243 /* Round offset up to next cylinder according to the bios-geometry */
246 Prev_Cyl_Aligned(const struct disk
*, daddr_t
);
247 /* Round offset down to previous cylinder according to the bios-geometry */
250 Track_Aligned(const struct disk
*, daddr_t
);
251 /* Check if offset is aligned on a track according to the bios geometry */
254 Next_Track_Aligned(const struct disk
*, daddr_t
);
255 /* Round offset up to next track according to the bios-geometry */
258 Prev_Track_Aligned(const struct disk
*, daddr_t
);
259 /* Check if offset is aligned on a track according to the bios geometry */
262 Create_Chunk_DWIM(struct disk
*, struct chunk
*, daddr_t
, chunk_e
, int,
265 * This one creates a partition inside the given parent of the given
266 * size, and returns a pointer to it. The first unused chunk big
271 ShowChunkFlags(struct chunk
*);
272 /* Return string to show flags. */
275 * Implementation details >>> DO NOT USE <<<
280 void Fill_Disklabel(struct disklabel
*, const struct disk
*,
281 const struct chunk
*);
282 void Debug_Chunk(struct chunk
*);
283 struct chunk
*New_Chunk(void);
284 void Free_Chunk(struct chunk
*);
285 struct chunk
*Clone_Chunk(const struct chunk
*);
286 int Add_Chunk(struct disk
*, daddr_t
, daddr_t
, const char *, chunk_e
, int,
287 u_long
, const char *);
288 void *read_block(int, daddr_t
, u_long
);
289 int write_block(int, daddr_t
, const void *, u_long
);
290 struct disklabel
*read_disklabel(int, daddr_t
, u_long
);
291 struct disk
*Int_Open_Disk(const char *, char *);
292 int Fixup_Names(struct disk
*);
293 int MakeDevChunk(const struct chunk
*, const char *);
296 #define dprintf printf
300 * Need an error string mechanism from the functions instead of warn()
302 * Make sure only FreeBSD start at offset==0
304 * Collapse must align.
306 * Make Write_Disk(struct disk*)
308 * Consider booting from OnTrack'ed disks.
310 * Get Bios-geom, ST506 & OnTrack from driver (or otherwise)
312 * Make Create_DWIM().
314 * Make Is_Unchanged(struct disk *d1, struct chunk *c1)
316 * don't rename slices unless we have to
318 *Sample output from tst01:
320 * Debug_Disk(wd0) flags=0 bios_geom=0/0/0
321 * >> 0x3d040 0 1411200 1411199 wd0 0 whole 0 0
322 * >>>> 0x3d080 0 960120 960119 wd0s1 3 freebsd 0 8
323 * >>>>>> 0x3d100 0 40960 40959 wd0s1a 5 part 0 0
324 * >>>>>> 0x3d180 40960 131072 172031 wd0s1b 5 part 0 0
325 * >>>>>> 0x3d1c0 172032 409600 581631 wd0s1e 5 part 0 0
326 * >>>>>> 0x3d200 581632 378488 960119 wd0s1f 5 part 0 0
327 * >>>> 0x3d140 960120 5670 965789 wd0s2 4 extended 0 8
328 * >>>>>> 0x3d2c0 960120 63 960182 - 6 unused 0 0
329 * >>>>>> 0x3d0c0 960183 5607 965789 wd0s5 2 fat 0 8
330 * >>>> 0x3d280 965790 1890 967679 wd0s3 1 foo -2 8
331 * >>>> 0x3d300 967680 443520 1411199 wd0s4 3 freebsd 0 8
332 * >>>>>> 0x3d340 967680 443520 1411199 wd0s4a 5 part 0 0
334 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
335 * level chunkptr start size end name type subtype flags
337 * Underlying data structure:
340 * <struct chunk> --> part
344 * <wd0> --> <wd0s1> --> <wd0s1a>
356 * <wd0s2> --> <unused>
365 * <wd0s4> --> <wd0s4a>
370 #endif /* _LIBDISK_H_ */