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

📄 fs.h

📁 Latest ucFS v.3.10d PC Windows Evaluation Ed., provided with free Flash driver
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                            uC/FS
*
*             (c) Copyright 2001 - 2007, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

**** 礐/FS file system for embedded applications ****
礐/FS is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : FS.h
Purpose     : Define global functions and types to be used by an
              application using the file system.

              This file needs to be included by any modul using the
              file system.
---------------------------END-OF-HEADER------------------------------
*/

#ifndef _FS_H_               // Avoid recursive and multiple inclusion
#define _FS_H_


/*********************************************************************
*
*             #include Section
*
**********************************************************************
*/

#include "FS_ConfDefaults.h"        /* FS Configuration */
#include "FS_Types.h"
#include "FS_Storage.h"
#include "FS_Dev.h"

#if defined(__cplusplus)
extern "C" {     /* Make sure we have C-declarations in C++ programs */
#endif

/*********************************************************************
*
*             #define constants
*
**********************************************************************
*/

/* File system version */
#define FS_VERSION                31004UL


#define FS_ERROR_ALLOC    (1)

/* Global error codes */
#define FS_ERR_OK                 0
#define FS_ERR_EOF                -1
#define FS_ERR_DISKFULL           -2
#define FS_ERR_INVALIDPAR         -3
#define FS_ERR_CMDNOTSUPPORTED    -4
#define FS_ERR_WRITEONLY          -5
#define FS_ERR_READONLY           -6
#define FS_ERR_READERROR          -7
#define FS_ERR_WRITEERROR         -8

/* Global constants*/
/* File Positions */
#define FS_SEEK_CUR               1
#define FS_SEEK_END               2
#define FS_SEEK_SET               0

#define FS_FILE_CURRENT           FS_SEEK_CUR
#define FS_FILE_END               FS_SEEK_END
#define FS_FILE_BEGIN             FS_SEEK_SET

/*********************************************************************
*
*       I/O commands for driver
*/
#define FS_CMD_REQUIRES_FORMAT        1003
#define FS_CMD_GET_DEVINFO            1004
#define FS_CMD_FORMAT_LOW_LEVEL       1005            /* Used internally by FS_FormatLow() to command the driver to perform low-level format */
#define FS_CMD_FREE_SECTORS           1006            /* Used internally: Allows the FS layer to inform driver about free sectors */
#define FS_CMD_SET_DELAY              1007            /* Used in the simulation to simulate a slow device with RAM driver */

#define FS_CMD_UNMOUNT                1008            /* Used internally by FS_STORAGE_Unmount() to inform the driver. Driver invalidates caches and all other information about medium. */
#define FS_CMD_UNMOUNT_FORCED         1009            /* Used internally by FS_STORAGE_UnmountForced() to inform the driver about an unforced remove of the device. */
                                                      /* Driver invalidates caches and all other information about medium. */
#define FS_CMD_SYNC                   1010            /* Tells the driver to clean caches. Typically, all dirty sectors are written */
#define FS_CMD_UNMOUNT_VOLUME         FS_CMD_UNMOUNT  // Obsolete: FS_CMD_UNMOUNT shall be used instead of FS_CMD_UNMOUNT_VOLUME.


/*********************************************************************
*
*       CACHE Commands (internal)
*/
#define FS_CMD_CACHE_SET_MODE     6000L
#define FS_CMD_CACHE_CLEAN        6001L   /* Write out all dirty sectors */
#define FS_CMD_CACHE_SET_QUOTA    6002L
#define FS_CMD_CACHE_FREE_SECTORS 6003L
#define FS_CMD_CACHE_INVALIDATE   6004L   /* Invalidate all sectors in cache */

/*********************************************************************
*
*       Directory entry attribute definitions
*/
#define FS_ATTR_READ_ONLY    0x01
#define FS_ATTR_HIDDEN       0x02
#define FS_ATTR_SYSTEM       0x04
#define FS_ATTR_ARCHIVE      0x20
#define FS_ATTR_DIRECTORY    0x10


/*********************************************************************
*
*       Directory entry attribute definitions
*/
#define FS_FILETIME_CREATE     0
#define FS_FILETIME_ACCESS     1
#define FS_FILETIME_MODIFY     2

/*********************************************************************
*
*       Media states
*/
#define FS_MEDIA_NOT_PRESENT       -1
#define FS_MEDIA_IS_PRESENT         0
#define FS_MEDIA_STATE_UNKNOWN      2

/*********************************************************************
*
*       Volume mount flags
*/
#define FS_MOUNT_R                  1
#define FS_MOUNT_RW                 3

/*********************************************************************
*
*       CheckDisk error codes
*/
enum {
  FS_ERRCODE_0FILE = 0x100,
  FS_ERRCODE_SHORTEN_CLUSTER,
  FS_ERRCODE_CROSSLINKED_CLUSTER,
  FS_ERRCODE_FEW_CLUSTER,
  FS_ERRCODE_CLUSTER_UNUSED,
  FS_ERRCODE_CLUSTER_NOT_EOC,
  FS_ERRCODE_INVALID_CLUSTER,
  FS_ERRCODE_INVALID_DIRECTORY_ENTRY
};

/*********************************************************************
*
*       Global data types
*
**********************************************************************
*/

typedef int  FS_QUERY_F_TYPE(int ErrCode, ...);
typedef void FS_BUSY_LED_CALLBACK(U8 OnOff);
typedef int  FS_MEMORY_IS_ACCESSIBLE_CALLBACK(void * p, U32 NumBytes);

struct FS_DIRENT {
  char  DirName[FS_MAX_PATH];
  U8    Attributes;
  U32   Size;
  U32   TimeStamp;
};

typedef struct {
  U32 Cluster;                    /* Cluster of current sector */
  U32 FirstCluster;
  U32 DirEntryIndex;              /* Directory entry index (first directory entry has index 0 */
  U32 ClusterIndex;
} FS_DIR_POS;

typedef struct {
  FS_DIR_POS  DirPos;             /* current position in file     */
  U16         DirEntryIndex;
  U32         FirstCluster;
  FS_VOLUME * pVolume;
  I16         error;              /* error code                   */
  U8          InUse;              /* handle in use mark           */
} FS__DIR;

typedef struct {
  U8     Attributes;
  U32    CreationTime;
  U32    LastAccessTime;
  U32    LastWriteTime;
  U32    FileSize;
  char * sFileName;
  int    SizeofFileName;
} FS_DIRENTRY_INFO;

typedef struct {
  U8     Attributes;
  U32    CreationTime;
  U32    LastAccessTime;
  U32    LastWriteTime;
  U32    FileSize;
  char * sFileName;
  // Private elements. Not be used by the application
  int SizeofFileName;
  FS__DIR Dir;
} FS_FIND_DATA;

typedef struct {
  U32 NumTotalClusters;
  U32 NumFreeClusters;
  U16 SectorsPerCluster;
  U16 BytesPerSector;
} FS_DISK_INFO;

 typedef struct {
  U16        SectorsPerCluster;
  U16        NumRootDirEntries;    /* Proposed, actual value depends on FATType */
  FS_DEV_INFO * pDevInfo;
} FS_FORMAT_INFO;

typedef struct {
  U16           SectorsPerCluster;
  U16           NumRootDirEntries;    /* Proposed, actual value depends on FATType */
  U16           NumReservedSectors;
  U8            UpdatePartition;
  FS_DEV_INFO * pDevInfo;
} FS_FORMAT_INFO_EX;

typedef struct {
  U16 Year;
  U16 Month;
  U16 Day;
  U16 Hour;
  U16 Minute;
  U16 Second;
} FS_FILETIME;

/*********************************************************************
*
*             Non blocking (backgrounded) file I/O functions
*/
/* Information for background data */
typedef struct FS_BG_DATA {
  struct FS_BG_DATA * pNext;
  U32                 NumBytes;
  U32                 NumBytesRem;         /* Remaining bytes to transfer */
  void              * pData;
  FS_FILE           * pFile;
  U8                  Operation;
  void (*pfOnCompletion) (void * p);   /* Optional completion routine */
  void              * pCompletionData;     /* Optional data for completion routine */
  char                IsCompleted;
} FS_BG_DATA;

void FS_Daemon(void);
void FS_FReadNonBlock (void       * pData,
                       U32          NumBytes,
                       FS_FILE    * pFile,
                       FS_BG_DATA * pBGData,                    /* User supplied management block */
                       void (*pfOnCompletion) (void * p),   /* Optional completion routine */
                       void * pCompletionData                   /* Optional data for completion routine */
                      );
void FS_FWriteNonBlock(const void * pData,
                       U32          NumBytes,
                       FS_FILE    * pFile,
                       FS_BG_DATA * pBGData,                    /* User supplied management block */
                       void (*pfOnCompletion) (void * p),   /* Optional completion routine */
                       void * pCompletionData                   /* Optional data for completion routine */
                       );
char FS_IsCompleted(FS_BG_DATA * pBGData);

/*********************************************************************
*
*       Global function prototypes
*
**********************************************************************
*/

/*********************************************************************
*
*       "Standard" file I/O functions
*/
FS_FILE *        FS_FOpen (const char * pFileName, const char * pMode);
int              FS_FClose(FS_FILE    * pFile);
U32              FS_FRead (      void * pData, U32 Size, U32 N, FS_FILE * pFile);
U32              FS_FWrite(const void * pData, U32 Size, U32 N, FS_FILE * pFile);

/*********************************************************************
*
*       Non-standard file I/O functions
*/
U32           FS_Read (FS_FILE * pFile,       void * pData, U32 NumBytes);
U32           FS_Write(FS_FILE * pFile, const void * pData, U32 NumBytes);

/*********************************************************************
*
*       File pointer handling
*/
int              FS_FSeek       (FS_FILE * pFile, I32 Offset,         int Origin);
int              FS_SetEndOfFile(FS_FILE * pFile);
int              FS_SetFilePos  (FS_FILE * pFile, I32 DistanceToMove, int MoveMethod);
I32              FS_GetFilePos  (FS_FILE * pFile);
I32              FS_FTell       (FS_FILE * pFile);

/*********************************************************************
*
*       I/O error handling
*/
int              FS_FEof        (FS_FILE * pFile);
I16              FS_FError      (FS_FILE * pFile);
void             FS_ClearErr    (FS_FILE * pFile);
const char *     FS_ErrorNo2Text(int       ErrCode);

/*********************************************************************
*
*       File functions
*/
int              FS_CopyFile   (const char * sSource,       const char * sDest);
U32              FS_GetFileSize(FS_FILE    * pFile);
int              FS_Move       (const char * sExistingName, const char * sNewName);
int              FS_Remove     (const char * pFileName);
int              FS_Rename     (const char * sOldName,      const char * sNewName);
int              FS_Truncate   (FS_FILE    * pFile,         U32          NewSize);
int              FS_Verify     (FS_FILE    * pFile,         const void * pData, U32 NumBytes);

/*********************************************************************
*
*       IOCTL
*/
int              FS_IoCtl(const char *pDevName, I32 Cmd, I32 Aux, void *pBuffer);

/*********************************************************************
*
*       Volume related functions
*/
int              FS_GetVolumeName     (int Index, char * pBuffer, int MaxSize);
U32              FS_GetVolumeSize     (const char * sVolume);
U32              FS_GetVolumeFreeSpace(const char * sVolume);
int              FS_GetNumVolumes     (void);
FS_VOLUME *      FS_AddDevice         (const FS_DEVICE_TYPE * pDevType);
void             FS_Unmount           (const char * sVolume);
int              FS_Mount             (const char * sVolName);
int              FS_MountEx           (const char * sVolume, U8 MountType);
int              FS_GetVolumeInfo     (const char * sVolume, FS_DISK_INFO * pInfo);
int              FS_IsVolumeMounted   (const char * sVolumeName);
int              FS_GetVolumeLabel    (const char * sVolume, char * pVolumeLabel, unsigned VolumeLabelSize);
int              FS_SetVolumeLabel    (const char * sVolume, const char * pVolumeLabel);
void             FS_CleanVolume       (const char * sVolume);
int              FS_IsLLFormatted     (const char * sVolume);
int              FS_IsHLFormatted     (const char * sVolume);
int              FS_FormatLLIfRequired(const char * sVolume);
int              FS_CreateJournal     (const char * sVolume, U32 NumBytes);
void             FS_UnmountForced     (const char * sVolume);
void             FS_SetAutoMount      (const char * sVolume, U8 MountType);
void             FS_UnmountLL         (const char * sVolume);
int              FS_GetVolumeStatus   (const char * sVolume);
FS_VOLUME *      FS_FindVolume        (const char * sVolume);

/*********************************************************************
*
*       FS_Attrib
*/
int              FS_SetFileAttributes(const char * pName, U8 Attributes);
U8               FS_GetFileAttributes(const char * pName);

/*********************************************************************
*
*       FS_Time
*/
void             FS_FileTimeToTimeStamp(const FS_FILETIME * pFileTime, U32 *         pTimeStamp);
int              FS_GetFileTime        (const char *        pName,     U32 *         pTimeStamp);
int              FS_GetFileTimeEx      (const char *        pName,     U32 *         pTimeStamp, int Index);
int              FS_SetFileTime        (const char *        pName,     U32            TimeStamp);
int              FS_SetFileTimeEx      (const char *        pName,     U32            TimeStamp, int Index);
void             FS_TimeStampToFileTime(U32                 TimeStamp, FS_FILETIME * pFileTime);

⌨️ 快捷键说明

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