Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
f3a7a9c6
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
461
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f3a7a9c6
编写于
1月 31, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 31, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1102 fix: 修复proc静态问题
Merge pull request !1102 from zhushengle/proc_fix
上级
1f05c6a2
c8dbdaeb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
110 addition
and
18 deletion
+110
-18
fs/proc/os_adapt/proc_vfs.c
fs/proc/os_adapt/proc_vfs.c
+82
-14
fs/proc/src/proc_file.c
fs/proc/src/proc_file.c
+28
-4
未找到文件。
fs/proc/os_adapt/proc_vfs.c
浏览文件 @
f3a7a9c6
...
@@ -125,10 +125,18 @@ int VfsProcfsRead(struct file *filep, char *buffer, size_t buflen)
...
@@ -125,10 +125,18 @@ int VfsProcfsRead(struct file *filep, char *buffer, size_t buflen)
return
-
EINVAL
;
return
-
EINVAL
;
}
}
VnodeHold
();
entry
=
VnodeToEntry
(
filep
->
f_vnode
);
entry
=
VnodeToEntry
(
filep
->
f_vnode
);
if
(
entry
==
NULL
)
{
VnodeDrop
();
return
-
EPERM
;
}
spin_lock
(
&
entry
->
pdeUnloadLock
);
size
=
(
ssize_t
)
ReadProcFile
(
entry
,
(
void
*
)
buffer
,
buflen
);
size
=
(
ssize_t
)
ReadProcFile
(
entry
,
(
void
*
)
buffer
,
buflen
);
filep
->
f_pos
=
entry
->
pf
->
fPos
;
filep
->
f_pos
=
entry
->
pf
->
fPos
;
spin_unlock
(
&
entry
->
pdeUnloadLock
);
VnodeDrop
();
return
size
;
return
size
;
}
}
...
@@ -140,10 +148,18 @@ int VfsProcfsWrite(struct file *filep, const char *buffer, size_t buflen)
...
@@ -140,10 +148,18 @@ int VfsProcfsWrite(struct file *filep, const char *buffer, size_t buflen)
return
-
EINVAL
;
return
-
EINVAL
;
}
}
VnodeHold
();
entry
=
VnodeToEntry
(
filep
->
f_vnode
);
entry
=
VnodeToEntry
(
filep
->
f_vnode
);
if
(
entry
==
NULL
)
{
VnodeDrop
();
return
-
EPERM
;
}
spin_lock
(
&
entry
->
pdeUnloadLock
);
size
=
(
ssize_t
)
WriteProcFile
(
entry
,
(
void
*
)
buffer
,
buflen
);
size
=
(
ssize_t
)
WriteProcFile
(
entry
,
(
void
*
)
buffer
,
buflen
);
filep
->
f_pos
=
entry
->
pf
->
fPos
;
filep
->
f_pos
=
entry
->
pf
->
fPos
;
spin_unlock
(
&
entry
->
pdeUnloadLock
);
VnodeDrop
();
return
size
;
return
size
;
}
}
...
@@ -156,9 +172,12 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
...
@@ -156,9 +172,12 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
if
(
entry
==
NULL
)
{
if
(
entry
==
NULL
)
{
return
-
ENODATA
;
return
-
ENODATA
;
}
}
spin_lock
(
&
procfsLock
);
entry
=
entry
->
subdir
;
entry
=
entry
->
subdir
;
while
(
1
)
{
while
(
1
)
{
if
(
entry
==
NULL
)
{
if
(
entry
==
NULL
)
{
spin_unlock
(
&
procfsLock
);
return
-
ENOENT
;
return
-
ENOENT
;
}
}
if
(
EntryMatch
(
name
,
len
,
entry
))
{
if
(
EntryMatch
(
name
,
len
,
entry
))
{
...
@@ -166,6 +185,7 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
...
@@ -166,6 +185,7 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
}
}
entry
=
entry
->
next
;
entry
=
entry
->
next
;
}
}
spin_unlock
(
&
procfsLock
);
*
vpp
=
EntryToVnode
(
entry
);
*
vpp
=
EntryToVnode
(
entry
);
if
((
*
vpp
)
==
NULL
)
{
if
((
*
vpp
)
==
NULL
)
{
...
@@ -214,11 +234,17 @@ int VfsProcfsUnmount(void *handle, struct Vnode **blkdriver)
...
@@ -214,11 +234,17 @@ int VfsProcfsUnmount(void *handle, struct Vnode **blkdriver)
int
VfsProcfsStat
(
struct
Vnode
*
node
,
struct
stat
*
buf
)
int
VfsProcfsStat
(
struct
Vnode
*
node
,
struct
stat
*
buf
)
{
{
VnodeHold
();
struct
ProcDirEntry
*
entry
=
VnodeToEntry
(
node
);
struct
ProcDirEntry
*
entry
=
VnodeToEntry
(
node
);
if
(
entry
==
NULL
)
{
VnodeDrop
();
return
-
EPERM
;
}
(
void
)
memset_s
(
buf
,
sizeof
(
struct
stat
),
0
,
sizeof
(
struct
stat
));
(
void
)
memset_s
(
buf
,
sizeof
(
struct
stat
),
0
,
sizeof
(
struct
stat
));
spin_lock
(
&
entry
->
pdeUnloadLock
);
buf
->
st_mode
=
entry
->
mode
;
buf
->
st_mode
=
entry
->
mode
;
spin_unlock
(
&
entry
->
pdeUnloadLock
);
VnodeDrop
();
return
LOS_OK
;
return
LOS_OK
;
}
}
...
@@ -226,9 +252,7 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
...
@@ -226,9 +252,7 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
{
{
int
result
;
int
result
;
char
*
buffer
=
NULL
;
char
*
buffer
=
NULL
;
int
buflen
=
NAME_MAX
;
unsigned
int
minSize
,
dstNameSize
;
unsigned
int
min_size
;
unsigned
int
dst_name_size
;
struct
ProcDirEntry
*
pde
=
NULL
;
struct
ProcDirEntry
*
pde
=
NULL
;
int
i
=
0
;
int
i
=
0
;
...
@@ -238,28 +262,38 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
...
@@ -238,28 +262,38 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
if
(
node
->
type
!=
VNODE_TYPE_DIR
)
{
if
(
node
->
type
!=
VNODE_TYPE_DIR
)
{
return
-
ENOTDIR
;
return
-
ENOTDIR
;
}
}
VnodeHold
();
pde
=
VnodeToEntry
(
node
);
pde
=
VnodeToEntry
(
node
);
if
(
pde
==
NULL
)
{
VnodeDrop
();
return
-
EPERM
;
}
spin_lock
(
&
pde
->
pdeUnloadLock
);
while
(
i
<
dir
->
read_cnt
)
{
while
(
i
<
dir
->
read_cnt
)
{
buffer
=
(
char
*
)
zalloc
(
sizeof
(
char
)
*
NAME_MAX
);
buffer
=
(
char
*
)
zalloc
(
sizeof
(
char
)
*
NAME_MAX
);
if
(
buffer
==
NULL
)
{
if
(
buffer
==
NULL
)
{
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
PRINT_ERR
(
"malloc failed
\n
"
);
PRINT_ERR
(
"malloc failed
\n
"
);
return
-
ENOMEM
;
return
-
ENOMEM
;
}
}
result
=
ReadProcFile
(
pde
,
(
void
*
)
buffer
,
buflen
);
result
=
ReadProcFile
(
pde
,
(
void
*
)
buffer
,
NAME_MAX
);
if
(
result
!=
ENOERR
)
{
if
(
result
!=
ENOERR
)
{
free
(
buffer
);
free
(
buffer
);
break
;
break
;
}
}
dst
_name_s
ize
=
sizeof
(
dir
->
fd_dir
[
i
].
d_name
);
dst
NameS
ize
=
sizeof
(
dir
->
fd_dir
[
i
].
d_name
);
min
_size
=
(
dst_name_size
<
NAME_MAX
)
?
dst_name_s
ize
:
NAME_MAX
;
min
Size
=
(
dstNameSize
<
NAME_MAX
)
?
dstNameS
ize
:
NAME_MAX
;
result
=
strncpy_s
(
dir
->
fd_dir
[
i
].
d_name
,
dst
_name_size
,
buffer
,
min_s
ize
);
result
=
strncpy_s
(
dir
->
fd_dir
[
i
].
d_name
,
dst
NameSize
,
buffer
,
minS
ize
);
if
(
result
!=
EOK
)
{
if
(
result
!=
EOK
)
{
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
free
(
buffer
);
free
(
buffer
);
return
-
ENAMETOOLONG
;
return
-
ENAMETOOLONG
;
}
}
dir
->
fd_dir
[
i
].
d_name
[
dst
_name_s
ize
-
1
]
=
'\0'
;
dir
->
fd_dir
[
i
].
d_name
[
dst
NameS
ize
-
1
]
=
'\0'
;
dir
->
fd_position
++
;
dir
->
fd_position
++
;
dir
->
fd_dir
[
i
].
d_off
=
dir
->
fd_position
;
dir
->
fd_dir
[
i
].
d_off
=
dir
->
fd_position
;
dir
->
fd_dir
[
i
].
d_reclen
=
(
uint16_t
)
sizeof
(
struct
dirent
);
dir
->
fd_dir
[
i
].
d_reclen
=
(
uint16_t
)
sizeof
(
struct
dirent
);
...
@@ -267,21 +301,30 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
...
@@ -267,21 +301,30 @@ int VfsProcfsReaddir(struct Vnode *node, struct fs_dirent_s *dir)
i
++
;
i
++
;
free
(
buffer
);
free
(
buffer
);
}
}
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
return
i
;
return
i
;
}
}
int
VfsProcfsOpendir
(
struct
Vnode
*
node
,
struct
fs_dirent_s
*
dir
)
int
VfsProcfsOpendir
(
struct
Vnode
*
node
,
struct
fs_dirent_s
*
dir
)
{
{
VnodeHold
();
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
node
);
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
node
);
if
(
pde
==
NULL
)
{
if
(
pde
==
NULL
)
{
VnodeDrop
();
return
-
EINVAL
;
return
-
EINVAL
;
}
}
spin_lock
(
&
pde
->
pdeUnloadLock
);
pde
->
pdirCurrent
=
pde
->
subdir
;
pde
->
pdirCurrent
=
pde
->
subdir
;
if
(
pde
->
pf
==
NULL
)
{
if
(
pde
->
pf
==
NULL
)
{
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
return
-
EINVAL
;
return
-
EINVAL
;
}
}
pde
->
pf
->
fPos
=
0
;
pde
->
pf
->
fPos
=
0
;
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
return
LOS_OK
;
return
LOS_OK
;
}
}
...
@@ -290,9 +333,17 @@ int VfsProcfsOpen(struct file *filep)
...
@@ -290,9 +333,17 @@ int VfsProcfsOpen(struct file *filep)
if
(
filep
==
NULL
)
{
if
(
filep
==
NULL
)
{
return
-
EINVAL
;
return
-
EINVAL
;
}
}
VnodeHold
();
struct
Vnode
*
node
=
filep
->
f_vnode
;
struct
Vnode
*
node
=
filep
->
f_vnode
;
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
node
);
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
node
);
if
(
pde
==
NULL
)
{
VnodeDrop
();
return
-
EPERM
;
}
spin_lock
(
&
pde
->
pdeUnloadLock
);
if
(
ProcOpen
(
pde
->
pf
)
!=
OK
)
{
if
(
ProcOpen
(
pde
->
pf
)
!=
OK
)
{
spin_unlock
(
&
pde
->
pdeUnloadLock
);
return
-
ENOMEM
;
return
-
ENOMEM
;
}
}
if
(
S_ISREG
(
pde
->
mode
)
&&
(
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
open
!=
NULL
))
{
if
(
S_ISREG
(
pde
->
mode
)
&&
(
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
open
!=
NULL
))
{
...
@@ -303,6 +354,8 @@ int VfsProcfsOpen(struct file *filep)
...
@@ -303,6 +354,8 @@ int VfsProcfsOpen(struct file *filep)
pde
->
pf
->
fPos
=
0
;
pde
->
pf
->
fPos
=
0
;
}
}
filep
->
f_priv
=
(
void
*
)
pde
;
filep
->
f_priv
=
(
void
*
)
pde
;
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
return
LOS_OK
;
return
LOS_OK
;
}
}
...
@@ -312,15 +365,24 @@ int VfsProcfsClose(struct file *filep)
...
@@ -312,15 +365,24 @@ int VfsProcfsClose(struct file *filep)
if
(
filep
==
NULL
)
{
if
(
filep
==
NULL
)
{
return
-
EINVAL
;
return
-
EINVAL
;
}
}
VnodeHold
();
struct
Vnode
*
node
=
filep
->
f_vnode
;
struct
Vnode
*
node
=
filep
->
f_vnode
;
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
node
);
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
node
);
if
(
pde
==
NULL
)
{
VnodeDrop
();
return
-
EPERM
;
}
spin_lock
(
&
pde
->
pdeUnloadLock
);
pde
->
pf
->
fPos
=
0
;
pde
->
pf
->
fPos
=
0
;
if
((
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
release
!=
NULL
))
{
if
((
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
release
!=
NULL
))
{
result
=
pde
->
procFileOps
->
release
((
struct
Vnode
*
)
pde
,
pde
->
pf
);
result
=
pde
->
procFileOps
->
release
((
struct
Vnode
*
)
pde
,
pde
->
pf
);
}
}
LosBufRelease
(
pde
->
pf
->
sbuf
);
LosBufRelease
(
pde
->
pf
->
sbuf
);
pde
->
pf
->
sbuf
=
NULL
;
pde
->
pf
->
sbuf
=
NULL
;
spin_unlock
(
&
pde
->
pdeUnloadLock
);
VnodeDrop
();
return
result
;
return
result
;
}
}
...
@@ -345,9 +407,15 @@ ssize_t VfsProcfsReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
...
@@ -345,9 +407,15 @@ ssize_t VfsProcfsReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
}
}
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
vnode
);
struct
ProcDirEntry
*
pde
=
VnodeToEntry
(
vnode
);
if
(
pde
==
NULL
)
{
return
-
EPERM
;
}
spin_lock
(
&
pde
->
pdeUnloadLock
);
if
((
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
readLink
!=
NULL
))
{
if
((
pde
->
procFileOps
!=
NULL
)
&&
(
pde
->
procFileOps
->
readLink
!=
NULL
))
{
result
=
pde
->
procFileOps
->
readLink
(
pde
,
buffer
,
bufLen
);
result
=
pde
->
procFileOps
->
readLink
(
pde
,
buffer
,
bufLen
);
}
}
spin_unlock
(
&
pde
->
pdeUnloadLock
);
return
result
;
return
result
;
}
}
...
...
fs/proc/src/proc_file.c
浏览文件 @
f3a7a9c6
...
@@ -378,11 +378,34 @@ struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcD
...
@@ -378,11 +378,34 @@ struct ProcDirEntry *CreateProcEntry(const char *name, mode_t mode, struct ProcD
return
pde
;
return
pde
;
}
}
static
void
ProcEntryClearVnode
(
struct
ProcDirEntry
*
entry
)
{
struct
Vnode
*
item
=
NULL
;
struct
Vnode
*
nextItem
=
NULL
;
VnodeHold
();
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE
(
item
,
nextItem
,
GetVnodeActiveList
(),
struct
Vnode
,
actFreeEntry
)
{
if
((
struct
ProcDirEntry
*
)
item
->
data
!=
entry
)
{
continue
;
}
if
(
VnodeFree
(
item
)
!=
LOS_OK
)
{
PRINT_ERR
(
"ProcEntryClearVnode free failed, entry: %s : 0x%x
\n
"
,
entry
->
name
,
item
);
}
}
VnodeDrop
();
return
;
}
static
void
FreeProcEntry
(
struct
ProcDirEntry
*
entry
)
static
void
FreeProcEntry
(
struct
ProcDirEntry
*
entry
)
{
{
if
(
entry
==
NULL
)
{
if
(
entry
==
NULL
)
{
return
;
return
;
}
}
ProcEntryClearVnode
(
entry
);
spin_lock
(
&
entry
->
pdeUnloadLock
);
if
(
entry
->
pf
!=
NULL
)
{
if
(
entry
->
pf
!=
NULL
)
{
free
(
entry
->
pf
);
free
(
entry
->
pf
);
entry
->
pf
=
NULL
;
entry
->
pf
=
NULL
;
...
@@ -391,6 +414,7 @@ static void FreeProcEntry(struct ProcDirEntry *entry)
...
@@ -391,6 +414,7 @@ static void FreeProcEntry(struct ProcDirEntry *entry)
free
(
entry
->
data
);
free
(
entry
->
data
);
entry
->
data
=
NULL
;
entry
->
data
=
NULL
;
}
}
spin_unlock
(
&
entry
->
pdeUnloadLock
);
free
(
entry
);
free
(
entry
);
}
}
...
@@ -562,22 +586,21 @@ static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
...
@@ -562,22 +586,21 @@ static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
struct
ProcDirEntry
*
OpenProcFile
(
const
char
*
fileName
,
int
flags
,
...)
struct
ProcDirEntry
*
OpenProcFile
(
const
char
*
fileName
,
int
flags
,
...)
{
{
unsigned
int
intSave
;
struct
ProcDirEntry
*
pn
=
ProcFindEntry
(
fileName
);
struct
ProcDirEntry
*
pn
=
ProcFindEntry
(
fileName
);
if
(
pn
==
NULL
)
{
if
(
pn
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
SCHEDULER_LOCK
(
intSave
);
spin_lock
(
&
pn
->
pdeUnloadLock
);
if
(
S_ISREG
(
pn
->
mode
)
&&
(
pn
->
count
!=
1
))
{
if
(
S_ISREG
(
pn
->
mode
)
&&
(
pn
->
count
!=
1
))
{
SCHEDULER_UNLOCK
(
intSave
);
spin_unlock
(
&
pn
->
pdeUnloadLock
);
return
NULL
;
return
NULL
;
}
}
pn
->
flags
=
(
unsigned
int
)(
pn
->
flags
)
|
(
unsigned
int
)
flags
;
pn
->
flags
=
(
unsigned
int
)(
pn
->
flags
)
|
(
unsigned
int
)
flags
;
atomic_set
(
&
pn
->
count
,
PROC_INUSE
);
atomic_set
(
&
pn
->
count
,
PROC_INUSE
);
SCHEDULER_UNLOCK
(
intSave
);
if
(
ProcOpen
(
pn
->
pf
)
!=
OK
)
{
if
(
ProcOpen
(
pn
->
pf
)
!=
OK
)
{
spin_unlock
(
&
pn
->
pdeUnloadLock
);
return
NULL
;
return
NULL
;
}
}
if
(
S_ISREG
(
pn
->
mode
)
&&
(
pn
->
procFileOps
!=
NULL
)
&&
(
pn
->
procFileOps
->
open
!=
NULL
))
{
if
(
S_ISREG
(
pn
->
mode
)
&&
(
pn
->
procFileOps
!=
NULL
)
&&
(
pn
->
procFileOps
->
open
!=
NULL
))
{
...
@@ -587,6 +610,7 @@ struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
...
@@ -587,6 +610,7 @@ struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...)
pn
->
pdirCurrent
=
pn
->
subdir
;
pn
->
pdirCurrent
=
pn
->
subdir
;
pn
->
pf
->
fPos
=
0
;
pn
->
pf
->
fPos
=
0
;
}
}
spin_unlock
(
&
pn
->
pdeUnloadLock
);
return
pn
;
return
pn
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录