Multimedia File Server - fsys
#include <fsysinit.h>
#include <device.h>
#include <fsys.h>
struct fsysinit {
uint_16 fsi_msgsize;
uint_16 fsi_nclones; /* Number of servers to create. */
uint_32 fsi_datalog; /* Past Global index of server. Now datlog bit definition */
uint_16 fsi_nbuffers; /* Number of buffers in buffer cache, minimum 2*/
uint_16 fsi_blocksize; /* Memory block size: 256 for RAM-disc, 512 for sd/mmc-card */
uint_16 fsi_maxopen; /* Max number of open files */
uint_16 fsi_ndrives; /* Maximum number of allocated disk, valid for FATFS only*/
};
The multimedia file server - fsys is Linux compatible file system. File system can use RAM disc or SD card or equivalent depending of low level driver implementation specified in demo application, typically file devstrad.c (see example below)
Fsys supports the following operations:
Typical operation for the file server involves several steps common in various operating system environments including Linux.
Create a file server first so that commands can be carried out for the selected media. Use pthread_create to do this.
Register the file server so that it can be found as a server in the system.
Make a file system using mkfs. This creates a root directory structure on the media. And doing formatting of media, all information will be erased.
Mount the file system. Note that an extra directory or a root directory is specified in addition to the registered file server name.
The file system is now ready to use with the remaining file system commands.
Compile Options
Run Time Options
Initialization Options
Open Options
IOCTL Options
For more details, see functions description in I/O Library.
In case of successful start up pthread_create will return 0 value.
In case of any errors during operation with fsys system set errno to the corresponding POSIX compatible error code.
struct fsysinit {
uint_16 fsi_msgsize;
uint_16 fsi_nclones; /* Number of servers to create. */
uint_32 fsi_datalog; /* Past Global index of server. Now datlog bit definition */
uint_16 fsi_nbuffers; /* Number of buffers in buffer cache, minimum 2*/
uint_16 fsi_blocksize;/* Memory block size: 256 for RAM-disc, 512 for sd/mmc-card */
uint_16 fsi_maxopen; /* Max number of open files */
uint_16 fsi_ndrives; /* Maximum number of allocated disk, valid for FATFS only*/
};
...
/*
*
* FSYS Initialization
*
*
*/
/* create the File server and mount the ram disk */
fsysinit.fsi_msgsize = sizeof(struct fsysinit);
fsysinit.fsi_nclones = 1;
fsysinit.fsi_datalog = 0x3;
fsysinit.fsi_nbuffers = 4; /* num of disk buffers (cache size) */
fsysinit.fsi_maxopen = 2; /* max num of open files */
fsysinit.fsi_blocksize = 256; //512 for SD/MMC cards
// set up stack size and priority for main fsys threads and all clones
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, FSYSSTACKSIZE);
myNewFsysPriority.sched_priority = FSYSPRIO;
pthread_attr_setschedparam(&attr, &myNewFsysPriority);
if(!pthread_create(&tid, &attr, (void *(*)(void*))_file_server, (char*)&fsysinit))
{if(!dir_register(FSYS_DIRECTORY, tid, TYPE_SERVER))
{
xprintf("..Unable to register name of File Server\n..");
xprintf("..Required resource not present - aborting..\n");
#if RTOS_DEBUG
dir_deregister("Main thread");
#endif
exit(1);
}
}
...
File devstrad.c content
...
******** For SD card usage *********
struct bdevsw bdevsw[] = {
{
(int(*)(udev_t, int, int, char*,int))nodev,
nodev,
nodev,
0}, /* zero is an invalid dev num */
{sd_strategy, sd_open, sd_close, 0}
};
...
int sd_open(udev_t dev) - will initialize SD card driver
int sd_close(udev_t dev) - empty function for SD
int sd_strategy(udev_t dev, int_32 off, int len, char *buf, int rwflag)- this routine is used to read/write data from/to the disk
******** For RAM usage *********
static char ram_disk[DISK_SIZE]; - Space for RAM disc
struct bdevsw bdevsw[] = {
{
(int(*)(udev_t, int, int, char*,int))nodev,
nodev,
nodev,
0}, /* zero is an invalid dev num */
{ram_strategy, ram_open_close, ram_open_close, 0}
};
...
/* now require a routine to open/close the ram- this is a trivial routine since RAM always exists and there is no hardware initialization to do - simply return EOK */
int ram_open_close(udev_t dev)
/* next routine is used to read/write data from/to the disk */
int ram_strategy(udev_t dev, int_32 off, int len, char *buf, int rwflag)
See demo examples for more details
chmod(), close(), lseek(),mkdir(), mkfs(), mount(), open(), read(), stat(), write(), fatfs