diff options
| author | [email protected] <[email protected]> | 2012-12-26 01:12:13 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-12-26 01:12:13 +0000 |
| commit | 69521e2c8fa17515a625f96fae138df2c1ca8ba3 (patch) | |
| tree | 7228654ca2f917870d2f7a0c44cf0e1e33d7495f /components/dfs/src/dfs.c | |
| parent | ef5c47e6840a2d2cd986f4ecfdde87c9148375b2 (diff) | |
fixed the coding style in components/dfs
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2530 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/dfs/src/dfs.c')
| -rw-r--r-- | components/dfs/src/dfs.c | 383 |
1 files changed, 192 insertions, 191 deletions
diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 05a7615f2e..86ef809fbf 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -16,7 +16,7 @@ #include <dfs_fs.h> #include <dfs_file.h> -#define NO_WORKING_DIR "system does not support working dir\n" +#define NO_WORKING_DIR "system does not support working dir\n" /* Global variables */ const struct dfs_filesystem_operation *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; @@ -46,20 +46,20 @@ struct dfs_fd fd_table[DFS_FD_MAX]; */ void dfs_init(void) { - /* clear filesystem operations table */ - rt_memset(filesystem_operation_table, 0, sizeof(filesystem_operation_table)); - /* clear filesystem table */ - rt_memset(filesystem_table, 0, sizeof(filesystem_table)); - /* clean fd table */ - rt_memset(fd_table, 0, sizeof(fd_table)); + /* clear filesystem operations table */ + rt_memset(filesystem_operation_table, 0, sizeof(filesystem_operation_table)); + /* clear filesystem table */ + rt_memset(filesystem_table, 0, sizeof(filesystem_table)); + /* clean fd table */ + rt_memset(fd_table, 0, sizeof(fd_table)); - /* create device filesystem lock */ - rt_mutex_init(&fslock, "fslock", RT_IPC_FLAG_FIFO); + /* create device filesystem lock */ + rt_mutex_init(&fslock, "fslock", RT_IPC_FLAG_FIFO); #ifdef DFS_USING_WORKDIR - /* set current working directory */ - rt_memset(working_directory, 0, sizeof(working_directory)); - working_directory[0] = '/'; + /* set current working directory */ + rt_memset(working_directory, 0, sizeof(working_directory)); + working_directory[0] = '/'; #endif } @@ -70,13 +70,13 @@ void dfs_init(void) */ void dfs_lock(void) { - rt_err_t result; + rt_err_t result; - result = rt_mutex_take(&fslock, RT_WAITING_FOREVER); - if (result != RT_EOK) - { - RT_ASSERT(0); - } + result = rt_mutex_take(&fslock, RT_WAITING_FOREVER); + if (result != RT_EOK) + { + RT_ASSERT(0); + } } /** @@ -86,7 +86,7 @@ void dfs_lock(void) */ void dfs_unlock(void) { - rt_mutex_release(&fslock); + rt_mutex_release(&fslock); } /** @@ -97,36 +97,36 @@ void dfs_unlock(void) */ int fd_new(void) { - struct dfs_fd *d; - int idx; + struct dfs_fd *d; + int idx; - /* lock filesystem */ - dfs_lock(); + /* lock filesystem */ + dfs_lock(); - /* find an empty fd entry */ + /* find an empty fd entry */ #ifdef DFS_USING_STDIO - for (idx = 3; idx < DFS_FD_MAX + 3 && fd_table[idx].ref_count > 0; idx++); + 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++); + for (idx = 0; idx < DFS_FD_MAX && fd_table[idx].ref_count > 0; idx++); #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) + if (idx == DFS_FD_MAX + 3) #else - if (idx == DFS_FD_MAX) + if (idx == DFS_FD_MAX) #endif - { - idx = -1; - goto __result; - } + { + idx = -1; + goto __result; + } - d = &(fd_table[idx]); - d->ref_count = 1; + d = &(fd_table[idx]); + d->ref_count = 1; __result: - dfs_unlock(); - return idx; + dfs_unlock(); + return idx; } /** @@ -140,24 +140,24 @@ __result: */ struct dfs_fd *fd_get(int fd) { - struct dfs_fd *d; + struct dfs_fd *d; #ifdef DFS_USING_STDIO - if (fd < 3 || fd >= DFS_FD_MAX + 3) - return RT_NULL; + if (fd < 3 || fd >= DFS_FD_MAX + 3) + return RT_NULL; #else - if (fd < 0 || fd >= DFS_FD_MAX) - return RT_NULL; + if (fd < 0 || fd >= DFS_FD_MAX) + return RT_NULL; #endif - dfs_lock(); - d = &fd_table[fd]; + dfs_lock(); + d = &fd_table[fd]; - /* increase the reference count */ - d->ref_count ++; - dfs_unlock(); + /* increase the reference count */ + d->ref_count ++; + dfs_unlock(); - return d; + return d; } /** @@ -167,17 +167,17 @@ struct dfs_fd *fd_get(int fd) */ void fd_put(struct dfs_fd *fd) { - RT_ASSERT(fd != RT_NULL); + RT_ASSERT(fd != RT_NULL); - dfs_lock(); - fd->ref_count --; + dfs_lock(); + fd->ref_count --; - /* clear this fd entry */ - if (fd->ref_count == 0) - { - rt_memset(fd, 0, sizeof(struct dfs_fd)); - } - dfs_unlock(); + /* clear this fd entry */ + if (fd->ref_count == 0) + { + rt_memset(fd, 0, sizeof(struct dfs_fd)); + } + dfs_unlock(); }; /** @@ -191,52 +191,52 @@ void fd_put(struct dfs_fd *fd) */ int fd_is_open(const char *pathname) { - char *fullpath; - unsigned int index; - struct dfs_filesystem *fs; - struct dfs_fd *fd; + char *fullpath; + unsigned int index; + struct dfs_filesystem *fs; + struct dfs_fd *fd; - fullpath = dfs_normalize_path(RT_NULL, pathname); - if (fullpath != RT_NULL) - { - char *mountpath; - fs = dfs_filesystem_lookup(fullpath); - if (fs == RT_NULL) - { - /* can't find mounted file system */ - rt_free(fullpath); + fullpath = dfs_normalize_path(RT_NULL, pathname); + if (fullpath != RT_NULL) + { + char *mountpath; + fs = dfs_filesystem_lookup(fullpath); + if (fs == RT_NULL) + { + /* can't find mounted file system */ + rt_free(fullpath); - return -1; - } + return -1; + } - /* get file path name under mounted file system */ - if (fs->path[0] == '/' && fs->path[1] == '\0') - mountpath = fullpath; - else - mountpath = fullpath + strlen(fs->path); + /* get file path name under mounted file system */ + if (fs->path[0] == '/' && fs->path[1] == '\0') + mountpath = fullpath; + else + mountpath = fullpath + strlen(fs->path); - dfs_lock(); - for (index = 0; index < DFS_FD_MAX; index++) - { - fd = &(fd_table[index]); - if (fd->fs == RT_NULL) - continue; + dfs_lock(); + for (index = 0; index < DFS_FD_MAX; index++) + { + fd = &(fd_table[index]); + if (fd->fs == RT_NULL) + continue; - if (fd->fs == fs && strcmp(fd->path, mountpath) == 0) - { - /* found file in file descriptor table */ - rt_free(fullpath); - dfs_unlock(); + if (fd->fs == fs && strcmp(fd->path, mountpath) == 0) + { + /* found file in file descriptor table */ + rt_free(fullpath); + dfs_unlock(); - return 0; - } - } - dfs_unlock(); + return 0; + } + } + dfs_unlock(); - rt_free(fullpath); - } + rt_free(fullpath); + } - return -1; + return -1; } /** @@ -249,22 +249,23 @@ int fd_is_open(const char *pathname) */ const char *dfs_subdir(const char *directory, const char *filename) { - const char *dir; + const char *dir; - if (strlen(directory) == strlen(filename)) /* it's a same path */ - return RT_NULL; + if (strlen(directory) == strlen(filename)) /* it's a same path */ + return RT_NULL; - dir = filename + strlen(directory); - if ((*dir != '/') && (dir != filename)) - { - dir --; - } + dir = filename + strlen(directory); + if ((*dir != '/') && (dir != filename)) + { + dir --; + } - return dir; + return dir; } /** - * this function will normalize a path according to specified parent directory and file name. + * this function will normalize a path according to specified parent directory + * and file name. * * @param directory the parent path * @param filename the file name @@ -273,113 +274,113 @@ const char *dfs_subdir(const char *directory, const char *filename) */ char *dfs_normalize_path(const char *directory, const char *filename) { - char *fullpath; - char *dst0, *dst, *src; + char *fullpath; + char *dst0, *dst, *src; - /* check parameters */ - RT_ASSERT(filename != RT_NULL); + /* check parameters */ + RT_ASSERT(filename != RT_NULL); #ifdef DFS_USING_WORKDIR - if (directory == RT_NULL) /* shall use working directory */ - directory = &working_directory[0]; + if (directory == RT_NULL) /* shall use working directory */ + directory = &working_directory[0]; #else - if ((directory == RT_NULL) && (filename[0] != '/')) - { - rt_kprintf(NO_WORKING_DIR); + if ((directory == RT_NULL) && (filename[0] != '/')) + { + rt_kprintf(NO_WORKING_DIR); - return RT_NULL; - } + return RT_NULL; + } #endif - if (filename[0] != '/') /* it's a absolute path, use it directly */ - { - fullpath = rt_malloc(strlen(directory) + strlen(filename) + 2); + if (filename[0] != '/') /* it's a absolute path, use it directly */ + { + fullpath = rt_malloc(strlen(directory) + strlen(filename) + 2); - /* join path and file name */ - rt_snprintf(fullpath, strlen(directory) + strlen(filename) + 2, - "%s/%s", directory, filename); - } - else - { - fullpath = rt_strdup(filename); /* copy string */ - } + /* join path and file name */ + rt_snprintf(fullpath, strlen(directory) + strlen(filename) + 2, + "%s/%s", directory, filename); + } + else + { + fullpath = rt_strdup(filename); /* copy string */ + } - src = fullpath; - dst = fullpath; - - dst0 = dst; - while (1) - { - char c = *src; + src = fullpath; + dst = fullpath; + + dst0 = dst; + while (1) + { + char c = *src; - if (c == '.') - { - if (!src[1]) src ++; /* '.' and ends */ - else if (src[1] == '/') - { - /* './' case */ - src += 2; + if (c == '.') + { + if (!src[1]) src ++; /* '.' and ends */ + else if (src[1] == '/') + { + /* './' case */ + src += 2; - while ((*src == '/') && (*src != '\0')) - src ++; - continue; - } - else if (src[1] == '.') - { - if (!src[2]) - { - /* '..' and ends case */ - src += 2; - goto up_one; - } - else if (src[2] == '/') - { - /* '../' case */ - src += 3; + while ((*src == '/') && (*src != '\0')) + src ++; + continue; + } + else if (src[1] == '.') + { + if (!src[2]) + { + /* '..' and ends case */ + src += 2; + goto up_one; + } + else if (src[2] == '/') + { + /* '../' case */ + src += 3; - while ((*src == '/') && (*src != '\0')) - src ++; - goto up_one; - } - } - } + while ((*src == '/') && (*src != '\0')) + src ++; + goto up_one; + } + } + } - /* copy up the next '/' and erase all '/' */ - while ((c = *src++) != '\0' && c != '/') - *dst ++ = c; + /* copy up the next '/' and erase all '/' */ + while ((c = *src++) != '\0' && c != '/') + *dst ++ = c; - if (c == '/') - { - *dst ++ = '/'; - while (c == '/') - c = *src++; + if (c == '/') + { + *dst ++ = '/'; + while (c == '/') + c = *src++; - src --; - } - else if (!c) - break; + src --; + } + else if (!c) + break; - continue; + continue; up_one: - dst --; - if (dst < dst0) - { - rt_free(fullpath); - return RT_NULL; - } - while (dst0 < dst && dst[-1] != '/') - dst --; - } + dst --; + if (dst < dst0) + { + rt_free(fullpath); + return RT_NULL; + } + while (dst0 < dst && dst[-1] != '/') + dst --; + } - *dst = '\0'; + *dst = '\0'; - /* remove '/' in the end of path if exist */ - dst --; - if ((dst != fullpath) && (*dst == '/')) - *dst = '\0'; + /* remove '/' in the end of path if exist */ + dst --; + if ((dst != fullpath) && (*dst == '/')) + *dst = '\0'; - return fullpath; + return fullpath; } /*@}*/ |
