diff options
| author | 陈豪 <[email protected]> | 2014-08-06 22:55:49 +0800 |
|---|---|---|
| committer | 陈豪 <[email protected]> | 2014-08-06 22:55:49 +0800 |
| commit | 5fc32bf12ef4356ecbd46cfa21079cddb522b5c7 (patch) | |
| tree | 8f77e59c1bcec59c3c5efd0fe022f3dc0a0c901e /components/dfs | |
| parent | 0c8335d5ab046ce9fe36c4e01d5d40e4ba152b49 (diff) | |
| parent | a8fadf15b1828569e7684049d983cc6cb7fda2c9 (diff) | |
Merge pull request #1 from RT-Thread/master
sync
Diffstat (limited to 'components/dfs')
| -rw-r--r-- | components/dfs/include/dfs_fs.h | 2 | ||||
| -rw-r--r-- | components/dfs/src/dfs_file.c | 16 | ||||
| -rw-r--r-- | components/dfs/src/dfs_fs.c | 31 | ||||
| -rw-r--r-- | components/dfs/src/dfs_posix.c | 24 |
4 files changed, 61 insertions, 12 deletions
diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 3fa999c344..498aa5db54 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -94,6 +94,8 @@ struct dfs_mount_tbl int dfs_register(const struct dfs_filesystem_operation *ops); struct dfs_filesystem *dfs_filesystem_lookup(const char *path); +const char* dfs_filesystem_get_mounted_path(struct rt_device* device); + rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *buf, rt_uint32_t pindex); diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 32198371d7..f5619e2354 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -555,7 +555,7 @@ void ls(const char *pathname) if (pathname == RT_NULL) rt_free(path); } -FINSH_FUNCTION_EXPORT(ls, list directory contents) +FINSH_FUNCTION_EXPORT(ls, list directory contents); void rm(const char *filename) { @@ -564,7 +564,7 @@ void rm(const char *filename) rt_kprintf("Delete %s failed\n", filename); } } -FINSH_FUNCTION_EXPORT(rm, remove files or directories) +FINSH_FUNCTION_EXPORT(rm, remove files or directories); void cat(const char* filename) { @@ -590,7 +590,7 @@ void cat(const char* filename) dfs_file_close(&fd); } -FINSH_FUNCTION_EXPORT(cat, print file) +FINSH_FUNCTION_EXPORT(cat, print file); #define BUF_SZ 4096 static void copyfile(const char *src, const char *dst) @@ -629,7 +629,15 @@ static void copyfile(const char *src, const char *dst) read_bytes = dfs_file_read(&src_fd, block_ptr, BUF_SZ); if (read_bytes > 0) { - dfs_file_write(&fd, block_ptr, read_bytes); + int length; + + length = dfs_file_write(&fd, block_ptr, read_bytes); + if (length != read_bytes) + { + /* write failed. */ + rt_kprintf("Write file data failed, errno=%d\n", length); + break; + } } } while (read_bytes > 0); diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index a41f36cf09..bdd9560d56 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -116,6 +116,37 @@ struct dfs_filesystem *dfs_filesystem_lookup(const char *path) } /** + * this function will return the mounted path for specified device. + * + * @param device the device object which is mounted. + * + * @return the mounted path or RT_NULL if none device mounted. + */ +const char* dfs_filesystem_get_mounted_path(struct rt_device* device) +{ + const char* path = RT_NULL; + struct dfs_filesystem *iter; + + dfs_lock(); + for (iter = &filesystem_table[0]; + iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++) + { + /* fint the mounted device */ + if (iter->ops == RT_NULL) continue; + else if (iter->dev_id == device) + { + path = iter->path; + break; + } + } + + /* release filesystem_table lock */ + dfs_unlock(); + + return path; +} + +/** * this function will fetch the partition table on specified buffer. * * @param part the returned partition structure. diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 96139837e9..c1a6a5beb6 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -33,11 +33,11 @@ /** * this function is a POSIX compliant version, which will open a file and - * return a file descriptor. + * return a file descriptor according specified flags. * * @param file the path name of file. * @param flags the file open flags. - * @param mode + * @param mode ignored parameter * * @return the non-negative integer on successful open, others for failed. */ @@ -120,7 +120,8 @@ RTM_EXPORT(close); * @param buf the buffer to save the read data. * @param len the maximal length of data buffer * - * @return the actual read data buffer length + * @return the actual read data buffer length. If the returned value is 0, it + * may be reach the end of file, please check errno. */ int read(int fd, void *buf, size_t len) { @@ -200,7 +201,7 @@ RTM_EXPORT(write); * @param offset the offset to be seeked. * @param whence the directory of seek. * - * @return the current file position, or -1 on failed. + * @return the current read/write position in the file, or -1 on failed. */ off_t lseek(int fd, off_t offset, int whence) { @@ -336,6 +337,8 @@ RTM_EXPORT(stat); * * @param fildes the file description * @param buf the data buffer to save stat description. + * + * @return 0 on successful, -1 on failed. */ int fstat(int fildes, struct stat *buf) { @@ -470,7 +473,7 @@ RTM_EXPORT(rmdir); * * @param name the path name to be open. * - * @return the DIR pointer of directory, NULL on open failed. + * @return the DIR pointer of directory, NULL on open directory failed. */ DIR *opendir(const char *name) { @@ -537,12 +540,17 @@ struct dirent *readdir(DIR *d) if (fd == RT_NULL) { rt_set_errno(-DFS_STATUS_EBADF); - return RT_NULL; } - if (!d->num || - (d->cur += ((struct dirent *)(d->buf + d->cur))->d_reclen) >= d->num) + if (d->num) + { + struct dirent* dirent_ptr; + dirent_ptr = (struct dirent*)&d->buf[d->cur]; + d->cur += dirent_ptr->d_reclen; + } + + if (!d->num || d->cur >= d->num) { /* get a new entry */ result = dfs_file_getdents(fd, |
