Advertisements

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

  1. #1 by david on 2018-01-31 - 14:27

    That’s weird. tz=UTC is supposed to enable the timezone conversions (“this filesystems’s timestamps are in UTC, not local as defined in the spec”). It’s supposed to assume they are local by default. Do you have tz=UTC set in /etc/fstab perchance?

    • #2 by Ed on 2018-01-31 - 14:40

      I’m doing the mounts manually and don’t know of any global options anywhere; mount shows the tz=UTC option only when I specify it.

      I must stand on my head to understand this:

      tz=UTC This option disables the conversion of timestamps between local time (as used by Windows on FAT) and UTC (which Linux uses internally). This is particularly useful when mounting devices (like digital cameras) that are set to UTC in order to avoid the pitfalls of local time.

      So, yeah, it disables the local conversion, which means it should treat whatever’s there differently, but it doesn’t.

      Yet another case of programming as an experimental science …

      • #3 by david on 2018-02-01 - 00:14

        I don’t know where you’re quoting that from but MINE says, much more straightforwardly:

        tz=UTC — Interpret timestamps as UTC rather than local time.
        This option disables the conversion of timestamps
        between local time (as used by Windows on FAT) and UTC
        (which Linux uses internally). This is particularly
        useful when mounting devices (like digital cameras)
        that are set to UTC in order to avoid the pitfalls of
        local time.

        Don’t you just love modern technology?

        • #4 by david on 2018-02-01 - 00:17

          (I think the real question is, how does the camera know what time it is? Is it getting it from GPS, in which case It Knows Where You Are and can mangle the timezone (probably getting it wrong, what with changes to DST dates), or did you set it (and it probably doesn’t know what timezone it’s even in)?

          • #5 by Ed on 2018-02-01 - 18:50

            No GPS on this one; you set the time and it’s off & running. No notion of time zones or even DST, which seems reasonable, given all the hassle of getting those right.

            So, basically, I set it to local time, which it puts on the OSD and uses in the FAT filesystem. I suppose a Windows box would report the “correct” file timestamps, because I’m in the same time zone.

        • #6 by Ed on 2018-02-01 - 18:47

          Looks like a slightly different version of man mount than I have on Ubuntu 16.04, which doesn’t explain any differences.

          Technology: as the lady says, “You gotta love it or live with it.” Something like that, anyhow.

  1. SJCAM M20 vs. Cycliq Fly6 Resolution: License Plates | The Smell of Molten Projects in the Morning