4 * Disk I/O include file for the ext2fs/DOS library.
6 * Copyright (c) 1997 Mark Habersack
9 * This file may be redistributed under the terms of the GNU Library
10 * General Public License, version 2.
18 # error "ext2fs/DOS library requires LARGE model!"
27 * A helper structure used in LBA => CHS conversion
31 unsigned short cyl; /* Cylinder (or track) */
33 unsigned short sector;
34 unsigned short offset; /* Offset of byte within the sector */
38 * All partition data we need is here
42 char *dev; /* _Linux_ device name (like "/dev/hda1") */
43 unsigned char phys; /* Physical DOS drive number */
44 unsigned long start; /* LBA address of partition start */
45 unsigned long len; /* length of partition in sectors */
46 unsigned char pno; /* Partition number (read from *dev) */
48 /* This partition's drive geometry */
55 * PC partition table entry format
63 unsigned char start_head;
64 unsigned char start_sec;
65 unsigned char start_cyl;
67 unsigned char end_head;
68 unsigned char end_sec;
69 unsigned char end_cyl;
70 unsigned long first_sec_rel;
78 * INT 0x13 operation codes
80 #define DISK_READ 0x02
81 #define DISK_WRITE 0x03
82 #define DISK_GET_GEOMETRY 0x08
83 #define DISK_READY 0x10
86 * Errors to put in _dio_error
88 #define ERR_BADDEV 0x00000001L
89 #define ERR_HARDWARE 0x00000002L
90 #define ERR_NOTSUPP 0x00000003L
91 #define ERR_NOTEXT2FS 0x00000004L
92 #define ERR_EMPTYPART 0x00000005L
93 #define ERR_LINUXSWAP 0x00000006L
96 * Functions in diskio.c
100 * Variable contains last module's error
102 extern unsigned long _dio_error;
105 * This one contains last hardware error (if _dio_error == ERR_HARDWARE)
107 extern unsigned long _dio_hw_error;
110 * Macros to check for disk hardware errors
112 #define HW_OK() ((unsigned char)_dio_hw_error == 0x00)
113 #define HW_BAD_CMD() ((unsigned char)_dio_hw_error == 0x01)
114 #define HW_NO_ADDR_MARK() ((unsigned char)_dio_hw_error == 0x02)
115 #define HW_WRITE_PROT() ((unsigned char)_dio_hw_error == 0x03)
116 #define HW_NO_SECTOR() ((unsigned char)_dio_hw_error == 0x04)
117 #define HW_RESET_FAIL() ((unsigned char)_dio_hw_error == 0x05)
118 #define HW_DISK_CHANGED() ((unsigned char)_dio_hw_error == 0x06)
119 #define HW_DRIVE_FAIL() ((unsigned char)_dio_hw_error == 0x07)
120 #define HW_DMA_OVERRUN() ((unsigned char)_dio_hw_error == 0x08)
121 #define HW_DMA_BOUNDARY() ((unsigned char)_dio_hw_error == 0x09)
122 #define HW_BAD_SECTOR() ((unsigned char)_dio_hw_error == 0x0A)
123 #define HW_BAD_TRACK() ((unsigned char)_dio_hw_error == 0x0B)
124 #define HW_UNSUPP_TRACK() ((unsigned char)_dio_hw_error == 0x0C)
125 #define HW_BAD_CRC_ECC() ((unsigned char)_dio_hw_error == 0x10)
126 #define HW_CRC_ECC_CORR() ((unsigned char)_dio_hw_error == 0x11)
127 #define HW_CONTR_FAIL() ((unsigned char)_dio_hw_error == 0x20)
128 #define HW_SEEK_FAIL() ((unsigned char)_dio_hw_error == 0x40)
129 #define HW_ATTACH_FAIL() ((unsigned char)_dio_hw_error == 0x80)
130 #define HW_DRIVE_NREADY() ((unsigned char)_dio_hw_error == 0xAA)
131 #define HW_UNDEF_ERROR() ((unsigned char)_dio_hw_error == 0xBB)
132 #define HW_WRITE_FAULT() ((unsigned char)_dio_hw_error == 0xCC)
133 #define HW_STATUS_ERROR() ((unsigned char)_dio_hw_error == 0xE0)
134 #define HW_SENSE_FAIL() ((unsigned char)_dio_hw_error == 0xFF)
138 * Open the specified partition.
139 * String 'dev' must have a format:
145 * only one of the option in curly braces can be used and X is an optional
146 * partition number for the given device. If X is not specified, function
147 * scans the drive's partition table in search for the first Linux ext2fs
148 * partition (signature 0x83). Along the way it dives into every extended
149 * partition encountered.
150 * Scan ends if either (a) there are no more used partition entries, or
151 * (b) there is no Xth partition.
153 * Routine returns 0 on success and !=0 otherwise.
155 int open_partition(char *dev);
157 #endif /* __diskio_h */