public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] Change Shell command ls to display file time in local time.
@ 2017-07-25 10:00 Ruiyu Ni
  2017-07-25 10:00 ` [PATCH 1/2] Nt32Pkg/WinNtSimpleFileSystemDxe: Change GetInfo() to get TimeZone Ruiyu Ni
  2017-07-25 10:00 ` [PATCH 2/2] ShellPkg/ls: Display the file time in local time Ruiyu Ni
  0 siblings, 2 replies; 3+ messages in thread
From: Ruiyu Ni @ 2017-07-25 10:00 UTC (permalink / raw)
  To: edk2-devel

Li Huajing (2):
  Nt32Pkg/WinNtSimpleFileSystemDxe: Change GetInfo() to get TimeZone.
  ShellPkg/ls: Display the file time in local time.

 .../WinNtSimpleFileSystem.c                        |  78 ++++++---------
 ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c   | 111 ++++++++++++++++++++-
 2 files changed, 142 insertions(+), 47 deletions(-)

-- 
2.12.2.windows.2



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

* [PATCH 1/2] Nt32Pkg/WinNtSimpleFileSystemDxe: Change GetInfo() to get TimeZone.
  2017-07-25 10:00 [PATCH 0/2] Change Shell command ls to display file time in local time Ruiyu Ni
@ 2017-07-25 10:00 ` Ruiyu Ni
  2017-07-25 10:00 ` [PATCH 2/2] ShellPkg/ls: Display the file time in local time Ruiyu Ni
  1 sibling, 0 replies; 3+ messages in thread
From: Ruiyu Ni @ 2017-07-25 10:00 UTC (permalink / raw)
  To: edk2-devel; +Cc: Li Huajing

From: Li Huajing <huajing.li@intel.com>

Signed-off-by: Huajing Li <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
 .../WinNtSimpleFileSystem.c                        | 78 +++++++++-------------
 1 file changed, 32 insertions(+), 46 deletions(-)

diff --git a/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c b/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c
index b687e9c957..f598c8e546 100644
--- a/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c
+++ b/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c
@@ -1492,6 +1492,30 @@ Returns:
   }
 }
 
+/**
+  Convert the FileTime to EfiTime.
+
+  @param PrivateFile  Pointer to WIN_NT_EFI_FILE_PRIVATE.
+  @param TimeZone     Pointer to the current time zone.
+  @param FileTime     Pointer to file time.
+  @param EfiTime      Pointer to EFI time.
+**/
+VOID
+WinNtFileTimeToEfiTime (  
+  IN CONST WIN_NT_EFI_FILE_PRIVATE *PrivateFile,
+  IN       TIME_ZONE_INFORMATION   *TimeZone,
+  IN CONST FILETIME                *FileTime,
+  OUT      EFI_TIME                *EfiTime
+  )
+{
+  FILETIME                         TempFileTime;
+  SYSTEMTIME                       SystemTime;
+
+  PrivateFile->WinNtThunk->FileTimeToLocalFileTime (FileTime, &TempFileTime);
+  PrivateFile->WinNtThunk->FileTimeToSystemTime (&TempFileTime, &SystemTime);
+  WinNtSystemTimeToEfiTime (&SystemTime, TimeZone, EfiTime);
+}
+
 EFI_STATUS
 EFIAPI
 WinNtSimpleFileSystemRead (
@@ -1535,7 +1559,6 @@ Returns:
   UINTN                   NameSize;
   UINTN                   ResultSize;
   UINTN                   Index;
-  SYSTEMTIME              SystemTime;
   EFI_FILE_INFO           *Info;
   WCHAR                   *pw;
   TIME_ZONE_INFORMATION   TimeZone;
@@ -1642,24 +1665,9 @@ Returns:
     Info->Size = ResultSize;
 
     PrivateFile->WinNtThunk->GetTimeZoneInformation (&TimeZone);
-
-    PrivateFile->WinNtThunk->FileTimeToLocalFileTime (
-                              &PrivateFile->FindBuf.ftCreationTime,
-                              &PrivateFile->FindBuf.ftCreationTime
-                              );
-
-    PrivateFile->WinNtThunk->FileTimeToSystemTime (&PrivateFile->FindBuf.ftCreationTime, &SystemTime);
-
-    WinNtSystemTimeToEfiTime (&SystemTime, &TimeZone, &Info->CreateTime);
-
-    PrivateFile->WinNtThunk->FileTimeToLocalFileTime (
-                              &PrivateFile->FindBuf.ftLastWriteTime,
-                              &PrivateFile->FindBuf.ftLastWriteTime
-                              );
-
-    PrivateFile->WinNtThunk->FileTimeToSystemTime (&PrivateFile->FindBuf.ftLastWriteTime, &SystemTime);
-
-    WinNtSystemTimeToEfiTime (&SystemTime, &TimeZone, &Info->ModificationTime);
+    WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftCreationTime, &Info->CreateTime);
+    WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftLastAccessTime, &Info->LastAccessTime);
+    WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftLastWriteTime, &Info->ModificationTime);
 
     Info->FileSize      = PrivateFile->FindBuf.nFileSizeLow;
 
@@ -1988,9 +1996,9 @@ Returns:
   UINTN                       ResultSize;
   EFI_FILE_INFO               *Info;
   BY_HANDLE_FILE_INFORMATION  FileInfo;
-  SYSTEMTIME                  SystemTime;
   CHAR16                      *RealFileName;
   CHAR16                      *TempPointer;
+  TIME_ZONE_INFORMATION       TimeZone;
 
   Size        = SIZE_OF_EFI_FILE_INFO;
 
@@ -2022,32 +2030,10 @@ Returns:
     Info->FileSize      = FileInfo.nFileSizeLow;
     Info->PhysicalSize  = Info->FileSize;
 
-    PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftCreationTime, &FileInfo.ftCreationTime);
-    PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftCreationTime, &SystemTime);
-    Info->CreateTime.Year   = SystemTime.wYear;
-    Info->CreateTime.Month  = (UINT8) SystemTime.wMonth;
-    Info->CreateTime.Day    = (UINT8) SystemTime.wDay;
-    Info->CreateTime.Hour   = (UINT8) SystemTime.wHour;
-    Info->CreateTime.Minute = (UINT8) SystemTime.wMinute;
-    Info->CreateTime.Second = (UINT8) SystemTime.wSecond;
-
-    PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftLastAccessTime, &FileInfo.ftLastAccessTime);
-    PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastAccessTime, &SystemTime);
-    Info->LastAccessTime.Year   = SystemTime.wYear;
-    Info->LastAccessTime.Month  = (UINT8) SystemTime.wMonth;
-    Info->LastAccessTime.Day    = (UINT8) SystemTime.wDay;
-    Info->LastAccessTime.Hour   = (UINT8) SystemTime.wHour;
-    Info->LastAccessTime.Minute = (UINT8) SystemTime.wMinute;
-    Info->LastAccessTime.Second = (UINT8) SystemTime.wSecond;
-
-    PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftLastWriteTime, &FileInfo.ftLastWriteTime);
-    PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastWriteTime, &SystemTime);
-    Info->ModificationTime.Year   = SystemTime.wYear;
-    Info->ModificationTime.Month  = (UINT8) SystemTime.wMonth;
-    Info->ModificationTime.Day    = (UINT8) SystemTime.wDay;
-    Info->ModificationTime.Hour   = (UINT8) SystemTime.wHour;
-    Info->ModificationTime.Minute = (UINT8) SystemTime.wMinute;
-    Info->ModificationTime.Second = (UINT8) SystemTime.wSecond;
+    PrivateFile->WinNtThunk->GetTimeZoneInformation (&TimeZone);
+    WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftCreationTime, &Info->CreateTime);
+    WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftLastAccessTime, &Info->LastAccessTime);
+    WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftLastWriteTime, &Info->ModificationTime);
 
     if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
       Info->Attribute |= EFI_FILE_ARCHIVE;
-- 
2.12.2.windows.2



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

* [PATCH 2/2] ShellPkg/ls: Display the file time in local time.
  2017-07-25 10:00 [PATCH 0/2] Change Shell command ls to display file time in local time Ruiyu Ni
  2017-07-25 10:00 ` [PATCH 1/2] Nt32Pkg/WinNtSimpleFileSystemDxe: Change GetInfo() to get TimeZone Ruiyu Ni
@ 2017-07-25 10:00 ` Ruiyu Ni
  1 sibling, 0 replies; 3+ messages in thread
From: Ruiyu Ni @ 2017-07-25 10:00 UTC (permalink / raw)
  To: edk2-devel; +Cc: Li Huajing

From: Li Huajing <huajing.li@intel.com>

Signed-off-by: Li Huajing <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
 ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 111 ++++++++++++++++++++++-
 1 file changed, 110 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
index 52ae18f19b..687f65b914 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
@@ -2,7 +2,7 @@
   Main file for ls shell level 2 function.
 
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -16,6 +16,8 @@
 #include "UefiShellLevel2CommandsLib.h"
 #include <Guid/FileSystemInfo.h>
 
