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

📄 fatfs.h

📁 从大量的wince源代码中剥离出的fat文件系统源代码.移植性非常高. 里面带有source i.rar
💻 H
📖 第 1 页 / 共 5 页
字号:
#else
#define OWNCRITICALSECTION(cs)  TRUE
#endif

/*  All internal file system operations are performed in fixed size blocks.
 *  Only the low level disk access routines care about the true sector size
 *  on the device.
 */

#define BLOCK_SIZE              512     #define BLOCK_LOG2              9
#define BLOCK_OFFSET_MASK       (BLOCK_SIZE - 1)
#define BYTESTOBLOCKS(b)        (((b)+BLOCK_SIZE-1)>>BLOCK_LOG2)

#if ((1 << BLOCK_LOG2) != BLOCK_SIZE)
#error  Block size inconsistency
#endif

typedef struct _DLINK DLINK, *PDLINK;
typedef struct _BUF BUF, *PBUF;
typedef struct _DSK DSK, *PDSK;
typedef struct _PARTINFO PARTINFO, *PPARTINFO, *PPI;
typedef struct _CACHE CACHE, *PCACHE;
typedef struct _VOLUME VOLUME, *PVOLUME;
typedef struct _DSTREAM DSTREAM, *PDSTREAM;
typedef struct _FHANDLE FHANDLE, *PFHANDLE;
typedef struct _SHANDLE SHANDLE, *PSHANDLE;

#define FS_DECL(type, api, args) extern type FAT_ ## api args
#define FS_HANDLE PVOLUME pvol

#include <extfile.h>
#include <fatui.h>

#include "fatfmt.h"
#include "dosbpb.h"
#include "bootsec.h"
#include "partiton.h"


/*  Doubly linked lists:
 *
 *  Should be the first element of structure being linked.  It may be used
 *  as the head of a list anywhere in a structure which contains the list.
 *
 *  NOTE: the multiple definitions of the basic DLINK structure are here
 *  simply to provide additional information to the debugger regarding what
 *  kind of structure each link in a particular DLINK points to.
 */

struct _DLINK {
    PDLINK      next;           // ptr to next item in list
    PDLINK      prev;           // ptr to previous item in list
};

typedef struct _BUF_DLINK {
    PBUF        pbufNext;       // ptr to next item in list
    PBUF        pbufPrev;       // ptr to previous item in list
} BUF_DLINK, *PBUF_DLINK;

typedef struct _DSK_DLINK {
    PDSK        pdskNext;       // ptr to next item in list
    PDSK        pdskPrev;       // ptr to previous item in list
} DSK_DLINK, *PDSK_DLINK;

typedef struct _PI_DLINK {
    PPARTINFO   ppiNext;        // ptr to next item in list
    PPARTINFO   ppiPrev;        // ptr to previous item in list
} PI_DLINK, *PPI_DLINK;

typedef struct _CCH_DLINK {
    PCACHE      pcchNext;       // ptr to next item in list
    PCACHE      pcchPrev;       // ptr to previous item in list
} CCH_DLINK, *PCCH_DLINK;

typedef struct _VOL_DLINK {
    PVOLUME     pvolNext;       // ptr to next item in list
    PVOLUME     pvolPrev;       // ptr to previous item in list
} VOL_DLINK, *PVOL_DLINK;

typedef struct _STM_DLINK {
    PDSTREAM    pstmNext;       // ptr to next item in list
    PDSTREAM    pstmPrev;       // ptr to previous item in list
} STM_DLINK, *PSTM_DLINK;

typedef struct _FH_DLINK {
    PFHANDLE    pfhNext;        // ptr to next item in list
    PFHANDLE    pfhPrev;        // ptr to previous item in list
} FH_DLINK, *PFH_DLINK;

typedef struct _SH_DLINK {
    PSHANDLE    pshNext;        // ptr to next item in list
    PSHANDLE    pshPrev;        // ptr to previous item in list
} SH_DLINK, *PSH_DLINK;


/*  Global flags
 */
#define FATFS_UPDATE_ACCESS         0x00000001  // update access times if set
#define FATFS_DISABLE_LOG           0x00000002  // disable event logging if set
#define FATFS_DISABLE_AUTOSCAN      0x00000004  // disable automatic ScanVolume()
#define FATFS_VERIFY_WRITES         0x00000008  // verify all writes (as opposed to a handful)
#define FATFS_ENABLE_BACKUP_FAT     0x00000010  // add a backup FAT to all formats
#define FATFS_DISABLE_AUTOFORMAT    0x00000040  // disable automatic formatting of unformatted volumes
#define FATFS_DISABLE_COMPCHECK     0x00000080  // disable automatic checking of compressed volumes

