Skip to contentSkip to conversation

wic/engine: fix copying directories into wic image with ext* partition

PATCH In review Dragomir, Daniel 3 participants 8 messages Oct 1, 2025 – Feb 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wic/engine: fix copying directories into wic image with ext* partition

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
 scripts/lib/wic/engine.py | 63 ++++++++++++++++++++++++++++++---------
 1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +49 -14
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                    path))
 
     def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part
+        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part
+        partimg = self._get_part_image(pnum)
 
         if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum))
-            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname)
+                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel)
+                            dest_dir = os.path.dirname(dest_file)
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" "{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+                                                     prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src,
+                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                       format(os.path.dirname(src.path), src.path,
-                             dest, src.path, dest, self.debugfs,
-                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
         else: # fat
             if isinstance(src, str):
                 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src, dest.path)
+                                                      partimg,
+                                                      src, dest.path)
             else:
                 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src.path, dest)
+                                                      partimg,
+                                                      src.path, dest)
 
         exec_cmd(cmd, as_shell=True)
         self._put_part_image(pnum)
Signature · 1 line
2.39.5
#1 lore raw

Is this also an issue on master? If so, you will need to submit this patch for master before I can take it for scarthgap. If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 111 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
 scripts/lib/wic/engine.py | 63 ++++++++++++++++++++++++++++++---------
 1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +49 -15
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                    path))
 
     def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part
+        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part
+        partimg = self._get_part_image(pnum)
 
         if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum))
-            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname)
+                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel)
+                            dest_dir = os.path.dirname(dest_file)
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" "{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+                                                     prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src,
+                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                       format(os.path.dirname(src.path), src.path,
-                             dest, src.path, dest, self.debugfs,
-                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
         else: # fat
             if isinstance(src, str):
                 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src, dest.path)
+                                                      partimg,
+                                                      src, dest.path)
             else:
                 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src.path, dest)
+                                                      partimg,
+                                                      src.path, dest)
 
         exec_cmd(cmd, as_shell=True)
         self._put_part_image(pnum)
--

2.39.5

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#224331): https://lists.openembedded.org/g/openembedded-core/message/224331
Mute This Topic: https://lists.openembedded.org/mt/115542019/3620601
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

Yes, this is an issue on master/master-next too.
I tested and the same patch can be applied fine on both master and scarthgap branches.

Regards,
Daniel

________________________________
From: Steve Sakoman <[email protected]>
Sent: Thursday, October 2, 2025 5:55 PM
To: Dragomir, Daniel <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [OE-core][scarthgap][PATCH] wic/engine: fix copying directories into wic image with ext* partition

Is this also an issue on master? If so, you will need to submit this patch for master before I can take it for scarthgap. If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 105 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
 scripts/lib/wic/engine.py | 63 ++++++++++++++++++++++++++++++---------
 1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +49 -15
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                    path))
 
     def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part
+        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part
+        partimg = self._get_part_image(pnum)
 
         if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum))
-            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname)
+                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel)
+                            dest_dir = os.path.dirname(dest_file)
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" "{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+                                                     prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src,
+                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                       format(os.path.dirname(src.path), src.path,
-                             dest, src.path, dest, self.debugfs,
-                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
         else: # fat
             if isinstance(src, str):
                 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src, dest.path)
+                                                      partimg,
+                                                      src, dest.path)
             else:
                 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src.path, dest)
+                                                      partimg,
+                                                      src.path, dest)
 
         exec_cmd(cmd, as_shell=True)
         self._put_part_image(pnum)
--

2.39.5

#3 lore raw
Quoted 3 lines · Daniel

Yes, this is an issue on master/master-next too.
I tested and the same patch can be applied fine on both master and scarthgap branches.

Thanks for checking.

Please submit the patch for the master branch. It would be helpful if you would then ping me when you see that it has been accepted. I'll try to remember to watch for it, but a ping would ensure I don't miss it :-)

Steve

Quoted 133 lines

Regards,
Daniel

