lkml.org 
[lkml]   [1999]   [Nov]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH] FAT timezones [was Re: updating the RTC automagically]

Hi Riley.

Here's the mount option for msdos/vfat: "tzoff=N" where N == minutes
west of UTC. Being very much a kernel-hacking newbie, I haven't
figured out how to get "-o remount" yet. (This patch, as simple as it
is, took me a lot longer than you'd think....)

The idea is that mount(8) could be enhanced to detect a FAT mount,
parse your "tzoff=PST8PDT" parameter, substitute number of minutes in
and pass it on. Also, mount(8) could use a default "tzoff=" parameter
with the system's or user's current time zone. (I haven't touched
util-linux yet, but it's on my todo list.) Furthermore, when DST comes
and goes, a cron job could remount all the FAT partitions to offset
them by an hour. All the policy in user space....

Alexander, what do you think of this (other than the current lack of
"remount" support)? In my opinion, since FAT does not store absolute
dates, the user who mounts the FS should get to decide on the time zone
for it.

Peter

diff -urN fs/msdos/namei.c~ fs/msdos/namei.c
--- fs/msdos/namei.c~ Tue Aug 31 13:23:03 1999
+++ fs/msdos/namei.c Sat Nov 20 19:48:16 1999
@@ -267,7 +267,7 @@
(*de)->attr |= ATTR_HIDDEN;
(*de)->start = 0;
(*de)->starthi = 0;
- fat_date_unix2dos(dir->i_mtime,&(*de)->time,&(*de)->date);
+ fat_date_unix2dos(sb, dir->i_mtime,&(*de)->time,&(*de)->date);
(*de)->size = 0;
fat_mark_buffer_dirty(sb, *bh, 1);
return 0;
diff -urN fs/fat/inode.c~ fs/fat/inode.c
--- fs/fat/inode.c~ Sun Nov 7 07:25:07 1999
+++ fs/fat/inode.c Sat Nov 20 20:25:01 1999
@@ -33,6 +33,7 @@
#include <asm/uaccess.h>
#include <asm/unaligned.h>

+extern struct timezone sys_tz;
extern struct cvf_format default_cvf, bigblock_cvf;

/* #define FAT_PARANOIA 1 */
@@ -215,6 +216,7 @@
opts->fs_uid = current->uid;
opts->fs_gid = current->gid;
opts->fs_umask = current->fs->umask;
+ opts->tzoff = sys_tz.tz_minuteswest*60 - (sys_tz.tz_dsttime != 0)*3600;
opts->quiet = opts->sys_immutable = opts->dotsOK = opts->showexec = 0;
opts->codepage = 0;
opts->utf8 = 0;
@@ -289,6 +291,13 @@
if (*value) ret = 0;
}
}
+ else if (!strcmp(this_char,"tzoff")) {
+ if (!value || !*value) ret = 0;
+ else {
+ opts->tzoff = simple_strtol(value,&value,0) * 60;
+ if (*value) ret = 0;
+ }
+ }
else if (!strcmp(this_char,"debug")) {
if (value) ret = 0;
else *debug = 1;
@@ -818,10 +827,10 @@
((inode->i_size+inode->i_blksize-1)>>sbi->cluster_bits) *
sbi->cluster_size;
inode->i_mtime = inode->i_atime =
- date_dos2unix(CF_LE_W(de->time),CF_LE_W(de->date));
+ fat_date_dos2unix(sb,CF_LE_W(de->time),CF_LE_W(de->date));
inode->i_ctime =
MSDOS_SB(sb)->options.isvfat
- ? date_dos2unix(CF_LE_W(de->ctime),CF_LE_W(de->cdate))
+ ? fat_date_dos2unix(sb,CF_LE_W(de->ctime),CF_LE_W(de->cdate))
: inode->i_mtime;
MSDOS_I(inode)->i_ctime_ms = de->ctime_ms;
}
@@ -862,11 +871,11 @@
MSDOS_I(inode)->i_attrs;
raw_entry->start = CT_LE_W(MSDOS_I(inode)->i_logstart);
raw_entry->starthi = CT_LE_W(MSDOS_I(inode)->i_logstart >> 16);
- fat_date_unix2dos(inode->i_mtime,&raw_entry->time,&raw_entry->date);
+ fat_date_unix2dos(sb,inode->i_mtime,&raw_entry->time,&raw_entry->date);
raw_entry->time = CT_LE_W(raw_entry->time);
raw_entry->date = CT_LE_W(raw_entry->date);
if (MSDOS_SB(sb)->options.isvfat) {
- fat_date_unix2dos(inode->i_ctime,&raw_entry->ctime,&raw_entry->cdate);
+ fat_date_unix2dos(sb,inode->i_ctime,&raw_entry->ctime,&raw_entry->cdate);
raw_entry->ctime_ms = MSDOS_I(inode)->i_ctime_ms;
raw_entry->ctime = CT_LE_W(raw_entry->ctime);
raw_entry->cdate = CT_LE_W(raw_entry->cdate);
diff -urN fs/fat/misc.c~ fs/fat/misc.c
--- fs/fat/misc.c~ Mon Aug 30 12:23:14 1999
+++ fs/fat/misc.c Sat Nov 20 20:38:44 1999
@@ -322,12 +322,9 @@
/* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */


-extern struct timezone sys_tz;
-
-
/* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */

-int date_dos2unix(unsigned short time,unsigned short date)
+int fat_date_dos2unix(struct super_block *sb, unsigned short time, unsigned short date)
{
int month,year,secs;

@@ -337,21 +334,19 @@
((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 &&
month < 2 ? 1 : 0)+3653);
/* days since 1.1.70 plus 80's leap day */
- secs += sys_tz.tz_minuteswest*60;
- if (sys_tz.tz_dsttime) secs -= 3600;
+ secs += sb->u.msdos_sb.options.tzoff;
return secs;
}


/* Convert linear UNIX date to a MS-DOS time/date pair. */

-void fat_date_unix2dos(int unix_date,unsigned short *time,
- unsigned short *date)
+void fat_date_unix2dos(struct super_block *sb, int unix_date,
+ unsigned short *time, unsigned short *date)
{
int day,year,nl_day,month;

- unix_date -= sys_tz.tz_minuteswest*60;
- if (sys_tz.tz_dsttime) unix_date += 3600;
+ unix_date -= sb->u.msdos_sb.options.tzoff;

*time = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
(((unix_date/3600) % 24) << 11);
diff -urN fs/fat/dir.c~ fs/fat/dir.c
--- fs/fat/dir.c~ Mon Aug 9 13:43:49 1999
+++ fs/fat/dir.c Sat Nov 20 20:07:48 1999
@@ -638,7 +638,7 @@

if ((bh = fat_extend_dir(dir)) == NULL) return -ENOSPC;
/* zeroed out, so... */
- fat_date_unix2dos(dir->i_mtime,&time,&date);
+ fat_date_unix2dos(sb,dir->i_mtime,&time,&date);
de = (struct msdos_dir_entry*)&bh->b_data[0];
memcpy(de[0].name,MSDOS_DOT,MSDOS_NAME);
memcpy(de[1].name,MSDOS_DOTDOT,MSDOS_NAME);
diff -urN fs/vfat/namei.c~ fs/vfat/namei.c
--- fs/vfat/namei.c~ Mon Aug 9 13:43:49 1999
+++ fs/vfat/namei.c Sat Nov 20 19:48:02 1999
@@ -850,7 +850,7 @@
dir->i_ctime = dir->i_mtime = dir->i_atime = CURRENT_TIME;
mark_inode_dirty(dir);

- fat_date_unix2dos(dir->i_mtime,&(*de)->time,&(*de)->date);
+ fat_date_unix2dos(sb, dir->i_mtime,&(*de)->time,&(*de)->date);
(*de)->ctime_ms = 0;
(*de)->ctime = (*de)->time;
(*de)->adate = (*de)->cdate = (*de)->date;
diff -urN include/linux/msdos_fs.h~ include/linux/msdos_fs.h
--- include/linux/msdos_fs.h~ Sat Nov 13 02:48:51 1999
+++ include/linux/msdos_fs.h Sat Nov 20 20:03:14 1999
@@ -197,11 +197,11 @@
extern void unlock_fat(struct super_block *sb);
extern int fat_add_cluster(struct inode *inode);
extern struct buffer_head *fat_extend_dir(struct inode *inode);
-extern int date_dos2unix(__u16 time, __u16 date);
+extern int fat_date_dos2unix(struct super_block *sb, __u16 time, __u16 date);
extern void fat_fs_panic(struct super_block *s,const char *msg);
extern void fat_lock_creation(void);
extern void fat_unlock_creation(void);
-extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
+extern void fat_date_unix2dos(struct super_block *sb, int unix_date,__u16 *time, __u16 *date);
extern int fat__get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
struct msdos_dir_entry **de,int *ino);
static __inline__ int fat_get_entry(struct inode *dir,loff_t *pos,
diff -urN include/linux/msdos_fs_sb.h~ include/linux/msdos_fs_sb.h
--- include/linux/msdos_fs_sb.h~ Sun Nov 7 07:25:09 1999
+++ include/linux/msdos_fs_sb.h Sat Nov 20 19:59:16 1999
@@ -14,6 +14,7 @@
char *iocharset; /* Charset used for filename input/display */
unsigned char name_check; /* r = relaxed, n = normal, s = strict */
unsigned char conversion; /* b = binary, t = text, a = auto */
+ short tzoff; /* seconds west of UTC */
unsigned quiet:1, /* set = fake successful chmods and chowns */
showexec:1, /* set = only set x bit for com/exe/bat */
sys_immutable:1, /* set = system files are immutable */
diff -urN kernel/ksyms.c~ kernel/ksyms.c
--- kernel/ksyms.c~ Sun Nov 7 07:25:09 1999
+++ kernel/ksyms.c Sat Nov 20 20:39:30 1999
@@ -362,6 +362,7 @@
EXPORT_SYMBOL(cdevname);
EXPORT_SYMBOL(partition_name); /* md.c only */
EXPORT_SYMBOL(simple_strtoul);
+EXPORT_SYMBOL(simple_strtol);
EXPORT_SYMBOL(system_utsname); /* UTS data */
EXPORT_SYMBOL(uts_sem); /* UTS semaphore */
EXPORT_SYMBOL(sys_call_table);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.069 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site