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

📄 rtfiles.h

📁 最新MTK手机软件源码
💻 H
📖 第 1 页 / 共 4 页
字号:
/************************************************************************/

#ifndef RTTDLL
   #ifdef RTT32DLL
      #if defined(_MSC_VER)
         #define RTTDLL __declspec(dllimport)
         #define RTTDDL __declspec(dllimport)
      #elif defined(__BORLANDC__)
         #define RTTDLL
         #define RTTDDL extern __import
      #else // importing needs no special declaration or is not supported
         #define RTTDLL
         #define RTTDDL extern
      #endif
   #else
      #define RTTDLL
      #define RTTDDL extern
   #endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

//#define RTFILE_VER 404

#if defined(_WIN32) || defined (WIN32) || defined (__FLAT__)
   #define RTF_32_BIT
   #define RTFAPI __cdecl
#else
   /* #define RTFAPI _cdecl */
   #define RTFAPI
#endif

#if !defined(WIN32)
#undef  _MSC_VER
#define min(X,Y) ((X) < (Y)) ? (X) : (Y)
#endif

#define LSB(FileName, i) (FileName[2*i])
#define MSB(FileName, i) (FileName[2*i+1])
#define isASCII(FileName, i) ( !((BYTE) MSB(FileName, i)) && (LSB(FileName, i)<0x80) )
#define toASCII(FileName, i) ((BYTE) LSB(FileName, i))
#define setASCII(FileName, i, ch) (LSB(FileName, i)=ch); (MSB(FileName,i)=0)
#define compASCII(FileName, i, c) (isASCII(FileName, i) && (toASCII(FileName, i) == c))


#define memset    kal_mem_set
#define memcpy    kal_mem_cpy

// for one byte alignment, pre-compile option in different environment
/* add GEN_FOR_PC for cgen compile error, Karen Hsu, 2004/02/09 */
#if defined(_WIN32) || defined(WIN32) || defined(GEN_FOR_PC)
#define ONE_BYTE_ALIGN_ADS
#else
#define ONE_BYTE_ALIGN_ADS   __packed
#endif

//#define RTF_MAX_FILES 32

#define RTF_MIN_BUFFER_SIZE       512
#define RTF_MAX_BUFFER_SIZE     32768
#define RTF_MAX_PATH              520   // 260x2=520

// error codes
#define RTF_NO_ERROR                      0
#define RTF_ERROR_RESERVED                -1
#define RTF_PARAM_ERROR                   -2
#define RTF_INVALID_FILENAME              -3
#define RTF_DRIVE_NOT_FOUND               -4
#define RTF_TOO_MANY_FILES                -5
#define RTF_NO_MORE_FILES                 -6
#define RTF_WRONG_MEDIA                   -7
#define RTF_INVALID_FILE_SYSTEM           -8
#define RTF_FILE_NOT_FOUND                -9
#define RTF_INVALID_FILE_HANDLE           -10
#define RTF_UNSUPPORTED_DEVICE            -11
#define RTF_UNSUPPORTED_DRIVER_FUNCTION   -12
#define RTF_CORRUPTED_PARTITION_TABLE     -13
#define RTF_TOO_MANY_DRIVES               -14
#define RTF_INVALID_FILE_POS              -15
#define RTF_ACCESS_DENIED                 -16
#define RTF_STRING_BUFFER_TOO_SMALL       -17
#define RTF_GENERAL_FAILURE               -18
#define RTF_PATH_NOT_FOUND                -19
#define RTF_FAT_ALLOC_ERROR               -20
#define RTF_ROOT_DIR_FULL                 -21
#define RTF_DISK_FULL                     -22
#define RTF_TIMEOUT                       -23
#define RTF_BAD_SECTOR                    -24
#define RTF_DATA_ERROR                    -25
#define RTF_MEDIA_CHANGED                 -26
#define RTF_SECTOR_NOT_FOUND              -27
#define RTF_ADDRESS_MARK_NOT_FOUND        -28
#define RTF_DRIVE_NOT_READY               -29
#define RTF_WRITE_PROTECTION              -30
#define RTF_DMA_OVERRUN                   -31
#define RTF_CRC_ERROR                     -32
#define RTF_DEVICE_RESOURCE_ERROR         -33
#define RTF_INVALID_SECTOR_SIZE           -34
#define RTF_OUT_OF_BUFFERS                -35
#define RTF_FILE_EXISTS                   -36
#define RTF_LONG_FILE_POS                 -37
#define RTF_FILE_TOO_LARGE                -38
#define RTF_BAD_DIR_ENTRY                 -39
#define RTF_ATTR_CONFLICT                 -40 // Recoverable support: Can't specify FS_PROTECTION_MODE and FS_NONBLOCK_MODE
#define RTF_CHECKDISK_RETRY               -41 // Recoverable support: used for CROSSLINK
#define RTF_LACK_OF_PROTECTION_SPACE      -42 // UN-USED

