File I/O and File System Access
[Nebula Kernel]
Detailed Description
A cross platform set of file I/O and file system objects that also support access to virtualized file systems.The features of the file system are:
- a fileserver object encapsulates the host filesystem.
- completely removes differences between Windows, Linux or XBox filesystem.
- OOP concepts
File and Directory as comfortable C++ classes (nFile, nDirectory). - support platform specific service.
Nebula uses Win32 file routines under Windows not the ANSI C file routines. (CreateFile(),WriteFile(),ReadFile()etc.) - offers 'Directory Assigns'
- Use
textures:image.ddsinstead ofc:\program files\...\textures\image.dds - Let Nebula convert it to the absolute path.
- This is inspired by AmigaOS.
- Use
Nebula also supports a file archive system which is integrated with its file sytem.
The features of file archive system are:
- similiar to Quake's PAK files
- packs directory hierarchies into one single file
- no wasted disk space with many small files
- drastically reduced loading time
- cleaner application directory layout
- See also:
- NPK File Management.
File Server Initialization
By default, the kernel server will create an instance of the nFileServer2 at/sys/servers/file2 when the kernel is initialized.It is also possible to subclass nFileServer2 to add additional or altered functionality, nNpkFileServer is an example of this. You may want to replace the default nFileServer2 instance with a specialized file server.
In TCL:
delete /sys/servers/file2 new nnpkserver /sys/servers/file2
In C++:
nFileServer2 * fileServer2; fileServer2 = kernelServer->Lookup("/sys/servers/file2"); n_delete fileServer2; fileServer2 = (nFileServer2*)kernelServer->New("nnpkfileserver", "/sys/servers/file2");
- Warning:
- That is obviously not safe, as anyone with a reference to the initial nFileServer2 instance will now be holding onto an invalid object. The API will be changing to address this issue.
File Server Usage
In order to read and write files a nFile object should be created.
nFile* file = fileServer2->NewFileObject();
The nFile object can then be opened and read from. The nFile object that is returned may be a subclass of nFile, such as nNpkFile, if you are using one of the more specialized nFileServer2 implementations.
nFile objects are reference-counted (via nRefCounted), so they must be released when you are done with them rather than simply deleted.
- Todo:
- Talk about nFileTime
// file input if (file->Open(fileName, "rb")) { void* buf = n_malloc(dataSize); int num = file->Read(buf, dataSize); } file->Close(); // file output if (file->Open("todo.txt", "w")) { file->PutS("Must write scene graph demo\n"); } file->Close(); file->Release();
Talk about nFileNode
The nDirectory class can be used to search directories.
nDirectory* folder = fileServer2->NewDirectoryObject(); if(folder->Open(dir)) { if(!folder->IsEmpty()) { do { entryName = folder->GetEntryName(); if(folder->GetEntryType() == nDirectory::FILE) { ... } } while (folder->SetToNextEntry()); } } folder->Close();
When using a more specialized nFileServer2 implementation, the nDirectory object returned may be a more specialized subclass.
Talk about how to mangle paths to process assigns and so on.
Assigns
Assigns provide a way to isolate system-specific paths from a path or filename. They are used in a path as an alias, which gets mapped to a new absolute path. For example, with an assign"data" that maps to "/usr/local/share/nebula":
"data:vehicle/vehicle.n3d"
would map to:
"/usr/local/share/nebula/vehicle/vehicle.n3d"
Assigns can be read and written with nFileServer2:
Assigns are stored as nEnv variables within /sys/share/assigns/ in the Nebula object hierarchy. By default, two assigns exist:
/sys/share/assigns/home - Nebula's home directory
/sys/share/assigns/bin - Nebula's application directory
- Todo:
- Mention the
projassign.
Shutdown
As the kernel server manages the file server, it will automatically handle shutting it down at the appropriate time.
Modules | |
| NPK File Management | |
| RAM File Management | |
Classes | |
| class | nFileTimePosix |
| class | nFileTimeWin32 |
| class | nDirectory |
| class | nDirectoryWatchHandler |
| class | nFile |
| Wrapper class for accessing file system files. More... | |
| class | nFileNode |
| class | nFileServer2 |
| Central server object of Nebula2's file system subsystem. Provides functions for creating file and directory objects and assigns. More... | |
| class | nFileTime |