Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos M
提交
590ab918
K
Kernel Liteos M
项目概览
OpenHarmony
/
Kernel Liteos M
10 个月 前同步成功
通知
20
Star
28
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos M
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
590ab918
编写于
2月 25, 2022
作者:
O
openharmony_ci
提交者:
Gitee
2月 25, 2022
浏览文件
操作
浏览文件
下载
差异文件
!609 feature: 补充pread/pwrite接口
Merge pull request !609 from Zhaotianyu/0224fs_pwrite
上级
36887d46
491cefae
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
274 addition
and
0 deletion
+274
-0
components/fs/fatfs/fatfs.c
components/fs/fatfs/fatfs.c
+106
-0
components/fs/fatfs/fatfs.h
components/fs/fatfs/fatfs.h
+2
-0
components/fs/littlefs/lfs_api.c
components/fs/littlefs/lfs_api.c
+86
-0
components/fs/littlefs/lfs_api.h
components/fs/littlefs/lfs_api.h
+2
-0
components/fs/vfs/fs_operations.h
components/fs/vfs/fs_operations.h
+2
-0
components/fs/vfs/los_fs.c
components/fs/vfs/los_fs.c
+52
-0
components/fs/vfs/los_fs.h
components/fs/vfs/los_fs.h
+4
-0
kal/libc/musl/fs.c
kal/libc/musl/fs.c
+10
-0
kal/libc/newlib/porting/src/fs.c
kal/libc/newlib/porting/src/fs.c
+10
-0
未找到文件。
components/fs/fatfs/fatfs.c
浏览文件 @
590ab918
...
...
@@ -1475,6 +1475,110 @@ OUT:
return
ret
;
}
ssize_t
fatfs_pread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
INT32
ret
;
off_t
savepos
,
pos
;
if
(
buf
==
NULL
)
{
errno
=
EFAULT
;
return
FS_FAILURE
;
}
ret
=
FsLock
();
if
(
ret
!=
0
)
{
errno
=
ret
;
return
FS_FAILURE
;
}
if
(
!
IsValidFd
(
fd
))
{
FsUnlock
();
errno
=
EBADF
;
return
FS_FAILURE
;
}
savepos
=
(
off_t
)
fatfs_lseek
(
fd
,
0
,
SEEK_CUR
);
if
(
savepos
==
(
off_t
)
-
1
)
{
errno
=
FatfsErrno
(
savepos
);
return
FS_FAILURE
;
}
pos
=
(
off_t
)
fatfs_lseek
(
fd
,
offset
,
SEEK_SET
);
if
(
pos
==
(
off_t
)
-
1
)
{
errno
=
FatfsErrno
(
pos
);
return
FS_FAILURE
;
}
ret
=
fatfs_read
(
fd
,
buf
,
nbyte
);
if
(
ret
<
0
)
{
FsUnlock
();
errno
=
FatfsErrno
(
ret
);
return
FS_FAILURE
;
}
pos
=
(
off_t
)
fatfs_lseek
(
fd
,
savepos
,
SEEK_SET
);
if
((
pos
==
(
off_t
)
-
1
)
&&
(
ret
>=
0
))
{
errno
=
FatfsErrno
(
pos
);
return
FS_FAILURE
;
}
FsUnlock
();
return
(
ssize_t
)
ret
;
}
ssize_t
fatfs_pwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
INT32
ret
;
off_t
savepos
,
pos
;
if
(
buf
==
NULL
)
{
errno
=
EFAULT
;
return
FS_FAILURE
;
}
ret
=
FsLock
();
if
(
ret
!=
0
)
{
errno
=
ret
;
return
FS_FAILURE
;
}
if
(
!
IsValidFd
(
fd
))
{
FsUnlock
();
errno
=
EBADF
;
return
FS_FAILURE
;
}
savepos
=
(
off_t
)
fatfs_lseek
(
fd
,
0
,
SEEK_CUR
);
if
(
savepos
==
(
off_t
)
-
1
)
{
errno
=
FatfsErrno
(
savepos
);
return
FS_FAILURE
;
}
pos
=
(
off_t
)
fatfs_lseek
(
fd
,
offset
,
SEEK_SET
);
if
(
pos
==
(
off_t
)
-
1
)
{
errno
=
FatfsErrno
(
pos
);
return
FS_FAILURE
;
}
ret
=
fatfs_write
(
fd
,
buf
,
nbyte
);
if
(
ret
<
0
)
{
FsUnlock
();
errno
=
FatfsErrno
(
ret
);
return
FS_FAILURE
;
}
pos
=
(
off_t
)
fatfs_lseek
(
fd
,
savepos
,
SEEK_SET
);
if
((
pos
==
(
off_t
)
-
1
)
&&
(
ret
>=
0
))
{
errno
=
FatfsErrno
(
pos
);
return
FS_FAILURE
;
}
FsUnlock
();
return
(
ssize_t
)
ret
;
}
struct
MountOps
g_fatfsMnt
=
{
.
Mount
=
fatfs_mount
,
.
Umount
=
fatfs_umount
,
...
...
@@ -1498,4 +1602,6 @@ struct FileOps g_fatfsFops = {
.
Getattr
=
fatfs_stat
,
.
Fsync
=
fatfs_fsync
,
.
Fstat
=
fatfs_fstat
,
.
Pread
=
fatfs_pread
,
.
Pwrite
=
fatfs_pwrite
,
};
components/fs/fatfs/fatfs.h
浏览文件 @
590ab918
...
...
@@ -69,6 +69,8 @@ int fatfs_rmdir(const char *path);
int
fatfs_rename
(
const
char
*
oldName
,
const
char
*
newName
);
int
fatfs_statfs
(
const
char
*
path
,
struct
statfs
*
buf
);
int
fatfs_ftruncate
(
int
fd
,
off_t
length
);
ssize_t
fatfs_pread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
ssize_t
fatfs_pwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
/**
* @brief divide a physical drive (SD card, U disk, and MMC card), this function is OHOS-specific
...
...
components/fs/littlefs/lfs_api.c
浏览文件 @
590ab918
...
...
@@ -323,6 +323,8 @@ const struct FileOps g_lfsFops = {
.
Getattr
=
LfsStat
,
.
Fsync
=
LfsFsync
,
.
Fstat
=
LfsFstat
,
.
Pread
=
LfsPread
,
.
Pwrite
=
LfsPwrite
,
};
int
LfsMount
(
const
char
*
source
,
const
char
*
target
,
const
char
*
fileSystemType
,
unsigned
long
mountflags
,
...
...
@@ -801,5 +803,89 @@ int LfsFstat(int fd, struct stat *buf)
errno
=
LittlefsErrno
(
ret
);
ret
=
VFS_ERROR
;
}
return
ret
;
}
int
LfsPread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
int
ret
;
off_t
savepos
,
pos
;
if
(
buf
==
NULL
)
{
errno
=
EFAULT
;
return
VFS_ERROR
;
}
if
(
LfsFdIsValid
(
fd
)
==
FALSE
)
{
errno
=
EBADF
;
return
VFS_ERROR
;
}
savepos
=
(
off_t
)
lfs_file_seek
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
0
,
SEEK_CUR
);
if
(
savepos
==
(
off_t
)
-
1
)
{
errno
=
LittlefsErrno
(
savepos
);
return
VFS_ERROR
;
}
pos
=
(
off_t
)
lfs_file_seek
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
offset
,
SEEK_SET
);
if
(
pos
==
(
off_t
)
-
1
)
{
errno
=
LittlefsErrno
(
pos
);
return
VFS_ERROR
;
}
ret
=
lfs_file_read
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
buf
,
nbyte
);
if
(
ret
<
0
)
{
errno
=
LittlefsErrno
(
ret
);
ret
=
VFS_ERROR
;
}
pos
=
(
off_t
)
lfs_file_seek
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
savepos
,
SEEK_SET
);
if
((
pos
==
(
off_t
)
-
1
)
&&
(
ret
>=
0
))
{
errno
=
LittlefsErrno
(
pos
);
return
VFS_ERROR
;
}
return
ret
;
}
int
LfsPwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
int
ret
;
off_t
savepos
,
pos
;
if
(
buf
==
NULL
)
{
errno
=
EFAULT
;
return
VFS_ERROR
;
}
if
(
LfsFdIsValid
(
fd
)
==
FALSE
)
{
errno
=
EBADF
;
return
VFS_ERROR
;
}
savepos
=
(
off_t
)
lfs_file_seek
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
0
,
SEEK_CUR
);
if
(
savepos
==
(
off_t
)
-
1
)
{
errno
=
LittlefsErrno
(
savepos
);
return
VFS_ERROR
;
}
pos
=
(
off_t
)
lfs_file_seek
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
offset
,
SEEK_SET
);
if
(
pos
==
(
off_t
)
-
1
)
{
errno
=
LittlefsErrno
(
pos
);
return
VFS_ERROR
;
}
ret
=
lfs_file_write
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
buf
,
nbyte
);
if
(
ret
<
0
)
{
errno
=
LittlefsErrno
(
ret
);
ret
=
VFS_ERROR
;
}
pos
=
(
off_t
)
lfs_file_seek
(
g_handle
[
fd
].
lfsHandle
,
&
(
g_handle
[
fd
].
file
),
savepos
,
SEEK_SET
);
if
((
pos
==
(
off_t
)
-
1
)
&&
(
ret
>=
0
))
{
errno
=
LittlefsErrno
(
pos
);
return
VFS_ERROR
;
}
return
ret
;
}
\ No newline at end of file
components/fs/littlefs/lfs_api.h
浏览文件 @
590ab918
...
...
@@ -97,6 +97,8 @@ int LfsStat(const char *path, struct stat *buf);
int
LfsFsync
(
int
fd
);
int
LfsFstat
(
int
fd
,
struct
stat
*
buf
);
int
SetDefaultMountPath
(
int
pathNameIndex
,
const
char
*
target
);
int
LfsPread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
int
LfsPwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
#endif
/* _LFS_API_H_ */
components/fs/vfs/fs_operations.h
浏览文件 @
590ab918
...
...
@@ -75,6 +75,8 @@ struct FileOps {
int
(
*
Fstat
)(
int
fd
,
struct
stat
*
buf
);
int
(
*
Stat
)(
const
char
*
path
,
struct
stat
*
buf
);
int
(
*
Ftruncate
)(
int
fd
,
off_t
length
);
int
(
*
Pread
)(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
int
(
*
Pwrite
)(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
};
#endif
/* _FS_OPERATIONS_H_ */
components/fs/vfs/los_fs.c
浏览文件 @
590ab918
...
...
@@ -595,3 +595,55 @@ int LOS_Ftruncate(int fd, off_t length)
}
return
g_fs
->
fsFops
->
Ftruncate
(
fd
,
length
);
}
ssize_t
LOS_Pread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
#ifdef LOSCFG_RANDOM_DEV
if
(
fd
==
RANDOM_DEV_FD
)
{
if
(
nbyte
==
0
)
{
return
FS_SUCCESS
;
}
if
(
buf
==
NULL
)
{
errno
=
EINVAL
;
return
FS_FAILURE
;
}
if
(
nbyte
>
1024
)
{
/* 1024, max random_size */
nbyte
=
1024
;
/* hks_generate_random: random_size must <= 1024 */
}
struct
hks_blob
key
=
{
HKS_BLOB_TYPE_RAW
,
(
uint8_t
*
)
buf
,
nbyte
};
if
(
hks_generate_random
(
&
key
)
!=
0
)
{
errno
=
EIO
;
return
FS_FAILURE
;
}
return
(
ssize_t
)
nbyte
;
}
#endif
if
(
g_fs
==
NULL
)
{
errno
=
ENODEV
;
return
FS_FAILURE
;
}
if
(
g_fs
->
fsFops
==
NULL
||
g_fs
->
fsFops
->
Pread
==
NULL
)
{
errno
=
ENOSYS
;
return
FS_FAILURE
;
}
return
g_fs
->
fsFops
->
Pread
(
fd
,
buf
,
nbyte
,
offset
);
}
ssize_t
LOS_Pwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
#ifdef LOSCFG_RANDOM_DEV
if
(
fd
==
RANDOM_DEV_FD
)
{
errno
=
EBADF
;
/* "/dev/random" is readonly */
return
FS_FAILURE
;
}
#endif
if
(
g_fs
==
NULL
)
{
errno
=
ENODEV
;
return
FS_FAILURE
;
}
if
(
g_fs
->
fsFops
==
NULL
||
g_fs
->
fsFops
->
Pwrite
==
NULL
)
{
errno
=
ENOSYS
;
return
FS_FAILURE
;
}
return
g_fs
->
fsFops
->
Pwrite
(
fd
,
buf
,
nbyte
,
offset
);
}
components/fs/vfs/los_fs.h
浏览文件 @
590ab918
...
...
@@ -92,6 +92,10 @@ int LOS_FsMount(const char *source, const char *target,
const
char
*
filesystemtype
,
unsigned
long
mountflags
,
const
void
*
data
);
ssize_t
LOS_Pread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
ssize_t
LOS_Pwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
);
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
...
...
kal/libc/musl/fs.c
浏览文件 @
590ab918
...
...
@@ -144,3 +144,13 @@ int ftruncate(int fd, off_t length)
{
return
LOS_Ftruncate
(
fd
,
length
);
}
ssize_t
pread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
return
LOS_Pread
(
fd
,
buf
,
nbyte
,
offset
);
}
ssize_t
pwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
return
LOS_Pwrite
(
fd
,
buf
,
nbyte
,
offset
);
}
kal/libc/newlib/porting/src/fs.c
浏览文件 @
590ab918
...
...
@@ -147,6 +147,16 @@ int ioctl(int fd, int req, ...)
return
-
1
;
}
ssize_t
pread
(
int
fd
,
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
return
LOS_Pread
(
fd
,
buf
,
nbyte
,
offset
);
}
ssize_t
pwrite
(
int
fd
,
const
void
*
buf
,
size_t
nbyte
,
off_t
offset
)
{
return
LOS_Pwrite
(
fd
,
buf
,
nbyte
,
offset
);
}
#else
/* #ifdef LOSCFG_FS_VFS */
int
_open
(
const
char
*
path
,
int
oflag
,
...)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录