|
@@ -26,6 +26,7 @@
|
|
|
|
|
|
#include <dfs.h>
|
|
#include <dfs.h>
|
|
#include <dfs_file.h>
|
|
#include <dfs_file.h>
|
|
|
|
+#include <dfs_private.h>
|
|
|
|
|
|
/**
|
|
/**
|
|
* @addtogroup FileApi
|
|
* @addtogroup FileApi
|
|
@@ -49,44 +50,53 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
|
|
int result;
|
|
int result;
|
|
|
|
|
|
/* parameter check */
|
|
/* parameter check */
|
|
- if (fd == RT_NULL)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ if (fd == NULL)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
/* make sure we have an absolute path */
|
|
/* make sure we have an absolute path */
|
|
- fullpath = dfs_normalize_path(RT_NULL, path);
|
|
|
|
- if (fullpath == RT_NULL)
|
|
|
|
|
|
+ fullpath = dfs_normalize_path(NULL, path);
|
|
|
|
+ if (fullpath == NULL)
|
|
{
|
|
{
|
|
- return -1;
|
|
|
|
|
|
+ return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
- dfs_log(DFS_DEBUG_INFO, ("open file:%s", fullpath));
|
|
|
|
|
|
+ dbg_log(DBG_LOG, "open file:%s\n", fullpath);
|
|
|
|
+
|
|
|
|
+ /* Check whether file is already open */
|
|
|
|
+ if (fd_is_open(fullpath) == 0)
|
|
|
|
+ {
|
|
|
|
+ rt_free(fullpath); /* release path */
|
|
|
|
+
|
|
|
|
+ return -EBUSY;
|
|
|
|
+ }
|
|
|
|
|
|
/* find filesystem */
|
|
/* find filesystem */
|
|
fs = dfs_filesystem_lookup(fullpath);
|
|
fs = dfs_filesystem_lookup(fullpath);
|
|
- if (fs == RT_NULL)
|
|
|
|
|
|
+ if (fs == NULL)
|
|
{
|
|
{
|
|
rt_free(fullpath); /* release path */
|
|
rt_free(fullpath); /* release path */
|
|
|
|
|
|
- return -DFS_STATUS_ENOENT;
|
|
|
|
|
|
+ return -ENOENT;
|
|
}
|
|
}
|
|
|
|
|
|
- dfs_log(DFS_DEBUG_INFO, ("open in filesystem:%s", fs->ops->name));
|
|
|
|
- fd->fs = fs;
|
|
|
|
|
|
+ dbg_log(DBG_LOG, "open in filesystem:%s\n", fs->ops->name);
|
|
|
|
+ fd->fops = fs->ops->fops; /* set file ops */
|
|
|
|
|
|
/* initialize the fd item */
|
|
/* initialize the fd item */
|
|
fd->type = FT_REGULAR;
|
|
fd->type = FT_REGULAR;
|
|
fd->flags = flags;
|
|
fd->flags = flags;
|
|
fd->size = 0;
|
|
fd->size = 0;
|
|
fd->pos = 0;
|
|
fd->pos = 0;
|
|
|
|
+ fd->data = fs;
|
|
|
|
|
|
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
|
|
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
|
|
{
|
|
{
|
|
- if (dfs_subdir(fs->path, fullpath) == RT_NULL)
|
|
|
|
|
|
+ if (dfs_subdir(fs->path, fullpath) == NULL)
|
|
fd->path = rt_strdup("/");
|
|
fd->path = rt_strdup("/");
|
|
else
|
|
else
|
|
fd->path = rt_strdup(dfs_subdir(fs->path, fullpath));
|
|
fd->path = rt_strdup(dfs_subdir(fs->path, fullpath));
|
|
rt_free(fullpath);
|
|
rt_free(fullpath);
|
|
- dfs_log(DFS_DEBUG_INFO, ("Actual file path: %s\n", fd->path));
|
|
|
|
|
|
+ dbg_log(DBG_LOG, "Actual file path: %s\n", fd->path);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -94,34 +104,34 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
|
|
}
|
|
}
|
|
|
|
|
|
/* specific file system open routine */
|
|
/* specific file system open routine */
|
|
- if (fs->ops->open == RT_NULL)
|
|
|
|
|
|
+ if (fd->fops->open == NULL)
|
|
{
|
|
{
|
|
/* clear fd */
|
|
/* clear fd */
|
|
rt_free(fd->path);
|
|
rt_free(fd->path);
|
|
- fd->path = RT_NULL;
|
|
|
|
|
|
+ fd->path = NULL;
|
|
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
- if ((result = fs->ops->open(fd)) < 0)
|
|
|
|
|
|
+ if ((result = fd->fops->open(fd)) < 0)
|
|
{
|
|
{
|
|
/* clear fd */
|
|
/* clear fd */
|
|
rt_free(fd->path);
|
|
rt_free(fd->path);
|
|
- fd->path = RT_NULL;
|
|
|
|
|
|
+ fd->path = NULL;
|
|
|
|
|
|
- dfs_log(DFS_DEBUG_INFO, ("open failed"));
|
|
|
|
|
|
+ dbg_log(DBG_ERROR, "open failed\n");
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
fd->flags |= DFS_F_OPEN;
|
|
fd->flags |= DFS_F_OPEN;
|
|
- if (flags & DFS_O_DIRECTORY)
|
|
|
|
|
|
+ if (flags & O_DIRECTORY)
|
|
{
|
|
{
|
|
fd->type = FT_DIRECTORY;
|
|
fd->type = FT_DIRECTORY;
|
|
fd->flags |= DFS_F_DIRECTORY;
|
|
fd->flags |= DFS_F_DIRECTORY;
|
|
}
|
|
}
|
|
|
|
|
|
- dfs_log(DFS_DEBUG_INFO, ("open successful"));
|
|
|
|
|
|
+ dbg_log(DBG_INFO, "open successful\n");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -136,18 +146,18 @@ int dfs_file_close(struct dfs_fd *fd)
|
|
{
|
|
{
|
|
int result = 0;
|
|
int result = 0;
|
|
|
|
|
|
- if (fd == RT_NULL)
|
|
|
|
- return -DFS_STATUS_ENXIO;
|
|
|
|
|
|
+ if (fd == NULL)
|
|
|
|
+ return -ENXIO;
|
|
|
|
|
|
- if (fd != RT_NULL && fd->fs->ops->close != RT_NULL)
|
|
|
|
- result = fd->fs->ops->close(fd);
|
|
|
|
|
|
+ if (fd->fops->close != NULL)
|
|
|
|
+ result = fd->fops->close(fd);
|
|
|
|
|
|
/* close fd error, return */
|
|
/* close fd error, return */
|
|
if (result < 0)
|
|
if (result < 0)
|
|
return result;
|
|
return result;
|
|
|
|
|
|
rt_free(fd->path);
|
|
rt_free(fd->path);
|
|
- fd->path = RT_NULL;
|
|
|
|
|
|
+ fd->path = NULL;
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -163,16 +173,13 @@ int dfs_file_close(struct dfs_fd *fd)
|
|
*/
|
|
*/
|
|
int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
|
|
int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
|
|
{
|
|
{
|
|
- struct dfs_filesystem *fs;
|
|
|
|
-
|
|
|
|
- if (fd == RT_NULL || fd->type != FT_REGULAR)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ if (fd == NULL || fd->type != FT_REGULAR)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
- fs = fd->fs;
|
|
|
|
- if (fs->ops->ioctl != RT_NULL)
|
|
|
|
- return fs->ops->ioctl(fd, cmd, args);
|
|
|
|
|
|
+ if (fd->fops->ioctl != NULL)
|
|
|
|
+ return fd->fops->ioctl(fd, cmd, args);
|
|
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -185,19 +192,17 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
|
|
*
|
|
*
|
|
* @return the actual read data bytes or 0 on end of file or failed.
|
|
* @return the actual read data bytes or 0 on end of file or failed.
|
|
*/
|
|
*/
|
|
-int dfs_file_read(struct dfs_fd *fd, void *buf, rt_size_t len)
|
|
|
|
|
|
+int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len)
|
|
{
|
|
{
|
|
- struct dfs_filesystem *fs;
|
|
|
|
int result = 0;
|
|
int result = 0;
|
|
|
|
|
|
- if (fd == RT_NULL)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ if (fd == NULL)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
- fs = (struct dfs_filesystem *)fd->fs;
|
|
|
|
- if (fs->ops->read == RT_NULL)
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ if (fd->fops->read == NULL)
|
|
|
|
+ return -ENOSYS;
|
|
|
|
|
|
- if ((result = fs->ops->read(fd, buf, len)) < 0)
|
|
|
|
|
|
+ if ((result = fd->fops->read(fd, buf, len)) < 0)
|
|
fd->flags |= DFS_F_EOF;
|
|
fd->flags |= DFS_F_EOF;
|
|
|
|
|
|
return result;
|
|
return result;
|
|
@@ -212,19 +217,16 @@ int dfs_file_read(struct dfs_fd *fd, void *buf, rt_size_t len)
|
|
*
|
|
*
|
|
* @return the read dirent, others on failed.
|
|
* @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, size_t nbytes)
|
|
{
|
|
{
|
|
- struct dfs_filesystem *fs;
|
|
|
|
-
|
|
|
|
/* parameter check */
|
|
/* parameter check */
|
|
- if (fd == RT_NULL || fd->type != FT_DIRECTORY)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ if (fd == NULL || fd->type != FT_DIRECTORY)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
- fs = (struct dfs_filesystem *)fd->fs;
|
|
|
|
- if (fs->ops->getdents != RT_NULL)
|
|
|
|
- return fs->ops->getdents(fd, dirp, nbytes);
|
|
|
|
|
|
+ if (fd->fops->getdents != NULL)
|
|
|
|
+ return fd->fops->getdents(fd, dirp, nbytes);
|
|
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -241,31 +243,31 @@ int dfs_file_unlink(const char *path)
|
|
struct dfs_filesystem *fs;
|
|
struct dfs_filesystem *fs;
|
|
|
|
|
|
/* Make sure we have an absolute path */
|
|
/* Make sure we have an absolute path */
|
|
- fullpath = dfs_normalize_path(RT_NULL, path);
|
|
|
|
- if (fullpath == RT_NULL)
|
|
|
|
|
|
+ fullpath = dfs_normalize_path(NULL, path);
|
|
|
|
+ if (fullpath == NULL)
|
|
{
|
|
{
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
/* get filesystem */
|
|
/* get filesystem */
|
|
- if ((fs = dfs_filesystem_lookup(fullpath)) == RT_NULL)
|
|
|
|
|
|
+ if ((fs = dfs_filesystem_lookup(fullpath)) == NULL)
|
|
{
|
|
{
|
|
- result = -DFS_STATUS_ENOENT;
|
|
|
|
|
|
+ result = -ENOENT;
|
|
goto __exit;
|
|
goto __exit;
|
|
}
|
|
}
|
|
|
|
|
|
/* Check whether file is already open */
|
|
/* Check whether file is already open */
|
|
if (fd_is_open(fullpath) == 0)
|
|
if (fd_is_open(fullpath) == 0)
|
|
{
|
|
{
|
|
- result = -DFS_STATUS_EBUSY;
|
|
|
|
|
|
+ result = -EBUSY;
|
|
goto __exit;
|
|
goto __exit;
|
|
}
|
|
}
|
|
|
|
|
|
- if (fs->ops->unlink != RT_NULL)
|
|
|
|
|
|
+ if (fs->ops->unlink != NULL)
|
|
{
|
|
{
|
|
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
|
|
if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
|
|
{
|
|
{
|
|
- if (dfs_subdir(fs->path, fullpath) == RT_NULL)
|
|
|
|
|
|
+ if (dfs_subdir(fs->path, fullpath) == NULL)
|
|
result = fs->ops->unlink(fs, "/");
|
|
result = fs->ops->unlink(fs, "/");
|
|
else
|
|
else
|
|
result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
|
|
result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
|
|
@@ -273,7 +275,7 @@ int dfs_file_unlink(const char *path)
|
|
else
|
|
else
|
|
result = fs->ops->unlink(fs, fullpath);
|
|
result = fs->ops->unlink(fs, fullpath);
|
|
}
|
|
}
|
|
- else result = -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ else result = -ENOSYS;
|
|
|
|
|
|
__exit:
|
|
__exit:
|
|
rt_free(fullpath);
|
|
rt_free(fullpath);
|
|
@@ -289,18 +291,15 @@ __exit:
|
|
*
|
|
*
|
|
* @return the actual written data length.
|
|
* @return the actual written data length.
|
|
*/
|
|
*/
|
|
-int dfs_file_write(struct dfs_fd *fd, const void *buf, rt_size_t len)
|
|
|
|
|
|
+int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len)
|
|
{
|
|
{
|
|
- struct dfs_filesystem *fs;
|
|
|
|
-
|
|
|
|
- if (fd == RT_NULL)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ if (fd == NULL)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
- fs = fd->fs;
|
|
|
|
- if (fs->ops->write == RT_NULL)
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ if (fd->fops->write == NULL)
|
|
|
|
+ return -ENOSYS;
|
|
|
|
|
|
- return fs->ops->write(fd, buf, len);
|
|
|
|
|
|
+ return fd->fops->write(fd, buf, len);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -312,16 +311,13 @@ int dfs_file_write(struct dfs_fd *fd, const void *buf, rt_size_t len)
|
|
*/
|
|
*/
|
|
int dfs_file_flush(struct dfs_fd *fd)
|
|
int dfs_file_flush(struct dfs_fd *fd)
|
|
{
|
|
{
|
|
- struct dfs_filesystem *fs;
|
|
|
|
-
|
|
|
|
- if (fd == RT_NULL)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ if (fd == NULL)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
- fs = fd->fs;
|
|
|
|
- if (fs->ops->flush == RT_NULL)
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ if (fd->fops->flush == NULL)
|
|
|
|
+ return -ENOSYS;
|
|
|
|
|
|
- return fs->ops->flush(fd);
|
|
|
|
|
|
+ return fd->fops->flush(fd);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -332,20 +328,17 @@ int dfs_file_flush(struct dfs_fd *fd)
|
|
*
|
|
*
|
|
* @return the current position after seek.
|
|
* @return the current position after seek.
|
|
*/
|
|
*/
|
|
-int dfs_file_lseek(struct dfs_fd *fd, rt_off_t offset)
|
|
|
|
|
|
+int dfs_file_lseek(struct dfs_fd *fd, off_t offset)
|
|
{
|
|
{
|
|
int result;
|
|
int result;
|
|
- struct dfs_filesystem *fs = fd->fs;
|
|
|
|
|
|
|
|
- if (fd == RT_NULL)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
- fs = fd->fs;
|
|
|
|
- if (fs == RT_NULL)
|
|
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
- if (fs->ops->lseek == RT_NULL)
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ if (fd == NULL)
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
- result = fs->ops->lseek(fd, offset);
|
|
|
|
|
|
+ if (fd->fops->lseek == NULL)
|
|
|
|
+ return -ENOSYS;
|
|
|
|
+
|
|
|
|
+ result = fd->fops->lseek(fd, offset);
|
|
|
|
|
|
/* update current position */
|
|
/* update current position */
|
|
if (result >= 0)
|
|
if (result >= 0)
|
|
@@ -368,30 +361,30 @@ int dfs_file_stat(const char *path, struct stat *buf)
|
|
char *fullpath;
|
|
char *fullpath;
|
|
struct dfs_filesystem *fs;
|
|
struct dfs_filesystem *fs;
|
|
|
|
|
|
- fullpath = dfs_normalize_path(RT_NULL, path);
|
|
|
|
- if (fullpath == RT_NULL)
|
|
|
|
|
|
+ fullpath = dfs_normalize_path(NULL, path);
|
|
|
|
+ if (fullpath == NULL)
|
|
{
|
|
{
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
- if ((fs = dfs_filesystem_lookup(fullpath)) == RT_NULL)
|
|
|
|
|
|
+ if ((fs = dfs_filesystem_lookup(fullpath)) == NULL)
|
|
{
|
|
{
|
|
- dfs_log(DFS_DEBUG_ERROR,
|
|
|
|
- ("can't find mounted filesystem on this path:%s", fullpath));
|
|
|
|
|
|
+ dbg_log(DBG_ERROR,
|
|
|
|
+ "can't find mounted filesystem on this path:%s\n", fullpath);
|
|
rt_free(fullpath);
|
|
rt_free(fullpath);
|
|
|
|
|
|
- return -DFS_STATUS_ENOENT;
|
|
|
|
|
|
+ return -ENOENT;
|
|
}
|
|
}
|
|
|
|
|
|
if ((fullpath[0] == '/' && fullpath[1] == '\0') ||
|
|
if ((fullpath[0] == '/' && fullpath[1] == '\0') ||
|
|
- (dfs_subdir(fs->path, fullpath) == RT_NULL))
|
|
|
|
|
|
+ (dfs_subdir(fs->path, fullpath) == NULL))
|
|
{
|
|
{
|
|
/* it's the root directory */
|
|
/* it's the root directory */
|
|
buf->st_dev = 0;
|
|
buf->st_dev = 0;
|
|
|
|
|
|
- buf->st_mode = DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
|
|
|
|
- DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
|
|
|
|
- buf->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
|
|
|
|
|
|
+ buf->st_mode = S_IRUSR | S_IRGRP | S_IROTH |
|
|
|
|
+ S_IWUSR | S_IWGRP | S_IWOTH;
|
|
|
|
+ buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
|
|
|
|
buf->st_size = 0;
|
|
buf->st_size = 0;
|
|
buf->st_mtime = 0;
|
|
buf->st_mtime = 0;
|
|
@@ -399,17 +392,17 @@ int dfs_file_stat(const char *path, struct stat *buf)
|
|
/* release full path */
|
|
/* release full path */
|
|
rt_free(fullpath);
|
|
rt_free(fullpath);
|
|
|
|
|
|
- return DFS_STATUS_OK;
|
|
|
|
|
|
+ return RT_EOK;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (fs->ops->stat == RT_NULL)
|
|
|
|
|
|
+ if (fs->ops->stat == NULL)
|
|
{
|
|
{
|
|
rt_free(fullpath);
|
|
rt_free(fullpath);
|
|
- dfs_log(DFS_DEBUG_ERROR,
|
|
|
|
- ("the filesystem didn't implement this function"));
|
|
|
|
|
|
+ dbg_log(DBG_ERROR,
|
|
|
|
+ "the filesystem didn't implement this function\n");
|
|
|
|
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
/* get the real file path and get file stat */
|
|
/* get the real file path and get file stat */
|
|
@@ -438,21 +431,21 @@ int dfs_file_rename(const char *oldpath, const char *newpath)
|
|
struct dfs_filesystem *oldfs, *newfs;
|
|
struct dfs_filesystem *oldfs, *newfs;
|
|
char *oldfullpath, *newfullpath;
|
|
char *oldfullpath, *newfullpath;
|
|
|
|
|
|
- result = DFS_STATUS_OK;
|
|
|
|
- newfullpath = RT_NULL;
|
|
|
|
- oldfullpath = RT_NULL;
|
|
|
|
|
|
+ result = RT_EOK;
|
|
|
|
+ newfullpath = NULL;
|
|
|
|
+ oldfullpath = NULL;
|
|
|
|
|
|
- oldfullpath = dfs_normalize_path(RT_NULL, oldpath);
|
|
|
|
- if (oldfullpath == RT_NULL)
|
|
|
|
|
|
+ oldfullpath = dfs_normalize_path(NULL, oldpath);
|
|
|
|
+ if (oldfullpath == NULL)
|
|
{
|
|
{
|
|
- result = -DFS_STATUS_ENOENT;
|
|
|
|
|
|
+ result = -ENOENT;
|
|
goto __exit;
|
|
goto __exit;
|
|
}
|
|
}
|
|
|
|
|
|
- newfullpath = dfs_normalize_path(RT_NULL, newpath);
|
|
|
|
- if (newfullpath == RT_NULL)
|
|
|
|
|
|
+ newfullpath = dfs_normalize_path(NULL, newpath);
|
|
|
|
+ if (newfullpath == NULL)
|
|
{
|
|
{
|
|
- result = -DFS_STATUS_ENOENT;
|
|
|
|
|
|
+ result = -ENOENT;
|
|
goto __exit;
|
|
goto __exit;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -461,9 +454,9 @@ int dfs_file_rename(const char *oldpath, const char *newpath)
|
|
|
|
|
|
if (oldfs == newfs)
|
|
if (oldfs == newfs)
|
|
{
|
|
{
|
|
- if (oldfs->ops->rename == RT_NULL)
|
|
|
|
|
|
+ if (oldfs->ops->rename == NULL)
|
|
{
|
|
{
|
|
- result = -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ result = -ENOSYS;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -478,7 +471,7 @@ int dfs_file_rename(const char *oldpath, const char *newpath)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- result = -DFS_STATUS_EXDEV;
|
|
|
|
|
|
+ result = -EXDEV;
|
|
}
|
|
}
|
|
|
|
|
|
__exit:
|
|
__exit:
|
|
@@ -500,8 +493,8 @@ void ls(const char *pathname)
|
|
int length;
|
|
int length;
|
|
char *fullpath, *path;
|
|
char *fullpath, *path;
|
|
|
|
|
|
- fullpath = RT_NULL;
|
|
|
|
- if (pathname == RT_NULL)
|
|
|
|
|
|
+ fullpath = NULL;
|
|
|
|
+ if (pathname == NULL)
|
|
{
|
|
{
|
|
#ifdef DFS_USING_WORKDIR
|
|
#ifdef DFS_USING_WORKDIR
|
|
/* open current working directory */
|
|
/* open current working directory */
|
|
@@ -509,7 +502,7 @@ void ls(const char *pathname)
|
|
#else
|
|
#else
|
|
path = rt_strdup("/");
|
|
path = rt_strdup("/");
|
|
#endif
|
|
#endif
|
|
- if (path == RT_NULL)
|
|
|
|
|
|
+ if (path == NULL)
|
|
return ; /* out of memory */
|
|
return ; /* out of memory */
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -518,26 +511,26 @@ void ls(const char *pathname)
|
|
}
|
|
}
|
|
|
|
|
|
/* list directory */
|
|
/* list directory */
|
|
- if (dfs_file_open(&fd, path, DFS_O_DIRECTORY) == 0)
|
|
|
|
|
|
+ if (dfs_file_open(&fd, path, O_DIRECTORY) == 0)
|
|
{
|
|
{
|
|
rt_kprintf("Directory %s:\n", path);
|
|
rt_kprintf("Directory %s:\n", path);
|
|
do
|
|
do
|
|
{
|
|
{
|
|
- rt_memset(&dirent, 0, sizeof(struct dirent));
|
|
|
|
|
|
+ memset(&dirent, 0, sizeof(struct dirent));
|
|
length = dfs_file_getdents(&fd, &dirent, sizeof(struct dirent));
|
|
length = dfs_file_getdents(&fd, &dirent, sizeof(struct dirent));
|
|
if (length > 0)
|
|
if (length > 0)
|
|
{
|
|
{
|
|
- rt_memset(&stat, 0, sizeof(struct stat));
|
|
|
|
|
|
+ memset(&stat, 0, sizeof(struct stat));
|
|
|
|
|
|
/* build full path for each file */
|
|
/* build full path for each file */
|
|
fullpath = dfs_normalize_path(path, dirent.d_name);
|
|
fullpath = dfs_normalize_path(path, dirent.d_name);
|
|
- if (fullpath == RT_NULL)
|
|
|
|
|
|
+ if (fullpath == NULL)
|
|
break;
|
|
break;
|
|
|
|
|
|
if (dfs_file_stat(fullpath, &stat) == 0)
|
|
if (dfs_file_stat(fullpath, &stat) == 0)
|
|
{
|
|
{
|
|
rt_kprintf("%-20s", dirent.d_name);
|
|
rt_kprintf("%-20s", dirent.d_name);
|
|
- if ( DFS_S_ISDIR(stat.st_mode))
|
|
|
|
|
|
+ if (S_ISDIR(stat.st_mode))
|
|
{
|
|
{
|
|
rt_kprintf("%-25s\n", "<DIR>");
|
|
rt_kprintf("%-25s\n", "<DIR>");
|
|
}
|
|
}
|
|
@@ -558,7 +551,7 @@ void ls(const char *pathname)
|
|
{
|
|
{
|
|
rt_kprintf("No such directory\n");
|
|
rt_kprintf("No such directory\n");
|
|
}
|
|
}
|
|
- if (pathname == RT_NULL)
|
|
|
|
|
|
+ if (pathname == NULL)
|
|
rt_free(path);
|
|
rt_free(path);
|
|
}
|
|
}
|
|
FINSH_FUNCTION_EXPORT(ls, list directory contents);
|
|
FINSH_FUNCTION_EXPORT(ls, list directory contents);
|
|
@@ -574,10 +567,10 @@ FINSH_FUNCTION_EXPORT(rm, remove files or directories);
|
|
|
|
|
|
void cat(const char* filename)
|
|
void cat(const char* filename)
|
|
{
|
|
{
|
|
- rt_uint32_t length;
|
|
|
|
|
|
+ uint32_t length;
|
|
char buffer[81];
|
|
char buffer[81];
|
|
|
|
|
|
- if (dfs_file_open(&fd, filename, DFS_O_RDONLY) < 0)
|
|
|
|
|
|
+ if (dfs_file_open(&fd, filename, O_RDONLY) < 0)
|
|
{
|
|
{
|
|
rt_kprintf("Open %s failed\n", filename);
|
|
rt_kprintf("Open %s failed\n", filename);
|
|
|
|
|
|
@@ -586,7 +579,7 @@ void cat(const char* filename)
|
|
|
|
|
|
do
|
|
do
|
|
{
|
|
{
|
|
- rt_memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
+ memset(buffer, 0, sizeof(buffer));
|
|
length = dfs_file_read(&fd, buffer, sizeof(buffer)-1 );
|
|
length = dfs_file_read(&fd, buffer, sizeof(buffer)-1 );
|
|
if (length > 0)
|
|
if (length > 0)
|
|
{
|
|
{
|
|
@@ -606,21 +599,21 @@ static void copyfile(const char *src, const char *dst)
|
|
rt_int32_t read_bytes;
|
|
rt_int32_t read_bytes;
|
|
|
|
|
|
block_ptr = rt_malloc(BUF_SZ);
|
|
block_ptr = rt_malloc(BUF_SZ);
|
|
- if (block_ptr == RT_NULL)
|
|
|
|
|
|
+ if (block_ptr == NULL)
|
|
{
|
|
{
|
|
rt_kprintf("out of memory\n");
|
|
rt_kprintf("out of memory\n");
|
|
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- if (dfs_file_open(&src_fd, src, DFS_O_RDONLY) < 0)
|
|
|
|
|
|
+ if (dfs_file_open(&src_fd, src, O_RDONLY) < 0)
|
|
{
|
|
{
|
|
rt_free(block_ptr);
|
|
rt_free(block_ptr);
|
|
rt_kprintf("Read %s failed\n", src);
|
|
rt_kprintf("Read %s failed\n", src);
|
|
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if (dfs_file_open(&fd, dst, DFS_O_WRONLY | DFS_O_CREAT) < 0)
|
|
|
|
|
|
+ if (dfs_file_open(&fd, dst, O_WRONLY | O_CREAT) < 0)
|
|
{
|
|
{
|
|
rt_free(block_ptr);
|
|
rt_free(block_ptr);
|
|
dfs_file_close(&src_fd);
|
|
dfs_file_close(&src_fd);
|
|
@@ -659,7 +652,7 @@ static void copydir(const char * src, const char * dst)
|
|
struct stat stat;
|
|
struct stat stat;
|
|
int length;
|
|
int length;
|
|
struct dfs_fd cpfd;
|
|
struct dfs_fd cpfd;
|
|
- if (dfs_file_open(&cpfd, src, DFS_O_DIRECTORY) < 0)
|
|
|
|
|
|
+ if (dfs_file_open(&cpfd, src, O_DIRECTORY) < 0)
|
|
{
|
|
{
|
|
rt_kprintf("open %s failed\n", src);
|
|
rt_kprintf("open %s failed\n", src);
|
|
return ;
|
|
return ;
|
|
@@ -667,37 +660,38 @@ static void copydir(const char * src, const char * dst)
|
|
|
|
|
|
do
|
|
do
|
|
{
|
|
{
|
|
- rt_memset(&dirent, 0, sizeof(struct dirent));
|
|
|
|
|
|
+ memset(&dirent, 0, sizeof(struct dirent));
|
|
|
|
+
|
|
length = dfs_file_getdents(&cpfd, &dirent, sizeof(struct dirent));
|
|
length = dfs_file_getdents(&cpfd, &dirent, sizeof(struct dirent));
|
|
if (length > 0)
|
|
if (length > 0)
|
|
{
|
|
{
|
|
- char * src_entry_full = RT_NULL;
|
|
|
|
- char * dst_entry_full = RT_NULL;
|
|
|
|
|
|
+ char * src_entry_full = NULL;
|
|
|
|
+ char * dst_entry_full = NULL;
|
|
|
|
|
|
if (strcmp(dirent.d_name, "..") == 0 || strcmp(dirent.d_name, ".") == 0)
|
|
if (strcmp(dirent.d_name, "..") == 0 || strcmp(dirent.d_name, ".") == 0)
|
|
continue;
|
|
continue;
|
|
|
|
|
|
/* build full path for each file */
|
|
/* build full path for each file */
|
|
- if ((src_entry_full = dfs_normalize_path(src, dirent.d_name)) == RT_NULL)
|
|
|
|
|
|
+ if ((src_entry_full = dfs_normalize_path(src, dirent.d_name)) == NULL)
|
|
{
|
|
{
|
|
rt_kprintf("out of memory!\n");
|
|
rt_kprintf("out of memory!\n");
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- if ((dst_entry_full = dfs_normalize_path(dst, dirent.d_name)) == RT_NULL)
|
|
|
|
|
|
+ if ((dst_entry_full = dfs_normalize_path(dst, dirent.d_name)) == NULL)
|
|
{
|
|
{
|
|
rt_kprintf("out of memory!\n");
|
|
rt_kprintf("out of memory!\n");
|
|
rt_free(src_entry_full);
|
|
rt_free(src_entry_full);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- rt_memset(&stat, 0, sizeof(struct stat));
|
|
|
|
|
|
+ memset(&stat, 0, sizeof(struct stat));
|
|
if (dfs_file_stat(src_entry_full, &stat) != 0)
|
|
if (dfs_file_stat(src_entry_full, &stat) != 0)
|
|
{
|
|
{
|
|
rt_kprintf("open file: %s failed\n", dirent.d_name);
|
|
rt_kprintf("open file: %s failed\n", dirent.d_name);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- if (DFS_S_ISDIR(stat.st_mode))
|
|
|
|
|
|
+ if (S_ISDIR(stat.st_mode))
|
|
{
|
|
{
|
|
mkdir(dst_entry_full, 0);
|
|
mkdir(dst_entry_full, 0);
|
|
copydir(src_entry_full, dst_entry_full);
|
|
copydir(src_entry_full, dst_entry_full);
|
|
@@ -717,7 +711,7 @@ static void copydir(const char * src, const char * dst)
|
|
static const char *_get_path_lastname(const char *path)
|
|
static const char *_get_path_lastname(const char *path)
|
|
{
|
|
{
|
|
char * ptr;
|
|
char * ptr;
|
|
- if ((ptr = strrchr(path, '/')) == RT_NULL)
|
|
|
|
|
|
+ if ((ptr = strrchr(path, '/')) == NULL)
|
|
return path;
|
|
return path;
|
|
|
|
|
|
/* skip the '/' then return */
|
|
/* skip the '/' then return */
|
|
@@ -736,7 +730,7 @@ void copy(const char *src, const char *dst)
|
|
#define FLAG_DST_NON_EXSIT 0x00
|
|
#define FLAG_DST_NON_EXSIT 0x00
|
|
|
|
|
|
struct stat stat;
|
|
struct stat stat;
|
|
- rt_uint32_t flag = 0;
|
|
|
|
|
|
+ uint32_t flag = 0;
|
|
|
|
|
|
/* check the staus of src and dst */
|
|
/* check the staus of src and dst */
|
|
if (dfs_file_stat(src, &stat) < 0)
|
|
if (dfs_file_stat(src, &stat) < 0)
|
|
@@ -744,7 +738,7 @@ void copy(const char *src, const char *dst)
|
|
rt_kprintf("copy failed, bad %s\n", src);
|
|
rt_kprintf("copy failed, bad %s\n", src);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if (DFS_S_ISDIR(stat.st_mode))
|
|
|
|
|
|
+ if (S_ISDIR(stat.st_mode))
|
|
flag |= FLAG_SRC_IS_DIR;
|
|
flag |= FLAG_SRC_IS_DIR;
|
|
else
|
|
else
|
|
flag |= FLAG_SRC_IS_FILE;
|
|
flag |= FLAG_SRC_IS_FILE;
|
|
@@ -755,7 +749,7 @@ void copy(const char *src, const char *dst)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (DFS_S_ISDIR(stat.st_mode))
|
|
|
|
|
|
+ if (S_ISDIR(stat.st_mode))
|
|
flag |= FLAG_DST_IS_DIR;
|
|
flag |= FLAG_DST_IS_DIR;
|
|
else
|
|
else
|
|
flag |= FLAG_DST_IS_FILE;
|
|
flag |= FLAG_DST_IS_FILE;
|