Thursday, September 20, 2007

Preserving time stamps on FAT32 copies

Strange thing about accessing FAT32 in Linux is that you get annoying warnings when manipulating the date and times of files. cp, tar and mv all raise wierd errors when doing the most basic things.

I especially needed to move some photos to my FAT32 mount, with the specific intention of retaining the file creation date and times. The correct command is "cp -p" where the "-p" flag means "preserve".

So we try:

$ cp -rp ../../cdrom/070915 .
cp: preserving times for `./070915/070915_P1250210.JPG': Operation not permitted
cp: preserving times for `./070915/070915_P1250211.JPG': Operation not permitted
$ ls -la 070915/
total 5344
drwxrwx--- 2 root plugdev 32768 2007-09-20 17:47 ./
drwxrwx--- 34 root plugdev 32768 2007-09-20 17:47 ../
-rwxrwx--- 1 root plugdev 593386 2007-09-20 17:47 070915_P1250210.JPG*
-rwxrwx--- 1 root plugdev 596410 2007-09-20 17:47 070915_P1250211.JPG*

The problem here is that the file creation date should be sometime on the 15th of September. NOT today. Did a google, and it brought me to this nugget of information:

This forum post:
if your own user id does not match the 'virtual' user-id, cp can not change the file date back to file date the source file.

The solution is clear - find out your user id (XXX), mount the partition with uid=XXX, and all the files on that partition belong to you - even the newly created ones. This way cp -a can set the original file date.

This works, of course, only for ONE user (and root).
So I changed the /etc/fstab file. Im quite disturbed by the new UUID usage instead of the ole fashioned /dev/hda access:

# Entry for /dev/sda5 :
UUID=41BD-AB60 /media/M vfat defaults,gid=users,utf8,umask=007 0 1

to

UUID=41BD-AB60 /media/M vfat defaults,uid=1000,gid=users,utf8,umask=002 0 0

Please note the changes in bold. A quick remount:

# umount /media/M
# mount -a

and copy:

# cp -rp ../../cdrom/070915 M/Photos/

Gives us:

# ls -la M/Photos/070915/070915_P1250210.JPG
-r-xr-xr-x 1 yky users 593386 2007-09-15 09:47 M/Photos/070915/070915_P1250210.JPG*

woohoo!

yk.

1 lewser:

Anonymous said...

Thank you very much. I've been searching how to solve this problem for a long time !! :)

Regards. ryke