• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions
5  * are met:
6  * 1. Redistributions of source code must retain the above copyright
7  *    notice, this list of conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright
9  *    notice, this list of conditions and the following disclaimer in
10  *    the documentation and/or other materials provided with the
11  *    distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
14  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef MKFS_DEFINE_H
27 #define MKFS_DEFINE_H
28 #include <stdint.h>
29 
30 /*
31  * BSD_NPARTS_MIN,BSD_NDRIVEDATA,BSD_NSPARE
32  * Link: https://github.com/freebsd/freebsd-src/
33  * Path:  freebsd-src/sys/sys/disk/bsd.h
34  */
35 #define	BSD_NPARTS_MIN		8
36 
37 /* Drive-type specific data size (in number of 32-bit inegrals) */
38 #define	BSD_NDRIVEDATA		5
39 
40 /* Number of spare 32-bit integrals following drive-type data */
41 #define	BSD_NSPARE		5
42 
43 /*
44  * MAXPHYS
45  * Link: https://github.com/freebsd/freebsd-src/
46  * Path:  freebsd-src/sys/sys/param.h
47  */
48 #ifdef __ILP32__
49 #define MAXPHYS		(128 * 1024)
50 #else
51 #define MAXPHYS		(1024 * 1024)
52 #endif
53 
54 /*
55  * DIOCGMEDIASIZE,DIOCGFWSECTORS,DIOCGSECTORSIZE,DIOCGFWHEADS
56  * Link: https://github.com/freebsd/freebsd-src/
57  * Path:  freebsd-src/sys/sys/disk.h
58  */
59 #define	DIOCGMEDIASIZE	_IOR('d', 129, off_t)	/* Get media size in bytes */
60 	/*
61 	 * Get the size of the entire device in bytes.  This should be a
62 	 * multiple of the sector size.
63 	 */
64 
65 #define	DIOCGFWSECTORS	_IOR('d', 130, u_int)	/* Get firmware's sectorcount */
66 	/*
67 	 * Get the firmware's notion of number of sectors per track.  This
68 	 * value is mostly used for compatibility with various ill designed
69 	 * disk label formats.  Don't use it unless you have to.
70 	 */
71 
72 #define	DIOCGSECTORSIZE	_IOR('d', 128, u_int)
73 	/*
74 	 * Get the sector size of the device in bytes.  The sector size is the
75 	 * smallest unit of data which can be transferred from this device.
76 	 * Usually this is a power of 2 but it might not be (i.e. CDROM audio).
77 	 */
78 
79 #define	DIOCGFWHEADS	_IOR('d', 131, u_int)	/* Get firmware's headcount */
80 	/*
81 	 * Get the firmwares notion of number of heads per cylinder.  This
82 	 * value is mostly used for compatibility with various ill designed
83 	 * disk label formats.  Don't use it unless you have to.
84 	 */
85 
86 /*
87  * FD_GTYPE
88  * Link: https://github.com/freebsd/freebsd-src/
89  * Path:  freebsd-src/sys/sys/fdcio.h
90  */
91 #ifndef	_MACHINE_IOCTL_FD_H_
92 #define FD_GTYPE  _IOR('F', 62, struct fd_type)  /* get drive type */
93 #endif
94 
95 /*
96  * disklabel
97  * Link: https://github.com/freebsd/freebsd-src/
98  * Path:  freebsd-src/sys/sys/disk/bsd.h
99  */
100 struct disklabel {
101 	uint32_t d_magic;		/* the magic number */
102 	uint16_t d_type;		/* drive type */
103 	uint16_t d_subtype;		/* controller/d_type specific */
104 	char	 d_typename[16];	/* type name, e.g. "eagle" */
105 
106 	char	 d_packname[16];	/* pack identifier */
107 
108 	/* disk geometry: */
109 	uint32_t d_secsize;		/* # of bytes per sector */
110 	uint32_t d_nsectors;		/* # of data sectors per track */
111 	uint32_t d_ntracks;		/* # of tracks per cylinder */
112 	uint32_t d_ncylinders;		/* # of data cylinders per unit */
113 	uint32_t d_secpercyl;		/* # of data sectors per cylinder */
114 	uint32_t d_secperunit;		/* # of data sectors per unit */
115 
116 	/*
117 	 * Spares (bad sector replacements) below are not counted in
118 	 * d_nsectors or d_secpercyl.  Spare sectors are assumed to
119 	 * be physical sectors which occupy space at the end of each
120 	 * track and/or cylinder.
121 	 */
122 	uint16_t d_sparespertrack;	/* # of spare sectors per track */
123 	uint16_t d_sparespercyl;	/* # of spare sectors per cylinder */
124 	/*
125 	 * Alternate cylinders include maintenance, replacement, configuration
126 	 * description areas, etc.
127 	 */
128 	uint32_t d_acylinders;		/* # of alt. cylinders per unit */
129 
130 	/* hardware characteristics: */
131 	/*
132 	 * d_interleave, d_trackskew and d_cylskew describe perturbations
133 	 * in the media format used to compensate for a slow controller.
134 	 * Interleave is physical sector interleave, set up by the
135 	 * formatter or controller when formatting.  When interleaving is
136 	 * in use, logically adjacent sectors are not physically
137 	 * contiguous, but instead are separated by some number of
138 	 * sectors.  It is specified as the ratio of physical sectors
139 	 * traversed per logical sector.  Thus an interleave of 1:1
140 	 * implies contiguous layout, while 2:1 implies that logical
141 	 * sector 0 is separated by one sector from logical sector 1.
142 	 * d_trackskew is the offset of sector 0 on track N relative to
143 	 * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
144 	 * is the offset of sector 0 on cylinder N relative to sector 0
145 	 * on cylinder N-1.
146 	 */
147 	uint16_t d_rpm;			/* rotational speed */
148 	uint16_t d_interleave;		/* hardware sector interleave */
149 	uint16_t d_trackskew;		/* sector 0 skew, per track */
150 	uint16_t d_cylskew;		/* sector 0 skew, per cylinder */
151 	uint32_t d_headswitch;		/* head switch time, usec */
152 	uint32_t d_trkseek;		/* track-to-track seek, usec */
153 	uint32_t d_flags;		/* generic flags */
154 	uint32_t d_drivedata[BSD_NDRIVEDATA];	/* drive-type specific data */
155 	uint32_t d_spare[BSD_NSPARE];	/* reserved for future use */
156 	uint32_t d_magic2;		/* the magic number (again) */
157 	uint16_t d_checksum;		/* xor of data incl. partitions */
158 
159 	/* filesystem and partition information: */
160 	uint16_t d_npartitions;	/* number of partitions in following */
161 	uint32_t d_bbsize;		/* size of boot area at sn0, bytes */
162 	uint32_t d_sbsize;		/* max size of fs superblock, bytes */
163 	struct partition {		/* the partition table */
164 		uint32_t p_size;	/* number of sectors in partition */
165 		uint32_t p_offset;	/* starting sector */
166 		uint32_t p_fsize;	/* filesystem basic fragment size */
167 		uint8_t  p_fstype;	/* filesystem type, see below */
168 		uint8_t  p_frag;	/* filesystem fragments per block */
169 		uint16_t p_cpg;		/* filesystem cylinders per group */
170 	} d_partitions[BSD_NPARTS_MIN];	/* actually may be more */
171 };
172 
173 /*
174  * fd_type
175  * Link: https://github.com/freebsd/freebsd-src/
176  * Path: freebsd-src/sys/sys/fdcio.h
177  */
178 struct fd_type {
179 	int	sectrac;		/* sectors per track         */
180 	int	secsize;		/* size code for sectors     */
181 	int	datalen;		/* data len when secsize = 0 */
182 	int	gap;			/* gap len between sectors   */
183 	int	tracks;			/* total number of cylinders */
184 	int	size;			/* size of disk in sectors   */
185 	int	trans;			/* transfer speed code       */
186 	int	heads;			/* number of heads	     */
187 	int     f_gap;                  /* format gap len            */
188 	int     f_inter;                /* format interleave factor  */
189 	int	offset_side2;		/* offset of sectors on side2 */
190 	int	flags;			/* misc. features */
191 #define FL_MFM		0x0001		/* MFM recording */
192 #define FL_2STEP	0x0002		/* 2 steps between cylinders */
193 #define FL_PERPND	0x0004		/* perpendicular recording */
194 #define FL_AUTO		0x0008		/* autodetect format */
195 };
196 #endif //MKFS_DEFINE_H