#define FATFS_REGISTRY_FLAGS        (FATFS_UPDATE_ACCESS |      \
                                     FATFS_DISABLE_LOG |        \
                                     FATFS_DISABLE_AUTOSCAN |   \
                                     FATFS_VERIFY_WRITES |      \
                                     FATFS_ENABLE_BACKUP_FAT |  \
                                     FATFS_DISABLE_AUTOFORMAT | \
                                     FATFS_DISABLE_COMPCHECK)


 /*  Global flags set only at run-time
 */
#define FATFS_SHUTDOWN              0x80000000  // block all threads if set


/*  Buffer structure:
 *
 *  This structure describes a buffer of disk data.
 */

// values for b_flags:
#define BUF_CARVED              0x01    // buffer is carved from large VirtualAlloc
#define BUF_UNCERTAIN           0x02    // buffer is in transition (ie, is being read)
#define BUF_BUSY                0x04    #define BUF_ERROR               0x40    // buffer is uncommitable (currently also implies dirty)
#define BUF_DIRTY               0x80    // buffer is dirty

// values for b_blk:
#define INVALID_BLOCK           0xFFFFFFFF

struct _BUF {
    BUF_DLINK   b_dlink;        // preferred location for dlinks (at offset 0)
    PVOLUME     b_pvol;         // pointer to VOLUME buffer belongs to, if any
    DWORD       b_blk;          // block #
    PBYTE       b_pdata;        // pointer to disk data
    PDSTREAM    b_pstm;         // pointer to stream holding this buffer, if any
    BYTE        b_hold;         // non-zero if buffer is being held
    BYTE        b_flags;        // eg, BUF_DIRTY
#ifdef DEBUG
    DWORD       b_refs;         // usage count for this buffer (DEBUG only)
    BYTE        b_achName[OEMNAMESIZE+1];
#endif
};


/*  Disk structure:
 *
 *  This structure describes a disk device, which has one or more VOLUMEs
 *  associated with it.
 */

#ifdef  UNDER_CE
#define MAX_DISK_PATH           16
#else
#define MAX_DISK_PATH           MAX_PATH    // enough room for a fully-qualified disk image filename
#endif

// values for d_flags:
#define DSKF_NONE               0x00000000
#define DSKF_FROZEN             0x00000004  // disk has been frozen (but not freed)
#define DSKF_REMOUNTED          0x00000008  // disk has been remounted
#define DSKF_RECYCLED           0x00000010  // disk has been recycled (like remounted but worse)
#define DSKF_READONLY           0x00080000  // disk is read-only (eg, write-protected)

// private flags in DISK_INFO.di_flags (reserved for use by FATFS)
#define DISK_INFO_FLAGS_FATFS_RESERVED      0xf0000000
#define DISK_INFO_FLAGS_FATFS_SIMULATED     0x10000000
#define DISK_INFO_FLAGS_FATFS_NEW_IOCTLS    0x80000000

struct _DSK {
    DSK_DLINK   d_dlOpenDisks;          // list of open disks in system
    PVOLUME     pVol;                   // Points to the volume that is mounted
    PI_DLINK    d_dlPartitions;         // list of partitions for this disk
    DWORD       d_csecUnused;           // largest contiguous chunk of unpartitioned space (in sectors)
    DWORD       d_csecTotalUnused;      // total unpartitioned space (in sectors)
    HANDLE      d_hdsk;                 // device driver handle to read/write disk
    DWORD       d_flags;                // see DSKF_*
    DISK_INFO   d_diActive;             // active drive geometry for disk
    DWORD       d_cwName;               // actual number of characters allocated in d_wsName (including NULL)
    WCHAR       d_wsName[MAX_PATH];     // name of disk device
};


/*  Partition structure:
 *
 *  This structure describes a partition on a disk device.
 */

// values for pi_flags:
#define PIF_NONE                0x0000

struct _PARTINFO {
    PI_DLINK    pi_dlPartitions;// link in partition list
    PI_DLINK    pi_dlChildren;  // list of child partitions, if any
    PPARTINFO   pi_ppiParent;   // pointer back to parent partition, if this is a child partition
    DWORD       pi_dwSig;       // set to BOOTSECVOLUMESIG
    PVOLUME     pi_pvol;        // points to mounted VOLUME if one exists
    PDSK        pi_pdsk;        // DSK the partition resides on
    DWORD       pi_secPartTable;// sector of partition table
    WORD        pi_idxPartTable;// index in partition table
    WORD        pi_flags;       // see PIF_*
    PARTENTRY   pi_PartEntry;   // copy of partition table entry at that index
    DWORD       pi_secAbsolute; // absolute starting sector of partition
    PWSTR       pi_pwsName;     // pointer to specific name to be associated with this partition, NULL if none
};


/*  Partition search structure:
 *
 *  This structure describes the state of a partition search in progress.
 */