// add for non_blocking write and protection
typedef enum{
  FS_BLOCK_ENUM,
  FS_NON_BLOCK_ENUM,
  FS_BLOCK_PROTECTION_ENUM
}fs_block_type_enum;// file attributes

// file attributes
#define RTF_ATTR_READ_ONLY      0x01
#define RTF_ATTR_HIDDEN         0x02
#define RTF_ATTR_SYSTEM         0x04
#define RTF_ATTR_VOLUME         0x08
#define RTF_ATTR_DIR            0x10
#define RTF_ATTR_ARCHIVE        0x20
#define RTF_LONGNAME_ATTR       (RTF_ATTR_READ_ONLY | RTF_ATTR_HIDDEN | RTF_ATTR_SYSTEM | RTF_ATTR_VOLUME)
#define RTF_ATTR_ANY            0x3F

// file open flags
// 0x000000XX - attributes
// 0x0000XX00 - sharing
// 0x000X0000 - creation
// 0xXX000000 - caching
// 0x00X00000 - RTFiles internal use

#define RTF_READ_WRITE          0x00000000L
#define RTF_READ_ONLY           0x00000100L
#define RTF_OPEN_SHARED         0x00000200L
#define RTF_OPEN_NO_DIR         0x00000400L
#define RTF_OPEN_DIR            0x00000800L

#define RTF_CREATE              0x00010000L // create if it does not exist
#define RTF_CREATE_ALWAYS       0x00020000L // always create

// defaults:
// DIR and FAT is written at file close
// buffers are written when file pointer leaves the sector
#define RTF_COMMITTED           0x01000000L // commit all buffers after every write
#define RTF_CACHE_DATA          0x02000000L // do not discard data buffers
#define RTF_LAZY_DATA           0x04000000L // do not commit buffer when file pointer leaves sector
// add a new flags for non_blocking write for flash driver
#define FS_NONBLOCK_MODE        0x10000000L // writing while encounter flash erase return immediately
/* add a new flags for write protection for flash driver.
  *  Note that, currently, we protect a write range of 2 or less sectors.
  *  Originally, only NVRAM files are meant to be protected.
  */
#define FS_PROTECTION_MODE      0x20000000L // Keep old versioned sectors for recovery on unexpected poweroff.


// note that RTF_DEVICE_LAZY_WRITE is a drive option and applies to all files

// file seek options
#define RTF_FILE_BEGIN          0
#define RTF_FILE_CURRENT        1
#define RTF_FILE_END            2

// format flags, low 8 bits are reserved for media specification
// Use RTF_FPLY_DRIVE_360/1200/720/1440/2880 to force a particular medium
// Default is the highest supported medium

#define RTF_FMT_SINGLE_FAT      0x00000100L
#define RTF_FMT_FORCE_LOW_LEVEL 0x00000200L
#define RTF_FMT_NO_LOW_LEVEL    0x00000400L
#define RTF_FMT_GET_DATA_SECTOR 0x00000800L
#define RTF_FMT_FAT_12          0x00001000L
#define RTF_FMT_FAT_16          0x00002000L
#define RTF_FMT_FAT_32          0x00004000L
#define RTF_FMT_NO_FAT_32       0x00008000L

#define RTF_FMT_PGS_LOW_FMT      1
#define RTF_FMT_PGS_HIGH_FMT     2
#define RTF_FMT_PGS_CLEAR_MEDIUM 5
#define RTF_FMT_PGS_DONE        -1

// check disk flags
#define RTF_CHK_FAT_MISMATCH              0x00000001L
#define RTF_CHK_FAT_MISMATCH_1            0x00000002L
#define RTF_CHK_FAT_MISMATCH_2            0x00000003L
#define RTF_CHK_FAT_MISMATCH_MASK         0x00000003L

#define RTF_CHK_INVALID_DIR               0x00000004L
#define RTF_CHK_INVALID_DIR_DELETE        0x00000008L
#define RTF_CHK_INVALID_DIR_MASK          0x0000000CL

#define RTF_CHK_INVALID_CLUSTER           0x00000010L
#define RTF_CHK_INVALID_CLUSTER_TRUNC     0x00000020L
#define RTF_CHK_INVALID_CLUSTER_DELETE    0x00000030L
#define RTF_CHK_INVALID_CLUSTER_MASK      0x00000030L

#define RTF_CHK_CROSSLINK                 0x00000040L
#define RTF_CHK_CROSSLINK_TRUNC           0x00000080L
#define RTF_CHK_CROSSLINK_DELETE          0x000000C0L
#define RTF_CHK_CROSSLINK_MASK            0x000000C0L

