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

📄 tmfat32private.h

📁 PNX1500上Fat32文件系统源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -------------------------------------------------------------------------- */
/* (C) Copyright 2000,2002, 2003 Koninklijke Philips Electronics N.V.,        */
/*     All rights reserved                                                    */
/*                                                                            */
/* This source code and any compilation or derivative thereof is the          */
/* proprietary information of Konlinklijke Philips Electronics N.V. and is    */
/* Confidential in nature.                                                    */
/* Under no circumstances is this software to be exposed to or placed under an*/
/* Open Source License of any type without the expressed written permission of*/
/* Koninklijke Philips Electronics N.V.                                       */
/* -------------------------------------------------------------------------- */
/* FILE NAME:    tmFat32Private.h                                             */
/*                                                                            */
/* DESCRIPTION:  This is a private API for TriMedia tmFat32.                  */
/*                                                                            */
/* DOCUMENT REF: tbd                                                          */
/* 																			  */
/* NOTES:        tbd                                                          */
/*                                                                            */
/* -------------------------------------------------------------------------- */

#ifndef _TMFAT32PRIVATE_H_
#define _TMFAT32PRIVATE_H_

// Build options

// USE_SIMULATOR is defined by makefiles. If defined it is useful for testing 
// the tmFat32 without using real hardware.

// USE_GENERIC_C is defined by makefiles. If non-zero it tries to build the tmFat32
// library using generic C (non-NDK, non-MPTK, non-TriMedia).

#if !USE_GENERIC_C
#define USE_MML         1      // If true use tmml memspace, otherwise use malloc/free.
#define USE_ERRNO       1      // If true set errno values.
#define USE_REENTRANCY  1      // If true support reentrancy
#endif

/* -------------------------------------------------------------------------- */
/*                                                                            */
/*   Standard include files:                                                  */
/*                                                                            */
/* -------------------------------------------------------------------------- */

#if USE_GENERIC_C
#include <tmFat32Generic.h>
#else // USE_GENERIC_C 
#include <sys/syslimits.h>
#include <tmml.h>
#endif //!USE_GENERIC_C
#include <tmFat32.h>
#include <tmFat32Device.h>
#include <tmFat32Debug.h>

/* -------------------------------------------------------------------------- */
/* Define extern c for C++ prototypes                                         */
/* -------------------------------------------------------------------------- */

#if defined(__cplusplus)
extern "C"{
#endif

/* -------------------------------------------------------------------------- */
/*    Types and defines:                                                      */
/* -------------------------------------------------------------------------- */

// Default heap size. FAT16 used 1MB, we can get by with less than 64K.

#define TMFAT_HEAP_SIZE (1024 * 1024)

#if USE_MML
#define TMFAT_MALLOC(x)   UTIL_malloc(x)
#define TMFAT_FREE(x)     UTIL_free(x)
#else
#define TMFAT_MALLOC(x)   calloc(x, 1)
#define TMFAT_FREE(x)     if (x) free(x)
#endif

#if USE_ERRNO
#define SET_ERRNO(x)    errno = (x)
#else
#define SET_ERRNO(x)
#endif
                            
#if USE_REENTRANCY

#if defined(__TCS__)
#define TMFAT_CREATE_LOCK   \
                            {\
                                if (gtmFat32_Lock==0)\
                                {\
                                    gtmFat32_Locked = False;\
                                    status = tmosalMutexCreate(&gtmFat32_Lock, tmosalMutexCreateFlagNone);\
                                    if (status != TM_OK) return status;\
                                }\
                            }
#define TMFAT_DESTROY_LOCK  {status = tmosalMutexDestroy(gtmFat32_Lock);gtmFat32_Lock=0;}
#define TMFAT_LOCK          {tmosalMutexEnter(gtmFat32_Lock, Null); gtmFat32_Locked = True;}
#define TMFAT_UNLOCK        {gtmFat32_Locked = False; tmosalMutexExit(gtmFat32_Lock);}
#define TMFAT_SET_FS(path)
#else
#define TMFAT_CREATE_LOCK   tmFat32_Create_Lock()
#define TMFAT_DESTROY_LOCK  tmFat32_Destroy_Lock()
#define TMFAT_LOCK          tmFat32_Lock()
#define TMFAT_UNLOCK        tmFat32_Unlock()
#define TMFAT_SET_FS(path)  TMFAT_LOCK; UTIL_set_fs(path)
#endif

#else

#define TMFAT_CREATE_LOCK
#define TMFAT_DESTROY_LOCK
#define TMFAT_LOCK
#define TMFAT_UNLOCK
#define TMFAT_SET_FS(path)  UTIL_set_fs(path)

#endif

// Convenience macros

#define GFS gptmFat32_PrivateInfo

#define TMFAT_MIN(a,b)  ((a) < (b) ? (a) : (b))
#define TMFAT_MAX(a,b)  ((a) > (b) ? (a) : (b))

#define YES_NO_STR(x)   ((x) ? "YES" : "NO")

// Macros for extracting data from sectors

#define GET16(p)    (UInt16) (( ((UInt8 *)(p))[1] <<  8 ) + \
                              ( ((UInt8 *)(p))[0]       ))