________________________________
From: Steve Sakoman <[email protected]>
Sent: Thursday, October 2, 2025 5:55 PM
To: Dragomir, Daniel <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [OE-core][scarthgap][PATCH] wic/engine: fix copying directories into wic image with ext* partition

Is this also an issue on master? If so, you will need to submit this patch for master before I can take it for scarthgap. If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 111 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
 scripts/lib/wic/engine.py | 63 ++++++++++++++++++++++++++++++---------
 1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +49 -15
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                    path))
 
     def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part
+        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part
+        partimg = self._get_part_image(pnum)
 
         if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum))
-            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname)
+                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel)
+                            dest_dir = os.path.dirname(dest_file)
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" "{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+                                                     prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src,
+                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                       format(os.path.dirname(src.path), src.path,
-                             dest, src.path, dest, self.debugfs,
-                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
         else: # fat
             if isinstance(src, str):
                 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src, dest.path)
+                                                      partimg,
+                                                      src, dest.path)
             else:
                 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src.path, dest)
+                                                      partimg,
+                                                      src.path, dest)
 
         exec_cmd(cmd, as_shell=True)
         self._put_part_image(pnum)
--

2.39.5

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#224331): https://lists.openembedded.org/g/openembedded-core/message/224331
Mute This Topic: https://lists.openembedded.org/mt/115542019/3620601
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#4 lore raw
Quoted 9 lines · Steve Sakoman

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 3 lines · Daniel

Yes, this is an issue on master/master-next too.
I tested and the same patch can be applied fine on both master and scarthgap branches.

Quoted 6 lines

Thanks for checking.

Please submit the patch for the master branch. It would be helpful if you would then ping me when you see that it has been accepted. I'll try to remember to watch for it, but a ping would ensure I don't miss it :-)

Hi Steve,

Those changes were accepted in master branch. I created also a selftest for this scenario.
Could you please back-port the commits to scarthgap branch? I tried locally and there is a minor merge conflict on one of the commits. If you want me to send again a scarthgap version of the commits on the mailing list, let me know.

Commits from master branch are:
6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition

Regards,
Daniel

Quoted 136 lines

Steve

Quoted 133 lines

Regards,
Daniel

________________________________
From: Steve Sakoman <[email protected]>
Sent: Thursday, October 2, 2025 5:55 PM
To: Dragomir, Daniel <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [OE-core][scarthgap][PATCH] wic/engine: fix copying directories into wic image with ext* partition

Is this also an issue on master? If so, you will need to submit this patch for master before I can take it for scarthgap. If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 111 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
  scripts/lib/wic/engine.py | 63 ++++++++++++++++++++++++++++++---------
  1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +49 -15
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                     path))
 
      def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part
+        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part
+        partimg = self._get_part_image(pnum)
 
          if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum))
-            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname)
+                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel)
+                            dest_dir = os.path.dirname(dest_file)
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" "{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+                                                     prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src,
+                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                  cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                        format(os.path.dirname(src.path), src.path,
-                             dest, src.path, dest, self.debugfs,
-                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
          else: # fat
              if isinstance(src, str):
                  cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src, dest.path)
+                                                      partimg,
+                                                      src, dest.path)
              else:
                  cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
-                                                  self._get_part_image(pnum),
-                                                  src.path, dest)
+                                                      partimg,
+                                                      src.path, dest)
 
          exec_cmd(cmd, as_shell=True)
          self._put_part_image(pnum)
--

2.39.5

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#224331): https://lists.openembedded.org/g/openembedded-core/message/224331
Mute This Topic: https://lists.openembedded.org/mt/115542019/3620601
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#5 lore raw
Quoted 19 lines · Daniel Dragomir
Quoted 9 lines · Steve Sakoman

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 3 lines · Daniel

Yes, this is an issue on master/master-next too.
I tested and the same patch can be applied fine on both master and scarthgap branches.

Quoted 6 lines

Thanks for checking.

Please submit the patch for the master branch.  It would be helpful if you would then ping me when you see that it has been accepted.  I'll try to remember to watch for it, but a ping would ensure I don't miss it :-)

Quoted 9 lines

Hi Steve,

