博客网 >

an implementation of virtual file system
作者:分类:默认分类标签:

Introduction to virtual file system

Liming Liu(USTB)

刘黎明(北京科技大学)

 

1 Description of Vfs virtual file system

Vfs virtual file system define the interface between ReadEngine/WriteEngine(even app) and the file system.

The Vfs virtual file system including five classes: VfsFileSystemRead, VfsFileSystemWrite, VfsFileInstance, VfsFileDescriptor, VfsFileEntry.

The Vfs virtual file system give the implementation of VfsFileInstance, VfsFileDescriptor, VfsFileEntry.

VfsFileSystemRead and VfsFileSystemWrite are virtual base class, they will be inherited by special file system, such as udf.

2 Architecture of Vfs virtual file system

Figure 1 describe the Architecture of Vfs virtual file system.

Figure 1

3 operation sequence and sample code

       It will work like this sample code:

       Char buf[8]=linksys;

       UDFFileSystemWrite Udf;

       VfsFileInstance *pInst = Udf.openfile(/test/file1,);

       Udf.writefile(buf,sizeof(buf),pInst);

       Udf.closefile(pInst);

 4 source code

/*                                      
 *   @File name:  VfsFs_Common.h
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */


#ifndef VFS_COMMON_H
#define VFS_COMMON_H


#include "Vfs_common.h" //thIs file locate in cvs server: /ODDRecEng/hdr/

/* similar to  udf2.6 2.1.4 -------------------------------------*/
struct VfsFSTimeStamp {
    UINT16 uTypeAndTimeZone;
    INT16  iYear;
    UINT8 uMonth;
    UINT8 uDay;
    UINT8 uHour;
    UINT8 uMinute;
    UINT8 uSecond;
    UINT8 uCentIseconds;
    UINT8 uHundredMicroseconds;
    UINT8 uMicroseconds;
};

/* VfsFileEntry PermIssions , similar to ECMA 167r3 4/14.9.5 PermIssions */
#define VFS_PERM_O_EXEC   0x00000001U
#define VFS_PERM_O_WRITE   0x00000002U
#define VFS_PERM_O_READ   0x00000004U
#define VFS_PERM_O_CHATTR  0x00000008U
#define VFS_PERM_O_DELETE  0x00000010U
#define VFS_PERM_G_EXEC   0x00000020U
#define VFS_PERM_G_WRITE   0x00000040U
#define VFS_PERM_G_READ   0x00000080U
#define VFS_PERM_G_CHATTR  0x00000100U
#define VFS_PERM_G_DELETE  0x00000200U
#define VFS_PERM_U_EXEC   0x00000400U
#define VFS_PERM_U_WRITE   0x00000800U
#define VFS_PERM_U_READ   0x00001000U
#define VFS_PERM_U_CHATTR  0x00002000U
#define VFS_PERM_U_DELETE  0x00004000U

/*VfsFileEntry  atributes*/
#define VFS_ATTR_DIR       0x01U
#define VFS_ATTR_HIDE   0x02U
#define VFS_ATTR_READONLY  0x04U
#define VFS_ATTR_SYNC      0x08U  //


// VfsFileInstance->flag (open)
#define FI_FLAG_RDONLY      0x0001
#define FI_FLAG_WRONLY      0x0002
#define FI_FLAG_RDWR       0x0004
#define FI_FLAG_APPEND      0x0008

// VfsFileInstance->mode (create)
#define FI_MODE_READ    1
#define FI_MODE_WRITE   2
#define FI_MODE_LSEEK     4 // 64 bit seek
#define FI_MODE_PREAD     8 //random read
#define FI_MODE_PWRITE    FMODE_PREAD     /* random write, These go hand in hand */


// VfsFileSystem->type
#define MEDIA_TYPE_UNKNOWN  0
#define MEDIA_TYPE_ISO9660     1
#define MEDIA_TYPE_UDF      2
#define MEDIA_TYPE_UDF_BRIDGE 3

