summaryrefslogtreecommitdiff
path: root/components/dfs/include
diff options
context:
space:
mode:
author[email protected] <[email protected]>2010-07-18 16:15:53 +0000
committer[email protected] <[email protected]>2010-07-18 16:15:53 +0000
commit33feb176d09c8f5a6d9374a4276ebfc46ae44a4a (patch)
treeb1f2b0afa253dd7fb9270916c052ef50103d1e47 /components/dfs/include
parentfd12462d57140c6ea800cc741646ccc9f68c5509 (diff)
add flush, statfs, mkfs to device file system interface.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@802 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/dfs/include')
-rw-r--r--components/dfs/include/dfs_def.h58
-rw-r--r--components/dfs/include/dfs_fat.h29
-rw-r--r--components/dfs/include/dfs_fs.h51
-rw-r--r--components/dfs/include/dfs_posix.h38
-rw-r--r--components/dfs/include/dfs_raw.h38
-rw-r--r--components/dfs/include/dfs_util.h36
6 files changed, 76 insertions, 174 deletions
diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h
index 9abe6d5c27..e3c52dd957 100644
--- a/components/dfs/include/dfs_def.h
+++ b/components/dfs/include/dfs_def.h
@@ -1,20 +1,18 @@
/*
-+------------------------------------------------------------------------------
-| Device FileSystem
-+------------------------------------------------------------------------------
-| Copyright 2004, 2005 www.fayfayspace.org.
-| All rights reserved.
-|------------------------------------------------------------------------------
-| File : dfs_def.h, the definitions of Device FileSystem
-|------------------------------------------------------------------------------
-| Chang Logs:
-| Date Author notes
-| 2004-10-01 ffxz The first version.
-| 2004-10-14 ffxz Clean up the code.
-| 2005-01-22 ffxz Clean up the code, port to MinGW
-+------------------------------------------------------------------------------
-*/
-
+ * File : dfs_def.h
+ * This file is part of Device File System in RT-Thread RTOS
+ * COPYRIGHT (C) 2004-2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE.
+ *
+ * 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__
@@ -113,15 +111,6 @@
#define DEVICE_FORMAT 2
#define DEVICE_CLEAN_SECTOR 3
-struct device_geometry
-{
- rt_uint32_t sector_count; /* count of sectors */
- rt_uint32_t cylinder_count; /* count of cylinder */
- rt_uint32_t sectors_per_track; /* number of sectors per track */
- rt_uint32_t head_count; /* count of head */
- rt_uint32_t bytes_per_sector; /* number of bytes per sector */
-};
-
struct dfs_stat
{
rt_device_t st_dev;
@@ -130,7 +119,13 @@ struct dfs_stat
rt_time_t st_mtime;
rt_uint32_t st_blksize;
};
-#define stat dfs_stat
+
+struct dfs_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 */
@@ -141,7 +136,7 @@ struct dfs_stat
/* file descriptor */
struct dfs_fd
{
- char path[DFS_PATH_MAX + 1];/* Name (below mount point) */
+ char* path; /* Name (below mount point) */
int type; /* Type (regular or socket) */
int ref_count; /* Descriptor reference count */
@@ -162,14 +157,9 @@ struct dfs_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[256]; /* The null-terminated file name */
+ rt_uint16_t d_reclen; /* length of this record */
+ char d_name[DFS_PATH_MAX]; /* The null-terminated file name */
};
#define dirent dfs_dirent
-struct dfs_session
-{
- rt_mailbox_t mbox;
-};
-
#endif
diff --git a/components/dfs/include/dfs_fat.h b/components/dfs/include/dfs_fat.h
deleted file mode 100644
index 65af6cebb3..0000000000
--- a/components/dfs/include/dfs_fat.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-+------------------------------------------------------------------------------
-| Project : Device Filesystem
-+------------------------------------------------------------------------------
-| Copyright 2004, 2005 www.fayfayspace.org.
-| All rights reserved.
-|------------------------------------------------------------------------------
-| File : dfs_fat.h, FAT 12/16/32 file system definitions
-|------------------------------------------------------------------------------
-| Chang Logs:
-| Date Author Notes
-| 2003-03-30 ffxz
-+------------------------------------------------------------------------------
-*/
-
-#ifndef __DFS_FAT_H__
-#define __DFS_FAT_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int fatfs_init(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h
index c31d9585a2..8c0a2b04d9 100644
--- a/components/dfs/include/dfs_fs.h
+++ b/components/dfs/include/dfs_fs.h
@@ -1,17 +1,16 @@
/*
-+------------------------------------------------------------------------------
-| Project : Device Filesystem
-+------------------------------------------------------------------------------
-| Copyright 2004, 2005 www.fayfayspace.org.
-| All rights reserved.
-|------------------------------------------------------------------------------
-| File : dfs_fs.h, the filesystem related defines of Device FileSystem
-|------------------------------------------------------------------------------
-| Chang Logs:
-| Date Author Notes
-| 2005-02-22 ffxz The first version.
-+------------------------------------------------------------------------------
-*/
+ * File : dfs_fs.h
+ * This file is part of Device File System in RT-Thread RTOS
+ * COPYRIGHT (C) 2004-2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2005-02-22 Bernard The first version.
+ */
#ifndef __DFS_FS_H__
#define __DFS_FS_H__
@@ -26,16 +25,22 @@ struct dfs_dirent;
/* File system operations struct */
struct dfs_filesystem_operation
{
- char name[DFS_FS_NAME_MAX + 1];
+ char *name;
+ /* mount and unmount file system */
int (*mount) (struct dfs_filesystem* fs, unsigned long rwflag, const void* data);
int (*unmount) (struct dfs_filesystem* fs);
- int (*open) (struct dfs_fd* fd);
+ /* make a file system */
+ int (*mkfs) (const char* device_name);
+ int (*statfs) (struct dfs_filesystem* fs, struct dfs_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 (*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 dfs_dirent* dirp, rt_uint32_t count);
@@ -47,13 +52,12 @@ struct dfs_filesystem_operation
/* Mounted file system */
struct dfs_filesystem
{
- rt_device_t dev_id; /* Attached device */
+ rt_device_t dev_id; /* Attached device */
- char path[DFS_PATH_MAX + 1]; /* File system mount point */
- struct dfs_filesystem_operation* ops; /* Operations for file system type */
- rt_uint32_t block_id; /* Current block_id on attached device */
+ char* path; /* File system mount point */
+ const struct dfs_filesystem_operation* ops; /* Operations for file system type */
- void *data; /* Specific file system data */
+ void *data; /* Specific file system data */
};
/* file system partition table */
@@ -65,7 +69,7 @@ struct dfs_partition
rt_sem_t lock;
};
-int dfs_register(struct dfs_filesystem_operation* ops);
+int dfs_register(const struct dfs_filesystem_operation* ops);
struct dfs_filesystem* dfs_filesystem_lookup(const char *path);
rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex);
@@ -75,12 +79,13 @@ int dfs_mount(const char* device_name, const char* path,
int dfs_unmount(const char *specialfile);
/* extern variable */
-extern struct dfs_filesystem_operation* filesystem_operation_table[];
+extern const struct dfs_filesystem_operation* filesystem_operation_table[];
extern struct dfs_filesystem filesystem_table[];
extern char working_directory[];
void dfs_lock(void);
void dfs_unlock(void);
+int dfs_statfs(const char* path, struct dfs_statfs* buffer);
#endif
diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h
index b39ab2cb3e..ce1e94028b 100644
--- a/components/dfs/include/dfs_posix.h
+++ b/components/dfs/include/dfs_posix.h
@@ -1,21 +1,21 @@
/*
-+------------------------------------------------------------------------------
-| Project : Device Filesystem
-+------------------------------------------------------------------------------
-| Copyright 2004, 2005 www.fayfayspace.org.
-| All rights reserved.
-|------------------------------------------------------------------------------
-| File : dfs_posix.h, the filesystem related defines of Device FileSystem
-|------------------------------------------------------------------------------
-| Chang Logs:
-| Date Author Notes
-| 2009-05-27 Yi.qiu The first version.
-+------------------------------------------------------------------------------
-*/
+ * File : dfs_def.h
+ * This file is part of Device File System in RT-Thread RTOS
+ * COPYRIGHT (C) 2004-2010, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE.
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2009-05-27 Yi.qiu The first version.
+ * 2010-07-18 Bernard add stat and statfs structure definitions.
+ */
#ifndef __DFS_POSIX_H__
#define __DFS_POSIX_H__
-#include <dfs_raw.h>
+#include <dfs_file.h>
#define O_RDONLY DFS_O_RDONLY
#define O_WRONLY DFS_O_WRONLY
@@ -74,6 +74,15 @@ typedef struct
int cur;
} DIR;
+struct stat
+{
+ struct dfs_stat parent;
+};
+struct statfs
+{
+ struct dfs_statfs parent;
+};
+
/* file api*/
int open(const char *file, int flags, int mode);
int close(int d);
@@ -83,6 +92,7 @@ int lseek(int fd, int offset, int dir);
int rename(const char* old, const char* new );
int unlink(const char *pathname);
int stat(const char *file, struct dfs_stat *buf);
+int statfs(const char *path, struct dfs_statfs *buf);
/* directory api*/
int mkdir (const char *path, rt_uint16_t mode);
diff --git a/components/dfs/include/dfs_raw.h b/components/dfs/include/dfs_raw.h
deleted file mode 100644
index dd6bfb0cad..0000000000
--- a/components/dfs/include/dfs_raw.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-+------------------------------------------------------------------------------
-| Project : Device Filesystem
-+------------------------------------------------------------------------------
-| Copyright 2004, 2005 www.fayfayspace.org.
-| All rights reserved.
-|------------------------------------------------------------------------------
-| File : dfs_raw.h, the raw APIs of Device FileSystem
-|------------------------------------------------------------------------------
-| Chang Logs:
-| Date Author Notes
-| 2005-01-26 ffxz The first version
-+------------------------------------------------------------------------------
-*/
-
-#ifndef __DFS_RAW_H__
-#define __DFS_RAW_H__
-
-#include <dfs_def.h>
-#include <dfs_fs.h>
-
-int dfile_raw_open(struct dfs_fd* fd, const char *path, int flags);
-int dfile_raw_close(struct dfs_fd* fd);
-int dfile_raw_ioctl(struct dfs_fd* fd, int cmd, void *args);
-int dfile_raw_read(struct dfs_fd* fd, void *buf, rt_size_t len);
-int dfile_raw_getdents(struct dfs_fd* fd, struct dfs_dirent* dirp, rt_size_t nbytes);
-int dfile_raw_unlink(const char *path);
-int dfile_raw_write(struct dfs_fd* fd, const void *buf, rt_size_t len);
-int dfile_raw_lseek(struct dfs_fd* fd, rt_off_t offset);
-int dfile_raw_stat(const char *path, struct dfs_stat *buf);
-int dfile_raw_rename(const char* oldpath, const char* newpath);
-
-/* FD APIs */
-int fd_new(void);
-struct dfs_fd* fd_get(int fd);
-void fd_put(struct dfs_fd* fd);
-
-#endif
diff --git a/components/dfs/include/dfs_util.h b/components/dfs/include/dfs_util.h
deleted file mode 100644
index 41ba8f2d36..0000000000
--- a/components/dfs/include/dfs_util.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-+------------------------------------------------------------------------------
-| Project : Device Filesystem
-+------------------------------------------------------------------------------
-| Copyright 2004, 2005 www.fayfayspace.org.
-| All rights reserved.
-|------------------------------------------------------------------------------
-| File : dfs_util.h, some misc definitions of Device FileSystem
-|------------------------------------------------------------------------------
-| Chang Logs:
-| Date Author Notes
-| 2005-01-26 ffxz The first version
-+------------------------------------------------------------------------------
-*/
-
-#ifndef __DFS_UTIL_H__
-#define __DFS_UTIL_H__
-
-#include <dfs_def.h>
-
-int dir_name(const char* path, char* dirname, int len);
-int file_name(const char* path, char* filename, int len);
-
-int next_dir_name(const char* path, int pos, char* next);
-void build_fullpath(const char *directory, const char *filename, char *fullpath);
-int str_is_prefix(const char* prefix, const char* str);
-
-#if !defined(RT_USING_MINILIBC) && !defined(RT_USING_NEWLIB)
-char *strrchr(const char *t, int c);
-#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION / 10000 < 35)
-#include <stddef.h>
-int strncasecmp(const char* s1, const char* s2, size_t len);
-#endif /* end of __ARMCC_VERSION */
-#endif
-
-#endif