Imported Upstream version 4.0.43
[platform/upstream/mtools.git] / partition.h
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 #include "msdos.h"
19
20 typedef struct hsc {
21         unsigned char byte0;
22         unsigned char head;             /* starting head */
23         unsigned char sector;           /* starting sector */
24         unsigned char cyl;              /* starting cylinder */
25 } hsc;
26
27 #define head(x) ((uint8_t)((x).head))
28 #define sector(x) ((uint8_t)((x).sector & 0x3f))
29 #define cyl(x) ((uint16_t)((x).cyl | (((x).sector & 0xc0)<<2)))
30
31 #define BEGIN(p) DWORD((p)->start_sect)
32 #define END(p) (DWORD((p)->start_sect)+(DWORD((p)->nr_sects)))
33 #define PART_SIZE(p) (DWORD((p)->nr_sects))
34
35
36 struct partition {
37         hsc start;
38         hsc end;
39         unsigned char start_sect[4];    /* starting sector counting from 0 */
40         unsigned char nr_sects[4];      /* nr of sectors in partition */
41 };
42
43 #define boot_ind start.byte0
44 #define sys_ind end.byte0
45
46 int consistencyCheck(struct partition *partTable, int doprint, int verbose,
47                      int *has_activated, uint32_t tot_sectors,
48                      struct device *used_dev, unsigned int target_partition);
49
50 void setBeginEnd(struct partition *partTable,
51                  uint32_t begin, uint32_t end,
52                  uint16_t iheads, uint16_t isectors,
53                  int activate, uint8_t type, unsigned int fat_bits);
54
55 Stream_t *OpenPartition(Stream_t *Next, struct device *dev,
56                         char *errmsg, mt_off_t *maxSize);
57
58 unsigned int findOverlap(struct partition *partTable, unsigned int until,
59                          uint32_t start, uint32_t end);