00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <string.h>
00024
00025 #include "device.h"
00026 #include "ata.h"
00027 #include "rprintf.h"
00028 #include "debug.h"
00029 #include "ataconf.h"
00030
00031 #include "part.h"
00032
00033 #define DEBUG_PART
00034
00035
00036 unsigned char PartBuffer[0x200];
00037
00038
00039 PartInfo_t PartInfo;
00040
00041
00042
00043
00044 int partInit(DiskInfo_t* disk)
00045 {
00046
00047 unsigned char* buffer = PartBuffer;
00048
00049
00050 PartInfo.disk = *disk;
00051
00052
00053
00054 ataReadSectors(&PartInfo.disk, 0, 1, buffer);
00055
00056
00057
00058
00059
00060 PartInfo.start = ((struct partsector *) buffer)->psPartition[0].prStartLBA;
00061 PartInfo.sizeinsectors = ((struct partsector *) buffer)->psPartition[0].prSize;
00062
00063
00064 #ifdef DEBUG_PART
00065 partPrintEntry( &((struct partsector *) buffer)->psPartition[0] );
00066 #endif
00067
00068
00069 PartInfo.dev.bytespersector = 512;
00070 PartInfo.dev.numsectors = PartInfo.sizeinsectors;
00071 PartInfo.dev.ReadSector = partReadSector;
00072 PartInfo.dev.WriteSector = partWriteSector;
00073
00074 return 0;
00075 }
00076
00077 void partPrintEntry(struct partrecord *partition)
00078 {
00079 rprintfProgStrM("----- Partition -----\r\n");
00080 rprintfProgStrM("Active : "); rprintfu08(partition->prIsActive); rprintfCRLF();
00081 rprintfProgStrM("StartHead : "); rprintfu08(partition->prStartHead); rprintfCRLF();
00082 rprintfProgStrM("StartCylSect : "); rprintfu16(partition->prStartCylSect); rprintfCRLF();
00083 rprintfProgStrM("Partition Type: ");
00084 switch(partition->prPartType)
00085 {
00086 case PART_TYPE_DOSFAT16:
00087 rprintfProgStrM("Found: DOSFAT 16\r\n");
00088 break;
00089 case PART_TYPE_FAT16:
00090 rprintfProgStrM("Found: FAT16\r\n");
00091 break;
00092 case PART_TYPE_FAT16LBA:
00093 rprintfProgStrM("Found: FAT16 LBA\r\n");
00094 break;
00095 case PART_TYPE_FAT32LBA:
00096 rprintfProgStrM("Found: FAT32 LBA\r\n");
00097 break;
00098 case PART_TYPE_FAT32:
00099 rprintfProgStrM("Found: FAT32\r\n");
00100 break;
00101 case PART_TYPE_UNKNOWN:
00102 rprintfProgStrM("No Partition\r\n");
00103 break;
00104 default:
00105 rprintf("Type: 0x%x\r\n", partition->prPartType);
00106 break;
00107 }
00108 rprintfProgStrM("EndHead : "); rprintfu08(partition->prEndHead); rprintfCRLF();
00109 rprintfProgStrM("EndCylSect : "); rprintfu16(partition->prEndCylSect); rprintfCRLF();
00110 rprintfProgStrM("StartLBA : "); rprintfu32(partition->prStartLBA); rprintfCRLF();
00111 rprintfProgStrM("Size : "); rprintfu32(partition->prSize); rprintfCRLF();
00112 }
00113
00114 void partPrintTable(struct partsector *buffer)
00115 {
00116 ataReadSectors(&PartInfo.disk, 0, 1, PartBuffer);
00117 buffer = (struct partsector*)PartBuffer;
00118
00119 if( (buffer->psBootSectSig0 == PART_BOOTSIG0) &&
00120 (buffer->psBootSectSig1 == PART_BOOTSIG1) )
00121 {
00122 rprintfProgStrM("Partition Sector Valid.\r\n");
00123 }
00124
00125 partPrintEntry( &buffer->psPartition[0] );
00126 partPrintEntry( &buffer->psPartition[1] );
00127 partPrintEntry( &buffer->psPartition[2] );
00128 partPrintEntry( &buffer->psPartition[3] );
00129 }
00130
00131
00132 int partReadSector(unsigned long sector, int numsectors, u08* buffer)
00133 {
00134 if(sector < PartInfo.sizeinsectors)
00135 {
00136 ataReadSectors(&PartInfo.disk, sector+PartInfo.start, numsectors, buffer);
00137 return 0;
00138 }
00139 else
00140 return 1;
00141 }
00142
00143 int partWriteSector(unsigned long sector, int numsectors, u08* buffer)
00144 {
00145 if(sector < PartInfo.sizeinsectors)
00146 {
00147 ataWriteSectors(&PartInfo.disk, sector+PartInfo.start, numsectors, buffer);
00148 return 0;
00149 }
00150 else
00151 return 1;
00152 }