#define RTF_CHK_FILESIZE_SMALL            0x00000100L     // DIR.FileSize < FAT.FileSize
#define RTF_CHK_FILESIZE_SMALL_TRUNC      0x00000200L     // truncate FAT chain
#define RTF_CHK_FILESIZE_SMALL_DELETE     0x00000300L
#define RTF_CHK_FILESIZE_SMALL_MASK       0x00000300L

#define RTF_CHK_FILESIZE_LARGE            0x00000400L     // DIR.FileSize > FAT.FileSize
#define RTF_CHK_FILESIZE_LARGE_TRUNC      0x00000800L     // truncate DIR.FileSize
#define RTF_CHK_FILESIZE_LARGE_DELETE     0x00000C00L
#define RTF_CHK_FILESIZE_LARGE_MASK       0x00000C00L

#define RTF_CHK_LOST_CLUSTER              0x00001000L
#define RTF_CHK_LOST_CLUSTER_FREE         0x00002000L
#define RTF_CHK_LOST_CLUSTER_MASK         0x00003000L

#define RTF_CHK_LONG_FILENAME             0x00004000L
#define RTF_CHK_LONG_FILENAME_REMOVE      0x00008000L
#define RTF_CHK_LONG_FILENAME_DELETE      0x0000C000L
#define RTF_CHK_LONG_FILENAME_MASK        0x0000C000L

#define RTF_CHK_VERBOSE                   0x80000000L

// Flags for RTFCompactDir

#define RTF_CMPCT_READ_ONLY               0x00000001
#define RTF_CMPCT_RECURSIVE               0x00000002

// Flags for RTFDiskInfoEx

#define RTF_DI_BASIC_INFO                 0x00000001L
#define RTF_DI_FREE_SPACE                 0x00000002L  // return FreeClusters
#define RTF_DI_FAT_STATISTICS             0x00000004L  // return BadClusters, Files, FileChains, FreeChains, LargestFreeChain

// device types

#define RTF_DEVICE_UNKNOWN      0
#define RTF_DEVICE_FLOPPY       1
#define RTF_DEVICE_FDISK        2

// device flags, use only lower 16 bits

#define RTF_DEVICE_SINGLE_FAT       0x0001
#define RTF_DEVICE_LAZY_WRITE       0x0002  // update FAT/DIR/data buffers at last file close of drive
#define RTF_DEVICE_MOUNT_CONTIGUOUS 0x0004
#define RTF_DEVICE_REMOVABLE        0x0008
#define RTF_DEVICE_NO_MEDIA         0x0010
#define RTF_DEVICE_NEW_LOCK         0x0020

// device driver flags, may only use upper 16 bits

// floppy driver flags
#define RTF_CUSTOM_TIMER        0x80000000L
#define RTF_MOTOR_TIMEOUT_1     0x40000000L
#define RTF_MOTOR_TIMEOUT_5     0x20000000L
#define RTF_MOTOR_TIMEOUT_10    0x10000000L
#define RTF_READ_AHEAD_0        0x01000000L
#define RTF_READ_AHEAD_2        0x02000000L
#define RTF_READ_AHEAD_8        0x03000000L
#define RTF_READ_AHEAD_16       0x04000000L

// IDE driver flags
#define RTF_NO_CMOS_RAM         0x80000000L
#define RTF_32_BIT_IO           0x40000000L
#define RTF_16_BIT_IO           0x20000000L
#define RTF_NO_MULTI_SECTOR     0x10000000L
#define RTF_NO_WRITE_CACHE      0x08000000L
#define RTF_CONTIGUOUS_IO       0x04000000L

// Flash driver flags
#define RTF_FLASH_NO_SECTOR_MAP 0x80000000L
#define RTF_FLASH_NO_LOW_FMT    0x40000000L
#define RTF_FLASH_NO_HIGH_FMT   0x20000000L

// a few data types

#ifndef _WINDOWS_
/* Patch for AMNT double define warning, Karen, 2004/01/08 */
#ifndef __AMNT__
typedef unsigned int  DWORD;
#endif
typedef unsigned short WORD;
typedef unsigned int   UINT;
typedef unsigned char  BYTE;
typedef void * HANDLE;
#endif

typedef int   RTFHANDLE;
typedef DWORD RTFSector;
typedef DWORD RTFCluster;

