⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat32.h

📁 这是一个基于8255扩展端口的keil c51固件
💻 H
字号:
/*
  Copyright (C) 2003 Bart Bilos <boombox666@yahoo.com>.

  code adapted and modified from the yampp project

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation, 
  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

// caching options
#define BUFFERS           1
#define FILES             10

// structure of an Boot sector

typedef struct
{
  
  char  BS_bootcode[0x1BE];
  unsigned char   BS_prIsActive;         /* 0x80 indicates active partition */
  unsigned char   BS_prStartHead;				/* starting head for partition */
  unsigned int    BS_prStartCylSect;			/* starting cylinder and sector */
  unsigned char   BS_prPartType;					/* partition type (see above) */
  unsigned char   BS_prEndHead;					/* ending head for this partition */
  unsigned int    BS_prEndCylSect;				/* ending cylinder and sector */
  unsigned long   BS_partition_start;    /* LBA sector start of partition */
  unsigned long   BS_partition_size;     /* size of partition in LBA units */
} Bootsector;

typedef struct
{
  unsigned char   BS_jmpBoot[3];   
  unsigned char   BS_OEMName[8];   
  unsigned int    BPB_BytsPerSec; 
  unsigned char   BPB_SecPerClus;
  unsigned int    BPB_ResvdSecCnt;
  unsigned char   BPB_NumFATs;
  unsigned int    BPB_RootEntCnt;
  unsigned int    BPB_TotSec16;
  unsigned char   BPB_Media;
  unsigned int    BPB_FATSz16;
  unsigned int    BPB_SecPerTrk;
  unsigned int    BPB_NumHeads;
  unsigned long   BPB_HiddSec;
  unsigned long   BPB_TotSec32;
  /* Here start the FAT32 specific fields (offset 36) */
  unsigned long   BPB_FATSz32;
  unsigned int    BPB_ExtFlags;
#define FATNUM    0xf         /* mask for numbering active FAT */
#define FATMIRROR 0x80        /* FAT is mirrored (like it always was) */
  unsigned int    BPB_FSVer;
#define FSVERS    0           /* currently only 0 is understood */
  unsigned long   BPB_RootClus;
  unsigned int    BPB_FSInfo;
  unsigned int    BPB_BkBootSec;
  unsigned char   BPB_Reserved[12];
  /* The following fields are present also in a FAT12/FAT16 BPB,     */
  /* but at offset 36. In a FAT32 BPB they are at offset 64 instead. */
  unsigned char   BS_DrvNum;
  unsigned char   BS_Reserved1;
  unsigned char   BS_BootSig;
  unsigned long   BS_VolID;
  unsigned char   BS_VolLab[11];
  unsigned char   BS_FilSysType[8];
} Bpb;

/*
 * Structure of a dos directory entry.
 */
typedef struct {
        char            DE_Name[8];      /* filename, blank filled */
#define SLOT_EMPTY      0x00            /* slot has never been used */
#define SLOT_E5         0x05            /* the real value is 0xe5 */
#define SLOT_DELETED    0xe5            /* file in this slot deleted */
        char            DE_Extension[3]; /* extension, blank filled */
        char            DE_Attributes;   /* file attributes */
#define ATTR_NORMAL     0x00            /* normal file */
#define ATTR_READONLY   0x01            /* file is readonly */
#define ATTR_HIDDEN     0x02            /* file is hidden */
#define ATTR_SYSTEM     0x04            /* file is a system file */
#define ATTR_VOLUME     0x08            /* entry is a volume label */
#define ATTR_LONG_FILENAME	0x0f		/* this is a long filename entry */			    
#define ATTR_DIRECTORY  0x10            /* entry is a directory name */
#define ATTR_ARCHIVE    0x20            /* file is new or modified */
        char            DE_LowerCase;    /* NT VFAT lower case flags */
#define LCASE_BASE      0x08            /* filename base in lower case */
#define LCASE_EXT       0x10            /* filename extension in lower case */
        char            DE_CHundredth;   /* hundredth of seconds in CTime */
        char            DE_CTime[2];     /* create time */
        char            DE_CDate[2];     /* create date */
        char            DE_ADate[2];     /* access date */
        unsigned int    DE_HighClust; 	/* high bytes of cluster number */
        char            DE_MTime[2];     /* last update time */
        char            DE_MDate[2];     /* last update date */
        unsigned int    DE_StartCluster; /* starting cluster of file */
        unsigned long   DE_FileSize;  	/* size of file in bytes */
} direntry;

// opened file structure
typedef struct  {
unsigned long fh_startsect;
unsigned long fh_fileptr;
unsigned long fh_size;
} filehandle ;

// function prototypes 
void fixBPB(Bpb *a_Bpb);
unsigned long clust2sect(unsigned long clust);
unsigned long rootdir();
char init_fat32(void);
char checksect(unsigned long a_sect_tocheck);
void FAT32entrydata(direntry *a_entry);
unsigned int traverse_dir(unsigned long int a_clust);
direntry * getfileentry(unsigned long a_cluster, char * filename);
void initfiles(void);
unsigned char fopen (char *a_filename);
unsigned long fseek(unsigned char a_handle, unsigned long pos, char mode);
unsigned char fclose (unsigned char a_handle);
unsigned char fread (unsigned char a_handle, char *a_buffer,unsigned int a_bytes);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -