diff options
| author | bernard <[email protected]> | 2017-10-15 22:44:53 +0800 |
|---|---|---|
| committer | bernard <[email protected]> | 2017-10-15 22:44:53 +0800 |
| commit | 0f5a68a55e2a3c44f1e85029d22de6180ad30390 (patch) | |
| tree | 300fe8aa92ce781200aa807d39ed4c5ed750a1ed /components/dfs/include | |
| parent | 5c7b16d00bdb536a694e6e31a2e0a1c33cb9dcb9 (diff) | |
[dfs] add poll/select
1. Add poll/select APIs;
2. Add wait queue implementation;
3. Remove DFS_STATUS_* code and use errno;
4. Add pipe API;
5. Use a standalone fops in DFS;
Diffstat (limited to 'components/dfs/include')
| -rw-r--r-- | components/dfs/include/dfs.h | 80 | ||||
| -rw-r--r-- | components/dfs/include/dfs_def.h | 316 | ||||
| -rw-r--r-- | components/dfs/include/dfs_elm.h | 38 | ||||
| -rw-r--r-- | components/dfs/include/dfs_file.h | 52 | ||||
| -rw-r--r-- | components/dfs/include/dfs_fs.h | 66 | ||||
| -rw-r--r-- | components/dfs/include/dfs_init.h | 39 | ||||
| -rw-r--r-- | components/dfs/include/dfs_posix.h | 171 | ||||
| -rw-r--r-- | components/dfs/include/dfs_private.h | 21 |
8 files changed, 274 insertions, 509 deletions
diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index 9ef14d3cfc..f1ea7fa1a4 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -25,17 +25,95 @@ #ifndef __DFS_H__ #define __DFS_H__ +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> #include <string.h> +#include <sys/types.h> + +#include <time.h> +#include <rtthread.h> +#include <rtdevice.h> + +#ifndef DFS_FILESYSTEMS_MAX +#define DFS_FILESYSTEMS_MAX 2 +#endif + +#ifndef DFS_FD_MAX +#define DFS_FD_MAX 4 +#endif + +/* + * skip stdin/stdout/stderr normally + */ +#ifndef DFS_FD_OFFSET +#define DFS_FD_OFFSET 3 +#endif + +#ifndef DFS_PATH_MAX +#define DFS_PATH_MAX 256 +#endif + +#ifndef SECTOR_SIZE +#define SECTOR_SIZE 512 +#endif + +#ifndef DFS_FILESYSTEM_TYPES_MAX +#define DFS_FILESYSTEM_TYPES_MAX 2 +#endif + +#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */ +#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */ + +/* File types */ +#define FT_REGULAR 0 /* regular file */ +#define FT_SOCKET 1 /* socket file */ +#define FT_DIRECTORY 2 /* directory */ +#define FT_USER 3 /* user defined */ + +/* File flags */ +#define DFS_F_OPEN 0x01000000 +#define DFS_F_DIRECTORY 0x02000000 +#define DFS_F_EOF 0x04000000 +#define DFS_F_ERR 0x08000000 #ifdef __cplusplus extern "C" { #endif -#define NO_WORKING_DIR "system does not support working directory\n" +struct stat +{ + struct rt_device* st_dev; + uint16_t st_mode; + uint32_t st_size; + time_t st_mtime; + uint32_t st_blksize; +}; + +struct statfs +{ + size_t f_bsize; /* block size */ + size_t f_blocks; /* total data blocks in file system */ + size_t f_bfree; /* free blocks in file system */ +}; + +struct dirent +{ + uint8_t d_type; /* The type of the file */ + uint8_t d_namlen; /* The length of the not including the terminating null file name */ + uint16_t d_reclen; /* length of this record */ + char d_name[DFS_PATH_MAX]; /* The null-terminated file name */ +}; + +/* Initialization of dfs */ +int dfs_init(void); char *dfs_normalize_path(const char *directory, const char *filename); const char *dfs_subdir(const char *directory, const char *filename); +void dfs_lock(void); +void dfs_unlock(void); + /* FD APIs */ int fd_new(void); struct dfs_fd *fd_get(int fd); diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h deleted file mode 100644 index 0f75a5162b..0000000000 --- a/components/dfs/include/dfs_def.h +++ /dev/null @@ -1,316 +0,0 @@ -/* - * File : dfs_def.h - * This file is part of Device File System in RT-Thread RTOS - * COPYRIGHT (C) 2004-2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2004-10-01 Beranard The first version. - * 2004-10-14 Beranard Clean up the code. - * 2005-01-22 Beranard Clean up the code, port to MinGW - */ - -#ifndef __DFS_DEF_H__ -#define __DFS_DEF_H__ - -#include <rtthread.h> - -#ifndef __D_FS__ -#define __D_FS__ -#endif - -#define DEVICE_GETGEOME 0 -#define DEVICE_GETINFO 1 -#define DEVICE_FORMAT 2 -#define DEVICE_CLEAN_SECTOR 3 - -/* File flags */ -#define DFS_F_OPEN 0x01000000 -#define DFS_F_DIRECTORY 0x02000000 -#define DFS_F_EOF 0x04000000 -#define DFS_F_ERR 0x08000000 - -#ifndef DFS_PATH_MAX -#define DFS_PATH_MAX 256 -#endif - -#ifndef SECTOR_SIZE -#define SECTOR_SIZE 512 -#endif - -#ifndef DFS_FILESYSTEM_TYPES_MAX -#define DFS_FILESYSTEM_TYPES_MAX 4 -#endif - -#define DFS_DEBUG_INFO 0x01 -#define DFS_DEBUG_WARNING 0x02 -#define DFS_DEBUG_ERROR 0x04 -#define DFS_DEBUG_LEVEL (DFS_DEBUG_INFO | DFS_DEBUG_WARNING | DFS_DEBUG_ERROR) - -/* #define DFS_DEBUG */ -#ifdef DFS_DEBUG -#define dfs_log(level, x) do { if (level & DFS_DEBUG_LEVEL) \ - {rt_kprintf("DFS %s, %d:", __FUNCTION__, __LINE__); rt_kprintf x; \ - rt_kprintf ("\n");}}while (0) -#else -#define dfs_log(level, x) -#endif - -#if defined(RT_USING_NEWLIB) -#include <string.h> -#include <sys/stat.h> /* used for struct stat */ -#include <sys/statfs.h> /* used for struct statfs */ -#include <sys/errno.h> /* used for error number */ -#include <sys/fcntl.h> /* used for operation flags */ -#include <sys/unistd.h> /* used for SEEK_SET/CUR/END */ -#include <dirent.h> /* used for struct dirent */ - -/* Device error codes */ -#define DFS_STATUS_OK 0 /* no error */ -#define DFS_STATUS_ENOENT ENOENT /* No such file or directory */ -#define DFS_STATUS_EIO EIO /* I/O error */ -#define DFS_STATUS_ENXIO ENXIO /* No such device or address */ -#define DFS_STATUS_EBADF EBADF /* Bad file number */ -#define DFS_STATUS_EAGAIN EAGAIN /* Try again */ -#define DFS_STATUS_ENOMEM ENOMEM /* no memory */ -#define DFS_STATUS_EBUSY EBUSY /* Device or resource busy */ -#define DFS_STATUS_EEXIST EEXIST /* File exists */ -#define DFS_STATUS_EXDEV EXDEV /* Cross-device link */ -#define DFS_STATUS_ENODEV ENODEV /* No such device */ -#define DFS_STATUS_ENOTDIR ENOTDIR /* Not a directory */ -#define DFS_STATUS_EISDIR EISDIR /* Is a directory */ -#define DFS_STATUS_EINVAL EINVAL /* Invalid argument */ -#define DFS_STATUS_ENOSPC ENOSPC /* No space left on device */ -#define DFS_STATUS_EROFS EROFS /* Read-only file system */ -#define DFS_STATUS_ENOSYS ENOSYS /* Function not implemented */ -#define DFS_STATUS_ENOTEMPTY ENOTEMPTY /* Directory not empty */ - -/* Operation flags */ -#define DFS_O_RDONLY O_RDONLY -#define DFS_O_WRONLY O_WRONLY -#define DFS_O_RDWR O_RDWR -#define DFS_O_ACCMODE O_ACCMODE -#define DFS_O_CREAT O_CREAT -#define DFS_O_EXCL O_EXCL -#define DFS_O_TRUNC O_TRUNC -#define DFS_O_APPEND O_APPEND -#define DFS_O_DIRECTORY O_DIRECTORY - -/* Seek flags */ -#define DFS_SEEK_SET SEEK_SET -#define DFS_SEEK_CUR SEEK_CUR -#define DFS_SEEK_END SEEK_END - -/* Stat codes */ -#define DFS_S_IFMT S_IFMT -#define DFS_S_IFSOCK S_IFSOCK -#define DFS_S_IFLNK S_IFLNK -#define DFS_S_IFREG S_IFREG -#define DFS_S_IFBLK S_IFBLK -#define DFS_S_IFDIR S_IFDIR -#define DFS_S_IFCHR S_IFCHR -#define DFS_S_IFIFO S_IFIFO -#define DFS_S_ISUID S_ISUID -#define DFS_S_ISGID S_ISGID -#define DFS_S_ISVTX S_ISVTX - -#define DFS_S_ISLNK(m) S_ISLNK(m) -#define DFS_S_ISREG(m) S_ISREG(m) -#define DFS_S_ISDIR(m) S_ISDIR(m) -#define DFS_S_ISCHR(m) S_ISCHR(m) -#define DFS_S_ISBLK(m) S_ISBLK(m) -#define DFS_S_ISFIFO(m) S_ISFIFO(m) -#define DFS_S_ISSOCK(m) S_ISSOCK(m) - -#define DFS_S_IRWXU S_IRWXU -#define DFS_S_IRUSR S_IRUSR -#define DFS_S_IWUSR S_IWUSR -#define DFS_S_IXUSR S_IXUSR - -#define DFS_S_IRWXG S_IRWXG -#define DFS_S_IRGRP S_IRGRP -#define DFS_S_IWGRP S_IWGRP -#define DFS_S_IXGRP S_IXGRP - -#define DFS_S_IRWXO S_IRWXO -#define DFS_S_IROTH S_IROTH -#define DFS_S_IWOTH S_IWOTH -#define DFS_S_IXOTH S_IXOTH - -/* Dirent types */ -#define DFS_DT_UNKNOWN DT_UNKNOWN -#define DFS_DT_REG DT_REG -#define DFS_DT_DIR DT_DIR - -#else - #ifdef RT_USING_MINILIBC - #include <string.h> - #else - typedef long off_t; - typedef int mode_t; - #endif - -/* Device error codes */ -#define DFS_STATUS_OK 0 /* no error */ -#define DFS_STATUS_ENOENT 2 /* No such file or directory */ -#define DFS_STATUS_EIO 5 /* I/O error */ -#define DFS_STATUS_ENXIO 6 /* No such device or address */ -#define DFS_STATUS_EBADF 9 /* Bad file number */ -#define DFS_STATUS_EAGAIN 11 /* Try again */ -#define DFS_STATUS_ENOMEM 12 /* no memory */ -#define DFS_STATUS_EBUSY 16 /* Device or resource busy */ -#define DFS_STATUS_EEXIST 17 /* File exists */ -#define DFS_STATUS_EXDEV 18 /* Cross-device link */ -#define DFS_STATUS_ENODEV 19 /* No such device */ -#define DFS_STATUS_ENOTDIR 20 /* Not a directory */ -#define DFS_STATUS_EISDIR 21 /* Is a directory */ -#define DFS_STATUS_EINVAL 22 /* Invalid argument */ -#define DFS_STATUS_ENOSPC 28 /* No space left on device */ -#define DFS_STATUS_EROFS 30 /* Read-only file system */ -#define DFS_STATUS_ENOSYS 38 /* Function not implemented */ -#define DFS_STATUS_ENOTEMPTY 39 /* Directory not empty */ - -/* Operation flags */ -#define DFS_O_RDONLY 0x0000000 -#define DFS_O_WRONLY 0x0000001 -#define DFS_O_RDWR 0x0000002 -#define DFS_O_ACCMODE 0x0000003 -#define DFS_O_CREAT 0x0000100 -#define DFS_O_EXCL 0x0000200 -#define DFS_O_TRUNC 0x0001000 -#define DFS_O_APPEND 0x0002000 -#define DFS_O_BINARY 0x0008000 -#define DFS_O_DIRECTORY 0x0200000 - -/* File flags */ -#define DFS_F_OPEN 0x01000000 -#define DFS_F_DIRECTORY 0x02000000 -#define DFS_F_EOF 0x04000000 -#define DFS_F_ERR 0x08000000 - -/* Seek flags */ -#ifdef __CC_ARM -#include <stdio.h> -#define DFS_SEEK_SET SEEK_SET -#define DFS_SEEK_CUR SEEK_CUR -#define DFS_SEEK_END SEEK_END -#elif defined(_MSC_VER) -#include <stdio.h> -#define DFS_SEEK_SET SEEK_SET -#define DFS_SEEK_CUR SEEK_CUR -#define DFS_SEEK_END SEEK_END -#else -#define DFS_SEEK_SET 0 -#define DFS_SEEK_CUR 1 -#define DFS_SEEK_END 2 -#endif - -/* Stat codes */ -#define DFS_S_IFMT 00170000 -#define DFS_S_IFSOCK 0140000 -#define DFS_S_IFLNK 0120000 -#define DFS_S_IFREG 0100000 -#define DFS_S_IFBLK 0060000 -#define DFS_S_IFDIR 0040000 -#define DFS_S_IFCHR 0020000 -#define DFS_S_IFIFO 0010000 -#define DFS_S_ISUID 0004000 -#define DFS_S_ISGID 0002000 -#define DFS_S_ISVTX 0001000 - -#define DFS_S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK) -#define DFS_S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG) -#define DFS_S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR) -#define DFS_S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR) -#define DFS_S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK) -#define DFS_S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO) -#define DFS_S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK) - -#define DFS_S_IRWXU 00700 -#define DFS_S_IRUSR 00400 -#define DFS_S_IWUSR 00200 -#define DFS_S_IXUSR 00100 - -#define DFS_S_IRWXG 00070 -#define DFS_S_IRGRP 00040 -#define DFS_S_IWGRP 00020 -#define DFS_S_IXGRP 00010 - -#define DFS_S_IRWXO 00007 -#define DFS_S_IROTH 00004 -#define DFS_S_IWOTH 00002 -#define DFS_S_IXOTH 00001 - -#ifdef _MSC_VER -#include <wchar.h> -#else -struct stat -{ - rt_device_t st_dev; - rt_uint16_t st_mode; - rt_uint32_t st_size; - rt_time_t st_mtime; -}; -#endif - -struct statfs -{ - rt_size_t f_bsize; /* block size */ - rt_size_t f_blocks; /* total data blocks in file system */ - rt_size_t f_bfree; /* free blocks in file system */ -}; - -/* File types */ -#define FT_REGULAR 0 /* regular file */ -#define FT_SOCKET 1 /* socket file */ -#define FT_DIRECTORY 2 /* directory */ -#define FT_USER 3 /* user defined */ - -/* Dirent types */ -#define DFS_DT_UNKNOWN 0x00 -#define DFS_DT_REG 0x01 -#define DFS_DT_DIR 0x02 - -struct dirent -{ - rt_uint8_t d_type; /* The type of the file */ - rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */ - rt_uint16_t d_reclen; /* length of this record */ - char d_name[DFS_PATH_MAX]; /* The null-terminated file name */ -}; -#endif - -/* file descriptor */ -#define DFS_FD_MAGIC 0xfdfd -struct dfs_fd -{ - rt_uint16_t magic; /* file descriptor magic number */ - rt_uint16_t type; /* Type (regular or socket) */ - char *path; /* Name (below mount point) */ - int ref_count; /* Descriptor reference count */ - - struct dfs_filesystem *fs; /* Resident file system */ - - rt_uint32_t flags; /* Descriptor flags */ - rt_size_t size; /* Size in bytes */ - rt_off_t pos; /* Current file position */ - - void *data; /* Specific file system data */ -}; - -#endif - diff --git a/components/dfs/include/dfs_elm.h b/components/dfs/include/dfs_elm.h deleted file mode 100644 index da8a217005..0000000000 --- a/components/dfs/include/dfs_elm.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * File : dfs_elm.h - * This file is part of Device File System in RT-Thread RTOS - * COPYRIGHT (C) 2008-2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2010-02-06 Bernard Add elm_init function declaration - */ - -#ifndef __DFS_ELM_H__ -#define __DFS_ELM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -int elm_init(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/dfs/include/dfs_file.h b/components/dfs/include/dfs_file.h index a574bdc334..5dc3946899 100644 --- a/components/dfs/include/dfs_file.h +++ b/components/dfs/include/dfs_file.h @@ -25,21 +25,63 @@ #ifndef __DFS_FILE_H__ #define __DFS_FILE_H__ -#include <dfs_def.h> #include <dfs.h> #include <dfs_fs.h> +#ifdef __cplusplus +extern "C" { +#endif + +struct rt_pollreq; + +struct dfs_file_ops +{ + int (*open) (struct dfs_fd *fd); + int (*close) (struct dfs_fd *fd); + int (*ioctl) (struct dfs_fd *fd, int cmd, void *args); + int (*read) (struct dfs_fd *fd, void *buf, size_t count); + int (*write) (struct dfs_fd *fd, const void *buf, size_t count); + int (*flush) (struct dfs_fd *fd); + int (*lseek) (struct dfs_fd *fd, off_t offset); + int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count); + + int (*poll) (struct dfs_fd *fd, struct rt_pollreq *req); +}; + +/* file descriptor */ +#define DFS_FD_MAGIC 0xfdfd +struct dfs_fd +{ + uint16_t magic; /* file descriptor magic number */ + uint16_t type; /* Type (regular or socket) */ + + char *path; /* Name (below mount point) */ + int ref_count; /* Descriptor reference count */ + + const struct dfs_file_ops *fops; + + uint32_t flags; /* Descriptor flags */ + size_t size; /* Size in bytes */ + off_t pos; /* Current file position */ + + void *data; /* Specific file system data */ +}; + int dfs_file_open(struct dfs_fd *fd, const char *path, int flags); int dfs_file_close(struct dfs_fd *fd); int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args); -int dfs_file_read(struct dfs_fd *fd, void *buf, rt_size_t len); -int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, rt_size_t nbytes); +int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len); +int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes); int dfs_file_unlink(const char *path); -int dfs_file_write(struct dfs_fd *fd, const void *buf, rt_size_t len); +int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len); int dfs_file_flush(struct dfs_fd *fd); -int dfs_file_lseek(struct dfs_fd *fd, rt_off_t offset); +int dfs_file_lseek(struct dfs_fd *fd, off_t offset); + int dfs_file_stat(const char *path, struct stat *buf); int dfs_file_rename(const char *oldpath, const char *newpath); +#ifdef __cplusplus +} #endif +#endif diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 498aa5db54..38d8766ee1 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -25,20 +25,24 @@ #ifndef __DFS_FS_H__ #define __DFS_FS_H__ -#include <dfs_def.h> +#include <dfs.h> -#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */ -#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */ +#ifdef __cplusplus +extern "C" { +#endif /* Pre-declaration */ struct dfs_filesystem; struct dfs_fd; -/* File system operations struct */ -struct dfs_filesystem_operation +/* File system operations */ +struct dfs_filesystem_ops { char *name; - rt_uint32_t flags; /* flags for file system operations */ + uint32_t flags; /* flags for file system operations */ + + /* operations for file */ + const struct dfs_file_ops *fops; /* mount and unmount file system */ int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data); @@ -48,15 +52,6 @@ struct dfs_filesystem_operation int (*mkfs) (rt_device_t devid); int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf); - int (*open) (struct dfs_fd *fd); - int (*close) (struct dfs_fd *fd); - int (*ioctl) (struct dfs_fd *fd, int cmd, void *args); - int (*read) (struct dfs_fd *fd, void *buf, rt_size_t count); - int (*write) (struct dfs_fd *fd, const void *buf, rt_size_t count); - int (*flush) (struct dfs_fd *fd); - int (*lseek) (struct dfs_fd *fd, rt_off_t offset); - int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, rt_uint32_t count); - int (*unlink) (struct dfs_filesystem *fs, const char *pathname); int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf); int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath); @@ -68,7 +63,7 @@ struct dfs_filesystem rt_device_t dev_id; /* Attached device */ char *path; /* File system mount point */ - const struct dfs_filesystem_operation *ops; /* Operations for file system type */ + const struct dfs_filesystem_ops *ops; /* Operations for file system type */ void *data; /* Specific file system data */ }; @@ -76,47 +71,42 @@ struct dfs_filesystem /* file system partition table */ struct dfs_partition { - rt_uint8_t type; /* file system type */ - rt_off_t offset; /* partition start offset */ - rt_size_t size; /* partition size */ + uint8_t type; /* file system type */ + off_t offset; /* partition start offset */ + size_t size; /* partition size */ rt_sem_t lock; }; /* mount table */ struct dfs_mount_tbl { - const char *device_name; - const char *path; - const char *filesystemtype; - unsigned long rwflag; - const void *data; + const char *device_name; + const char *path; + const char *filesystemtype; + unsigned long rwflag; + const void *data; }; -int dfs_register(const struct dfs_filesystem_operation *ops); +int dfs_register(const struct dfs_filesystem_ops *ops); struct dfs_filesystem *dfs_filesystem_lookup(const char *path); const char* dfs_filesystem_get_mounted_path(struct rt_device* device); -rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, - rt_uint8_t *buf, - rt_uint32_t pindex); +int dfs_filesystem_get_partition(struct dfs_partition *part, + uint8_t *buf, + uint32_t pindex); int dfs_mount(const char *device_name, const char *path, const char *filesystemtype, - rt_uint32_t rwflag, + unsigned long rwflag, const void *data); int dfs_unmount(const char *specialfile); -/* extern variable */ -extern const struct dfs_filesystem_operation *filesystem_operation_table[]; -extern struct dfs_filesystem filesystem_table[]; -extern const struct dfs_mount_tbl mount_table[]; - -extern char working_directory[]; - -void dfs_lock(void); -void dfs_unlock(void); int dfs_mkfs(const char *fs_name, const char *device_name); int dfs_statfs(const char *path, struct statfs *buffer); +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/dfs/include/dfs_init.h b/components/dfs/include/dfs_init.h deleted file mode 100644 index b421bdcb04..0000000000 --- a/components/dfs/include/dfs_init.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * File : dfs_init.h - * This file is part of Device File System in RT-Thread RTOS - * COPYRIGHT (C) 2004-2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2005-02-21 Bernard The first version. - */ - -#ifndef __DFS_INIT_H__ -#define __DFS_INIT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Initialization of dfs */ -int dfs_init(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 2e417c1461..e775474f0a 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -20,81 +20,21 @@ * Change Logs: * Date Author Notes * 2009-05-27 Yi.qiu The first version. - * 2010-07-18 Bernard add stat and statfs structure definitions. + * 2010-07-18 Bernard add stat and statfs structure definitions. * 2011-05-16 Yi.qiu Change parameter name of rename, "new" is C++ key word. */ - + #ifndef __DFS_POSIX_H__ #define __DFS_POSIX_H__ #include <dfs_file.h> -#include <dfs_def.h> +#include <sys/time.h> /* for struct timeval */ #ifdef __cplusplus extern "C" { #endif -#if !defined(RT_USING_NEWLIB) -#define O_RDONLY DFS_O_RDONLY -#define O_WRONLY DFS_O_WRONLY -#define O_RDWR DFS_O_RDWR -#define O_ACCMODE DFS_O_ACCMODE -#define O_CREAT DFS_O_CREAT -#define O_EXCL DFS_O_EXCL -#define O_TRUNC DFS_O_TRUNC -#define O_APPEND DFS_O_APPEND -#define O_BINARY DFS_O_BINARY -#define O_DIRECTORY DFS_O_DIRECTORY - -#if !defined(_WIN32) -#define S_IFMT DFS_S_IFMT -#define S_IFSOCK DFS_S_IFSOCK -#define S_IFLNK DFS_S_IFLNK -#define S_IFREG DFS_S_IFREG -#define S_IFBLK DFS_S_IFBLK -#define S_IFDIR DFS_S_IFDIR -#define S_IFCHR DFS_S_IFCHR -#define S_IFIFO DFS_S_IFIFO -#define S_ISUID DFS_S_ISUID -#define S_ISGID DFS_S_ISGID -#define S_ISVTX DFS_S_ISVTX - -#define S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK) -#define S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG) -#define S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR) -#define S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR) -#define S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK) -#define S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO) -#define S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK) - -#define S_IRWXU DFS_S_IRWXU -#define S_IRUSR DFS_S_IRUSR -#define S_IWUSR DFS_S_IWUSR -#define S_IXUSR DFS_S_IXUSR - -#define S_IRWXG DFS_S_IRWXG -#define S_IRGRP DFS_S_IRGRP -#define S_IWGRP DFS_S_IWGRP -#define S_IXGRP DFS_S_IXGRP - -#define S_IRWXO DFS_S_IRWXO -#define S_IROTH DFS_S_IROTH -#define S_IWOTH DFS_S_IWOTH -#define S_IXOTH DFS_S_IXOTH -#endif - -#if defined(__CC_ARM) -#include <stdio.h> -#include <stdlib.h> -#elif defined(_MSC_VER) -#include <stdio.h> -#else -#define SEEK_SET DFS_SEEK_SET -#define SEEK_CUR DFS_SEEK_CUR -#define SEEK_END DFS_SEEK_END -#endif - -typedef struct +typedef struct { int fd; /* directory file */ char buf[512]; @@ -111,13 +51,6 @@ void seekdir(DIR *d, off_t offset); void rewinddir(DIR *d); int closedir(DIR* d); -#else -/* use newlib header file */ -#include <sys/stat.h> -#endif - -struct stat; - /* file api*/ int open(const char *file, int flags, int mode); int close(int d); @@ -134,7 +67,7 @@ int unlink(const char *pathname); int stat(const char *file, struct stat *buf); int fstat(int fildes, struct stat *buf); int fsync(int fildes); -int ioctl(int fildes, long cmd, void *data); +int ioctl(int fildes, int cmd, void *data); /* directory api*/ int rmdir(const char *path); @@ -144,6 +77,100 @@ char *getcwd(char *buf, size_t size); /* file system api */ int statfs(const char *path, struct statfs *buf); +int access(const char *path, int amode); +int pipe(int fildes[2]); +int mkfifo(const char *path, mode_t mode); + +/* poll and select */ + +#define POLLIN (0x01) +#define POLLRDNORM (0x01) +#define POLLRDBAND (0x01) +#define POLLPRI (0x01) + +#define POLLOUT (0x02) +#define POLLWRNORM (0x02) +#define POLLWRBAND (0x02) + +#define POLLERR (0x04) +#define POLLHUP (0x08) +#define POLLNVAL (0x10) + +#define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM) + +typedef unsigned int nfds_t; + +struct pollfd +{ + int fd; + short events; + short revents; +}; + +int poll(struct pollfd *fds, nfds_t nfds, int timeout); + + +#ifdef RT_USING_LWIP +/* we use lwIP's structure definitions. */ +#include <lwip/sockets.h> +#else + +#ifndef FD_SET + +/* Get the total number of descriptors that we will have to support */ + +#define FD_SETSIZE (12) + +/* We will use a 32-bit bitsets to represent the set of descriptors. How + * many uint32_t's do we need to span all descriptors? + */ + +#if FD_SETSIZE <= 32 +# define __SELECT_NUINT32 1 +#elif FD_SETSIZE <= 64 +# define __SELECT_NUINT32 2 +#elif FD_SETSIZE <= 96 +# define __SELECT_NUINT32 3 +#elif FD_SETSIZE <= 128 +# define __SELECT_NUINT32 4 +#elif FD_SETSIZE <= 160 +# define __SELECT_NUINT32 5 +#elif FD_SETSIZE <= 192 +# define __SELECT_NUINT32 6 +#elif FD_SETSIZE <= 224 +# define __SELECT_NUINT32 7 +#elif FD_SETSIZE <= 256 +# define __SELECT_NUINT32 8 +#else +# warning "Larger fd_set needed" +#endif + +/* These macros map a file descriptor to an index and bit number */ + +#define _FD_NDX(fd) ((fd) >> 5) +#define _FD_BIT(fd) ((fd) & 0x1f) + +/* Standard helper macros */ + +#define FD_CLR(fd,set) \ + ((((fd_set*)(set))->arr)[_FD_NDX(fd)] &= ~(1 << _FD_BIT(fd))) +#define FD_SET(fd,set) \ + ((((fd_set*)(set))->arr)[_FD_NDX(fd)] |= (1 << _FD_BIT(fd))) +#define FD_ISSET(fd,set) \ + (((((fd_set*)(set))->arr)[_FD_NDX(fd)] & (1 << _FD_BIT(fd))) != 0) +#define FD_ZERO(set) \ + memset((set), 0, sizeof(fd_set)) + +typedef struct +{ + uint32_t arr[__SELECT_NUINT32]; +}fd_set; +#endif + +#endif + +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); + #ifdef __cplusplus } #endif diff --git a/components/dfs/include/dfs_private.h b/components/dfs/include/dfs_private.h new file mode 100644 index 0000000000..d5d630b47e --- /dev/null +++ b/components/dfs/include/dfs_private.h @@ -0,0 +1,21 @@ +#ifndef DFS_PRIVATE_H__ +#define DFS_PRIVATE_H__ + +#include <dfs.h> + +// #define DBG_ENABLE +#define DBG_SECTION_NAME "[ DFS]" +#define DBG_COLOR +#define DBG_LEVEL DBG_LOG +#include <rtdbg.h> + +#define NO_WORKING_DIR "system does not support working directory\n" + +/* extern variable */ +extern const struct dfs_filesystem_ops *filesystem_operation_table[]; +extern struct dfs_filesystem filesystem_table[]; +extern const struct dfs_mount_tbl mount_table[]; + +extern char working_directory[]; + +#endif |
