diff options
Diffstat (limited to 'e2fsprogs/ext2fs/dosio.h')
-rw-r--r-- | e2fsprogs/ext2fs/dosio.h | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/e2fsprogs/ext2fs/dosio.h b/e2fsprogs/ext2fs/dosio.h new file mode 100644 index 000000000..a0d652d5b --- /dev/null +++ b/e2fsprogs/ext2fs/dosio.h | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | * v1.0 | ||
3 | * | ||
4 | * Disk I/O include file for the ext2fs/DOS library. | ||
5 | * | ||
6 | * Copyright (c) 1997 Mark Habersack | ||
7 | * This file may be distributed under the terms of the GNU Public License. | ||
8 | * | ||
9 | */ | ||
10 | #ifndef __diskio_h | ||
11 | #define __diskio_h | ||
12 | #ifdef __TURBOC__ | ||
13 | #ifndef __LARGE__ | ||
14 | # error "ext2fs/DOS library requires LARGE model!" | ||
15 | #endif | ||
16 | #endif | ||
17 | |||
18 | #ifdef __TURBOC__ | ||
19 | #include "msdos.h" | ||
20 | #endif | ||
21 | |||
22 | /* | ||
23 | * A helper structure used in LBA => CHS conversion | ||
24 | */ | ||
25 | typedef struct | ||
26 | { | ||
27 | unsigned short cyl; /* Cylinder (or track) */ | ||
28 | unsigned short head; | ||
29 | unsigned short sector; | ||
30 | unsigned short offset; /* Offset of byte within the sector */ | ||
31 | } CHS; | ||
32 | |||
33 | /* | ||
34 | * All partition data we need is here | ||
35 | */ | ||
36 | typedef struct | ||
37 | { | ||
38 | char *dev; /* _Linux_ device name (like "/dev/hda1") */ | ||
39 | unsigned char phys; /* Physical DOS drive number */ | ||
40 | unsigned long start; /* LBA address of partition start */ | ||
41 | unsigned long len; /* length of partition in sectors */ | ||
42 | unsigned char pno; /* Partition number (read from *dev) */ | ||
43 | |||
44 | /* This partition's drive geometry */ | ||
45 | unsigned short cyls; | ||
46 | unsigned short heads; | ||
47 | unsigned short sects; | ||
48 | } PARTITION; | ||
49 | |||
50 | /* | ||
51 | * PC partition table entry format | ||
52 | */ | ||
53 | #ifdef __DJGPP__ | ||
54 | #pragma pack(1) | ||
55 | #endif | ||
56 | typedef struct | ||
57 | { | ||
58 | unsigned char active; | ||
59 | unsigned char start_head; | ||
60 | unsigned char start_sec; | ||
61 | unsigned char start_cyl; | ||
62 | unsigned char type; | ||
63 | unsigned char end_head; | ||
64 | unsigned char end_sec; | ||
65 | unsigned char end_cyl; | ||
66 | unsigned long first_sec_rel; | ||
67 | unsigned long size; | ||
68 | } PTABLE_ENTRY; | ||
69 | #ifdef __DJGPP__ | ||
70 | #pragma pack() | ||
71 | #endif | ||
72 | |||
73 | /* | ||
74 | * INT 0x13 operation codes | ||
75 | */ | ||
76 | #define DISK_READ 0x02 | ||
77 | #define DISK_WRITE 0x03 | ||
78 | #define DISK_GET_GEOMETRY 0x08 | ||
79 | #define DISK_READY 0x10 | ||
80 | |||
81 | /* | ||
82 | * Errors to put in _dio_error | ||
83 | */ | ||
84 | #define ERR_BADDEV 0x00000001L | ||
85 | #define ERR_HARDWARE 0x00000002L | ||
86 | #define ERR_NOTSUPP 0x00000003L | ||
87 | #define ERR_NOTEXT2FS 0x00000004L | ||
88 | #define ERR_EMPTYPART 0x00000005L | ||
89 | #define ERR_LINUXSWAP 0x00000006L | ||
90 | |||
91 | /* | ||
92 | * Functions in diskio.c | ||
93 | */ | ||
94 | |||
95 | /* | ||
96 | * Variable contains last module's error | ||
97 | */ | ||
98 | extern unsigned long _dio_error; | ||
99 | |||
100 | /* | ||
101 | * This one contains last hardware error (if _dio_error == ERR_HARDWARE) | ||
102 | */ | ||
103 | extern unsigned long _dio_hw_error; | ||
104 | |||
105 | /* | ||
106 | * Macros to check for disk hardware errors | ||
107 | */ | ||
108 | #define HW_OK() ((unsigned char)_dio_hw_error == 0x00) | ||
109 | #define HW_BAD_CMD() ((unsigned char)_dio_hw_error == 0x01) | ||
110 | #define HW_NO_ADDR_MARK() ((unsigned char)_dio_hw_error == 0x02) | ||
111 | #define HW_WRITE_PROT() ((unsigned char)_dio_hw_error == 0x03) | ||
112 | #define HW_NO_SECTOR() ((unsigned char)_dio_hw_error == 0x04) | ||
113 | #define HW_RESET_FAIL() ((unsigned char)_dio_hw_error == 0x05) | ||
114 | #define HW_DISK_CHANGED() ((unsigned char)_dio_hw_error == 0x06) | ||
115 | #define HW_DRIVE_FAIL() ((unsigned char)_dio_hw_error == 0x07) | ||
116 | #define HW_DMA_OVERRUN() ((unsigned char)_dio_hw_error == 0x08) | ||
117 | #define HW_DMA_BOUNDARY() ((unsigned char)_dio_hw_error == 0x09) | ||
118 | #define HW_BAD_SECTOR() ((unsigned char)_dio_hw_error == 0x0A) | ||
119 | #define HW_BAD_TRACK() ((unsigned char)_dio_hw_error == 0x0B) | ||
120 | #define HW_UNSUPP_TRACK() ((unsigned char)_dio_hw_error == 0x0C) | ||
121 | #define HW_BAD_CRC_ECC() ((unsigned char)_dio_hw_error == 0x10) | ||
122 | #define HW_CRC_ECC_CORR() ((unsigned char)_dio_hw_error == 0x11) | ||
123 | #define HW_CONTR_FAIL() ((unsigned char)_dio_hw_error == 0x20) | ||
124 | #define HW_SEEK_FAIL() ((unsigned char)_dio_hw_error == 0x40) | ||
125 | #define HW_ATTACH_FAIL() ((unsigned char)_dio_hw_error == 0x80) | ||
126 | #define HW_DRIVE_NREADY() ((unsigned char)_dio_hw_error == 0xAA) | ||
127 | #define HW_UNDEF_ERROR() ((unsigned char)_dio_hw_error == 0xBB) | ||
128 | #define HW_WRITE_FAULT() ((unsigned char)_dio_hw_error == 0xCC) | ||
129 | #define HW_STATUS_ERROR() ((unsigned char)_dio_hw_error == 0xE0) | ||
130 | #define HW_SENSE_FAIL() ((unsigned char)_dio_hw_error == 0xFF) | ||
131 | |||
132 | |||
133 | /* | ||
134 | * Open the specified partition. | ||
135 | * String 'dev' must have a format: | ||
136 | * | ||
137 | * /dev/{sd|hd|fd}[X] | ||
138 | * | ||
139 | * where, | ||
140 | * | ||
141 | * only one of the option in curly braces can be used and X is an optional | ||
142 | * partition number for the given device. If X is not specified, function | ||
143 | * scans the drive's partition table in search for the first Linux ext2fs | ||
144 | * partition (signature 0x83). Along the way it dives into every extended | ||
145 | * partition encountered. | ||
146 | * Scan ends if either (a) there are no more used partition entries, or | ||
147 | * (b) there is no Xth partition. | ||
148 | * | ||
149 | * Routine returns 0 on success and !=0 otherwise. | ||
150 | */ | ||
151 | int open_partition(char *dev); | ||
152 | |||
153 | #endif /* __diskio_h */ | ||