add full path options (DFS_FS_FLAG_FULLPATH) to the file system.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1904 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2012-01-01 13:37:21 +00:00
parent 76e81a9977
commit beaf51ff82
8 changed files with 677 additions and 651 deletions

View File

@ -248,6 +248,7 @@ int dfs_device_fs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t
static const struct dfs_filesystem_operation _device_fs = static const struct dfs_filesystem_operation _device_fs =
{ {
"devfs", "devfs",
DFS_FS_FLAG_DEFAULT,
dfs_device_fs_mount, dfs_device_fs_mount,
RT_NULL, RT_NULL,
RT_NULL, RT_NULL,

View File

@ -647,6 +647,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
static const struct dfs_filesystem_operation dfs_elm = static const struct dfs_filesystem_operation dfs_elm =
{ {
"elm", "elm",
DFS_FS_FLAG_DEFAULT,
dfs_elm_mount, dfs_elm_mount,
dfs_elm_unmount, dfs_elm_unmount,
dfs_elm_mkfs, dfs_elm_mkfs,

View File

@ -1057,6 +1057,7 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
static const struct dfs_filesystem_operation _nfs = static const struct dfs_filesystem_operation _nfs =
{ {
"nfs", "nfs",
DFS_FS_FLAG_DEFAULT,
nfs_mount, nfs_mount,
nfs_unmount, nfs_unmount,
RT_NULL, /* mkfs */ RT_NULL, /* mkfs */

View File

@ -264,6 +264,7 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t cou
static const struct dfs_filesystem_operation _romfs = static const struct dfs_filesystem_operation _romfs =
{ {
"rom", "rom",
DFS_FS_FLAG_DEFAULT,
dfs_romfs_mount, dfs_romfs_mount,
dfs_romfs_unmount, dfs_romfs_unmount,
RT_NULL, RT_NULL,

View File

@ -55,6 +55,7 @@ int dfs_skt_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count
static const struct dfs_filesystem_operation _skt_fs = static const struct dfs_filesystem_operation _skt_fs =
{ {
"skt", "skt",
DFS_FS_FLAG_DEFAULT,
dfs_skt_mount, dfs_skt_mount,
dfs_skt_unmount, dfs_skt_unmount,
RT_NULL, RT_NULL,

View File

@ -329,6 +329,7 @@ int dfs_uffs_rename(struct dfs_filesystem* fs, const char* oldpath, const char*
struct dfs_filesystem_operation _uffs = struct dfs_filesystem_operation _uffs =
{ {
"uffs", "uffs",
DFS_FS_FLAG_DEFAULT,
dfs_uffs_mount, dfs_uffs_mount,
dfs_uffs_unmount, dfs_uffs_unmount,
dfs_uffs_mkfs, dfs_uffs_mkfs,

View File

@ -17,6 +17,9 @@
#include <dfs_def.h> #include <dfs_def.h>
#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
/* Pre-declaration */ /* Pre-declaration */
struct dfs_filesystem; struct dfs_filesystem;
struct dfs_fd; struct dfs_fd;
@ -25,6 +28,7 @@ struct dfs_fd;
struct dfs_filesystem_operation struct dfs_filesystem_operation
{ {
char *name; char *name;
rt_uint32_t flags; /* flags for file system operations */
/* mount and unmount file system */ /* mount and unmount file system */
int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data); int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);

View File

@ -66,12 +66,19 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
fd->size = 0; fd->size = 0;
fd->pos = 0; fd->pos = 0;
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
{
if (dfs_subdir(fs->path, fullpath) == RT_NULL) if (dfs_subdir(fs->path, fullpath) == RT_NULL)
fd->path = rt_strdup("/"); fd->path = rt_strdup("/");
else else
fd->path = rt_strdup(dfs_subdir(fs->path, fullpath)); fd->path = rt_strdup(dfs_subdir(fs->path, fullpath));
rt_free(fullpath); rt_free(fullpath);
dfs_log(DFS_DEBUG_INFO, ("Actual file path: %s\n", fd->path)); dfs_log(DFS_DEBUG_INFO, ("Actual file path: %s\n", fd->path));
}
else
{
fd->path = fullpath;
}
/* specific file system open routine */ /* specific file system open routine */
if (fs->ops->open == RT_NULL) if (fs->ops->open == RT_NULL)
@ -240,12 +247,17 @@ int dfs_file_unlink(const char *path)
} }
if (fs->ops->unlink != RT_NULL) if (fs->ops->unlink != RT_NULL)
{
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
{ {
if (dfs_subdir(fs->path, fullpath) == RT_NULL) if (dfs_subdir(fs->path, fullpath) == RT_NULL)
result = fs->ops->unlink(fs, "/"); result = fs->ops->unlink(fs, "/");
else else
result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath)); result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
} }
else
result = fs->ops->unlink(fs, fullpath);
}
else result = -DFS_STATUS_ENOSYS; else result = -DFS_STATUS_ENOSYS;
__exit: __exit:
@ -380,7 +392,11 @@ int dfs_file_stat(const char *path, struct stat *buf)
} }
/* get the real file path and get file stat */ /* get the real file path and get file stat */
if (fs->ops->flags & DFS_FS_FLAG_FULLPATH)
result = fs->ops->stat(fs, fullpath, buf);
else
result = fs->ops->stat(fs, dfs_subdir(fs->path, fullpath), buf); result = fs->ops->stat(fs, dfs_subdir(fs->path, fullpath), buf);
} }
rt_free(fullpath); rt_free(fullpath);