const int MAX_FS_PATH = 256;
typedef struct _FileInfo
{
 signed char cFileName[MAX_FS_PATH];
 UINT32 permIssion; /* See above constants */
 UINT16 nlink; /* Number of links. */
 UINT32 uid;  /* User: Maybe significant on NT ? */
 UINT32 gid;  /* Group: */
 UINT32 size; /* File size in bytes */
 UINT32  size_on_dIsk;  /* */
 UINT8   attributes; /* see file atributes*/
 VfsFSTimeStamp st_atime; /* Accessed date (always 00:00 hrs local * on FAT) */
 VfsFSTimeStamp st_mtime; /* Modified time */
 VfsFSTimeStamp st_ctime; /* Creation time */
}FileInfo;

#endif

/* ' ;&,"vIE' ;&,"nbsp;                                
 *   @File name:  OddFileInstance.h
 *   @Author:     lliming(lliming@cisco.com)
 *   @Version:     0.1
 *   @Date:        July-10-2006
 *   @Copyright (c) 2006 by cisco Systems, Inc.
 *       All rights reserved.
 */
#ifndef VFS_FILE_INSTANCE_H
#define VFS_FILE_INSTANCE_H

#include "VFS_common.h"
#include "OddFileDescriptor.h"       
class OddFileDescriptor ;
class OddFileEntry;

class OddFileInstance
{
protected:

      //signed int mFcount; //link to this intstance
      signed int mPos;  //current position in file data
      signed int mUid;
      signed int mGid;  //who own the process which Opened thIs instance
      signed int mFlag; //Open flag
      signed int mMode; //creation mode
   OddFileDescriptor * mpDescriptor;
public:
      
        OddFileInstance();
        virtual ~OddFileInstance();

  //write the buffer to device
        //int sync();

  //count
  //void IncCount(){ mFcount++; };
  //void DecCount(){ mFcount--; };
  OddFileDescriptor * GetDescriptor(){ return mpDescriptor;};

  void SetUid(signed int uid){ mUid = uid;};
  void SetGid(signed int gid){ mGid = gid;};

  signed int GetUid(){ return mUid;};
  signed int GetGid(){ return mGid;};

  void SetFlags(signed int flag){ mFlag = flag;};
  void SetMode(signed int mode){ mMode = mode;};

  signed int GetMode(){ return mMode;};
  signed int GetFlag(){ return mFlag;};

       
   //read, should be done in vfs
        //string GetText(signed int location, signed int length);
        //string GetBytes(signed int location, signed int length);
        //string GetText(signed int length);
       
        //seek
  void SetDataPointer(signed int dp){ mPos = dp;};
  signed int GetDataPointer(){ return mPos; };

  //write, should be done in vfs
        /*virtual signed char AppendBytes( signed char * buf, signed int length);
        virtual signed char InsertBytes( signed int location, signed char * buf, signed int length);
        virtual signed char OverWriteBytes(,signed int location, signed char * buf, signed int length);*/
       
};

#endif

/*                                       
 *   @File name:  VfsFileInstance.cpp
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */

#include "VfsFileInstance.h"


VfsFileInstance::VfsFileInstance(VfsFileDescriptor *pDesc)
{
 mPos = 0;
 mUid = 0;
 mGid = 0;
 mFlag = 0;
 mMode = 0;
 mpDescriptor = pDesc;

}

VfsFileInstance::~VfsFileInstance()
{
}

/*                                      
 *   @File name:  VfsFileDescriptor.h
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */
#ifndef VFS_FILE_DESCRIPTOR_H
#define VFS_FILE_DESCRIPTOR_H

#include
#include
#include
#include "VFS_common.h"
#include "VfsFileEntry.h"
#include "VfsFileSystemWrite.h"
    
class UdfFileSystemWrite;

class VfsFileDescriptor;


//typedef VfsFileDescsVector::iterator VfsFileDescsIterator;

class VfsFileDescriptor {
protected:
        signed int mDcount; //link to thIs file descriptor
        signed int mLock;   //locked?1: locked;0 unlocked;
        VfsFileEntry *mpFileEntry;
        VfsFileDescriptor *mpParentDesc;
        string mName;
        string mPath;
        VfsFileDescsVector mChildren; //sub files/dirs
  const VfsFileSystemWrite * mpFileSystem;
  
        void *mPrivateData; //some private data structure
public:
  //VfsFileDescriptor(){};
  VfsFileDescriptor(string name, VfsFileEntry *pFileEntry=NULL,
    VfsFileDescriptor *pParentFileDesc=NULL, const VfsFileSystemWrite *const pFileSystem=NULL);

  virtual ~VfsFileDescriptor();

  const VfsFileEntry &GetFileEntry(){return *mpFileEntry;};
  //void SetFileEntry(VfsFileEntry &pFileEntry);

  //namd and path
  const string GetName(){return mName;};
  const string GetPath(){return mPath;};

  //modify name
  void rename(const string & newname){mName=newname;};

  //chidren
  const VfsFileDescsVector * GetChildren(){return &mChildren;};

  //parent
  const VfsFileDescriptor * GetParentDescriptor(){return mpParentDesc;};

  //count
  void IncCount(){ mDcount++; };
  void DecCount(){ mDcount--; };

  //lock
  void SetLock(signed int lock){ mLock = lock; };
};       

#endif

/* *------------------------------------------------------------------
 * @file name:  VfsFileDescriptor.cpp
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */
#include "VfsFileDescriptor.h"


VfsFileDescriptor::VfsFileDescriptor(string name, VfsFileEntry *pFileEntry,  VfsFileDescriptor *pParentFileDesc, const VfsFileSystemWrite *const pFileSystem)
 {
 mDcount = 0;
 mLock = 0;
 mpFileEntry = pFileEntry;
 mpParentDesc = pParentFileDesc;
 mName = name;
 mpFileSystem = pFileSystem;
 //mPath = pParentFileDesc->GetPath() + mpFileSystem->GetSeparator() + mName;
 //mChildren
 mPrivateData = NULL;

 }
 
 
 
 VfsFileDescriptor::~VfsFileDescriptor()
 {

 }

 /*                                      
 *   @File name:  VfsFileEntry.h
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */    All rights reserved.
 */
#ifndef VFS_FILE_ENTRY_H
#define VFS_FILE_ENTRY_H

#include "VFS_common.h"
       


class VfsFileEntry {
protected:
          //FileInfo
          signed int mPermIssion; //constant
          signed int mAttribute;  //constant
          signed int mElink;      //how many fileDescriptor linked to thIs file entry
          signed int mUid;
          signed int mGid;
          VfsFSTimeStamp mAccessTime; /* Accessed date (always 00:00 hrs local * on FAT) */
          VfsFSTimeStamp mModifyTime; /* Modified time */
          VfsFSTimeStamp mCreateTime; /* Creation time */
          signed int mRealSize; //bytes of content
          signed int mDiskSize; //bytes on dIsk
         
          bool mLocked;
          signed char mSync;
          void *mPrivateData;//some private data structure
public:
   VfsFileEntry();
   virtual ~VfsFileEntry();
   
   
   int GetLinkNumber();
   
   //Get size
   int GetRealSize(){return mRealSize;};
   int GetDIskSize(){return mDiskSize;};
   
   //Set time
   signed char SetLastModified(const VfsFSTimeStamp & rTs){mModifyTime = rTs;};
   signed char SetLastAccessed(const VfsFSTimeStamp & rTs){mAccessTime = rTs;};
   signed char SetCreationTime(const VfsFSTimeStamp & rTs){mCreateTime = rTs;};
           
   //lock
   void SetLocked(bool lock){mLocked=lock;};
   bool GetLocked(){return mLocked;};
     
   //attributes
   FileInfo GetFileInfo(){return FileEnfo};
   signed char SetSynced(signed char IsSync){ mSync = IsSync};
   signed char GetSynced(){return IsSync;};
   /*signed char IsDirectory();
   signed char IsFile();
   UINT32 GetSize();
   UINT32 GetSizeOnDIsk();
   signed char IsHidden();
   signed char SetHidden(signed char hide);
   signed char IsReadOnly();
   signed char SetReadOnly(signed char readonly);*/
   VfsFSTimeStamp GetAccessTime(){return mAccessTime;};
   VfsFSTimeStamp GetCeateTime(){return mCreateTime;};
   VfsFSTimeStamp GetModifyTime(){return mModifyTime;};   
      
};       


