merge some semaphores to one mutex in DFS

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@135 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2009-10-25 23:24:51 +00:00
parent 0b5641e3d6
commit 428b10bb91
5 changed files with 127 additions and 120 deletions

View File

@ -78,10 +78,9 @@ int dfs_unmount(const char *specialfile);
extern struct dfs_filesystem_operation* filesystem_operation_table[]; extern struct dfs_filesystem_operation* filesystem_operation_table[];
extern struct dfs_filesystem filesystem_table[]; extern struct dfs_filesystem filesystem_table[];
extern rt_sem_t filesystem_table_lock;
extern rt_sem_t filesystem_operation_table_lock;
extern char working_directory[]; extern char working_directory[];
extern rt_sem_t working_directory_lock;
void dfs_lock(void);
void dfs_unlock(void);
#endif #endif

View File

@ -32,34 +32,41 @@
*/ */
int dfs_register(struct dfs_filesystem_operation* ops) int dfs_register(struct dfs_filesystem_operation* ops)
{ {
int index; int index, result;
rt_sem_take(filesystem_operation_table_lock, RT_WAITING_FOREVER); result = 0;
/* lock filesystem */
dfs_lock();
/* check if this filesystem was already registered */ /* check if this filesystem was already registered */
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++) for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
{ {
if (filesystem_operation_table[index] != RT_NULL && if (filesystem_operation_table[index] != RT_NULL &&
strcmp(filesystem_operation_table[index]->name, ops->name) == 0) strcmp(filesystem_operation_table[index]->name, ops->name) == 0)
{
result = -1;
goto err; goto err;
} }
}
/* find out an empty filesystem type entry */ /* find out an empty filesystem type entry */
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX && filesystem_operation_table[index] != RT_NULL; for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX && filesystem_operation_table[index] != RT_NULL;
index++) ; index++) ;
/* filesystem type table full */ /* filesystem type table full */
if (index == DFS_FILESYSTEM_TYPES_MAX) goto err; if (index == DFS_FILESYSTEM_TYPES_MAX)
{
result = -1;
goto err;
}
/* save the filesystem's operations */ /* save the filesystem's operations */
filesystem_operation_table[index] = ops; filesystem_operation_table[index] = ops;
rt_sem_release(filesystem_operation_table_lock);
return 0;
err: err:
rt_sem_release(filesystem_operation_table_lock); dfs_unlock();
return -1; return result;
} }
/* /*
@ -80,8 +87,8 @@ struct dfs_filesystem* dfs_filesystem_lookup(const char *path)
fs = RT_NULL; fs = RT_NULL;
prefixlen = 0; prefixlen = 0;
/* lock filesystem table */ /* lock filesystem */
rt_sem_take(filesystem_table_lock, RT_WAITING_FOREVER); dfs_lock();
/* lookup it in the filesystem table */ /* lookup it in the filesystem table */
for (index = 0; index < DFS_FILESYSTEMS_MAX + 1; index++) for (index = 0; index < DFS_FILESYSTEMS_MAX + 1; index++)
@ -97,7 +104,8 @@ struct dfs_filesystem* dfs_filesystem_lookup(const char *path)
} }
} }
rt_sem_release(filesystem_table_lock); dfs_unlock();
return fs; return fs;
} }
@ -191,7 +199,7 @@ int dfs_mount(const char* device_name, const char* path,
struct dfs_filesystem_operation* ops; struct dfs_filesystem_operation* ops;
struct dfs_filesystem* fs; struct dfs_filesystem* fs;
char *fullpath=RT_NULL; char *fullpath=RT_NULL;
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
char full_path[DFS_PATH_MAX + 1]; char full_path[DFS_PATH_MAX + 1];
#endif #endif
rt_device_t dev_id; rt_device_t dev_id;
@ -207,7 +215,7 @@ int dfs_mount(const char* device_name, const char* path,
} }
/* find out specific filesystem */ /* find out specific filesystem */
rt_sem_take(filesystem_operation_table_lock, RT_WAITING_FOREVER); dfs_lock();
for ( index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++ ) for ( index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++ )
{ {
if (strcmp(filesystem_operation_table[index]->name, filesystemtype) == 0)break; if (strcmp(filesystem_operation_table[index]->name, filesystemtype) == 0)break;
@ -217,22 +225,22 @@ int dfs_mount(const char* device_name, const char* path,
if ( index == DFS_FILESYSTEM_TYPES_MAX ) if ( index == DFS_FILESYSTEM_TYPES_MAX )
{ {
rt_set_errno(-DFS_STATUS_ENODEV); rt_set_errno(-DFS_STATUS_ENODEV);
rt_sem_release(filesystem_operation_table_lock); dfs_unlock();
return -1; return -1;
} }
ops = filesystem_operation_table[index]; ops = filesystem_operation_table[index];
rt_sem_release(filesystem_operation_table_lock); dfs_unlock();
/* make full path for special file */ /* make full path for special file */
fullpath = (char*)path; fullpath = (char*)path;
if ( fullpath[0] != '/') /* not an abstract path */ if ( fullpath[0] != '/') /* not an abstract path */
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
fullpath = full_path; fullpath = full_path;
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, path, fullpath); build_fullpath(working_directory, path, fullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
rt_set_errno(-DFS_STATUS_ENOTDIR); rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1; return -1;
@ -253,7 +261,7 @@ int dfs_mount(const char* device_name, const char* path,
} }
/* check whether the file system mounted or not */ /* check whether the file system mounted or not */
rt_sem_take(filesystem_table_lock, RT_WAITING_FOREVER); dfs_lock();
for (index =0; index < DFS_FILESYSTEMS_MAX; index++) for (index =0; index < DFS_FILESYSTEMS_MAX; index++)
{ {
if ( filesystem_table[index].ops != RT_NULL && if ( filesystem_table[index].ops != RT_NULL &&
@ -279,19 +287,17 @@ int dfs_mount(const char* device_name, const char* path,
fs->ops = ops; fs->ops = ops;
fs->dev_id = dev_id; fs->dev_id = dev_id;
/* release filesystem_table lock */ /* release filesystem_table lock */
rt_sem_release(filesystem_table_lock); dfs_unlock();
/* open device, but do not check the status of device */ /* open device, but do not check the status of device */
rt_device_open(fs->dev_id, RT_DEVICE_OFLAG_RDWR); rt_device_open(fs->dev_id, RT_DEVICE_OFLAG_RDWR);
if ( ops->mount == RT_NULL ) /* there is no mount implementation */ if ( ops->mount == RT_NULL ) /* there is no mount implementation */
{ {
rt_sem_take(filesystem_table_lock, RT_WAITING_FOREVER); dfs_lock();
/* clear filesystem table entry */ /* clear filesystem table entry */
rt_memset(fs, 0, sizeof(struct dfs_filesystem)); rt_memset(fs, 0, sizeof(struct dfs_filesystem));
dfs_unlock();
rt_sem_release(filesystem_table_lock);
rt_set_errno(-DFS_STATUS_ENOSYS); rt_set_errno(-DFS_STATUS_ENOSYS);
return -1; return -1;
@ -300,7 +306,7 @@ int dfs_mount(const char* device_name, const char* path,
else if ( ops->mount(fs) < 0 ) else if ( ops->mount(fs) < 0 )
{ {
/* mount failed */ /* mount failed */
rt_sem_take(filesystem_table_lock, RT_WAITING_FOREVER); dfs_lock();
/* close device */ /* close device */
rt_device_close(fs->dev_id); rt_device_close(fs->dev_id);
@ -308,14 +314,14 @@ int dfs_mount(const char* device_name, const char* path,
/* clear filesystem table entry */ /* clear filesystem table entry */
rt_memset(fs, 0, sizeof(struct dfs_filesystem)); rt_memset(fs, 0, sizeof(struct dfs_filesystem));
rt_sem_release(filesystem_table_lock); dfs_unlock();
return -1; return -1;
} }
return 0; return 0;
err1: err1:
rt_sem_release(filesystem_table_lock); dfs_unlock();
return -1; return -1;
} }
@ -334,7 +340,7 @@ err1:
int dfs_unmount(const char *specialfile) int dfs_unmount(const char *specialfile)
{ {
char *fullpath; char *fullpath;
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
char full_path[DFS_PATH_MAX + 1]; char full_path[DFS_PATH_MAX + 1];
#endif #endif
struct dfs_filesystem* fs = RT_NULL; struct dfs_filesystem* fs = RT_NULL;
@ -342,20 +348,20 @@ int dfs_unmount(const char *specialfile)
fullpath = (char*)specialfile; fullpath = (char*)specialfile;
if ( fullpath[0] != '/') if ( fullpath[0] != '/')
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
fullpath = full_path; fullpath = full_path;
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, specialfile, fullpath); build_fullpath(working_directory, specialfile, fullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
rt_set_errno(-DFS_STATUS_ENOTDIR); rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1; return -1;
#endif #endif
} }
/* lock filesystem table */ /* lock filesystem */
rt_sem_take(filesystem_table_lock, RT_WAITING_FOREVER); dfs_lock();
fs = dfs_filesystem_lookup(fullpath); fs = dfs_filesystem_lookup(fullpath);
if (fs != RT_NULL && fs->ops->unmount != RT_NULL && fs->ops->unmount(fs) < 0) if (fs != RT_NULL && fs->ops->unmount != RT_NULL && fs->ops->unmount(fs) < 0)
@ -369,11 +375,12 @@ int dfs_unmount(const char *specialfile)
/* clear this filesystem table entry */ /* clear this filesystem table entry */
rt_memset(fs, 0, sizeof(struct dfs_filesystem)); rt_memset(fs, 0, sizeof(struct dfs_filesystem));
rt_sem_release(filesystem_table_lock); dfs_unlock();
return 0; return 0;
err1: err1:
rt_sem_release(filesystem_table_lock); dfs_unlock();
return -1; return -1;
} }

View File

@ -25,16 +25,18 @@
struct dfs_filesystem_operation* filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX + 1]; struct dfs_filesystem_operation* filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX + 1];
struct dfs_filesystem filesystem_table[DFS_FILESYSTEMS_MAX + 1]; struct dfs_filesystem filesystem_table[DFS_FILESYSTEMS_MAX + 1];
rt_sem_t filesystem_table_lock; /* device filesystem lock */
rt_sem_t filesystem_operation_table_lock; struct rt_mutex dlock;
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
char working_directory[DFS_PATH_MAX + 1]; char working_directory[DFS_PATH_MAX + 1];
rt_sem_t working_directory_lock;
#endif #endif
struct dfs_fd fd_table[DFS_FD_MAX + 1]; #ifdef DFS_USING_STDIO
rt_sem_t fd_table_lock; struct dfs_fd fd_table[3 + DFS_FD_MAX];
#else
struct dfs_fd fd_table[DFS_FD_MAX];
#endif
/* /*
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
@ -53,40 +55,34 @@ void dfs_init()
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX + 1; index++) for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX + 1; index++)
filesystem_operation_table[index] = RT_NULL; filesystem_operation_table[index] = RT_NULL;
/* create filesystem operations table lock */ /* create device filesystem lock */
filesystem_operation_table_lock = rt_sem_create("sem_fot", 1, RT_IPC_FLAG_FIFO); rt_mutex_init(&dlock, "dlock", RT_IPC_FLAG_FIFO);
/* clear filesystem table */ /* clear filesystem table */
for (index = 0; index < DFS_FILESYSTEMS_MAX + 1; index++) rt_memset(filesystem_table, 0, sizeof(filesystem_table));
{
rt_memset(filesystem_table[index].path, 0, DFS_PATH_MAX + 1);
filesystem_table[index].ops = RT_NULL; #ifdef DFS_USING_WORKDIR
filesystem_table[index].dev_id = 0;
filesystem_table[index].block_id = 0;
filesystem_table[index].data = RT_NULL;
}
/* create filesystem table lock */
filesystem_table_lock = rt_sem_create("sem_fst", 1, RT_IPC_FLAG_FIFO);
#ifdef RT_USING_WORKDIR
/* set current working directory */ /* set current working directory */
strcpy(working_directory, "/"); strcpy(working_directory, "/");
working_directory_lock = rt_sem_create("sem_wd", 1, RT_IPC_FLAG_FIFO);
#endif #endif
/* clean fd table */ /* clean fd table */
for ( index = 0; index < DFS_FD_MAX; index ++) rt_memset(fd_table, 0, sizeof(fd_table));
{
rt_memset(&fd_table[index], 0, sizeof(struct dfs_fd));
}
/* create fd table lock */
fd_table_lock = rt_sem_create("sem_fdt", 1, RT_IPC_FLAG_FIFO);
#if defined(RT_USING_FINSH) && !defined(FINSH_USING_SYMTAB) #if defined(RT_USING_FINSH) && !defined(FINSH_USING_SYMTAB)
dfs_export_finsh(); dfs_export_finsh();
#endif #endif
} }
void dfs_lock()
{
rt_err_t result;
result = rt_mutex_take(&dlock, RT_WAITING_FOREVER);
RT_ASSERT(result == RT_EOK);
}
void dfs_unlock()
{
rt_mutex_release(&dlock);
}

View File

@ -12,6 +12,8 @@
| 2009-05-27 Yi.qiu The first version. | 2009-05-27 Yi.qiu The first version.
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
*/ */
#include <string.h>
#include <dfs_util.h>
#include <dfs_posix.h> #include <dfs_posix.h>
/* /*
@ -521,20 +523,20 @@ int chdir(const char *path)
{ {
/* build full path */ /* build full path */
fullpath = full_path; fullpath = full_path;
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, path, fullpath); build_fullpath(working_directory, path, fullpath);
strcpy(working_directory, fullpath); strcpy(working_directory, fullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#endif #endif
} }
else else
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
rt_strncpy(working_directory, path, strlen(path) + 1); rt_strncpy(working_directory, path, strlen(path) + 1);
working_directory[strlen(path)] = '\0'; working_directory[strlen(path)] = '\0';
rt_sem_release(working_directory_lock); dfs_unlock();
#endif #endif
} }
@ -554,10 +556,12 @@ int chdir(const char *path)
*/ */
char* getcwd(char *buf, rt_size_t size) char* getcwd(char *buf, rt_size_t size)
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
rt_strncpy(buf, working_directory, size); rt_strncpy(buf, working_directory, size);
rt_sem_release(working_directory_lock); dfs_unlock();
#else
rt_kprintf("WARNING: not support working directory\n");
#endif #endif
return buf; return buf;
} }

