1 /* 2 * v1.0 3 * 4 * Disk I/O include file for the ext2fs/DOS library. 5 * 6 * Copyright (c) 1997 Mark Habersack 7 * 8 * %Begin-Header% 9 * This file may be redistributed under the terms of the GNU Library 10 * General Public License, version 2. 11 * %End-Header% 12 */ 13 14 #ifndef __diskio_h 15 #define __diskio_h 16 #ifdef __TURBOC__ 17 #ifndef __LARGE__ 18 # error "ext2fs/DOS library requires LARGE model!" 19 #endif 20 #endif 21 22 #ifdef __TURBOC__ 23 #include "msdos.h" 24 #endif 25 26 /* 27 * A helper structure used in LBA => CHS conversion 28 */ 29 typedef struct 30 { 31 unsigned short cyl; /* Cylinder (or track) */ 32 unsigned short head; 33 unsigned short sector; 34 unsigned short offset; /* Offset of byte within the sector */ 35 } CHS; 36 37 /* 38 * All partition data we need is here 39 */ 40 typedef struct 41 { 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) */ 47 48 /* This partition's drive geometry */ 49 unsigned short cyls; 50 unsigned short heads; 51 unsigned short sects; 52 } PARTITION; 53 54 /* 55 * PC partition table entry format 56 */ 57 #ifdef __DJGPP__ 58 #pragma pack(1) 59 #endif 60 typedef struct 61 { 62 unsigned char active; 63 unsigned char start_head; 64 unsigned char start_sec; 65 unsigned char start_cyl; 66 unsigned char type; 67 unsigned char end_head; 68 unsigned char end_sec; 69 unsigned char end_cyl; 70 unsigned long first_sec_rel; 71 unsigned long size; 72 } PTABLE_ENTRY; 73 #ifdef __DJGPP__ 74 #pragma pack() 75 #endif 76 77 /* 78 * INT 0x13 operation codes 79 */ 80 #define DISK_READ 0x02 81 #define DISK_WRITE 0x03 82 #define DISK_GET_GEOMETRY 0x08 83 #define DISK_READY 0x10 84 85 /* 86 * Errors to put in _dio_error 87 */ 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 94 95 /* 96 * Functions in diskio.c 97 */ 98 99 /* 100 * Variable contains last module's error 101 */ 102 extern unsigned long _dio_error; 103 104 /* 105 * This one contains last hardware error (if _dio_error == ERR_HARDWARE) 106 */ 107 extern unsigned long _dio_hw_error; 108 109 /* 110 * Macros to check for disk hardware errors 111 */ 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) 135 136 137 /* 138 * Open the specified partition. 139 * String 'dev' must have a format: 140 * 141 * /dev/{sd|hd|fd}[X] 142 * 143 * where, 144 * 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. 152 * 153 * Routine returns 0 on success and !=0 otherwise. 154 */ 155 int open_partition(char *dev); 156 157 #endif /* __diskio_h */ 158