diff options
| author | bernard.xiong <[email protected]> | 2010-11-29 11:32:24 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-11-29 11:32:24 +0000 |
| commit | fca005fe0c391e9bc683a9443bebb19ad4b9b15a (patch) | |
| tree | 2454e04cb7983f60faa6fd6131d8d558048ee3ac /components/dfs | |
| parent | a7bf529851a3e08474942a5eb78857d22257dd4b (diff) | |
change the timeout of NFS link; add copy function in finsh shell.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1138 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/dfs')
| -rw-r--r-- | components/dfs/filesystems/nfs/rpc/clnt_generic.c | 2 | ||||
| -rw-r--r-- | components/dfs/src/dfs_file.c | 44 |
2 files changed, 45 insertions, 1 deletions
diff --git a/components/dfs/filesystems/nfs/rpc/clnt_generic.c b/components/dfs/filesystems/nfs/rpc/clnt_generic.c index 85f5755bc0..4e4e6a1658 100644 --- a/components/dfs/filesystems/nfs/rpc/clnt_generic.c +++ b/components/dfs/filesystems/nfs/rpc/clnt_generic.c @@ -71,7 +71,7 @@ CLIENT *clnt_create (const char *hostname, const unsigned long prog, tv.tv_usec = 0; client = clntudp_create(&sin, prog, vers, tv, &sock); if (client == NULL) return NULL; - tv.tv_sec = 25; + tv.tv_sec = 1; clnt_control(client, CLSET_TIMEOUT, (char*)&tv); } else diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 95c9e9462a..fb6a7893da 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -534,6 +534,50 @@ void cat(const char* filename) }
FINSH_FUNCTION_EXPORT(cat, print file)
+#define BUF_SZ 4096
+void copy(const char* src, const char* dst)
+{
+ struct dfs_fd src_fd;
+ rt_uint8_t *block_ptr;
+ rt_uint32_t read_bytes, write_bytes;
+
+ block_ptr = rt_malloc(BUF_SZ);
+ if (block_ptr == RT_NULL)
+ {
+ rt_kprintf("out of memory\n");
+ return;
+ }
+
+ if (dfs_file_open(&src_fd, src, DFS_O_RDONLY) < 0)
+ {
+ rt_free(block_ptr);
+ rt_kprintf("Read %s failed\n", src);
+ return;
+ }
+ if (dfs_file_open(&fd, dst, DFS_O_WRONLY | DFS_O_CREAT) < 0)
+ {
+ rt_free(block_ptr);
+ dfs_file_close(&src_fd);
+
+ rt_kprintf("Write %s failed\n", dst);
+ return;
+ }
+
+ do
+ {
+ read_bytes = dfs_file_read(&src_fd, block_ptr, BUF_SZ);
+ if (read_bytes > 0)
+ {
+ dfs_file_write(&fd, block_ptr, read_bytes);
+ }
+ } while (read_bytes > 0);
+
+ dfs_file_close(&src_fd);
+ dfs_file_close(&fd);
+ rt_free(block_ptr);
+}
+FINSH_FUNCTION_EXPORT(copy, copy source file to destination file)
+
#endif
/* @} */
|
