Unison Help
- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
5.1.1. Multimedia File Server - fsys #
NAME
Multimedia File Server – fsys
SYNOPSIS
#include <fsysinit.h>
#include <device.h>
#include <fsys.h>
- pthread_create(&tid, &attr, (void *(*)(void*))_file_server, (char*)&fsysinit)
- THREAD _file_server( (char *)&fsysinit)
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*/ };
DESCRIPTION
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:
Operation | Description |
---|---|
mkfs | make a file system, minor device numbers are used for different partitions |
mount | mount a file system at a specific device and directory |
open | open/create a file using flags |
close | close a file |
read | read from a file |
write | write to a file |
mkdir | make a directory |
rmdir | remove directory |
stat | get file information |
fstat | get file information |
link | create a link to a file |
unlink | remove a link to a file |
lseek | goto a specific offset in a file |
umount | unmount a file system |
chmod | change mode of a file relative to directory file descriptor |
sync | schedule file system updates |
getdirentries | get directory entries in a filesystem independent format |
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
Option Description FSYSDEBUG Enable overall debug logging with xprintf DEBUGFSYS Enable deep structure debug logging with xprintf MOUNTDEBUG Enable Mount debug logging with xprintf RWDEBUG Enable read write debug logging with xprintf DEBUGGING Enable superblock debug logging with xprintf NOCLOCK No clock is used so return a fake time Run Time Options
Initialization Options
fsi_msgsizeThis is the size in bytes of the structure set for all standard Unison messages and initialization records.fsi_nclonesSet the number of parallel file servers. Each one is implemented as a separate thread.fsi_datalogSet the number of the file server for dynamic data logging.fsi_nbuffersNumber of buffers in buffer cache. Note that the cache can be disabled using an ioctl.fsi_maxopenSet the maximum number of open files.fsi_blocksizeSet the file system block size. The common values are 256 for the RAM disc and 512 for the SD and uSD cards.Open Options
Option Description O_CONTIG Preallocates a specific size for the file using continuous blocks and extents. O_CREATE | O_CREAT Create the file if it does not exist except if O_EXCL is set. O_WRITE | O_WRONLY Open for writing. O_READ | O_RDONLY Open for reading. O_DIRECT Do not use buffer cache and use DMA hardware to write directly to the media. Not implemented on all systems. O_EXCLUSIVE | O_EXCL If this is set with O_CREATE, the creation will fail if the file exists. Useful for simple file locking. O_TRUNC | O_TRUNCATE Erases the file by setting the file length to zero. Does not alter file contents or free space. O_APPEND | O_APPENDD Set the seek pointer to the end of the file prior to each write O_UNBUF No space to be allocated for buffered I/O. IOCTL Options
For more details, see functions description in I/O Library.
RETURN VALUES
In case of successful start up pthread_create will return 0 value.
ERRORS
In case of any errors during operation with fsys system set errno to the corresponding POSIX compatible error code.
EACCESSearch permission is denied on a component of the path prefix, pr the file exists and the permissions specified b oflag are denied, or the file does not exist and write permission is denied for the parent directory of the file to be created, or O_TRUNC is specified and write permission is denied.EEXISTO_CREAT and O_EXCL are set and the named file exists.EINVALThe implementation does not support synchronized I/O for this file or another invalid parameter has been passed into the file server.EISDIRThe named file is a directory, and the oflag argument specifies write or read/write access.EMFILEToo many file descriptors are currently in use.EMLINIToo many file links are currently in use.ENODEVThe device is not available.ENFILEToo many files currently open in the system.ENOENTO_CREAT is not set and the named file does not exist, or O_CREAT is set and either the path prefix does not exist or the path argument points to an empty string.ENOMEMInsufficient memory exists to complete the request.ENOTDIRA component of the path prefix is not a directory.EROFSThe named file resides on a read-only file system and either O_WRONLY, O_RDWR, O_CREAT (if the file does not exist), or O_TRUNC is set in oflag argument.EIOA physical I/O error occured.EPERMInsufficient ownership for the file operation.ENOTEMPTYThe file or directory is not empty and the operation cannot be completed.ENOTSUPPORTEDThe fatfs file system does not support this operation.EBUSYThe file system is busy and cannot complete the operation.ENODEVNo such device.EFAULTFile system error.EBADFBad file operation.EBADFSYSFile system is corrupted.
EXAMPLE
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 pthread_exit((void*)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
SEE ALSO
chmod(), close(), lseek(),mkdir(), mkfs(), mount(), open(), read(), stat(), write(), fatfs