|
@@ -11,13 +11,14 @@
|
|
* Date Author Notes
|
|
* Date Author Notes
|
|
* 2012-11-27 prife the first version
|
|
* 2012-11-27 prife the first version
|
|
* 2013-03-03 aozima add dfs_win32_stat st_mtime support.
|
|
* 2013-03-03 aozima add dfs_win32_stat st_mtime support.
|
|
|
|
+ * 2017-10-20 urey support rt-thread 3.0
|
|
*/
|
|
*/
|
|
#include <rtthread.h>
|
|
#include <rtthread.h>
|
|
|
|
+#include <rtlibc.h>
|
|
|
|
|
|
#include <dfs_fs.h>
|
|
#include <dfs_fs.h>
|
|
-#include <dfs_def.h>
|
|
|
|
|
|
+#include <dfs_file.h>
|
|
#include <rtdevice.h>
|
|
#include <rtdevice.h>
|
|
-//#include "dfs_win32.h"
|
|
|
|
|
|
|
|
#include <io.h>
|
|
#include <io.h>
|
|
#include <fcntl.h>
|
|
#include <fcntl.h>
|
|
@@ -48,7 +49,7 @@
|
|
*/
|
|
*/
|
|
#define FILE_PATH_MAX 256 /* the longest file path */
|
|
#define FILE_PATH_MAX 256 /* the longest file path */
|
|
|
|
|
|
-#define WIN32_DIRDISK_ROOT "." /* "F:\\Project\\svn\\rtt\\trunk\\bsp\\simulator_test" */
|
|
|
|
|
|
+#define WIN32_DIRDISK_ROOT "./disk" /* "F:\\Project\\svn\\rtt\\trunk\\bsp\\simulator_test" */
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
HANDLE handle;
|
|
HANDLE handle;
|
|
@@ -71,13 +72,13 @@ struct _errcode_map
|
|
|
|
|
|
static const struct _errcode_map errcode_table[] =
|
|
static const struct _errcode_map errcode_table[] =
|
|
{
|
|
{
|
|
- {DFS_STATUS_ENOENT, ERROR_FILE_NOT_FOUND },
|
|
|
|
- {DFS_STATUS_ENOENT, ERROR_PATH_NOT_FOUND },
|
|
|
|
- {DFS_STATUS_EEXIST, ERROR_FILE_EXISTS },
|
|
|
|
- {DFS_STATUS_EEXIST, ERROR_ALREADY_EXISTS },
|
|
|
|
- {DFS_STATUS_ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
|
|
|
|
- {DFS_STATUS_EBUSY, ERROR_PATH_BUSY },
|
|
|
|
- {DFS_STATUS_EINVAL, ERROR_ACCESS_DENIED },
|
|
|
|
|
|
+ {ENOENT, ERROR_FILE_NOT_FOUND },
|
|
|
|
+ {ENOENT, ERROR_PATH_NOT_FOUND },
|
|
|
|
+ {EEXIST, ERROR_FILE_EXISTS },
|
|
|
|
+ {EEXIST, ERROR_ALREADY_EXISTS },
|
|
|
|
+ {ENOTEMPTY, ERROR_DIR_NOT_EMPTY },
|
|
|
|
+ {EBUSY, ERROR_PATH_BUSY },
|
|
|
|
+ {EINVAL, ERROR_ACCESS_DENIED },
|
|
|
|
|
|
#if 0 /* TODO: MORE NEED BE ADDED */
|
|
#if 0 /* TODO: MORE NEED BE ADDED */
|
|
{DFS_STATUS_EISDIR, ERROR_FILE_EXISTS },
|
|
{DFS_STATUS_EISDIR, ERROR_FILE_EXISTS },
|
|
@@ -121,13 +122,13 @@ static int dfs_win32_unmount(struct dfs_filesystem *fs)
|
|
|
|
|
|
static int dfs_win32_mkfs(rt_device_t devid)
|
|
static int dfs_win32_mkfs(rt_device_t devid)
|
|
{
|
|
{
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
static int dfs_win32_statfs(struct dfs_filesystem *fs,
|
|
static int dfs_win32_statfs(struct dfs_filesystem *fs,
|
|
struct statfs *buf)
|
|
struct statfs *buf)
|
|
{
|
|
{
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
static char *winpath_dirdup(char *des, const char *src)
|
|
static char *winpath_dirdup(char *des, const char *src)
|
|
@@ -167,12 +168,12 @@ char * dfs_win32_dirdup(char * path)
|
|
static int dfs_win32_open(struct dfs_fd *file)
|
|
static int dfs_win32_open(struct dfs_fd *file)
|
|
{
|
|
{
|
|
int fd;
|
|
int fd;
|
|
- int oflag, mode;
|
|
|
|
|
|
+ uint32_t oflag, mode;
|
|
char *file_path;
|
|
char *file_path;
|
|
int res;
|
|
int res;
|
|
|
|
|
|
oflag = file->flags;
|
|
oflag = file->flags;
|
|
- if (oflag & DFS_O_DIRECTORY) /* operations about dir */
|
|
|
|
|
|
+ if (oflag & O_DIRECTORY) /* operations about dir */
|
|
{
|
|
{
|
|
WINDIR *wdirp;
|
|
WINDIR *wdirp;
|
|
HANDLE handle;
|
|
HANDLE handle;
|
|
@@ -180,7 +181,7 @@ static int dfs_win32_open(struct dfs_fd *file)
|
|
|
|
|
|
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->path);
|
|
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->path);
|
|
|
|
|
|
- if (oflag & DFS_O_CREAT) /* create a dir*/
|
|
|
|
|
|
+ if (oflag & O_CREAT) /* create a dir*/
|
|
{
|
|
{
|
|
res = CreateDirectory(file_path, NULL);
|
|
res = CreateDirectory(file_path, NULL);
|
|
if (res == 0)
|
|
if (res == 0)
|
|
@@ -218,19 +219,19 @@ static int dfs_win32_open(struct dfs_fd *file)
|
|
|
|
|
|
file->data = (void *)wdirp;
|
|
file->data = (void *)wdirp;
|
|
rt_free(file_path);
|
|
rt_free(file_path);
|
|
- return DFS_STATUS_OK;
|
|
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
/* regular file operations */
|
|
/* regular file operations */
|
|
mode = O_BINARY;
|
|
mode = O_BINARY;
|
|
- if (oflag & DFS_O_RDONLY) mode |= O_RDONLY;
|
|
|
|
- if (oflag & DFS_O_WRONLY) mode |= O_WRONLY;
|
|
|
|
- if (oflag & DFS_O_RDWR) mode |= O_RDWR;
|
|
|
|
|
|
+ if (oflag & O_RDONLY) mode |= O_RDONLY;
|
|
|
|
+ if (oflag & O_WRONLY) mode |= O_WRONLY;
|
|
|
|
+ if (oflag & O_RDWR) mode |= O_RDWR;
|
|
/* Opens the file, if it is existing. If not, a new file is created. */
|
|
/* Opens the file, if it is existing. If not, a new file is created. */
|
|
- if (oflag & DFS_O_CREAT) mode |= O_CREAT;
|
|
|
|
|
|
+ if (oflag & O_CREAT) mode |= O_CREAT;
|
|
/* Creates a new file. If the file is existing, it is truncated and overwritten. */
|
|
/* Creates a new file. If the file is existing, it is truncated and overwritten. */
|
|
- if (oflag & DFS_O_TRUNC) mode |= O_TRUNC;
|
|
|
|
|
|
+ if (oflag & O_TRUNC) mode |= O_TRUNC;
|
|
/* Creates a new file. The function fails if the file is already existing. */
|
|
/* Creates a new file. The function fails if the file is already existing. */
|
|
- if (oflag & DFS_O_EXCL) mode |= O_EXCL;
|
|
|
|
|
|
+ if (oflag & O_EXCL) mode |= O_EXCL;
|
|
|
|
|
|
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->path);
|
|
file_path = winpath_dirdup(WIN32_DIRDISK_ROOT, file->path);
|
|
fd = _open(file_path, mode, 0x0100 | 0x0080); /* _S_IREAD | _S_IWRITE */
|
|
fd = _open(file_path, mode, 0x0100 | 0x0080); /* _S_IREAD | _S_IWRITE */
|
|
@@ -245,7 +246,7 @@ static int dfs_win32_open(struct dfs_fd *file)
|
|
file->pos = 0;
|
|
file->pos = 0;
|
|
file->size = _lseek(fd, 0, SEEK_END);
|
|
file->size = _lseek(fd, 0, SEEK_END);
|
|
|
|
|
|
- if (oflag & DFS_O_APPEND)
|
|
|
|
|
|
+ if (oflag & O_APPEND)
|
|
{
|
|
{
|
|
file->pos = file->size;
|
|
file->pos = file->size;
|
|
}
|
|
}
|
|
@@ -261,7 +262,7 @@ __err:
|
|
|
|
|
|
static int dfs_win32_close(struct dfs_fd *file)
|
|
static int dfs_win32_close(struct dfs_fd *file)
|
|
{
|
|
{
|
|
- if (file->flags & DFS_O_DIRECTORY)
|
|
|
|
|
|
+ if (file->flags & O_DIRECTORY)
|
|
{
|
|
{
|
|
WINDIR *wdirp = (WINDIR*)(file->data);
|
|
WINDIR *wdirp = (WINDIR*)(file->data);
|
|
RT_ASSERT(wdirp != RT_NULL);
|
|
RT_ASSERT(wdirp != RT_NULL);
|
|
@@ -282,10 +283,10 @@ static int dfs_win32_close(struct dfs_fd *file)
|
|
|
|
|
|
static int dfs_win32_ioctl(struct dfs_fd *file, int cmd, void *args)
|
|
static int dfs_win32_ioctl(struct dfs_fd *file, int cmd, void *args)
|
|
{
|
|
{
|
|
- return -DFS_STATUS_ENOSYS;
|
|
|
|
|
|
+ return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
|
|
-static int dfs_win32_read(struct dfs_fd *file, void *buf, rt_size_t len)
|
|
|
|
|
|
+static int dfs_win32_read(struct dfs_fd *file, void *buf, size_t len)
|
|
{
|
|
{
|
|
int fd;
|
|
int fd;
|
|
int char_read;
|
|
int char_read;
|
|
@@ -300,9 +301,7 @@ static int dfs_win32_read(struct dfs_fd *file, void *buf, rt_size_t len)
|
|
return char_read;
|
|
return char_read;
|
|
}
|
|
}
|
|
|
|
|
|
-static int dfs_win32_write(struct dfs_fd *file,
|
|
|
|
- const void *buf,
|
|
|
|
- rt_size_t len)
|
|
|
|
|
|
+static int dfs_win32_write(struct dfs_fd *file, const void *buf, size_t len)
|
|
{
|
|
{
|
|
int fd;
|
|
int fd;
|
|
int char_write;
|
|
int char_write;
|
|
@@ -347,10 +346,7 @@ static int dfs_win32_seek(struct dfs_fd *file,
|
|
}
|
|
}
|
|
|
|
|
|
/* return the size of struct dirent*/
|
|
/* return the size of struct dirent*/
|
|
-static int dfs_win32_getdents(
|
|
|
|
- struct dfs_fd *file,
|
|
|
|
- struct dirent *dirp,
|
|
|
|
- rt_uint32_t count)
|
|
|
|
|
|
+static int dfs_win32_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
|
|
{
|
|
{
|
|
WINDIR *wdirp;
|
|
WINDIR *wdirp;
|
|
struct dirent *d = dirp;
|
|
struct dirent *d = dirp;
|
|
@@ -358,7 +354,7 @@ static int dfs_win32_getdents(
|
|
|
|
|
|
/* make integer count */
|
|
/* make integer count */
|
|
if (count / sizeof(struct dirent) != 1)
|
|
if (count / sizeof(struct dirent) != 1)
|
|
- return -DFS_STATUS_EINVAL;
|
|
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
wdirp = (WINDIR*)(file->data);
|
|
wdirp = (WINDIR*)(file->data);
|
|
RT_ASSERT(wdirp != RT_NULL);
|
|
RT_ASSERT(wdirp != RT_NULL);
|
|
@@ -367,9 +363,9 @@ static int dfs_win32_getdents(
|
|
|
|
|
|
/* get the current entry */
|
|
/* get the current entry */
|
|
if (wdirp->finddata.attrib & _A_SUBDIR)
|
|
if (wdirp->finddata.attrib & _A_SUBDIR)
|
|
- d->d_type = DFS_DT_DIR;
|
|
|
|
|
|
+ d->d_type = DT_DIR;
|
|
else
|
|
else
|
|
- d->d_type = DFS_DT_REG;
|
|
|
|
|
|
+ d->d_type = DT_REG;
|
|
d->d_namlen = strlen(wdirp->curr);
|
|
d->d_namlen = strlen(wdirp->curr);
|
|
strncpy(d->d_name, wdirp->curr, DFS_PATH_MAX);
|
|
strncpy(d->d_name, wdirp->curr, DFS_PATH_MAX);
|
|
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
|
|
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
|
|
@@ -408,7 +404,7 @@ static int dfs_win32_unlink(struct dfs_filesystem *fs, const char *path)
|
|
if (fp == RT_NULL)
|
|
if (fp == RT_NULL)
|
|
{
|
|
{
|
|
rt_kprintf("out of memory.\n");
|
|
rt_kprintf("out of memory.\n");
|
|
- return -DFS_STATUS_ENOMEM;
|
|
|
|
|
|
+ return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
result = GetFileAttributes(fp);
|
|
result = GetFileAttributes(fp);
|
|
@@ -445,7 +441,7 @@ static int dfs_win32_rename(
|
|
if (op == RT_NULL || np == RT_NULL)
|
|
if (op == RT_NULL || np == RT_NULL)
|
|
{
|
|
{
|
|
rt_kprintf("out of memory.\n");
|
|
rt_kprintf("out of memory.\n");
|
|
- return -DFS_STATUS_ENOMEM;
|
|
|
|
|
|
+ return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
/* If the function fails, the return value is zero. */
|
|
/* If the function fails, the return value is zero. */
|
|
@@ -469,7 +465,7 @@ static int dfs_win32_stat(struct dfs_filesystem *fs, const char *path, struct st
|
|
if (fp == RT_NULL)
|
|
if (fp == RT_NULL)
|
|
{
|
|
{
|
|
rt_kprintf("out of memory.\n");
|
|
rt_kprintf("out of memory.\n");
|
|
- return -DFS_STATUS_ENOMEM;
|
|
|
|
|
|
+ return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
|
|
hFind = FindFirstFile(fp, &fileInfo);
|
|
hFind = FindFirstFile(fp, &fileInfo);
|
|
@@ -478,14 +474,14 @@ static int dfs_win32_stat(struct dfs_filesystem *fs, const char *path, struct st
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
goto __err;
|
|
goto __err;
|
|
|
|
|
|
- st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
|
|
|
|
- DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
|
|
|
|
|
|
+ st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
|
|
|
|
+ S_IWUSR | S_IWGRP | S_IWOTH;
|
|
|
|
|
|
/* convert file info to dfs stat structure */
|
|
/* convert file info to dfs stat structure */
|
|
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
{
|
|
{
|
|
- st->st_mode &= ~DFS_S_IFREG;
|
|
|
|
- st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
|
|
|
|
|
|
+ st->st_mode &= ~S_IFREG;
|
|
|
|
+ st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
}
|
|
}
|
|
|
|
|
|
st->st_dev = 0;
|
|
st->st_dev = 0;
|
|
@@ -513,15 +509,8 @@ __err:
|
|
return win32_result_to_dfs(GetLastError());
|
|
return win32_result_to_dfs(GetLastError());
|
|
}
|
|
}
|
|
|
|
|
|
-static const struct dfs_filesystem_operation dfs_win32_ops =
|
|
|
|
|
|
+static const struct dfs_file_ops dfs_win32_file_ops =
|
|
{
|
|
{
|
|
- "wdir", /* file system type: dir */
|
|
|
|
- DFS_FS_FLAG_DEFAULT,
|
|
|
|
- dfs_win32_mount,
|
|
|
|
- dfs_win32_unmount,
|
|
|
|
- dfs_win32_mkfs,
|
|
|
|
- dfs_win32_statfs,
|
|
|
|
-
|
|
|
|
dfs_win32_open,
|
|
dfs_win32_open,
|
|
dfs_win32_close,
|
|
dfs_win32_close,
|
|
dfs_win32_ioctl,
|
|
dfs_win32_ioctl,
|
|
@@ -530,6 +519,17 @@ static const struct dfs_filesystem_operation dfs_win32_ops =
|
|
dfs_win32_flush,
|
|
dfs_win32_flush,
|
|
dfs_win32_seek,
|
|
dfs_win32_seek,
|
|
dfs_win32_getdents,
|
|
dfs_win32_getdents,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static const struct dfs_filesystem_ops dfs_win32_ops =
|
|
|
|
+{
|
|
|
|
+ "wdir", /* file system type: dir */
|
|
|
|
+ DFS_FS_FLAG_DEFAULT,
|
|
|
|
+ &dfs_win32_file_ops,
|
|
|
|
+ dfs_win32_mount,
|
|
|
|
+ dfs_win32_unmount,
|
|
|
|
+ dfs_win32_mkfs,
|
|
|
|
+ dfs_win32_statfs,
|
|
dfs_win32_unlink,
|
|
dfs_win32_unlink,
|
|
dfs_win32_stat,
|
|
dfs_win32_stat,
|
|
dfs_win32_rename,
|
|
dfs_win32_rename,
|