Those changes were accepted in master branch. I created also a selftest for this scenario.
Could you please back-port the commits to scarthgap branch? I tried locally and there is a minor merge conflict on one of the commits. If you want me to send again a scarthgap version of the commits on the mailing list, let me know.

Commits from master branch are:
6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition

Hi Steve and Yoann,

Can you please help with a back-port on scarthgap for the commits bellow which were accepted in master?

6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition cb536737be wic/engine: error on old host debugfs for standalone directory copy

Thank you!
Daniel

Quoted 152 lines

Regards,
Daniel

Quoted 149 lines

Steve

Quoted 146 lines

Regards,
Daniel

________________________________
From: Steve Sakoman <[email protected]>
Sent: Thursday, October 2, 2025 5:55 PM
To: Dragomir, Daniel <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [OE-core][scarthgap][PATCH] wic/engine: fix copying directories into wic image with ext* partition

Is this also an issue on master?  If so, you will need to submit this patch for master before I can take it for scarthgap.  If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 124 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
     -l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
  scripts/lib/wic/engine.py | 63
++++++++++++++++++++++++++++++---------

  1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +0 -0
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                      path))
 

      def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part +        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part +        partimg = self._get_part_image(pnum)

          if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum)) -            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname) +                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel) +                            dest_dir = os.path.dirname(dest_file)

scripts/lib/wic/engine.py +11 -0
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" 

"{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+
prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src, +                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                  cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                        format(os.path.dirname(src.path), src.path, -                             dest, src.path, dest, self.debugfs, -                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
          else: # fat
              if isinstance(src, str):
                  cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, -
self._get_part_image(pnum),
-                                                  src, dest.path) +                                                      partimg,
+                                                      src, dest.path) else:
                  cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, -
self._get_part_image(pnum),
-                                                  src.path, dest) +                                                      partimg,
+                                                      src.path, dest)

          exec_cmd(cmd, as_shell=True)
          self._put_part_image(pnum)

Signature · 10 lines
2.39.5


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#224331): https://lists.openembedded.org/g/openembedded-core/message/224331
Mute This Topic: https://lists.openembedded.org/mt/115542019/3620601
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
#6 lore raw
Quoted 33 lines · Daniel via lists.openembedded.org Dragomir
Quoted 30 lines · Daniel Dragomir
Quoted 11 lines · Steve Sakoman

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 4 lines · Daniel

Yes, this is an issue on master/master-next too.
I tested and the same patch can be applied fine on both master and scarthgap branches.

Quoted 6 lines

Thanks for checking.

Please submit the patch for the master branch.  It would be helpful if you would then ping me when you see that it has been accepted.  I'll try to remember to watch for it, but a ping would ensure I don't miss it :-)

Hi Steve,

Those changes were accepted in master branch. I created also a selftest for this scenario.
Could you please back-port the commits to scarthgap branch? I tried locally and there is a minor merge conflict on one of the commits. If you want me to send again a scarthgap version of the commits on the mailing list, let me know.

Quoted 7 lines
Quoted 5 lines

Commits from master branch are:
6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition

Hi Steve and Yoann,

Hello,

Quoted 6 lines

Can you please help with a back-port on scarthgap for the commits bellow which were accepted in master?

6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition

I reviewed those 2 and they will be in my next series.

Quoted 1 line

cb536737be wic/engine: error on old host debugfs for standalone directory copy

For this one, can you send backport patches to scarthgap and whinlatter?

Quoted 153 lines

Thank you!
Daniel

Quoted 149 lines

Regards,
Daniel

Quoted 146 lines

Steve

Quoted 143 lines

Regards,
Daniel

________________________________
From: Steve Sakoman <[email protected]>
Sent: Thursday, October 2, 2025 5:55 PM
To: Dragomir, Daniel <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [OE-core][scarthgap][PATCH] wic/engine: fix copying directories into wic image with ext* partition

Is this also an issue on master?  If so, you will need to submit this patch for master before I can take it for scarthgap.  If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 119 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
     -l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
  scripts/lib/wic/engine.py | 63
