File: 0007-swu_file-Renumber-cpio-inodes-to-support-64-bit-file.patch

package info (click to toggle)
swugenerator 0.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 452 kB
  • sloc: python: 1,304; sh: 107; makefile: 14
file content (72 lines) | stat: -rw-r--r-- 2,841 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 6d8dc70352e8bfea457e3956d465fca74db7d273 Mon Sep 17 00:00:00 2001
From: Tobias Deiminger <tobias.deiminger@linutronix.de>
Date: Thu, 13 Nov 2025 23:10:03 +0100
Subject: [PATCH] swu_file: Renumber cpio inodes to support 64 bit file systems

The cpio newc header format reserves an 8 byte hex string for inodes,
where "ffffffff" is the max value. Until now, we took the inode from the
original file system, checked if within 32 bit range and exited with
error if not. This is safe, but doesn't support file systems like XFS
that use 64 bit inodes.

64 bit inodes obviously can't be represented in a newc header directly.
However, we can get some ideas to handle the situation from GNU cpio.
Their strategy is
- default: silently truncate inodes to 32 bit,
- with -W truncate: truncate and print warning message,
- with --renumber-inodes: create artificial inode numbers to use up the
  full 32 bit space.

The approach picked here is similar to "--renumber-indoes", but
simplified. As long as swupdate doesn't preserve hardlinks, there's no
need to maintain per-hardlink sets. Counting up is enough.

Note: Truncating inodes -- or even setting a const value -- would have
been enough to fix the issue. Though, the counter makes the 32 bit
limitation obvious to future developers that may wish to add hard link
support.

Signed-off-by: Tobias Deiminger <tobias.deiminger@linutronix.de>
Forwarded: https://github.com/sbabic/swugenerator/pull/22
---
 swugenerator/swu_file.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/swugenerator/swu_file.py b/swugenerator/swu_file.py
index 058a413..126e0d1 100644
--- a/swugenerator/swu_file.py
+++ b/swugenerator/swu_file.py
@@ -25,6 +25,7 @@ class SWUFile:
         """
         self.position = 0
         self.file = file
+        self.renumbered_inode_count = 0
         self.artifacts = []
         # for reading
         self.header = None
@@ -86,13 +87,21 @@ class SWUFile:
             raise CPIOException("File was changed while reading", cpio_filename)
         self.artifacts.append(cpio_filename)
 
+    def next_renumbered_inode(self):
+        """Make renumbered inode to be safe on 64 bit file systems.
+
+        Simply counting up inodes is enough since swupdate doesn't preserve hard links.
+        """
+        self.renumbered_inode_count += 1
+        return self.renumbered_inode_count
+
     def write_header(self, cpio_filename):
         if cpio_filename != "TRAILER!!!":
             statres = os.stat(cpio_filename)
             crc = self.cpiocrc(cpio_filename)
             base_filename = os.path.basename(cpio_filename)
             fields = [
-                statres.st_ino,
+                self.next_renumbered_inode(),
                 statres.st_mode,
                 statres.st_uid,
                 statres.st_gid,
-- 
2.47.3