Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Consistent times on FAT filesystems over the whole year
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Mon Sep 03, 2007 5:32 pm    Post subject: Consistent times on FAT filesystems over the whole year Reply with quote

Are you living in a timezone with summer time and hate it when FAT filestamps change every half a year?

The reason is that FAT filestamps are by definition local time without specifying which one, and the kernel knows only timezones of the time GMT+x (i.e. he is not able to deal with summer time). Currently, the kernel always assumes that the "local" timezone on all FAT systems corresponds to the timezone GMT+x where "x" is the time difference to GMT in the moment when hwclock --hctosys is called (on gentoo this is usually only the case when /etc/init.d/clock is [re-]started).
Hence, if you use a timezone with summer time, the "x" will be a different value, depending on whether you start your computer in summer or in winter.

As long as there is no FAT mount option to specify the FAT's local time "GMT+x" (or even a userspace filesystem, e.g. based on fuse, which could even allow arbitrary timezones - even those including summer times), there is no real solution to the problem.

However, in a usenet discussion in de.comp.os.unix.linux.misc, an interesting workaround was proposed: To change the timezone temporarily to GMT+x whenever hwclock --hctosys/--systohc is called. This means that the FAT filestamps will be consistent all over the year. (However, be aware that the time actually written on FAT is always winter time, never summer time - but maybe this is better anyway than if filestamps of files copied in summer with cp -p are written in summer time even if their date is in winter).

On gentoo, it is very easy to achieve the suggested setting: Just put the following at the beginning of /etc/conf.d/clock:
Code:
# exporting TZ=GMT+x (or TZ=UTC) only here is a hack which ensures that
# timestamps on FAT partitions under linux are the same all over the year.
# This solution is not perfect, but it is currently the only way to have
# this consistency if you use a TIMEZONE which has e.g. summer and winter
# time, because the current linux kernel implementation of FAT is only able
# to use a GMT+x (i.e. UTC+x) timezone for FAT timestamps.
# Note that not exporting TZ=GMT+x means the same as TZ=${TIMEZONE}
# (after a re-emerge of timezone-data) and that e.g. TZ="Europe/Berlin"
# causes the kernel to consider FAT dates of all files as GMT-1 if
# /etc/init.d/clock is started in winter and as GMT-2 if /etc/init.d/clock
# is started in summer (by the above mentioned kernel restriction
# the timezone is for FAT somehow "translated" into GMT+x for fixed x;
# note that the kernel has a cache so that restarting /etc/init.d/clock
# from a running session might have no immediate effect on FAT filesystems
# already used; remounting these FAT filesystems after an
# /etc/init.d/clock restart might help, but this may depend on the kernel
# version).
#
# The disadvantage of exporting TZ=GMT+x is that the timestamps of
# currently created files on FAT systems are locally in GMT+x which
# differs from the way other operating systems (like Windows) consider
# the timestamps - they consider them as local time. This may cause
# problems when the same FAT filesystem is accessed by different operating
# systems. However, by the above mentioned kernel restriction there is
# no solution for that problem, anyway (with TZ=LOCALTIME="Europe/Berlin"
# files would differ which have been created in the other half of the year).
#
# If you export TZ=GMT+x, a side effect is that if you set the subsequent
# variable CLOCK="local" this means "local to GMT+x" and not
# "local to your TIMEZONE", as would be preferable if you dual boot with
# Windows. So, practically, if you want consistency of FAT timestamps under
# Linux you can run your hardwareclock also only in GMT+x (or in UTC) time
# and not really in local time. Choose your poison:

export TZ=GMT-1

The examples GMT-1/GMT-2 are for Europe/Berlin. For e.g. Europe/London the corresponding values are GMT/GMT-1.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Wed Mar 11, 2009 9:36 pm    Post subject: Reply with quote

To reanimate this thread (it came just up again in the German forum): Essentially the same thing works with baselayout-2/openrc. The only changes are that the filename should now of course be /etc/*.d/hwclock (instead of /etc/*.d/clock), and that the variable CLOCK has been renamed into clock. Here is the correspondingly modified recommended beginning of /etc/conf.d/hwclock:
Code:

# exporting TZ=GMT+x (or TZ=UTC) only here is a hack which ensures that
# timestamps on FAT partitions under linux are the same all over the year.
# This solution is not perfect, but it is currently the only way to have
# this consistency if you use a TIMEZONE which has e.g. summer and winter
# time, because the current linux kernel implementation of FAT is only able
# to use a GMT+x (i.e. UTC+x) timezone for FAT timestamps.
# Note that not exporting TZ=GMT+x means the same as TZ=${TIMEZONE}
# (after a re-emerge of timezone-data) and that e.g. TZ="Europe/Berlin"
# causes the kernel to consider FAT dates of all files as GMT-1 if
# /etc/init.d/hwclock is started in winter and as GMT-2 if /etc/init.d/hwclock
# is started in summer (by the above mentioned kernel restriction
# the timezone is for FAT somehow "translated" into GMT+x for fixed x;
# note that the kernel has a cache so that restarting /etc/init.d/hwclock
# from a running session might have no immediate effect on FAT filesystems
# already used; remounting these FAT filesystems after an
# /etc/init.d/hwclock restart might help, but this may depend on the kernel
# version).
#
# The disadvantage of exporting TZ=GMT+x is that the timestamps of
# currently created files on FAT systems are locally in GMT+x which
# differs from the way other operating systems (like Windows) consider
# the timestamps - they consider them as local time. This may cause
# problems when the same FAT filesystem is accessed by different operating
# systems. However, by the above mentioned kernel restriction there is
# no solution for that problem, anyway (with TZ=LOCALTIME="Europe/Berlin"
# files would differ which have been created in the other half of the year).
#
# If you export TZ=GMT+x, a side effect is that if you set the subsequent
# variable clock="local" this means "local to GMT+x" and not
# "local to your TIMEZONE", as would be preferable if you dual boot with
# Windows. So, practically, if you want consistency of FAT timestamps under
# Linux you can run your hardwareclock also only in GMT+x (or in UTC) time
# and not really in local time. Choose your poison:
export TZ=GMT-1
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum