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

📄 tmfat32.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:    tmFat32.h                                                     */
/*                                                                            */
/* DESCRIPTION:  This is the common public API for tmFat32.                   */
/*                                                                            */
/* DOCUMENT REF: tbd                                                          */
/* 																			  */
/* NOTES:        tbd                                                          */
/*                                                                            */
/* -------------------------------------------------------------------------- */

#ifndef _TMFAT32_H_
#define _TMFAT32_H_

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

#if !defined(USE_GENERIC_C)
#define USE_GENERIC_C 0
#endif // !defined(USE_GENERIC_C)

#if !USE_GENERIC_C
#include "tmNxTypes.h"
#include <tmNxCompId.h>
#endif // !USE_GENERIC_C

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

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

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

/* We do the following gymnastics so we can have error codes for tmFat32. */

#define TM_FAT32_ERR_BASE           ((CID_COMP_IDE) | (CID_LAYER_DEVLIB))
#define TM_FAT32_ERR_COMP           ((CID_COMP_IDE) | (CID_LAYER_DEVLIB) | \
                                        (TM_ERR_COMP_UNIQUE_START))

// tmFat32 component error codes
#define TM_FAT32_ERR_NOT_INITIALIZED  (TM_FAT32_ERR_BASE | TM_ERR_NOT_INITIALIZED)
#define TM_FAT32_ERR_INIT_FAILED      (TM_FAT32_ERR_BASE | TM_ERR_INIT_FAILED)
#define TM_FAT32_ERR_NULL_PARAMETER   (TM_FAT32_ERR_BASE | TM_ERR_NULL_PARAMETER)
#define TM_FAT32_ERR_READ		      (TM_FAT32_ERR_BASE | TM_ERR_READ)
#define TM_FAT32_ERR_WRITE            (TM_FAT32_ERR_BASE | TM_ERR_WRITE)
#define TM_FAT32_ERR_BAD_PARAMETER    (TM_FAT32_ERR_BASE | TM_ERR_BAD_PARAMETER)
#define TM_FAT32_ERR_FULL             (TM_FAT32_ERR_BASE | TM_ERR_FULL)
#define TM_FAT32_ERR_OVERFLOW         (TM_FAT32_ERR_BASE | TM_ERR_OVERFLOW)
#define TM_FAT32_ERR_OUT_OF_MEMORY    (TM_FAT32_ERR_BASE | TM_ERR_OUT_OF_MEMORY)
#define TM_FAT32_ERR_NOT_SUPPORTED    (TM_FAT32_ERR_BASE | TM_ERR_NOT_SUPPORTED)

// tmFat32 component unique error codes
#define TM_FAT32_ERR_NOT_FOUND        (TM_FAT32_ERR_COMP + 0x00)
#define TM_FAT32_ERR_NOT_OPEN         (TM_FAT32_ERR_COMP + 0x01)
#define TM_FAT32_ERR_IN_READ_MODE     (TM_FAT32_ERR_COMP + 0x02)
#define TM_FAT32_ERR_IN_WRITE_MODE    (TM_FAT32_ERR_COMP + 0x03)
#define TM_FAT32_ERR_CLOSE_FAILED     (TM_FAT32_ERR_COMP + 0x04)
#define TM_FAT32_ERR_VOLUME_EXISTS    (TM_FAT32_ERR_COMP + 0x05)

#define TM_FAT32_COMPATIBILITY_NR     0   // API compatibility number
#define TM_FAT32_MAJOR_VERSION_NR     1   // API major version number
#define TM_FAT32_MINOR_VERSION_NR     9   // API minor version number

/* Some name limits and defaults. */

#define TM_FAT32_MAX_LONG_NAME      (255*4)   // Longest long file name or directory
                                              // name. Not including trailing Null
                                              // AN - changed from 255 to 255*4
                                              //      4 bytes/char is the max in UTF8

/* 
Maximum length of the mount name. This is the name to be used by the
tmFat32 recognition function when the file system is mounted. It includes the
terminating colon but not the terminating Null. E.g., if you open the
file "MYDISK:/foo/bar/x.txt" the length of the mount name is 7. This
mount name is NOT the volume name that Windoze puts at the beginning of
the data area for a partition. That name has a maximum length of 11 not
counting the terminating Null.

The mount name can also be Unix-like but it must begin with a forward
slash, e.g., "/foo" so you can open files such as "/foo/bar/info.dat".
*/

#define TM_FAT32_MAX_MOUNT_NAME      16   // Not including trailing Null
#define TM_FAT32_MAX_VOLUME_NAME     11   // Not including trailing Null
#define TM_FAT32_MAX_SERIAL_NAME     31   // Not including trailing Null

#define TM_FAT32_DEFAULT_MOUNT_NAME  "DISK:"

typedef void *	ptmFat32_Instance_t; /* Anonymous pointer to a tmFat32 instance. */

/* Callback notification functions. */

#define TM_FAT32_EVENT_READ      (1 << 0)   // Low level read operation started
#define TM_FAT32_EVENT_WRITE     (1 << 1)   // Low level write operation started
#define TM_FAT32_EVENT_EJECT     (1 << 2)   // Device ejected
#define TM_FAT32_EVENT_INSERT    (1 << 3)   // Device inserted

/* File and directory attributes.  */

#define TM_FAT32_ATTR_READ_ONLY  0x01
#define TM_FAT32_ATTR_HIDDEN     0x02
#define TM_FAT32_ATTR_SYSTEM     0x04
#define TM_FAT32_ATTR_ARCHIVE    0x20

/* Media type.  */

#define TM_FAT32_MEDIA_FIXED      0xF8
#define TM_FAT32_MEDIA_REMOVABLE  0xF0

typedef void  (*tmFat32_NotifyEvent)(ptmFat32_Instance_t vol, UInt32 event);

/* Device types. */

typedef enum
{
	tmFat32_NullDevice,     /* Null device. */
	tmFat32_IdeDevice,      /* IDE hard disk. */
	tmFat32_RamDevice,      /* RAM disk */
	tmFat32_UsbDevice,      /* USB host device */
	tmFat32_FlashDevice,    /* Flash memory */
	tmFat32_SdDevice        /* SD Card */
} tmFat32_DeviceType_t;

/* File system types. */

typedef enum
{
	tmFat32_FAT32,
	tmFat32_FAT16,
	tmFat32_FAT12
} tmFat32_FSType_t;

/* Partition info requests. */

typedef enum
{
	tmFat32_GetNumUnits,
	tmFat32_GetNumPartitions,
	tmFat32_GetPartitionData
} tmFat32_PartitionInfoRequest_t;

/* Format control structure. */

typedef struct tmFat32_Format 
{
    tmFat32_FSType_t fsType;        // File system type

    tmFat32_DeviceType_t deviceType;    // Default is tmFat32_IdeDevice
    
    UInt32  unit;          // Unit number, e.g, IDE may have a master
                           // and slave device on primary and secondary
                           // channels, so it can have units 0,1,2, and 3.

    Bool    quickFormat;   // If true, only the control information
                           // (directories, etc.) are written to
                           // indicate an empty file system. Otherwise,
                           // all sectors are erased -- this can take
                           // a very long time. Default is True.
                           
    String  volumeName;    // Volume label. If Null default is no label.
    
    UInt32  clusterSize;   // Cluster size, in bytes, to override the
                           // default allocation unit size. Default 
                           // settings are strongly recommended for general 
                           // use. FAT32 supports 512, 1024, 2048, 4096, 
                           // 8192, 16K, 32K, 64K, (128K, 256K for sector 
                           // size > 512 bytes). Note that the FAT and FAT32 
                           // files systems impose the following restrictions 
                           // on the number of clusters on a volume:
                           //   FAT: Number of clusters <= 65526
                           //   FAT32: 65526 < Number of clusters < 268435446
                           // Format will immediately stop processing if it 
                           // decides that the above requirements cannot be 
                           // met using the specified cluster size.
                           // If 0 use default values.

    UInt8   mediaType;     // Removable (0xF0) or fixed (0xF8)? Default 
                           // is fixed.

    UInt64  baseSector;    // Starting sector where to put the MBR (Master
                           // Boot Record). By default this is 0 but this,
                           // in combination with numSectors, can be used
                           // format only part of the disk.

    UInt64  numSectors;    // Number of sectors to use. If 0 use all remaining
                           // sectors starting at baseSector. baseSector plus
                           // numSectors, of course, must be less than the
                           // total number of sectors on the disk.

} tmFat32_Format_t, *ptmFat32_Format_t;
        