#define GET32(p)    (UInt32) (( ((UInt8 *)(p))[3] << 24 ) + \
                              ( ((UInt8 *)(p))[2] << 16 ) + \
                              ( ((UInt8 *)(p))[1] <<  8 ) + \
                              ( ((UInt8 *)(p))[0]       ))

#define SET16(p,v)  { \
                        ((UInt8 *)(p))[0] = ((v)      ) & 0xFF;\
                        ((UInt8 *)(p))[1] = ((v) >> 8 ) & 0xFF;\
                    }
                    
#define SET32(p,v)  { \
                        ((UInt8 *)(p))[0] = ((v)      ) & 0xFF;\
                        ((UInt8 *)(p))[1] = ((v) >> 8 ) & 0xFF;\
                        ((UInt8 *)(p))[2] = ((v) >> 16) & 0xFF;\
                        ((UInt8 *)(p))[3] = ((v) >> 24) & 0xFF;\
                    }
                    
// Certain DOS constants

#define DOS_DEFAULT_SECTOR_SIZE     512
#define TMFAT_MAX_SECTOR_SIZE       (DOS_DEFAULT_SECTOR_SIZE * 8)

// DOS Master Boot Record or BPB sector

#define MAGIC_SECTOR_TRIES  256   // Number of sectors to read before giving up looking
                                  // for an MBR or BPB sector.

/* Directory attributes. */

#define DIR_DELIMITERS	"/"   // Forward slashes (backward slashes normalized out)

#define DIR_ENTRY_SIZE   	32   /* Size of directory entry, in bytes. */

#define ATTR_READ_ONLY   	0x01
#define ATTR_HIDDEN 	    0x02
#define ATTR_SYSTEM 	    0x04
#define ATTR_VOLUME_ID 	    0x08
#define ATTR_DIRECTORY	    0x10
#define ATTR_ARCHIVE  	    0x20
#define ATTR_LONG_NAME 	    (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID)

#define ATTR_LONG_NAME_MASK	(ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | \
                             ATTR_VOLUME_ID | ATTR_DIRECTORY | ATTR_ARCHIVE)

/* Directory offsets. */

