From cd7dd378887dc1e50677309cc220498425721e54 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 17 Nov 2025 00:02:29 -0600 Subject: [PATCH] scripts: dbglfs3.py: Adopted % as littlefs root dir character The idea is this is similar to ~ for the home directory, hopefully simplifying littlefs path parsing in scripts: - /hi -> hi in root dir - ./hi -> hi in current dir - ../hi -> hi in parent dir - ~/hi -> hi in home dir - %/hi -> hi in littlefs root dir Note this only works when standalone: - ~hi != ~/hi - %hi != %/hi And files named % can still be referenced with a ./ prefix: - ./% -> % in current dir - %/% -> % in littlefs root dir --- This is probably overkill for dbglfs3.py, as the arg ordering was already enough to disambiguate disk path vs mroot address vs littlefs path, but eventually I think the idea will be useful for more powerful scripts. A hypothetical: $ mklfs3 cp disk -b4096 -r image_files %/image_files --- scripts/dbglfs3.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/dbglfs3.py b/scripts/dbglfs3.py index 4b09299f..f8a0a6be 100755 --- a/scripts/dbglfs3.py +++ b/scripts/dbglfs3.py @@ -4422,8 +4422,14 @@ def dbg_files(lfs, paths, *, # parse all paths first, error if anything is malformed dirs = [] # default paths to the root dir - for path in (paths or ['/']): + for path in (paths or ['%']): try: + # skip leading % + if path == '%': + path = '/' + if path.startswith('%/'): + path = path[1:] + # lookup path dir = lfs.pathlookup(path, all=args.get('all')) except Lfs3.PathError as e: @@ -4952,16 +4958,17 @@ if __name__ == "__main__": parser.add_argument( 'mroots', nargs='*', - type=lambda x: rbydaddr(x) if not x.startswith('/') else x, + type=lambda x: rbydaddr(x) if not x.startswith('%') else x, action=AppendMrootOrPath, help="Block address of the mroots. Defaults to 0x{0,1}.") parser.add_argument( 'paths', nargs='*', - type=lambda x: rbydaddr(x) if not x.startswith('/') else x, + type=lambda x: rbydaddr(x) if not x.startswith('%') else x, action=AppendMrootOrPath, - help="Paths to show, must start with a leading slash. Defaults " - "to the root directory.") + help="Paths to show, must start with %% where %% indicates the " + "root littlefs directory. Defaults to the root littlefs " + "directory.") parser.add_argument( '--trunk', type=lambda x: int(x, 0),