Disklabel separation work - more.
[dragonfly.git] / sys / sys / ndisklabel.h
1 /*
2  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sys/sys/Attic/ndisklabel.h,v 1.2 2007/05/15 17:51:02 dillon Exp $
35  */
36
37 /*
38  * DragonFly disk label
39  */
40 #ifndef _SYS_NDISKLABEL_H_
41 #define _SYS_NDISKLABEL_H_
42
43 #ifndef _SYS_TYPES_H_
44 #include <sys/types.h>
45 #endif
46
47 /*
48  * A Dragonfly new-style disklabel always resides at byte offset 4096
49  * from the beginning of the block device, regardless of the sector size.
50  *
51  * All offsets stored in the disklabel are in bytes relative to the
52  * beginning of the block device, not relative to the disk label.
53  */
54 #define DFLY_LABEL_BYTE_OFFSET  4096
55
56 /*
57  * Misc constants.
58  *
59  * Disklabels are stored in native-endian format and are portable as long
60  * as the code checks for and properly converts the label.  Only big-endian
61  * and little-endian formats are supported.  All fields are structuralized.
62  */
63 #define DFLY_DISKMAGIC          ((u_int64_t)0xc4466c7942534430ULL)
64 #define DFLY_DISKMAGIC_OTHER    ((u_int64_t)0x30445342796c46c4ULL)
65 #define DFLY_MAXPARTITIONS      16
66
67 #ifndef LOCORE
68
69 /*
70  * The disk label and partitions a-p.  All offsets and sizes are in bytes
71  * but must be sector-aligned.  Other then the alignment requirement, the
72  * disklabel doesn't care what the physical sector size of the media is.
73  *
74  * All offsets are in bytes and are relative to the beginning of the
75  * block device in question (raw disk, slice, whatever), NOT the beginning
76  * of the label.
77  */
78 struct dfly_disklabel {
79         u_int64_t       d_magic;        /* magic number / endian check */
80         u_int64_t       d_serialno;     /* initial disklabel creation */
81         u_int64_t       d_timestamp;    /* timestamp of disklabel creation */
82         u_int64_t       d_crc;          /* cyclic redundancy check for label */
83                                         /* (after any endian translation) */
84         u_int64_t       d_size;         /* size of block device in bytes */
85         u_int32_t       d_npart;        /* actual number of partitions */
86         u_int32_t       d_labelsize;    /* max size of label in bytes */
87         u_int32_t       d_bootpart;     /* -1 if not defined */
88         u_int32_t       d_version;      /* disklabel version control */
89         char            d_label[64];    /* user defined label (mandatory) */
90         char            d_reserved[128];
91
92         /*
93          * Partitions do not have individual labels.  The filesystem or
94          * storage layer id is specified in ascii, 14 chars max, 0-extended.
95          * p_layer[15] must always be 0.
96          *
97          * All offsets and sizes are in bytes but still must be aligned to
98          * the native sector size of the media.
99          */
100         struct dfly_diskpart {
101                 u_int64_t       p_offset;       /* offset in bytes */
102                 u_int64_t       p_size;         /* size in bytes */
103                 u_int32_t       p_flags;        /* misc flags */
104                 char            p_layer[16];    /* FS or storage layer ID */
105         } d_partitions[DFLY_MAXPARTITIONS];
106         /* might be extended further */
107 };
108
109 #endif
110
111 #define DFLY_PARTF_VALID        0x0001          /* partition defined */
112 #define DFLY_PARTF_GOOD         0x0002          /* fs/storage formatted */
113 #define DFLY_PARTF_RECURSE      0x0004          /* recursive disklabel */
114
115 #define DFLY_DISKLABEL_SWAP     "swap"          /* strcmp w/ p_layer[] */
116 #define DFLY_DISKLABEL_UFS      "ufs"           /* strcmp w/ p_layer[] */
117
118 #ifndef LOCORE
119
120 #define DFLY_DIOCGDINFO   _IOR('d', 101, struct dfly_disklabel) /* get */
121 #define DFLY_DIOCSDINFO   _IOW('d', 102, struct dfly_disklabel) /* set */
122 #define DFLY_DIOCWDINFO   _IOW('d', 103, struct dfly_disklabel) /* set, update */
123 #define DFLY_DIOCGDVIRGIN _IOR('d', 105, struct dfly_disklabel) /* get new */
124
125 #endif
126
127 #endif /* !_SYS_NDISKLABEL_H_ */