我希望实现一个非常简单的虚拟文件系统(VFS),支持一些基本的文件系统操作,比如fwrite、fopen、fput等。VFS是在某些具体操作系统(例如Windows、Linux等)之上的抽象层。现在假设,fopen接口长这个样子
FILE VFS_File_Open( const unsigned char* strFile, int flags );
现在我想知道如何在实际实现这个接口时区分我正在讨论哪个文件系统。在C语言中,是否有一些东西可以告诉我应用程序运行在哪个操作系统上,以便我可以像这样做:
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
}
编辑:
现在我想知道是否有人知道在Windows中可以找到文件操作的系统调用? 在Linux中很容易找到它们,但我很难找到类似于Windows的内容,例如,我对打开文件、写文件等系统调用感兴趣。
另外一件事:C stdio.h提供了许多标准IO操作,如
FILE * fopen (const char *filename, const char *opentype)
换句话说,我不需要在我的VFS中重新实现fopen例程,因为Gnu C库会处理它正在处理的操作系统,是这样吗?我只需要实现stdio库不支持的功能,例如创建目录,这些功能因文件系统而异?谢谢。