rfshell.dll
This document describes the interface of the RFSHELL.DLL
which can be used to easily add
ReiserFS support for existing applications.
Overview
The RFSHELL.DLL
has three C-style functions:
- Detect ReiserFS partitions on the local system and return the unique name for each
- Create an instance of the
IFilesystem
interface - Destroy an instance of the
IFilesystem
interface previously created
It is necessary to first find out which ReiserFS partitions are on the host system, thus the autodetect function. The other two functions are used to create an interface for the filesystem (you can access two or more reiserfs partitions at once).
Autodetecting partitions
Prototype
typedef void (WINAPI* LPFNFoundPartition)(LPCSTR lpszName); void WINAPI FS_Autodetect( LPFNFoundPartition lpCallback );
Description
This function autodetects all reiserfs partitions on the local machine. For each partition found,
it will call the callback specified as parameter lpCallback
Input
LPFNFoundPartition lpCallback
- Pointer to a caller-provided function that looks like this:
void WINAPI FoundPartition(LPCSTR lpszName) { // todo: add implementation }
Output
None
Creating an instance of IFilesystem
Prototype
IFilesystem* WINAPI FS_CreateInstance( LPCSTR lpszName );
Description
This function creates an instance of IFilesystem
for the reiserfs partition
specified by lpszName
. See below for a description of the IFilesystem
interface.
Input
LPCSTR lpszName
- Pointer to the name of a reiserfs partition.
Output
Pointer to a newly allocated IFilesystem
or NULL
if an error occured.
Destroying an instance of IFilesystem
Prototype
void WINAPI FS_DestroyInstance( IFilesystem* pFilesystem );
Description
This function destroys an instance of IFilesystem
previously allocated using FS_CreateInstance
Input
IFilesystem* pFilesystem
- Pointer to the IFilesystem
.
Output
None
The IFilesystem
interface
Overview
class IFilesystem : public IUnknown { public: virtual HANDLE OpenFile(LPCTSTR szFilename) const = 0; virtual void ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD NumberOfBytesToRead, DWORD& NumberOfBytesRead) const = 0; virtual void CloseFile(HANDLE hFile) const = 0; virtual HANDLE FindFirstFile(LPCTSTR szPath) const = 0; virtual bool FindNextFile(HANDLE hFind, UNIX_FILEINFO& FileInfo) const = 0; virtual void CloseFind(HANDLE hFind) const = 0; };
IFilesystem::OpenFile
Prototype
HANDLE IFilesystem::OpenFile(LPCTSTR szFilename) const;
Description
This function opens a handle for the file specified by szFilename
. Note that
the file returned is readonly, because rfstool
supports readonly-mode only.
Input
LPCTSTR szFilename
- Name of a file on the local filesystem, e.g. /etc/fstab
Output
Handle for the file.
IFilesystem::ReadFile
Prototype
void IFilesystem::ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD NumberOfBytesToRead, DWORD& NumberOfBytesRead) const;
Description
This function reads data from a file. Note that due to implementation issues, in the current version of rfstool
,
the whole file is read to memory first.
Input
HANDLE hFile
- Filehandle previously allocated by IFilesystem::OpenFile
LPVOID lpBuffer
- Pointer to a BYTE
buffer to receive the file data
DWORD NumberOfBytesToRead
- Size of the Buffer pointed to by lpBuffer
DWORD& NumberOfBytesRead
- Reference to a DWORD
that will receive the number of bytes actually retrieved.
This might be less than NumberOfBytesToRead
, indicating end-of-file.
Output
None
IFilesystem::OpenFile
Prototype
void IFilesystem::CloseFile(HANDLE hFile) const;
Description
This function closes a handle for a file on a reiserfs partition. Do NOT call the Win32-CloseHandle
API on handles returned from IFilesystem
Input
HANDLE hFile
- Filehandle previously allocated by IFilesystem::OpenFile
Output
None
IFilesystem::FindFirstFile
Prototype
HANDLE IFilesystem::FindFirstFile(LPCTSTR szPath) const;
Description
This function opens a handle for a directory in szPath
Input
LPCTSTR szPath
- Name of a directory the local filesystem, e.g. /usr/include
Output
Handle for the directory.
IFilesystem::FindNextFile
Prototype
bool IFilesystem::FindNextFile(HANDLE hFind, UNIX_FILEINFO& FileInfo) const;
Description
This function returns the description of the next file in the directory, or false if there are no more files in the directory.
Input
HANDLE hFind
- Handle to a directory previously allocated by IFilesystem::FindFirstFile
UNIX_FILEINFO& FileInfo
- Reference to a UNIX_FILEINFO
structure describing the file. This structure
looks like this:
struct UNIX_FILEINFO { __u16 i_mode; /* File mode (permissions)*/ __u16 i_uid; /* Low 16 bits of Owner Uid */ __u16 i_gid; /* Low 16 bits of Group Id */ __u32 i_size; /* Size in bytes */ __s32 i_atime; /* Access time */ __s32 i_ctime; /* Creation time */ __s32 i_mtime; /* Modification time */ TCHAR szFileName[UNIX_FILENAME_LENGTH]; };
Output
If the function returns true
, there are more files to check. If the function returns false
, end of directory has been reached.
IFilesystem::CloseFind
Prototype
void IFilesystem::CloseFind(HANDLE hFind) const;
Description
This function closes a handle for a directory on a reiserfs partition. Do NOT call the Win32-CloseHandle
API on handles returned from IFilesystem
Input
HANDLE hFind
- Filehandle previously allocated by IFilesystem::FindFirstFile
Output
None
Appendix: The header IFilesystem.h
#ifndef IFILESYSTEM_H #define IFILESYSTEM_H typedef unsigned char __u8; typedef unsigned short __u16; typedef unsigned long __u32; typedef char __s8; typedef short __s16; typedef long __s32; #define UNIX_FILENAME_LENGTH 255 struct UNIX_FILEINFO { __u16 i_mode; /* File mode (permissions)*/ __u16 i_uid; /* Low 16 bits of Owner Uid */ __u16 i_gid; /* Low 16 bits of Group Id */ __u32 i_size; /* Size in bytes */ __s32 i_atime; /* Access time */ __s32 i_ctime; /* Creation time */ __s32 i_mtime; /* Modification time */ TCHAR szFileName[UNIX_FILENAME_LENGTH]; }; class IFilesystem : public IUnknown { public: virtual HANDLE OpenFile(LPCTSTR szFilename) const = 0; virtual void ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD NumberOfBytesToRead, DWORD& NumberOfBytesRead) const = 0; virtual void CloseFile(HANDLE hFile) const = 0; virtual HANDLE FindFirstFile(LPCTSTR szPath) const = 0; virtual bool FindNextFile(HANDLE hFind, UNIX_FILEINFO& FileInfo) const = 0; virtual void CloseFind(HANDLE hFind) const = 0; }; #ifdef __cplusplus extern "C" { #endif typedef void (WINAPI* LPFNFoundPartition)(LPCSTR lpszName); void WINAPI FS_Autodetect( LPFNFoundPartition lpCallback ); IFilesystem* WINAPI FS_CreateInstance( LPCSTR lpszName ); void WINAPI FS_DestroyInstance( IFilesystem* pFilesystem ); #ifdef __cplusplus } #endif #endif // IFilesystem_H