diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 4d1418b8085..c392975f419 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -16,6 +16,15 @@ if RT_USING_DFS bool "Using working directory" default y + config RT_USING_DFS_LARGE_FILE + bool "Enable 64-bit DFS internal file offset" + default n + help + Enable this option to use a signed 64-bit file offset type inside + DFS. The POSIX off_t type is still provided by the selected C + library/toolchain, but DFS filesystem drivers and DFS-native helper + APIs can handle file positions and file sizes larger than 2GB. + if RT_USING_DFS_V1 config RT_USING_DFS_MNTTABLE bool "Using mount table for file system" diff --git a/components/dfs/dfs_v1/filesystems/9pfs/dfs_9pfs.c b/components/dfs/dfs_v1/filesystems/9pfs/dfs_9pfs.c index 6e842f51c85..c4ef53579a2 100644 --- a/components/dfs/dfs_v1/filesystems/9pfs/dfs_9pfs.c +++ b/components/dfs/dfs_v1/filesystems/9pfs/dfs_9pfs.c @@ -807,7 +807,7 @@ static int dfs_9pfs_flush(struct dfs_file *fd) return p9_to_fs_err(rc); } -static off_t dfs_9pfs_lseek(struct dfs_file *fd, off_t offset) +static dfs_off_t dfs_9pfs_lseek(struct dfs_file *fd, dfs_off_t offset) { int ret = -EIO; @@ -1049,7 +1049,7 @@ static int dfs_9pfs_unlink(struct dfs_filesystem *fs, const char *pathname) } static int dfs_9pfs_stat(struct dfs_filesystem *fs, - const char *filename, struct stat *st) + const char *filename, struct dfs_stat *st) { int rc = 0, fid; rt_uint32_t size, mode; @@ -1108,8 +1108,8 @@ static int dfs_9pfs_stat(struct dfs_filesystem *fs, st->st_mode |= S_ISVTX; } - st->st_atime = get_rx_value32_of(conn, P9_MSG_STAT_ATIME); - st->st_mtime = get_rx_value32_of(conn, P9_MSG_STAT_MTIME); + st->atime = get_rx_value32_of(conn, P9_MSG_STAT_ATIME); + st->mtime = get_rx_value32_of(conn, P9_MSG_STAT_MTIME); st->st_size = get_rx_value64_of(conn, P9_MSG_STAT_LEN); /* diff --git a/components/dfs/dfs_v1/filesystems/cromfs/dfs_cromfs.c b/components/dfs/dfs_v1/filesystems/cromfs/dfs_cromfs.c index fee8b8dbd15..5158b590ad7 100644 --- a/components/dfs/dfs_v1/filesystems/cromfs/dfs_cromfs.c +++ b/components/dfs/dfs_v1/filesystems/cromfs/dfs_cromfs.c @@ -788,7 +788,7 @@ static int dfs_cromfs_read(struct dfs_file *file, void *buf, size_t count) return length; } -static int dfs_cromfs_lseek(struct dfs_file *file, off_t offset) +static dfs_off_t dfs_cromfs_lseek(struct dfs_file *file, dfs_off_t offset) { if (offset <= file->vnode->size) { @@ -1012,7 +1012,7 @@ static int dfs_cromfs_open(struct dfs_file *file) return ret; } -static int dfs_cromfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) +static int dfs_cromfs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { uint32_t size = 0, osize = 0; int is_dir = 0; @@ -1042,7 +1042,7 @@ static int dfs_cromfs_stat(struct dfs_filesystem *fs, const char *path, struct s st->st_size = osize; } - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } diff --git a/components/dfs/dfs_v1/filesystems/devfs/devfs.c b/components/dfs/dfs_v1/filesystems/devfs/devfs.c index cceb14150e8..d27011e9245 100644 --- a/components/dfs/dfs_v1/filesystems/devfs/devfs.c +++ b/components/dfs/dfs_v1/filesystems/devfs/devfs.c @@ -284,7 +284,7 @@ int dfs_device_fs_unlink(struct dfs_filesystem *fs, const char *path) return RT_EOK; } -int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) +int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { st->st_dev = (dev_t)((size_t)dfs_filesystem_lookup(fs->path)); /* stat root directory */ @@ -296,7 +296,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; st->st_size = 0; - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } @@ -322,7 +322,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat st->st_mode |= S_IFREG; st->st_size = 0; - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } diff --git a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c index effd1bcd7c7..13548f83a3b 100644 --- a/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c @@ -504,13 +504,19 @@ int dfs_elm_ioctl(struct dfs_file *file, int cmd, void *args) { FIL *fd; FSIZE_t fptr, length; + dfs_off_t dfs_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; + dfs_length = *(dfs_off_t*)args; + if (dfs_length < 0 || (dfs_off_t)(FSIZE_t)dfs_length != dfs_length) + { + return -EINVAL; + } + length = (FSIZE_t)dfs_length; if (length <= fd->obj.objsize) { fd->fptr = length; @@ -591,9 +597,14 @@ int dfs_elm_flush(struct dfs_file *file) return elm_result_to_dfs(result); } -off_t dfs_elm_lseek(struct dfs_file *file, off_t offset) +dfs_off_t dfs_elm_lseek(struct dfs_file *file, dfs_off_t offset) { FRESULT result = FR_OK; + if (offset < 0 || (dfs_off_t)(FSIZE_t)offset != offset) + { + return -EINVAL; + } + if (file->vnode->type == FT_REGULAR) { FIL *fd; @@ -602,7 +613,7 @@ off_t dfs_elm_lseek(struct dfs_file *file, off_t offset) fd = (FIL *)(file->data); RT_ASSERT(fd != RT_NULL); - result = f_lseek(fd, offset); + result = f_lseek(fd, (FSIZE_t)offset); if (result == FR_OK) { /* return current position */ @@ -751,7 +762,7 @@ int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *n return elm_result_to_dfs(result); } -int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) +int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { FATFS *f; FILINFO file_info; @@ -836,7 +847,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) tm_file.tm_min = min; /* Minutes: 0-59 */ tm_file.tm_sec = sec; /* Seconds: 0-59 */ - st->st_mtime = timegm(&tm_file); + st->mtime = timegm(&tm_file); } /* get st_mtime. */ } diff --git a/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c b/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c index 2358280a799..950e996648e 100644 --- a/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c +++ b/components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c @@ -475,7 +475,7 @@ static ssize_t dfs_iso9660_read(struct dfs_file *fd, void *buf, size_t count) return rcount; } -static off_t dfs_iso9660_lseek(struct dfs_file *fd, off_t offset) +static dfs_off_t dfs_iso9660_lseek(struct dfs_file *fd, dfs_off_t offset) { int ret = -EIO; @@ -648,7 +648,7 @@ static int dfs_iso9660_unmount(struct dfs_filesystem *fs) } static int dfs_iso9660_stat(struct dfs_filesystem *fs, - const char *filename, struct stat *st) + const char *filename, struct dfs_stat *st) { struct iso9660 *iso = fs->data; struct iso9660_fd *fd = iso9660_lookup(iso, filename, RT_NULL); @@ -668,9 +668,9 @@ static int dfs_iso9660_stat(struct dfs_filesystem *fs, st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; } - st->st_atime = iso9660_convert_unixtime(iso->joliet ? + st->atime = iso9660_convert_unixtime(iso->joliet ? &iso->supp.created : &iso->primary.created); - st->st_mtime = iso9660_convert_unixtime2(&fd->dirent.mtime); + st->mtime = iso9660_convert_unixtime2(&fd->dirent.mtime); st->st_size = rt_le32_to_cpu(fd->dirent.size); rt_free(fd); diff --git a/components/dfs/dfs_v1/filesystems/mqueue/dfs_mqueue.c b/components/dfs/dfs_v1/filesystems/mqueue/dfs_mqueue.c index e279c50de1f..222f1abc62d 100644 --- a/components/dfs/dfs_v1/filesystems/mqueue/dfs_mqueue.c +++ b/components/dfs/dfs_v1/filesystems/mqueue/dfs_mqueue.c @@ -84,11 +84,11 @@ int dfs_mqueue_open(struct dfs_file *file) { return 0; } -int dfs_mqueue_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { +int dfs_mqueue_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { st->st_dev = 0; st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH; st->st_size = 0; - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } diff --git a/components/dfs/dfs_v1/filesystems/nfs/dfs_nfs.c b/components/dfs/dfs_v1/filesystems/nfs/dfs_nfs.c index b24e6361845..315f8490cc2 100644 --- a/components/dfs/dfs_v1/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/dfs_v1/filesystems/nfs/dfs_nfs.c @@ -685,7 +685,7 @@ int nfs_write(struct dfs_file *file, const void *buf, size_t count) return total; } -int nfs_lseek(struct dfs_file *file, off_t offset) +dfs_off_t nfs_lseek(struct dfs_file *file, dfs_off_t offset) { nfs_file *fd; nfs_filesystem *nfs; @@ -837,7 +837,7 @@ int nfs_open(struct dfs_file *file) return 0; } -int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) +int nfs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { GETATTR3args args; GETATTR3res res; @@ -880,7 +880,7 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) } st->st_size = info->size; - st->st_mtime = info->mtime.seconds; + st->mtime = info->mtime.seconds; xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); diff --git a/components/dfs/dfs_v1/filesystems/ramfs/dfs_ramfs.c b/components/dfs/dfs_v1/filesystems/ramfs/dfs_ramfs.c index 1cb7085964c..94c3cdacf0d 100644 --- a/components/dfs/dfs_v1/filesystems/ramfs/dfs_ramfs.c +++ b/components/dfs/dfs_v1/filesystems/ramfs/dfs_ramfs.c @@ -201,9 +201,9 @@ ssize_t dfs_ramfs_write(struct dfs_file *fd, const void *buf, size_t count) return count; } -off_t dfs_ramfs_lseek(struct dfs_file *file, off_t offset) +dfs_off_t dfs_ramfs_lseek(struct dfs_file *file, dfs_off_t offset) { - if (offset <= (off_t)file->vnode->size) + if (offset <= file->vnode->size) { file->pos = offset; @@ -346,7 +346,7 @@ int dfs_ramfs_open(struct dfs_file *file) int dfs_ramfs_stat(struct dfs_filesystem *fs, const char *path, - struct stat *st) + struct dfs_stat *st) { rt_size_t size; struct ramfs_dirent *dirent; @@ -363,7 +363,7 @@ int dfs_ramfs_stat(struct dfs_filesystem *fs, S_IWUSR | S_IWGRP | S_IWOTH; st->st_size = dirent->size; - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } diff --git a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c index f50f0c74d62..c51527cd5dd 100644 --- a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c @@ -178,7 +178,7 @@ ssize_t dfs_romfs_read(struct dfs_file *file, void *buf, size_t count) return length; } -off_t dfs_romfs_lseek(struct dfs_file *file, off_t offset) +dfs_off_t dfs_romfs_lseek(struct dfs_file *file, dfs_off_t offset) { if (offset <= file->vnode->size) { @@ -269,7 +269,7 @@ int dfs_romfs_open(struct dfs_file *file) return RT_EOK; } -int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) +int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { rt_size_t size; struct romfs_dirent *dirent; @@ -294,7 +294,7 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) } st->st_size = dirent->size; - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } diff --git a/components/dfs/dfs_v1/filesystems/skeleton/skeleton.c b/components/dfs/dfs_v1/filesystems/skeleton/skeleton.c index 5c35cd1ffc3..cbd2c264279 100644 --- a/components/dfs/dfs_v1/filesystems/skeleton/skeleton.c +++ b/components/dfs/dfs_v1/filesystems/skeleton/skeleton.c @@ -34,7 +34,7 @@ int dfs_skt_read(struct dfs_file *file, void *buf, rt_size_t count) return count; } -int dfs_skt_lseek(struct dfs_file *file, rt_off_t offset) +dfs_off_t dfs_skt_lseek(struct dfs_file *file, dfs_off_t offset) { return -RT_EIO; } @@ -49,7 +49,7 @@ int dfs_skt_open(struct dfs_file *file) return RT_EOK; } -int dfs_skt_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) +int dfs_skt_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) { return RT_EOK; } diff --git a/components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c b/components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c index cb971ef30c3..9049d5cee5a 100644 --- a/components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c +++ b/components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c @@ -392,9 +392,9 @@ ssize_t dfs_tmpfs_write(struct dfs_file *fd, const void *buf, size_t count) return count; } -off_t dfs_tmpfs_lseek(struct dfs_file *file, off_t offset) +dfs_off_t dfs_tmpfs_lseek(struct dfs_file *file, dfs_off_t offset) { - if (offset <= (off_t)file->vnode->size) + if (offset <= file->vnode->size) { file->pos = offset; @@ -550,7 +550,7 @@ int dfs_tmpfs_open(struct dfs_file *file) int dfs_tmpfs_stat(struct dfs_filesystem *fs, const char *path, - struct stat *st) + struct dfs_stat *st) { rt_size_t size; struct tmpfs_file *d_file; @@ -572,7 +572,7 @@ int dfs_tmpfs_stat(struct dfs_filesystem *fs, } st->st_size = d_file->size; - st->st_mtime = 0; + st->mtime = 0; return RT_EOK; } diff --git a/components/dfs/dfs_v1/include/dfs.h b/components/dfs/dfs_v1/include/dfs.h index 12b0d599314..a8a35fe9c66 100644 --- a/components/dfs/dfs_v1/include/dfs.h +++ b/components/dfs/dfs_v1/include/dfs.h @@ -69,6 +69,37 @@ extern "C" { #define DFS_F_EOF 0x04000000 #define DFS_F_ERR 0x08000000 +#ifdef RT_USING_DFS_LARGE_FILE +typedef int64_t dfs_off_t; +#define DFS_OFF_MAX INT64_MAX +#else +typedef int32_t dfs_off_t; +#define DFS_OFF_MAX INT32_MAX +#endif + +struct dfs_stat +{ + dev_t st_dev; + uint16_t st_ino; + uint16_t st_mode; + uint16_t st_nlink; + uint16_t st_uid; + uint16_t st_gid; + struct rt_device *st_rdev; + dfs_off_t st_size; + time_t atime; + long st_spare1; + time_t mtime; + long st_spare2; + time_t ctime; + long st_spare3; + uint32_t st_blksize; + uint32_t st_blocks; + long st_spare4[2]; +}; + +void dfs_print_off_t(dfs_off_t value); + struct dfs_fdtable { uint32_t maxfd; diff --git a/components/dfs/dfs_v1/include/dfs_file.h b/components/dfs/dfs_v1/include/dfs_file.h index 26c74c8f161..4449228365a 100644 --- a/components/dfs/dfs_v1/include/dfs_file.h +++ b/components/dfs/dfs_v1/include/dfs_file.h @@ -28,7 +28,7 @@ struct dfs_file_ops ssize_t (*read) (struct dfs_file *fd, void *buf, size_t count); ssize_t (*write) (struct dfs_file *fd, const void *buf, size_t count); int (*flush) (struct dfs_file *fd); - off_t (*lseek) (struct dfs_file *fd, off_t offset); + dfs_off_t (*lseek) (struct dfs_file *fd, dfs_off_t offset); int (*getdents) (struct dfs_file *fd, struct dirent *dirp, uint32_t count); int (*poll) (struct dfs_file *fd, struct rt_pollreq *req); @@ -50,7 +50,7 @@ struct dfs_vnode const struct dfs_file_ops *fops; uint32_t flags; /* self flags, is dir etc.. */ - size_t size; /* Size in bytes */ + dfs_off_t size; /* Size in bytes */ void *data; /* Specific file system data */ }; @@ -59,7 +59,7 @@ struct dfs_file uint16_t magic; /* file descriptor magic number */ uint32_t flags; /* Descriptor flags */ int ref_count; /* Descriptor reference count */ - off_t pos; /* Current file position */ + dfs_off_t pos; /* Current file position */ struct dfs_vnode *vnode; /* file node struct */ void *data; /* Specific fd data */ }; @@ -72,7 +72,7 @@ struct dfs_mmap2_args size_t length; int prot; int flags; - off_t pgoffset; + dfs_off_t pgoffset; struct rt_lwp *lwp; void *ret; @@ -91,11 +91,11 @@ int dfs_file_getdents(struct dfs_file *fd, struct dirent *dirp, size_t nbytes); int dfs_file_unlink(const char *path); ssize_t dfs_file_write(struct dfs_file *fd, const void *buf, size_t len); int dfs_file_flush(struct dfs_file *fd); -off_t dfs_file_lseek(struct dfs_file *fd, off_t offset); +dfs_off_t dfs_file_lseek(struct dfs_file *fd, dfs_off_t offset); -int dfs_file_stat(const char *path, struct stat *buf); +int dfs_file_stat(const char *path, struct dfs_stat *buf); int dfs_file_rename(const char *oldpath, const char *newpath); -int dfs_file_ftruncate(struct dfs_file *fd, off_t length); +int dfs_file_ftruncate(struct dfs_file *fd, dfs_off_t length); #ifdef RT_USING_SMART int dfs_file_mmap2(struct dfs_file *fd, struct dfs_mmap2_args *mmap2); #endif diff --git a/components/dfs/dfs_v1/include/dfs_fs.h b/components/dfs/dfs_v1/include/dfs_fs.h index adfed8d787a..12d00ffd2e2 100644 --- a/components/dfs/dfs_v1/include/dfs_fs.h +++ b/components/dfs/dfs_v1/include/dfs_fs.h @@ -41,7 +41,7 @@ struct dfs_filesystem_ops int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf); int (*unlink) (struct dfs_filesystem *fs, const char *pathname); - int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf); + int (*stat) (struct dfs_filesystem *fs, const char *filename, struct dfs_stat *buf); int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath); }; @@ -60,7 +60,7 @@ struct dfs_filesystem struct dfs_partition { uint8_t type; /* file system type */ - off_t offset; /* partition start offset */ + dfs_off_t offset; /* partition start offset */ size_t size; /* partition size */ rt_sem_t lock; }; diff --git a/components/dfs/dfs_v1/src/dfs.c b/components/dfs/dfs_v1/src/dfs.c index 9a7c98cc336..6bfc20b1368 100644 --- a/components/dfs/dfs_v1/src/dfs.c +++ b/components/dfs/dfs_v1/src/dfs.c @@ -39,6 +39,35 @@ static struct dfs_fdtable _fdtab; static int fd_alloc(struct dfs_fdtable *fdt, int startfd); #endif /* DFS_USING_POSIX */ +void dfs_print_off_t(dfs_off_t value) +{ + char buf[24]; + int i = 0; + rt_uint64_t number; + + if (value < 0) + { + rt_kprintf("-"); + number = (rt_uint64_t)(-(value + 1)) + 1; + } + else + { + number = (rt_uint64_t)value; + } + + do + { + buf[i++] = (char)('0' + number % 10); + number /= 10; + } + while (number != 0); + + while (i > 0) + { + rt_kprintf("%c", buf[--i]); + } +} + /** * @addtogroup group_device_virtual_file_system * @{ diff --git a/components/dfs/dfs_v1/src/dfs_file.c b/components/dfs/dfs_v1/src/dfs_file.c index f1c4e7ee4d2..d3902ca99c0 100644 --- a/components/dfs/dfs_v1/src/dfs_file.c +++ b/components/dfs/dfs_v1/src/dfs_file.c @@ -578,9 +578,9 @@ int dfs_file_flush(struct dfs_file *fd) * * @return the current position after seek. */ -off_t dfs_file_lseek(struct dfs_file *fd, off_t offset) +dfs_off_t dfs_file_lseek(struct dfs_file *fd, dfs_off_t offset) { - int result; + dfs_off_t result; if (fd == NULL) return -EINVAL; @@ -605,7 +605,7 @@ off_t dfs_file_lseek(struct dfs_file *fd, 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 dfs_stat *buf) { int result; char *fullpath; @@ -734,7 +734,7 @@ int dfs_file_rename(const char *oldpath, const char *newpath) * * @return the status of truncated. */ -int dfs_file_ftruncate(struct dfs_file *fd, off_t length) +int dfs_file_ftruncate(struct dfs_file *fd, dfs_off_t length) { int result; @@ -787,7 +787,7 @@ void ls(const char *pathname) { struct dfs_file fd; struct dirent dirent; - struct stat stat; + struct dfs_stat stat; int length; char *fullpath, *path; @@ -819,7 +819,7 @@ void ls(const char *pathname) 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 dfs_stat)); /* build full path for each file */ fullpath = dfs_normalize_path(path, dirent.d_name); @@ -835,7 +835,9 @@ void ls(const char *pathname) } else { - rt_kprintf(" %-25lu\n", (unsigned long)stat.st_size); + rt_kprintf(" "); + dfs_print_off_t((dfs_off_t)stat.st_size); + rt_kprintf("\n"); } } else @@ -959,7 +961,7 @@ extern int mkdir(const char *path, mode_t mode); static void copydir(const char *src, const char *dst) { struct dirent dirent; - struct stat stat; + struct dfs_stat stat; int length; struct dfs_file cpfd; if (dfs_file_open(&cpfd, src, O_DIRECTORY) < 0) @@ -994,7 +996,7 @@ static void copydir(const char *src, const char *dst) break; } - rt_memset(&stat, 0, sizeof(struct stat)); + rt_memset(&stat, 0, sizeof(struct dfs_stat)); if (dfs_file_stat(src_entry_full, &stat) != 0) { rt_kprintf("open file: %s failed\n", dirent.d_name); @@ -1041,7 +1043,7 @@ void copy(const char *src, const char *dst) #define FLAG_DST_IS_FILE 0x08 #define FLAG_DST_NON_EXSIT 0x00 - struct stat stat; + struct dfs_stat stat; uint32_t flag = 0; /* check the staus of src and dst */ diff --git a/components/dfs/dfs_v1/src/dfs_posix.c b/components/dfs/dfs_v1/src/dfs_posix.c index f3d7b70c318..844f297916d 100644 --- a/components/dfs/dfs_v1/src/dfs_posix.c +++ b/components/dfs/dfs_v1/src/dfs_posix.c @@ -284,9 +284,10 @@ RTM_EXPORT(write); * * @return the resulting read/write position in the file, or -1 on failed. */ -off_t lseek(int fd, off_t offset, int whence) +dfs_off_t lseek(int fd, dfs_off_t offset, int whence) { - int result; + dfs_off_t dfs_offset; + dfs_off_t result; struct dfs_file *d; d = fd_get(fd); @@ -300,14 +301,15 @@ off_t lseek(int fd, off_t offset, int whence) switch (whence) { case SEEK_SET: + dfs_offset = (dfs_off_t)offset; break; case SEEK_CUR: - offset += d->pos; + dfs_offset = d->pos + (dfs_off_t)offset; break; case SEEK_END: - offset += d->vnode->size; + dfs_offset = d->vnode->size + (dfs_off_t)offset; break; default: @@ -316,13 +318,13 @@ off_t lseek(int fd, off_t offset, int whence) return -1; } - if (offset < 0) + if (dfs_offset < 0) { rt_set_errno(-EINVAL); return -1; } - result = dfs_file_lseek(d, offset); + result = dfs_file_lseek(d, dfs_offset); if (result < 0) { rt_set_errno(result); @@ -330,7 +332,7 @@ off_t lseek(int fd, off_t offset, int whence) return -1; } - return offset; + return result; } RTM_EXPORT(lseek); @@ -398,8 +400,10 @@ RTM_EXPORT(unlink); int stat(const char *file, struct stat *buf) { int result; + struct dfs_stat dfs_buf; - result = dfs_file_stat(file, buf); + rt_memset(&dfs_buf, 0, sizeof(dfs_buf)); + result = dfs_file_stat(file, &dfs_buf); if (result < 0) { rt_set_errno(result); @@ -407,6 +411,21 @@ int stat(const char *file, struct stat *buf) return -1; } + rt_memset(buf, 0, sizeof(struct stat)); + buf->st_dev = dfs_buf.st_dev; + buf->st_ino = dfs_buf.st_ino; + buf->st_mode = dfs_buf.st_mode; + buf->st_nlink = dfs_buf.st_nlink; + buf->st_uid = dfs_buf.st_uid; + buf->st_gid = dfs_buf.st_gid; + buf->st_rdev = dfs_buf.st_rdev; + buf->st_size = dfs_buf.st_size; + buf->st_atime = dfs_buf.atime; + buf->st_mtime = dfs_buf.mtime; + buf->st_ctime = dfs_buf.ctime; + buf->st_blksize = dfs_buf.st_blksize; + buf->st_blocks = dfs_buf.st_blocks; + return result; } RTM_EXPORT(stat); @@ -549,7 +568,7 @@ RTM_EXPORT(ioctl); * @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 ftruncate(int fd, dfs_off_t length) { int result; struct dfs_file *d; @@ -568,7 +587,7 @@ int ftruncate(int fd, off_t length) return -1; } - result = dfs_file_ftruncate(d, length); + result = dfs_file_ftruncate(d, (dfs_off_t)length); if (result < 0) { rt_set_errno(result); diff --git a/components/libc/compilers/common/include/sys/unistd.h b/components/libc/compilers/common/include/sys/unistd.h index 824891d57e4..7c21ae9f5ce 100644 --- a/components/libc/compilers/common/include/sys/unistd.h +++ b/components/libc/compilers/common/include/sys/unistd.h @@ -13,6 +13,7 @@ #define __SYS_UNISTD_H__ #include +#include #include #ifdef __cplusplus @@ -33,13 +34,13 @@ extern "C" { unsigned alarm(unsigned __secs); ssize_t read(int fd, void *buf, size_t len); ssize_t write(int fd, const void *buf, size_t len); -off_t lseek(int fd, off_t offset, int whence); +dfs_off_t lseek(int fd, dfs_off_t offset, int whence); int pause(void); int fsync(int fildes); long sysconf(int __name); int unlink(const char *pathname); int close(int d); -int ftruncate(int fd, off_t length); +int ftruncate(int fd, dfs_off_t length); int rmdir(const char *path); int chdir(const char *path); char *getcwd(char *buf, size_t size);