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.3.NAND File Server - nandfsys #
NAME
NAND Flash File Server – nandfsys
SYNOPSIS
#include <fsysinit.h>
#include <device.h>
#include <fsys.h>
#include <nand_flash.h>
- pthread_create(&tid, &attr, (void *(*)(void*))_nand_file_server, (char*)&fsysinit)
- THREAD _nand_file_server( (char *)&fsysinit)
struct fsysinit {
uint_16 fsi_msgsize;
uint_16 fsi_nclones; /* Number of servers to create. */
uint_32 fsi_datalog; /* datlog bit definition */
uint_16 fsi_nbuffers; /* Number of buffers in buffer cache, minimum 2*/
uint_16 fsi_blocksize; /* Memory block size: 256 for NAND Flash, 512 for sd/mmc-card */
uint_16 fsi_maxopen; /* Max number of open files */
uint_16 fsi_ndrives; /* Maximum number of allocated disks, valid for FATFS only*/
};
DESCRIPTION
The NAND Flash file server – fsys is Linux compatible file system with NAND Flash . File can use RAM disc or SD card or equivalent or NAND flash depending of low level driver implementation specified in demo application. The files are devstrad.c, nand_flash.c and nand_flash.h (see example below)
Nandfsys supports the following operations:
- 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. There is no difference with the various media choices.
- 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 (formatting media, all content will be deleted).
- 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
The following compile options are for the Nand Flash File Server. The driver has the second set of options.
FSYSDEBUGEnable overall debug logging with xprintf.DEBUGFSYSEnable deep structure debug logging with xprintf.MOUNTDEBUGEnable Mount debug logging with xprintf.RWDEBUGEnable read write debug logging with xprintf.DEBUGGINGEnable superblock debug logging with xprintf.NOCLOCKNo clock is used so return a fake time.NAND_ECC_ENABLEEnable ECC for NAND.NAND Driver Options setup in devstrad
DEV_TYPEDevice type, in this case DEV_NAND, DEV_SD, DEV_RAMDEV_PAGE_SIZEDevice page size. Used only for DEV_NAND type.DEV_PAGE_DATA_SIZEDevice page data size. Used only for DEV_NAND type.SPARE_PAGE_SIZESpare device page size. Used only for DEV_NAND type.DEV_NUM_PAGE_BLOCKSNumber of pages in a physical block. Used only for DEV_NAND type.DEV_NUM_BLOCKSNumber of blocks in the device. Used only for DEV_NAND type.DEV_BLOCK_ERASEErase the block. Used only for DEV_NAND type.DEV_BLOCK_CHECKVerify the block. Used only for DEV_NAND type.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 PAGE_DATA_SIZE for the NAND flash. The other common values are 256 for the RAM disc and 512 for the SD and uSD cards. The NAND flash requires additional information from NAND driver, see NAND Driver Options setup above.Open Options
O_CONTIGPreallocates a specific size for the file using continuous blocks and extents.O_CREATE, O_CREATCreate the file if it does not exist except if O_EXCL is set.O_WRITE, O_WRONLYOpen for writing.O_READ, O_RDONLYOpen for reading.O_DIRECTDo not use buffer cache and use DMA hardware to write directly to the media. Not implemented on all systems.O_EXCLUSIVE, O_EXCLIf this is set with O_CREATE, the creation will fail if the file exists. Useful for simple file locking.O_TRUNC, O_TRUNCATEErases the file by setting the file length to zero. Does not alter file contents or free space.O_APPEND, O_APPENDDSet the seek pointer to the end of the file prior to each writeO_UNBUFNo space to be allocated for buffered I/O.IOCTL Options for NAND Flash
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; /* datlog bit definition */ uint_16 fsi_nbuffers; /* Number of buffers in buffer cache, minimum 2*/ uint_16 fsi_blocksize; /* Memory block size: 256 for NAND Flash, 512 for sd/mmc-card */ uint_16 fsi_maxopen; /* Max number of open files */ uint_16 fsi_ndrives; /* Maximum number of allocated disks, 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 = PAGE_DATA_SIZE; // 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*))_nand_file_server, (char*)&fsysinit)) { if(!dir_register(FSYS_DIRECTORY, tid, TYPE_SERVER)) { xprintf("..Unable to register name of Nand File Server..\n"); xprintf("..Required resource not present - aborting..\n"); #if RTOS_DEBUG dir_deregister("Main thread"); #endif pthread_exit((void*)1); } } else { xprintf("..Unable to create File Server..\n"); xprintf("..Required resource for program not present - aborting..\n"); #if RTOS_DEBUG dir_deregister("Main thread"); #endif pthread_exit((void*)1); } xprintf(".. Nand Fsys File server is now created..\n"); xprintf("..Attempting to mkfs and mount it...\n"); // parameters found in main.h mkfs_status = mkfs(FSYS_DIRECTORY, NAND_DEVICE_NO, 0, NAND_DISK_MAX_FILES); if(mkfs_status == -1) { xprintf("..Unable to make a file system. errno=%d\n", errno); xprintf("..Please fix me\n"); #if RTOS_DEBUG dir_deregister("Main thread"); #endif pthread_exit((void*)1); } // must mount a directory for each mount point, here d1, // unique name for each if((mount_status = mount(NAND_DEVICE_NO, FSYS_MOUNT, 0)) == -1) { xprintf("..Unable to mount nand flash disk. errno=%d\n", errno); xprintf("..Please fix me\n"); #if RTOS_DEBUG dir_deregister("Main thread"); #endif pthread_exit((void*)1); } ... File devstrad.c content ... ******** NAND FLASH usage ********* struct bdevsw bdevsw[] = { {(int(*)(udev_t,int,int,char*,int))nodev, nodev, nodev,(int(*)(udev_t,char,void*))nodev, 0}, /* zero is an invalid dev num */ {disk_strategy, disk_open, disk_close,disk_ioctl,0} }; ... int disk_open(udev_t dev) - will initialize the NAND flash driver int disk_close(udev_t dev) - will close the NAND flash driver. int disk_strategy(udev_t dev, int_32 off, int len, char *buf, int rwflag)- this routine is used to read/write data from/to the NAND flash disk int disk_ioctl(udev_t dev, char ctrl, void *buff)- this routine is used to control NAND flash parameters and spare page operations for the NAND flash disk See demo examples for more detailsSEE ALSO
chmod(), close(), lseek(),mkdir(), mkfs(), mount(), open(), read(), stat(), write(), fatfs
