diff options
| author | bernard.xiong <[email protected]> | 2010-10-19 08:18:24 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-10-19 08:18:24 +0000 |
| commit | b4a98e4457c3a58301b41db5db50bfbca4546255 (patch) | |
| tree | 161b79af9aa9f3cebeab41905ec795a69658c2e9 /components/dfs/src | |
| parent | 14a0eaf61780622995868dc00e9fb0bf7dddd4f8 (diff) | |
Improve the Device File System of the POSIX compatibility
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1015 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/dfs/src')
| -rw-r--r-- | components/dfs/src/dfs_file.c | 25 | ||||
| -rw-r--r-- | components/dfs/src/dfs_fs.c | 6 | ||||
| -rw-r--r-- | components/dfs/src/dfs_posix.c | 34 |
3 files changed, 29 insertions, 36 deletions
diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 0d708d82fb..c326052090 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -176,7 +176,7 @@ int dfs_file_read(struct dfs_fd* fd, void *buf, rt_size_t len) *
* @return the read dirent, others on failed.
*/
-int dfs_file_getdents(struct dfs_fd* fd, struct _dirent* dirp, rt_size_t nbytes)
+int dfs_file_getdents(struct dfs_fd* fd, struct dirent* dirp, rt_size_t nbytes)
{
struct dfs_filesystem* fs;
@@ -306,7 +306,7 @@ int dfs_file_lseek(struct dfs_fd* fd, rt_off_t offset) *
* @return 0 on successful, -1 on failed.
*/
-int dfs_file_stat(const char *path, struct _stat *buf)
+int dfs_file_stat(const char *path, struct stat *buf)
{
int result;
char* fullpath;
@@ -434,10 +434,10 @@ __exit: #include <finsh.h>
static struct dfs_fd fd;
-static struct _dirent dirent;
+static struct dirent dirent;
void ls(const char* pathname)
{
- struct _stat stat;
+ struct stat stat;
int length;
char* fullpath;
@@ -449,11 +449,11 @@ void ls(const char* pathname) rt_kprintf("Directory %s:\n", pathname);
do
{
- rt_memset(&dirent, 0, sizeof(struct _dirent));
- length = dfs_file_getdents(&fd, &dirent, sizeof(struct _dirent));
+ rt_memset(&dirent, 0, sizeof(struct dirent));
+ length = dfs_file_getdents(&fd, &dirent, sizeof(struct dirent));
if ( length > 0 )
{
- rt_memset(&stat, 0, sizeof(struct _stat));
+ rt_memset(&stat, 0, sizeof(struct stat));
/* build full path for each file */
if (pathname[strlen(pathname) - 1] != '/')
@@ -483,17 +483,6 @@ void ls(const char* pathname) }
FINSH_FUNCTION_EXPORT(ls, list directory contents)
-static void mkdir(const char* pathname)
-{
- /* make a new directory */
- if (dfs_file_open(&fd, pathname, DFS_O_DIRECTORY | DFS_O_CREAT) == 0)
- {
- dfs_file_close(&fd);
- }
- else rt_kprintf("Can't mkdir %s\n", pathname);
-}
-FINSH_FUNCTION_EXPORT(mkdir, make a directory)
-
void rm(const char* filename)
{
if (dfs_file_unlink(filename) < 0)
diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 71ddb479ec..9db83a16c9 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -266,7 +266,7 @@ int dfs_mount(const char* device_name, const char* path, index++) ;
if ( index == DFS_FILESYSTEMS_MAX ) /* can't find en empty filesystem table entry */
{
- rt_set_errno(-DFS_STATUS_EMMOUNT);
+ rt_set_errno(-DFS_STATUS_ENOSPC);
goto err1;
}
@@ -408,7 +408,7 @@ int dfs_mkfs(const char* fs_name, const char* device_name) *
* @return 0 on successful, others on failed.
*/
-int dfs_statfs(const char* path, struct _statfs* buffer)
+int dfs_statfs(const char* path, struct statfs* buffer)
{
struct dfs_filesystem* fs;
@@ -432,7 +432,7 @@ FINSH_FUNCTION_EXPORT(mkfs, make a file system); void df(const char* path)
{
- struct _statfs buffer;
+ struct statfs buffer;
if (dfs_statfs(path, &buffer) == 0)
{
diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 415ae455b1..26395aafc6 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -95,7 +95,7 @@ int close(int fd) *
* @return the actual read data buffer length
*/
-int read(int fd, char *buf, int len)
+int read(int fd, void *buf, size_t len)
{
int result;
struct dfs_fd* d;
@@ -132,7 +132,7 @@ int read(int fd, char *buf, int len) *
* @return the actual written data buffer length.
*/
-int write(int fd, char *buf, int len)
+int write(int fd, const void *buf, size_t len)
{
int result;
struct dfs_fd* d;
@@ -169,7 +169,7 @@ int write(int fd, char *buf, int len) *
* @return the current file position, or -1 on failed.
*/
-int lseek(int fd, int offset, int dir)
+off_t lseek(int fd, off_t offset, int whence)
{
int result;
struct dfs_fd* d;
@@ -181,7 +181,7 @@ int lseek(int fd, int offset, int dir) return -1;
}
- switch (dir)
+ switch (whence)
{
case DFS_SEEK_SET:
break;
@@ -261,7 +261,7 @@ int unlink(const char *pathname) *
* @return 0 on successful, -1 on failed.
*/
-int stat(const char *file, struct _stat *buf)
+int stat(const char *file, struct stat *buf)
{
int result;
@@ -283,7 +283,7 @@ int stat(const char *file, struct _stat *buf) *
* @return 0 on successful, others on failed.
*/
-int statfs(const char *path, struct _statfs *buf)
+int statfs(const char *path, struct statfs *buf)
{
int result;
@@ -305,7 +305,7 @@ int statfs(const char *path, struct _statfs *buf) *
* @return 0 on successful, others on failed.
*/
-int mkdir (const char *path, rt_uint16_t mode)
+int mkdir (const char *path, mode_t mode)
{
int fd;
struct dfs_fd* d;
@@ -326,6 +326,10 @@ int mkdir (const char *path, rt_uint16_t mode) fd_put(d);
return 0;
}
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+FINSH_FUNCTION_EXPORT(mkdir, create a directory);
+#endif
/**
* this function is a POSIX compliant version, which will remove a directory.
@@ -404,7 +408,7 @@ DIR* opendir(const char* name) *
* @return the next directory entry, NULL on the end of directory or failed.
*/
-struct _dirent* readdir(DIR *d)
+struct dirent* readdir(DIR *d)
{
int result;
struct dfs_fd* fd;
@@ -416,9 +420,9 @@ struct _dirent* readdir(DIR *d) return RT_NULL;
}
- if (!d->num || (d->cur += ((struct _dirent*)(d->buf + d->cur))->d_reclen) >= d->num)
+ if (!d->num || (d->cur += ((struct dirent*)(d->buf + d->cur))->d_reclen) >= d->num)
{
- result = dfs_file_getdents(fd, (struct _dirent*)d->buf, sizeof(d->buf) - 1);
+ result = dfs_file_getdents(fd, (struct dirent*)d->buf, sizeof(d->buf) - 1);
if (result <= 0)
{
rt_set_errno(result);
@@ -432,7 +436,7 @@ struct _dirent* readdir(DIR *d) }
fd_put(fd);
- return (struct _dirent*)(d->buf+d->cur);
+ return (struct dirent*)(d->buf+d->cur);
}
/**
@@ -443,10 +447,10 @@ struct _dirent* readdir(DIR *d) *
* @return the current location in directory stream.
*/
-rt_off_t telldir(DIR *d)
+long telldir(DIR *d)
{
struct dfs_fd* fd;
- rt_off_t result;
+ long result;
fd = fd_get(d->fd);
if (fd == RT_NULL)
@@ -468,7 +472,7 @@ rt_off_t telldir(DIR *d) * @param d the directory stream.
* @param offset the offset in directory stream.
*/
-void seekdir(DIR *d, rt_off_t offset)
+void seekdir(DIR *d, off_t offset)
{
struct dfs_fd* fd;
@@ -589,7 +593,7 @@ int chdir(const char *path) *
* @return the returned current directory.
*/
-char* getcwd(char *buf, rt_size_t size)
+char *getcwd(char *buf, size_t size)
{
#ifdef DFS_USING_WORKDIR
dfs_lock();
|
