OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [services/] [dos.c] - Diff between revs 175 and 406

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 175 Rev 406
Line 17... Line 17...
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
*/
 
 
 
 
//#include "common.h"
//#include "common.h"
 
 
#include <stddef.h>
#include <stddef.h>
#include <string.h>
#include <string.h>
#include "dos.h"
#include "dos.h"
#include "ata.h"
#include "ata.h"
 
 
 
 
/*
/*
  D O S _ O P E N
  D O S _ O P E N
*/
*/
int dos_open(struct dosparam *params)
int dos_open(struct dosparam *params)
{
{
Line 41... Line 39...
  struct request *request = &params->request;
  struct request *request = &params->request;
 
 
  if( (error = ata_open(inode, filp)) )
  if( (error = ata_open(inode, filp)) )
    return error;
    return error;
 
 
 
 
  /* device opened, read MBR                                          */
  /* device opened, read MBR                                          */
  request->cmd = READ;
  request->cmd = READ;
  request->sector = 0;
  request->sector = 0;
  request->nr_sectors = 1;
  request->nr_sectors = 1;
  request->buffer = buf;
  request->buffer = buf;
Line 59... Line 56...
  partition = 0;    /* first partition                                */
  partition = 0;    /* first partition                                */
  partition *= 16;  /* 16 bytes per partition table                   */
  partition *= 16;  /* 16 bytes per partition table                   */
  partition += 446; /* skip bootloader, go to partition table         */
  partition += 446; /* skip bootloader, go to partition table         */
  start_sector = buf[partition +11] << 24 |
  start_sector = buf[partition +11] << 24 |
                 buf[partition +10] << 16 |
                 buf[partition +10] << 16 |
                 buf[partition +9] << 8   |
            buf[partition + 9] << 8 | buf[partition + 8];
                 buf[partition +8];
 
 
 
  /* device opened, read boot-sector                                  */
  /* device opened, read boot-sector                                  */
  request->cmd = READ;
  request->cmd = READ;
  request->sector = start_sector;
  request->sector = start_sector;
  request->nr_sectors = 1;
  request->nr_sectors = 1;
Line 78... Line 74...
  params->fats = buf[16];
  params->fats = buf[16];
  params->sectors_per_fat = (buf[23]<<8) | buf[22];
  params->sectors_per_fat = (buf[23]<<8) | buf[22];
  params->root_entries = (buf[18]<<8) | buf[17];
  params->root_entries = (buf[18]<<8) | buf[17];
  params->sectors_per_cluster = buf[13];
  params->sectors_per_cluster = buf[13];
 
 
 
 
  /* set start of current directory to start of root-directory        */
  /* set start of current directory to start of root-directory        */
  params->ssector = start_sector + params->fats * params->sectors_per_fat +1;
        params->ssector =
 
            start_sector + params->fats * params->sectors_per_fat + 1;
 
 
  /* set current sector to start of root-directory                    */
  /* set current sector to start of root-directory                    */
  params->csector = params->ssector;
  params->csector = params->ssector;
 
 
  /* set start-entry number                                           */
  /* set start-entry number                                           */
Line 131... Line 127...
  fext[4] = '\0';
  fext[4] = '\0';
 
 
  return ( strcmp(fname, name) && strcmp(fext, ext) );
  return ( strcmp(fname, name) && strcmp(fext, ext) );
}
}
 
 
 
 
/*
/*
  D O S _ D I R _ F I N D _ E N T R Y
  D O S _ D I R _ F I N D _ E N T R Y
*/
*/
struct dos_dir_entry *dos_dir_find_entry(struct dosparam *params, const char *name)
struct dos_dir_entry *dos_dir_find_entry(struct dosparam *params,
 
                                         const char *name)
{
{
  struct dos_dir_entry *entry;
  struct dos_dir_entry *entry;
  unsigned long entry_no = 0;
  unsigned long entry_no = 0;
 
 
  /* go to start of current directory                                 */
  /* go to start of current directory                                 */
  if (params->csector != params->ssector)
  if (params->csector != params->ssector)
    dos_dir_cluster_reset(params);
    dos_dir_cluster_reset(params);
 
 
  /* search for the requested entry                                   */
  /* search for the requested entry                                   */
  while ( (entry = dos_dir_get_entry(params, entry_no)) && dos_namecmp(name, entry->name, entry->ext) )
        while ((entry = dos_dir_get_entry(params, entry_no))
 
               && dos_namecmp(name, entry->name, entry->ext))
    entry_no++;
    entry_no++;
 
 
  return entry;
  return entry;
}
}
 
 
 
 
/*
/*
  D O S _ D I R _ G E T _ E N T R Y
  D O S _ D I R _ G E T _ E N T R Y
*/
*/
struct dos_dir_entry *dos_dir_get_entry(struct dosparam *params, unsigned long entry)
struct dos_dir_entry *dos_dir_get_entry(struct dosparam *params,
 
                                        unsigned long entry)
{
{
  char *buf = params->cbuf;
  char *buf = params->cbuf;
 
 
  if (entry < params->sentry)
  if (entry < params->sentry)
    buf = dos_dir_cluster_reset(params);
    buf = dos_dir_cluster_reset(params);
 
 
  while ( entry >= (params->sentry + entries_per_cluster(params)) )
  while ( entry >= (params->sentry + entries_per_cluster(params)) )
      if ( !(buf = dos_dir_cluster_read_nxt(params)) )
      if ( !(buf = dos_dir_cluster_read_nxt(params)) )
        return NULL;
        return NULL;
 
 
  return (struct dos_dir_entry*)(buf + ( (entry - params->sentry) * sizeof(struct dos_dir_entry)) );
        return (struct dos_dir_entry *)(buf +
 
                                        ((entry -
 
                                          params->sentry) *
 
                                         sizeof(struct dos_dir_entry)));
}
}
 
 
 
 
/*
/*
  D O S _ R E A D _ C L U S T E R
  D O S _ R E A D _ C L U S T E R
*/
*/
char *dos_read_cluster(struct dosparam *params, unsigned long ssector)
char *dos_read_cluster(struct dosparam *params, unsigned long ssector)
{
{
Line 194... Line 193...
  params->csector = ssector;
  params->csector = ssector;
 
 
  return params->cbuf;
  return params->cbuf;
}
}
 
 
 
 
/*
/*
  D O S _ D I R _ C L U S T E R _ R E A D _ N X T
  D O S _ D I R _ C L U S T E R _ R E A D _ N X T
*/
*/
char *dos_dir_cluster_read_nxt(struct dosparam *params)
char *dos_dir_cluster_read_nxt(struct dosparam *params)
{
{
Line 210... Line 208...
  nxt_cluster_start = params->csector + params->sectors_per_cluster;
  nxt_cluster_start = params->csector + params->sectors_per_cluster;
 
 
  if ( !(p = dos_read_cluster(params, nxt_cluster_start)) )
  if ( !(p = dos_read_cluster(params, nxt_cluster_start)) )
    return NULL;
    return NULL;
 
 
 
 
  params->sentry += entries_per_cluster(params);
  params->sentry += entries_per_cluster(params);
 
 
  return p;
  return p;
}
}
 
 
 
 
/*
/*
  D O S _ D I R _ C L U S T E R _ R E S E T
  D O S _ D I R _ C L U S T E R _ R E S E T
*/
*/
char *dos_dir_cluster_reset(struct dosparam *params)
char *dos_dir_cluster_reset(struct dosparam *params)
{
{
  params->sentry = 0;
  params->sentry = 0;
  return dos_read_cluster(params, params->ssector);
  return dos_read_cluster(params, params->ssector);
}
}
 
 
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.