#if defined(WIN32)
#pragma pack(1)
#endif
typedef ONE_BYTE_ALIGN_ADS struct {
   BYTE  BootIndicator,       // 0x80 for bootable, 0 otherwise
         StartHead,           // 0 based
         StartSector,         // 1 based, bits 0..5, bits 6,7 are bits 8,9 of StartTrack
         StartTrack,          // 0 based, bits 0..7
         OSType,              // FAT-12: 1, FAT-16: 4, 6, 14, FAT-32: 11, 12
         EndHead,             // see StartHead
         EndSector,           // see StartSector
         EndTrack;            // see StartTrack
   RTFSector RelativeSector,  // offset to first sector of partition data
                              // for primary partitions, this is the absolute
                              // LBA of the boot sector
                              // for logical drives, the boot sector is at ExtendedPartition.RelativeSector + Drive.RelativeSector
         Sectors;             // number of sectors in partition
} RTFPartitionRecord; /* ! Must SYNC ! */

typedef ONE_BYTE_ALIGN_ADS struct {
   unsigned int Second2:5;
   unsigned int Minute:6;
   unsigned int Hour:5;
   unsigned int Day:5;
   unsigned int Month:4;
   unsigned int Year1980:7;
} RTFDOSDateTime; /* ! Must SYNC ! */

typedef ONE_BYTE_ALIGN_ADS struct {
   char           FileName[8];
   char           Extension[3];
   BYTE           Attributes;
   BYTE           NTReserved;
   BYTE           CreateTimeTenthSecond; // range 0..199, not used
   RTFDOSDateTime CreateDateTime;
   WORD           LastAccessDate;        // not used
   WORD           FirstClusterHi;        // FAT-32 only
   RTFDOSDateTime DateTime;              // of last modification
   WORD           FirstCluster;
   DWORD          FileSize;
} RTFDOSDirEntry; /* ! Must SYNC ! */

// end of one byte alignment for structure definitions
#if defined(WIN32)
#pragma pack()
#endif

typedef struct {
   const RTFDOSDirEntry * DirEntry;
   DWORD                  FilePos;
   DWORD                  AllocatedSize;
   DWORD                  ClusterChains;
   DWORD                  VolumeSerialNumber;
   const char           * FullName;
} RTFFileInfo; /* ! Must SYNC ! */

typedef struct {
   char             Label[24];
   char             DriveLetter;
   /* Add for memory card write protection, Karen Hsu, 2004/04/14, MOD START */
   BYTE             WriteProtect;
   char             Reserved[2];
   //char             Reserved[3];
   /* Add for memory card write protection, Karen Hsu, 2004/04/14, MOD END */
   DWORD            SerialNumber;
   DWORD            FirstPhysicalSector;
   UINT             FATType;            // 12 or 16
   UINT             FATCount;
   UINT             MaxDirEntries;
   UINT             BytesPerSector;
   UINT             SectorsPerCluster;
   RTFCluster       TotalClusters;
   RTFCluster       BadClusters;
   RTFCluster       FreeClusters;
   DWORD            Files;
   DWORD            FileChains;
   DWORD            FreeChains;
   RTFCluster       LargestFreeChain;
} RTFDiskInfo; /* ! Must SYNC ! */

typedef struct {
   RTFPartitionRecord Partition;
   RTFSector PartitionSector;      // absolute sector containing the partition table (0 for primary partitions and floppies)
   int       PhysicalDiskIndex;    // nth physical hard disk (0 based, -1 for floppies)
   UINT      BytesPerSector;       // usually 512
   BYTE      MediaDescriptor;      // F8 for hard disks, 0 for unknown
   BYTE      Reserved;             // for alignment
   short     DeviceListIndex;      // nth entry in the RTFiles device list (0 based)
} RTFPartitionInfo;

typedef struct {
   DWORD TotalBuffers,             // number of installed sector buffers
         ValidBuffers,             // buffers currently holding valid data
         DirtyBuffers,             // buffers currently holding unflushed data
         MaxDirtyBuffers,          // max number of dirty buffers

         PhysicalBufferReads,      // number of physical buffer reads
         CachedBufferReads,        // number of times data was in the cache
         BuffersDiscarded,         // number of times a valid buffer was discared to make room for a new buffer
         CacheHits,                // 100 * CachedBufferReads / (PhysicalBufferReads+CachedBufferReads)

         PhysicalBufferWrites,     // buffer writes to disk
         CachedBufferWrites,       // updates of a dirty buffer
         AsynchBufferFlushs,       // buffers written in a differen RTFiles API call than the first update to that buffer

         UnbufferedReads,          // sectors read bypassing the buffer cache
         UnbufferedWrites;         // sectors written bypassing the buffer cache
} RTFBufferStatistic;

typedef enum { RTFRetry, RTFFail } RTFErrorAction;
typedef RTFErrorAction (RTFAPI * RTFCriticalErrorHandler)(WCHAR Drive, DWORD SerialNumber, int ErrorCode);

typedef void (RTFAPI * RTFFormatCallback)(const char * DeviceName, int Action, DWORD Total, DWORD Completed);

typedef DWORD (RTFAPI * RTFCheckDiskCallback)(DWORD Flag,

⌨️ 快捷键说明

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