++++++++++++++++++++++++++++++---------

  1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +0 -0
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                      path))
 

      def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part +        """Copy files or directories to/from the vfat or ext* partition."""
+        pnum = dest.part if isinstance(src, str) else src.part +        partimg = self._get_part_image(pnum)

          if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src, os.path.basename(src),
-                             self.debugfs, self._get_part_image(pnum)) -            else: # copy from wic
-                # run both dump and rdump to support both files and directory
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname) +                            rel = os.path.relpath(host_file, base_parent)
+                            dest_file = os.path.join(dest.path, rel) +                            dest_dir = os.path.dirname(dest_file)

scripts/lib/wic/engine.py +11 -0
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}" 

"{dest_file}"')
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w', delete=False,
+
prefix='wic-debugfs-') as tf:
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname} {partimg}"
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src, +                                 os.path.basename(src), self.debugfs, partimg)
+
+            else: # image to host case
                  cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
                        format(os.path.dirname(src.path), src.path, -                             dest, src.path, dest, self.debugfs, -                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs, partimg)
+
          else: # fat
              if isinstance(src, str):
                  cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, -
self._get_part_image(pnum),
-                                                  src, dest.path) +                                                      partimg, +                                                      src, dest.path) else:
                  cmd = "{} -i {} -snop ::{} {}".format(self.mcopy, -
self._get_part_image(pnum),
-                                                  src.path, dest) +                                                      partimg, +                                                      src.path, dest)

          exec_cmd(cmd, as_shell=True)
          self._put_part_image(pnum)

Signature · 1 line
2.39.5
Signature · 2 lines
Yoann Congal
Smile ECS
#7 lore raw
Quoted 50 lines · Yoann Congal

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 33 lines · Daniel via lists.openembedded.org Dragomir
Quoted 30 lines · Daniel Dragomir
Quoted 11 lines · Steve Sakoman

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 4 lines · Daniel

Yes, this is an issue on master/master-next too.
I tested and the same patch can be applied fine on both master and scarthgap branches.

Quoted 6 lines

Thanks for checking.

Please submit the patch for the master branch. It would be helpful if you would then ping me when you see that it has been accepted. I'll try to remember to watch for it, but a ping would ensure I don't miss it :-)

Hi Steve,

Those changes were accepted in master branch. I created also a selftest for this scenario.
Could you please back-port the commits to scarthgap branch? I tried locally and there is a minor merge conflict on one of the commits. If you want me to send again a scarthgap version of the commits on the mailing list, let me know.

Quoted 7 lines
Quoted 5 lines

Commits from master branch are:
6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition

Hi Steve and Yoann,

Hello,

Quoted 3 lines

Can you please help with a back-port on scarthgap for the commits bellow which were accepted in master?

Quoted 8 lines
Quoted 3 lines

6de3d2602f oeqa/selftest/wic: test recursive dir copy on ext partitions 1ed38aff5f wic/engine: fix copying directories into wic image with ext* partition

I reviewed those 2 and they will be in my next series.

Quoted 1 line

cb536737be wic/engine: error on old host debugfs for standalone directory copy

For this one, can you send backport patches to scarthgap and whinlatter?

Sure! Will send for both branches.
Thanks Yoann!

Quoted 160 lines
Quoted 146 lines

Thank you!
Daniel

Quoted 141 lines

Regards,
Daniel

Quoted 138 lines

Steve

Quoted 135 lines

Regards,
Daniel

________________________________
From: Steve Sakoman <[email protected]>
Sent: Thursday, October 2, 2025 5:55 PM
To: Dragomir, Daniel <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [OE-core][scarthgap][PATCH] wic/engine: fix copying directories into wic image with ext* partition

Is this also an issue on master? If so, you will need to submit this patch for master before I can take it for scarthgap. If not, can you explain why it isn't needed there?

Thanks,

Steve

Quoted 111 lines · Daniel via lists.openembedded.org

wic uses debugfs to write on ext* partitions, but debugfs can only write to the current working directory and it cannot copy complete directory trees. Running 'wic ls' on a copied directory show this:
-l: Ext2 inode is not a directory

