Advertisements

Archive for January 31st, 2018

VFAT Time Zone Offset Correction

An SJCAM M20 action camera includes the date and time in its file names, but the directory entries appear with the wrong timestamp:

sudo mount -o uid=ed /dev/sdc1 /mnt/part
ll -tr /mnt/part/DCIM/Photo/ | head
total 4.8G
drwxr-xr-x 4 ed root  16K Apr  8  2016 ../
drwxr-xr-x 2 ed root 144K Jan 25 18:52 ./
-rwxr-xr-x 1 ed root 3.8M Jan 26 05:08 2018_0126_100825_001.JPG*
-rwxr-xr-x 1 ed root 3.8M Jan 26 05:08 2018_0126_100830_002.JPG*

I’m in the Eastern US time zone, -5 hr from UTC.

By definition, FAT directory entries contain the “local time” when the file was created / changed. Because it cannot know which “local time” applies, the Linux VFAT filesystem treats the timestamp as UTC and adjusts it by -5 hr.

So the camera writes the directory timestamps properly. When mounted, Linux correctly (for a reasonable definition of correctly) regards them as UTC, knocks off five hours to match this time zone, and displays the result.

Alas, disabling the VFAT timestamp conversion has no effect:

sudo mount -o uid=ed,tz=UTC /dev/sdc1 /mnt/part
ll -tr /mnt/part/DCIM/Photo/ | head
total 4.8G
drwxr-xr-x 4 ed root  16K Apr  8  2016 ../
drwxr-xr-x 2 ed root 144K Jan 25 18:52 ./
-rwxr-xr-x 1 ed root 3.8M Jan 26 05:08 2018_0126_100825_001.JPG*
-rwxr-xr-x 1 ed root 3.8M Jan 26 05:08 2018_0126_100830_002.JPG*

I’m not sure why that doesn’t do anything; it doesn’t generate any error messages.

Although it seems like a reasonable thing, one cannot force a specific time zone with, say, tz=EST or tz=EDT or tz=UTC8 or whatever.

You can specify an offset in minutes:

sudo mount -o uid=ed,time_offset=$((-5*60)) /dev/sdc1 /mnt/part
ll -tr /mnt/part/DCIM/Photo/ | head
total 4.8G
drwxr-xr-x 4 ed root  16K Apr  8  2016 ../
drwxr-xr-x 2 ed root 144K Jan 25 23:52 ./
-rwxr-xr-x 1 ed root 3.8M Jan 26 10:08 2018_0126_100825_001.JPG*
-rwxr-xr-x 1 ed root 3.8M Jan 26 10:08 2018_0126_100830_002.JPG*

The time_offset value is subtracted from the directory timestamp, which means you’re feeding in the actual time offset from UTC, including whatever Daylight Saving Time offset may be in order.

So Linux takes the FAT timestamp, adds (subtracts a negative) 5 hr, and displays the result as my (now correct) local time.

I suppose I could set the camera to UTC, but then the camera’s on-screen and in-video timestamps would be off by four or five hours, depending on the season. So it goes.

Advertisements

7 Comments