Linux copy to fat32 filesystem: invalid argument

4,277

Solution 1

The usual suspects when you want complex copies or renames are GNU cp, zmv from zsh, rsync and pax (or cpio). There's no rename feature in cp, nor (I think) in rsync. While zmv can rename, this doesn't mesh well with recursive copies. But pax can do it:

cd /ext3
pax -rw -s '/[*?:]/_/gp' stuff /fat32/partition

This changes each *?: to _. Warning: minimally tested. If there are collisions, whichever file is copied last wins.

Solution 2

Based on post by Gilles I tested the following list:

#!/bin/sh
touch questionmark?
touch less<
touch less\<
touch more\>
touch backslash\\
touch colon:
touch asterisk\*
touch pipe\|
touch inch\"
touch carret\^
touch comma,
touch semicolon\;
touch plus+
touch equals=
touch lbracket[
touch rbracket]
touch quote\'

I tried to copy that onto Android phone MicroSDHC card with vfat filesystem and refined pax command until everything worked. That may still not be enough for Windows and Unicode:

pax -rw -s '/[?<>\\:*|\"]/_/gp' source dest

You may also want to use the -k option to ensure that there are no overwrites (due to collisions in file names). Both lists I gave in the comment were different from Linux vfat behaviour.

Share:
4,277

Related videos on Youtube

asf
Author by

asf

Updated on September 17, 2022

Comments

  • asf
    asf over 1 year

    After writing the following code, am getting the error as Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)

    FileStream MyFileStream = new FileStream(fileName, FileMode.Open);
    long FileSize;
    FileSize = MyFileStream.Length;
    byte[] Buffer = new byte[] { (((int)(FileSize)) - 1) };
    

    Help me to solve this issue. Thanks.

    Solution: (Thanks to p.s.w.g)

    byte[] Buffer = new byte[FileSize];
    

    Solved the issue. As p.s.w.g suggested I've changed the value to 4096 in order to use the MemoryStream.

    • Karthik
      Karthik almost 11 years
      (((int)(FileSize)) - 1) why would you want to convert this to byte array?
    • Mitch Wheat
      Mitch Wheat almost 11 years
      code makes no sense. Solve by closing!
    • Karthik
      Karthik almost 11 years
      @Dineshkumar explain what you are trying to do
  • mo-seph
    mo-seph over 13 years
    Nice - haven't used pax before. Thanks for putting me on to it.
  • lzap
    lzap over 12 years
    Backslash also makes problems to vfat. Include it in the regexp as well. Thanks!
  • dhill
    dhill about 12 years
    The full list according to support.grouplogic.com/?p=1607 is: / ? < > \ : * | ” ^. Also it cannot end with space or dot and some names are reserved. Mtools manpage gives even bigger list: , ; : ? + * = [ ] < > ' " \ / |
  • asf
    asf almost 11 years
    Thanks for your quick reply. It works...!
  • balu
    balu over 10 years
    And a different note and for people having the same issue as me: pax does not support using -s in combination with the update command -u. I.e. it will always copy renamed files again even if they already exist. It took me hours to find out about that.