Linux copy to fat32 filesystem: invalid argument
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.
Related videos on Youtube
asf
Updated on September 17, 2022Comments
-
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 almost 11 years(((int)(FileSize)) - 1) why would you want to convert this to byte array?
-
Mitch Wheat almost 11 yearscode makes no sense. Solve by closing!
-
Karthik almost 11 years@Dineshkumar explain what you are trying to do
-
-
mo-seph over 13 yearsNice - haven't used pax before. Thanks for putting me on to it.
-
lzap over 12 yearsBackslash also makes problems to vfat. Include it in the regexp as well. Thanks!
-
dhill about 12 yearsThe 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 almost 11 yearsThanks for your quick reply. It works...!
-
balu over 10 yearsAnd 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.