+UINTN     mDayOfMonth[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
+
 /**
   print out the standard format output volume entry.
 
@@ -319,6 +321,89 @@ PrintNonSfoFooter(
 }
 
 /**
+  Change the file time to local time based on the timezone.
+
+  @param[in] Time               The file time.
+  @param[in] LocalTimeZone      Local time zone.
+**/
+VOID
+FileTimeToLocalTime (
+  IN EFI_TIME             *Time,
+  IN INT16                LocalTimeZone
+  )
+{
+  INTN                    MinuteDiff;
+  INTN                    TempMinute;
+  INTN                    HourNumberOfTempMinute;
+  INTN                    TempHour;
+  INTN                    DayNumberOfTempHour;
+  INTN                    TempDay;
+  INTN                    MonthNumberOfTempDay;
+  INTN                    TempMonth;
+  INTN                    YearNumberOfTempMonth;
+  INTN                    MonthRecord;
+
+  ASSERT ((Time->TimeZone >= -1440) && (Time->TimeZone <=1440));
+  ASSERT ((LocalTimeZone >= -1440) && (LocalTimeZone <=1440));
+  ASSERT ((Time->Month >= 1) && (Time->Month <= 12));
+
+  if((Time->Year % 4 == 0 && Time->Year / 100 != 0)||(Time->Year % 400 == 0)) {
+    //
+    // Day in February of leap year is 29.
+    //
+    mDayOfMonth[1] = 29;
+  }
+
+  MinuteDiff = Time->TimeZone - LocalTimeZone;
+  TempMinute = Time->Minute + MinuteDiff;
+
+  //
+  // Calculate Time->Minute
+  // TempHour will be used to calculate Time->Hour
+  //
+  HourNumberOfTempMinute = TempMinute / 60;
+  if(TempMinute < 0) {
+    HourNumberOfTempMinute --; 
+  }
+  TempHour = Time->Hour + HourNumberOfTempMinute;
+  Time->Minute = (UINT8)(TempMinute - 60 * HourNumberOfTempMinute);
+
+  //
+  // Calculate Time->Hour
+  // TempDay will be used to calculate Time->Day
+  //
+  DayNumberOfTempHour = TempHour / 24 ;
+  if(TempHour < 0){
+    DayNumberOfTempHour--;
+  }
+  TempDay = Time->Day + DayNumberOfTempHour;
+  Time->Hour = (UINT8)(TempHour - 24 * DayNumberOfTempHour);
+
+  //
+  // Calculate Time->Day
+  // TempMonth will be used to calculate Time->Month
+  //
+  MonthNumberOfTempDay = (TempDay - 1) / mDayOfMonth[Time->Month - 1];
+  MonthRecord = (INTN)(Time->Month) ;
+  if(TempDay - 1 < 0){
+    MonthNumberOfTempDay -- ;
+    MonthRecord -- ;
+  }
+  TempMonth = Time->Month + MonthNumberOfTempDay;
+  Time->Day = (UINT8)(TempDay - mDayOfMonth[(MonthRecord - 1 + 12) % 12] * MonthNumberOfTempDay);
+
+  //
+  // Calculate Time->Month, Time->Year
+  //
+  YearNumberOfTempMonth = (TempMonth - 1) / 12;
+  if(TempMonth - 1 < 0){
+    YearNumberOfTempMonth --;
+  }
+  Time->Month = (UINT8)(TempMonth - 12 * (YearNumberOfTempMonth));
+  Time->Year = (UINT16)(Time->Year + YearNumberOfTempMonth);
+}
+
+/**
   print out the list of files and directories from the LS command
 
   @param[in] Rec            TRUE to automatically recurse into each found directory
@@ -357,6 +442,7 @@ PrintLsOutput(
   CHAR16                *CorrectedPath;
   BOOLEAN               FoundOne;
   BOOLEAN               HeaderPrinted;
+  EFI_TIME              LocalTime;
 
   HeaderPrinted = FALSE;
   FileCount     = 0;
@@ -408,6 +494,29 @@ PrintLsOutput(
         break;
       }
       ASSERT(Node != NULL);
+
+      //
+      // Change the file time to local time.
+      //
+      Status = gRT->GetTime(&LocalTime, NULL);
+      if (!EFI_ERROR (Status)) {
+        if ((Node->Info->CreateTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
+            (Node->Info->CreateTime.Month >= 1 && Node->Info->CreateTime.Month <= 12)) {
+          //
+          // FileTimeToLocalTime () requires Month is in a valid range, other buffer out-of-band access happens.
+          //
+          FileTimeToLocalTime (&Node->Info->CreateTime, LocalTime.TimeZone);
+        }
+        if ((Node->Info->LastAccessTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
+            (Node->Info->LastAccessTime.Month >= 1 && Node->Info->LastAccessTime.Month <= 12)) {
+          FileTimeToLocalTime (&Node->Info->LastAccessTime, LocalTime.TimeZone);
+        }
+        if ((Node->Info->ModificationTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
+            (Node->Info->ModificationTime.Month >= 1 && Node->Info->ModificationTime.Month <= 12)) {
+          FileTimeToLocalTime (&Node->Info->ModificationTime, LocalTime.TimeZone);
+        }
+      }
+
       if (LongestPath < StrSize(Node->FullName)) {
         LongestPath = StrSize(Node->FullName);
       }
-- 
2.12.2.windows.2



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

end of thread, other threads:[~2017-07-25  9:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 10:00 [PATCH 0/2] Change Shell command ls to display file time in local time Ruiyu Ni
2017-07-25 10:00 ` [PATCH 1/2] Nt32Pkg/WinNtSimpleFileSystemDxe: Change GetInfo() to get TimeZone Ruiyu Ni
2017-07-25 10:00 ` [PATCH 2/2] ShellPkg/ls: Display the file time in local time Ruiyu Ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox