Add structures to manage block drivers
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@207 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
6a2863c3fd
commit
8bdcd7c208
@ -1,5 +1,5 @@
|
||||
/************************************************************
|
||||
* fs.h
|
||||
/****************************************************************************
|
||||
* nutts/fs.h
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
@ -31,63 +31,108 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __FS_H
|
||||
#define __FS_H
|
||||
#ifndef __NUTTX_FS_H
|
||||
#define __NUTTX_FS_H
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <semaphore.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure is provided by filesystems when they are
|
||||
* registered with the system. It is used to call back to
|
||||
* perform fs/device specific operations.
|
||||
/* This structure is provided by devices when they are registered with the
|
||||
* system. It is used to call back to perform device specific operations.
|
||||
*/
|
||||
|
||||
struct file;
|
||||
struct file_operations
|
||||
{
|
||||
int (*open)(FAR struct file *);
|
||||
int (*close)(FAR struct file *);
|
||||
ssize_t (*read)(FAR struct file *, char *, size_t);
|
||||
ssize_t (*write)(FAR struct file *, const char *, size_t);
|
||||
int (*open)(FAR struct file *filp);
|
||||
int (*close)(FAR struct file *filp);
|
||||
ssize_t (*read)(FAR struct file *filp, char *buffer, size_t buflen);
|
||||
ssize_t (*write)(FAR struct file *filp, const char *buffer, size_t buflen);
|
||||
off_t (*seek)(FAR struct file *filp, off_t offset, int whence);
|
||||
int (*ioctl)(FAR struct file *filp, int cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
/* This structure provides information about the state of a block driver */
|
||||
|
||||
struct geometry
|
||||
{
|
||||
boolean geo_available; /* False if the device is not available */
|
||||
size_t geo_nsectors; /* Number of sectors on the device */
|
||||
size_t geo_sectorsize; /* Size of one sector */
|
||||
};
|
||||
|
||||
/* This structure is provided by block devices when they register with the
|
||||
* system. It is used by file systems to perform filesystem transfers.
|
||||
*/
|
||||
|
||||
struct block_operations
|
||||
{
|
||||
int (*open)(FAR struct file *filp);
|
||||
int (*close)(FAR struct file *filp);
|
||||
ssize_t (*read)(FAR struct file *filp, char *buffer,
|
||||
size_t start_sector, size_t nsectors);
|
||||
ssize_t (*write)(FAR struct file *filp, const char *buffer,
|
||||
size_t start_sector, size_t nsectors);
|
||||
size_t (*geometry)(FAR struct file *filp, struct geometry *geometry);
|
||||
int (*ioctl)(FAR struct file *, int, unsigned long);
|
||||
};
|
||||
|
||||
/* This structure is provided by a filesystem to describe a mount point.
|
||||
* Note that this structure differs from file_operations ONLY in the form of
|
||||
* the open method. Once the file is opened, it can be accessed either as a
|
||||
* struct file_operations or struct mountpt_operations
|
||||
*/
|
||||
|
||||
struct mountpt_operations
|
||||
{
|
||||
int (*open)(FAR struct file *filp, const char *rel_path);
|
||||
int (*close)(FAR struct file *filp);
|
||||
ssize_t (*read)(FAR struct file *filp, char *buffer, size_t buflen);
|
||||
ssize_t (*write)(FAR struct file *filp, const char *buffer, size_t buflen);
|
||||
off_t (*seek)(FAR struct file *filp, off_t offset, int whence);
|
||||
int (*ioctl)(FAR struct file *filp, int cmd, unsigned long arg);
|
||||
};
|
||||
|
||||
/* This structure represents one inode in the Nuttx psuedo-file system */
|
||||
|
||||
struct inode
|
||||
{
|
||||
FAR struct inode *i_peer; /* Pointer to inode at same level */
|
||||
FAR struct inode *i_child; /* Pointer to inode at lower level */
|
||||
struct file_operations *i_ops; /* Driver file operations for inode */
|
||||
sint16 i_crefs; /* References to inode */
|
||||
uint16 i_flags; /* flags for inode */
|
||||
FAR struct inode *i_peer; /* Pointer to same level inode */
|
||||
FAR struct inode *i_child; /* Pointer to lower level inode */
|
||||
sint16 i_crefs; /* References to inode */
|
||||
uint16 i_flags; /* flags for inode */
|
||||
union
|
||||
{
|
||||
const struct file_operations *i_ops; /* Driver operations for inode */
|
||||
const struct block_operations *i_bops; /* Block driver operations */
|
||||
const struct mountpt_operations *i_mops; /* Operations on a mountpoint */
|
||||
} u;
|
||||
#ifdef CONFIG_FILE_MODE
|
||||
mode_t i_mode; /* Access mode flags */
|
||||
mode_t i_mode; /* Access mode flags */
|
||||
#endif
|
||||
FAR void *i_private; /* Driver private data */
|
||||
char i_name[1]; /* Name of inode (variable length) */
|
||||
FAR void *i_private; /* Driver private data */
|
||||
char i_name[1]; /* Name of inode (variable) */
|
||||
};
|
||||
#define FSNODE_SIZE(n) (sizeof(struct inode) + (n))
|
||||
|
||||
/* This is the underlying representation of a ropen file.
|
||||
* A file descriptor is an index into an array of such types.
|
||||
* The type associates the file descriptor to the file state
|
||||
* and to a set of inode operations.
|
||||
/* This is the underlying representation of an open file. A file
|
||||
* descriptor is an index into an array of such types. The type associates
|
||||
* the file descriptor to the file state and to a set of inode operations.
|
||||
*/
|
||||
|
||||
struct file
|
||||
@ -95,6 +140,7 @@ struct file
|
||||
int f_oflags; /* Open mode flags */
|
||||
off_t f_pos; /* File position */
|
||||
FAR struct inode *f_inode; /* Driver interface */
|
||||
void *f_priv; /* Per file driver private data */
|
||||
};
|
||||
|
||||
/* This defines a list of files indexed by the file descriptor */
|
||||
@ -142,9 +188,9 @@ struct streamlist
|
||||
};
|
||||
#endif /* CONFIG_NFILE_STREAMS */
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
@ -154,23 +200,37 @@ extern "C" {
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* fs_inode.c ***********************************************/
|
||||
/* fs_inode.c ***************************************************************/
|
||||
|
||||
/* These interfaces are used by drivers to register their
|
||||
* inodes in the inode tree.
|
||||
*/
|
||||
|
||||
EXTERN void weak_function fs_initialize(void);
|
||||
EXTERN STATUS register_inode(const char *path,
|
||||
struct file_operations *fops,
|
||||
mode_t mode, void *private);
|
||||
EXTERN STATUS unregister_inode(const char *path);
|
||||
|
||||
/* fs_open.c ************************************************/
|
||||
/* fs_registerdriver.c ******************************************************/
|
||||
|
||||
EXTERN STATUS register_driver(const char *path,
|
||||
const struct file_operations *fops,
|
||||
mode_t mode, void *private);
|
||||
|
||||
/* fs_registerdriver.c ******************************************************/
|
||||
|
||||
EXTERN STATUS register_blockdriver(const char *path,
|
||||
const struct block_operations *bops,
|
||||
mode_t mode, void *private);
|
||||
|
||||
/* fs_inoderemove.c *********************************************************/
|
||||
|
||||
EXTERN STATUS inode_remove(const char *path);
|
||||
#define unregister_driver(p) inode_remove(p)
|
||||
#define unregister_blockdriver(p) inode_remove(p)
|
||||
|
||||
/* fs_open.c ****************************************************************/
|
||||
|
||||
EXTERN int inode_checkflags(FAR struct inode *inode, int oflags);
|
||||
|
||||
/* fs_files.c ***********************************************/
|
||||
/* fs_files.c ***************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS >0
|
||||
EXTERN FAR struct filelist *files_alloclist(void);
|
||||
@ -179,7 +239,7 @@ EXTERN int files_releaselist(FAR struct filelist *list);
|
||||
EXTERN int files_dup(FAR struct file *filep1, FAR struct file *filep2);
|
||||
#endif
|
||||
|
||||
/* lib_fopen.c **********************************************/
|
||||
/* lib_fopen.c **************************************************************/
|
||||
|
||||
/* Used by the OS to clone stdin, stdout, stderr */
|
||||
|
||||
@ -190,13 +250,13 @@ EXTERN FAR struct file_struct *lib_fdopen(int fd,
|
||||
FAR struct streamlist *slist);
|
||||
#endif
|
||||
|
||||
/* lib_fflush.c *********************************************/
|
||||
/* lib_fflush.c *************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
EXTERN void lib_flushall(FAR struct streamlist *list);
|
||||
#endif
|
||||
|
||||
/* drivers **************************************************/
|
||||
/* drivers ******************************************************************/
|
||||
|
||||
/* Call in of these to register the corresponding default
|
||||
* default drivers in the drivers/ subdirectory
|
||||
@ -210,4 +270,4 @@ EXTERN void devnull_register(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FS_H */
|
||||
#endif /* __NUTTX_FS_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user