コード例 #1
0
ファイル: fat32.c プロジェクト: kristenmills/Efcs
/*---------------------------------------------------------------------------
  This only reads from the primary boot record, it assumes it has been
  loaded by boot.s
   uint32_t initHDD(void)
  Where:

  Returns: 0 for success, non-zero for failure
---------------------------------------------------------------------------*/
uint32_t initHDD(void)
{
    //-----------------------------------------------------------------------
    // These are use to read the data file on the PC, your file location
    // can vary.  This is not needed for the RPI implementation
    //-----------------------------------------------------------------------
    const char *fileName = "images/file1.img";	// Might need to change this!
    FILE *myFile;
    uint32_t size;

    //-------------------------------------------------------------------------
    // Read in the file data on the PC only, already predefined on the RPI
    // comment out on the pie
    //-------------------------------------------------------------------------
    myFile = fopen(fileName, "rb");
    if (!myFile)
    {
        printf( "Can't open file %s\n", fileName);
        return(97);
    }
    size = fread(HDDimage, 1, sizeof(HDDimage), myFile);   //myFile.Read(HDDimage, sizeof(HDDimage));
    fclose(myFile);

    if (size == 0)
    {
        printf( "Can't read file %s\n", fileName);
        return(98);
    }
    // Get bootRecord and volume id and ffilled IO_INIT
    bootRecord* b = (bootRecord*)readLBA(0);
    FAT_VolID* v = (FAT_VolID*)readLBA(b->par[0].LBA_Begin);
    MediaDescriptorGlobal.fatBeginLBA = b->par[0].LBA_Begin + v->reservedSectors;
    MediaDescriptorGlobal.dirBeginLBA = MediaDescriptorGlobal.fatBeginLBA + (v->numFats*v->sectorsPerFat);
    MediaDescriptorGlobal.sectorsPerCluster = v->sectorsPerCluster;
    MediaDescriptorGlobal.bytesPerSector = v->bytesPerSector;

    //Print all the information
    printf("Boot record size=%d, ", sizeof(bootRecord));
    printf("Partition description size %d\n", sizeof(partitionDescription));
    printf("FAT VOL ID size=%d, ", sizeof(FAT_VolID));
    printf("ROOT DIR size = %d\n", sizeof(FAT_DirSector));
    printf("num Sectors = %#x ", b->par[0].numSectors);
    printf("size = %d (MB)\n", b->par[0].numSectors*v->bytesPerSector/1048576);
    printf("LBA starts at %#x\n", b->par[0].LBA_Begin );
    printf("bytes per sector=%d, ", v->bytesPerSector);
    printf("sectors per cluster=%d, ", v->sectorsPerCluster);
    printf("reserved sectors %#x\n", v->reservedSectors);
    printf("number of FATS %d, ", v->numFats);
    printf("sectors per fat %#x, ", v->sectorsPerFat);
    printf("root cluster %#x, ", v->rootCluster);
    printf("signature %#x\n", v->signature);
    printf("FAT Begin LBA = %#x ", MediaDescriptorGlobal.fatBeginLBA);
    printf("Cluster begin LBA = %#x\n", MediaDescriptorGlobal.dirBeginLBA);
    return(0);
} // End initHDD
コード例 #2
0
ファイル: fat32.c プロジェクト: kristenmills/Efcs
/*---------------------------------------------------------------------------
  This only reads from the primary boot record, it assumes it has been
  loaded by boot.s
   uint32_t initHDD(void)
  Where:

  Returns: 0 for success, non-zero for failure
---------------------------------------------------------------------------*/
uint32_t initHDD(void)
{
    // Get bootRecord and volume id and filled IO_INIT
    bootRecord* b = (bootRecord*)readLBA(0);
    FAT_VolID* v = (FAT_VolID*)readLBA(b->par[0].LBA_Begin);
    MediaDescriptorGlobal.fatBeginLBA = b->par[0].LBA_Begin + v->reservedSectors;
    MediaDescriptorGlobal.dirBeginLBA = MediaDescriptorGlobal.fatBeginLBA + (v->numFats*v->sectorsPerFat);
    MediaDescriptorGlobal.sectorsPerCluster = v->sectorsPerCluster;
    MediaDescriptorGlobal.bytesPerSector = v->bytesPerSector;
    return(0);
} // End initHDD
コード例 #3
0
ファイル: fat32.c プロジェクト: kristenmills/Efcs
/*---------------------------------------------------------------------------
  This only reads from the primary boot record, it assumes it has been
  loaded by boot.s
   uint32_t initHDD(void)
  Where:

  Returns: 0 for success, non-zero for failure
---------------------------------------------------------------------------*/
uint32_t initHDD(void)
{
    // Get bootRecord and volume id and filled IO_INIT
    bootRecord* b = (bootRecord*)readLBA(0);
    FAT_VolID* v = (FAT_VolID*)readLBA(b->par[0].LBA_Begin);
    MediaDescriptorGlobal.fatBeginLBA = b->par[0].LBA_Begin + v->reservedSectors;
    MediaDescriptorGlobal.dirBeginLBA = MediaDescriptorGlobal.fatBeginLBA + (v->numFats*v->sectorsPerFat);
    MediaDescriptorGlobal.sectorsPerCluster = v->sectorsPerCluster;
    MediaDescriptorGlobal.bytesPerSector = v->bytesPerSector;

    //Print all the information

    putStr("Boot record size=");
    hexstring(sizeof(bootRecord));
    putStr(", Partition description size ");
    hexstring(sizeof(partitionDescription));
    putStr("\nFAT VOL ID size=");
    hexstring(sizeof(FAT_VolID));
    putStr(", ROOT DIR size = ");
    hexstring(sizeof(FAT_DirSector));
    putStr("\nnum Sectors = ");
    hexstring(b->par[0].numSectors);
    putStr(", size = ");
    hexstring(b->par[0].numSectors*v->bytesPerSector/1048576);
    putStr(" (MB)\nLBA starts at ");
    hexstring(b->par[0].LBA_Begin);
    putStr("\nbytes per sector=");
    hexstring(v->bytesPerSector);
    putStr(", sectors per cluster=");
    hexstring(v->sectorsPerCluster);
    putStr(", reserved sectors ");
    hexstring(v->reservedSectors);
    putStr("\nnumber of FATS ");
    hexstring(v->numFats);
    putStr(", sectors per fat ");
    hexstring(v->sectorsPerFat);
    putStr(", root cluster ");
    hexstring(v->rootCluster);
    putStr(", signature ");
    hexstring(v->signature);
    putStr("\nFAT Begin LBA = ");
    hexstring(MediaDescriptorGlobal.fatBeginLBA);
    putStr(", Cluster begin LBA = ");
    hexstring(MediaDescriptorGlobal.dirBeginLBA);
    uart_putc((uint32_t)'\n');
  return(0);
} // End initHDD
コード例 #4
0
ファイル: fat32.c プロジェクト: kristenmills/Efcs
/*---------------------------------------------------------------------------
  This reads a cluster of a file given the file cluster id and the cluster
  begin area.  Buffer must be at least 512 bytes * number of sectors per cluster
   uint32_t readCluster(uint32_t cluster, uint8_t *buffer)
  Where:
   uint32_t cluster - cluster to read
   uint8_t *buffer  - pointer to the buffer
  Returns: bytes read
---------------------------------------------------------------------------*/
uint32_t readCluster(uint32_t cluster, uint8_t *buffer)
{
    uint32_t spc = MediaDescriptorGlobal.sectorsPerCluster;
    uint32_t bps = MediaDescriptorGlobal.bytesPerSector;
    uint32_t i;
    uint8_t* b = (uint8_t*)readLBA(MediaDescriptorGlobal.dirBeginLBA + cluster -2);
    //Mem move
    for(i = 0; i < spc*bps; i++){
        buffer[i] = b[i];
    }
    return spc*bps;
}// End readCluster
コード例 #5
0
ファイル: fat32.c プロジェクト: kristenmills/Efcs
/*---------------------------------------------------------------------------
  This function searches the directory structure on sector at a time.
  It only requires 1 buffer
   FAT_DirEntry *searchDir(const char *fileName)
  Where:
   char *fileName - Pointer to the case specific file name to fine
 Returns: 0 if no entry is found or a pointer to a FAT_DirEntry for success
---------------------------------------------------------------------------*/
FAT_DirEntry *searchDir(const char *fileName)
{
    FAT_DirSector *sector = readLBA(MediaDescriptorGlobal.dirBeginLBA);
    uint32_t i;
    uint32_t j;
    for(i = 0; i < 8; i++){
        uint32_t equal = 1;
        // String compare for non nul terminated strings
        for(j = 0; j < 11; j++){
            if(sector->dirEntry[i].Name[j] != fileName[j]){
                equal = 0;
                break;
            }
        }
        if(equal){
            return &sector->dirEntry[i];
        }
    }
    return 0;
} // End searchDir
コード例 #6
0
ファイル: sectread.c プロジェクト: anilgit90/pdos
int main(int argc, char **argv)
{
    char buf[512];
    int drive;
    long sect;
    FILE *fq;
    int rc;
    
    if (argc <= 3)
    {
        printf("usage: sectread <drive> <sect #> <outfile>\n");
        printf("example: sectread 81 63 boot.com\n");
        printf("A drive = 0, D drive = 81, etc\n");
        return (EXIT_FAILURE);
    }
    
    drive = strtol(*(argv + 1), NULL, 16);
    sect = atol(*(argv + 2));
    fq = fopen(*(argv + 3), "wb");
    if (fq == NULL)
    {
        printf("failed to open %s for writing\n", *(argv + 3));
        return (EXIT_FAILURE);
    }
    
    rc = readLBA(buf, 1, drive, sect);

    if (rc != 0)
    {
        printf("read failed with rc %d\n", rc);
        return (EXIT_FAILURE);
    }
    fwrite(buf, 1, sizeof buf, fq);
    printf("sector dumped successfully\n");
    return (0);
}
コード例 #7
0
ファイル: fat32.c プロジェクト: kristenmills/Efcs
/*---------------------------------------------------------------------------
  This follows a 32 FAT chain, no checking is done.  The caller must
  check for less than FAT32_LAST_CLUSTER or FAT32_INVALID_CLUSTER
   uint32_t nextFatEntry(uint32_t cluster)
  Where:
   uint32_t cluster - Starting FAT cluster
  Returns: the next FAT cluster OR some value between
         FAT32_LAST_CLUSTER and FAT32_INVALID_CLUSTER for end
         Success is <  FAT32_LAST_CLUSTER
---------------------------------------------------------------------------*/
uint32_t nextFatEntry(uint32_t cluster)
{
    return ((uint32_t*)readLBA(MediaDescriptorGlobal.fatBeginLBA))[cluster];
} // nextFatEntry