aboutsummaryrefslogtreecommitdiffstats
path: root/tools/net/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2024-10-03 14:54:35 -0400
committerChuck Lever <chuck.lever@oracle.com>2024-11-11 13:42:02 -0500
commit16c98ce04a6929019f66dab40367fb14d0afc678 (patch)
tree436a86f099eb5423937287dcc8626fcfd142cc58 /tools/net/sunrpc
parentxdrgen: XDR widths for enum types (diff)
downloadlinux-16c98ce04a6929019f66dab40367fb14d0afc678.tar.gz
linux-16c98ce04a6929019f66dab40367fb14d0afc678.zip
xdrgen: XDR width for fixed-length opaque
The XDR width for a fixed-length opaque is the byte size of the opaque rounded up to the next XDR_UNIT, divided by XDR_UNIT. Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Diffstat (limited to 'tools/net/sunrpc')
-rw-r--r--tools/net/sunrpc/xdrgen/xdr_ast.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py
index fbee954c7f70..9fe7fa688caa 100644
--- a/tools/net/sunrpc/xdrgen/xdr_ast.py
+++ b/tools/net/sunrpc/xdrgen/xdr_ast.py
@@ -21,6 +21,16 @@ pass_by_reference = set()
constants = {}
+
+def xdr_quadlen(val: str) -> int:
+ """Return integer XDR width of an XDR type"""
+ if val in constants:
+ octets = constants[val]
+ else:
+ octets = int(val)
+ return int((octets + 3) / 4)
+
+
symbolic_widths = {
"void": ["XDR_void"],
"bool": ["XDR_bool"],
@@ -117,6 +127,18 @@ class _XdrFixedLengthOpaque(_XdrDeclaration):
size: str
template: str = "fixed_length_opaque"
+ def max_width(self) -> int:
+ """Return width of type in XDR_UNITS"""
+ return xdr_quadlen(self.size)
+
+ def symbolic_width(self) -> List:
+ """Return list containing XDR width of type's components"""
+ return ["XDR_QUADLEN(" + self.size + ")"]
+
+ def __post_init__(self):
+ max_widths[self.name] = self.max_width()
+ symbolic_widths[self.name] = self.symbolic_width()
+
@dataclass
class _XdrVariableLengthOpaque(_XdrDeclaration):