Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

part.c

Go to the documentation of this file.
00001 /*! \file part.c \brief Disk Partition Interface. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'part.c'
00005 // Title        : Disk Partition Interface
00006 // Author       : Pascal Stang (c) 2004
00007 // Date         : 8/13/2004
00008 // Revised      : 8/13/2004
00009 // Version      : 0.3
00010 // Target MCU   : any?
00011 // Editor Tabs  : 4
00012 //
00013 // NOTE: This code is currently below version 1.0, and therefore is considered
00014 // to be lacking in some functionality or documentation, or may not be fully
00015 // tested.  Nonetheless, you can expect most functions to work.
00016 //
00017 // This code is distributed under the GNU Public License
00018 //      which can be found at http://www.gnu.org/licenses/gpl.txt
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 // globals
00036 unsigned char PartBuffer[0x200];
00037 
00038 // filesystem constants/metrics
00039 PartInfo_t PartInfo;
00040 
00041 /*************************************************************************/
00042 /*************************************************************************/
00043 
00044 int partInit(DiskInfo_t* disk)
00045 {
00046     //unsigned char* buffer = (unsigned char*) SECTOR_BUFFER_ADDR;
00047     unsigned char* buffer = PartBuffer;
00048 
00049     // local drivers
00050     PartInfo.disk = *disk;
00051 
00052     // read partition table
00053     // TODO.... error checking
00054     ataReadSectors(&PartInfo.disk, 0, 1, buffer);
00055     // map first partition record   
00056     // save partition information to global PartRecord
00057     //PartRecord = ((struct partsector *) SectorBuffer)->psPartition[0]);
00058     
00059     // setup global disk constants
00060     PartInfo.start =            ((struct partsector *) buffer)->psPartition[0].prStartLBA;
00061     PartInfo.sizeinsectors =    ((struct partsector *) buffer)->psPartition[0].prSize;
00062 
00063     // do debug
00064 #ifdef DEBUG_PART
00065     partPrintEntry( &((struct partsector *) buffer)->psPartition[0] );
00066 #endif
00067 
00068     // setup access methods
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 }

Generated on Mon Nov 6 23:36:59 2006 for Procyon ARMlib by  doxygen 1.4.2