#endif

/*                                       
 *   @File name:  VfsFileEntry.cpp
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */


#include "VfsFileEntry.h"

VfsFileEntry::VfsFileEntry(VfsFileDescriptor *pDesc)
{
 mPos = 0;
 mUid = 0;
 mGid = 0;
 mFlag = 0;
 mMode = 0;
 mpDescriptor = pDesc;

}

VfsFileEntry::~VfsFileEntry()
{
}

/*                                      
 *   @File name:  VfsFileSystemWrite.h
 *   @Author:     liming liu(liuliming2008@126.com)
 *   @Version:    0.1
 *   @Date:       July-10-2006
 *   @Copyright : GPL
 */

#ifndef VFS_FILE_SYSTEM_WRITE_H
#define VFS_FILE_SYSTEM_WRITE_H

//#include
#include "VFS_common.h"
#include "VfsFileDescriptor.h"
#include "VfsFileInstance.h"

class VfsFileInstance;
class VfsFileDescriptor;


class VfsFileSystemWrite {
 
public:
   virtual ~VfsFileSystemWrite(void){};
   
   virtual signed char LoadDisk() =0; //0: false;1:succeed
               
            //file system
            virtual signed int GetFileSystemType() =0; //0: Iso;1:udf
            virtual const string GetFileSystemName() =0; //
           
            //device ,
            virtual signed int GetDeviceType() = 0;
            virtual signed char SetDeviceType(signed int type) = 0;
           
            //lock
            virtual signed char GetLocked(VfsFileInstance * rFi) const = 0; //1: locked, 0 unlocked
            virtual signed char SetLocked(VfsFileInstance * rFi, signed char locked)=0;//1: locked, 0 unlocked
           
            //this fs modified?
            virtual signed char GetModefied()const =0;//1: Modefie, 0 unModefie
            virtual signed char SetModified(signed char modify)const =0;
           
          
            //Get statIstic
            virtual signed int GetDirCount()const = 0;
            virtual signed int GetFileCount()const = 0;
           
            //Get file system variable
            virtual signed int GetSectorSize()const = 0;
            virtual signed int GetLogicalBlockSize()const = 0;
         
            //Open
            virtual const VfsFileInstance * OpenFile(const signed char * sFileName, signed int flag) = 0; 

   virtual FileInfo * FindFirstFileInDir(const signed char * sDirName) = 0; 
   virtual FileInfo * FindNextFileInDir(const signed char * sDirName,FileInfo * preFi) = 0; 
           
            //Close
            virtual signed char CloseFile(VfsFileInstance * fi) = 0; //
           
                            
            virtual signed char FlushFileBuffers(const VfsFileInstance * pFile) = 0;//    Causes all buffered data to be written to the file. 
           
            /*******************
            * functions about oodFile
            ********************/

            //Get base attribute
            virtual const VfsFileDescriptor * GetParentDesc(VfsFileInstance * pFile)const = 0; //
            virtual const string GetName(VfsFileInstance * pFile)const = 0;
            virtual const string GetPath(VfsFileInstance * pFile)const = 0;
            virtual const string GetParentName(VfsFileInstance * pFile)const = 0;
            virtual const string GetParentPath(VfsFileInstance * pFile)const = 0;
           
            //Get attribute
            virtual signed char IsDirectory(VfsFileInstance * pFile)const = 0;//1: yes 0:no
            virtual signed char IsFile(VfsFileInstance * pFile)const = 0;//1: yes 0:no
   virtual signed char IsDirectory(const signed char * sFilePath)const = 0;//1: yes 0:no
            virtual signed char IsFile(const signed char * sFilePath)const = 0;//1: yes 0:no
            virtual UINT32 GetSize(VfsFileInstance * pFile)const = 0;
            virtual UINT32 GetSizeOnDisk(VfsFileInstance * pFile)const = 0;
            virtual signed char IsHidden(VfsFileInstance * pFile)const = 0;//1: yes 0:no
            virtual signed char IsReadOnly(VfsFileInstance * pFile)const = 0;//1: yes 0:no

            virtual const VfsFSTimeStamp  GetLastModified(VfsFileInstance * pFile)const = 0;
            virtual const VfsFSTimeStamp  GetLastAccessed(VfsFileInstance * pFile)const = 0;
            virtual const VfsFSTimeStamp  GetCreationTime(VfsFileInstance * pFile)const = 0;
            virtual const VfsFSTimeStamp  GetExpiredTime(VfsFileInstance * pFile)const = 0;
           
            //special
            virtual signed char IsSynced(const VfsFileInstance * pFile)const = 0;          
            //virtual signed char compareFileInstance(const VfsFileInstance & rFile1, const VfsFileInstance & rFile2)const = 0; //Compare two abstract pathnames lexicographically.
            virtual signed char compareToFilePath(const VfsFileInstance * pFile, const signed char * PathName)const = 0;           
           
          
            //search
            virtual const VfsFileDescsVector * GetChildrenFileDescriptor( VfsFileInstance * pFile) = 0;
            virtual const VfsFileDescriptor * GetFileDescriptor(const  VfsFileInstance * pFile)  = 0;
   virtual const VfsFileDescriptor * GetFileDescriptor(const signed char * sPath) = 0;
            
            //read
            //return the real length readed
            virtual signed int GetBytes(signed char * buf, signed int itemlength, signed int itemCount,  VfsFileInstance * pFile)const = 0;
           

            //seek
            virtual signed char SetDataPointer(VfsFileInstance * pFile, signed int dp, signed char flog)const = 0;
            virtual signed int GetDataPointer(const VfsFileInstance * pFile)const = 0;
           
           
            virtual signed char GetSeparator()const=0;
            virtual signed char GetPathSeparator()const=0;
           
            //modify attrbute
            virtual signed char SetLastModified(VfsFileInstance * pFile, VfsFSTimeStamp & rTs)const = 0;
            virtual signed char SetLastAccessed(VfsFileInstance * pFile, VfsFSTimeStamp & rTs)const = 0;
            virtual signed char SetCreationTime(VfsFileInstance * pFile, VfsFSTimeStamp & rTs)const = 0;
            virtual signed char Rename(VfsFileInstance * pFile, const signed char * sNewName)const = 0;
            virtual signed char SetReadOnly(VfsFileInstance * pFile, signed char sync)const = 0;
            virtual signed char SetHidden(VfsFileInstance * pFile, signed char hide)const = 0;
               
            //write    
            //virtual signed char AppendBytes(VfsFileInstance * pFile, signed char * buf, signed int length)const = 0;
            //virtual signed char InsertBytes(VfsFileInstance * pFile,  signed int location, signed char * buf, signed int length)const = 0;
            virtual signed char WriteBytes(signed char * buf, signed int itemlength, signed int itemCount,  VfsFileInstance * pFile)const = 0;

   //create
   virtual const VfsFileInstance * CreateFile(const signed char * sFileName, signed int flag) = 0;  //
   virtual const VfsFileInstance * CreateDirectory(const signed char * sFileName, signed int flag) = 0; //

   //delete
   virtual signed char DeleteFile(const signed char * sFileName)= 0;;
   virtual signed char DeleteDirectory(const signed char * sFileName)= 0;;
            /*************
            * end of functions about file
            *************/     
};       

#endif

 

 

 

  vfs

 

 

 

 

 

 

 

<< install mpeg4ip / 纪念逝去的校园生活 >>

专题推荐

不平凡的水果世界

不平凡的水果世界

平凡的水果世界,平凡中的不平凡。 今朝看水果是水果 ,看水果还是水果 ,看水果已不是水果。这境界,谁人可比?在不平凡的水果世界里,仁者见仁,智者见智。

中国春节的那些习俗

中国春节的那些习俗

正月是农历新年的开始,人们往往将它看作是新的一年年运好坏的兆示期。所以,过年的时候“禁忌”特别多。当然,各个地方的风俗习惯不一样,过年的禁忌也是不一样的。

评论
0/200
表情 验证码:

liming2008

  • 文章总数0
  • 画报总数0
  • 画报点击数0
  • 文章点击数0
个人排行
        博文分类
        日期归档