[PATCH v2 27/28] fs/squashfs: sqfs_read: fragmented files are not supported

Richard Genoud richard.genoud at posteo.net
Wed Nov 25 09:58:00 CET 2020


Hi,

Le 20/11/2020 à 02:35, Tom Rini a écrit :
> On Tue, Nov 03, 2020 at 12:11:25PM +0100, Richard Genoud wrote:
> 
>> The code for reading a fragmented file is not functionnal.
>> It's better to signal this to the user.
>>
>> Signed-off-by: Richard Genoud <richard.genoud at posteo.net>
> 
> This change causes the test.py squashfs tests to fail.  I am unsure if
> the problem is with the tests or this exposing further problems in the
> code.
Actually, reading a fragmented file doesn't work.
The test only check if the file is read, but not it's content.

With this following patch, we'll see that the file content is not the same :


 From 68f87301c059aaae8e90e42fbec9b560aee0c6eb Mon Sep 17 00:00:00 2001
From: Richard Genoud <richard.genoud at posteo.net>
Date: Tue, 24 Nov 2020 17:45:07 +0100
Subject: [PATCH] test/py: SquashFS: Check if loaded file is corrupted

After loading the file in memory, its content should be checked for
errors.

Signed-off-by: Richard Genoud <richard.genoud at posteo.net>
---
  test/py/tests/test_fs/test_squashfs/sqfs_common.py    | 5 ++++-
  test/py/tests/test_fs/test_squashfs/test_sqfs_load.py | 6 +++++-
  2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
index c96f92c1d8f..a7673c73762 100644
--- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py
+++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
@@ -6,6 +6,7 @@ import os
  import random
  import string
  import subprocess
+import zlib

  def sqfs_get_random_letters(size):
      letters = []
@@ -19,12 +20,14 @@ def sqfs_generate_file(path, size):
      file = open(path, "w")
      file.write(content)
      file.close()
+    return zlib.crc32(content.encode())

  class Compression:
      def __init__(self, name, files, sizes, block_size = 4096):
          self.name = name
          self.files = files
          self.sizes = sizes
+        self.crc = []
          self.mksquashfs_opts = " -b " + str(block_size) + " -comp " + self.name

      def add_opt(self, opt):
@@ -34,7 +37,7 @@ class Compression:
          src = os.path.join(build_dir, "sqfs_src/")
          os.mkdir(src)
          for (f, s) in zip(self.files, self.sizes):
-            sqfs_generate_file(src + f, s)
+            self.crc.append(sqfs_generate_file(src + f, s))

          # the symbolic link always targets the first file
          os.symlink(self.files[0], src + "sym")
diff --git a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
index 9e900623846..2ab4660036e 100644
--- a/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
+++ b/test/py/tests/test_fs/test_squashfs/test_sqfs_load.py
@@ -4,6 +4,7 @@

  import os
  import pytest
+import zlib
  from sqfs_common import *

  @pytest.mark.boardspec('sandbox')
@@ -14,6 +15,7 @@ from sqfs_common import *
  def test_sqfs_load(u_boot_console):
      build_dir = u_boot_console.config.build_dir
      command = "sqfsload host 0 $kernel_addr_r "
+    sum_command = "crc32 -v $kernel_addr_r $filesize "

      for opt in comp_opts:
          # generate and load the squashfs image
@@ -30,10 +32,12 @@ def test_sqfs_load(u_boot_console):
          output = u_boot_console.run_command(command + "xxx")
          assert "File not found." in output

-        for (f, s) in zip(opt.files, opt.sizes):
+        for (f, s, c) in zip(opt.files, opt.sizes, opt.crc):
              try:
                  output = u_boot_console.run_command(command + f)
                  assert str(s) in output
+                output = u_boot_console.run_command(sum_command + format(c, '08x'))
+                assert not 'ERROR' in output
              except:
                  assert False
                  opt.cleanup(build_dir)



More information about the U-Boot mailing list