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

📄 zfat.h

📁 &#8226 控制器(CPU): Atmel AT90S8515 AVR &#8226 MP3解码器: STA013 &#8226 音频 DAC: CS4334 &#8226 IDE 接口
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
    Copyright 2003 Nasif Akand (nasif@yifan.net)
    http://go.to/zipamp
    http://zipamp.virtualave.net

    This file is part of ZipAmp MP3 software.

    ZipAmp 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.

    ZipAmp 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 code; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

//This module is the implementation to interface ZIPAMP with FAT filesystem
//Nasif Akand

#ifndef __ZFAT_H__
#define __ZFAT_H__

#include "ztype.h";

/*
Definitions for initializing and controlling FAT file system. To reduce memory
some "dirty tricks" has been used. Comments are given for any shortcut or dirty methods.

byte = unsigned char
word = unsigned int
dword = unsigned long
*/

#define MSDOSFSROOT     0               /* cluster 0 means the root dir */
#define CLUST_FREE      0               /* cluster 0 also means a free cluster */
#define MSDOSFSFREE     CLUST_FREE
#define CLUST_FIRST     2               /* first legal cluster number */
#define CLUST_RSRVD     0xfffffff6      /* reserved cluster range */
#define CLUST_BAD       0xfffffff7      /* a cluster with a defect */
#define CLUST_EOFS      0xfffffff8      /* start of eof cluster range */
#define CLUST_EOFE      0xffffffff      /* end of eof cluster range */

#define FAT12_MASK      0x00000fff      /* mask for 12 bit cluster numbers */
#define FAT16_MASK      0x0000ffff      /* mask for 16 bit cluster numbers */
#define FAT32_MASK      0x0fffffff      /* mask for FAT32 cluster numbers */


/* Partition Type used in the partition record */

#define PART_TYPE_UNKNOWN	0x00
#define PART_TYPE_FAT12		0x01
#define PART_TYPE_XENIX		0x02
#define PART_TYPE_DOSFAT16	0x04
#define PART_TYPE_EXTDOS	0x05
#define PART_TYPE_FAT16		0x06
#define PART_TYPE_NTFS		0x07
#define PART_TYPE_FAT32		0x0B
#define PART_TYPE_FAT32LBA	0x0C
#define PART_TYPE_FAT16LBA	0x0E
#define PART_TYPE_EXTDOSLBA	0x0F
#define PART_TYPE_ONTRACK	0x33
#define PART_TYPE_NOVELL	0x40
#define PART_TYPE_PCIX		0x4B
#define PART_TYPE_PHOENIXSAVE	0xA0
#define PART_TYPE_CPM		0xDB
#define PART_TYPE_DBFS		0xE0
#define PART_TYPE_BBT		0xFF

// Boot signature
#define BOOTSIG0        0x55
#define BOOTSIG1        0xaa	                   
#define EXBOOTSIG       0x29

//For Win9x (DOS 7.10) BPB
#define FATNUM      0xf             /* mask for numbering active FAT */
#define FATMIRROR   0x80            /* FAT is mirrored (like it always was) */
#define FSVERS      0               /* currently only 0 is understood */

//For dirEntry
#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 */
#define ATTR_NORMAL     	0x00            /* normal file */
#define ATTR_READ_ONLY   	0x01            /* file is readonly */
#define ATTR_HIDDEN     	0x02            /* file is hidden */
#define ATTR_SYSTEM     	0x04            /* file is a system file */
#define ATTR_VOLUME_ID     	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 */
#define LCASE_BASE      	0x08            /* filename base in lower case */
#define LCASE_EXT       	0x10            /* filename extension in lower case */
#define ATTR_LONG_NAME		0x0f
#define ATTR_LONG_NAME_MASK	0x3f //ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID | ATTR_DIRECTORY | ATTR_ARCHIVE

//For winentry (windows long file name entry)
#define WIN_LAST        0x40
#define WIN_CNT         0x3f
#define ATTR_WIN95      0x0f
#define WIN_CHARS       13      /* Number of chars per winentry */
#define WIN_MAXLEN      255    	// Maximum filename length in Win95
				//Note: Must be < sizeof(dirent.d_name)


/*unsigned long*/ 	dword	FirstDataSector;	//First data sector of the partition
/*unsigned int*/  	word 	Bytes_Per_Sector;	//Bytes per sector in drive, usually 512 bytes
/*unsigned int*/  	byte	Sectors_Per_Cluster;	//Sectors per cluster
/*unsigned long*/ 	dword	FirstFATSector;		//First sector of the FAT table
/*unsigned long*/	dword	FirstDirSector;		//First sector of data
/*unsigned long*/	dword	FileSize=0;             //File size of the file just read from dir table
			dword   DriveSize;		//Drive size (free space in drive, used for identification)


			byte	fileName[41]; 		//file name, NULL terminated
			byte	fileExtension[4];	//file extension, 4 byte to make it dword
			word	currentFileNum; 	//File number from the directory table
			dword	currentCluster;		//Current cluster in file chain.	
			dword	firstCluster;		//First cluster of the file just read from dir table.
			byte	subDirLevel=0;		//# of dir level we went down from root directory
			dword	dirStackLBA;		//LBA address of ZIPAMP.SYS file for directory stack
			dword	cfgFileLBA;		//LBA address of ZIPAMP.CFG file
			byte	dirString[21];		//Dir tree string, used for displaying path on LCD
							//position 0 (dirString[0]) stores size of the string.
               
               
struct {		//Holds the read offset of each dir entry position
 dword	cluster;	//Cluster #
 byte	sectorPos;      //Sector # in this cluster
 word	offset;         //Offset in sector
 word	fileNum;        //File number
} dirReadOffset;



struct driveID {
 	word	res1;		//reserved     						0
 	word	cylinder;	//# of cylinders                                        1
 	word	res2;  		//reserved                                              2
 	word	head;		//# of head                                             3
 	word 	obsolete[2];	//obsolete data                                         5
 	word	sector;		//# of sectors                                          6
 	word	skip[16];       //skipping 40 bytes                                    7-26
	byte    firmware[8];    //firmware number
 	byte	model[40];	//model name string, stored word by word               27-46
 				//each word has two characters, and they are stored
 				//in little endian structure. "SEAGATE" would be stored
 				//as "ESGATA",0,"E" (0 is the null character)
 	word	res3[2];        //                                                     47-48
 	word	detect;         //                                                     49
 	word	skip2[10];      //                                                     50-59
 	word    totalSecLo;
 	word	totalSecHi;
// 	dword	totalSec;	//total LBA sectors                                    60-61
 	//...............
 	//There are more structures but we don't use them.
};			


struct driveSize {
 word	nothing[60];
 word	totalSecLo;
 word	totalSecHi; 	
};

//Naming shotcuts:
// part = partition
// Sec  = Sector         
// Cyl  = Cylinder
// Rec  = Record
//BPB	= Bios Parameter Block

struct partRec {			        //16 byte partition definition
 	byte	  	isActive;		/* 0x80 indicates active partition */
	byte	  	startHead;		/* starting head for partition */
	word	  	startCylSec;		/* starting cylinder and sector */
	byte	  	type;	  		/* partition type (see above) */
	byte  	  	endHead;		/* ending head for this partition */
	word	  	endCylSect;		/* ending cylinder and sector */
	dword		startLBA;		/* first LBA sector for this partition */
	dword		size;			/* size of this partition (bytes or sectors ?) */
	
};


⌨️ 快捷键说明

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