Skip to content
Snippets Groups Projects
  1. Mar 27, 2020
  2. Feb 07, 2020
    • Marek Szyprowski's avatar
      fat: write: adjust data written in each partial write · a54ece40
      Marek Szyprowski authored and Tom Rini's avatar Tom Rini committed
      
      The code for handing file overwrite incorrectly calculated the amount of
      data to write when writing to the last non-cluster aligned chunk. Fix
      this by ensuring that no more data than the 'filesize' is written to disk.
      While touching min()-based calculations, change it to type-safe min_t()
      function.
      
      Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
      
      This patch finally fixes the issue revealed by the test script from the
      previous patch. The correctness of the change has been also verified by
      the following additional test scripts:
      
      --->8-fat_test2.sh---
      #!/bin/bash
      make sandbox_defconfig
      make
      dd if=/dev/zero of=/tmp/10M.img bs=1024 count=10k
      mkfs.vfat -v /tmp/10M.img
      cat >/tmp/cmds <<EOF
      x
      host bind 0 /tmp/10M.img
      fatls host 0
      mw 0x1000000 0x0a434241 0x1000 # "ABC\n"
      mw 0x1100000 0x0a464544 0x8000 # "DEF\n"
      fatwrite host 0 0x1000000 file0001.raw 0x1000
      fatwrite host 0 0x1000000 file0002.raw 0x1000
      fatwrite host 0 0x1000000 file0003.raw 0x1000
      fatwrite host 0 0x1000000 file0004.raw 0x1000
      fatwrite host 0 0x1000000 file0005.raw 0x1000
      fatrm host 0 file0002.raw
      fatrm host 0 file0004.raw
      fatls host 0
      fatwrite host 0 0x1100000 file0007.raw 0x2000
      fatwrite host 0 0x1100000 file0007.raw 0x1f00
      reset
      EOF
      ./u-boot </tmp/cmds
      #verify
      rm -r /tmp/result /tmp/model
      mkdir /tmp/result
      mkdir /tmp/model
      yes ABC | head -c 4096 >/tmp/model/file0001.raw
      yes ABC | head -c 4096 >/tmp/model/file0003.raw
      yes ABC | head -c 4096 >/tmp/model/file0005.raw
      yes DEF | head -c 7936 >/tmp/model/file0007.raw
      mcopy -n -i /tmp/10M.img ::file0001.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0003.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0005.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0007.raw /tmp/result
      hd /tmp/10M.img
      if diff -urq /tmp/model /tmp/result
      then
      	echo Test okay
      else
      	echo Test fail
      fi
      --->8-fat_test3.sh---
      #!/bin/bash
      make sandbox_defconfig
      make
      dd if=/dev/zero of=/tmp/10M.img bs=1024 count=10k
      mkfs.vfat -v /tmp/10M.img
      cat >/tmp/cmds <<EOF
      x
      host bind 0 /tmp/10M.img
      fatls host 0
      mw 0x1000000 0x0a434241 0x1000 # "ABC\n"
      mw 0x1100000 0x0a464544 0x8000 # "DEF\n"
      fatwrite host 0 0x1000000 file0001.raw 0x1000
      fatwrite host 0 0x1000000 file0002.raw 0x1000
      fatwrite host 0 0x1000000 file0003.raw 0x1000
      fatwrite host 0 0x1000000 file0004.raw 0x1000
      fatwrite host 0 0x1000000 file0005.raw 0x1000
      fatrm host 0 file0002.raw
      fatrm host 0 file0004.raw
      fatls host 0
      fatwrite host 0 0x1100000 file0007.raw 0x2000
      fatwrite host 0 0x1100000 file0007.raw 0x2100
      reset
      EOF
      ./u-boot </tmp/cmds
      #verify
      rm -r /tmp/result /tmp/model
      mkdir /tmp/result
      mkdir /tmp/model
      yes ABC | head -c 4096 >/tmp/model/file0001.raw
      yes ABC | head -c 4096 >/tmp/model/file0003.raw
      yes ABC | head -c 4096 >/tmp/model/file0005.raw
      yes DEF | head -c 8448 >/tmp/model/file0007.raw
      mcopy -n -i /tmp/10M.img ::file0001.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0003.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0005.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0007.raw /tmp/result
      hd /tmp/10M.img
      if diff -urq /tmp/model /tmp/result
      then
      	echo Test okay
      else
      	echo Test fail
      fi
      --->8-fat_test4.sh---
      #!/bin/bash
      make sandbox_defconfig
      make
      dd if=/dev/zero of=/tmp/10M.img bs=1024 count=10k
      mkfs.vfat -v /tmp/10M.img
      cat >/tmp/cmds <<EOF
      x
      host bind 0 /tmp/10M.img
      fatls host 0
      mw 0x1000000 0x0a434241 0x1000 # "ABC\n"
      mw 0x1100000 0x0a464544 0x8000 # "DEF\n"
      mw 0x1200000 0x0a494847 0x8000 # "GHI\n"
      fatwrite host 0 0x1000000 file0001.raw 0x1000
      fatwrite host 0 0x1000000 file0002.raw 0x1000
      fatwrite host 0 0x1000000 file0003.raw 0x1000
      fatwrite host 0 0x1000000 file0004.raw 0x1000
      fatwrite host 0 0x1000000 file0005.raw 0x1000
      fatrm host 0 file0002.raw
      fatrm host 0 file0004.raw
      fatls host 0
      fatwrite host 0 0x1100000 file0007.raw 0x900
      fatwrite host 0 0x1200000 file0007.raw 0x900 0x900
      fatwrite host 0 0x1100000 file0007.raw 0x900 0x1200
      fatwrite host 0 0x1200000 file0007.raw 0x900 0x1b00
      reset
      EOF
      ./u-boot </tmp/cmds
      #verify
      rm -r /tmp/result /tmp/model
      mkdir /tmp/result
      mkdir /tmp/model
      yes ABC | head -c 4096 >/tmp/model/file0001.raw
      yes ABC | head -c 4096 >/tmp/model/file0003.raw
      yes ABC | head -c 4096 >/tmp/model/file0005.raw
      yes DEF | head -c 2304 >/tmp/model/file0007.raw
      yes GHI | head -c 2304 >>/tmp/model/file0007.raw
      yes DEF | head -c 2304 >>/tmp/model/file0007.raw
      yes GHI | head -c 2304 >>/tmp/model/file0007.raw
      mcopy -n -i /tmp/10M.img ::file0001.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0003.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0005.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0007.raw /tmp/result
      hd /tmp/10M.img
      if diff -urq /tmp/model /tmp/result
      then
      	echo Test okay
      else
      	echo Test fail
      fi
      --->8---
      Feel free to prepare a proper sandbox/py_test based tests based on
      the provided test scripts.
      a54ece40
    • Marek Szyprowski's avatar
      fat: write: fix broken write to fragmented files · 5e615b74
      Marek Szyprowski authored and Tom Rini's avatar Tom Rini committed
      
      The code for handing file overwrite incorrectly assumed that the file on
      disk is always contiguous. This resulted in corrupting disk structure
      every time when write to existing fragmented file happened. Fix this
      by adding proper check for cluster discontinuity and adjust chunk size
      on each partial write.
      
      Signed-off-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
      
      This patch partially fixes the issue revealed by the following test
      script:
      
      --->8-fat_test1.sh---
      #!/bin/bash
      make sandbox_defconfig
      make
      dd if=/dev/zero of=/tmp/10M.img bs=1024 count=10k
      mkfs.vfat -v /tmp/10M.img
      cat >/tmp/cmds <<EOF
      x
      host bind 0 /tmp/10M.img
      fatls host 0
      mw 0x1000000 0x0a434241 0x1000 # "ABC\n"
      mw 0x1100000 0x0a464544 0x8000 # "DEF\n"
      fatwrite host 0 0x1000000 file0001.raw 0x1000
      fatwrite host 0 0x1000000 file0002.raw 0x1000
      fatwrite host 0 0x1000000 file0003.raw 0x1000
      fatwrite host 0 0x1000000 file0004.raw 0x1000
      fatwrite host 0 0x1000000 file0005.raw 0x1000
      fatrm host 0 file0002.raw
      fatrm host 0 file0004.raw
      fatls host 0
      fatwrite host 0 0x1100000 file0007.raw 0x4000
      fatwrite host 0 0x1100000 file0007.raw 0x4000
      reset
      EOF
      ./u-boot </tmp/cmds
      #verify
      rm -r /tmp/result /tmp/model
      mkdir /tmp/result
      mkdir /tmp/model
      yes ABC | head -c 4096 >/tmp/model/file0001.raw
      yes ABC | head -c 4096 >/tmp/model/file0003.raw
      yes ABC | head -c 4096 >/tmp/model/file0005.raw
      yes DEF | head -c 16384 >/tmp/model/file0007.raw
      mcopy -n -i /tmp/10M.img ::file0001.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0003.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0005.raw /tmp/result
      mcopy -n -i /tmp/10M.img ::file0007.raw /tmp/result
      hd /tmp/10M.img
      if diff -urq /tmp/model /tmp/result
      then
      	echo Test okay
      else
      	echo Test fail
      fi
      --->8---
      
      Overwritting a discontiguous test file (file0007.raw) no longer causes
      corruption to file0003.raw, which's data lies between the chunks of the
      test file. The amount of data written to disk is still incorrect, what
      causes damage to the file (file0005.raw), which's data lies next to the
      test file. This will be fixed by the next patch.
      
      Feel free to prepare a proper sandbox/py_test based tests based on the
      provided test scripts.
      5e615b74
  3. Feb 06, 2020
  4. Dec 06, 2019
  5. Dec 05, 2019
    • AKASHI Takahiro's avatar
      fs: fat: handle deleted directory entries correctly · 39606d46
      AKASHI Takahiro authored and Tom Rini's avatar Tom Rini committed
      
      Unlink test for FAT file system seems to fail at test_unlink2.
      (When I added this test, I haven't seen any errors though.)
      for example,
      ===8<===
      fs_obj_unlink = ['fat', '/home/akashi/tmp/uboot_sandbox_test/128MB.fat32.img']
      
          def test_unlink2(self, u_boot_console, fs_obj_unlink):
              """
              Test Case 2 - delete many files
              """
              fs_type,fs_img = fs_obj_unlink
              with u_boot_console.log.section('Test Case 2 - unlink (many)'):
                  output = u_boot_console.run_command('host bind 0 %s' % fs_img)
      
                  for i in range(0, 20):
                      output = u_boot_console.run_command_list([
                          '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i),
                          '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)])
                      assert('' == ''.join(output))
      
                  output = u_boot_console.run_command(
                      '%sls host 0:0 dir2' % fs_type)
      >           assert('0 file(s), 2 dir(s)' in output)
      E           AssertionError: assert '0 file(s), 2 dir(s)' in '            ./\r\r\n            ../\r\r\n        0   0123456789abcdef11\r\r\n\r\r\n1 file(s), 2 dir(s)'
      
      test/py/tests/test_fs/test_unlink.py:52: AssertionError
      ===>8===
      
      This can happen when fat_itr_next() wrongly detects an already-
      deleted directory entry.
      
      File deletion, which was added in the commit f8240ce9 ("fs: fat:
      support unlink"), is implemented by marking its entry for a short name
      with DELETED_FLAG, but related entry slots for a long file name are kept
      unmodified. (So entries will never be actually deleted from media.)
      
      To handle this case correctly, an additional check for a directory slot
      will be needed in fat_itr_next().
      
      In addition, I added extra comments about long file name and short file
      name format in FAT file system. Although they are not directly related
      to the issue, I hope it will be helpful for better understandings
      in general.
      
      Signed-off-by: default avatarAKASHI Takahiro <takahiro.akashi@linaro.org>
      39606d46
  6. Dec 02, 2019
  7. Oct 17, 2019
  8. Oct 11, 2019
  9. Aug 26, 2019
  10. Aug 21, 2019
  11. Aug 20, 2019
  12. Aug 18, 2019
  13. Aug 11, 2019
  14. Jul 24, 2019
  15. Jul 18, 2019
  16. Jun 20, 2019
  17. May 28, 2019
  18. May 05, 2019
  19. May 03, 2019
    • Marek Behún's avatar
      fs: btrfs: fix btrfs methods return values on failure · cd22e34c
      Marek Behún authored and Tom Rini's avatar Tom Rini committed
      
      The btrfs implementation methods .ls(), .size() and .read() returns 1 on
      failure, but the command handlers expect values <0 on failure.
      
      For example if given a nonexistent path, the load command currently
      returns success, and hush scripting does not work.
      
      Fix this by setting return values of these methods to -1 instead of 1 on
      failure.
      
      Signed-off-by: default avatarMarek Behún <marek.behun@nic.cz>
      cd22e34c
Loading