Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
混口饭吃,
rt-thread
提交
b72bdefa
R
rt-thread
项目概览
混口饭吃,
/
rt-thread
与 Fork 源项目一致
Fork自
Mr_Pangza / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b72bdefa
编写于
10月 17, 2017
作者:
A
ArdaFu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DFS][NFS] Fix compile error. Move nfs_file/nfs_dir data ptr into struct nfs_filesystem.
上级
a13fdaac
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
183 addition
and
167 deletion
+183
-167
components/dfs/filesystems/nfs/dfs_nfs.c
components/dfs/filesystems/nfs/dfs_nfs.c
+183
-167
未找到文件。
components/dfs/filesystems/nfs/dfs_nfs.c
浏览文件 @
b72bdefa
...
@@ -24,7 +24,8 @@
...
@@ -24,7 +24,8 @@
#include <stdio.h>
#include <stdio.h>
#include <rtthread.h>
#include <rtthread.h>
#include <dfs_fs.h>
#include <dfs_fs.h>
#include <dfs_def.h>
#include <dfs.h>
#include <dfs_file.h>
#include <rpc/rpc.h>
#include <rpc/rpc.h>
...
@@ -59,6 +60,7 @@ struct nfs_dir
...
@@ -59,6 +60,7 @@ struct nfs_dir
#define HOST_LENGTH 32
#define HOST_LENGTH 32
#define EXPORT_PATH_LENGTH 32
#define EXPORT_PATH_LENGTH 32
struct
nfs_filesystem
struct
nfs_filesystem
{
{
nfs_fh3
root_handle
;
nfs_fh3
root_handle
;
...
@@ -68,10 +70,14 @@ struct nfs_filesystem
...
@@ -68,10 +70,14 @@ struct nfs_filesystem
char
host
[
HOST_LENGTH
];
char
host
[
HOST_LENGTH
];
char
export
[
EXPORT_PATH_LENGTH
];
char
export
[
EXPORT_PATH_LENGTH
];
void
*
data
;
/* nfs_file or nfs_dir */
};
};
typedef
struct
nfs_filesystem
nfs_filesystem
;
typedef
struct
nfs_file
nfs_file
;
typedef
struct
nfs_file
nfs_file
;
typedef
struct
nfs_dir
nfs_dir
;
typedef
struct
nfs_dir
nfs_dir
;
nfs_dir
*
nfs_opendir
(
struct
nfs_filesystem
*
nfs
,
const
char
*
path
);
nfs_dir
*
nfs_opendir
(
nfs_filesystem
*
nfs
,
const
char
*
path
);
static
int
nfs_parse_host_export
(
const
char
*
host_export
,
static
int
nfs_parse_host_export
(
const
char
*
host_export
,
char
*
host
,
char
*
host
,
...
@@ -98,7 +104,7 @@ static int nfs_parse_host_export(const char *host_export,
...
@@ -98,7 +104,7 @@ static int nfs_parse_host_export(const char *host_export,
if
(
index
==
host_len
)
if
(
index
==
host_len
)
return
-
1
;
return
-
1
;
/* make
RT_
NULL */
/* make NULL */
host_len
=
index
;
host_len
=
index
;
host
[
host_len
]
=
'\0'
;
host
[
host_len
]
=
'\0'
;
...
@@ -124,7 +130,7 @@ static void copy_handle(nfs_fh3 *dest, const nfs_fh3 *source)
...
@@ -124,7 +130,7 @@ static void copy_handle(nfs_fh3 *dest, const nfs_fh3 *source)
{
{
dest
->
data
.
data_len
=
source
->
data
.
data_len
;
dest
->
data
.
data_len
=
source
->
data
.
data_len
;
dest
->
data
.
data_val
=
rt_malloc
(
dest
->
data
.
data_len
);
dest
->
data
.
data_val
=
rt_malloc
(
dest
->
data
.
data_len
);
if
(
dest
->
data
.
data_val
==
RT_
NULL
)
if
(
dest
->
data
.
data_val
==
NULL
)
{
{
dest
->
data
.
data_len
=
0
;
dest
->
data
.
data_len
=
0
;
...
@@ -134,25 +140,25 @@ static void copy_handle(nfs_fh3 *dest, const nfs_fh3 *source)
...
@@ -134,25 +140,25 @@ static void copy_handle(nfs_fh3 *dest, const nfs_fh3 *source)
memcpy
(
dest
->
data
.
data_val
,
source
->
data
.
data_val
,
dest
->
data
.
data_len
);
memcpy
(
dest
->
data
.
data_val
,
source
->
data
.
data_val
,
dest
->
data
.
data_len
);
}
}
static
nfs_fh3
*
get_handle
(
struct
nfs_filesystem
*
nfs
,
const
char
*
name
)
static
nfs_fh3
*
get_handle
(
nfs_filesystem
*
nfs
,
const
char
*
name
)
{
{
nfs_fh3
*
handle
=
RT_
NULL
;
nfs_fh3
*
handle
=
NULL
;
char
*
file
;
char
*
file
;
char
*
path
;
char
*
path
;
char
*
init
;
char
*
init
;
init
=
path
=
rt_malloc
(
strlen
(
name
)
+
1
);
init
=
path
=
rt_malloc
(
strlen
(
name
)
+
1
);
if
(
init
==
RT_
NULL
)
if
(
init
==
NULL
)
return
RT_
NULL
;
return
NULL
;
memcpy
(
init
,
name
,
strlen
(
name
)
+
1
);
memcpy
(
init
,
name
,
strlen
(
name
)
+
1
);
handle
=
rt_malloc
(
sizeof
(
nfs_fh3
));
handle
=
rt_malloc
(
sizeof
(
nfs_fh3
));
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
{
{
rt_free
(
init
);
rt_free
(
init
);
return
RT_
NULL
;
return
NULL
;
}
}
if
(
path
[
0
]
==
'/'
)
if
(
path
[
0
]
==
'/'
)
...
@@ -165,7 +171,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -165,7 +171,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
copy_handle
(
handle
,
&
nfs
->
current_handle
);
copy_handle
(
handle
,
&
nfs
->
current_handle
);
}
}
while
((
file
=
strtok_r
(
RT_NULL
,
"/"
,
&
path
))
!=
RT_
NULL
)
while
((
file
=
strtok_r
(
NULL
,
"/"
,
&
path
))
!=
NULL
)
{
{
LOOKUP3args
args
;
LOOKUP3args
args
;
LOOKUP3res
res
;
LOOKUP3res
res
;
...
@@ -181,7 +187,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -181,7 +187,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
rt_free
(
handle
);
rt_free
(
handle
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
return
RT_
NULL
;
return
NULL
;
}
}
else
if
(
res
.
status
!=
NFS3_OK
)
else
if
(
res
.
status
!=
NFS3_OK
)
{
{
...
@@ -191,7 +197,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -191,7 +197,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_LOOKUP3res
,
(
char
*
)
&
res
);
xdr_free
((
xdrproc_t
)
xdr_LOOKUP3res
,
(
char
*
)
&
res
);
return
RT_
NULL
;
return
NULL
;
}
}
copy_handle
(
handle
,
&
res
.
LOOKUP3res_u
.
resok
.
object
);
copy_handle
(
handle
,
&
res
.
LOOKUP3res_u
.
resok
.
object
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
...
@@ -203,24 +209,24 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -203,24 +209,24 @@ static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name)
return
handle
;
return
handle
;
}
}
static
nfs_fh3
*
get_dir_handle
(
struct
nfs_filesystem
*
nfs
,
const
char
*
name
)
static
nfs_fh3
*
get_dir_handle
(
nfs_filesystem
*
nfs
,
const
char
*
name
)
{
{
nfs_fh3
*
handle
=
RT_
NULL
;
nfs_fh3
*
handle
=
NULL
;
char
*
file
;
char
*
file
;
char
*
path
;
char
*
path
;
char
*
init
;
char
*
init
;
init
=
path
=
rt_malloc
(
strlen
(
name
)
+
1
);
init
=
path
=
rt_malloc
(
strlen
(
name
)
+
1
);
if
(
init
==
RT_
NULL
)
if
(
init
==
NULL
)
return
RT_
NULL
;
return
NULL
;
memcpy
(
init
,
name
,
strlen
(
name
)
+
1
);
memcpy
(
init
,
name
,
strlen
(
name
)
+
1
);
handle
=
rt_malloc
(
sizeof
(
nfs_fh3
));
handle
=
rt_malloc
(
sizeof
(
nfs_fh3
));
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
{
{
rt_free
(
init
);
rt_free
(
init
);
return
RT_
NULL
;
return
NULL
;
}
}
if
(
path
[
0
]
==
'/'
)
if
(
path
[
0
]
==
'/'
)
...
@@ -233,7 +239,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -233,7 +239,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
copy_handle
(
handle
,
&
nfs
->
current_handle
);
copy_handle
(
handle
,
&
nfs
->
current_handle
);
}
}
while
((
file
=
strtok_r
(
RT_NULL
,
"/"
,
&
path
))
!=
RT_
NULL
&&
path
[
0
]
!=
0
)
while
((
file
=
strtok_r
(
NULL
,
"/"
,
&
path
))
!=
NULL
&&
path
[
0
]
!=
0
)
{
{
LOOKUP3args
args
;
LOOKUP3args
args
;
LOOKUP3res
res
;
LOOKUP3res
res
;
...
@@ -249,7 +255,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -249,7 +255,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
rt_free
(
handle
);
rt_free
(
handle
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
return
RT_
NULL
;
return
NULL
;
}
}
else
if
(
res
.
status
!=
NFS3_OK
)
else
if
(
res
.
status
!=
NFS3_OK
)
{
{
...
@@ -259,7 +265,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -259,7 +265,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_LOOKUP3res
,
(
char
*
)
&
res
);
xdr_free
((
xdrproc_t
)
xdr_LOOKUP3res
,
(
char
*
)
&
res
);
return
RT_
NULL
;
return
NULL
;
}
}
copy_handle
(
handle
,
&
res
.
LOOKUP3res_u
.
resok
.
object
);
copy_handle
(
handle
,
&
res
.
LOOKUP3res_u
.
resok
.
object
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
args
.
what
.
dir
);
...
@@ -271,7 +277,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
...
@@ -271,7 +277,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name)
return
handle
;
return
handle
;
}
}
static
size_t
nfs_get_filesize
(
struct
nfs_filesystem
*
nfs
,
nfs_fh3
*
handle
)
static
size_t
nfs_get_filesize
(
nfs_filesystem
*
nfs
,
nfs_fh3
*
handle
)
{
{
GETATTR3args
args
;
GETATTR3args
args
;
GETATTR3res
res
;
GETATTR3res
res
;
...
@@ -297,7 +303,7 @@ static size_t nfs_get_filesize(struct nfs_filesystem *nfs, nfs_fh3 *handle)
...
@@ -297,7 +303,7 @@ static size_t nfs_get_filesize(struct nfs_filesystem *nfs, nfs_fh3 *handle)
return
size
;
return
size
;
}
}
rt_bool_t
nfs_is_directory
(
struct
nfs_filesystem
*
nfs
,
const
char
*
name
)
rt_bool_t
nfs_is_directory
(
nfs_filesystem
*
nfs
,
const
char
*
name
)
{
{
GETATTR3args
args
;
GETATTR3args
args
;
GETATTR3res
res
;
GETATTR3res
res
;
...
@@ -307,7 +313,7 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem *nfs, const char *name)
...
@@ -307,7 +313,7 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem *nfs, const char *name)
result
=
RT_FALSE
;
result
=
RT_FALSE
;
handle
=
get_handle
(
nfs
,
name
);
handle
=
get_handle
(
nfs
,
name
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
return
RT_FALSE
;
return
RT_FALSE
;
args
.
object
=
*
handle
;
args
.
object
=
*
handle
;
...
@@ -339,26 +345,26 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem *nfs, const char *name)
...
@@ -339,26 +345,26 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem *nfs, const char *name)
return
result
;
return
result
;
}
}
int
nfs_create
(
struct
nfs_filesystem
*
nfs
,
const
char
*
name
,
mode_t
mode
)
int
nfs_create
(
nfs_filesystem
*
nfs
,
const
char
*
name
,
mode_t
mode
)
{
{
CREATE3args
args
;
CREATE3args
args
;
CREATE3res
res
;
CREATE3res
res
;
int
ret
=
0
;
int
ret
=
0
;
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
if
(
nfs
->
nfs_client
==
RT_
NULL
)
if
(
nfs
->
nfs_client
==
NULL
)
{
{
return
-
1
;
return
-
1
;
}
}
handle
=
get_dir_handle
(
nfs
,
name
);
handle
=
get_dir_handle
(
nfs
,
name
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
{
{
return
-
1
;
return
-
1
;
}
}
args
.
where
.
dir
=
*
handle
;
args
.
where
.
dir
=
*
handle
;
args
.
where
.
name
=
strrchr
(
name
,
'/'
)
+
1
;
args
.
where
.
name
=
strrchr
(
name
,
'/'
)
+
1
;
if
(
args
.
where
.
name
==
RT_
NULL
)
if
(
args
.
where
.
name
==
NULL
)
{
{
args
.
where
.
name
=
(
char
*
)
name
;
args
.
where
.
name
=
(
char
*
)
name
;
}
}
...
@@ -391,23 +397,23 @@ int nfs_create(struct nfs_filesystem *nfs, const char *name, mode_t mode)
...
@@ -391,23 +397,23 @@ int nfs_create(struct nfs_filesystem *nfs, const char *name, mode_t mode)
return
ret
;
return
ret
;
}
}
int
nfs_mkdir
(
struct
nfs_filesystem
*
nfs
,
const
char
*
name
,
mode_t
mode
)
int
nfs_mkdir
(
nfs_filesystem
*
nfs
,
const
char
*
name
,
mode_t
mode
)
{
{
MKDIR3args
args
;
MKDIR3args
args
;
MKDIR3res
res
;
MKDIR3res
res
;
int
ret
=
0
;
int
ret
=
0
;
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
if
(
nfs
->
nfs_client
==
RT_
NULL
)
if
(
nfs
->
nfs_client
==
NULL
)
return
-
1
;
return
-
1
;
handle
=
get_dir_handle
(
nfs
,
name
);
handle
=
get_dir_handle
(
nfs
,
name
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
return
-
1
;
return
-
1
;
args
.
where
.
dir
=
*
handle
;
args
.
where
.
dir
=
*
handle
;
args
.
where
.
name
=
strrchr
(
name
,
'/'
)
+
1
;
args
.
where
.
name
=
strrchr
(
name
,
'/'
)
+
1
;
if
(
args
.
where
.
name
==
RT_
NULL
)
if
(
args
.
where
.
name
==
NULL
)
{
{
args
.
where
.
name
=
(
char
*
)
name
;
args
.
where
.
name
=
(
char
*
)
name
;
}
}
...
@@ -439,14 +445,14 @@ int nfs_mkdir(struct nfs_filesystem *nfs, const char *name, mode_t mode)
...
@@ -439,14 +445,14 @@ int nfs_mkdir(struct nfs_filesystem *nfs, const char *name, mode_t mode)
return
ret
;
return
ret
;
}
}
/* mount(
RT_
NULL, "/mnt", "nfs", 0, "192.168.1.1:/export") */
/* mount(NULL, "/mnt", "nfs", 0, "192.168.1.1:/export") */
int
nfs_mount
(
struct
dfs_filesystem
*
fs
,
unsigned
long
rwflag
,
const
void
*
data
)
int
nfs_mount
(
struct
dfs_filesystem
*
fs
,
unsigned
long
rwflag
,
const
void
*
data
)
{
{
mountres3
res
;
mountres3
res
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
nfs
=
(
struct
nfs_filesystem
*
)
rt_malloc
(
sizeof
(
struct
nfs_filesystem
));
nfs
=
(
nfs_filesystem
*
)
rt_malloc
(
sizeof
(
nfs_filesystem
));
memset
(
nfs
,
0
,
sizeof
(
struct
nfs_filesystem
));
memset
(
nfs
,
0
,
sizeof
(
nfs_filesystem
));
if
(
nfs_parse_host_export
((
const
char
*
)
data
,
nfs
->
host
,
HOST_LENGTH
,
if
(
nfs_parse_host_export
((
const
char
*
)
data
,
nfs
->
host
,
HOST_LENGTH
,
nfs
->
export
,
EXPORT_PATH_LENGTH
)
<
0
)
nfs
->
export
,
EXPORT_PATH_LENGTH
)
<
0
)
...
@@ -456,7 +462,7 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
...
@@ -456,7 +462,7 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
}
}
nfs
->
mount_client
=
clnt_create
((
char
*
)
nfs
->
host
,
MOUNT_PROGRAM
,
MOUNT_V3
,
"udp"
);
nfs
->
mount_client
=
clnt_create
((
char
*
)
nfs
->
host
,
MOUNT_PROGRAM
,
MOUNT_V3
,
"udp"
);
if
(
nfs
->
mount_client
==
RT_
NULL
)
if
(
nfs
->
mount_client
==
NULL
)
{
{
rt_kprintf
(
"create mount client failed
\n
"
);
rt_kprintf
(
"create mount client failed
\n
"
);
goto
__return
;
goto
__return
;
...
@@ -474,7 +480,7 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
...
@@ -474,7 +480,7 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
goto
__return
;
goto
__return
;
}
}
nfs
->
nfs_client
=
clnt_create
((
char
*
)
nfs
->
host
,
NFS_PROGRAM
,
NFS_V3
,
"udp"
);
nfs
->
nfs_client
=
clnt_create
((
char
*
)
nfs
->
host
,
NFS_PROGRAM
,
NFS_V3
,
"udp"
);
if
(
nfs
->
nfs_client
==
RT_
NULL
)
if
(
nfs
->
nfs_client
==
NULL
)
{
{
rt_kprintf
(
"creat nfs client failed
\n
"
);
rt_kprintf
(
"creat nfs client failed
\n
"
);
goto
__return
;
goto
__return
;
...
@@ -488,15 +494,15 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
...
@@ -488,15 +494,15 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
return
0
;
return
0
;
__return:
__return:
if
(
nfs
!=
RT_
NULL
)
if
(
nfs
!=
NULL
)
{
{
if
(
nfs
->
mount_client
!=
RT_
NULL
)
if
(
nfs
->
mount_client
!=
NULL
)
{
{
clnt_destroy
(
nfs
->
mount_client
);
clnt_destroy
(
nfs
->
mount_client
);
}
}
if
(
nfs
->
nfs_client
!=
RT_
NULL
)
if
(
nfs
->
nfs_client
!=
NULL
)
{
{
if
(
nfs
->
nfs_client
->
cl_auth
!=
RT_
NULL
)
if
(
nfs
->
nfs_client
->
cl_auth
!=
NULL
)
{
{
auth_destroy
(
nfs
->
nfs_client
->
cl_auth
);
auth_destroy
(
nfs
->
nfs_client
->
cl_auth
);
}
}
...
@@ -510,73 +516,73 @@ __return:
...
@@ -510,73 +516,73 @@ __return:
int
nfs_unmount
(
struct
dfs_filesystem
*
fs
)
int
nfs_unmount
(
struct
dfs_filesystem
*
fs
)
{
{
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
RT_ASSERT
(
fs
!=
RT_
NULL
);
RT_ASSERT
(
fs
!=
NULL
);
RT_ASSERT
(
fs
->
data
!=
RT_
NULL
);
RT_ASSERT
(
fs
->
data
!=
NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
fs
->
data
;
nfs
=
(
nfs_filesystem
*
)
fs
->
data
;
if
(
nfs
->
mount_client
!=
RT_NULL
&&
if
(
nfs
->
mount_client
!=
NULL
&&
mountproc3_umnt_3
((
char
*
)
nfs
->
export
,
RT_
NULL
,
nfs
->
mount_client
)
!=
RPC_SUCCESS
)
mountproc3_umnt_3
((
char
*
)
nfs
->
export
,
NULL
,
nfs
->
mount_client
)
!=
RPC_SUCCESS
)
{
{
rt_kprintf
(
"umount failed
\n
"
);
rt_kprintf
(
"u
n
mount failed
\n
"
);
return
-
1
;
return
-
1
;
}
}
/* destroy nfs client */
/* destroy nfs client */
if
(
nfs
->
nfs_client
!=
RT_
NULL
)
if
(
nfs
->
nfs_client
!=
NULL
)
{
{
if
(
nfs
->
nfs_client
->
cl_auth
!=
RT_
NULL
)
if
(
nfs
->
nfs_client
->
cl_auth
!=
NULL
)
{
{
auth_destroy
(
nfs
->
nfs_client
->
cl_auth
);
auth_destroy
(
nfs
->
nfs_client
->
cl_auth
);
nfs
->
nfs_client
->
cl_auth
=
RT_
NULL
;
nfs
->
nfs_client
->
cl_auth
=
NULL
;
}
}
clnt_destroy
(
nfs
->
nfs_client
);
clnt_destroy
(
nfs
->
nfs_client
);
nfs
->
nfs_client
=
RT_
NULL
;
nfs
->
nfs_client
=
NULL
;
}
}
/* destroy mount client */
/* destroy mount client */
if
(
nfs
->
mount_client
!=
RT_
NULL
)
if
(
nfs
->
mount_client
!=
NULL
)
{
{
if
(
nfs
->
mount_client
->
cl_auth
!=
RT_
NULL
)
if
(
nfs
->
mount_client
->
cl_auth
!=
NULL
)
{
{
auth_destroy
(
nfs
->
mount_client
->
cl_auth
);
auth_destroy
(
nfs
->
mount_client
->
cl_auth
);
nfs
->
mount_client
->
cl_auth
=
RT_
NULL
;
nfs
->
mount_client
->
cl_auth
=
NULL
;
}
}
clnt_destroy
(
nfs
->
mount_client
);
clnt_destroy
(
nfs
->
mount_client
);
nfs
->
mount_client
=
RT_
NULL
;
nfs
->
mount_client
=
NULL
;
}
}
rt_free
(
nfs
);
rt_free
(
nfs
);
fs
->
data
=
RT_
NULL
;
fs
->
data
=
NULL
;
return
0
;
return
0
;
}
}
int
nfs_ioctl
(
struct
dfs_fd
*
file
,
int
cmd
,
void
*
args
)
int
nfs_ioctl
(
struct
dfs_fd
*
file
,
int
cmd
,
void
*
args
)
{
{
return
-
DFS_STATUS_
ENOSYS
;
return
-
ENOSYS
;
}
}
int
nfs_read
(
struct
dfs_fd
*
file
,
void
*
buf
,
rt_
size_t
count
)
int
nfs_read
(
struct
dfs_fd
*
file
,
void
*
buf
,
size_t
count
)
{
{
READ3args
args
;
READ3args
args
;
READ3res
res
;
READ3res
res
;
ssize_t
bytes
,
total
=
0
;
ssize_t
bytes
,
total
=
0
;
nfs_file
*
fd
;
nfs_file
*
fd
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
if
(
file
->
type
==
FT_DIRECTORY
)
if
(
file
->
type
==
FT_DIRECTORY
)
return
-
DFS_STATUS_
EISDIR
;
return
-
EISDIR
;
fd
=
(
nfs_file
*
)(
file
->
data
);
RT_ASSERT
(
fd
!=
RT_NULL
);
RT_ASSERT
(
file
->
fs
!=
RT_NULL
);
RT_ASSERT
(
file
->
fs
->
data
!=
RT_NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
file
->
fs
->
data
;
if
(
nfs
->
nfs_client
==
RT_NULL
)
RT_ASSERT
(
file
->
data
!=
NULL
);
nfs
=
(
nfs_filesystem
*
)((
struct
dfs_filesystem
*
)(
file
->
data
));
fd
=
(
nfs_file
*
)(
nfs
->
data
);
RT_ASSERT
(
fd
!=
NULL
);
if
(
nfs
->
nfs_client
==
NULL
)
return
-
1
;
return
-
1
;
/* end of file */
/* end of file */
...
@@ -626,24 +632,23 @@ int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count)
...
@@ -626,24 +632,23 @@ int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count)
return
total
;
return
total
;
}
}
int
nfs_write
(
struct
dfs_fd
*
file
,
const
void
*
buf
,
rt_
size_t
count
)
int
nfs_write
(
struct
dfs_fd
*
file
,
const
void
*
buf
,
size_t
count
)
{
{
WRITE3args
args
;
WRITE3args
args
;
WRITE3res
res
;
WRITE3res
res
;
ssize_t
bytes
,
total
=
0
;
ssize_t
bytes
,
total
=
0
;
nfs_file
*
fd
;
nfs_file
*
fd
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
if
(
file
->
type
==
FT_DIRECTORY
)
if
(
file
->
type
==
FT_DIRECTORY
)
return
-
DFS_STATUS_
EISDIR
;
return
-
EISDIR
;
fd
=
(
nfs_file
*
)(
file
->
data
);
RT_ASSERT
(
file
->
data
!=
NULL
);
RT_ASSERT
(
fd
!=
RT_NULL
);
nfs
=
(
nfs_filesystem
*
)((
struct
dfs_filesystem
*
)(
file
->
data
));
RT_ASSERT
(
file
->
fs
!=
RT_NULL
);
fd
=
(
nfs_file
*
)(
nfs
->
data
);
RT_ASSERT
(
file
->
fs
->
data
!=
RT_NULL
);
RT_ASSERT
(
fd
!=
NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
file
->
fs
->
data
;
if
(
nfs
->
nfs_client
==
RT_
NULL
)
if
(
nfs
->
nfs_client
==
NULL
)
return
-
1
;
return
-
1
;
args
.
file
=
fd
->
handle
;
args
.
file
=
fd
->
handle
;
...
@@ -690,15 +695,18 @@ int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count)
...
@@ -690,15 +695,18 @@ int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count)
return
total
;
return
total
;
}
}
int
nfs_lseek
(
struct
dfs_fd
*
file
,
rt_
off_t
offset
)
int
nfs_lseek
(
struct
dfs_fd
*
file
,
off_t
offset
)
{
{
nfs_file
*
fd
;
nfs_file
*
fd
;
nfs_filesystem
*
nfs
;
if
(
file
->
type
==
FT_DIRECTORY
)
if
(
file
->
type
==
FT_DIRECTORY
)
return
-
DFS_STATUS_
EISDIR
;
return
-
EISDIR
;
fd
=
(
nfs_file
*
)(
file
->
data
);
RT_ASSERT
(
file
->
data
!=
NULL
);
RT_ASSERT
(
fd
!=
RT_NULL
);
nfs
=
(
nfs_filesystem
*
)((
struct
dfs_filesystem
*
)(
file
->
data
));
fd
=
(
nfs_file
*
)(
nfs
->
data
);
RT_ASSERT
(
fd
!=
NULL
);
if
(
offset
<=
fd
->
size
)
if
(
offset
<=
fd
->
size
)
{
{
...
@@ -707,16 +715,20 @@ int nfs_lseek(struct dfs_fd *file, rt_off_t offset)
...
@@ -707,16 +715,20 @@ int nfs_lseek(struct dfs_fd *file, rt_off_t offset)
return
offset
;
return
offset
;
}
}
return
-
DFS_STATUS_
EIO
;
return
-
EIO
;
}
}
int
nfs_close
(
struct
dfs_fd
*
file
)
int
nfs_close
(
struct
dfs_fd
*
file
)
{
{
nfs_filesystem
*
nfs
;
RT_ASSERT
(
file
->
data
!=
NULL
);
nfs
=
(
nfs_filesystem
*
)((
struct
dfs_filesystem
*
)(
file
->
data
));
if
(
file
->
type
==
FT_DIRECTORY
)
if
(
file
->
type
==
FT_DIRECTORY
)
{
{
struct
nfs_dir
*
dir
;
struct
nfs_dir
*
dir
;
dir
=
(
struct
nfs_dir
*
)
file
->
data
;
dir
=
(
struct
nfs_dir
*
)
nfs
->
data
;
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
dir
->
handle
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
dir
->
handle
);
xdr_free
((
xdrproc_t
)
xdr_READDIR3res
,
(
char
*
)
&
dir
->
res
);
xdr_free
((
xdrproc_t
)
xdr_READDIR3res
,
(
char
*
)
&
dir
->
res
);
rt_free
(
dir
);
rt_free
(
dir
);
...
@@ -725,38 +737,37 @@ int nfs_close(struct dfs_fd *file)
...
@@ -725,38 +737,37 @@ int nfs_close(struct dfs_fd *file)
{
{
struct
nfs_file
*
fd
;
struct
nfs_file
*
fd
;
fd
=
(
struct
nfs_file
*
)
file
->
data
;
fd
=
(
struct
nfs_file
*
)
nfs
->
data
;
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
fd
->
handle
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
&
fd
->
handle
);
rt_free
(
fd
);
rt_free
(
fd
);
}
}
file
->
data
=
RT_
NULL
;
nfs
->
data
=
NULL
;
return
0
;
return
0
;
}
}
int
nfs_open
(
struct
dfs_fd
*
file
)
int
nfs_open
(
struct
dfs_fd
*
file
)
{
{
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
RT_ASSERT
(
file
->
data
!=
NULL
);
nfs
=
(
nfs_filesystem
*
)((
struct
dfs_filesystem
*
)(
file
->
data
));
RT_ASSERT
(
file
->
fs
!=
RT_NULL
);
RT_ASSERT
(
file
->
fs
->
data
!=
RT_NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
file
->
fs
->
data
;
if
(
file
->
flags
&
DFS_
O_DIRECTORY
)
if
(
file
->
flags
&
O_DIRECTORY
)
{
{
nfs_dir
*
dir
;
nfs_dir
*
dir
;
if
(
file
->
flags
&
DFS_
O_CREAT
)
if
(
file
->
flags
&
O_CREAT
)
{
{
if
(
nfs_mkdir
(
nfs
,
file
->
path
,
0755
)
<
0
)
if
(
nfs_mkdir
(
nfs
,
file
->
path
,
0755
)
<
0
)
return
-
DFS_STATUS_
EAGAIN
;
return
-
EAGAIN
;
}
}
/* open directory */
/* open directory */
dir
=
nfs_opendir
(
nfs
,
file
->
path
);
dir
=
nfs_opendir
(
nfs
,
file
->
path
);
if
(
dir
==
RT_NULL
)
return
-
DFS_STATUS_
ENOENT
;
if
(
dir
==
NULL
)
return
-
ENOENT
;
file
->
data
=
dir
;
nfs
->
data
=
dir
;
}
}
else
else
{
{
...
@@ -764,23 +775,23 @@ int nfs_open(struct dfs_fd *file)
...
@@ -764,23 +775,23 @@ int nfs_open(struct dfs_fd *file)
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
/* create file */
/* create file */
if
(
file
->
flags
&
DFS_
O_CREAT
)
if
(
file
->
flags
&
O_CREAT
)
{
{
if
(
nfs_create
(
nfs
,
file
->
path
,
0664
)
<
0
)
if
(
nfs_create
(
nfs
,
file
->
path
,
0664
)
<
0
)
return
-
DFS_STATUS_
EAGAIN
;
return
-
EAGAIN
;
}
}
/* open file (get file handle ) */
/* open file (get file handle ) */
fp
=
rt_malloc
(
sizeof
(
nfs_file
));
fp
=
rt_malloc
(
sizeof
(
nfs_file
));
if
(
fp
==
RT_
NULL
)
if
(
fp
==
NULL
)
return
-
DFS_STATUS_
ENOMEM
;
return
-
ENOMEM
;
handle
=
get_handle
(
nfs
,
file
->
path
);
handle
=
get_handle
(
nfs
,
file
->
path
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
{
{
rt_free
(
fp
);
rt_free
(
fp
);
return
-
DFS_STATUS_
ENOENT
;
return
-
ENOENT
;
}
}
/* get size of file */
/* get size of file */
...
@@ -792,13 +803,13 @@ int nfs_open(struct dfs_fd *file)
...
@@ -792,13 +803,13 @@ int nfs_open(struct dfs_fd *file)
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
handle
);
xdr_free
((
xdrproc_t
)
xdr_nfs_fh3
,
(
char
*
)
handle
);
rt_free
(
handle
);
rt_free
(
handle
);
if
(
file
->
flags
&
DFS_
O_APPEND
)
if
(
file
->
flags
&
O_APPEND
)
{
{
fp
->
offset
=
fp
->
size
;
fp
->
offset
=
fp
->
size
;
}
}
/* set private file */
/* set private file */
file
->
data
=
fp
;
nfs
->
data
=
fp
;
file
->
size
=
fp
->
size
;
file
->
size
=
fp
->
size
;
}
}
...
@@ -811,14 +822,14 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
...
@@ -811,14 +822,14 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
GETATTR3res
res
;
GETATTR3res
res
;
fattr3
*
info
;
fattr3
*
info
;
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
RT_ASSERT
(
fs
!=
RT_
NULL
);
RT_ASSERT
(
fs
!=
NULL
);
RT_ASSERT
(
fs
->
data
!=
RT_
NULL
);
RT_ASSERT
(
fs
->
data
!=
NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
fs
->
data
;
nfs
=
(
nfs_filesystem
*
)
fs
->
data
;
handle
=
get_handle
(
nfs
,
path
);
handle
=
get_handle
(
nfs
,
path
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
return
-
1
;
return
-
1
;
args
.
object
=
*
handle
;
args
.
object
=
*
handle
;
...
@@ -840,12 +851,11 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
...
@@ -840,12 +851,11 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
st
->
st_dev
=
0
;
st
->
st_dev
=
0
;
st
->
st_mode
=
DFS_S_IFREG
|
DFS_S_IRUSR
|
DFS_S_IRGRP
|
DFS_S_IROTH
|
st
->
st_mode
=
S_IFREG
|
S_IRUSR
|
S_IRGRP
|
S_IROTH
|
S_IWUSR
|
S_IWGRP
|
S_IWOTH
;
DFS_S_IWUSR
|
DFS_S_IWGRP
|
DFS_S_IWOTH
;
if
(
info
->
type
==
NFS3DIR
)
if
(
info
->
type
==
NFS3DIR
)
{
{
st
->
st_mode
&=
~
DFS_
S_IFREG
;
st
->
st_mode
&=
~
S_IFREG
;
st
->
st_mode
|=
DFS_S_IFDIR
|
DFS_S_IXUSR
|
DFS_S_IXGRP
|
DFS_
S_IXOTH
;
st
->
st_mode
|=
S_IFDIR
|
S_IXUSR
|
S_IXGRP
|
S_IXOTH
;
}
}
st
->
st_size
=
info
->
size
;
st
->
st_size
=
info
->
size
;
...
@@ -858,23 +868,23 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
...
@@ -858,23 +868,23 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
return
0
;
return
0
;
}
}
nfs_dir
*
nfs_opendir
(
struct
nfs_filesystem
*
nfs
,
const
char
*
path
)
nfs_dir
*
nfs_opendir
(
nfs_filesystem
*
nfs
,
const
char
*
path
)
{
{
nfs_dir
*
dir
;
nfs_dir
*
dir
;
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
dir
=
rt_malloc
(
sizeof
(
nfs_dir
));
dir
=
rt_malloc
(
sizeof
(
nfs_dir
));
if
(
dir
==
RT_
NULL
)
if
(
dir
==
NULL
)
{
{
return
RT_
NULL
;
return
NULL
;
}
}
handle
=
get_handle
(
nfs
,
path
);
handle
=
get_handle
(
nfs
,
path
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
{
{
rt_free
(
dir
);
rt_free
(
dir
);
return
RT_
NULL
;
return
NULL
;
}
}
copy_handle
(
&
dir
->
handle
,
handle
);
copy_handle
(
&
dir
->
handle
,
handle
);
...
@@ -883,21 +893,21 @@ nfs_dir *nfs_opendir(struct nfs_filesystem *nfs, const char *path)
...
@@ -883,21 +893,21 @@ nfs_dir *nfs_opendir(struct nfs_filesystem *nfs, const char *path)
dir
->
cookie
=
0
;
dir
->
cookie
=
0
;
memset
(
&
dir
->
cookieverf
,
'\0'
,
sizeof
(
cookieverf3
));
memset
(
&
dir
->
cookieverf
,
'\0'
,
sizeof
(
cookieverf3
));
dir
->
entry
=
RT_
NULL
;
dir
->
entry
=
NULL
;
dir
->
eof
=
FALSE
;
dir
->
eof
=
FALSE
;
memset
(
&
dir
->
res
,
'\0'
,
sizeof
(
dir
->
res
));
memset
(
&
dir
->
res
,
'\0'
,
sizeof
(
dir
->
res
));
return
dir
;
return
dir
;
}
}
char
*
nfs_readdir
(
struct
nfs_filesystem
*
nfs
,
nfs_dir
*
dir
)
char
*
nfs_readdir
(
nfs_filesystem
*
nfs
,
nfs_dir
*
dir
)
{
{
static
char
name
[
NAME_MAX
];
static
char
name
[
NAME_MAX
];
if
(
nfs
->
nfs_client
==
RT_NULL
||
dir
==
RT_
NULL
)
if
(
nfs
->
nfs_client
==
NULL
||
dir
==
NULL
)
return
RT_
NULL
;
return
NULL
;
if
(
dir
->
entry
==
RT_
NULL
)
if
(
dir
->
entry
==
NULL
)
{
{
READDIR3args
args
;
READDIR3args
args
;
...
@@ -913,21 +923,21 @@ char *nfs_readdir(struct nfs_filesystem *nfs, nfs_dir *dir)
...
@@ -913,21 +923,21 @@ char *nfs_readdir(struct nfs_filesystem *nfs, nfs_dir *dir)
{
{
rt_kprintf
(
"Readdir failed
\n
"
);
rt_kprintf
(
"Readdir failed
\n
"
);
return
RT_
NULL
;
return
NULL
;
}
}
else
if
(
dir
->
res
.
status
!=
NFS3_OK
)
else
if
(
dir
->
res
.
status
!=
NFS3_OK
)
{
{
rt_kprintf
(
"Readdir failed: %d
\n
"
,
dir
->
res
.
status
);
rt_kprintf
(
"Readdir failed: %d
\n
"
,
dir
->
res
.
status
);
return
RT_
NULL
;
return
NULL
;
}
}
memcpy
(
&
dir
->
cookieverf
,
&
dir
->
res
.
READDIR3res_u
.
resok
.
cookieverf
,
sizeof
(
cookieverf3
));
memcpy
(
&
dir
->
cookieverf
,
&
dir
->
res
.
READDIR3res_u
.
resok
.
cookieverf
,
sizeof
(
cookieverf3
));
dir
->
eof
=
dir
->
res
.
READDIR3res_u
.
resok
.
reply
.
eof
;
dir
->
eof
=
dir
->
res
.
READDIR3res_u
.
resok
.
reply
.
eof
;
dir
->
entry
=
dir
->
res
.
READDIR3res_u
.
resok
.
reply
.
entries
;
dir
->
entry
=
dir
->
res
.
READDIR3res_u
.
resok
.
reply
.
entries
;
}
}
if
(
dir
->
eof
==
TRUE
&&
dir
->
entry
==
RT_
NULL
)
if
(
dir
->
eof
==
TRUE
&&
dir
->
entry
==
NULL
)
return
RT_
NULL
;
return
NULL
;
dir
->
cookie
=
dir
->
entry
->
cookie
;
dir
->
cookie
=
dir
->
entry
->
cookie
;
strncpy
(
name
,
dir
->
entry
->
name
,
NAME_MAX
-
1
);
strncpy
(
name
,
dir
->
entry
->
name
,
NAME_MAX
-
1
);
...
@@ -940,11 +950,11 @@ char *nfs_readdir(struct nfs_filesystem *nfs, nfs_dir *dir)
...
@@ -940,11 +950,11 @@ char *nfs_readdir(struct nfs_filesystem *nfs, nfs_dir *dir)
int
nfs_unlink
(
struct
dfs_filesystem
*
fs
,
const
char
*
path
)
int
nfs_unlink
(
struct
dfs_filesystem
*
fs
,
const
char
*
path
)
{
{
int
ret
=
0
;
int
ret
=
0
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
RT_ASSERT
(
fs
!=
RT_
NULL
);
RT_ASSERT
(
fs
!=
NULL
);
RT_ASSERT
(
fs
->
data
!=
RT_
NULL
);
RT_ASSERT
(
fs
->
data
!=
NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
fs
->
data
;
nfs
=
(
nfs_filesystem
*
)
fs
->
data
;
if
(
nfs_is_directory
(
nfs
,
path
)
==
RT_FALSE
)
if
(
nfs_is_directory
(
nfs
,
path
)
==
RT_FALSE
)
{
{
...
@@ -954,12 +964,12 @@ int nfs_unlink(struct dfs_filesystem *fs, const char *path)
...
@@ -954,12 +964,12 @@ int nfs_unlink(struct dfs_filesystem *fs, const char *path)
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
handle
=
get_dir_handle
(
nfs
,
path
);
handle
=
get_dir_handle
(
nfs
,
path
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
return
-
1
;
return
-
1
;
args
.
object
.
dir
=
*
handle
;
args
.
object
.
dir
=
*
handle
;
args
.
object
.
name
=
strrchr
(
path
,
'/'
)
+
1
;
args
.
object
.
name
=
strrchr
(
path
,
'/'
)
+
1
;
if
(
args
.
object
.
name
==
RT_
NULL
)
if
(
args
.
object
.
name
==
NULL
)
{
{
args
.
object
.
name
=
(
char
*
)
path
;
args
.
object
.
name
=
(
char
*
)
path
;
}
}
...
@@ -988,12 +998,12 @@ int nfs_unlink(struct dfs_filesystem *fs, const char *path)
...
@@ -988,12 +998,12 @@ int nfs_unlink(struct dfs_filesystem *fs, const char *path)
nfs_fh3
*
handle
;
nfs_fh3
*
handle
;
handle
=
get_dir_handle
(
nfs
,
path
);
handle
=
get_dir_handle
(
nfs
,
path
);
if
(
handle
==
RT_
NULL
)
if
(
handle
==
NULL
)
return
-
1
;
return
-
1
;
args
.
object
.
dir
=
*
handle
;
args
.
object
.
dir
=
*
handle
;
args
.
object
.
name
=
strrchr
(
path
,
'/'
)
+
1
;
args
.
object
.
name
=
strrchr
(
path
,
'/'
)
+
1
;
if
(
args
.
object
.
name
==
RT_
NULL
)
if
(
args
.
object
.
name
==
NULL
)
{
{
args
.
object
.
name
=
(
char
*
)
path
;
args
.
object
.
name
=
(
char
*
)
path
;
}
}
...
@@ -1026,31 +1036,31 @@ int nfs_rename(struct dfs_filesystem *fs, const char *src, const char *dest)
...
@@ -1026,31 +1036,31 @@ int nfs_rename(struct dfs_filesystem *fs, const char *src, const char *dest)
nfs_fh3
*
sHandle
;
nfs_fh3
*
sHandle
;
nfs_fh3
*
dHandle
;
nfs_fh3
*
dHandle
;
int
ret
=
0
;
int
ret
=
0
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
RT_ASSERT
(
fs
!=
RT_
NULL
);
RT_ASSERT
(
fs
!=
NULL
);
RT_ASSERT
(
fs
->
data
!=
RT_
NULL
);
RT_ASSERT
(
fs
->
data
!=
NULL
);
nfs
=
(
struct
nfs_filesystem
*
)
fs
->
data
;
nfs
=
(
nfs_filesystem
*
)
fs
->
data
;
if
(
nfs
->
nfs_client
==
RT_
NULL
)
if
(
nfs
->
nfs_client
==
NULL
)
return
-
1
;
return
-
1
;
sHandle
=
get_dir_handle
(
nfs
,
src
);
sHandle
=
get_dir_handle
(
nfs
,
src
);
if
(
sHandle
==
RT_
NULL
)
if
(
sHandle
==
NULL
)
return
-
1
;
return
-
1
;
dHandle
=
get_dir_handle
(
nfs
,
dest
);
dHandle
=
get_dir_handle
(
nfs
,
dest
);
if
(
dHandle
==
RT_
NULL
)
if
(
dHandle
==
NULL
)
return
-
1
;
return
-
1
;
args
.
from
.
dir
=
*
sHandle
;
args
.
from
.
dir
=
*
sHandle
;
args
.
from
.
name
=
strrchr
(
src
,
'/'
)
+
1
;
args
.
from
.
name
=
strrchr
(
src
,
'/'
)
+
1
;
if
(
args
.
from
.
name
==
RT_
NULL
)
if
(
args
.
from
.
name
==
NULL
)
args
.
from
.
name
=
(
char
*
)
src
;
args
.
from
.
name
=
(
char
*
)
src
;
args
.
to
.
dir
=
*
dHandle
;
args
.
to
.
dir
=
*
dHandle
;
args
.
to
.
name
=
strrchr
(
src
,
'/'
)
+
1
;
args
.
to
.
name
=
strrchr
(
src
,
'/'
)
+
1
;
if
(
args
.
to
.
name
==
RT_
NULL
)
if
(
args
.
to
.
name
==
NULL
)
args
.
to
.
name
=
(
char
*
)
dest
;
args
.
to
.
name
=
(
char
*
)
dest
;
memset
(
&
res
,
'\0'
,
sizeof
(
res
));
memset
(
&
res
,
'\0'
,
sizeof
(
res
));
...
@@ -1073,24 +1083,24 @@ int nfs_rename(struct dfs_filesystem *fs, const char *src, const char *dest)
...
@@ -1073,24 +1083,24 @@ int nfs_rename(struct dfs_filesystem *fs, const char *src, const char *dest)
return
ret
;
return
ret
;
}
}
int
nfs_getdents
(
struct
dfs_fd
*
file
,
struct
dirent
*
dirp
,
rt_
uint32_t
count
)
int
nfs_getdents
(
struct
dfs_fd
*
file
,
struct
dirent
*
dirp
,
uint32_t
count
)
{
{
nfs_dir
*
dir
;
nfs_dir
*
dir
;
rt_uint32_t
index
;
rt_uint32_t
index
;
struct
dirent
*
d
;
struct
dirent
*
d
;
struct
nfs_filesystem
*
nfs
;
nfs_filesystem
*
nfs
;
char
*
name
;
char
*
name
;
dir
=
(
nfs_dir
*
)(
file
->
data
);
RT_ASSERT
(
dir
!=
RT_
NULL
);
RT_ASSERT
(
file
->
data
!=
NULL
);
RT_ASSERT
(
file
->
fs
!=
RT_NULL
);
nfs
=
(
nfs_filesystem
*
)((
struct
dfs_filesystem
*
)(
file
->
data
)
);
RT_ASSERT
(
file
->
fs
->
data
!=
RT_NULL
);
dir
=
(
nfs_dir
*
)(
nfs
->
data
);
nfs
=
(
struct
nfs_filesystem
*
)
file
->
fs
->
data
;
RT_ASSERT
(
dir
!=
NULL
)
;
/* make integer count */
/* make integer count */
count
=
(
count
/
sizeof
(
struct
dirent
))
*
sizeof
(
struct
dirent
);
count
=
(
count
/
sizeof
(
struct
dirent
))
*
sizeof
(
struct
dirent
);
if
(
count
==
0
)
if
(
count
==
0
)
return
-
DFS_STATUS_
EINVAL
;
return
-
EINVAL
;
index
=
0
;
index
=
0
;
while
(
1
)
while
(
1
)
...
@@ -1098,10 +1108,10 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
...
@@ -1098,10 +1108,10 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
d
=
dirp
+
index
;
d
=
dirp
+
index
;
name
=
nfs_readdir
(
nfs
,
dir
);
name
=
nfs_readdir
(
nfs
,
dir
);
if
(
name
==
RT_
NULL
)
if
(
name
==
NULL
)
break
;
break
;
d
->
d_type
=
D
FS_D
T_REG
;
d
->
d_type
=
DT_REG
;
d
->
d_namlen
=
rt_strlen
(
name
);
d
->
d_namlen
=
rt_strlen
(
name
);
d
->
d_reclen
=
(
rt_uint16_t
)
sizeof
(
struct
dirent
);
d
->
d_reclen
=
(
rt_uint16_t
)
sizeof
(
struct
dirent
);
...
@@ -1115,22 +1125,28 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
...
@@ -1115,22 +1125,28 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
return
index
*
sizeof
(
struct
dirent
);
return
index
*
sizeof
(
struct
dirent
);
}
}
static
const
struct
dfs_filesystem_operation
_nfs
=
static
const
struct
dfs_file_ops
nfs_fops
=
{
nfs_open
,
nfs_close
,
nfs_ioctl
,
nfs_read
,
nfs_write
,
NULL
,
/* flush */
nfs_lseek
,
nfs_getdents
,
NULL
,
/* poll */
};
static
const
struct
dfs_filesystem_ops
_nfs
=
{
{
"nfs"
,
"nfs"
,
DFS_FS_FLAG_DEFAULT
,
DFS_FS_FLAG_DEFAULT
,
&
nfs_fops
,
nfs_mount
,
nfs_mount
,
nfs_unmount
,
nfs_unmount
,
RT_NULL
,
/* mkfs */
NULL
,
/* mkfs */
RT_NULL
,
/* statfs */
NULL
,
/* statfs */
nfs_open
,
nfs_close
,
nfs_ioctl
,
nfs_read
,
nfs_write
,
RT_NULL
,
/* flush */
nfs_lseek
,
nfs_getdents
,
nfs_unlink
,
nfs_unlink
,
nfs_stat
,
nfs_stat
,
nfs_rename
,
nfs_rename
,
...
@@ -1138,7 +1154,7 @@ static const struct dfs_filesystem_operation _nfs =
...
@@ -1138,7 +1154,7 @@ static const struct dfs_filesystem_operation _nfs =
int
nfs_init
(
void
)
int
nfs_init
(
void
)
{
{
/* register
fat
fs file system */
/* register
n
fs file system */
dfs_register
(
&
_nfs
);
dfs_register
(
&
_nfs
);
return
RT_EOK
;
return
RT_EOK
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录