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