View File

@ -16,8 +16,7 @@
#include <dfs_util.h> #include <dfs_util.h>
#include <string.h> #include <string.h>
extern struct dfs_fd fd_table[DFS_FD_MAX + 1]; extern struct dfs_fd fd_table[];
extern rt_sem_t fd_table_lock;
/* /*
+------------------------------------------------------------------------------ +------------------------------------------------------------------------------
@ -35,26 +34,32 @@ int fd_new(void)
struct dfs_fd* d; struct dfs_fd* d;
int idx; int idx;
rt_sem_take(fd_table_lock, RT_WAITING_FOREVER); /* lock filesystem */
dfs_lock();
/* find an empty fd entry */ /* find an empty fd entry */
#ifdef RT_USING_STDIO #ifdef DFS_USING_STDIO
for (idx = 3; idx < DFS_FD_MAX && fd_table[idx].ref_count > 0; idx++); for (idx = 3; idx < DFS_FD_MAX + 3 && fd_table[idx].ref_count > 0; idx++);
#else #else
for (idx = 0; idx < DFS_FD_MAX && fd_table[idx].ref_count > 0; idx++); for (idx = 0; idx < DFS_FD_MAX && fd_table[idx].ref_count > 0; idx++);
#endif #endif
/* can't find an empty fd entry */ /* can't find an empty fd entry */
#ifdef DFS_USING_STDIO
if (idx == DFS_FD_MAX + 3)
#else
if (idx == DFS_FD_MAX) if (idx == DFS_FD_MAX)
#endif
{ {
rt_sem_release(fd_table_lock); idx = -1;
return -1; goto __result;
} }
d = &(fd_table[idx]); d = &(fd_table[idx]);
d->ref_count = 1; d->ref_count = 1;
rt_sem_release(fd_table_lock);
__result:
dfs_unlock();
return idx; return idx;
} }
@ -73,17 +78,17 @@ struct dfs_fd* fd_get(int fd)
{ {
struct dfs_fd* d; struct dfs_fd* d;
#ifdef RT_USING_STDIO #ifdef DFS_USING_STDIO
if ( fd < 3 || fd > DFS_FD_MAX ) return RT_NULL; if ( fd < 3 || fd > DFS_FD_MAX + 3) return RT_NULL;
#else #else
if ( fd < 0 || fd > DFS_FD_MAX ) return RT_NULL; if ( fd < 0 || fd > DFS_FD_MAX ) return RT_NULL;
#endif #endif
d = &fd_table[fd]; d = &fd_table[fd];
rt_sem_take(fd_table_lock, RT_WAITING_FOREVER); dfs_lock();
d->ref_count ++; d->ref_count ++;
rt_sem_release(fd_table_lock); dfs_unlock();
return d; return d;
} }
@ -101,14 +106,14 @@ struct dfs_fd* fd_get(int fd)
*/ */
void fd_put(struct dfs_fd* fd) void fd_put(struct dfs_fd* fd)
{ {
rt_sem_take(fd_table_lock, RT_WAITING_FOREVER); dfs_lock();
fd->ref_count --; fd->ref_count --;
/* clear this fd entry */ /* clear this fd entry */
if ( fd->ref_count == 0 ) if ( fd->ref_count == 0 )
{ {
rt_memset(fd, 0, sizeof(struct dfs_fd)); rt_memset(fd, 0, sizeof(struct dfs_fd));
} }
rt_sem_release(fd_table_lock); dfs_unlock();
}; };
/* /*
@ -126,7 +131,7 @@ int dfile_raw_open(struct dfs_fd* fd, const char *path, int flags)
{ {
struct dfs_filesystem* fs; struct dfs_filesystem* fs;
char *fullpath; char *fullpath;
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
char full_path[DFS_PATH_MAX + 1]; char full_path[DFS_PATH_MAX + 1];
#endif #endif
int fspathlen, result; int fspathlen, result;
@ -138,12 +143,12 @@ int dfile_raw_open(struct dfs_fd* fd, const char *path, int flags)
fullpath = (char*)path; fullpath = (char*)path;
if ( fullpath[0] != '/') if ( fullpath[0] != '/')
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
fullpath = &full_path[0]; fullpath = &full_path[0];
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, path, fullpath); build_fullpath(working_directory, path, fullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
rt_kprintf("bad filename"); rt_kprintf("bad filename");
@ -341,7 +346,7 @@ int dfile_raw_unlink(const char *path)
{ {
struct dfs_filesystem* fs; struct dfs_filesystem* fs;
char *fullpath, *real_path, search_path[DFS_PATH_MAX + 1]; char *fullpath, *real_path, search_path[DFS_PATH_MAX + 1];
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
char full_path[DFS_PATH_MAX+1]; char full_path[DFS_PATH_MAX+1];
#endif #endif
struct dfs_fd* fd; struct dfs_fd* fd;
@ -351,12 +356,12 @@ int dfile_raw_unlink(const char *path)
fullpath = (char*)path; fullpath = (char*)path;
if ( fullpath[0] != '/') if ( fullpath[0] != '/')
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
fullpath = full_path; fullpath = full_path;
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, path, fullpath); build_fullpath(working_directory, path, fullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
rt_kprintf("bad filename"); rt_kprintf("bad filename");
@ -368,7 +373,7 @@ int dfile_raw_unlink(const char *path)
if ( (fs = dfs_filesystem_lookup(fullpath)) == RT_NULL) return -DFS_STATUS_ENOENT; if ( (fs = dfs_filesystem_lookup(fullpath)) == RT_NULL) return -DFS_STATUS_ENOENT;
/* Check whether file is already open */ /* Check whether file is already open */
rt_sem_take(fd_table_lock, RT_WAITING_FOREVER); dfs_lock();
for (index = 0; index < DFS_FD_MAX; index++) for (index = 0; index < DFS_FD_MAX; index++)
{ {
fd = &(fd_table[index]); fd = &(fd_table[index]);
@ -377,11 +382,11 @@ int dfile_raw_unlink(const char *path)
build_fullpath(fd->fs->path, fd->path, search_path); build_fullpath(fd->fs->path, fd->path, search_path);
if (strcmp(fullpath, search_path) == 0) if (strcmp(fullpath, search_path) == 0)
{ {
rt_sem_release(fd_table_lock); dfs_unlock();
return -DFS_STATUS_EEXIST; return -DFS_STATUS_EEXIST;
} }
} }
rt_sem_release(fd_table_lock); dfs_unlock();
fspathlen = strlen(fs->path); fspathlen = strlen(fs->path);
real_path = search_path; real_path = search_path;
@ -452,7 +457,7 @@ int dfile_raw_stat(const char *path, struct dfs_stat *buf)
{ {
struct dfs_filesystem* fs; struct dfs_filesystem* fs;
char* fullpath, real_path[DFS_PATH_MAX + 1]; char* fullpath, real_path[DFS_PATH_MAX + 1];
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
char full_path[DFS_PATH_MAX + 1]; char full_path[DFS_PATH_MAX + 1];
#endif #endif
int fspathlen; int fspathlen;
@ -460,15 +465,15 @@ int dfile_raw_stat(const char *path, struct dfs_stat *buf)
fullpath = (char*)path; fullpath = (char*)path;
if ( fullpath[0] != '/' ) if ( fullpath[0] != '/' )
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
fullpath = full_path; fullpath = full_path;
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, path, fullpath); build_fullpath(working_directory, path, fullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
#ifdef RT_USING_FINSH #ifdef RT_USING_FINSH
rt_kprintf("bad filename"); rt_kprintf("not support working directory, bad filename\n");
#endif #endif
return -1; return -1;
#endif #endif
@ -509,7 +514,7 @@ int dfile_raw_rename(const char* oldpath, const char* newpath)
{ {
struct dfs_filesystem *oldfs, *newfs; struct dfs_filesystem *oldfs, *newfs;
char *oldfullpath, *newfullpath; char *oldfullpath, *newfullpath;
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* Change DFS_PATH_MAX to DFS_PATH_MAX + 1, yi.qiu@2008.09.23*/ /* Change DFS_PATH_MAX to DFS_PATH_MAX + 1, yi.qiu@2008.09.23*/
char old_realpath[DFS_PATH_MAX + 1], new_realpath[DFS_PATH_MAX + 1]; char old_realpath[DFS_PATH_MAX + 1], new_realpath[DFS_PATH_MAX + 1];
#endif #endif
@ -519,32 +524,28 @@ int dfile_raw_rename(const char* oldpath, const char* newpath)
if ( oldfullpath[0] != '/' ) if ( oldfullpath[0] != '/' )
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
oldfullpath = old_realpath; oldfullpath = old_realpath;
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, oldpath, oldfullpath); build_fullpath(working_directory, oldpath, oldfullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
#ifdef RT_USING_FINSH rt_kprintf("bad filename\n");
rt_kprintf("bad filename");
#endif
return -1; return -1;
#endif #endif
} }
if ( newfullpath[0] != '/' ) if ( newfullpath[0] != '/' )
{ {
#ifdef RT_USING_WORKDIR #ifdef DFS_USING_WORKDIR
/* build full path */ /* build full path */
newfullpath = new_realpath; newfullpath = new_realpath;
rt_sem_take(working_directory_lock, RT_WAITING_FOREVER); dfs_lock();
build_fullpath(working_directory, newpath, newfullpath); build_fullpath(working_directory, newpath, newfullpath);
rt_sem_release(working_directory_lock); dfs_unlock();
#else #else
#ifdef RT_USING_FINSH
rt_kprintf("bad filename"); rt_kprintf("bad filename");
#endif
return -1; return -1;
#endif #endif
} }