mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
tools/pynuttx: update fs.py base on new structure fd and file
Update the Python script based on the PR "Separate file descriptors from file descriptions" in fs/vfs. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+17
-16
@@ -36,8 +36,8 @@ CONFIG_PSEUDOFS_FILE = utils.get_symbol_value("CONFIG_PSEUDOFS_FILE")
|
|||||||
CONFIG_PSEUDOFS_ATTRIBUTES = utils.get_symbol_value("CONFIG_PSEUDOFS_ATTRIBUTES")
|
CONFIG_PSEUDOFS_ATTRIBUTES = utils.get_symbol_value("CONFIG_PSEUDOFS_ATTRIBUTES")
|
||||||
|
|
||||||
CONFIG_FS_BACKTRACE = utils.get_symbol_value("CONFIG_FS_BACKTRACE")
|
CONFIG_FS_BACKTRACE = utils.get_symbol_value("CONFIG_FS_BACKTRACE")
|
||||||
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK = int(
|
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK = utils.get_field_nitems(
|
||||||
utils.get_symbol_value("CONFIG_NFILE_DESCRIPTORS_PER_BLOCK")
|
"struct fdlist", "fl_prefds"
|
||||||
)
|
)
|
||||||
CONFIG_FS_SHMFS = utils.get_symbol_value("CONFIG_FS_SHMFS")
|
CONFIG_FS_SHMFS = utils.get_symbol_value("CONFIG_FS_SHMFS")
|
||||||
|
|
||||||
@@ -171,9 +171,9 @@ def inode_gettype(inode: p.Inode) -> InodeType:
|
|||||||
|
|
||||||
def get_file(tcb: Tcb, fd):
|
def get_file(tcb: Tcb, fd):
|
||||||
group = tcb.group
|
group = tcb.group
|
||||||
filelist = group.tg_filelist
|
fdlist = group.tg_fdlist
|
||||||
fl_files = filelist.fl_files
|
fl_fds = fdlist.fl_fds
|
||||||
fl_rows = filelist.fl_rows
|
fl_rows = fdlist.fl_rows
|
||||||
|
|
||||||
row = fd // CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
|
row = fd // CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
|
||||||
col = fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
|
col = fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
|
||||||
@@ -181,7 +181,7 @@ def get_file(tcb: Tcb, fd):
|
|||||||
if row >= fl_rows:
|
if row >= fl_rows:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return fl_files[row][col]
|
return fl_fds[row][col]
|
||||||
|
|
||||||
|
|
||||||
def foreach_inode(root=None, path="") -> Generator[Tuple[p.Inode, str], None, None]:
|
def foreach_inode(root=None, path="") -> Generator[Tuple[p.Inode, str], None, None]:
|
||||||
@@ -197,20 +197,21 @@ def foreach_inode(root=None, path="") -> Generator[Tuple[p.Inode, str], None, No
|
|||||||
def foreach_file(tcb: Tcb):
|
def foreach_file(tcb: Tcb):
|
||||||
"""Iterate over all file descriptors in a tcb"""
|
"""Iterate over all file descriptors in a tcb"""
|
||||||
group = tcb.group
|
group = tcb.group
|
||||||
filelist = group.tg_filelist
|
fdlist = group.tg_fdlist
|
||||||
fl_files = filelist.fl_files
|
fl_fds = fdlist.fl_fds
|
||||||
fl_rows = filelist.fl_rows
|
fl_rows = fdlist.fl_rows
|
||||||
|
|
||||||
for row in range(fl_rows):
|
for row in range(fl_rows):
|
||||||
for col in range(CONFIG_NFILE_DESCRIPTORS_PER_BLOCK):
|
for col in range(CONFIG_NFILE_DESCRIPTORS_PER_BLOCK):
|
||||||
file = fl_files[row][col]
|
fdp = fl_fds[row][col]
|
||||||
|
|
||||||
if not file or not file.f_inode:
|
if not fdp or not fdp.f_file:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fd = row * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + col
|
fd = row * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + col
|
||||||
|
file = fdp.f_file
|
||||||
|
|
||||||
yield fd, file
|
yield fd, fdp, file
|
||||||
|
|
||||||
|
|
||||||
class Fdinfo(gdb.Command):
|
class Fdinfo(gdb.Command):
|
||||||
@@ -220,7 +221,7 @@ class Fdinfo(gdb.Command):
|
|||||||
super().__init__("fdinfo", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)
|
super().__init__("fdinfo", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)
|
||||||
self.total_fd_count = 0
|
self.total_fd_count = 0
|
||||||
|
|
||||||
def print_file_info(self, fd, file: p.File, formatter: str):
|
def print_file_info(self, fd, fdp: p.Fd, file: p.File, formatter: str):
|
||||||
backtrace_formatter = "{0:<5} {1:<36} {2}"
|
backtrace_formatter = "{0:<5} {1:<36} {2}"
|
||||||
|
|
||||||
oflags = int(file.f_oflags)
|
oflags = int(file.f_oflags)
|
||||||
@@ -230,7 +231,7 @@ class Fdinfo(gdb.Command):
|
|||||||
output = []
|
output = []
|
||||||
if CONFIG_FS_BACKTRACE:
|
if CONFIG_FS_BACKTRACE:
|
||||||
backtrace = utils.Backtrace(
|
backtrace = utils.Backtrace(
|
||||||
utils.ArrayIterator(file.f_backtrace), formatter=backtrace_formatter
|
utils.ArrayIterator(fdp.f_backtrace), formatter=backtrace_formatter
|
||||||
)
|
)
|
||||||
|
|
||||||
output.append(
|
output.append(
|
||||||
@@ -269,8 +270,8 @@ class Fdinfo(gdb.Command):
|
|||||||
gdb.write(formatter.format(*headers) + "\n")
|
gdb.write(formatter.format(*headers) + "\n")
|
||||||
|
|
||||||
fd_count = 0
|
fd_count = 0
|
||||||
for fd, file in foreach_file(tcb):
|
for fd, fdp, file in foreach_file(tcb):
|
||||||
self.print_file_info(fd, file, formatter)
|
self.print_file_info(fd, fdp, file, formatter)
|
||||||
fd_count += 1
|
fd_count += 1
|
||||||
self.total_fd_count += fd_count
|
self.total_fd_count += fd_count
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,16 @@
|
|||||||
from .value import Value
|
from .value import Value
|
||||||
|
|
||||||
|
|
||||||
|
class Fd(Value):
|
||||||
|
"""struct fd"""
|
||||||
|
|
||||||
|
f_file: Value
|
||||||
|
f_cloexec: Value
|
||||||
|
f_tag_fdcheck: Value
|
||||||
|
f_tag_fdsan: Value
|
||||||
|
f_backtrace: Value
|
||||||
|
|
||||||
|
|
||||||
class File(Value):
|
class File(Value):
|
||||||
"""struct file"""
|
"""struct file"""
|
||||||
|
|
||||||
@@ -31,9 +41,6 @@ class File(Value):
|
|||||||
f_pos: Value
|
f_pos: Value
|
||||||
f_inode: Value
|
f_inode: Value
|
||||||
f_priv: Value
|
f_priv: Value
|
||||||
f_tag_fdsan: Value
|
|
||||||
f_tag_fdcheck: Value
|
|
||||||
f_backtrace: Value
|
|
||||||
f_locked: Value
|
f_locked: Value
|
||||||
|
|
||||||
|
|
||||||
@@ -58,8 +65,8 @@ class Inode(Value):
|
|||||||
i_name: Value
|
i_name: Value
|
||||||
|
|
||||||
|
|
||||||
class FileList(Value):
|
class FdList(Value):
|
||||||
"""struct filelist_s"""
|
"""struct fdlist"""
|
||||||
|
|
||||||
fl_rows: Value
|
fl_rows: Value
|
||||||
fl_files: Value
|
fl_fds: Value
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
from .fs import FileList
|
from .fs import FdList
|
||||||
from .value import Value
|
from .value import Value
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ class Group(Value):
|
|||||||
tg_envp: Value
|
tg_envp: Value
|
||||||
tg_envc: Value
|
tg_envc: Value
|
||||||
itimer: Value
|
itimer: Value
|
||||||
tg_filelist: FileList
|
tg_fdlist: FdList
|
||||||
tg_mm_map: Value
|
tg_mm_map: Value
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user