fixed warnings when compiled with -Wwrite-strings
[reactos.git] / reactos / boot / freeldr / freeldr / disk / disk.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <freeldr.h>
21 #include <disk.h>
22 #include <arch.h>
23 #include <rtl.h>
24 #include <ui.h>
25 #include <debug.h>
26
27
28 #undef UNIMPLEMENTED
29 #define UNIMPLEMENTED BugCheck((DPRINT_WARNING, "Unimplemented\n"));
30
31 static BOOL bReportError = TRUE;
32
33 /////////////////////////////////////////////////////////////////////////////////////////////
34 // FUNCTIONS
35 /////////////////////////////////////////////////////////////////////////////////////////////
36
37 VOID DiskReportError (BOOL bError)
38 {
39 bReportError = bError;
40 }
41
42 VOID DiskError(PCSTR ErrorString, ULONG ErrorCode)
43 {
44 CHAR ErrorCodeString[200];
45
46 if (bReportError == FALSE)
47 return;
48
49 sprintf(ErrorCodeString, "%s\n\nError Code: 0x%x\nError: %s", ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode));
50
51 DbgPrint((DPRINT_DISK, "%s\n", ErrorCodeString));
52
53 UiMessageBox(ErrorCodeString);
54 }
55
56 PCSTR DiskGetErrorCodeString(ULONG ErrorCode)
57 {
58 switch (ErrorCode)
59 {
60 case 0x00: return "no error";
61 case 0x01: return "bad command passed to driver";
62 case 0x02: return "address mark not found or bad sector";
63 case 0x03: return "diskette write protect error";
64 case 0x04: return "sector not found";
65 case 0x05: return "fixed disk reset failed";
66 case 0x06: return "diskette changed or removed";
67 case 0x07: return "bad fixed disk parameter table";
68 case 0x08: return "DMA overrun";
69 case 0x09: return "DMA access across 64k boundary";
70 case 0x0A: return "bad fixed disk sector flag";
71 case 0x0B: return "bad fixed disk cylinder";
72 case 0x0C: return "unsupported track/invalid media";
73 case 0x0D: return "invalid number of sectors on fixed disk format";
74 case 0x0E: return "fixed disk controlled data address mark detected";
75 case 0x0F: return "fixed disk DMA arbitration level out of range";
76 case 0x10: return "ECC/CRC error on disk read";
77 case 0x11: return "recoverable fixed disk data error, data fixed by ECC";
78 case 0x20: return "controller error (NEC for floppies)";
79 case 0x40: return "seek failure";
80 case 0x80: return "time out, drive not ready";
81 case 0xAA: return "fixed disk drive not ready";
82 case 0xBB: return "fixed disk undefined error";
83 case 0xCC: return "fixed disk write fault on selected drive";
84 case 0xE0: return "fixed disk status error/Error reg = 0";
85 case 0xFF: return "sense operation failed";
86
87 default: return "unknown error code";
88 }
89 }
90
91 // This function is in arch/i386/i386disk.c
92 //BOOL DiskReadLogicalSectors(ULONG DriveNumber, U64 SectorNumber, ULONG SectorCount, PVOID Buffer)
93
94 BOOL DiskIsDriveRemovable(ULONG DriveNumber)
95 {
96 // Hard disks use drive numbers >= 0x80
97 // So if the drive number indicates a hard disk
98 // then return FALSE
99 if (DriveNumber >= 0x80)
100 {
101 return FALSE;
102 }
103
104 // Drive is a floppy diskette so return TRUE
105 return TRUE;
106 }
107
108 // This function is in arch/i386/i386disk.c
109 //VOID DiskStopFloppyMotor(VOID)
110
111 // This function is in arch/i386/i386disk.c
112 //ULONG DiskGetCacheableBlockCount(ULONG DriveNumber)