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 =
{
"devfs",
DFS_FS_FLAG_DEFAULT,
dfs_device_fs_mount,
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 =
{
"elm",
DFS_FS_FLAG_DEFAULT,
dfs_elm_mount,
dfs_elm_unmount,
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 =
{
"nfs",
DFS_FS_FLAG_DEFAULT,
nfs_mount,
nfs_unmount,
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 =
{
"rom",
DFS_FS_FLAG_DEFAULT,
dfs_romfs_mount,
dfs_romfs_unmount,
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 =
{
"skt",
DFS_FS_FLAG_DEFAULT,
dfs_skt_mount,
dfs_skt_unmount,
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 =
{
"uffs",
DFS_FS_FLAG_DEFAULT,
dfs_uffs_mount,
dfs_uffs_unmount,
dfs_uffs_mkfs,

View File

@ -17,6 +17,9 @@
#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 */
struct dfs_filesystem;
struct dfs_fd;
@ -25,6 +28,7 @@ struct dfs_fd;
struct dfs_filesystem_operation
{
char *name;
rt_uint32_t flags; /* flags for file system operations */
/* mount and unmount file system */
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->pos = 0;
if (dfs_subdir(fs->path, fullpath) == RT_NULL)
fd->path = rt_strdup("/");
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
{
if (dfs_subdir(fs->path, fullpath) == RT_NULL)
fd->path = rt_strdup("/");
else
fd->path = rt_strdup(dfs_subdir(fs->path, fullpath));
rt_free(fullpath);
dfs_log(DFS_DEBUG_INFO, ("Actual file path: %s\n", fd->path));
}
else
fd->path = rt_strdup(dfs_subdir(fs->path, fullpath));
rt_free(fullpath);
dfs_log(DFS_DEBUG_INFO, ("Actual file path: %s\n", fd->path));
{
fd->path = fullpath;
}
/* specific file system open routine */
if (fs->ops->open == RT_NULL)
@ -241,10 +248,15 @@ int dfs_file_unlink(const char *path)
if (fs->ops->unlink != RT_NULL)
{
if (dfs_subdir(fs->path, fullpath) == RT_NULL)
result = fs->ops->unlink(fs, "/");
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
{
if (dfs_subdir(fs->path, fullpath) == RT_NULL)
result = fs->ops->unlink(fs, "/");
else
result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
}
else
result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
result = fs->ops->unlink(fs, fullpath);
}
else result = -DFS_STATUS_ENOSYS;
@ -380,7 +392,11 @@ int dfs_file_stat(const char *path, struct stat *buf)
}
/* get the real file path and get file stat */
result = fs->ops->stat(fs, dfs_subdir(fs->path, fullpath), buf);
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);
}
rt_free(fullpath);