xref: /aosp_15_r20/external/mtools/partition.h (revision d5c9a868b113e0ec0db2f27bc2ce8a253e77c4b0)
1 /*  Copyright 1997,1998,2001-2003,2006,2009 Alain Knaff.
2  *  This file is part of mtools.
3  *
4  *  Mtools is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  Mtools is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 typedef struct hsc {
19 	unsigned char byte0;
20 	unsigned char head;		/* starting head */
21 	unsigned char sector;		/* starting sector */
22 	unsigned char cyl;		/* starting cylinder */
23 } hsc;
24 
25 #define head(x) ((uint8_t)((x).head))
26 #define sector(x) ((uint8_t)((x).sector & 0x3f))
27 #define cyl(x) ((uint16_t)((x).cyl | (((x).sector & 0xc0)<<2)))
28 
29 #define BEGIN(p) _DWORD((p)->start_sect)
30 #define END(p) (_DWORD((p)->start_sect)+(_DWORD((p)->nr_sects)))
31 #define PART_SIZE(p) (_DWORD((p)->nr_sects))
32 
33 
34 struct partition {
35 	hsc start;
36 	hsc end;
37 	unsigned char start_sect[4];	/* starting sector counting from 0 */
38 	unsigned char nr_sects[4];     	/* nr of sectors in partition */
39 };
40 
41 #define boot_ind start.byte0
42 #define sys_ind end.byte0
43 
44 int consistencyCheck(struct partition *partTable, int doprint, int verbose,
45 		     int *has_activated, uint32_t tot_sectors,
46 		     struct device *used_dev, unsigned int target_partition);
47 
48 void setBeginEnd(struct partition *partTable,
49 		 uint32_t begin, uint32_t end,
50 		 uint16_t iheads, uint16_t isectors,
51 		 int activate, uint8_t type, unsigned int fat_bits);
52 
53 Stream_t *OpenPartition(Stream_t *Next, struct device *dev,
54 			char *errmsg, mt_off_t *maxSize);
55 
56 unsigned int findOverlap(struct partition *partTable, unsigned int until,
57 			 uint32_t start, uint32_t end);
58