Visible to Intel only — GUID: mwh1416946766624
Ixiasoft
Visible to Intel only — GUID: mwh1416946766624
Ixiasoft
6.6. File System
For more information, refer to an example in the "Read-Only Zip File System" chapter.
You can access files in a HAL-based file system by using either the C standard library file I/O functions in the newlib C library (for example fopen(), fclose(), and fread()), or using the UNIX-style file I/O provided by the HAL.
The HAL provides the following UNIX-style functions for file manipulation:
- close()
- fstat()
- ioctl()
- isatty()
- lseek()
- open()
- read()
- stat()
- write()
For more information about these functions, refer to the "HAL API Reference" chapter.
The HAL registers a file subsystem as a mount point in the global HAL file system. Attempts to access files below that mount point are directed to the file subsystem. For example, if a read-only zip file subsystem (zipfs) is mounted as /mount/zipfs0, the zipfs file subsystem handles calls to fopen() for /mount/zipfs0/myfile.
There is no concept of a current directory. Software must access all files using absolute paths.
#include <stdio.h> #include <stddef.h> #include <stdlib.h> #define BUF_SIZE (10) int main(void) { FILE* fp; char buffer[BUF_SIZE]; fp = fopen ("/mount/rozipfs/test", "r"); if (fp == NULL) { printf ("Cannot open file.\n"); exit (1); } fread (buffer, BUF_SIZE, 1, fp); fclose (fp); return 0; }
For more information about the use of these functions, refer to the newlib C library documentation installed with the Nios II EDS. To access the documentation, go to the Windows Start menu, click Programs > Altera > Nios II > Nios II Documentation.