提交 fdc7dfc7 编写于 作者: D dzzxzz@gmail.com

use RT_NULL instead of NULL in DFS, and format the code in DFS

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2213 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 9d4072ce
/*
* File : dfs.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -38,6 +38,7 @@ struct dfs_fd fd_table[DFS_FD_MAX];
/**
* @addtogroup DFS
*/
/*@{*/
/**
......@@ -204,6 +205,7 @@ int fd_is_open(const char *pathname)
{
/* can't find mounted file system */
rt_free(fullpath);
return -1;
}
......@@ -225,6 +227,7 @@ int fd_is_open(const char *pathname)
/* found file in file descriptor table */
rt_free(fullpath);
dfs_unlock();
return 0;
}
}
......@@ -256,6 +259,7 @@ const char *dfs_subdir(const char *directory, const char *filename)
{
dir --;
}
return dir;
}
......@@ -276,12 +280,13 @@ char *dfs_normalize_path(const char *directory, const char *filename)
RT_ASSERT(filename != RT_NULL);
#ifdef DFS_USING_WORKDIR
if (directory == NULL) /* shall use working directory */
if (directory == RT_NULL) /* shall use working directory */
directory = &working_directory[0];
#else
if ((directory == NULL) && (filename[0] != '/'))
if ((directory == RT_NULL) && (filename[0] != '/'))
{
rt_kprintf(NO_WORKING_DIR);
return RT_NULL;
}
#endif
......@@ -361,7 +366,7 @@ up_one:
if (dst < dst0)
{
rt_free(fullpath);
return NULL;
return RT_NULL;
}
while (dst0 < dst && dst[-1] != '/')
dst --;
......
......@@ -58,6 +58,7 @@ int open(const char *file, int flags, int mode)
/* release the ref-count of fd */
fd_put(d);
return fd;
}
......@@ -87,10 +88,12 @@ int close(int fd)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
fd_put(d);
return 0;
}
......@@ -128,6 +131,7 @@ int read(int fd, void *buf, size_t len)
/* release the ref-count of fd */
fd_put(d);
return result;
}
......@@ -151,6 +155,7 @@ int write(int fd, const void *buf, size_t len)
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
......@@ -165,6 +170,7 @@ int write(int fd, const void *buf, size_t len)
/* release the ref-count of fd */
fd_put(d);
return result;
}
......@@ -206,12 +212,12 @@ off_t lseek(int fd, off_t offset, int whence)
default:
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
}
if (offset < 0)
{
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
}
result = dfs_file_lseek(d, offset);
......@@ -219,11 +225,13 @@ off_t lseek(int fd, off_t offset, int whence)
{
fd_put(d);
rt_set_errno(result);
return -1;
}
/* release the ref-count of fd */
fd_put(d);
return offset;
}
......@@ -246,8 +254,10 @@ int rename(const char *old, const char *new)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
return 0;
}
......@@ -267,8 +277,10 @@ int unlink(const char *pathname)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
return 0;
}
......@@ -288,8 +300,10 @@ int stat(const char *file, struct stat *buf)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
return result;
}
......@@ -308,6 +322,7 @@ int fstat(int fildes, struct stat *buf)
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
......@@ -348,6 +363,7 @@ int statfs(const char *path, struct statfs *buf)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
......@@ -372,6 +388,7 @@ int mkdir(const char *path, mode_t mode)
if (fd == -1)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
return -1;
}
......@@ -383,11 +400,13 @@ int mkdir(const char *path, mode_t mode)
{
fd_put(d);
rt_set_errno(result);
return -1;
}
dfs_file_close(d);
fd_put(d);
return 0;
}
#ifdef RT_USING_FINSH
......@@ -400,7 +419,7 @@ FINSH_FUNCTION_EXPORT(mkdir, create a directory);
*
* @param pathname the path name to be removed.
*
* @return 0 on sucessfull, others on failed.
* @return 0 on successful, others on failed.
*/
int rmdir(const char *pathname)
{
......@@ -410,6 +429,7 @@ int rmdir(const char *pathname)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
......@@ -436,6 +456,7 @@ DIR *opendir(const char *name)
if (fd == -1)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
return RT_NULL;
}
d = fd_get(fd);
......@@ -456,6 +477,7 @@ DIR *opendir(const char *name)
t->fd = fd;
}
fd_put(d);
return t;
}
......@@ -485,6 +507,7 @@ struct dirent *readdir(DIR *d)
if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return RT_NULL;
}
......@@ -505,6 +528,7 @@ struct dirent *readdir(DIR *d)
}
fd_put(fd);
return (struct dirent *)(d->buf+d->cur);
}
......@@ -525,6 +549,7 @@ long telldir(DIR *d)
if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return 0;
}
......@@ -549,6 +574,7 @@ void seekdir(DIR *d, off_t offset)
if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return ;
}
......@@ -571,6 +597,7 @@ void rewinddir(DIR *d)
if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return ;
}
......@@ -597,6 +624,7 @@ int closedir(DIR *d)
if (fd == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
......@@ -609,9 +637,11 @@ int closedir(DIR *d)
if (result < 0)
{
rt_set_errno(result);
return -1;
}
else return 0;
else
return 0;
}
#ifdef DFS_USING_WORKDIR
......@@ -632,12 +662,14 @@ int chdir(const char *path)
dfs_lock();
rt_kprintf("%s\n", working_directory);
dfs_unlock();
return 0;
}
if (rt_strlen(path) > DFS_PATH_MAX)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1;
}
......@@ -645,6 +677,7 @@ int chdir(const char *path)
if (fullpath == RT_NULL)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1; /* build path failed */
}
......@@ -655,6 +688,7 @@ int chdir(const char *path)
rt_free(fullpath);
/* this is a not exist directory */
dfs_unlock();
return -1;
}
......@@ -692,6 +726,7 @@ char *getcwd(char *buf, size_t size)
#else
rt_kprintf("WARNING: not support working directory\n");
#endif
return buf;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册