From a41c1de32c9d58f0e4380f59e8ce0bc8770cbf02 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 28 Sep 2014 10:15:33 -0600 Subject: [PATCH] Add basic data structures that will allow us to move named semaphore support out of the OS and into the VFS (not complete). --- include/fcntl.h | 2 +- include/fixedmath.h | 2 +- include/mqueue.h | 6 +-- include/nuttx/ascii.h | 2 +- include/nuttx/compiler.h | 2 +- include/nuttx/configdata.h | 2 +- include/nuttx/fs/fs.h | 81 ++++++++++++++++++++++++++----------- include/nuttx/fs/ioctl.h | 2 +- include/nuttx/fs/nxffs.h | 2 +- include/nuttx/fs/procfs.h | 2 +- include/nuttx/fs/smart.h | 2 +- include/nuttx/init.h | 2 +- include/nuttx/irq.h | 2 +- include/nuttx/kthread.h | 2 +- include/nuttx/lib.h | 2 +- include/nuttx/mmcsd.h | 2 +- include/nuttx/mqueue.h | 2 +- include/nuttx/page.h | 2 +- include/nuttx/pgalloc.h | 2 +- include/nuttx/pthread.h | 2 +- include/nuttx/pwm.h | 2 +- include/nuttx/regex.h | 2 +- include/nuttx/scsi.h | 2 +- include/nuttx/sdio.h | 2 +- include/nuttx/streams.h | 2 +- include/nuttx/time.h | 2 +- include/nuttx/vt100.h | 2 +- include/nuttx/wqueue.h | 2 +- include/pthread.h | 6 +-- include/stdlib.h | 2 +- sched/semaphore/semaphore.h | 2 +- 31 files changed, 87 insertions(+), 62 deletions(-) diff --git a/include/fcntl.h b/include/fcntl.h index c13bd90f95..381cf5cad8 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -46,7 +46,7 @@ #include /******************************************************************************** - * Definitions + * Pre-processor Definitions ********************************************************************************/ /* open flag settings for open() (and related APIs) */ diff --git a/include/fixedmath.h b/include/fixedmath.h index 4456361c76..69bb8394ae 100644 --- a/include/fixedmath.h +++ b/include/fixedmath.h @@ -43,7 +43,7 @@ #include /************************************************************************** - * Definitions + * Pre-processor Definitions **************************************************************************/ /* Common numbers */ diff --git a/include/mqueue.h b/include/mqueue.h index 67dd5842d9..e29dfb2c58 100644 --- a/include/mqueue.h +++ b/include/mqueue.h @@ -45,11 +45,7 @@ #include "queue.h" /******************************************************************************** - * Compilations Switches - ********************************************************************************/ - -/******************************************************************************** - * Definitions + * Pre-processor Definitions ********************************************************************************/ #define MQ_NONBLOCK O_NONBLOCK diff --git a/include/nuttx/ascii.h b/include/nuttx/ascii.h index 99c6fcf476..0261481c82 100644 --- a/include/nuttx/ascii.h +++ b/include/nuttx/ascii.h @@ -42,7 +42,7 @@ ****************************************************************************/ /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* All 7-bit ASCII codes */ diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 9347c9bef3..8276d7c9c6 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -41,7 +41,7 @@ ****************************************************************************/ /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /* GCC-specific definitions *************************************************/ diff --git a/include/nuttx/configdata.h b/include/nuttx/configdata.h index a12989f59e..e43f0b63cc 100644 --- a/include/nuttx/configdata.h +++ b/include/nuttx/configdata.h @@ -55,7 +55,7 @@ #ifdef CONFIG_PLATFORM_CONFIGDATA /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ /* CONFIG_AUDIO - Enables Audio driver support diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index f9e50cb303..420c9c360f 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -48,8 +48,10 @@ #include #include +#include + /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /* Stream flags for the fs_flags field of in struct file_struct */ @@ -57,7 +59,7 @@ #define __FS_FLAG_ERROR (1 << 1) /* Error detected by any operation */ /**************************************************************************** - * Type Definitions + * Public Type Definitions ****************************************************************************/ /* This structure is provided by devices when they are registered with the @@ -66,7 +68,6 @@ struct file; struct pollfd; - struct file_operations { /* The device driver open method differs from the mountpoint open method */ @@ -114,9 +115,9 @@ struct block_operations int (*open)(FAR struct inode *inode); int (*close)(FAR struct inode *inode); ssize_t (*read)(FAR struct inode *inode, FAR unsigned char *buffer, - size_t start_sector, unsigned int nsectors); + size_t start_sector, unsigned int nsectors); ssize_t (*write)(FAR struct inode *inode, FAR const unsigned char *buffer, - size_t start_sector, unsigned int nsectors); + size_t start_sector, unsigned int nsectors); int (*geometry)(FAR struct inode *inode, FAR struct geometry *geometry); int (*ioctl)(FAR struct inode *inode, int cmd, unsigned long arg); }; @@ -140,16 +141,17 @@ struct mountpt_operations */ int (*open)(FAR struct file *filep, FAR const char *relpath, - int oflags, mode_t mode); + int oflags, mode_t mode); - /* The following methods must be identical in signature and position because - * the struct file_operations and struct mountp_operations are treated like - * unions. + /* The following methods must be identical in signature and position + * because the struct file_operations and struct mountp_operations are + * treated like unions. */ int (*close)(FAR struct file *filep); ssize_t (*read)(FAR struct file *filep, FAR char *buffer, size_t buflen); - ssize_t (*write)(FAR struct file *filep, FAR const char *buffer, size_t buflen); + ssize_t (*write)(FAR struct file *filep, FAR const char *buffer, + size_t buflen); off_t (*seek)(FAR struct file *filep, off_t offset, int whence); int (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg); @@ -165,43 +167,74 @@ struct mountpt_operations /* Directory operations */ - int (*opendir)(FAR struct inode *mountpt, FAR const char *relpath, FAR struct fs_dirent_s *dir); - int (*closedir)(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir); - int (*readdir)(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir); - int (*rewinddir)(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir); + int (*opendir)(FAR struct inode *mountpt, FAR const char *relpath, + FAR struct fs_dirent_s *dir); + int (*closedir)(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); + int (*readdir)(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); + int (*rewinddir)(FAR struct inode *mountpt, + FAR struct fs_dirent_s *dir); /* General volume-related mountpoint operations: */ - int (*bind)(FAR struct inode *blkdriver, FAR const void *data, FAR void **handle); + int (*bind)(FAR struct inode *blkdriver, FAR const void *data, + FAR void **handle); int (*unbind)(FAR void *handle, FAR struct inode **blkdriver); - int (*statfs)(FAR struct inode *mountpt, FAR struct statfs *buf); /* Operations on paths */ int (*unlink)(FAR struct inode *mountpt, FAR const char *relpath); - int (*mkdir)(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode); + int (*mkdir)(FAR struct inode *mountpt, FAR const char *relpath, + mode_t mode); int (*rmdir)(FAR struct inode *mountpt, FAR const char *relpath); - int (*rename)(FAR struct inode *mountpt, FAR const char *oldrelpath, FAR const char *newrelpath); - int (*stat)(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf); + int (*rename)(FAR struct inode *mountpt, FAR const char *oldrelpath, + FAR const char *newrelpath); + int (*stat)(FAR struct inode *mountpt, FAR const char *relpath, + FAR struct stat *buf); - /* NOTE: More operations will be needed here to support: disk usage stats - * file stat(), file attributes, file truncation, etc. + /* NOTE: More operations will be needed here to support: disk usage + * stats file stat(), file attributes, file truncation, etc. */ }; #endif /* CONFIG_DISABLE_MOUNTPOUNT */ +/* Named OS resources are also maintained by the VFS. This includes: + * + * - Named semaphores: sem_open(), sem_close(), and sem_unlink() + * - POSIX Message Queues: mq_open() and mq_close() + * - Shared memory: shm_open() and shm_unlink(); + * + * These are a special case in that they do not follow quite the same + * pattern as the other file system types in that they have no read or + * write methods. + * + * Each inode type carries a payload specific to the OS resource; + * Only the contents of struct special_operations is visible to the VFS. + */ + +struct inode; +struct special_operations +{ + int (*open)(FAR struct inode *inode); + int (*close)(FAR struct inode *inode); + int (*unlink)(FAR struct inode *inode, FAR const char *relpath); +}; + /* These are the various kinds of operations that can be associated with * an inode. */ union inode_ops_u { - FAR const struct file_operations *i_ops; /* Driver operations for inode */ + FAR const struct file_operations *i_ops; /* Driver operations for inode */ #ifndef CONFIG_DISABLE_MOUNTPOUNT - FAR const struct block_operations *i_bops; /* Block driver operations */ - FAR const struct mountpt_operations *i_mops; /* Operations on a mountpoint */ + FAR const struct block_operations *i_bops; /* Block driver operations */ + FAR const struct mountpt_operations *i_mops; /* Operations on a mountpoint */ #endif + FAR const struct special_operations *i_xops; /* Generic operations on OS resources */ + FAR const struct semaphore_operations *i_sops; /* Operations for named semaphores */ }; /* This structure represents one inode in the Nuttx pseudo-file system */ diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 0d9f594a1c..5b74687f29 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -43,7 +43,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* General ioctl definitions ************************************************/ /* Each NuttX ioctl commands are uint16_t's consisting of an 8-bit type diff --git a/include/nuttx/fs/nxffs.h b/include/nuttx/fs/nxffs.h index 60c3af1e93..0a0917f7c8 100644 --- a/include/nuttx/fs/nxffs.h +++ b/include/nuttx/fs/nxffs.h @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ /* If the erased state of FLASH memory is anything other than 0xff, then this diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h index 35314f2453..120087937f 100644 --- a/include/nuttx/fs/procfs.h +++ b/include/nuttx/fs/procfs.h @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Data entry declaration prototypes ****************************************/ diff --git a/include/nuttx/fs/smart.h b/include/nuttx/fs/smart.h index 6b95a42bd9..50ae2c038c 100644 --- a/include/nuttx/fs/smart.h +++ b/include/nuttx/fs/smart.h @@ -47,7 +47,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Macros to hide implementation */ diff --git a/include/nuttx/init.h b/include/nuttx/init.h index 72520a4c18..2038427f39 100644 --- a/include/nuttx/init.h +++ b/include/nuttx/init.h @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h index 5283c6a4c7..9bdc1cf7d2 100644 --- a/include/nuttx/irq.h +++ b/include/nuttx/irq.h @@ -45,7 +45,7 @@ #endif /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* IRQ detach is a convenience definition. Detaching an interrupt handler * is equivalent to setting a NULL interrupt handler. diff --git a/include/nuttx/kthread.h b/include/nuttx/kthread.h index 01726f6f62..1adfde5fc5 100644 --- a/include/nuttx/kthread.h +++ b/include/nuttx/kthread.h @@ -45,7 +45,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/lib.h b/include/nuttx/lib.h index a5d289858f..609f4f86f7 100644 --- a/include/nuttx/lib.h +++ b/include/nuttx/lib.h @@ -45,7 +45,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/mmcsd.h b/include/nuttx/mmcsd.h index 03b7dafd87..230728c096 100644 --- a/include/nuttx/mmcsd.h +++ b/include/nuttx/mmcsd.h @@ -43,7 +43,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 27961717b6..fd5ab3164f 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -53,7 +53,7 @@ #if CONFIG_MQ_MAXMSGSIZE > 0 /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/page.h b/include/nuttx/page.h index 7f4d79e621..d6bfbcb8ca 100644 --- a/include/nuttx/page.h +++ b/include/nuttx/page.h @@ -51,7 +51,7 @@ #ifdef CONFIG_PAGING /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ diff --git a/include/nuttx/pgalloc.h b/include/nuttx/pgalloc.h index dc878790e9..c4b6ecab0a 100644 --- a/include/nuttx/pgalloc.h +++ b/include/nuttx/pgalloc.h @@ -49,7 +49,7 @@ #ifdef CONFIG_MM_PGALLOC /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ /* CONFIG_MM_PGALLOC - Enable page allocator support diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index cd896e8f8f..23f39dc5a6 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Default pthread attribute initializer */ diff --git a/include/nuttx/pwm.h b/include/nuttx/pwm.h index 228e151d7b..bda36d7198 100644 --- a/include/nuttx/pwm.h +++ b/include/nuttx/pwm.h @@ -64,7 +64,7 @@ #ifdef CONFIG_PWM /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ /* CONFIG_PWM - Enables because PWM driver support diff --git a/include/nuttx/regex.h b/include/nuttx/regex.h index 030823a6f6..2d1e270ae1 100644 --- a/include/nuttx/regex.h +++ b/include/nuttx/regex.h @@ -45,7 +45,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/scsi.h b/include/nuttx/scsi.h index 6d0aa5b209..3cf589085d 100644 --- a/include/nuttx/scsi.h +++ b/include/nuttx/scsi.h @@ -57,7 +57,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* SCSI commands ************************************************************/ diff --git a/include/nuttx/sdio.h b/include/nuttx/sdio.h index fd74eecc3a..5bd80329c0 100644 --- a/include/nuttx/sdio.h +++ b/include/nuttx/sdio.h @@ -49,7 +49,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* SDIO events needed by the driver diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index 848fb85f47..01ec965c3a 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -44,7 +44,7 @@ #include /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/include/nuttx/time.h b/include/nuttx/time.h index 106eb79810..cccacdf933 100644 --- a/include/nuttx/time.h +++ b/include/nuttx/time.h @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* If Gregorian time is not supported, then neither is Julian */ diff --git a/include/nuttx/vt100.h b/include/nuttx/vt100.h index 1dca7619d9..2d18fad375 100644 --- a/include/nuttx/vt100.h +++ b/include/nuttx/vt100.h @@ -44,7 +44,7 @@ #include /******************************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ********************************************************************************************/ #define VT100_SETNL {ASCII_ESC, '[', '2', '0', 'h'} /* Set new line mode */ diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index 72bb3a166e..323b4413db 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -48,7 +48,7 @@ #include /**************************************************************************** - * Pre-Processor Definitions + * Pre-processor Definitions ****************************************************************************/ /* Configuration ************************************************************/ /* CONFIG_SCHED_WORKQUEUE. Create a dedicated "worker" thread to diff --git a/include/pthread.h b/include/pthread.h index 404df642af..a7b0b5c9b0 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -54,7 +54,7 @@ #include /* Needed for struct timespec */ /******************************************************************************** - * Compilation Switches + * Pre-processor Definitions ********************************************************************************/ /* Standard POSIX switches */ @@ -67,10 +67,6 @@ # define _POSIX_THREAD_ATTR_STACKSIZE #endif -/******************************************************************************** - * Definitions - ********************************************************************************/ - /* Values for the process shared (pshared) attribute */ #define PTHREAD_PROCESS_PRIVATE 0 diff --git a/include/stdlib.h b/include/stdlib.h index 4ef0188be9..127b35163d 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -46,7 +46,7 @@ #include /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /* The C standard specifies two constants, EXIT_SUCCESS and diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index 00e47c3fda..4d62bda652 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -75,7 +75,7 @@ typedef struct nsem_s nsem_t; * Public Variables ****************************************************************************/ -/* This is a list of dyanamically allocated named semaphores */ +/* This is a list of dynamically allocated named semaphores */ extern dq_queue_t g_nsems;