📄 fatfs.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
/*++
Module Name:
fatfs.h
Abstract:
This file contains internal definitions for the WINCE FAT file system
implementation.
Unlike FILESYS.EXE (WINCE's RAM-based object store), one of FATFS'
goals is to be as re-entrant as possible, so that while one thread is
blocked waiting for I/O, other threads can still perform FATFS operations.
The rationale for this is that I/O can, in terms of CPU cycles, take an
extremely long time, and many types of calls do not need to perform any
I/O to complete (usually because the data they need is in the buffer pool).
Revision History:
Compilation options:
BIG_BUFFERS - Ths enables a preferred buffer size equal to the
operating system's page size. Currently, the preferred buffer
size is equal to the sector size of the media being mounted (just
like real-mode MS-DOS). Note that if you enable this option, you
may uncover some bugs (it hasn't been tested a lot this way).
DEMAND_PAGING - This enables support for demand-paging and the
associated services (in v2.0, that was ReadFilePagein; post-v2.0,
they are ReadFileWithSeek and WriteFileWithSeek).
DEMAND_PAGING_DEADLOCKS - This enabled code to deal with some
dead-lock consequences if/when the kernel called our demand-paging
functions with a variety of critical sections held. Unfortunately,
there were still a number caveats we couldn't really address, but
post-v2.0, the kernel has stopped holding critical sections across
demand-paging requests, so this code should be moot now.
FAT32 - This enables support for FAT32 volumes.
PATH_CACHING - This enables path-caching code, which remembers up
to 4 recently-used paths per volume (see MAX_CACHE_PER_VOLUME). This
code makes a HUGE difference in certain scenarios (most notably our
tests that create and destroy large directory structures), and does
not significantly impact other scenarios.
SHELL_MESSAGE_NOTIFICATION - This enables RegisterFileSystemNotification.
The function is always present; this simply determines whether the
underlying code is present or if the function should always return FALSE.
v1.x was essentially built with SHELL_MESSAGE_NOTIFICATION defined.
SHELL_CALLBACK_NOTIFICATION - This enables RegisterFileSystemFunction.
The function is always present; this simply determines whether the
underlying code is present or if the function should always return FALSE.
SHELL_CALLBACK_NOTIFICATION is a new notification mechanism for v2.x.
--*/
#ifndef FATFS_H
#define FATFS_H
#if defined(_DEBUG) && !defined(DEBUG)
#define DEBUG
#endif
#ifndef INCLUDE_FATFS
#include <windows.h>
#include <tchar.h>
#if defined(UNDER_CE)
//
// Define CE compilation options here instead of in the 'sources' files,
// to insure component compilation consistency (aka CCC)
//
#define DEMAND_PAGING
#define FAT32
#define PATH_CACHING
#define SHELL_CALLBACK_NOTIFICATION
#define DISK_CACHING
#include <types.h>
#else
#include <sys\types.h>
#endif
#include <excpt.h>
#include <memory.h>
#include <diskio.h>
#include <fsdmgr.h>
#ifdef PVOLUME
#undef PVOLUME
#endif
DWORD GetDeviceKeys(LPCTSTR DevName, LPTSTR ActiveKey, LPDWORD lpActiveLen, LPTSTR DriverKey, LPDWORD lpDriverLen);
#define TEXTW(s) L##s
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
#define DBGPRINTF NKDbgPrintfW
#define DBGPRINTFW NKDbgPrintfW
#define DBGSCANF
#define DBGSCANFW
#ifndef CRLF
#define DBGTEXT(fmt) TEXT(fmt)
#define DBGTEXTW(fmt) TEXTW(fmt)
#else
#define DBGTEXT(fmt) TEXT(fmt) TEXT("\r")
#define DBGTEXTW(fmt) TEXTW(fmt) TEXTW("\r")
#endif
#define DBGTEXTNOCRLF(fmt) TEXT(fmt)
#define DBGTEXTWNOCRLF(fmt) TEXTW(fmt)
#define DEBUGMSGW DEBUGMSG
#ifndef ASSERT
#define ASSERT(c) DEBUGCHK(c)
#endif
#endif // !INCLUDE_FATFS
/* General-purpose macros (that really should be elsewhere)
*/
#ifdef UNDER_CE
#define GetSystemTimeAsFileTime(pft) { \
SYSTEMTIME st; \
GetSystemTime(&st); \
SystemTimeToFileTime(&st, pft); \
}
#endif
#define ENTER_BREAK_SCOPE switch(TRUE) { case TRUE:
#define LEAVE_BREAK_SCOPE }
#define INVALID_PTR ((PVOID)0xFFFFFFFF)
#ifdef DEBUG
#define DEBUGONLY(s) s
#define RETAILONLY(s)
#define VERIFYTRUE(c) DEBUGCHK(c)
#define VERIFYNULL(c) DEBUGCHK(!(c))
#else
#define DEBUGONLY(s)
#define RETAILONLY(s) s
#define VERIFYTRUE(c) c
#define VERIFYNULL(c) c
#endif
#if defined(XREF_CPP_FILE)
#define ERRFALSE(exp)
#elif !defined(ERRFALSE)
// This macro is used to trigger a compile error if exp is false.
// If exp is false, i.e. 0, then the array is declared with size 0, triggering a compile error.
// If exp is true, the array is declared correctly.
// There is no actual array however. The declaration is extern and the array is never actually referenced.
#define ERRFALSE(exp) extern char __ERRXX[(exp)!=0]
#endif
#ifdef DEBUG
#define DEBUGALLOC_CS 3 // arbitrary value for tracking InitializeCriticalSection "allocations"
#define DEBUGALLOC_EVENT 5 // arbitrary value for tracking CreateEvent "allocations"
#define DEBUGALLOC_API 7 // arbitrary value for tracking CreateAPISet "allocations"
#define DEBUGALLOC_HANDLE 11 // arbitrary value for tracking CreateFile "allocations"
#define DEBUGALLOC(cb) { \
EnterCriticalSection(&csAlloc); \
cbAlloc += (cb); \
DEBUGMSG(ZONE_MEM,(DBGTEXT("FATFS!alloc(0x%x)\n"), cb)); \
LeaveCriticalSection(&csAlloc); \
}
#define DEBUGFREE(cb) { \
EnterCriticalSection(&csAlloc); \
cbAlloc -= (cb); \
DEBUGMSG(ZONE_MEM,(DBGTEXT("FATFS!free(0x%x)\n"), cb)); \
LeaveCriticalSection(&csAlloc); \
}
#else
#define DEBUGALLOC(cb)
#define DEBUGFREE(cb)
#endif
/* Debug-zone stuff
*/
#ifdef DEBUG
#define ZONEID_INIT 0
#define ZONEID_ERRORS 1
#define ZONEID_SHELLMSGS 2
#define ZONEID_MEM 4
#define ZONEID_APIS 5
#define ZONEID_MSGS 6
#define ZONEID_STREAMS 7
#define ZONEID_BUFFERS 8
#define ZONEID_CLUSTERS 9
#define ZONEID_FATIO 10
#define ZONEID_DISKIO 11
#define ZONEID_LOGIO 12
#define ZONEID_READVERIFY 13
#define ZONEID_WRITEVERIFY 14
#define ZONEID_PROMPTS 15
#define ZONEMASK_INIT (1 << ZONEID_INIT)
#define ZONEMASK_ERRORS (1 << ZONEID_ERRORS)
#define ZONEMASK_SHELLMSGS (1 << ZONEID_SHELLMSGS)
#define ZONEMASK_MEM (1 << ZONEID_MEM)
#define ZONEMASK_APIS (1 << ZONEID_APIS)
#define ZONEMASK_MSGS (1 << ZONEID_MSGS)
#define ZONEMASK_STREAMS (1 << ZONEID_STREAMS)
#define ZONEMASK_BUFFERS (1 << ZONEID_BUFFERS)
#define ZONEMASK_CLUSTERS (1 << ZONEID_CLUSTERS)
#define ZONEMASK_FATIO (1 << ZONEID_FATIO)
#define ZONEMASK_DISKIO (1 << ZONEID_DISKIO)
#define ZONEMASK_LOGIO (1 << ZONEID_LOGIO)
#define ZONEMASK_READVERIFY (1 << ZONEID_READVERIFY)
#define ZONEMASK_WRITEVERIFY (1 << ZONEID_WRITEVERIFY)
#define ZONEMASK_PROMPTS (1 << ZONEID_PROMPTS)
#define ZONE_INIT DEBUGZONE(ZONEID_INIT)
#define ZONE_ERRORS DEBUGZONE(ZONEID_ERRORS)
#define ZONE_SHELLMSGS DEBUGZONE(ZONEID_SHELLMSGS)
#define ZONE_MEM DEBUGZONE(ZONEID_MEM)
#define ZONE_APIS DEBUGZONE(ZONEID_APIS)
#define ZONE_MSGS DEBUGZONE(ZONEID_MSGS)
#define ZONE_STREAMS DEBUGZONE(ZONEID_STREAMS)
#define ZONE_BUFFERS DEBUGZONE(ZONEID_BUFFERS)
#define ZONE_CLUSTERS DEBUGZONE(ZONEID_CLUSTERS)
#define ZONE_FATIO DEBUGZONE(ZONEID_FATIO)
#define ZONE_DISKIO DEBUGZONE(ZONEID_DISKIO)
#define ZONE_LOGIO DEBUGZONE(ZONEID_LOGIO)
#define ZONE_READVERIFY DEBUGZONE(ZONEID_READVERIFY)
#define ZONE_WRITEVERIFY DEBUGZONE(ZONEID_WRITEVERIFY)
#define ZONE_PROMPTS DEBUGZONE(ZONEID_PROMPTS)
#ifndef ZONEMASK_DEFAULT
#define ZONEMASK_DEFAULT (ZONEMASK_INIT|ZONEMASK_ERRORS|ZONEMASK_SHELLMSGS)
#endif
#define DEBUGBREAK(cond) if (cond) DebugBreak(); else
#define DEBUGMSGBREAK(cond,msg) if (cond) {DEBUGMSG(TRUE,msg); DebugBreak();} else
#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_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
#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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -