summaryrefslogtreecommitdiff
path: root/components/dfs
diff options
context:
space:
mode:
Diffstat (limited to 'components/dfs')
-rw-r--r--components/dfs/filesystems/elmfat/dfs_elm.c39
-rw-r--r--components/dfs/filesystems/elmfat/ff.c2
-rw-r--r--components/dfs/filesystems/nfs/SConscript2
-rw-r--r--components/dfs/filesystems/nfs/dfs_nfs.c13
-rw-r--r--components/dfs/filesystems/nfs/mount_xdr.c2
-rw-r--r--components/dfs/filesystems/nfs/nfs_auth.c172
-rw-r--r--components/dfs/filesystems/nfs/nfs_xdr.c2
-rw-r--r--components/dfs/filesystems/uffs/dfs_uffs.c4
-rw-r--r--components/dfs/include/dfs_file.h4
-rw-r--r--components/dfs/include/dfs_fs.h1
-rw-r--r--components/dfs/include/dfs_posix.h1
-rw-r--r--components/dfs/src/dfs.c8
-rw-r--r--components/dfs/src/dfs_file.c33
-rw-r--r--components/dfs/src/dfs_fs.c39
-rw-r--r--components/dfs/src/dfs_posix.c50
-rw-r--r--components/dfs/src/poll.c5
-rw-r--r--components/dfs/src/select.c3
17 files changed, 360 insertions, 20 deletions
diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c
index a45c15aa03..b4c4c627aa 100644
--- a/components/dfs/filesystems/elmfat/dfs_elm.c
+++ b/components/dfs/filesystems/elmfat/dfs_elm.c
@@ -202,7 +202,7 @@ int dfs_elm_mkfs(rt_device_t dev_id)
int index;
char logic_nbr[2] = {'0', ':'};
- work = rt_malloc(_MAX_SS);
+ work = (BYTE *)rt_malloc(_MAX_SS);
if (RT_NULL == work)
{
return -ENOMEM;
@@ -233,7 +233,7 @@ int dfs_elm_mkfs(rt_device_t dev_id)
}
else
{
- fat = rt_malloc(sizeof(FATFS));
+ fat = (FATFS *)rt_malloc(sizeof(FATFS));
if (fat == RT_NULL)
{
rt_free(work); /* release memory */
@@ -340,7 +340,7 @@ int dfs_elm_open(struct dfs_fd *file)
vol = elm_get_vol((FATFS *)fs->data);
if (vol < 0)
return -ENOENT;
- drivers_fn = rt_malloc(256);
+ drivers_fn = (char *)rt_malloc(256);
if (drivers_fn == RT_NULL)
return -ENOMEM;
@@ -478,6 +478,33 @@ int dfs_elm_close(struct dfs_fd *file)
int dfs_elm_ioctl(struct dfs_fd *file, int cmd, void *args)
{
+ switch (cmd)
+ {
+ case RT_FIOFTRUNCATE:
+ {
+ FIL *fd;
+ FSIZE_t fptr, length;
+ FRESULT result = FR_OK;
+ fd = (FIL *)(file->data);
+ RT_ASSERT(fd != RT_NULL);
+
+ /* save file read/write point */
+ fptr = fd->fptr;
+ length = *(off_t*)args;
+ if (length <= fd->obj.objsize)
+ {
+ fd->fptr = length;
+ result = f_truncate(fd);
+ }
+ else
+ {
+ result = f_lseek(fd, length);
+ }
+ /* restore file read/write point */
+ fd->fptr = fptr;
+ return elm_result_to_dfs(result);
+ }
+ }
return -ENOSYS;
}
@@ -648,7 +675,7 @@ int dfs_elm_unlink(struct dfs_filesystem *fs, const char *path)
vol = elm_get_vol((FATFS *)fs->data);
if (vol < 0)
return -ENOENT;
- drivers_fn = rt_malloc(256);
+ drivers_fn = (char *)rt_malloc(256);
if (drivers_fn == RT_NULL)
return -ENOMEM;
@@ -680,7 +707,7 @@ int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *n
if (vol < 0)
return -ENOENT;
- drivers_oldfn = rt_malloc(256);
+ drivers_oldfn = (char *)rt_malloc(256);
if (drivers_oldfn == RT_NULL)
return -ENOMEM;
drivers_newfn = newpath;
@@ -714,7 +741,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
vol = elm_get_vol((FATFS *)fs->data);
if (vol < 0)
return -ENOENT;
- drivers_fn = rt_malloc(256);
+ drivers_fn = (char *)rt_malloc(256);
if (drivers_fn == RT_NULL)
return -ENOMEM;
diff --git a/components/dfs/filesystems/elmfat/ff.c b/components/dfs/filesystems/elmfat/ff.c
index 4a2f0258b6..19df7450e2 100644
--- a/components/dfs/filesystems/elmfat/ff.c
+++ b/components/dfs/filesystems/elmfat/ff.c
@@ -569,7 +569,7 @@ static WCHAR LfnBuf[_MAX_LFN+1]; /* LFN enabled with static working buffer */
#define FREE_NAMBUF() ff_memfree(lfn)
#else
#define DEF_NAMBUF WCHAR *lfn;
-#define INIT_NAMBUF(fs) { lfn = ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; }
+#define INIT_NAMBUF(fs) { lfn = (WCHAR *)ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; }
#define FREE_NAMBUF() ff_memfree(lfn)
#endif
diff --git a/components/dfs/filesystems/nfs/SConscript b/components/dfs/filesystems/nfs/SConscript
index 8f1e6defcd..f830dfc754 100644
--- a/components/dfs/filesystems/nfs/SConscript
+++ b/components/dfs/filesystems/nfs/SConscript
@@ -6,6 +6,8 @@ cwd = GetCurrentDir()
src = Glob('*.c') + Glob('rpc/*.c')
CPPPATH = [cwd]
+SrcRemove(src, ['rpc/auth_none.c'])
+
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS', 'RT_USING_DFS_NFS'], CPPPATH = CPPPATH)
Return('group')
diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c
index f365314564..e60f6f98c0 100644
--- a/components/dfs/filesystems/nfs/dfs_nfs.c
+++ b/components/dfs/filesystems/nfs/dfs_nfs.c
@@ -225,7 +225,7 @@ static nfs_fh3 *get_dir_handle(nfs_filesystem *nfs, const char *name)
copy_handle(handle, &nfs->current_handle);
}
- while ((file = strtok_r(NULL, "/", &path)) != NULL && path[0] != 0)
+ while ((file = strtok_r(NULL, "/", &path)) != NULL && path && path[0] != 0)
{
LOOKUP3args args;
LOOKUP3res res;
@@ -747,7 +747,7 @@ int nfs_open(struct dfs_fd *file)
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
-
+ RT_ASSERT(nfs != NULL);
if (file->flags & O_DIRECTORY)
{
@@ -1106,6 +1106,15 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
if (name == NULL)
break;
+ if (rt_strcmp(name, ".") == 0)
+ {
+ continue;
+ }
+ else if (rt_strcmp(name, "..") == 0)
+ {
+ continue;
+ }
+
d->d_type = DT_REG;
d->d_namlen = rt_strlen(name);
diff --git a/components/dfs/filesystems/nfs/mount_xdr.c b/components/dfs/filesystems/nfs/mount_xdr.c
index 8e191d3017..04faa3bb7a 100644
--- a/components/dfs/filesystems/nfs/mount_xdr.c
+++ b/components/dfs/filesystems/nfs/mount_xdr.c
@@ -101,6 +101,8 @@ xdr_mountres3(register XDR *xdrs, mountres3 *objp)
if (!xdr_mountres3_ok(xdrs, &objp->mountres3_u.mountinfo))
return (FALSE);
break;
+ default :
+ return (FALSE);
}
return (TRUE);
}
diff --git a/components/dfs/filesystems/nfs/nfs_auth.c b/components/dfs/filesystems/nfs/nfs_auth.c
new file mode 100644
index 0000000000..c65a1126a6
--- /dev/null
+++ b/components/dfs/filesystems/nfs/nfs_auth.c
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
+
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#include <rpc/auth.h>
+
+#define MAX_MARSHEL_SIZE 64
+
+struct nfs_credentia
+{
+ rt_uint32_t stamp;
+ char *name;
+ rt_uint32_t uid;
+ rt_uint32_t gid;
+ rt_uint32_t *auxi;
+ rt_uint32_t auxi_count;
+};
+
+static void authnone_verf(AUTH *);
+static bool_t authnone_validate(AUTH *, struct opaque_auth *);
+static bool_t authnone_refresh(AUTH *);
+static void authnone_destroy(AUTH *);
+static bool_t authnone_marshal(AUTH *client, XDR *xdrs);
+
+static struct nfs_credentia _credentia = {
+ .stamp = 0,
+ .name = "rt-thread",
+ .uid = 0,
+ .gid = 0,
+ .auxi = NULL,
+ .auxi_count = 0,
+};
+
+struct opaque_auth _null_auth;
+
+static struct auth_ops ops =
+{
+ authnone_verf,
+ authnone_marshal,
+ authnone_validate,
+ authnone_refresh,
+ authnone_destroy
+};
+
+static struct authnone_private
+{
+ AUTH no_client;
+ char marshalled_client[MAX_MARSHEL_SIZE];
+ unsigned int mcnt;
+} *authnone_private;
+
+AUTH *authnone_create(void)
+{
+ register struct authnone_private *ap = authnone_private;
+ XDR xdr_stream;
+ register XDR *xdrs;
+ extern bool_t xdr_opaque_auth(XDR * xdrs, struct opaque_auth * ap);
+ struct opaque_auth auth;
+ rt_uint32_t *auth_buf, *auth_base;
+ int buf_len = 0, str_len = 0;
+
+ if (_credentia.name)
+ {
+ str_len = strlen(_credentia.name);
+ }
+ if (str_len == 0)
+ {
+ _credentia.name = "unknown";
+ str_len = strlen(_credentia.name);
+ }
+ buf_len = ((str_len) + (sizeof(rt_uint32_t)) - 1) & ~((sizeof(rt_uint32_t)) - 1);
+ buf_len += sizeof(struct nfs_credentia);
+ if (_credentia.auxi && _credentia.auxi_count)
+ {
+ buf_len += sizeof(rt_uint32_t) * _credentia.auxi_count;
+ }
+ auth_buf = auth_base = rt_malloc(buf_len);
+ if (auth_buf == NULL)
+ {
+ return NULL;
+ }
+ memset(auth_buf, 0, buf_len);
+ *auth_buf++ = htonl(rt_tick_get());
+ *auth_buf++ = htonl(str_len);
+ memcpy(auth_buf, _credentia.name, str_len);
+ auth_buf += (str_len + sizeof(rt_uint32_t) - 1) >> 2;
+ *auth_buf++ = htonl(_credentia.uid);
+ *auth_buf++ = htonl(_credentia.gid);
+ if (_credentia.auxi && _credentia.auxi_count)
+ {
+ rt_uint32_t tmp_cnt = 0;
+ *auth_buf++ = htonl(_credentia.auxi_count);
+ while (tmp_cnt < _credentia.auxi_count)
+ {
+ *auth_buf++ = htonl(_credentia.auxi[tmp_cnt]);
+ }
+ }
+ else
+ {
+ *auth_buf++ = htonl(0);
+ }
+
+ if (ap == 0)
+ {
+ ap = (struct authnone_private *) rt_malloc(sizeof(*ap));
+ if (ap == 0)
+ {
+ rt_free(auth_base);
+ return NULL;
+ }
+ memset(ap, 0, sizeof(*ap));
+ authnone_private = ap;
+ }
+
+ if (!ap->mcnt)
+ {
+ memset(&auth, 0, sizeof(auth));
+ auth.oa_flavor = 1;
+ auth.oa_base = (char *)auth_base;
+ auth.oa_length = (auth_buf - auth_base) * sizeof(rt_uint32_t);
+ ap->no_client.ah_cred = auth;
+ ap->no_client.ah_verf = _null_auth;
+ ap->no_client.ah_ops = &ops;
+ xdrs = &xdr_stream;
+ xdrmem_create(xdrs, ap->marshalled_client,
+ (unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
+ (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
+ (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
+ ap->mcnt = XDR_GETPOS(xdrs);
+ XDR_DESTROY(xdrs);
+ }
+ rt_free(auth_base);
+ return (&ap->no_client);
+}
+
+/*ARGSUSED*/
+static bool_t authnone_marshal(AUTH *client, XDR *xdrs)
+{
+ register struct authnone_private *ap = authnone_private;
+
+ if (ap == 0)
+ return (0);
+ return ((*xdrs->x_ops->x_putbytes)(xdrs,
+ ap->marshalled_client, ap->mcnt));
+}
+
+static void authnone_verf(AUTH *x)
+{
+}
+
+static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
+{
+
+ return (TRUE);
+}
+
+static bool_t authnone_refresh(AUTH *x)
+{
+
+ return (FALSE);
+}
+
+static void authnone_destroy(AUTH *x)
+{
+}
diff --git a/components/dfs/filesystems/nfs/nfs_xdr.c b/components/dfs/filesystems/nfs/nfs_xdr.c
index 4cd69ba743..33563976c3 100644
--- a/components/dfs/filesystems/nfs/nfs_xdr.c
+++ b/components/dfs/filesystems/nfs/nfs_xdr.c
@@ -496,6 +496,8 @@ xdr_GETATTR3res(register XDR *xdrs, GETATTR3res *objp)
if (!xdr_GETATTR3resok(xdrs, &objp->GETATTR3res_u.resok))
return (FALSE);
break;
+ default :
+ return (FALSE);
}
return (TRUE);
}
diff --git a/components/dfs/filesystems/uffs/dfs_uffs.c b/components/dfs/filesystems/uffs/dfs_uffs.c
index c89102f3e3..fb8caf9dd7 100644
--- a/components/dfs/filesystems/uffs/dfs_uffs.c
+++ b/components/dfs/filesystems/uffs/dfs_uffs.c
@@ -226,7 +226,7 @@ static int dfs_uffs_mkfs(rt_device_t dev_id)
}
/*2. then unmount the partition */
- uffs_Mount(nand_part[index].mount_path);
+ uffs_UnMount(nand_part[index].mount_path);
mtd = nand_part[index].dev;
/*3. erase all blocks on the partition */
@@ -234,11 +234,13 @@ static int dfs_uffs_mkfs(rt_device_t dev_id)
for (; block <= mtd->block_end; block++)
{
rt_mtd_nand_erase_block(mtd, block);
+#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
if (rt_mtd_nand_check_block(mtd, block) != RT_EOK)
{
rt_kprintf("found bad block %d\n", block);
rt_mtd_nand_mark_badblock(mtd, block);
}
+#endif
}
/*4. remount it */
diff --git a/components/dfs/include/dfs_file.h b/components/dfs/include/dfs_file.h
index aaff3f6e9c..2dfacd653e 100644
--- a/components/dfs/include/dfs_file.h
+++ b/components/dfs/include/dfs_file.h
@@ -66,6 +66,10 @@ int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
int dfs_file_stat(const char *path, struct stat *buf);
int dfs_file_rename(const char *oldpath, const char *newpath);
+int dfs_file_ftruncate(struct dfs_fd *fd, off_t length);
+
+/* 0x5254 is just a magic number to make these relatively unique ("RT") */
+#define RT_FIOFTRUNCATE 0x52540000U
#ifdef __cplusplus
}
diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h
index d3a00fc542..58a9e5cf55 100644
--- a/components/dfs/include/dfs_fs.h
+++ b/components/dfs/include/dfs_fs.h
@@ -90,6 +90,7 @@ int dfs_unmount(const char *specialfile);
int dfs_mkfs(const char *fs_name, const char *device_name);
int dfs_statfs(const char *path, struct statfs *buffer);
+int dfs_mount_device(rt_device_t dev);
#ifdef __cplusplus
}
diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h
index 9fd76debe2..87d5f0771e 100644
--- a/components/dfs/include/dfs_posix.h
+++ b/components/dfs/include/dfs_posix.h
@@ -58,6 +58,7 @@ int fstat(int fildes, struct stat *buf);
int fsync(int fildes);
int fcntl(int fildes, int cmd, ...);
int ioctl(int fildes, int cmd, ...);
+int ftruncate(int fd, off_t length);
/* directory api*/
int rmdir(const char *path);
diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c
index 5bddb96930..b20de13988 100644
--- a/components/dfs/src/dfs.c
+++ b/components/dfs/src/dfs.c
@@ -141,7 +141,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
cnt = fdt->maxfd + 4;
cnt = cnt > DFS_FD_MAX ? DFS_FD_MAX : cnt;
- fds = rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *));
+ fds = (struct dfs_fd **)rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *));
if (fds == NULL) goto __exit; /* return fdt->maxfd */
/* clean the new allocated fds */
@@ -157,7 +157,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd)
/* allocate 'struct dfs_fd' */
if (idx < (int)fdt->maxfd && fdt->fds[idx] == RT_NULL)
{
- fdt->fds[idx] = rt_calloc(1, sizeof(struct dfs_fd));
+ fdt->fds[idx] = (struct dfs_fd *)rt_calloc(1, sizeof(struct dfs_fd));
if (fdt->fds[idx] == RT_NULL)
idx = fdt->maxfd;
}
@@ -393,7 +393,7 @@ char *dfs_normalize_path(const char *directory, const char *filename)
if (filename[0] != '/') /* it's a absolute path, use it directly */
{
- fullpath = rt_malloc(strlen(directory) + strlen(filename) + 2);
+ fullpath = (char *)rt_malloc(strlen(directory) + strlen(filename) + 2);
if (fullpath == NULL)
return NULL;
@@ -537,7 +537,7 @@ int list_fd(void)
if (fd && fd->fops)
{
- rt_kprintf("%2d ", index);
+ rt_kprintf("%2d ", index + DFS_FD_OFFSET);
if (fd->type == FT_DIRECTORY) rt_kprintf("%-7.7s ", "dir");
else if (fd->type == FT_REGULAR) rt_kprintf("%-7.7s ", "file");
else if (fd->type == FT_SOCKET) rt_kprintf("%-7.7s ", "socket");
diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c
index 65fd0c45e8..1063a278ab 100644
--- a/components/dfs/src/dfs_file.c
+++ b/components/dfs/src/dfs_file.c
@@ -482,6 +482,35 @@ __exit:
return result;
}
+/**
+ * this function is will cause the regular file referenced by fd
+ * to be truncated to a size of precisely length bytes.
+ *
+ * @param fd the file descriptor.
+ * @param length the length to be truncated.
+ *
+ * @return the status of truncated.
+ */
+int dfs_file_ftruncate(struct dfs_fd *fd, off_t length)
+{
+ int result;
+
+ /* fd is null or not a regular file system fd, or length is invalid */
+ if (fd == NULL || fd->type != FT_REGULAR || length < 0)
+ return -EINVAL;
+
+ if (fd->fops->ioctl == NULL)
+ return -ENOSYS;
+
+ result = fd->fops->ioctl(fd, RT_FIOFTRUNCATE, (void*)&length);
+
+ /* update current size */
+ if (result == 0)
+ fd->size = length;
+
+ return result;
+}
+
#ifdef RT_USING_FINSH
#include <finsh.h>
@@ -600,7 +629,7 @@ static void copyfile(const char *src, const char *dst)
rt_uint8_t *block_ptr;
rt_int32_t read_bytes;
- block_ptr = rt_malloc(BUF_SZ);
+ block_ptr = (rt_uint8_t *)rt_malloc(BUF_SZ);
if (block_ptr == NULL)
{
rt_kprintf("out of memory\n");
@@ -715,7 +744,7 @@ static void copydir(const char *src, const char *dst)
static const char *_get_path_lastname(const char *path)
{
char *ptr;
- if ((ptr = strrchr(path, '/')) == NULL)
+ if ((ptr = (char *)strrchr(path, '/')) == NULL)
return path;
/* skip the '/' then return */
diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c
index 04d862e85d..164beed719 100644
--- a/components/dfs/src/dfs_fs.c
+++ b/components/dfs/src/dfs_fs.c
@@ -508,7 +508,7 @@ int dfs_mount_table(void)
mount_table[index].rwflag,
mount_table[index].data) != 0)
{
- rt_kprintf("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype,
+ LOG_E("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype,
mount_table[index].path);
return -RT_ERROR;
}
@@ -518,6 +518,43 @@ int dfs_mount_table(void)
return 0;
}
INIT_ENV_EXPORT(dfs_mount_table);
+
+int dfs_mount_device(rt_device_t dev)
+{
+ int index = 0;
+
+ if(dev == RT_NULL) {
+ rt_kprintf("the device is NULL to be mounted.\n");
+ return -RT_ERROR;
+ }
+
+ while (1)
+ {
+ if (mount_table[index].path == NULL) break;
+
+ if(strcmp(mount_table[index].device_name, dev->parent.name) == 0) {
+ if (dfs_mount(mount_table[index].device_name,
+ mount_table[index].path,
+ mount_table[index].filesystemtype,
+ mount_table[index].rwflag,
+ mount_table[index].data) != 0)
+ {
+ LOG_E("mount fs[%s] device[%s] to %s failed.\n", mount_table[index].filesystemtype, dev->parent.name,
+ mount_table[index].path);
+ return -RT_ERROR;
+ } else {
+ LOG_D("mount fs[%s] device[%s] to %s ok.\n", mount_table[index].filesystemtype, dev->parent.name,
+ mount_table[index].path);
+ return RT_EOK;
+ }
+ }
+
+ index ++;
+ }
+
+ rt_kprintf("can't find device:%s to be mounted.\n", dev->parent.name);
+ return -RT_ERROR;
+}
#endif
#ifdef RT_USING_FINSH
diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c
index 6d643e2d4a..fc603df437 100644
--- a/components/dfs/src/dfs_posix.c
+++ b/components/dfs/src/dfs_posix.c
@@ -265,11 +265,11 @@ RTM_EXPORT(lseek);
*
* note: the old and new file name must be belong to a same file system.
*/
-int rename(const char *old, const char *new)
+int rename(const char *old_file, const char *new_file)
{
int result;
- result = dfs_file_rename(old, new);
+ result = dfs_file_rename(old_file, new_file);
if (result < 0)
{
rt_set_errno(result);
@@ -472,6 +472,52 @@ int ioctl(int fildes, int cmd, ...)
RTM_EXPORT(ioctl);
/**
+ *
+ * this function is a POSIX compliant version, which cause the regular file
+ * referenced by fd to be truncated to a size of precisely length bytes.
+ * @param fd the file descriptor.
+ * @param length the length to be truncated.
+ *
+ * @return Upon successful completion, ftruncate() shall return 0;
+ * otherwise, -1 shall be returned and errno set to indicate the error.
+ */
+int ftruncate(int fd, off_t length)
+{
+ int result;
+ struct dfs_fd *d;
+
+ d = fd_get(fd);
+ if (d == NULL)
+ {
+ rt_set_errno(-EBADF);
+
+ return -1;
+ }
+
+ if (length < 0)
+ {
+ fd_put(d);
+ rt_set_errno(-EINVAL);
+
+ return -1;
+ }
+ result = dfs_file_ftruncate(d, length);
+ if (result < 0)
+ {
+ fd_put(d);
+ rt_set_errno(result);
+
+ return -1;
+ }
+
+ /* release the ref-count of fd */
+ fd_put(d);
+
+ return 0;
+}
+RTM_EXPORT(ftruncate);
+
+/**
* this function is a POSIX compliant version, which will return the
* information about a mounted file system.
*
diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c
index aee157eed5..3f304549f7 100644
--- a/components/dfs/src/poll.c
+++ b/components/dfs/src/poll.c
@@ -19,6 +19,8 @@
#include <dfs_posix.h>
#include <dfs_poll.h>
+#ifdef RT_USING_POSIX
+
struct rt_poll_node;
struct rt_poll_table
@@ -54,7 +56,7 @@ static void _poll_add(rt_wqueue_t *wq, rt_pollreq_t *req)
struct rt_poll_table *pt;
struct rt_poll_node *node;
- node = rt_malloc(sizeof(struct rt_poll_node));
+ node = (struct rt_poll_node *)rt_malloc(sizeof(struct rt_poll_node));
if (node == RT_NULL)
return;
@@ -214,3 +216,4 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
return num;
}
+#endif
diff --git a/components/dfs/src/select.c b/components/dfs/src/select.c
index b20f7cf656..181855bc74 100644
--- a/components/dfs/src/select.c
+++ b/components/dfs/src/select.c
@@ -14,6 +14,8 @@
#include <dfs_poll.h>
#include <dfs_select.h>
+#ifdef RT_USING_POSIX
+
static void fdszero(fd_set *set, int nfds)
{
fd_mask *m;
@@ -178,3 +180,4 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
return ret;
}
+#endif