struct _PARTSRCH {
    DWORD       ps_csecMinimum; // minimum requested sectors
    DWORD       ps_csecDesired; // desired requested sectors
    PPI_DLINK   ps_pdlFound;    // pointer to head of partition list containing available sectors
    PPARTINFO   ps_ppiFound;    // pointer to PARTINFO on above list that follows available sectors
    DWORD       ps_csecFound;   // number of available sectors
    DWORD       ps_csecTotalFound;      // total of all available sectors found
};
typedef struct _PARTSRCH PARTSRCH, *PPARTSRCH;


/*  Cache structure:
 *
 *  This structure describes a cache entry.  Entries are linked onto a
 *  volume's cache chain.  The volume's cache critical section should be taken
 *  whenever an entry is created, destroyed, or searched on that volume's cache
 *  chain.
 *
 *  Currently, there is only one kind of entry: CACHE_PATH.  When an entry
 *  is created, an additional ref count is applied to the stream corresponding
 *  to that path;  similarly, that stream's ref count is reduced when the cache
 *  entry is destroyed (or reused).
 *
 *  Like SHANDLEs, when a CACHE structure is allocated, c_awcPath is not really
 *  MAX_PATH WCHARs big.  It is allocated only to the length stored in c_cwPath.
 */

#define MAX_CACHE_PER_VOLUME    4       // max cache entries per volume

// values for c_flags:
#define CACHE_PATH              0x01    // path cache entry

struct _CACHE {
    CCH_DLINK   c_dlink;        // preferred location for dlinks (at offset 0)
    PDSTREAM    c_pstm;         // pointer to stream
    BYTE        c_flags;        // see CACHE_*
    BYTE        c_reserved;     // not used (for padding only)
    WORD        c_cwPath;       // # characters in c_awcPath (includes room for NULL)
#ifdef DEBUG
    DWORD       c_cbAlloc;      // used to track size of this allocation only
#endif
    WCHAR       c_awcPath[MAX_PATH];
};


/*  File system volume structure:
 *
 *  This structure is used by the file system to hold specific volume
 *  information. E.G.: volume size, block to sector conversions, size of the
 *  FAT, the root directory file, etc.
 */

#define MAX_VOLUMES             99

// values for v_flags:
#define VOLF_NONE               0x00000000
#define VOLF_INVALID            0x00000001  // volume is invalid (eg, unformatted)
#define VOLF_UNMOUNTED          0x00000002  // volume has been unmounted
#define VOLF_FROZEN         DSKF_FROZEN     // volume has been frozen (but not freed)
#define VOLF_REMOUNTED      DSKF_REMOUNTED  // volume has been remounted
#define VOLF_RECYCLED       DSKF_RECYCLED   // volume has been recycled (like remounted but worse)
#define VOLF_READLOCKED         0x00000020  // volume has been locked for read access (can't be written by others)
#define VOLF_WRITELOCKED        0x00000040  // volume has been locked for write access (can't be read *or* written by others)
#define VOLF_LOCKED        (VOLF_READLOCKED | VOLF_WRITELOCKED)
#define VOLF_FORMATTING         0x00000080  // volume is being (re)formatted
#define VOLF_12BIT_FAT          0x00000100  // 12-bit FAT
#define VOLF_16BIT_FAT          0x00000200  // 16-bit FAT
#define VOLF_32BIT_FAT          0x00000400  // 32-bit FAT
#define VOLF_BACKUP_FAT         0x00000800  // one or more additional backup FATs exist
#define VOLF_MODDISKINFO        0x00001000  // volume DISK_INFO has been modified
#define VOLF_BUFFERED           0x00004000  // volume is buffered
#define VOLF_RETAIN             0x00008000  // volume should be retained across an unmount
#define VOLF_UNCERTAIN          0x00010000  // volume state is uncertain (do not assume unformatted!)
#define VOLF_DIRTY              0x00020000  // volume has dirty buffers pending
#define VOLF_CLOSING            0x00040000  // volume being closed, discard all open handles/dirty buffers
#define VOLF_READONLY       DSKF_READONLY   // volume is read-only (eg, write-protected)
#define VOLF_SCANNING           0x00100000  // volume is being scanned for inconsistencies
#define VOLF_MODIFIED           0x00200000  // volume has been modified (ie, 1 or more volume writes)
#define VOLF_LOGINIT            0x00400000  // volume has been "logging enabled"
#define VOLF_INITCOMPLETE       0x00800000  // volume has been fully initialized (no need to scan, etc)
#define VOLF_UPDATE_ACCESS      0x01000000  // per-volume version of FATFS_UPDATE_ACCESS
#define VOLF_DIRTY_WARN         0x02000000  // per-volume dirty data warning flag

#ifdef FAT32
#define VOLF_UNSUPPORTED    (VOLF_UNCERTAIN)
#else

⌨️ 快捷键说明

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