A newer version of this document is available. Customers should click here to go to the newest version.
7.6. File System
The HAL provides infrastructure for UNIX-style file access. You can use this infrastructure to build a file system on any storage devices available in your hardware.For more information about the infrastructure, 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.
- close()
- fstat()
- ioctl()
- isatty()
- lseek()
- open()
- read()
- stat()
- write()
For more information about the UNIX-style 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.
You must aways access files using absolute paths; there is no concept of a current directory.
#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;
}