From nobody Sun May 5 11:10:29 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 150097685229093.54993897232771; Tue, 25 Jul 2017 03:00:52 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5234821D28FF8; Tue, 25 Jul 2017 02:58:45 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4CD9E21D28FF5 for ; Tue, 25 Jul 2017 02:58:44 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2017 03:00:45 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.7]) by orsmga004.jf.intel.com with ESMTP; 25 Jul 2017 03:00:45 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,411,1496127600"; d="scan'208";a="111708186" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 25 Jul 2017 18:00:28 +0800 Message-Id: <20170725100029.31284-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170725100029.31284-1-ruiyu.ni@intel.com> References: <20170725100029.31284-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 1/2] Nt32Pkg/WinNtSimpleFileSystemDxe: Change GetInfo() to get TimeZone. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Huajing MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Li Huajing Signed-off-by: Huajing Li Reviewed-by: Ruiyu Ni --- .../WinNtSimpleFileSystem.c | 78 +++++++++---------= ---- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c b/Nt3= 2Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c index b687e9c957..f598c8e546 100644 --- a/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c +++ b/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c @@ -1492,6 +1492,30 @@ Returns: } } =20 +/** + 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 ( =20 + 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, &TempFileTim= e); + PrivateFile->WinNtThunk->FileTimeToSystemTime (&TempFileTime, &SystemTim= e); + 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 =3D ResultSize; =20 PrivateFile->WinNtThunk->GetTimeZoneInformation (&TimeZone); - - PrivateFile->WinNtThunk->FileTimeToLocalFileTime ( - &PrivateFile->FindBuf.ftCreationTime, - &PrivateFile->FindBuf.ftCreationTime - ); - - PrivateFile->WinNtThunk->FileTimeToSystemTime (&PrivateFile->FindBuf.f= tCreationTime, &SystemTime); - - WinNtSystemTimeToEfiTime (&SystemTime, &TimeZone, &Info->CreateTime); - - PrivateFile->WinNtThunk->FileTimeToLocalFileTime ( - &PrivateFile->FindBuf.ftLastWriteTime, - &PrivateFile->FindBuf.ftLastWriteTime - ); - - PrivateFile->WinNtThunk->FileTimeToSystemTime (&PrivateFile->FindBuf.f= tLastWriteTime, &SystemTime); - - WinNtSystemTimeToEfiTime (&SystemTime, &TimeZone, &Info->ModificationT= ime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.= ftCreationTime, &Info->CreateTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.= ftLastAccessTime, &Info->LastAccessTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.= ftLastWriteTime, &Info->ModificationTime); =20 Info->FileSize =3D PrivateFile->FindBuf.nFileSizeLow; =20 @@ -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; =20 Size =3D SIZE_OF_EFI_FILE_INFO; =20 @@ -2022,32 +2030,10 @@ Returns: Info->FileSize =3D FileInfo.nFileSizeLow; Info->PhysicalSize =3D Info->FileSize; =20 - PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftCreationT= ime, &FileInfo.ftCreationTime); - PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftCreationTim= e, &SystemTime); - Info->CreateTime.Year =3D SystemTime.wYear; - Info->CreateTime.Month =3D (UINT8) SystemTime.wMonth; - Info->CreateTime.Day =3D (UINT8) SystemTime.wDay; - Info->CreateTime.Hour =3D (UINT8) SystemTime.wHour; - Info->CreateTime.Minute =3D (UINT8) SystemTime.wMinute; - Info->CreateTime.Second =3D (UINT8) SystemTime.wSecond; - - PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftLastAcces= sTime, &FileInfo.ftLastAccessTime); - PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastAccessT= ime, &SystemTime); - Info->LastAccessTime.Year =3D SystemTime.wYear; - Info->LastAccessTime.Month =3D (UINT8) SystemTime.wMonth; - Info->LastAccessTime.Day =3D (UINT8) SystemTime.wDay; - Info->LastAccessTime.Hour =3D (UINT8) SystemTime.wHour; - Info->LastAccessTime.Minute =3D (UINT8) SystemTime.wMinute; - Info->LastAccessTime.Second =3D (UINT8) SystemTime.wSecond; - - PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftLastWrite= Time, &FileInfo.ftLastWriteTime); - PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastWriteTi= me, &SystemTime); - Info->ModificationTime.Year =3D SystemTime.wYear; - Info->ModificationTime.Month =3D (UINT8) SystemTime.wMonth; - Info->ModificationTime.Day =3D (UINT8) SystemTime.wDay; - Info->ModificationTime.Hour =3D (UINT8) SystemTime.wHour; - Info->ModificationTime.Minute =3D (UINT8) SystemTime.wMinute; - Info->ModificationTime.Second =3D (UINT8) SystemTime.wSecond; + PrivateFile->WinNtThunk->GetTimeZoneInformation (&TimeZone); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftCreationTi= me, &Info->CreateTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftLastAccess= Time, &Info->LastAccessTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftLastWriteT= ime, &Info->ModificationTime); =20 if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) { Info->Attribute |=3D EFI_FILE_ARCHIVE; --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 11:10:29 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1500976852414873.5451158967891; Tue, 25 Jul 2017 03:00:52 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C43821D28FFE; Tue, 25 Jul 2017 02:58:46 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3718121D28FF5 for ; Tue, 25 Jul 2017 02:58:45 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2017 03:00:46 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.7]) by orsmga004.jf.intel.com with ESMTP; 25 Jul 2017 03:00:45 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,411,1496127600"; d="scan'208";a="111708192" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 25 Jul 2017 18:00:29 +0800 Message-Id: <20170725100029.31284-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.12.2.windows.2 In-Reply-To: <20170725100029.31284-1-ruiyu.ni@intel.com> References: <20170725100029.31284-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/2] ShellPkg/ls: Display the file time in local time. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Huajing MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Li Huajing Signed-off-by: Li Huajing Reviewed-by: Ruiyu Ni --- ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 111 +++++++++++++++++++= +++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Li= brary/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. =20 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -16,6 +16,8 @@ #include "UefiShellLevel2CommandsLib.h" #include =20 +UINTN mDayOfMonth[] =3D {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 3= 0}; + /** print out the standard format output volume entry. =20 @@ -319,6 +321,89 @@ PrintNonSfoFooter( } =20 /** + 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 >=3D -1440) && (Time->TimeZone <=3D1440)); + ASSERT ((LocalTimeZone >=3D -1440) && (LocalTimeZone <=3D1440)); + ASSERT ((Time->Month >=3D 1) && (Time->Month <=3D 12)); + + if((Time->Year % 4 =3D=3D 0 && Time->Year / 100 !=3D 0)||(Time->Year % 4= 00 =3D=3D 0)) { + // + // Day in February of leap year is 29. + // + mDayOfMonth[1] =3D 29; + } + + MinuteDiff =3D Time->TimeZone - LocalTimeZone; + TempMinute =3D Time->Minute + MinuteDiff; + + // + // Calculate Time->Minute + // TempHour will be used to calculate Time->Hour + // + HourNumberOfTempMinute =3D TempMinute / 60; + if(TempMinute < 0) { + HourNumberOfTempMinute --;=20 + } + TempHour =3D Time->Hour + HourNumberOfTempMinute; + Time->Minute =3D (UINT8)(TempMinute - 60 * HourNumberOfTempMinute); + + // + // Calculate Time->Hour + // TempDay will be used to calculate Time->Day + // + DayNumberOfTempHour =3D TempHour / 24 ; + if(TempHour < 0){ + DayNumberOfTempHour--; + } + TempDay =3D Time->Day + DayNumberOfTempHour; + Time->Hour =3D (UINT8)(TempHour - 24 * DayNumberOfTempHour); + + // + // Calculate Time->Day + // TempMonth will be used to calculate Time->Month + // + MonthNumberOfTempDay =3D (TempDay - 1) / mDayOfMonth[Time->Month - 1]; + MonthRecord =3D (INTN)(Time->Month) ; + if(TempDay - 1 < 0){ + MonthNumberOfTempDay -- ; + MonthRecord -- ; + } + TempMonth =3D Time->Month + MonthNumberOfTempDay; + Time->Day =3D (UINT8)(TempDay - mDayOfMonth[(MonthRecord - 1 + 12) % 12]= * MonthNumberOfTempDay); + + // + // Calculate Time->Month, Time->Year + // + YearNumberOfTempMonth =3D (TempMonth - 1) / 12; + if(TempMonth - 1 < 0){ + YearNumberOfTempMonth --; + } + Time->Month =3D (UINT8)(TempMonth - 12 * (YearNumberOfTempMonth)); + Time->Year =3D (UINT16)(Time->Year + YearNumberOfTempMonth); +} + +/** print out the list of files and directories from the LS command =20 @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; =20 HeaderPrinted =3D FALSE; FileCount =3D 0; @@ -408,6 +494,29 @@ PrintLsOutput( break; } ASSERT(Node !=3D NULL); + + // + // Change the file time to local time. + // + Status =3D gRT->GetTime(&LocalTime, NULL); + if (!EFI_ERROR (Status)) { + if ((Node->Info->CreateTime.TimeZone !=3D EFI_UNSPECIFIED_TIMEZONE= ) && + (Node->Info->CreateTime.Month >=3D 1 && Node->Info->CreateTime= .Month <=3D 12)) { + // + // FileTimeToLocalTime () requires Month is in a valid range, ot= her buffer out-of-band access happens. + // + FileTimeToLocalTime (&Node->Info->CreateTime, LocalTime.TimeZone= ); + } + if ((Node->Info->LastAccessTime.TimeZone !=3D EFI_UNSPECIFIED_TIME= ZONE) && + (Node->Info->LastAccessTime.Month >=3D 1 && Node->Info->LastAc= cessTime.Month <=3D 12)) { + FileTimeToLocalTime (&Node->Info->LastAccessTime, LocalTime.Time= Zone); + } + if ((Node->Info->ModificationTime.TimeZone !=3D EFI_UNSPECIFIED_TI= MEZONE) && + (Node->Info->ModificationTime.Month >=3D 1 && Node->Info->Modi= ficationTime.Month <=3D 12)) { + FileTimeToLocalTime (&Node->Info->ModificationTime, LocalTime.Ti= meZone); + } + } + if (LongestPath < StrSize(Node->FullName)) { LongestPath =3D StrSize(Node->FullName); } --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel