Commit 8e3c6f5d authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] msdos and vfat endianness fixes

Some callers of fat_date_unix2dos() (in msdos/namei.c and vfat/namei.c)
forgot to convert returned host-endian date and time to little-endian.
Since all callers want to get little-endian values, moved the conversion
into function itself.
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f521ddc9
......@@ -745,12 +745,12 @@ int fat_new_dir(struct inode *dir, struct inode *parent, int is_vfat)
memcpy(de[0].name,MSDOS_DOT,MSDOS_NAME);
memcpy(de[1].name,MSDOS_DOTDOT,MSDOS_NAME);
de[0].attr = de[1].attr = ATTR_DIR;
de[0].time = de[1].time = CT_LE_W(time);
de[0].date = de[1].date = CT_LE_W(date);
de[0].time = de[1].time = time;
de[0].date = de[1].date = date;
if (is_vfat) { /* extra timestamps */
de[0].ctime = de[1].ctime = CT_LE_W(time);
de[0].ctime = de[1].ctime = time;
de[0].adate = de[0].cdate =
de[1].adate = de[1].cdate = CT_LE_W(date);
de[1].adate = de[1].cdate = date;
}
de[0].start = CT_LE_W(MSDOS_I(dir)->i_logstart);
de[0].starthi = CT_LE_W(MSDOS_I(dir)->i_logstart>>16);
......
......@@ -1268,14 +1268,10 @@ void fat_write_inode(struct inode *inode, int wait)
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.tv_sec,&raw_entry->time,&raw_entry->date);
raw_entry->time = CT_LE_W(raw_entry->time);
raw_entry->date = CT_LE_W(raw_entry->date);
fat_date_unix2dos(inode->i_mtime.tv_sec, &raw_entry->time, &raw_entry->date);
if (MSDOS_SB(sb)->options.isvfat) {
fat_date_unix2dos(inode->i_ctime.tv_sec,&raw_entry->ctime,&raw_entry->cdate);
raw_entry->ctime_ms = MSDOS_I(inode)->i_ctime_ms; /* use i_ctime.tv_nsec? */
raw_entry->ctime = CT_LE_W(raw_entry->ctime);
raw_entry->cdate = CT_LE_W(raw_entry->cdate);
}
spin_unlock(&fat_inode_lock);
mark_buffer_dirty(bh);
......
......@@ -254,8 +254,8 @@ void fat_date_unix2dos(int unix_date,unsigned short *time,
if (unix_date < 315532800)
unix_date = 315532800;
*time = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
(((unix_date/3600) % 24) << 11);
*time = cpu_to_le16((unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
(((unix_date/3600) % 24) << 11));
day = unix_date/86400-3652;
year = day/365;
if ((year+3)/4+365*year > day) year--;
......@@ -269,7 +269,7 @@ void fat_date_unix2dos(int unix_date,unsigned short *time,
for (month = 0; month < 12; month++)
if (day_n[month] > nl_day) break;
}
*date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9);
*date = cpu_to_le16(nl_day-day_n[month-1]+1+(month << 5)+(year << 9));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment