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