/* tmFat32 control structure. */

typedef struct tmFat32_Control 
{
    tmFat32_DeviceType_t deviceType;    // Default is tmFat32_IdeDevice

    UInt32  unit;             // Unit number, e.g, IDE may have a master
                              // and slave device on primary and secondary
                              // channels, so it can have units 0,1,2, and 3.

    Bool    syncIO;           // Use synchronous I/O with this unit. Some
                              // devices, such as IDE with tmdlIde can do
                              // I/O operations synchronously or asynchronously.
                              // Synchronous I/O is slightly faster and uses
                              // fewer OS resources but it blocks until I/O
                              // is complete.

    String  mountName;        // Mount name, e.g., "MYFAT32:", if Null
                              // defaults to TM_FAT32_DEFAULT_MOUNT_NAME.
                              
    String  deviceName;       // Device name to select which partition to
                              // mount. If Null it will mount the first FAT
                              // partition (FAT12, FAT16, or FAT32) found for 
                              // this unit and deviceType. Otherwise it uses 
                              // the following naming scheme with examples
                              // given below:
                              //
                              // hda0   1st partition on hard disk (IDE) unit 0.
                              // hdb3   4st partition on hard disk (IDE) unit 1.
                              // rama2  3rd partition on RAMDISK unit 0.
                              // usbc5  6th partition on USB unit 2.
                              // usba1  2nd partition on USB unit 0.
                              // sda1   2nd partition on SD unit 0.
                              //
                              // If deviceName is provided it is used to determine 
                              // the device type, unit number, and partition number. 
                              // I.e., it overrides deviceType and unit fields.

    Bool    readOnly;         // Mount volume as read only. Default is False.
    
    Bool    showHidden;       // Show hidden files and directories for functions
                              // such as open, opendir and readdir. Default
                              // is False.
                              
    UInt32  heapSize;         // tmml heap size to use for each mounted volume.
                              // Default is 1 MB.

    Pointer appHeap;          // If nonzero use the tmml heap allocated by the
                              // application. This is a pointer to a 
                              // tmml handle (tmmlMmspHandle_t). This tells
                              // tmFat32 not to allocate its own heap for the
                              // volume to be mounted but to use the heap
                              // provided by the application. If this value is nonzero
                              // heapSize must also be nonzero.
                              
    UInt    maxOpenFiles;     // Maximum number of open files allowed. Default
                              // is FOPEN_MAX from stdio.h (20 for TriMedia).
                              
    Bool    noFragmentCheck;  // If True do not scan a file's FAT at open time
                              // to determine if it's fragmented. Default is
                              // False, check for fragmentation. The scan increases
                              // open time but speeds up reading/seeking contiguous
                              // readonly file.
                              
    UInt    syncFrequency;    // Synchronization frequency to maintain file system
                              // integrity. This only applies to file systems
                              // not mounted readOnly. It controls how often
                              // cached data gets written to the media. Currently
                              // it can be the following values:
                              //
                              // 0        Flush cache after a file is opened for
                              //          writing, unlink (delete), rename, mkdir, 
                              //          and rmdir in addition to cases
                              //          described below in 2. Default.
                              //

⌨️ 快捷键说明

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