Fix this by creating a command list for debugfs (-f parameter) when recursive parsing the host directory in order to create a similar directory structure (mkdir) and copy files (write) on each level into the destination directory from the wic's ext* partition.

---
   scripts/lib/wic/engine.py | 63
++++++++++++++++++++++++++++++---------
   1 file changed, 49 insertions(+), 14 deletions(-)
scripts/lib/wic/engine.py +1 -2
index b9e60cbe4e..9d596be3a7 100644
@@ -345,29 +345,64 @@ class Disk:
                                                      path))
 
       def copy(self, src, dest):
-        """Copy partition image into wic image."""
-        pnum =  dest.part if isinstance(src, str) else src.part
+        """Copy files or directories to/from the vfat or ext*

partition."""

scripts/lib/wic/engine.py +2 -3
+        pnum = dest.part if isinstance(src, str) else src.part
+        partimg = self._get_part_image(pnum)
 
           if self.partitions[pnum].fstype.startswith('ext'):
-            if isinstance(src, str):
-                cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
-                      format(os.path.dirname(dest.path), src,

os.path.basename(src),

scripts/lib/wic/engine.py +0 -3
-                             self.debugfs, self._get_part_image(pnum))
-            else: # copy from wic
-                # run both dump and rdump to support both files and

directory

scripts/lib/wic/engine.py +11 -0
+            if isinstance(src, str): # host to image case
+                if os.path.isdir(src):
+                    base = os.path.abspath(src)
+                    base_parent = os.path.dirname(base)
+                    cmds = []
+                    made = set()
+
+                    for root, dirs, files in os.walk(base):
+                        for fname in files:
+                            host_file = os.path.join(root, fname)
+                            rel = os.path.relpath(host_file,

base_parent)

scripts/lib/wic/engine.py +13 -0
+                            dest_file = os.path.join(dest.path, rel)
+                            dest_dir = os.path.dirname(dest_file)
+
+                            # create dir structure (mkdir -p)
+                            parts = dest_dir.strip('/').split('/')
+                            cur = ''
+                            for p in parts:
+                                cur = cur + '/' + p
+                                if cur not in made:
+                                    cmds.append(f'mkdir "{cur}"')
+                                    made.add(cur)
+
+                            cmds.append(f'write "{host_file}"

"{dest_file}"')

scripts/lib/wic/engine.py +3 -0
+
+                    # write script to a temp file
+                    with tempfile.NamedTemporaryFile(mode='w',

delete=False,
+
prefix='wic-debugfs-') as tf:

scripts/lib/wic/engine.py +5 -0
+                        for line in cmds:
+                            tf.write(line + '\n')
+                        scriptname = tf.name
+
+                    cmd = f"{self.debugfs} -w -f {scriptname}

{partimg}"

scripts/lib/wic/engine.py +5 -0
+
+                else: # single file
+                    cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
+                          format(os.path.dirname(dest.path), src,
+                                 os.path.basename(src),

self.debugfs, partimg)

scripts/lib/wic/engine.py +2 -0
+
+            else: # image to host case
                   cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n'

| {} {}".\
format(os.path.dirname(src.path), src.path,

scripts/lib/wic/engine.py +1 -2
-                             dest, src.path, dest, self.debugfs,
-                             self._get_part_image(pnum))
+                             dest, src.path, dest, self.debugfs,

partimg)

scripts/lib/wic/engine.py +1 -1
+
           else: # fat
               if isinstance(src, str):
                   cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
-

self._get_part_image(pnum),

scripts/lib/wic/engine.py +2 -2
-                                                  src, dest.path)
+                                                      partimg,
+                                                      src, dest.path)
               else:
                   cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
-

self._get_part_image(pnum),

scripts/lib/wic/engine.py +2 -1
-                                                  src.path, dest)
+                                                      partimg,
+                                                      src.path, dest)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

exec_cmd(cmd, as_shell=True)
self._put_part_image(pnum)
--
2.39.5

--
Yoann Congal
Smile ECS