#define OFFSET_DIRName	         0	//11	Short name.
#define OFFSET_DIRAttr	        11	//1	File attributes:
#define OFFSET_DIRNTRes	        12	//1	Reserved for use by Windows NT. Set value to 0 when a file is created and never modify or look at it after that.
#define OFFSET_DIRCrtTimeTenth	13	//1	Millisecond stamp at file creation time. This field actually contains a count of tenths of a second. The granularity of the seconds part of #define OFFSET_DIRCrtTime is 2 seconds so this field is a count of tenths of a second and its valid value range is 0-199 inclusive.
#define OFFSET_DIRCrtTime	    14	//2	Time file was created.
#define OFFSET_DIRCrtDate	    16	//2	Date file was created.
#define OFFSET_DIRLstAccDate	18	//2	Last access date. Note that there is no last access time, only a date. This is the date of last read or write. In the case of a write, this should be set to the same date as #define OFFSET_DIRWrtDate.
#define OFFSET_DIRFstClusHI	    20	//2	High word of this entry's first cluster number (always 0 for a FAT12 or FAT16 volume).
#define OFFSET_DIRWrtTime	    22	//2	Time of last write. Note that file creation is considered a write.
#define OFFSET_DIRWrtDate	    24	//2	Date of last write. Note that file creation is considered a write.
#define OFFSET_DIRFstClusLO	    26	//2	Low word of this entry's first cluster number.
#define OFFSET_DIRFileSize	    28	//4	32-bit DWORD holding this file's size in bytes.

/* Long Directory Entry Offsets. */

#define LDIR_Ord	    0	//1	The order of this entry in the sequence of long dir entries associated with the short dir entry at the end of the long dir set.If masked with 0x40 (LAST_LONG_ENTRY), this indicates the entry is the last long dir entry in a set of long dir entries. All valid sets of long dir entries must begin with an entry having this mask.
#define LDIR_Name1	    1	//10	Characters 1-5 of the long-name sub-component in this dir entry.
#define LDIR_Attr	    11	//1	Attributes - must be ATTR_LONG_NAME
#define LDIR_Type	    12	//1	If zero, indicates a directory entry that is a sub-component of a long name.  NOTE: Other values reserved for future extensions.Non-zero implies other dirent types.
#define LDIR_Chksum	    13	//1	Checksum of name in the short dir entry at the end of the long dir set.
#define LDIR_Name2	    14	// 12	Characters 6-11 of the long-name sub-component in this dir entry.
#define LDIR_FstClusLO	26	//2	Must be ZERO. This 
//is an artifact of the FAT "first cluster" and must be zero for
// compatibility with existing disk utilities.  It's 
//meaningless in the context of a long dir entry.
#define LDIR_Name3	    28	//4	Characters 12-13 of the long-name sub-component in this dir entry.

#define	DOSPARTSIZE	16
#define	DOSPARTOFF	446
#define	DOSMAGICOFFSET	510
#define	DOSMAGIC1	0xAA
#define	DOSMAGIC0	0x55
#define	NDOSPART	4

#define FAT12_PART_TYPE1   0x01      // 12-bit FAT partition

#define FAT16_PART_TYPE1   0x04      // 16-bit FAT partition less than 32 MB
#define FATXX_PART_EXTEND1 0x05      // Extended MS-DOS partition
#define FAT16_PART_TYPE2   0x06      // 16-bit FAT partition greater than 32 MB
#define FAT16_PART_TYPE3   0x0E      // Same as 0x06, but uses LBA(1) 13h extensions
#define FATXX_PART_EXTEND2 0x0F      // Extended MS-DOS partition

#define FAT32_PART_TYPE1   0x0B      // 32-bit FAT partition up to 2048 GB
#define FAT32_PART_TYPE2   0x0C      // Same, but uses LBA(1) 13h extensions
#define FAT32_PART_TYPE3   0x42      // Dynamic, simple (no partitions) FAT32?

#define FATXX_PART_TYPE    0xFF      // Unknown because we don't have MBR

// BPB (BIOS Parameter Block) offsets

#define BPB_BytsPerSec	11	        // 2 bytes
#define BPB_SecPerClus	13	        // 1 byte
#define BPB_RsvdSecCnt	14	        // 2 bytes
#define BPB_NumFATs	    16	        // 1 byte
#define BPB_RootEntCnt	17	        // 2 byte
#define BPB_TotSec16 	19	        // 2 bytes
#define BPB_Media       21          // 1 byte
#define BPB_FATSz16	    22	        // 2 bytes
#define BPB_SecPerTrk 	24	        // 2 bytes
#define BPB_NumHeads 	26	        // 2 bytes
#define BPB_HiddSec 	28	        // 4 bytes
#define BPB_TotSec32 	32	        // 4 bytes

