Commit 7879398b authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] ncpfs (2/7): date handling cleanup

trivial cleanup: endianness conversions pulled into ncp_date_dos2unix() and
ncp_date_unix2dos() from their callers.
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c3d28db7
......@@ -395,8 +395,7 @@ static time_t ncp_obtain_mtime(struct dentry *dentry)
if (ncp_obtain_info(server, inode, NULL, &i))
return 0;
return ncp_date_dos2unix(le16_to_cpu(i.modifyTime),
le16_to_cpu(i.modifyDate));
return ncp_date_dos2unix(i.modifyTime, i.modifyDate);
}
static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir)
......@@ -1213,8 +1212,9 @@ static int local2utc(int time)
/* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70). */
int
ncp_date_dos2unix(unsigned short time, unsigned short date)
ncp_date_dos2unix(__le16 t, __le16 d)
{
unsigned short time = le16_to_cpu(t), date = le16_to_cpu(d);
int month, year, secs;
/* first subtract and mask after that... Otherwise, if
......@@ -1231,13 +1231,14 @@ ncp_date_dos2unix(unsigned short time, unsigned short date)
/* Convert linear UNIX date to a MS-DOS time/date pair. */
void
ncp_date_unix2dos(int unix_date, unsigned short *time, unsigned short *date)
ncp_date_unix2dos(int unix_date, __le16 *time, __le16 *date)
{
int day, year, nl_day, month;
unix_date = utc2local(unix_date);
*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)
......@@ -1252,5 +1253,5 @@ ncp_date_unix2dos(int unix_date, unsigned short *time, unsigned short *date)
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));
}
......@@ -142,12 +142,9 @@ static void ncp_update_dates(struct inode *inode, struct nw_info_struct *nwi)
inode->i_blocks = (inode->i_size + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;
inode->i_mtime.tv_sec = ncp_date_dos2unix(le16_to_cpu(nwi->modifyTime),
le16_to_cpu(nwi->modifyDate));
inode->i_ctime.tv_sec = ncp_date_dos2unix(le16_to_cpu(nwi->creationTime),
le16_to_cpu(nwi->creationDate));
inode->i_atime.tv_sec = ncp_date_dos2unix(0,
le16_to_cpu(nwi->lastAccessDate));
inode->i_mtime.tv_sec = ncp_date_dos2unix(nwi->modifyTime, nwi->modifyDate);
inode->i_ctime.tv_sec = ncp_date_dos2unix(nwi->creationTime, nwi->creationDate);
inode->i_atime.tv_sec = ncp_date_dos2unix(0, nwi->lastAccessDate);
inode->i_atime.tv_nsec = 0;
inode->i_mtime.tv_nsec = 0;
inode->i_ctime.tv_nsec = 0;
......@@ -918,23 +915,18 @@ int ncp_notify_change(struct dentry *dentry, struct iattr *attr)
if ((attr->ia_valid & ATTR_CTIME) != 0) {
info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);
ncp_date_unix2dos(attr->ia_ctime.tv_sec,
&(info.creationTime), &(info.creationDate));
info.creationTime = le16_to_cpu(info.creationTime);
info.creationDate = le16_to_cpu(info.creationDate);
&info.creationTime, &info.creationDate);
}
if ((attr->ia_valid & ATTR_MTIME) != 0) {
info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
ncp_date_unix2dos(attr->ia_mtime.tv_sec,
&(info.modifyTime), &(info.modifyDate));
info.modifyTime = le16_to_cpu(info.modifyTime);
info.modifyDate = le16_to_cpu(info.modifyDate);
&info.modifyTime, &info.modifyDate);
}
if ((attr->ia_valid & ATTR_ATIME) != 0) {
__u16 dummy;
__le16 dummy;
info_mask |= (DM_LAST_ACCESS_DATE);
ncp_date_unix2dos(attr->ia_atime.tv_sec,
&(dummy), &(info.lastAccessDate));
info.lastAccessDate = le16_to_cpu(info.lastAccessDate);
&dummy, &info.lastAccessDate);
}
if (info_mask != 0) {
result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
......
......@@ -239,8 +239,8 @@ void ncp_update_inode2(struct inode *, struct ncp_entry_info *);
extern struct inode_operations ncp_dir_inode_operations;
extern struct file_operations ncp_dir_operations;
int ncp_conn_logged_in(struct super_block *);
int ncp_date_dos2unix(__u16 time, __u16 date);
void ncp_date_unix2dos(int unix_date, __u16 * time, __u16 * date);
int ncp_date_dos2unix(__le16 time, __le16 date);
void ncp_date_unix2dos(int unix_date, __le16 * time, __le16 * date);
/* linux/fs/ncpfs/ioctl.c */
int ncp_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
......
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