forked from Imagelibrary/littlefs
dbgerr.py and dbgtag.py have proven to be incredibly useful for quick debugging/introspection, so I figured why not have more of that. My favorite part is being able to quickly see all flags set on an open file handle: (gdb) p file.o.o.flags $2 = 24117517 (gdb) !./scripts/dbgflags.py o 24117517 LFS_O_WRONLY 0x00000001 Open a file as write only LFS_O_CREAT 0x00000004 Create a file if it does not exist LFS_O_EXCL 0x00000008 Fail if a file already exists LFS_O_DESYNC 0x00000100 Do not sync or recieve file updates LFS_o_REG 0x01000000 Type = regular-file LFS_o_UNFLUSH 0x00100000 File's data does not match disk LFS_o_UNSYNC 0x00200000 File's metadata does not match disk LFS_o_UNCREAT 0x00400000 File does not exist yet The only concern is if dbgflags.py falls out-of-sync often, I suspect flag encoding will have quite a bit more churn than flags/tags. But we can always drop this script in the future if this turns into a problem. --- While poking around this also ended up with a bunch of other small changes: - Added LFS_*_MODE masks for consistency with other "type<->flag embeddings" - Added compat flag comments - Adopted lowercase prefix for internal flags (LFS_o_ZOMBIE), though not sure if I'll keep this yet... - Tweaked dbgerr.py to also match ERR_ prefixes and to ignore case
111 lines
3.6 KiB
Python
Executable File
111 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# prevent local imports
|
|
if __name__ == "__main__":
|
|
__import__('sys').path.pop(0)
|
|
|
|
|
|
ERRS = [
|
|
('OK', 0, "No error" ),
|
|
('UNKNOWN', -1, "Unknown error" ),
|
|
('INVAL', -22, "Invalid parameter" ),
|
|
('NOTSUP', -95, "Operation not supported" ),
|
|
('IO', -5, "Error during device operation" ),
|
|
('CORRUPT', -84, "Corrupted" ),
|
|
('NOENT', -2, "No directory entry" ),
|
|
('EXIST', -17, "Entry already exists" ),
|
|
('NOTDIR', -20, "Entry is not a dir" ),
|
|
('ISDIR', -21, "Entry is a dir" ),
|
|
('NOTEMPTY', -39, "Dir is not empty" ),
|
|
('FBIG', -27, "File too large" ),
|
|
('NOSPC', -28, "No space left on device" ),
|
|
('NOMEM', -12, "No more memory available" ),
|
|
('NOATTR', -61, "No data/attr available" ),
|
|
('NAMETOOLONG', -36, "File name too long" ),
|
|
('RANGE', -34, "Result out of range" ),
|
|
]
|
|
|
|
|
|
def main(errs, *,
|
|
list=False):
|
|
import builtins
|
|
list_, list = list, builtins.list
|
|
|
|
lines = []
|
|
# list all known error codes
|
|
if list_:
|
|
for n, e, h in ERRS:
|
|
lines.append(('LFS_ERR_'+n, str(e), h))
|
|
|
|
# find these errors
|
|
else:
|
|
def find_err(err):
|
|
# find by LFS_ERR_+name
|
|
for n, e, h in ERRS:
|
|
if 'LFS_ERR_'+n == err.upper():
|
|
return n, e, h
|
|
# find by ERR_+name
|
|
for n, e, h in ERRS:
|
|
if 'ERR_'+n == err.upper():
|
|
return n, e, h
|
|
# find by name
|
|
for n, e, h in ERRS:
|
|
if n == err.upper():
|
|
return n, e, h
|
|
# find by E+name
|
|
for n, e, h in ERRS:
|
|
if 'E'+n == err.upper():
|
|
return n, e, h
|
|
try:
|
|
# find by err code
|
|
for n, e, h in ERRS:
|
|
if e == int(err, 0):
|
|
return n, e, h
|
|
# find by negated err code
|
|
for n, e, h in ERRS:
|
|
if e == -int(err, 0):
|
|
return n, e, h
|
|
except ValueError:
|
|
pass
|
|
# not found
|
|
raise KeyError(err)
|
|
|
|
for err in errs:
|
|
try:
|
|
n, e, h = find_err(err)
|
|
lines.append(('LFS_ERR_'+n, str(e), h))
|
|
except KeyError:
|
|
lines.append(('?', err, 'Unknown err code'))
|
|
|
|
# first find widths
|
|
w = [0, 0]
|
|
for l in lines:
|
|
w[0] = max(w[0], len(l[0]))
|
|
w[1] = max(w[1], len(l[1]))
|
|
|
|
# then print results
|
|
for l in lines:
|
|
print('%-*s %-*s %s' % (
|
|
w[0], l[0],
|
|
w[1], l[1],
|
|
l[2]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
import sys
|
|
parser = argparse.ArgumentParser(
|
|
description="Decode littlefs error codes.",
|
|
allow_abbrev=False)
|
|
parser.add_argument(
|
|
'errs',
|
|
nargs='*',
|
|
help="Error codes or error names to decode.")
|
|
parser.add_argument(
|
|
'-l', '--list',
|
|
action='store_true',
|
|
help="List all known error codes.")
|
|
sys.exit(main(**{k: v
|
|
for k, v in vars(parser.parse_intermixed_args()).items()
|
|
if v is not None}))
|