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

📄 fatfs.h

📁 FAT文件系统源代码
💻 H
📖 第 1 页 / 共 5 页
字号:
#define DEBUGMSGWBREAK(cond,msg) if (cond) {DEBUGMSGW(TRUE,msg); DebugBreak();} else

#else   // !DEBUG

#define DEBUGBREAK(cond)
#define DEBUGMSGBREAK(cond,msg)
#define DEBUGMSGWBREAK(cond,msg)

#define ZONE_INIT               FALSE
#define ZONE_ERRORS             FALSE
#define ZONE_SHELLMSGS          TRUE
#define ZONE_TFAT               FALSE
#define ZONE_MEM                FALSE
#define ZONE_APIS               FALSE
#define ZONE_MSGS               FALSE
#define ZONE_STREAMS            FALSE
#define ZONE_BUFFERS            FALSE
#define ZONE_CLUSTERS           FALSE
#define ZONE_FATIO              FALSE
#define ZONE_DISKIO             FALSE
#define ZONE_LOGIO              FALSE
#define ZONE_READVERIFY         FALSE
#define ZONE_WRITEVERIFY        FALSE
#define ZONE_PROMPTS            FALSE

#endif  // !DEBUG

#ifndef UNDER_CE
// NT ONLY
#define PREFAST_DEBUGCHK(a)
#define DEBUGCHK(a)
#define DEBUGMSG(a,b)
#define RETAILMSG(a,b)
#define DEBUGREGISTER(a)
#define VERIFY(a)           a
#endif 


#include <fatapi.h>


#define CloseAPIHandle(h)       CloseHandle(h)
#define CloseFileHandle(pfh)    CloseHandle(pfh->fh_h)
#define CloseFindHandle(psh)    CloseHandle(psh->sh_h)
#define FAT_CloseFileHandle(h)  CloseHandle(h)
#define FAT_CloseFindHandle(h)  CloseHandle(h)


#ifdef DEBUG
#ifdef UNDER_CE
#define OWNCRITICALSECTION(cs)  ((cs)->LockCount > 0 && (DWORD)(cs)->OwnerThread == GetCurrentThreadId())
#else
#define OWNCRITICALSECTION(cs)  TRUE    #endif
#else
#define OWNCRITICALSECTION(cs)  TRUE
#endif


typedef struct _DLINK DLINK, *PDLINK;
typedef struct _BUF BUF, *PBUF;
typedef struct _DSK DSK, *PDSK;
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>

#ifdef FATUI
#include <fatui.h>
#endif

#include "fatfmt.h"
#include "dosbpb.h"
#include "bootsec.h"
#include "streamrun.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 _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_FORCE_WRITETHROUGH    0x00000020  // Force fat to be always writethrough
#define FATFS_DISABLE_AUTOFORMAT    0x00000040  // disable automatic formatting of unformatted volumes

#define FATFS_WFWS_NOWRITETHRU      0x00010000  // disable writethrough on WriteFileWithSeek API, improve memory-mapped file performance
#define FATFS_DISABLE_FORMAT        0x00020000  // disable format
#define FATFS_TRANS_DATA            0x00040000  // transact data on a write (i.e. clone cluster on every write)
#define FATFS_TFAT_NONATOMIC_SECTOR 0x00080000  // Use cluster 1 entry in FAT table for TFAT transaction, since sector writes are non-atomic.
												// By default, TFAT uses the NOF field of the boot sector
#define FATFS_DISABLE_TFAT_REDIR    0x00100000  // Indicates to disable redirect the root directory to another hidden director
                                                                                   // for FAT12 or 16, since root dir isn't transacted in those cases
#define FATFS_TFAT_ALWAYS           0x00200000  // Always mark transaction status, even only one sector in FAT is changed
#define FATFS_FORCE_TFAT            0x00400000  // Force TFAT transactioning even if volume isn't formatted as TFAT
#define FATFS_LFN_EXTENDED          0x00800000  // Generate LFN entries for extended characters always
#define FATFS_TFAT_DISABLE_MOVEDIR  0x01000000  // Disable MoveFile on a directory for TFAT because it isn't transaction-safe

#ifdef TFAT
#define FATFS_REGISTRY_FLAGS        (FATFS_UPDATE_ACCESS |      \
                                     FATFS_DISABLE_LOG |        \
                                     FATFS_DISABLE_AUTOSCAN |   \
                                     FATFS_VERIFY_WRITES |      \
                                     FATFS_ENABLE_BACKUP_FAT |  \
                                     FATFS_FORCE_WRITETHROUGH | \
                                     FATFS_DISABLE_AUTOFORMAT | \
                                     FATFS_DISABLE_FORMAT | \
                                     FATFS_TFAT_ALWAYS)
#else
#define FATFS_REGISTRY_FLAGS        (FATFS_UPDATE_ACCESS |      \
                                     FATFS_DISABLE_LOG |        \
                                     FATFS_DISABLE_AUTOSCAN |   \
                                     FATFS_VERIFY_WRITES |      \
                                     FATFS_ENABLE_BACKUP_FAT |  \
                                     FATFS_FORCE_WRITETHROUGH | \
                                     FATFS_DISABLE_AUTOFORMAT | \
                                     FATFS_TFAT_ALWAYS)
#endif


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

// values for b_flags:
#define BUF_UNCERTAIN           0x02    // buffer is in transition (ie, is being read)
#define BUF_BUSY                0x04    #define BUF_INVALID            0x08
#define BUF_FREE                0x10    // buffer is free to assign
#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
    DWORD       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)
#define DSKF_SENDDELETE         0x00100000  // disk driver needs to be sent IOCTL_DISK_DELETE_SECTOR

// 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
    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
};


/*  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    50     // max cache entries per volume

#define FAT_CACHE_SECTORS       2       // number of cache FAT sectors

// 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)

⌨️ 快捷键说明

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