Hi
I would like to implement a very simple Virtual Filesystem (VFS) which supports some basic file system operation like fwrite, fopen, fput, etc. The VFS is an abstraction layer on top of some concrete OS, e.g. Windows, Linux etc. Assume now, that the fopen interface looks something like this
FILE VFS_File_Open( const unsigned char* strFile, int flags );
Now I am wondering how I can make in the actual implementation of this interface the distinction about which filesystem I am talking to. Is there in C something that tells me on which OS the application is running so that I could do something like this:
FILE VFS_File_Open( const unsigned char strFile, int flags )
{
int OS = getOSID();
if (0S == 1)
//implement here the system calls required to open a file on a WIN OS
else if (OS == 2)
//implement here the system calls required to open a file on a Linux OS
etc
}
EDIT:
Thanks so far for your answer gents, that was really helpful to clarify some things!
Now I am wondering if anyone knows where I can find the system calls for file oeprations for windows? It is easy to find them for Linux but I struggeled to find something similar for windows, e.g. I would be interested in the system calls to open a file, write a file, etc.
On another note: The C stdio.h offers a number of stand IO operations like
FILE * fopen (const char *filename, const char *opentype)
In other words, I do not have to reimplement the fopen routine in my VFS as the Gnu C library takes care about what OS it is dealing with, is that right? I just have to implement functionaliy that is not supported by stdio library, e.g. creating directories, which differ from filesystem to filesystem?
Thanks