Tuesday, November 18, 2008

On filesystems

Some PalmOS thigns will not work on DGOS. Specifically I am talking about SlotDrivers and FsLibs. Why? Specifically because:
  • In DGOS, for efficiency reasons, the driver model is differet from PalmOS
  • Drivers are in kernel space in DGOS, so they can make very quick system calls, and admitting any PalmOS code into kernel space is a bad idea because it was never written to be even thread safe
  • Porting an existing driver to DGOS is not hard


Filesystems are created as a kernel module, and register themselves with the DGOS kernel using the vfsRegisterFs() function, which takes, as a parameter, a pointer to a VfsFS structure. This structure is a table of function pointers and an FS name.

The module provides this, and from then on, until it is unregistered using vfsUnregisterFs(), it can be used to mount and format filesystems.

Here it is in details:



#define VFS_OPEN_MODE_READ 1
#define VFS_OPEN_MODE_RW 2
#define VFS_OPEN_MODE_EXCLUSIVE 4

#define VFS_SEEK_SET 0
#define VFS_SEEK_CUR 1
#define VFS_SEEK_END 2

#define FILE_ATTR_HIDDEN 0x00000001
#define FILE_ATTR_SYSTEM 0x00000002
#define FILE_ATTR_READONLY 0x00000004
#define FILE_ATTR_ARCHIVE 0x00000008

#define VFS_FS_NAME_SZ 16

typedef Err (*VfsVolInitFn) (void** fsData);
typedef Err (*VfsVolDeinitFn) (void* fsData);

typedef Err (*VfsFsMountFn) (void* fsData,UInt32 blkDev);
typedef Err (*VfsFsUnmountFn) (void* fsData);
typedef Err (*VfsFsSizesFn) (void* fsData,UInt64* free,UInt64* used,UInt64* total); //in bytes
typedef Err (*VfsFsInfoFn) (void* fsData,VfsFsInfo* info);
typedef Err (*VfsFsCreate) (void* fsData,UInt32 blkDev);
typedef Err (*VfsFsGetLabel) (void* fsData,wchar_t* label,UInt32* size /* in / out */);
typedef Err (*VfsFsSetLabel) (void* fsData,const wchar_t* label);

typedef Err (*VfsFileCreateFn) (void* fsData,const wchar_t* path);
typedef Err (*VfsFileDeleteFn) (void* fsData,const wchar_t* path);
typedef Err (*VfsFileRenameFn) (void* fsData,const wchar_t* oldPath,const wchar_t* newPath); //MUST handle moving files too, not just renaming

typedef Err (*VfsFileOpenFn) (void* fsData,const wchar_t* path,UInt32 mode,void** openFileData);
typedef Err (*VfsFileCloseFn) (void* fsData,void* openFileData);
typedef Err (*VfsFileReadFn) (void* fsData,void* openFileData,void* buf,UInt32 bytes,UInt32* done);
typedef Err (*VfsFileWriteFn) (void* fsData,void* openFileData,const void* buf,UInt32 bytes,UInt32* done);
typedef Err (*VfsFileSeekFn) (void* fsData,void* openFileData,UInt32 whence,Int32 offset);
typedef Err (*VfsFileTellFn) (void* fsData,void* openFileData,UInt32* position);
typedef Err (*VfsFileGetAttrFn) (void* fsData,void* openFileData,UInt32* attr);
typedef Err (*VfsFileSetAttrFn) (void* fsData,void* openFileData,UInt32 attr);
typedef Err (*VfsFileGetDateFn) (void* fsData,void* openFileData,UInt32* create,UInt32* mod,UInt32* access); //null to not get
typedef Err (*VfsFileSetDateFn) (void* fsData,void* openFileData,UInt32* create,UInt32* mod,UInt32* access); //null to not set
typedef Err (*VfsFileGetSizeFn) (void* fsData,void* openFileData,UInt32* sz);
typedef Err (*VfsFileSetSizeFn) (void* fsData,void* openFileData,UInt32 sz);

typedef Err (*VfsDirCreateFn) (void* fsData,const wchar_t* path);
typedef Err (*VfsDirDeleteFn) (void* fsData,const wchar_t* path);
typedef Err (*VfsDirOpenFn) (void* fsData,const wchar_t* path,void** openDirData);
typedef Err (*VfsDirCloseFn) (void* fsData,void* openDirData);
typedef Err (*VfsDirEnumeFn) (void* fsData,void* openDirData,UInt32* iterator,VfsDirEntry* entry);

typedef struct{

wchar_t fsName[VFS_FS_NAME_SZ];

//vol ops
VfsVolInitFn volInit;
VfsVolDeinitFn volDeinit;

//FS ops
VfsFsMountFn fsMount;
VfsFsUnmountFn fsUnmount;
VfsFsSizesFn fsSizes; //used,free,total
VfsFsInfoFn fsInfo;
VfsFsCreate fsCreate; //format a disk
VfsFsGetLabel fsGetLabel;
VfsFsSetLabel fsSetLabel;

//ops on unopened files
VfsFileCreateFn fileCreate;
VfsFileDeleteFn fileDelete;
VfsFileRenameFn fileRename;

//ops on opened files
VfsFileOpenFn fileOpen;
VfsFileCloseFn fileClose;
VfsFileReadFn fileRead;
VfsFileWriteFn fileWrite;
VfsFileSeekFn fileSeek;
VfsFileTellFn fileTell;
VfsFileGetAttrFn fileGetAttr;
VfsFileSetAttrFn fileSetAttr;
VfsFileGetDateFn fileGetDates;
VfsFileSetDateFn fileSetDates;
VfsFileGetSizeFn fileGetSize;
VfsFileSetSizeFn fileSetSize; //resize

//ops on unopened dirs
VfsDirCreateFn dirCreate;
VfsDirDeleteFn dirDelete;

//open on open dirs
VfsDirOpenFn dirOpen;
VfsDirCloseFn dirClose;
VfsDirEnumeFn dirEnumerate;

}VfsFS;

No comments: