DriverDev-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 1/4] staging: exfat: drop unused function parameter
@ 2019-09-08 17:35 Valentin Vidic
  2019-09-08 17:35 ` [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct Valentin Vidic
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Valentin Vidic @ 2019-09-08 17:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Valentin Vidic, Valdis Kletnieks, linux-kernel

sbi parameter not used inside the function so remove it.
Also cleanup unused variables generated by this change.

Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
---
v2: split up into multiple patches
v3: split up some more
    fix if statement braces
    add utc offset fields

 drivers/staging/exfat/exfat_super.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/exfat/exfat_super.c b/drivers/staging/exfat/exfat_super.c
index 60dfea73a7a4..3a58907caf7c 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -56,8 +56,7 @@ static void exfat_write_super(struct super_block *sb);
 #define UNIX_SECS_2108    4354819200L
 
 /* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
-static void exfat_time_fat2unix(struct exfat_sb_info *sbi,
-				struct timespec64 *ts, struct date_time_t *tp)
+static void exfat_time_fat2unix(struct timespec64 *ts, struct date_time_t *tp)
 {
 	ts->tv_sec = mktime64(tp->Year + 1980, tp->Month + 1, tp->Day,
 			      tp->Hour, tp->Minute, tp->Second);
@@ -66,8 +65,7 @@ static void exfat_time_fat2unix(struct exfat_sb_info *sbi,
 }
 
 /* Convert linear UNIX date to a FAT time/date pair. */
-static void exfat_time_unix2fat(struct exfat_sb_info *sbi,
-				struct timespec64 *ts, struct date_time_t *tp)
+static void exfat_time_unix2fat(struct timespec64 *ts, struct date_time_t *tp)
 {
 	time64_t second = ts->tv_sec;
 	struct tm tm;
@@ -3349,9 +3347,9 @@ static int exfat_fill_inode(struct inode *inode, struct file_id_t *fid)
 	inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1))
 				& ~((loff_t)p_fs->cluster_size - 1)) >> 9;
 
-	exfat_time_fat2unix(sbi, &inode->i_mtime, &info.ModifyTimestamp);
-	exfat_time_fat2unix(sbi, &inode->i_ctime, &info.CreateTimestamp);
-	exfat_time_fat2unix(sbi, &inode->i_atime, &info.AccessTimestamp);
+	exfat_time_fat2unix(&inode->i_mtime, &info.ModifyTimestamp);
+	exfat_time_fat2unix(&inode->i_ctime, &info.CreateTimestamp);
+	exfat_time_fat2unix(&inode->i_atime, &info.AccessTimestamp);
 
 	return 0;
 }
@@ -3412,8 +3410,6 @@ static void exfat_destroy_inode(struct inode *inode)
 
 static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
 {
-	struct super_block *sb = inode->i_sb;
-	struct exfat_sb_info *sbi = EXFAT_SB(sb);
 	struct dir_entry_t info;
 
 	if (inode->i_ino == EXFAT_ROOT_INO)
@@ -3422,9 +3418,9 @@ static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
 	info.Attr = exfat_make_attr(inode);
 	info.Size = i_size_read(inode);
 
-	exfat_time_unix2fat(sbi, &inode->i_mtime, &info.ModifyTimestamp);
-	exfat_time_unix2fat(sbi, &inode->i_ctime, &info.CreateTimestamp);
-	exfat_time_unix2fat(sbi, &inode->i_atime, &info.AccessTimestamp);
+	exfat_time_unix2fat(&inode->i_mtime, &info.ModifyTimestamp);
+	exfat_time_unix2fat(&inode->i_ctime, &info.CreateTimestamp);
+	exfat_time_unix2fat(&inode->i_atime, &info.AccessTimestamp);
 
 	ffsWriteStat(inode, &info);
 
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct
  2019-09-08 17:35 [PATCH v3 1/4] staging: exfat: drop unused function parameter Valentin Vidic
@ 2019-09-08 17:35 ` Valentin Vidic
  2019-09-08 18:50   ` Greg Kroah-Hartman
  2019-09-08 18:54   ` Greg Kroah-Hartman
  2019-09-08 17:35 ` [PATCH v3 3/4] staging: exfat: drop unused field access_time_ms Valentin Vidic
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Valentin Vidic @ 2019-09-08 17:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Valentin Vidic, Valdis Kletnieks, linux-kernel

Use timestamp_t for everything and cleanup duplicate code.

Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
---
 drivers/staging/exfat/exfat.h       |  35 +++---
 drivers/staging/exfat/exfat_super.c | 158 ++++++++--------------------
 2 files changed, 55 insertions(+), 138 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 0aa14dea4e09..58e1e889779f 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -241,16 +241,6 @@ static inline u16 get_row_index(u16 i)
 #define UNI_PAR_DIR_NAME        "\0.\0."
 #endif
 
-struct date_time_t {
-	u16      Year;
-	u16      Month;
-	u16      Day;
-	u16      Hour;
-	u16      Minute;
-	u16      Second;
-	u16      MilliSecond;
-};
-
 struct part_info_t {
 	u32      Offset;    /* start sector number of the partition */
 	u32      Size;      /* in sectors */
@@ -289,6 +279,16 @@ struct file_id_t {
 	u32      hint_last_clu;
 };
 
+struct timestamp_t {
+	u16      millisec;   /* 0 ~ 999              */
+	u16      sec;        /* 0 ~ 59               */
+	u16      min;        /* 0 ~ 59               */
+	u16      hour;       /* 0 ~ 23               */
+	u16      day;        /* 1 ~ 31               */
+	u16      mon;        /* 1 ~ 12               */
+	u16      year;       /* 0 ~ 127 (since 1980) */
+};
+
 struct dir_entry_t {
 	char Name[MAX_NAME_LENGTH * MAX_CHARSET_SIZE];
 
@@ -298,18 +298,9 @@ struct dir_entry_t {
 	u32 Attr;
 	u64 Size;
 	u32 NumSubdirs;
-	struct date_time_t CreateTimestamp;
-	struct date_time_t ModifyTimestamp;
-	struct date_time_t AccessTimestamp;
-};
-
-struct timestamp_t {
-	u16      sec;        /* 0 ~ 59               */
-	u16      min;        /* 0 ~ 59               */
-	u16      hour;       /* 0 ~ 23               */
-	u16      day;        /* 1 ~ 31               */
-	u16      mon;        /* 1 ~ 12               */
-	u16      year;       /* 0 ~ 127 (since 1980) */
+	struct timestamp_t CreateTimestamp;
+	struct timestamp_t ModifyTimestamp;
+	struct timestamp_t AccessTimestamp;
 };
 
 /* MS_DOS FAT partition boot record (512 bytes) */
diff --git a/drivers/staging/exfat/exfat_super.c b/drivers/staging/exfat/exfat_super.c
index 3a58907caf7c..54b6c2ff3c96 100644
--- a/drivers/staging/exfat/exfat_super.c
+++ b/drivers/staging/exfat/exfat_super.c
@@ -56,16 +56,16 @@ static void exfat_write_super(struct super_block *sb);
 #define UNIX_SECS_2108    4354819200L
 
 /* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */
-static void exfat_time_fat2unix(struct timespec64 *ts, struct date_time_t *tp)
+static void exfat_time_fat2unix(struct timespec64 *ts, struct timestamp_t *tp)
 {
-	ts->tv_sec = mktime64(tp->Year + 1980, tp->Month + 1, tp->Day,
-			      tp->Hour, tp->Minute, tp->Second);
+	ts->tv_sec = mktime64(tp->year + 1980, tp->mon + 1, tp->day,
+			      tp->hour, tp->min, tp->sec);
 
-	ts->tv_nsec = tp->MilliSecond * NSEC_PER_MSEC;
+	ts->tv_nsec = tp->millisec * NSEC_PER_MSEC;
 }
 
 /* Convert linear UNIX date to a FAT time/date pair. */
-static void exfat_time_unix2fat(struct timespec64 *ts, struct date_time_t *tp)
+static void exfat_time_unix2fat(struct timespec64 *ts, struct timestamp_t *tp)
 {
 	time64_t second = ts->tv_sec;
 	struct tm tm;
@@ -73,69 +73,42 @@ static void exfat_time_unix2fat(struct timespec64 *ts, struct date_time_t *tp)
 	time64_to_tm(second, 0, &tm);
 
 	if (second < UNIX_SECS_1980) {
-		tp->MilliSecond = 0;
-		tp->Second	= 0;
-		tp->Minute	= 0;
-		tp->Hour	= 0;
-		tp->Day		= 1;
-		tp->Month	= 1;
-		tp->Year	= 0;
+		tp->millisec	= 0;
+		tp->sec		= 0;
+		tp->min		= 0;
+		tp->hour	= 0;
+		tp->day		= 1;
+		tp->mon		= 1;
+		tp->year	= 0;
 		return;
 	}
 
 	if (second >= UNIX_SECS_2108) {
-		tp->MilliSecond = 999;
-		tp->Second	= 59;
-		tp->Minute	= 59;
-		tp->Hour	= 23;
-		tp->Day		= 31;
-		tp->Month	= 12;
-		tp->Year	= 127;
+		tp->millisec	= 999;
+		tp->sec		= 59;
+		tp->min		= 59;
+		tp->hour	= 23;
+		tp->day		= 31;
+		tp->mon		= 12;
+		tp->year	= 127;
 		return;
 	}
 
-	tp->MilliSecond = ts->tv_nsec / NSEC_PER_MSEC;
-	tp->Second	= tm.tm_sec;
-	tp->Minute	= tm.tm_min;
-	tp->Hour	= tm.tm_hour;
-	tp->Day		= tm.tm_mday;
-	tp->Month	= tm.tm_mon + 1;
-	tp->Year	= tm.tm_year + 1900 - 1980;
+	tp->millisec	= ts->tv_nsec / NSEC_PER_MSEC;
+	tp->sec		= tm.tm_sec;
+	tp->min		= tm.tm_min;
+	tp->hour	= tm.tm_hour;
+	tp->day		= tm.tm_mday;
+	tp->mon		= tm.tm_mon + 1;
+	tp->year	= tm.tm_year + 1900 - 1980;
 }
 
 struct timestamp_t *tm_current(struct timestamp_t *tp)
 {
-	time64_t second = ktime_get_real_seconds();
-	struct tm tm;
-
-	time64_to_tm(second, 0, &tm);
-
-	if (second < UNIX_SECS_1980) {
-		tp->sec  = 0;
-		tp->min  = 0;
-		tp->hour = 0;
-		tp->day  = 1;
-		tp->mon  = 1;
-		tp->year = 0;
-		return tp;
-	}
+	struct timespec64 ts;
 
-	if (second >= UNIX_SECS_2108) {
-		tp->sec  = 59;
-		tp->min  = 59;
-		tp->hour = 23;
-		tp->day  = 31;
-		tp->mon  = 12;
-		tp->year = 127;
-		return tp;
-	}
-
-	tp->sec  = tm.tm_sec;
-	tp->min  = tm.tm_min;
-	tp->hour = tm.tm_hour;
-	tp->day  = tm.tm_mday;
-	tp->mon  = tm.tm_mon + 1;
-	tp->year = tm.tm_year + 1900 - 1980;
+	ktime_get_real_ts64(&ts);
+	exfat_time_unix2fat(&ts, tp);
 
 	return tp;
 }
@@ -1500,7 +1473,6 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
 	int ret = FFS_SUCCESS;
 	struct chain_t dir;
 	struct uni_name_t uni_name;
-	struct timestamp_t tm;
 	struct dentry_t *ep, *ep2;
 	struct super_block *sb = inode->i_sb;
 	struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
@@ -1518,11 +1490,11 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
 		    (fid->entry == -1)) {
 			info->Attr = ATTR_SUBDIR;
 			memset((char *)&info->CreateTimestamp, 0,
-			       sizeof(struct date_time_t));
+			       sizeof(struct timestamp_t));
 			memset((char *)&info->ModifyTimestamp, 0,
-			       sizeof(struct date_time_t));
+			       sizeof(struct timestamp_t));
 			memset((char *)&info->AccessTimestamp, 0,
-			       sizeof(struct date_time_t));
+			       sizeof(struct timestamp_t));
 			strcpy(info->ShortName, ".");
 			strcpy(info->Name, ".");
 
@@ -1573,25 +1545,9 @@ static int ffsReadStat(struct inode *inode, struct dir_entry_t *info)
 	/* set FILE_INFO structure using the acquired struct dentry_t */
 	info->Attr = p_fs->fs_func->get_entry_attr(ep);
 
-	p_fs->fs_func->get_entry_time(ep, &tm, TM_CREATE);
-	info->CreateTimestamp.Year = tm.year;
-	info->CreateTimestamp.Month = tm.mon;
-	info->CreateTimestamp.Day = tm.day;
-	info->CreateTimestamp.Hour = tm.hour;
-	info->CreateTimestamp.Minute = tm.min;
-	info->CreateTimestamp.Second = tm.sec;
-	info->CreateTimestamp.MilliSecond = 0;
-
-	p_fs->fs_func->get_entry_time(ep, &tm, TM_MODIFY);
-	info->ModifyTimestamp.Year = tm.year;
-	info->ModifyTimestamp.Month = tm.mon;
-	info->ModifyTimestamp.Day = tm.day;
-	info->ModifyTimestamp.Hour = tm.hour;
-	info->ModifyTimestamp.Minute = tm.min;
-	info->ModifyTimestamp.Second = tm.sec;
-	info->ModifyTimestamp.MilliSecond = 0;
-
-	memset((char *) &info->AccessTimestamp, 0, sizeof(struct date_time_t));
+	p_fs->fs_func->get_entry_time(ep, &info->CreateTimestamp, TM_CREATE);
+	p_fs->fs_func->get_entry_time(ep, &info->ModifyTimestamp, TM_MODIFY);
+	memset((char *)&info->AccessTimestamp, 0, sizeof(struct timestamp_t));
 
 	*(uni_name.name) = 0x0;
 	/* XXX this is very bad for exfat cuz name is already included in es.
@@ -1650,7 +1606,6 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
 {
 	sector_t sector = 0;
 	int ret = FFS_SUCCESS;
-	struct timestamp_t tm;
 	struct dentry_t *ep, *ep2;
 	struct entry_set_cache_t *es = NULL;
 	struct super_block *sb = inode->i_sb;
@@ -1697,22 +1652,8 @@ static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info)
 	p_fs->fs_func->set_entry_attr(ep, info->Attr);
 
 	/* set FILE_INFO structure using the acquired struct dentry_t */
-	tm.sec  = info->CreateTimestamp.Second;
-	tm.min  = info->CreateTimestamp.Minute;
-	tm.hour = info->CreateTimestamp.Hour;
-	tm.day  = info->CreateTimestamp.Day;
-	tm.mon  = info->CreateTimestamp.Month;
-	tm.year = info->CreateTimestamp.Year;
-	p_fs->fs_func->set_entry_time(ep, &tm, TM_CREATE);
-
-	tm.sec  = info->ModifyTimestamp.Second;
-	tm.min  = info->ModifyTimestamp.Minute;
-	tm.hour = info->ModifyTimestamp.Hour;
-	tm.day  = info->ModifyTimestamp.Day;
-	tm.mon  = info->ModifyTimestamp.Month;
-	tm.year = info->ModifyTimestamp.Year;
-	p_fs->fs_func->set_entry_time(ep, &tm, TM_MODIFY);
-
+	p_fs->fs_func->set_entry_time(ep, &info->CreateTimestamp, TM_CREATE);
+	p_fs->fs_func->set_entry_time(ep, &info->ModifyTimestamp, TM_MODIFY);
 	p_fs->fs_func->set_entry_size(ep2, info->Size);
 
 	if (p_fs->vol_type != EXFAT) {
@@ -1939,7 +1880,6 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
 	sector_t sector;
 	struct chain_t dir, clu;
 	struct uni_name_t uni_name;
-	struct timestamp_t tm;
 	struct dentry_t *ep;
 	struct super_block *sb = inode->i_sb;
 	struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info);
@@ -2036,26 +1976,12 @@ static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry)
 			buf_lock(sb, sector);
 			dir_entry->Attr = fs_func->get_entry_attr(ep);
 
-			fs_func->get_entry_time(ep, &tm, TM_CREATE);
-			dir_entry->CreateTimestamp.Year = tm.year;
-			dir_entry->CreateTimestamp.Month = tm.mon;
-			dir_entry->CreateTimestamp.Day = tm.day;
-			dir_entry->CreateTimestamp.Hour = tm.hour;
-			dir_entry->CreateTimestamp.Minute = tm.min;
-			dir_entry->CreateTimestamp.Second = tm.sec;
-			dir_entry->CreateTimestamp.MilliSecond = 0;
-
-			fs_func->get_entry_time(ep, &tm, TM_MODIFY);
-			dir_entry->ModifyTimestamp.Year = tm.year;
-			dir_entry->ModifyTimestamp.Month = tm.mon;
-			dir_entry->ModifyTimestamp.Day = tm.day;
-			dir_entry->ModifyTimestamp.Hour = tm.hour;
-			dir_entry->ModifyTimestamp.Minute = tm.min;
-			dir_entry->ModifyTimestamp.Second = tm.sec;
-			dir_entry->ModifyTimestamp.MilliSecond = 0;
-
+			fs_func->get_entry_time(ep, &dir_entry->CreateTimestamp,
+						TM_CREATE);
+			fs_func->get_entry_time(ep, &dir_entry->ModifyTimestamp,
+						TM_MODIFY);
 			memset((char *)&dir_entry->AccessTimestamp, 0,
-			       sizeof(struct date_time_t));
+			       sizeof(struct timestamp_t));
 
 			*(uni_name.name) = 0x0;
 			fs_func->get_uni_name_from_ext_entry(sb, &dir, dentry,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 3/4] staging: exfat: drop unused field access_time_ms
  2019-09-08 17:35 [PATCH v3 1/4] staging: exfat: drop unused function parameter Valentin Vidic
  2019-09-08 17:35 ` [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct Valentin Vidic
@ 2019-09-08 17:35 ` Valentin Vidic
  2019-09-08 17:35 ` [PATCH v3 4/4] staging: exfat: add millisecond support Valentin Vidic
  2019-09-09  0:28 ` [PATCH v3 1/4] staging: exfat: drop unused function parameter Valdis Klētnieks
  3 siblings, 0 replies; 9+ messages in thread
From: Valentin Vidic @ 2019-09-08 17:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Valentin Vidic, Valdis Kletnieks, linux-kernel

Spec defines that UtcOffset fields should start in this
position instead.

Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
---
 drivers/staging/exfat/exfat.h      | 6 ++++--
 drivers/staging/exfat/exfat_core.c | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
index 58e1e889779f..9b75c5d3f072 100644
--- a/drivers/staging/exfat/exfat.h
+++ b/drivers/staging/exfat/exfat.h
@@ -444,8 +444,10 @@ struct file_dentry_t {
 	u8       access_date[2];
 	u8       create_time_ms;
 	u8       modify_time_ms;
-	u8       access_time_ms;
-	u8       reserved2[9];
+	u8       create_utc_offset;
+	u8       modify_utc_offset;
+	u8       access_utc_offset;
+	u8       reserved2[7];
 };
 
 /* MS-DOS EXFAT stream extension directory entry (32 bytes) */
diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
index 995358cc7c79..d21f68d786b8 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1456,7 +1456,9 @@ void init_file_entry(struct file_dentry_t *ep, u32 type)
 	exfat_set_entry_time((struct dentry_t *)ep, tp, TM_ACCESS);
 	ep->create_time_ms = 0;
 	ep->modify_time_ms = 0;
-	ep->access_time_ms = 0;
+	ep->create_utc_offset = 0;
+	ep->modify_utc_offset = 0;
+	ep->access_utc_offset = 0;
 }
 
 void init_strm_entry(struct strm_dentry_t *ep, u8 flags, u32 start_clu, u64 size)
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 4/4] staging: exfat: add millisecond support
  2019-09-08 17:35 [PATCH v3 1/4] staging: exfat: drop unused function parameter Valentin Vidic
  2019-09-08 17:35 ` [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct Valentin Vidic
  2019-09-08 17:35 ` [PATCH v3 3/4] staging: exfat: drop unused field access_time_ms Valentin Vidic
@ 2019-09-08 17:35 ` Valentin Vidic
  2019-09-09  0:28 ` [PATCH v3 1/4] staging: exfat: drop unused function parameter Valdis Klētnieks
  3 siblings, 0 replies; 9+ messages in thread
From: Valentin Vidic @ 2019-09-08 17:35 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Valentin Vidic, Valdis Kletnieks, linux-kernel

Use create_time_ms and modify_time_ms fields to store the millisecond
part of the file timestamp with the precision of 10 ms.

Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
---
 drivers/staging/exfat/exfat_core.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
index d21f68d786b8..d6e33a485d5f 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -1139,6 +1139,7 @@ void exfat_set_entry_size(struct dentry_t *p_entry, u64 size)
 void fat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 			u8 mode)
 {
+	u8 ms = 0;
 	u16 t = 0x00, d = 0x21;
 	struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
 
@@ -1146,6 +1147,7 @@ void fat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 	case TM_CREATE:
 		t = GET16_A(ep->create_time);
 		d = GET16_A(ep->create_date);
+		ms = ep->create_time_ms * 10;
 		break;
 	case TM_MODIFY:
 		t = GET16_A(ep->modify_time);
@@ -1159,11 +1161,17 @@ void fat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 	tp->day  = (d & 0x001F);
 	tp->mon  = (d >> 5) & 0x000F;
 	tp->year = (d >> 9);
+
+	if (ms >= 1000) {
+		ms -= 1000;
+		tp->sec++;
+	}
 }
 
 void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 			  u8 mode)
 {
+	u8 ms = 0;
 	u16 t = 0x00, d = 0x21;
 	struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
 
@@ -1171,10 +1179,12 @@ void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 	case TM_CREATE:
 		t = GET16_A(ep->create_time);
 		d = GET16_A(ep->create_date);
+		ms = ep->create_time_ms * 10;
 		break;
 	case TM_MODIFY:
 		t = GET16_A(ep->modify_time);
 		d = GET16_A(ep->modify_date);
+		ms = ep->modify_time_ms * 10;
 		break;
 	case TM_ACCESS:
 		t = GET16_A(ep->access_time);
@@ -1188,21 +1198,32 @@ void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 	tp->day  = (d & 0x001F);
 	tp->mon  = (d >> 5) & 0x000F;
 	tp->year = (d >> 9);
+
+	if (ms >= 1000) {
+		ms -= 1000;
+		tp->sec++;
+	}
 }
 
 void fat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 			u8 mode)
 {
+	u8 ms;
 	u16 t, d;
 	struct dos_dentry_t *ep = (struct dos_dentry_t *)p_entry;
 
 	t = (tp->hour << 11) | (tp->min << 5) | (tp->sec >> 1);
 	d = (tp->year <<  9) | (tp->mon << 5) |  tp->day;
 
+	ms = tp->millisec;
+	if (tp->sec & 1)
+		ms += 1000;
+
 	switch (mode) {
 	case TM_CREATE:
 		SET16_A(ep->create_time, t);
 		SET16_A(ep->create_date, d);
+		ep->create_time_ms = ms / 10;
 		break;
 	case TM_MODIFY:
 		SET16_A(ep->modify_time, t);
@@ -1214,20 +1235,27 @@ void fat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 void exfat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp,
 			  u8 mode)
 {
+	u8 ms;
 	u16 t, d;
 	struct file_dentry_t *ep = (struct file_dentry_t *)p_entry;
 
 	t = (tp->hour << 11) | (tp->min << 5) | (tp->sec >> 1);
 	d = (tp->year <<  9) | (tp->mon << 5) |  tp->day;
 
+	ms = tp->millisec;
+	if (tp->sec & 1)
+		ms += 1000;
+
 	switch (mode) {
 	case TM_CREATE:
 		SET16_A(ep->create_time, t);
 		SET16_A(ep->create_date, d);
+		ep->create_time_ms = ms / 10;
 		break;
 	case TM_MODIFY:
 		SET16_A(ep->modify_time, t);
 		SET16_A(ep->modify_date, d);
+		ep->modify_time_ms = ms / 10;
 		break;
 	case TM_ACCESS:
 		SET16_A(ep->access_time, t);
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct
  2019-09-08 17:35 ` [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct Valentin Vidic
@ 2019-09-08 18:50   ` Greg Kroah-Hartman
  2019-09-08 19:40     ` Valentin Vidić
  2019-09-08 18:54   ` Greg Kroah-Hartman
  1 sibling, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2019-09-08 18:50 UTC (permalink / raw)
  To: Valentin Vidic; +Cc: devel, Valdis Kletnieks, linux-kernel

On Sun, Sep 08, 2019 at 05:35:37PM +0000, Valentin Vidic wrote:
> Use timestamp_t for everything and cleanup duplicate code.

Wait, how are these "duplicate"?  The fields are in different order,
don't these refer to things on-disk?

Did you test this?

> -struct date_time_t {
> -	u16      Year;
> -	u16      Month;
> -	u16      Day;
> -	u16      Hour;
> -	u16      Minute;
> -	u16      Second;
> -	u16      MilliSecond;
> -};
> -
>  struct part_info_t {
>  	u32      Offset;    /* start sector number of the partition */
>  	u32      Size;      /* in sectors */
> @@ -289,6 +279,16 @@ struct file_id_t {
>  	u32      hint_last_clu;
>  };
>  
> +struct timestamp_t {
> +	u16      millisec;   /* 0 ~ 999              */
> +	u16      sec;        /* 0 ~ 59               */
> +	u16      min;        /* 0 ~ 59               */
> +	u16      hour;       /* 0 ~ 23               */
> +	u16      day;        /* 1 ~ 31               */
> +	u16      mon;        /* 1 ~ 12               */
> +	u16      year;       /* 0 ~ 127 (since 1980) */
> +};

They really look "backwards" to me, how are these the same?  What am I
missing?

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct
  2019-09-08 17:35 ` [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct Valentin Vidic
  2019-09-08 18:50   ` Greg Kroah-Hartman
@ 2019-09-08 18:54   ` Greg Kroah-Hartman
  2019-09-08 19:31     ` Valentin Vidić
  1 sibling, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2019-09-08 18:54 UTC (permalink / raw)
  To: Valentin Vidic; +Cc: devel, Valdis Kletnieks, linux-kernel

On Sun, Sep 08, 2019 at 05:35:37PM +0000, Valentin Vidic wrote:
> Use timestamp_t for everything and cleanup duplicate code.
> 
> Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr>
> ---
>  drivers/staging/exfat/exfat.h       |  35 +++---
>  drivers/staging/exfat/exfat_super.c | 158 ++++++++--------------------
>  2 files changed, 55 insertions(+), 138 deletions(-)
> 
> diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h
> index 0aa14dea4e09..58e1e889779f 100644
> --- a/drivers/staging/exfat/exfat.h
> +++ b/drivers/staging/exfat/exfat.h
> @@ -241,16 +241,6 @@ static inline u16 get_row_index(u16 i)
>  #define UNI_PAR_DIR_NAME        "\0.\0."
>  #endif
>  
> -struct date_time_t {
> -	u16      Year;
> -	u16      Month;
> -	u16      Day;
> -	u16      Hour;
> -	u16      Minute;
> -	u16      Second;
> -	u16      MilliSecond;
> -};
> -
>  struct part_info_t {
>  	u32      Offset;    /* start sector number of the partition */
>  	u32      Size;      /* in sectors */
> @@ -289,6 +279,16 @@ struct file_id_t {
>  	u32      hint_last_clu;
>  };
>  
> +struct timestamp_t {
> +	u16      millisec;   /* 0 ~ 999              */

You added this field to this structure, why?  You did not document that
in the changelog text above.  Are you _sure_ you can do this and that
this does not refer to an on-disk layout?

thanks,

greg k-h
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct
  2019-09-08 18:54   ` Greg Kroah-Hartman
@ 2019-09-08 19:31     ` Valentin Vidić
  0 siblings, 0 replies; 9+ messages in thread
From: Valentin Vidić @ 2019-09-08 19:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Valdis Kletnieks, linux-kernel

On Sun, Sep 08, 2019 at 07:54:24PM +0100, Greg Kroah-Hartman wrote:
> On Sun, Sep 08, 2019 at 05:35:37PM +0000, Valentin Vidic wrote:
> > +struct timestamp_t {
> > +	u16      millisec;   /* 0 ~ 999              */
> 
> You added this field to this structure, why?  You did not document that
> in the changelog text above.  Are you _sure_ you can do this and that
> this does not refer to an on-disk layout?

Both date_time_t and timestamp_t were used in memory only, but
date_time_t had the additional MilliSecond field. To keep the
functionality I added the millisec field to timestamp_t and
replaced all usages of date_time_t with timestamp_t.

For storing on disk the values from timestamp_t get shifted
and combined (exfat_set_entry_time).

-- 
Valentin
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct
  2019-09-08 18:50   ` Greg Kroah-Hartman
@ 2019-09-08 19:40     ` Valentin Vidić
  0 siblings, 0 replies; 9+ messages in thread
From: Valentin Vidić @ 2019-09-08 19:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, Valdis Kletnieks, linux-kernel

On Sun, Sep 08, 2019 at 07:50:31PM +0100, Greg Kroah-Hartman wrote:
> Wait, how are these "duplicate"?  The fields are in different order,
> don't these refer to things on-disk?

On-disk combines the values from these structures in a different form:

          offset  bits
DoubleSeconds  0  5
Minute         5  6
Hour          11  5
Day           16  5
Month         21  4
Year          25  7

> Did you test this?

Just compile tested for now.

> > -struct date_time_t {
> > -	u16      Year;
> > -	u16      Month;
> > -	u16      Day;
> > -	u16      Hour;
> > -	u16      Minute;
> > -	u16      Second;
> > -	u16      MilliSecond;
> > -};
> > -
> >  struct part_info_t {
> >  	u32      Offset;    /* start sector number of the partition */
> >  	u32      Size;      /* in sectors */
> > @@ -289,6 +279,16 @@ struct file_id_t {
> >  	u32      hint_last_clu;
> >  };
> >  
> > +struct timestamp_t {
> > +	u16      millisec;   /* 0 ~ 999              */
> > +	u16      sec;        /* 0 ~ 59               */
> > +	u16      min;        /* 0 ~ 59               */
> > +	u16      hour;       /* 0 ~ 23               */
> > +	u16      day;        /* 1 ~ 31               */
> > +	u16      mon;        /* 1 ~ 12               */
> > +	u16      year;       /* 0 ~ 127 (since 1980) */
> > +};
> 
> They really look "backwards" to me, how are these the same?  What am I
> missing?

date_time_t was only used in a few functions and there was a lot of
copying of the same fields between the two structs. Also some code was
duplicated to do the same thing for each of the structs.

-- 
Valentin
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/4] staging: exfat: drop unused function parameter
  2019-09-08 17:35 [PATCH v3 1/4] staging: exfat: drop unused function parameter Valentin Vidic
                   ` (2 preceding siblings ...)
  2019-09-08 17:35 ` [PATCH v3 4/4] staging: exfat: add millisecond support Valentin Vidic
@ 2019-09-09  0:28 ` Valdis Klētnieks
  3 siblings, 0 replies; 9+ messages in thread
From: Valdis Klētnieks @ 2019-09-09  0:28 UTC (permalink / raw)
  To: Valentin Vidic; +Cc: devel, Greg Kroah-Hartman, linux-kernel

[-- Attachment #1.1: Type: text/plain, Size: 531 bytes --]

On Sun, 08 Sep 2019 17:35:36 -0000, Valentin Vidic said:
> sbi parameter not used inside the function so remove it.
> Also cleanup unused variables generated by this change.

Tread carefully with this sort of patch - there's still a lot of places in the code
where we have matching pairs of exfat_foo() and fat_foo() functions which need
to have the same signatures because they're called through a function pointer.

This particular one looks OK, but there's other functions that come in pairs that
you need to watch out for...



[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-08 17:35 [PATCH v3 1/4] staging: exfat: drop unused function parameter Valentin Vidic
2019-09-08 17:35 ` [PATCH v3 2/4] staging: exfat: drop duplicate date_time_t struct Valentin Vidic
2019-09-08 18:50   ` Greg Kroah-Hartman
2019-09-08 19:40     ` Valentin Vidić
2019-09-08 18:54   ` Greg Kroah-Hartman
2019-09-08 19:31     ` Valentin Vidić
2019-09-08 17:35 ` [PATCH v3 3/4] staging: exfat: drop unused field access_time_ms Valentin Vidic
2019-09-08 17:35 ` [PATCH v3 4/4] staging: exfat: add millisecond support Valentin Vidic
2019-09-09  0:28 ` [PATCH v3 1/4] staging: exfat: drop unused function parameter Valdis Klētnieks

DriverDev-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/driverdev-devel/0 driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ https://lore.kernel.org/driverdev-devel \
		driverdev-devel@linuxdriverproject.org devel@driverdev.osuosl.org driverdev-devel@archiver.kernel.org
	public-inbox-index driverdev-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxdriverproject.driverdev-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox