Remove last remnants of the wd(4) driver which was moved to the Attic some
[dragonfly.git] / lib / libdisk / libdisk.h
CommitLineData
984263bc
MD
1/*
2* ----------------------------------------------------------------------------
3* "THE BEER-WARE LICENSE" (Revision 42):
4* <phk@login.dknet.dk> 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* ----------------------------------------------------------------------------
8*
9* $FreeBSD: src/lib/libdisk/libdisk.h,v 1.32.2.8 2002/01/07 07:53:29 dillon Exp $
365ae791 10* $DragonFly: src/lib/libdisk/Attic/libdisk.h,v 1.4 2005/02/26 12:00:54 swildner Exp $
984263bc
MD
11*
12*/
13
14#define MAX_NO_DISKS 32
15/* Max # of disks Disk_Names() will return */
16
17#define MAX_SEC_SIZE 2048 /* maximum sector size that is supported */
18#define MIN_SEC_SIZE 512 /* the sector size to end sensing at */
19
20typedef enum {
21 whole,
22 unknown,
23 fat,
24 freebsd,
25 extended,
26 part,
27 unused
28} chunk_e;
29
30__BEGIN_DECLS
31struct disk {
32 char *name;
33 u_long flags;
34# define DISK_ON_TRACK 1
35 u_long bios_cyl;
36 u_long bios_hd;
37 u_long bios_sect;
38#ifdef PC98
39 u_char *bootipl;
40 size_t bootipl_size;
41 u_char *bootmenu;
42 size_t bootmenu_size;
43#else
44 u_char *bootmgr;
45 size_t bootmgr_size;
46#endif
47 u_char *boot1;
48#if defined(__i386__) /* the i386 needs extra help... */
49 u_char *boot2;
50#endif
51 struct chunk *chunks;
52 u_long sector_size; /* media sector size, a power of 2 */
53};
54
55struct chunk {
56 struct chunk *next;
57 struct chunk *part;
58 struct disk *disk;
59 long offset;
60 u_long size;
61 u_long end;
62#ifdef PC98
63 char *sname;
64#endif
65 char *name;
66 char *oname;
67 /* Used during Fixup_Names() to avoid renaming more than
68 * absolutely needed.
69 */
70 chunk_e type;
71 int subtype;
72 u_long flags;
73 void (*private_free)(void*);
74 void *(*private_clone)(void*);
75 void *private_data;
76 /* For data private to the application, and the management
77 * thereof. If the functions are not provided, no storage
78 * management is done, Cloning will just copy the pointer
79 * and freeing will just forget it.
80 */
81};
82
83/*
84 * flags:
85 *
86 * BSD_COMPAT - This chunk is in the BSD-compatibility, and has
365ae791 87 * a short name too, ie ad0s4f -> ad0f
984263bc
MD
88 * ALIGN - This chunk should be aligned
89 * IS_ROOT - This 'part' is a rootfs, allocate 'a'
90 * ACTIVE - This is the active slice in the MBR
91 * FORCE_ALL - Force a dedicated disk for FreeBSD, bypassing
92 * all BIOS geometry considerations
93 * AUTO_SIZE - This chunk was auto-sized and can fill-out a
94 * following chunk if the following chunk is deleted.
95 * NEWFS - newfs pending, used to enable auto-resizing on
96 * delete (along with AUTO_SIZE).
97 */
98
99#define CHUNK_BSD_COMPAT 0x0002
100#define CHUNK_ALIGN 0x0008
101#define CHUNK_IS_ROOT 0x0010
102#define CHUNK_ACTIVE 0x0020
103#define CHUNK_FORCE_ALL 0x0040
104#define CHUNK_AUTO_SIZE 0x0080
105#define CHUNK_NEWFS 0x0100
106
107#define DELCHUNK_NORMAL 0x0000
108#define DELCHUNK_RECOVER 0x0001
109
110
111extern const char *chunk_n[];
112
113const char *
114slice_type_name( int type, int subtype );
115/* "chunk_n" for subtypes too
116 */
117
118struct disk *
119Open_Disk(const char *devname);
120/* Will open the named disk, and return populated tree.
121 */
122
123struct disk *
124Clone_Disk(struct disk *disk);
125/* Clone a copy of a tree. Useful for "Undo" functionality
126 */
127
128void
129Free_Disk(struct disk *disk);
130/* Free a tree made with Open_Disk() or Clone_Disk()
131 */
132
133void
134Debug_Disk(struct disk *disk);
135/* Print the content of the tree to stdout
136 */
137
138void
139Set_Bios_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
140/* Set the geometry the bios uses.
141 */
142
143void
144Sanitize_Bios_Geom(struct disk *disk);
145/* Set the bios geometry to something sane
146 */
147
148int
149Delete_Chunk2(struct disk *disk, struct chunk *, int flags);
150/* Free a chunk of disk_space modified by the passed
151 * flags.
152 */
153
154int
155Delete_Chunk(struct disk *disk, struct chunk *);
156/* Free a chunk of disk_space
157 */
158
159void
160Collapse_Disk(struct disk *disk);
161/* Experimental, do not use.
162 */
163int
164Collapse_Chunk(struct disk *disk, struct chunk *chunk);
165/* Experimental, do not use.
166 */
167
168int
169#ifdef PC98
170Create_Chunk(struct disk *disk, u_long offset, u_long size, chunk_e type,
171 int subtype, u_long flags, const char *);
172#else
173Create_Chunk(struct disk *disk, u_long offset, u_long size, chunk_e type,
174 int subtype, u_long flags);
175#endif
176/* Create a chunk with the specified paramters
177 */
178
179void
180All_FreeBSD(struct disk *d, int force_all);
181/* Make one FreeBSD chunk covering the entire disk;
182 * if force_all is set, bypass all BIOS geometry
183 * considerations.
184 */
185
186char *
187CheckRules(struct disk *);
188/* Return char* to warnings about broken design rules in this disklayout
189 */
190
191char **
f6eb8355 192Disk_Names(void);
365ae791 193/* Return char** with all disk's names (ad0, ad1 ...). You must free
984263bc
MD
194 * each pointer, as well as the array by hand
195 */
196
197#ifdef PC98
198void
199Set_Boot_Mgr(struct disk *d, const u_char *bootipl, const size_t bootipl_size,
200 const u_char *bootmenu, const size_t bootmenu_size);
201#else
202void
203Set_Boot_Mgr(struct disk *d, const u_char *bootmgr, const size_t bootmgr_size);
204#endif
205/* Use this boot-manager on this disk. Gets written when Write_Disk()
206 * is called
207 */
208
209int
210Set_Boot_Blocks(struct disk *d, const u_char *_boot1, const u_char *_boot2);
211/* Use these boot-blocks on this disk. Gets written when Write_Disk()
212 * is called. Returns nonzero upon failure.
213 */
214
215int
216Write_Disk(struct disk *d);
217/* Write all the MBRs, disklabels, bootblocks and boot managers
218 */
219
220int
221Cyl_Aligned(struct disk *d, u_long offset);
222/* Check if offset is aligned on a cylinder according to the
223 * bios geometry
224 */
225
226u_long
227Next_Cyl_Aligned(struct disk *d, u_long offset);
228/* Round offset up to next cylinder according to the bios-geometry
229 */
230
231u_long
232Prev_Cyl_Aligned(struct disk *d, u_long offset);
233/* Round offset down to previous cylinder according to the bios-
234 * geometry
235 */
236
237int
238Track_Aligned(struct disk *d, u_long offset);
239/* Check if offset is aligned on a track according to the
240 * bios geometry
241 */
242
243u_long
244Next_Track_Aligned(struct disk *d, u_long offset);
245/* Round offset up to next track according to the bios-geometry
246 */
247
248u_long
249Prev_Track_Aligned(struct disk *d, u_long offset);
250/* Check if offset is aligned on a track according to the
251 * bios geometry
252 */
253
254struct chunk *
255Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size,
256 chunk_e type, int subtype, u_long flags);
257/* This one creates a partition inside the given parent of the given
258 * size, and returns a pointer to it. The first unused chunk big
259 * enough is used.
260 */
261
262int
263MakeDev(struct chunk *c, const char *path);
264
265int
266MakeDevDisk(struct disk *d, const char *path);
267/* Make device nodes for all chunks on this disk */
268
269char *
270ShowChunkFlags(struct chunk *c);
271/* Return string to show flags. */
272
273char *
274ChunkCanBeRoot(struct chunk *c);
275/* Return NULL if chunk can be /, explanation otherwise */
276
277/*
278 * Implementation details >>> DO NOT USE <<<
279 */
280
281void Debug_Chunk(struct chunk *);
282void Free_Chunk(struct chunk *);
283struct chunk * Clone_Chunk(struct chunk *);
284#ifdef PC98
285int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long, const char *);
286#else
287int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long);
288#endif
289void * read_block(int, daddr_t, u_long);
290int write_block(int, daddr_t, void *, u_long);
291struct disklabel * read_disklabel(int, daddr_t, u_long);
292struct chunk * Find_Mother_Chunk(struct chunk *, u_long, u_long, chunk_e);
293struct disk * Int_Open_Disk(const char *name, u_long size);
294int Fixup_Names(struct disk *);
295__END_DECLS
296
297#define dprintf printf
298
299/* TODO
300 *
301 * Need a error string mechanism from the functions instead of warn()
302 *
303 * Make sure only FreeBSD start at offset==0
304 *
305 * Collapse must align.
306 *
307 * Make Write_Disk(struct disk*)
308 *
309 * Consider booting from OnTrack'ed disks.
310 *
311 * Get Bios-geom, ST506 & OnTrack from driver (or otherwise)
312 *
313 * Make Create_DWIM().
314 *
315 * Make Is_Unchanged(struct disk *d1, struct chunk *c1)
316 *
317 * don't rename slices unless we have to
318 *
319 *Sample output from tst01:
320 *
365ae791
SW
321 * Debug_Disk(ad0) flags=0 bios_geom=0/0/0
322 * >> 0x3d040 0 1411200 1411199 ad0 0 whole 0 0
323 * >>>> 0x3d080 0 960120 960119 ad0s1 3 freebsd 0 8
324 * >>>>>> 0x3d100 0 40960 40959 ad0s1a 5 part 0 0
325 * >>>>>> 0x3d180 40960 131072 172031 ad0s1b 5 part 0 0
326 * >>>>>> 0x3d1c0 172032 409600 581631 ad0s1e 5 part 0 0
327 * >>>>>> 0x3d200 581632 378488 960119 ad0s1f 5 part 0 0
328 * >>>> 0x3d140 960120 5670 965789 ad0s2 4 extended 0 8
984263bc 329 * >>>>>> 0x3d2c0 960120 63 960182 - 6 unused 0 0
365ae791
SW
330 * >>>>>> 0x3d0c0 960183 5607 965789 ad0s5 2 fat 0 8
331 * >>>> 0x3d280 965790 1890 967679 ad0s3 1 foo -2 8
332 * >>>> 0x3d300 967680 443520 1411199 ad0s4 3 freebsd 0 8
333 * >>>>>> 0x3d340 967680 443520 1411199 ad0s4a 5 part 0 0
984263bc
MD
334 *
335 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
336 * level chunkptr start size end name type subtype flags
337 *
338 * Underlying data structure:
339 *
340 * Legend:
341 * <struct chunk> --> part
342 * |
343 * v next
344 *
365ae791 345 * <ad0> --> <ad0s1> --> <ad0s1a>
984263bc
MD
346 * | |
347 * | v
365ae791 348 * | <ad0s1b>
984263bc
MD
349 * | |
350 * | v
365ae791 351 * | <ad0s1e>
984263bc
MD
352 * | |
353 * | v
365ae791 354 * | <ad0s1f>
984263bc
MD
355 * |
356 * v
365ae791 357 * <ad0s2> --> <unused>
984263bc
MD
358 * | |
359 * | v
365ae791 360 * | <ad0s5>
984263bc
MD
361 * |
362 * v
365ae791 363 * <ad0s3>
984263bc
MD
364 * |
365 * v
365ae791 366 * <ad0s4> --> <ad0s4a>
984263bc
MD
367 *
368 *
369 */