// FAT12/FAT16 only

#define BS_DrvNum16     36          // 1 byte
#define BS_BootSig16    38          // 1 byte
#define BS_VolID16      39          // 4 bytes
#define BS_VolLab16     43          // 11 bytes
#define BS_FilSysType16 54          // 8 bytes

#define FAT16_ROOT_ENTRY_COUNT   512      // Count of 32-byte entries in root directory

// FAT32 only

#define BPB_FATSz32	    36	        // 4 bytes
#define BPB_ExtFlags	40	        // 2 bytes
#define BPB_RootClus	44	        // 4 bytes
#define BPB_FSInfo	    48	        // 2 bytes
#define BPB_BkBootSec	50	        // 2 bytes
#define BS_DrvNum       64          // 1 byte
#define BS_BootSig      66          // 1 byte
#define BS_VolID        67          // 4 bytes
#define BS_VolLab       71          // 11 bytes
#define BS_FilSysType   82          // 8 bytes

#define FAT32_BACKUP_BOOT_SECTOR_OFFSET   6

// Number of sectors between the MBR and the first sector 
// of the first partition.

#define MBR_TO_FIRST_PARTITION_OFFSET    63      

#define BPB_Extended_Boot_Signature 0x29

// FSI (FAT32 File System Information Structure) constants and offsets

#define UNKNOWN_FSI_INFO    0xFFFFFFFF

#define FSI_LeadSig	        0	        // 4 bytes
#define FSI_LeadSigVal	    0x41615252
#define FSI_StrucSig	    484	        // 4 bytes
#define FSI_StrucSigVal	    0x61417272
#define FSI_Free_Count	    488	        // 4 bytes
#define FSI_Nxt_Free	    492	        // 4 bytes

#define IS_DOSMAGIC(p) (( ((UInt8 *)(p))[0] == DOSMAGIC0)  && \
                        ( ((UInt8 *)(p))[1] == DOSMAGIC1) ) ? 1 : 0
                         
// Open file types and directory entry types

#define TMFAT_TYPE_ANY      0
#define TMFAT_TYPE_DIR      1
#define TMFAT_TYPE_REG      2
#define TMFAT_TYPE_VOL      3

// Dirty volume flag masks.

#define ClnShutBitMask32      0x08000000
#define HrdErrBitMask32       0x04000000
#define ClnShutBitMask16          0x8000
#define HrdErrBitMask16           0x4000

// FAT entry values.

#define FAT_RESERVED_CLUSTERS        2  // The reserved clusters at start of FAT
#define FAT_FREE_CLUSTER    0x00000000

#define FAT12_EOC               0x0FF8
#define FAT16_EOC               0xFFF8
#define FAT32_EOC           0x0FFFFFF8

#define FAT12_CLUSTER_MASK  0x00000FFFL
#define FAT16_CLUSTER_MASK  0x0000FFFFL
#define FAT32_CLUSTER_MASK  0x0FFFFFFFL

#define FAT12_BAD_CLUSTER       0x0FF7
#define FAT16_BAD_CLUSTER       0xFFF7
#define FAT32_BAD_CLUSTER   0x0FFFFFF7

// FAT operations

#define SET_FAT_ENTRY      0
#define GET_FAT_ENTRY      1

// Cluster operations

#define GET_CLUSTER_CONTENT         0   // Read data from a cluster
#define SET_CLUSTER_CONTENT         1   // Write data to a cluster
#define SET_CLUSTER_CONTENT_CLEAR   2   // Clear cluster on allocation before writing
#define SET_CLUSTER_CONTENT_NOCACHE 3   // Write data to a cluster directly, not through cache

// Type of time stamp and time operations

#define TIME_CREATE        0    /* Creation time. */
#define TIME_WRITE         1    /* Time of last write. */
#define TIME_ACCESS        2    /* Time of last access. */

#define SET_TIME           0
#define GET_TIME           1

⌨️ 快捷键说明

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