ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
May 2018
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
23 participants
218 discussions
Start a n
N
ew thread
03/04: [USETUP] Factor out the UI-specific code from the GenList code, and wrap it inside a GENERIC_LIST_UI structure.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=92692eae3d5561c213164…
commit 92692eae3d5561c213164a39a867f6f608348a9f Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Mon May 15 16:22:18 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 22:45:50 2018 +0200 [USETUP] Factor out the UI-specific code from the GenList code, and wrap it inside a GENERIC_LIST_UI structure. The aim here is to decouple the UI-specific code from code that can be used by both the text-mode USETUP and a future 1st-stage GUI setup. Indeed, the GenLists can actually be used in the 1st-stage GUI; and their contents be displayed inside ListBoxes/ListViews... (this is just one example amongst others). Additionally (in usetup.c): - Make both FormatPartitionPage and CheckFileSystemPage return PAGE_NUMBERs. - Improve a couple of comments. svn path=/branches/setup_improvements/; revision=74553 --- base/setup/usetup/genlist.c | 322 +++++++++++++++++++++++--------------------- base/setup/usetup/genlist.h | 132 ++++++++++-------- base/setup/usetup/usetup.c | 97 ++++++------- 3 files changed, 298 insertions(+), 253 deletions(-) diff --git a/base/setup/usetup/genlist.c b/base/setup/usetup/genlist.c index 5f79a906bf..1ff2275aa3 100644 --- a/base/setup/usetup/genlist.c +++ b/base/setup/usetup/genlist.c @@ -38,7 +38,7 @@ typedef struct _GENERIC_LIST_ENTRY LIST_ENTRY Entry; PGENERIC_LIST List; PVOID UserData; - CHAR Text[1]; + CHAR Text[1]; // FIXME: UI stuff } GENERIC_LIST_ENTRY; @@ -47,18 +47,11 @@ typedef struct _GENERIC_LIST LIST_ENTRY ListHead; ULONG NumOfEntries; - PLIST_ENTRY FirstShown; - PLIST_ENTRY LastShown; - SHORT Left; - SHORT Top; - SHORT Right; - SHORT Bottom; - BOOL Redraw; - PGENERIC_LIST_ENTRY CurrentEntry; PGENERIC_LIST_ENTRY BackupEntry; } GENERIC_LIST; + PGENERIC_LIST CreateGenericList(VOID) { @@ -73,23 +66,16 @@ CreateGenericList(VOID) InitializeListHead(&List->ListHead); List->NumOfEntries = 0; - List->Left = 0; - List->Top = 0; - List->Right = 0; - List->Bottom = 0; - List->Redraw = TRUE; - List->CurrentEntry = NULL; List->BackupEntry = NULL; return List; } - VOID DestroyGenericList( - PGENERIC_LIST List, - BOOLEAN FreeUserData) + IN OUT PGENERIC_LIST List, + IN BOOLEAN FreeUserData) { PGENERIC_LIST_ENTRY ListEntry; PLIST_ENTRY Entry; @@ -112,13 +98,12 @@ DestroyGenericList( RtlFreeHeap (ProcessHeap, 0, List); } - BOOLEAN AppendGenericListEntry( - PGENERIC_LIST List, - PCHAR Text, - PVOID UserData, - BOOLEAN Current) + IN OUT PGENERIC_LIST List, + IN PCHAR Text, + IN PVOID UserData, + IN BOOLEAN Current) { PGENERIC_LIST_ENTRY Entry; @@ -145,18 +130,34 @@ AppendGenericListEntry( } +VOID +InitGenericListUi( + IN OUT PGENERIC_LIST_UI ListUi, + IN PGENERIC_LIST List) +{ + ListUi->List = List; + ListUi->FirstShown = NULL; + ListUi->LastShown = NULL; + + ListUi->Left = 0; + ListUi->Top = 0; + ListUi->Right = 0; + ListUi->Bottom = 0; + ListUi->Redraw = TRUE; +} + static VOID DrawListFrame( - PGENERIC_LIST GenericList) + IN PGENERIC_LIST_UI ListUi) { COORD coPos; DWORD Written; SHORT i; /* Draw upper left corner */ - coPos.X = GenericList->Left; - coPos.Y = GenericList->Top; + coPos.X = ListUi->Left; + coPos.Y = ListUi->Top; FillConsoleOutputCharacterA (StdOutput, 0xDA, // '+', 1, @@ -164,17 +165,17 @@ DrawListFrame( &Written); /* Draw upper edge */ - coPos.X = GenericList->Left + 1; - coPos.Y = GenericList->Top; + coPos.X = ListUi->Left + 1; + coPos.Y = ListUi->Top; FillConsoleOutputCharacterA (StdOutput, 0xC4, // '-', - GenericList->Right - GenericList->Left - 1, + ListUi->Right - ListUi->Left - 1, coPos, &Written); /* Draw upper right corner */ - coPos.X = GenericList->Right; - coPos.Y = GenericList->Top; + coPos.X = ListUi->Right; + coPos.Y = ListUi->Top; FillConsoleOutputCharacterA (StdOutput, 0xBF, // '+', 1, @@ -182,9 +183,9 @@ DrawListFrame( &Written); /* Draw left and right edge */ - for (i = GenericList->Top + 1; i < GenericList->Bottom; i++) + for (i = ListUi->Top + 1; i < ListUi->Bottom; i++) { - coPos.X = GenericList->Left; + coPos.X = ListUi->Left; coPos.Y = i; FillConsoleOutputCharacterA (StdOutput, 0xB3, // '|', @@ -192,7 +193,7 @@ DrawListFrame( coPos, &Written); - coPos.X = GenericList->Right; + coPos.X = ListUi->Right; FillConsoleOutputCharacterA (StdOutput, 0xB3, //'|', 1, @@ -201,8 +202,8 @@ DrawListFrame( } /* Draw lower left corner */ - coPos.X = GenericList->Left; - coPos.Y = GenericList->Bottom; + coPos.X = ListUi->Left; + coPos.Y = ListUi->Bottom; FillConsoleOutputCharacterA (StdOutput, 0xC0, // '+', 1, @@ -210,17 +211,17 @@ DrawListFrame( &Written); /* Draw lower edge */ - coPos.X = GenericList->Left + 1; - coPos.Y = GenericList->Bottom; + coPos.X = ListUi->Left + 1; + coPos.Y = ListUi->Bottom; FillConsoleOutputCharacterA (StdOutput, 0xC4, // '-', - GenericList->Right - GenericList->Left - 1, + ListUi->Right - ListUi->Left - 1, coPos, &Written); /* Draw lower right corner */ - coPos.X = GenericList->Right; - coPos.Y = GenericList->Bottom; + coPos.X = ListUi->Right; + coPos.Y = ListUi->Bottom; FillConsoleOutputCharacterA (StdOutput, 0xD9, // '+', 1, @@ -232,29 +233,30 @@ DrawListFrame( static VOID DrawListEntries( - PGENERIC_LIST GenericList) + IN PGENERIC_LIST_UI ListUi) { + PGENERIC_LIST List = ListUi->List; PGENERIC_LIST_ENTRY ListEntry; PLIST_ENTRY Entry; COORD coPos; DWORD Written; USHORT Width; - coPos.X = GenericList->Left + 1; - coPos.Y = GenericList->Top + 1; - Width = GenericList->Right - GenericList->Left - 1; + coPos.X = ListUi->Left + 1; + coPos.Y = ListUi->Top + 1; + Width = ListUi->Right - ListUi->Left - 1; - Entry = GenericList->FirstShown; - while (Entry != &GenericList->ListHead) + Entry = ListUi->FirstShown; + while (Entry != &List->ListHead) { ListEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry); - if (coPos.Y == GenericList->Bottom) + if (coPos.Y == ListUi->Bottom) break; - GenericList->LastShown = Entry; + ListUi->LastShown = Entry; FillConsoleOutputAttribute (StdOutput, - (GenericList->CurrentEntry == ListEntry) ? + (List->CurrentEntry == ListEntry) ? FOREGROUND_BLUE | BACKGROUND_WHITE : FOREGROUND_WHITE | BACKGROUND_BLUE, Width, @@ -279,7 +281,7 @@ DrawListEntries( Entry = Entry->Flink; } - while (coPos.Y < GenericList->Bottom) + while (coPos.Y < ListUi->Bottom) { FillConsoleOutputAttribute (StdOutput, FOREGROUND_WHITE | BACKGROUND_BLUE, @@ -300,15 +302,16 @@ DrawListEntries( static VOID DrawScrollBarGenericList( - PGENERIC_LIST GenericList) + IN PGENERIC_LIST_UI ListUi) { + PGENERIC_LIST List = ListUi->List; COORD coPos; DWORD Written; - coPos.X = GenericList->Right + 1; - coPos.Y = GenericList->Top; + coPos.X = ListUi->Right + 1; + coPos.Y = ListUi->Top; - if (GenericList->FirstShown != GenericList->ListHead.Flink) + if (ListUi->FirstShown != List->ListHead.Flink) { FillConsoleOutputCharacterA (StdOutput, '\x18', @@ -325,8 +328,8 @@ DrawScrollBarGenericList( &Written); } - coPos.Y = GenericList->Bottom; - if (GenericList->LastShown != GenericList->ListHead.Blink) + coPos.Y = ListUi->Bottom; + if (ListUi->LastShown != List->ListHead.Blink) { FillConsoleOutputCharacterA (StdOutput, '\x19', @@ -348,18 +351,22 @@ DrawScrollBarGenericList( static VOID CenterCurrentListItem( - PGENERIC_LIST List) + IN PGENERIC_LIST_UI ListUi) { + PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry; ULONG MaxVisibleItems, ItemCount, i; - if ((List->Top == 0 && List->Bottom == 0) || + if ((ListUi->Top == 0 && ListUi->Bottom == 0) || IsListEmpty(&List->ListHead) || List->CurrentEntry == NULL) + { return; + } - MaxVisibleItems = (ULONG)(List->Bottom - List->Top - 1); + MaxVisibleItems = (ULONG)(ListUi->Bottom - ListUi->Top - 1); +/***************************************** ItemCount = 0; Entry = List->ListHead.Flink; while (Entry != &List->ListHead) @@ -367,6 +374,8 @@ CenterCurrentListItem( ItemCount++; Entry = Entry->Flink; } +*****************************************/ + ItemCount = List->NumOfEntries; // GetNumberOfListEntries(List); if (ItemCount > MaxVisibleItems) { @@ -377,7 +386,7 @@ CenterCurrentListItem( Entry = Entry->Blink; } - List->FirstShown = Entry; + ListUi->FirstShown = Entry; for (i = 0; i < MaxVisibleItems; i++) { @@ -385,87 +394,90 @@ CenterCurrentListItem( Entry = Entry->Flink; } - List->LastShown = Entry; + ListUi->LastShown = Entry; } } VOID DrawGenericList( - PGENERIC_LIST List, - SHORT Left, - SHORT Top, - SHORT Right, - SHORT Bottom) + IN PGENERIC_LIST_UI ListUi, + IN SHORT Left, + IN SHORT Top, + IN SHORT Right, + IN SHORT Bottom) { - List->FirstShown = List->ListHead.Flink; - List->Left = Left; - List->Top = Top; - List->Right = Right; - List->Bottom = Bottom; + PGENERIC_LIST List = ListUi->List; - DrawListFrame(List); + ListUi->FirstShown = List->ListHead.Flink; + ListUi->Left = Left; + ListUi->Top = Top; + ListUi->Right = Right; + ListUi->Bottom = Bottom; + + DrawListFrame(ListUi); if (IsListEmpty(&List->ListHead)) return; - CenterCurrentListItem(List); + CenterCurrentListItem(ListUi); - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); } VOID ScrollPageDownGenericList( - PGENERIC_LIST List) + IN PGENERIC_LIST_UI ListUi) { SHORT i; /* Suspend auto-redraw */ - List->Redraw = FALSE; + ListUi->Redraw = FALSE; - for (i = List->Top + 1; i < List->Bottom - 1; i++) + for (i = ListUi->Top + 1; i < ListUi->Bottom - 1; i++) { - ScrollDownGenericList (List); + ScrollDownGenericList(ListUi); } /* Update user interface */ - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); /* Re enable auto-redraw */ - List->Redraw = TRUE; + ListUi->Redraw = TRUE; } VOID ScrollPageUpGenericList( - PGENERIC_LIST List) + IN PGENERIC_LIST_UI ListUi) { SHORT i; /* Suspend auto-redraw */ - List->Redraw = FALSE; + ListUi->Redraw = FALSE; - for (i = List->Bottom - 1; i > List->Top + 1; i--) + for (i = ListUi->Bottom - 1; i > ListUi->Top + 1; i--) { - ScrollUpGenericList (List); + ScrollUpGenericList(ListUi); } /* Update user interface */ - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); /* Re enable auto-redraw */ - List->Redraw = TRUE; + ListUi->Redraw = TRUE; } VOID ScrollDownGenericList( - PGENERIC_LIST List) + IN PGENERIC_LIST_UI ListUi) { + PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry; if (List->CurrentEntry == NULL) @@ -474,17 +486,17 @@ ScrollDownGenericList( if (List->CurrentEntry->Entry.Flink != &List->ListHead) { Entry = List->CurrentEntry->Entry.Flink; - if (List->LastShown == &List->CurrentEntry->Entry) + if (ListUi->LastShown == &List->CurrentEntry->Entry) { - List->FirstShown = List->FirstShown->Flink; - List->LastShown = List->LastShown->Flink; + ListUi->FirstShown = ListUi->FirstShown->Flink; + ListUi->LastShown = ListUi->LastShown->Flink; } - List->CurrentEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry); + List->CurrentEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry); - if (List->Redraw) + if (ListUi->Redraw) { - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); } } } @@ -492,9 +504,10 @@ ScrollDownGenericList( VOID ScrollToPositionGenericList( - PGENERIC_LIST List, - ULONG uIndex) + IN PGENERIC_LIST_UI ListUi, + IN ULONG uIndex) { + PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry; ULONG uCount = 0; @@ -506,29 +519,30 @@ ScrollToPositionGenericList( if (List->CurrentEntry->Entry.Flink != &List->ListHead) { Entry = List->CurrentEntry->Entry.Flink; - if (List->LastShown == &List->CurrentEntry->Entry) + if (ListUi->LastShown == &List->CurrentEntry->Entry) { - List->FirstShown = List->FirstShown->Flink; - List->LastShown = List->LastShown->Flink; + ListUi->FirstShown = ListUi->FirstShown->Flink; + ListUi->LastShown = ListUi->LastShown->Flink; } - List->CurrentEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry); + List->CurrentEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry); } uCount++; } while (uIndex != uCount); - if (List->Redraw) + if (ListUi->Redraw) { - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); } } VOID ScrollUpGenericList( - PGENERIC_LIST List) + IN PGENERIC_LIST_UI ListUi) { + PGENERIC_LIST List = ListUi->List; PLIST_ENTRY Entry; if (List->CurrentEntry == NULL) @@ -537,17 +551,17 @@ ScrollUpGenericList( if (List->CurrentEntry->Entry.Blink != &List->ListHead) { Entry = List->CurrentEntry->Entry.Blink; - if (List->FirstShown == &List->CurrentEntry->Entry) + if (ListUi->FirstShown == &List->CurrentEntry->Entry) { - List->FirstShown = List->FirstShown->Blink; - List->LastShown = List->LastShown->Blink; + ListUi->FirstShown = ListUi->FirstShown->Blink; + ListUi->LastShown = ListUi->LastShown->Blink; } - List->CurrentEntry = CONTAINING_RECORD (Entry, GENERIC_LIST_ENTRY, Entry); + List->CurrentEntry = CONTAINING_RECORD(Entry, GENERIC_LIST_ENTRY, Entry); - if (List->Redraw) + if (ListUi->Redraw) { - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); } } } @@ -555,23 +569,24 @@ ScrollUpGenericList( VOID RedrawGenericList( - PGENERIC_LIST List) + IN PGENERIC_LIST_UI ListUi) { - if (List->CurrentEntry == NULL) + if (ListUi->List->CurrentEntry == NULL) return; - if (List->Redraw) + if (ListUi->Redraw) { - DrawListEntries(List); - DrawScrollBarGenericList(List); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); } } + VOID SetCurrentListEntry( - PGENERIC_LIST List, - PGENERIC_LIST_ENTRY Entry) + IN PGENERIC_LIST List, + IN PGENERIC_LIST_ENTRY Entry) { if (Entry->List != List) return; @@ -581,7 +596,7 @@ SetCurrentListEntry( PGENERIC_LIST_ENTRY GetCurrentListEntry( - PGENERIC_LIST List) + IN PGENERIC_LIST List) { return List->CurrentEntry; } @@ -589,7 +604,7 @@ GetCurrentListEntry( PGENERIC_LIST_ENTRY GetFirstListEntry( - PGENERIC_LIST List) + IN PGENERIC_LIST List) { PLIST_ENTRY Entry = List->ListHead.Flink; @@ -601,7 +616,7 @@ GetFirstListEntry( PGENERIC_LIST_ENTRY GetNextListEntry( - PGENERIC_LIST_ENTRY Entry) + IN PGENERIC_LIST_ENTRY Entry) { PLIST_ENTRY Next = Entry->Entry.Flink; @@ -613,7 +628,7 @@ GetNextListEntry( PVOID GetListEntryUserData( - PGENERIC_LIST_ENTRY Entry) + IN PGENERIC_LIST_ENTRY Entry) { return Entry->UserData; } @@ -621,7 +636,7 @@ GetListEntryUserData( LPCSTR GetListEntryText( - PGENERIC_LIST_ENTRY Entry) + IN PGENERIC_LIST_ENTRY Entry) { return Entry->Text; } @@ -629,40 +644,42 @@ GetListEntryText( ULONG GetNumberOfListEntries( - PGENERIC_LIST List) + IN PGENERIC_LIST List) { return List->NumOfEntries; } + VOID GenericListKeyPress( - PGENERIC_LIST GenericList, - CHAR AsciiChar) + IN PGENERIC_LIST_UI ListUi, + IN CHAR AsciiChar) { + PGENERIC_LIST List = ListUi->List; PGENERIC_LIST_ENTRY ListEntry; PGENERIC_LIST_ENTRY OldListEntry; BOOLEAN Flag = FALSE; - ListEntry = GenericList->CurrentEntry; - OldListEntry = GenericList->CurrentEntry; + ListEntry = List->CurrentEntry; + OldListEntry = List->CurrentEntry; - GenericList->Redraw = FALSE; + ListUi->Redraw = FALSE; if ((strlen(ListEntry->Text) > 0) && (tolower(ListEntry->Text[0]) == AsciiChar) && - (GenericList->CurrentEntry->Entry.Flink != &GenericList->ListHead)) + (List->CurrentEntry->Entry.Flink != &List->ListHead)) { - ScrollDownGenericList(GenericList); - ListEntry = GenericList->CurrentEntry; + ScrollDownGenericList(ListUi); + ListEntry = List->CurrentEntry; if ((strlen(ListEntry->Text) > 0) && (tolower(ListEntry->Text[0]) == AsciiChar)) goto End; } - while (GenericList->CurrentEntry->Entry.Blink != &GenericList->ListHead) - ScrollUpGenericList(GenericList); + while (List->CurrentEntry->Entry.Blink != &List->ListHead) + ScrollUpGenericList(ListUi); - ListEntry = GenericList->CurrentEntry; + ListEntry = List->CurrentEntry; for (;;) { @@ -672,34 +689,35 @@ GenericListKeyPress( break; } - if (GenericList->CurrentEntry->Entry.Flink == &GenericList->ListHead) + if (List->CurrentEntry->Entry.Flink == &List->ListHead) break; - ScrollDownGenericList(GenericList); - ListEntry = GenericList->CurrentEntry; + ScrollDownGenericList(ListUi); + ListEntry = List->CurrentEntry; } if (!Flag) { - while (GenericList->CurrentEntry->Entry.Blink != &GenericList->ListHead) + while (List->CurrentEntry->Entry.Blink != &List->ListHead) { - if (GenericList->CurrentEntry != OldListEntry) - ScrollUpGenericList(GenericList); + if (List->CurrentEntry != OldListEntry) + ScrollUpGenericList(ListUi); else break; } } + End: - DrawListEntries(GenericList); - DrawScrollBarGenericList(GenericList); + DrawListEntries(ListUi); + DrawScrollBarGenericList(ListUi); - GenericList->Redraw = TRUE; + ListUi->Redraw = TRUE; } VOID SaveGenericListState( - PGENERIC_LIST List) + IN PGENERIC_LIST List) { List->BackupEntry = List->CurrentEntry; } @@ -707,15 +725,15 @@ SaveGenericListState( VOID RestoreGenericListState( - PGENERIC_LIST List) + IN PGENERIC_LIST List) { List->CurrentEntry = List->BackupEntry; } -BOOL +BOOLEAN GenericListHasSingleEntry( - PGENERIC_LIST List) + IN PGENERIC_LIST List) { if (!IsListEmpty(&List->ListHead) && List->ListHead.Flink == List->ListHead.Blink) return TRUE; diff --git a/base/setup/usetup/genlist.h b/base/setup/usetup/genlist.h index adc5c5c923..1c07ec3c3d 100644 --- a/base/setup/usetup/genlist.h +++ b/base/setup/usetup/genlist.h @@ -36,93 +36,115 @@ CreateGenericList(VOID); VOID DestroyGenericList( - PGENERIC_LIST List, - BOOLEAN FreeUserData); + IN OUT PGENERIC_LIST List, + IN BOOLEAN FreeUserData); BOOLEAN AppendGenericListEntry( - PGENERIC_LIST List, - PCHAR Text, - PVOID UserData, - BOOLEAN Current); - -VOID -DrawGenericList( - PGENERIC_LIST List, - SHORT Left, - SHORT Top, - SHORT Right, - SHORT Bottom); - -VOID -ScrollDownGenericList( - PGENERIC_LIST List); - -VOID -ScrollUpGenericList( - PGENERIC_LIST List); - -VOID -ScrollPageDownGenericList( - PGENERIC_LIST List); - -VOID -ScrollPageUpGenericList( - PGENERIC_LIST List); - -VOID -ScrollToPositionGenericList( - PGENERIC_LIST List, - ULONG uIndex); - -VOID -RedrawGenericList( - PGENERIC_LIST List); + IN OUT PGENERIC_LIST List, + IN PCHAR Text, + IN PVOID UserData, + IN BOOLEAN Current); VOID SetCurrentListEntry( - PGENERIC_LIST List, - PGENERIC_LIST_ENTRY Entry); + IN PGENERIC_LIST List, + IN PGENERIC_LIST_ENTRY Entry); PGENERIC_LIST_ENTRY GetCurrentListEntry( - PGENERIC_LIST List); + IN PGENERIC_LIST List); PGENERIC_LIST_ENTRY GetFirstListEntry( - PGENERIC_LIST List); + IN PGENERIC_LIST List); PGENERIC_LIST_ENTRY GetNextListEntry( - PGENERIC_LIST_ENTRY Entry); + IN PGENERIC_LIST_ENTRY Entry); PVOID GetListEntryUserData( - PGENERIC_LIST_ENTRY Entry); + IN PGENERIC_LIST_ENTRY Entry); LPCSTR GetListEntryText( - PGENERIC_LIST_ENTRY Entry); + IN PGENERIC_LIST_ENTRY Entry); ULONG GetNumberOfListEntries( - PGENERIC_LIST List); + IN PGENERIC_LIST List); VOID SaveGenericListState( - PGENERIC_LIST List); + IN PGENERIC_LIST List); VOID RestoreGenericListState( - PGENERIC_LIST List); + IN PGENERIC_LIST List); + +BOOLEAN +GenericListHasSingleEntry( + IN PGENERIC_LIST List); + + + + +typedef struct _GENERIC_LIST_UI +{ + PGENERIC_LIST List; + + PLIST_ENTRY FirstShown; + PLIST_ENTRY LastShown; + + SHORT Left; + SHORT Top; + SHORT Right; + SHORT Bottom; + BOOL Redraw; +} GENERIC_LIST_UI, *PGENERIC_LIST_UI; VOID -GenericListKeyPress( - PGENERIC_LIST GenericList, - CHAR AsciiChar); +InitGenericListUi( + IN OUT PGENERIC_LIST_UI ListUi, + IN PGENERIC_LIST List); -BOOL -GenericListHasSingleEntry( - PGENERIC_LIST List); +VOID +DrawGenericList( + IN PGENERIC_LIST_UI ListUi, + IN SHORT Left, + IN SHORT Top, + IN SHORT Right, + IN SHORT Bottom); + +VOID +ScrollDownGenericList( + IN PGENERIC_LIST_UI ListUi); + +VOID +ScrollUpGenericList( + IN PGENERIC_LIST_UI ListUi); + +VOID +ScrollPageDownGenericList( + IN PGENERIC_LIST_UI ListUi); + +VOID +ScrollPageUpGenericList( + IN PGENERIC_LIST_UI ListUi); + +VOID +ScrollToPositionGenericList( + IN PGENERIC_LIST_UI ListUi, + IN ULONG uIndex); + +VOID +RedrawGenericList( + IN PGENERIC_LIST_UI ListUi); + +VOID +GenericListKeyPress( + IN PGENERIC_LIST_UI ListUi, + IN CHAR AsciiChar); /* EOF */ diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 0fe4f16a57..49f3af72cc 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -640,6 +640,7 @@ UpdateKBLayout(VOID) static PAGE_NUMBER LanguagePage(PINPUT_RECORD Ir) { + GENERIC_LIST_UI ListUi; PWCHAR NewLanguageId; BOOL RefreshPage = FALSE; @@ -647,7 +648,6 @@ LanguagePage(PINPUT_RECORD Ir) if (LanguageList == NULL) { LanguageList = CreateLanguageList(SetupInf, DefaultLanguage); - if (LanguageList == NULL) { PopupError("Setup failed to initialize available translations", NULL, NULL, POPUP_WAIT_NONE); @@ -668,13 +668,14 @@ LanguagePage(PINPUT_RECORD Ir) return INTRO_PAGE; } - DrawGenericList(LanguageList, + InitGenericListUi(&ListUi, LanguageList); + DrawGenericList(&ListUi, 2, 18, xScreen - 3, yScreen - 3); - ScrollToPositionGenericList(LanguageList, GetDefaultLanguageIndex()); + ScrollToPositionGenericList(&ListUi, GetDefaultLanguageIndex()); MUIDisplayPage(LANGUAGE_PAGE); @@ -685,25 +686,25 @@ LanguagePage(PINPUT_RECORD Ir) if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */ { - ScrollDownGenericList(LanguageList); + ScrollDownGenericList(&ListUi); RefreshPage = TRUE; } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */ { - ScrollUpGenericList(LanguageList); + ScrollUpGenericList(&ListUi); RefreshPage = TRUE; } if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_NEXT)) /* PAGE DOWN */ { - ScrollPageDownGenericList(LanguageList); + ScrollPageDownGenericList(&ListUi); RefreshPage = TRUE; } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_PRIOR)) /* PAGE UP */ { - ScrollPageUpGenericList(LanguageList); + ScrollPageUpGenericList(&ListUi); RefreshPage = TRUE; } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && @@ -712,7 +713,7 @@ LanguagePage(PINPUT_RECORD Ir) if (ConfirmQuit(Ir) != FALSE) return QUIT_PAGE; else - RedrawGenericList(LanguageList); + RedrawGenericList(&ListUi); } else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */ { @@ -733,7 +734,7 @@ LanguagePage(PINPUT_RECORD Ir) else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) && (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b)) { /* a-z */ - GenericListKeyPress(LanguageList, Ir->Event.KeyEvent.uChar.AsciiChar); + GenericListKeyPress(&ListUi, Ir->Event.KeyEvent.uChar.AsciiChar); RefreshPage = TRUE; } @@ -915,12 +916,11 @@ SetupStartPage(PINPUT_RECORD Ir) LanguageList = CreateLanguageList(SetupInf, DefaultLanguage); /* new part */ - wcscpy(SelectedLanguageId,LocaleID); + wcscpy(SelectedLanguageId, LocaleID); LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF); /* first we hack LanguageList */ ListEntry = GetFirstListEntry(LanguageList); - while (ListEntry != NULL) { if (!wcsicmp(LocaleID, GetListEntryUserData(ListEntry))) @@ -935,7 +935,6 @@ SetupStartPage(PINPUT_RECORD Ir) /* now LayoutList */ ListEntry = GetFirstListEntry(LayoutList); - while (ListEntry != NULL) { if (!wcsicmp(LocaleID, GetListEntryUserData(ListEntry))) @@ -1319,7 +1318,7 @@ DeviceSettingsPage(PINPUT_RECORD Ir) * Ir: The PINPUT_RECORD */ static PAGE_NUMBER -HandleGenericList(PGENERIC_LIST GenericList, +HandleGenericList(PGENERIC_LIST_UI ListUi, PAGE_NUMBER nextPage, PINPUT_RECORD Ir) { @@ -1330,36 +1329,36 @@ HandleGenericList(PGENERIC_LIST GenericList, if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_DOWN)) /* DOWN */ { - ScrollDownGenericList(GenericList); + ScrollDownGenericList(ListUi); } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_UP)) /* UP */ { - ScrollUpGenericList(GenericList); + ScrollUpGenericList(ListUi); } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_NEXT)) /* PAGE DOWN */ { - ScrollPageDownGenericList(GenericList); + ScrollPageDownGenericList(ListUi); } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_PRIOR)) /* PAGE UP */ { - ScrollPageUpGenericList(GenericList); + ScrollPageUpGenericList(ListUi); } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_F3)) /* F3 */ { if (ConfirmQuit(Ir) != FALSE) return QUIT_PAGE; - - continue; + else + RedrawGenericList(ListUi); } else if ((Ir->Event.KeyEvent.uChar.AsciiChar == 0x00) && (Ir->Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)) /* ESC */ { - RestoreGenericListState(GenericList); - return nextPage; + RestoreGenericListState(ListUi->List); + return nextPage; // Use some "prevPage;" instead? } else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */ { @@ -1368,7 +1367,7 @@ HandleGenericList(PGENERIC_LIST GenericList, else if ((Ir->Event.KeyEvent.uChar.AsciiChar > 0x60) && (Ir->Event.KeyEvent.uChar.AsciiChar < 0x7b)) { /* a-z */ - GenericListKeyPress(GenericList, Ir->Event.KeyEvent.uChar.AsciiChar); + GenericListKeyPress(ListUi, Ir->Event.KeyEvent.uChar.AsciiChar); } } } @@ -1387,9 +1386,11 @@ HandleGenericList(PGENERIC_LIST GenericList, static PAGE_NUMBER ComputerSettingsPage(PINPUT_RECORD Ir) { + GENERIC_LIST_UI ListUi; MUIDisplayPage(COMPUTER_SETTINGS_PAGE); - DrawGenericList(ComputerList, + InitGenericListUi(&ListUi, ComputerList); + DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1397,7 +1398,7 @@ ComputerSettingsPage(PINPUT_RECORD Ir) SaveGenericListState(ComputerList); - return HandleGenericList(ComputerList, DEVICE_SETTINGS_PAGE, Ir); + return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir); } @@ -1414,9 +1415,11 @@ ComputerSettingsPage(PINPUT_RECORD Ir) static PAGE_NUMBER DisplaySettingsPage(PINPUT_RECORD Ir) { + GENERIC_LIST_UI ListUi; MUIDisplayPage(DISPLAY_SETTINGS_PAGE); - DrawGenericList(DisplayList, + InitGenericListUi(&ListUi, DisplayList); + DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1424,7 +1427,7 @@ DisplaySettingsPage(PINPUT_RECORD Ir) SaveGenericListState(DisplayList); - return HandleGenericList(DisplayList, DEVICE_SETTINGS_PAGE, Ir); + return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir); } @@ -1441,9 +1444,11 @@ DisplaySettingsPage(PINPUT_RECORD Ir) static PAGE_NUMBER KeyboardSettingsPage(PINPUT_RECORD Ir) { + GENERIC_LIST_UI ListUi; MUIDisplayPage(KEYBOARD_SETTINGS_PAGE); - DrawGenericList(KeyboardList, + InitGenericListUi(&ListUi, KeyboardList); + DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1451,7 +1456,7 @@ KeyboardSettingsPage(PINPUT_RECORD Ir) SaveGenericListState(KeyboardList); - return HandleGenericList(KeyboardList, DEVICE_SETTINGS_PAGE, Ir); + return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir); } @@ -1468,9 +1473,11 @@ KeyboardSettingsPage(PINPUT_RECORD Ir) static PAGE_NUMBER LayoutSettingsPage(PINPUT_RECORD Ir) { + GENERIC_LIST_UI ListUi; MUIDisplayPage(LAYOUT_SETTINGS_PAGE); - DrawGenericList(LayoutList, + InitGenericListUi(&ListUi, LayoutList); + DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1478,7 +1485,7 @@ LayoutSettingsPage(PINPUT_RECORD Ir) SaveGenericListState(LayoutList); - return HandleGenericList(LayoutList, DEVICE_SETTINGS_PAGE, Ir); + return HandleGenericList(&ListUi, DEVICE_SETTINGS_PAGE, Ir); } @@ -2945,7 +2952,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) * RETURNS * Number of the next page. */ -static ULONG +static PAGE_NUMBER FormatPartitionPage(PINPUT_RECORD Ir) { UNICODE_STRING PartitionRootPath; @@ -3135,7 +3142,7 @@ FormatPartitionPage(PINPUT_RECORD Ir) * RETURNS * Number of the next page. */ -static ULONG +static PAGE_NUMBER CheckFileSystemPage(PINPUT_RECORD Ir) { PFILE_SYSTEM_ITEM CurrentFileSystem; @@ -3996,8 +4003,7 @@ FileCopyCallback(PVOID Context, * RETURNS * Number of the next page. */ -static -PAGE_NUMBER +static PAGE_NUMBER FileCopyPage(PINPUT_RECORD Ir) { COPYCONTEXT CopyContext; @@ -4194,7 +4200,6 @@ RegistryPage(PINPUT_RECORD Ir) } /* Set GeoID */ - if (!SetGeoID(MUIGetGeoID())) { MUIDisplayError(ERROR_UPDATE_GEOID, Ir, POPUP_WAIT_ENTER); @@ -4428,7 +4433,7 @@ BootLoaderFloppyPage(PINPUT_RECORD Ir) MUIDisplayPage(BOOT_LOADER_FLOPPY_PAGE); -// SetStatusText(" Please wait..."); +// CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); while (TRUE) { @@ -4592,48 +4597,49 @@ QuitPage(PINPUT_RECORD Ir) { MUIDisplayPage(QUIT_PAGE); - /* Destroy partition list */ + /* Destroy the partition list */ if (PartitionList != NULL) { DestroyPartitionList(PartitionList); PartitionList = NULL; } - /* Destroy filesystem list */ + /* Destroy the filesystem list */ if (FileSystemList != NULL) { DestroyFileSystemList(FileSystemList); FileSystemList = NULL; } - /* Destroy computer settings list */ + /* Destroy the computer settings list */ if (ComputerList != NULL) { DestroyGenericList(ComputerList, TRUE); ComputerList = NULL; } - /* Destroy display settings list */ + /* Destroy the display settings list */ if (DisplayList != NULL) { DestroyGenericList(DisplayList, TRUE); DisplayList = NULL; } - /* Destroy keyboard settings list */ + /* Destroy the keyboard settings list */ if (KeyboardList != NULL) { DestroyGenericList(KeyboardList, TRUE); KeyboardList = NULL; } - /* Destroy keyboard layout list */ + /* Destroy the keyboard layout list */ if (LayoutList != NULL) { DestroyGenericList(LayoutList, TRUE); LayoutList = NULL; } + /* Destroy the languages list */ if (LanguageList != NULL) { DestroyGenericList(LanguageList, FALSE); @@ -4723,6 +4729,7 @@ RunUSetup(VOID) NtQuerySystemTime(&Time); + /* Create the PnP thread in suspended state */ Status = RtlCreateUserThread(NtCurrentProcess(), NULL, TRUE, @@ -4800,9 +4807,7 @@ RunUSetup(VOID) case SCSI_CONTROLLER_PAGE: Page = ScsiControllerPage(&Ir); break; -#endif -#if 0 case OEM_DRIVER_PAGE: Page = OemDriverPage(&Ir); break; @@ -4857,11 +4862,11 @@ RunUSetup(VOID) break; case FORMAT_PARTITION_PAGE: - Page = (PAGE_NUMBER) FormatPartitionPage(&Ir); + Page = FormatPartitionPage(&Ir); break; case CHECK_FILE_SYSTEM_PAGE: - Page = (PAGE_NUMBER) CheckFileSystemPage(&Ir); + Page = CheckFileSystemPage(&Ir); break; case INSTALL_DIRECTORY_PAGE:
6 years, 7 months
1
0
0
0
02/04: [USETUP] Additions for generic lists.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=199fb91939fb8d395af50…
commit 199fb91939fb8d395af504d620f3564dbfca4e51 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Mon May 15 01:43:28 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 22:45:50 2018 +0200 [USETUP] Additions for generic lists. - Allow retrieving the number of items existing in the list; - Fix the name of some function parameters. svn path=/branches/setup_improvements/; revision=74547 --- base/setup/usetup/genlist.c | 20 ++++++++++++++++---- base/setup/usetup/genlist.h | 12 ++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/base/setup/usetup/genlist.c b/base/setup/usetup/genlist.c index c6b0b536d1..5f79a906bf 100644 --- a/base/setup/usetup/genlist.c +++ b/base/setup/usetup/genlist.c @@ -45,6 +45,7 @@ typedef struct _GENERIC_LIST_ENTRY typedef struct _GENERIC_LIST { LIST_ENTRY ListHead; + ULONG NumOfEntries; PLIST_ENTRY FirstShown; PLIST_ENTRY LastShown; @@ -70,6 +71,7 @@ CreateGenericList(VOID) return NULL; InitializeListHead(&List->ListHead); + List->NumOfEntries = 0; List->Left = 0; List->Top = 0; @@ -78,6 +80,7 @@ CreateGenericList(VOID) List->Redraw = TRUE; List->CurrentEntry = NULL; + List->BackupEntry = NULL; return List; } @@ -131,6 +134,7 @@ AppendGenericListEntry( InsertTailList(&List->ListHead, &Entry->Entry); + List->NumOfEntries++; if (Current || List->CurrentEntry == NULL) { @@ -609,17 +613,25 @@ GetNextListEntry( PVOID GetListEntryUserData( - PGENERIC_LIST_ENTRY List) + PGENERIC_LIST_ENTRY Entry) { - return List->UserData; + return Entry->UserData; } LPCSTR GetListEntryText( - PGENERIC_LIST_ENTRY List) + PGENERIC_LIST_ENTRY Entry) +{ + return Entry->Text; +} + + +ULONG +GetNumberOfListEntries( + PGENERIC_LIST List) { - return List->Text; + return List->NumOfEntries; } diff --git a/base/setup/usetup/genlist.h b/base/setup/usetup/genlist.h index 0361d2b888..adc5c5c923 100644 --- a/base/setup/usetup/genlist.h +++ b/base/setup/usetup/genlist.h @@ -98,11 +98,15 @@ GetNextListEntry( PVOID GetListEntryUserData( - PGENERIC_LIST_ENTRY List); + PGENERIC_LIST_ENTRY Entry); LPCSTR GetListEntryText( - PGENERIC_LIST_ENTRY List); + PGENERIC_LIST_ENTRY Entry); + +ULONG +GetNumberOfListEntries( + PGENERIC_LIST List); VOID SaveGenericListState( @@ -114,8 +118,8 @@ RestoreGenericListState( VOID GenericListKeyPress( - PGENERIC_LIST List, - CHAR AsciChar); + PGENERIC_LIST GenericList, + CHAR AsciiChar); BOOL GenericListHasSingleEntry(
6 years, 7 months
1
0
0
0
01/04: [USETUP] Additions for the PartList code.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2521d3c4787c60fc1b19c…
commit 2521d3c4787c60fc1b19c22ab82fd7a64a5600a9 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat May 13 16:40:30 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 22:45:39 2018 +0200 [USETUP] Additions for the PartList code. - Document more some of the fields in the PARTENTRY, DISKETNRY and PARTLIST structures; - Remove the redundant members "SystemDisk", "OriginalSystemDisk" and "TempDisk" in PARTLIST as these can be consistently deduced from the corresponding (Original)(System)(Temp)Partition members (note that we however keep "CurrentDisk" alongside "CurrentPartition", see the comment in the code why we do it so). - Adjust the rest of the code to take the removal of the redundant members into account. The 2nd parameter of GetNextUnformattedPartition() and GetNextUncheckedPartition() is now really optional. - Introduce a SetPartitionType() helper to simplify the code that sets the partition type, which also automatically adjusts other internal variables of said partition in accordance. - "Mounted" logical drives can have assigned letters too, registered in \DosDevices\. svn path=/branches/setup_improvements/; revision=74532 --- base/setup/usetup/partlist.c | 176 ++++++++++++++++++++++++++++++------------- base/setup/usetup/partlist.h | 50 +++++++++--- base/setup/usetup/usetup.c | 48 ++++-------- 3 files changed, 176 insertions(+), 98 deletions(-) diff --git a/base/setup/usetup/partlist.c b/base/setup/usetup/partlist.c index 22867b73a4..7d52208bad 100644 --- a/base/setup/usetup/partlist.c +++ b/base/setup/usetup/partlist.c @@ -700,10 +700,28 @@ AddPartitionToDisk( if (IsContainerPartition(PartEntry->PartitionType)) { PartEntry->FormatState = Unformatted; + PartEntry->FileSystem = NULL; if (LogicalPartition == FALSE && DiskEntry->ExtendedPartition == NULL) DiskEntry->ExtendedPartition = PartEntry; } +#if 0 + else if (IsRecognizedPartition(PartEntry->PartitionType)) + { + // FIXME FIXME! We should completely rework how we get this 'FileSystemList' available... + PartEntry->FileSystem = GetFileSystem(FileSystemList, PartEntry); + if (!PartEntry->FileSystem) + PartEntry->FormatState = Preformatted; + else + PartEntry->FormatState = Unformatted; + // PartEntry->FormatState = UnknownFormat; + } + else + { + /* Unknown partition, so unknown partition format (may or may not be actually formatted) */ + PartEntry->FormatState = UnknownFormat; + } +#endif else if ((PartEntry->PartitionType == PARTITION_FAT_12) || (PartEntry->PartitionType == PARTITION_FAT_16) || (PartEntry->PartitionType == PARTITION_HUGE) || @@ -806,6 +824,7 @@ ScanForUnpartitionedDiskSpace( DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; InsertTailList(&DiskEntry->PrimaryPartListHead, &NewPartEntry->ListEntry); @@ -852,6 +871,7 @@ ScanForUnpartitionedDiskSpace( DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; /* Insert the table into the list */ InsertTailList(&PartEntry->ListEntry, @@ -892,6 +912,7 @@ ScanForUnpartitionedDiskSpace( DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; /* Append the table to the list */ InsertTailList(&DiskEntry->PrimaryPartListHead, @@ -924,6 +945,7 @@ ScanForUnpartitionedDiskSpace( DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; InsertTailList(&DiskEntry->LogicalPartListHead, &NewPartEntry->ListEntry); @@ -971,6 +993,7 @@ ScanForUnpartitionedDiskSpace( DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; /* Insert the table into the list */ InsertTailList(&PartEntry->ListEntry, @@ -1012,6 +1035,7 @@ ScanForUnpartitionedDiskSpace( DPRINT("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; /* Append the table to the list */ InsertTailList(&DiskEntry->LogicalPartListHead, @@ -1158,6 +1182,11 @@ AddDiskToList( if (!NT_SUCCESS(Status)) return; + /* + * Check whether the disk is initialized, by looking at its MBR. + * NOTE that this must be generalized to GPT disks as well! + */ + Mbr = (PARTITION_SECTOR*)RtlAllocateHeap(ProcessHeap, 0, DiskGeometry.BytesPerSector); @@ -1207,6 +1236,7 @@ AddDiskToList( DiskEntry->BiosFound = FALSE; /* Check if this disk has a valid MBR */ + // FIXME: Check for the MBR signature as well, etc... if (Mbr->BootCode[0] == 0 && Mbr->BootCode[1] == 0) DiskEntry->NoMbr = TRUE; else @@ -1215,6 +1245,7 @@ AddDiskToList( /* Free the MBR sector buffer */ RtlFreeHeap(ProcessHeap, 0, Mbr); + ListEntry = List->BiosDiskListHead.Flink; while (ListEntry != &List->BiosDiskListHead) { @@ -1422,12 +1453,9 @@ CreatePartitionList( List->CurrentDisk = NULL; List->CurrentPartition = NULL; - List->SystemDisk = NULL; List->SystemPartition = NULL; - List->OriginalSystemDisk = NULL; List->OriginalSystemPartition = NULL; - List->TempDisk = NULL; List->TempPartition = NULL; List->FormatState = Start; @@ -2739,6 +2767,7 @@ CreatePrimaryPartition( PartEntry->IsPartitioned = TRUE; PartEntry->PartitionType = PARTITION_ENTRY_UNUSED; PartEntry->FormatState = Unformatted; + PartEntry->FileSystem = NULL; PartEntry->AutoCreate = AutoCreate; PartEntry->New = TRUE; PartEntry->BootIndicator = FALSE; @@ -2776,6 +2805,7 @@ CreatePrimaryPartition( NewPartEntry->New = TRUE; NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; NewPartEntry->BootIndicator = FALSE; PartEntry->StartSector.QuadPart = NewPartEntry->StartSector.QuadPart + NewPartEntry->SectorCount.QuadPart; @@ -2818,6 +2848,7 @@ AddLogicalDiskSpace( DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart); NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; InsertTailList(&DiskEntry->LogicalPartListHead, &NewPartEntry->ListEntry); @@ -2854,7 +2885,8 @@ CreateExtendedPartition( /* Convert current entry to 'new (unformatted)' */ PartEntry->IsPartitioned = TRUE; - PartEntry->FormatState = Formatted; + PartEntry->FormatState = Formatted; // FIXME? Possibly to make GetNextUnformattedPartition work (i.e. skip the extended partition container) + PartEntry->FileSystem = NULL; PartEntry->AutoCreate = FALSE; PartEntry->New = FALSE; PartEntry->BootIndicator = FALSE; @@ -2899,7 +2931,8 @@ CreateExtendedPartition( NewPartEntry->StartSector.QuadPart; NewPartEntry->New = FALSE; - NewPartEntry->FormatState = Formatted; + NewPartEntry->FormatState = Formatted; // FIXME? Possibly to make GetNextUnformattedPartition work (i.e. skip the extended partition container) + NewPartEntry->FileSystem = NULL; NewPartEntry->BootIndicator = FALSE; if (NewPartEntry->StartSector.QuadPart < 1450560) @@ -2967,6 +3000,7 @@ CreateLogicalPartition( PartEntry->IsPartitioned = TRUE; PartEntry->PartitionType = PARTITION_ENTRY_UNUSED; PartEntry->FormatState = Unformatted; + PartEntry->FileSystem = NULL; PartEntry->AutoCreate = FALSE; PartEntry->New = TRUE; PartEntry->BootIndicator = FALSE; @@ -3005,6 +3039,7 @@ CreateLogicalPartition( NewPartEntry->New = TRUE; NewPartEntry->FormatState = Unformatted; + NewPartEntry->FileSystem = NULL; NewPartEntry->BootIndicator = FALSE; NewPartEntry->LogicalPartition = TRUE; @@ -3042,7 +3077,6 @@ DeleteCurrentPartition( /* Clear the system disk and partition pointers if the system partition is being deleted */ if (List->SystemPartition == List->CurrentPartition) { - List->SystemDisk = NULL; List->SystemPartition = NULL; } @@ -3122,6 +3156,7 @@ DeleteCurrentPartition( PartEntry->IsPartitioned = FALSE; PartEntry->PartitionType = PARTITION_ENTRY_UNUSED; PartEntry->FormatState = Unformatted; + PartEntry->FileSystem = NULL; PartEntry->DriveLetter = 0; } @@ -3148,9 +3183,7 @@ CheckActiveSystemPartition( /* Check for empty disk list */ if (IsListEmpty(&List->DiskListHead)) { - List->SystemDisk = NULL; List->SystemPartition = NULL; - List->OriginalSystemDisk = NULL; List->OriginalSystemPartition = NULL; return; } @@ -3161,35 +3194,31 @@ CheckActiveSystemPartition( /* Check for empty partition list */ if (IsListEmpty(&DiskEntry->PrimaryPartListHead)) { - List->SystemDisk = NULL; List->SystemPartition = NULL; - List->OriginalSystemDisk = NULL; List->OriginalSystemPartition = NULL; return; } - if (List->SystemDisk != NULL && List->SystemPartition != NULL) + if (List->SystemPartition != NULL) { /* We already have an active system partition */ DPRINT1("Use the current system partition %lu in disk %lu, drive letter %c\n", List->SystemPartition->PartitionNumber, - List->SystemDisk->DiskNumber, + List->SystemPartition->DiskEntry->DiskNumber, (List->SystemPartition->DriveLetter == 0) ? '-' : List->SystemPartition->DriveLetter); return; } DPRINT1("We are here (1)!\n"); - List->SystemDisk = NULL; List->SystemPartition = NULL; - List->OriginalSystemDisk = NULL; List->OriginalSystemPartition = NULL; /* Retrieve the first partition of the disk */ PartEntry = CONTAINING_RECORD(DiskEntry->PrimaryPartListHead.Flink, PARTENTRY, ListEntry); - List->SystemDisk = DiskEntry; + ASSERT(DiskEntry == PartEntry->DiskEntry); List->SystemPartition = PartEntry; // @@ -3201,16 +3230,14 @@ CheckActiveSystemPartition( { if (PartEntry->PartitionType == PARTITION_ENTRY_UNUSED || PartEntry->BootIndicator == FALSE) { - /* FIXME: Might be incorrect if partitions were created by Linux FDISK */ - List->SystemDisk = DiskEntry; + ASSERT(DiskEntry == PartEntry->DiskEntry); List->SystemPartition = PartEntry; - List->OriginalSystemDisk = List->SystemDisk; List->OriginalSystemPartition = List->SystemPartition; DPRINT1("Use new first active system partition %lu in disk %lu, drive letter %c\n", List->SystemPartition->PartitionNumber, - List->SystemDisk->DiskNumber, + List->SystemPartition->DiskEntry->DiskNumber, (List->SystemPartition->DriveLetter == 0) ? '-' : List->SystemPartition->DriveLetter); goto SetSystemPartition; @@ -3249,22 +3276,18 @@ CheckActiveSystemPartition( * OK we haven't encountered any used and active partition, * so use the first one as the system partition. */ - - /* FIXME: Might be incorrect if partitions were created by Linux FDISK */ - List->OriginalSystemDisk = List->SystemDisk; // DiskEntry + ASSERT(DiskEntry == List->SystemPartition->DiskEntry); List->OriginalSystemPartition = List->SystemPartition; // First PartEntry DPRINT1("Use first active system partition %lu in disk %lu, drive letter %c\n", List->SystemPartition->PartitionNumber, - List->SystemDisk->DiskNumber, + List->SystemPartition->DiskEntry->DiskNumber, (List->SystemPartition->DriveLetter == 0) ? '-' : List->SystemPartition->DriveLetter); goto SetSystemPartition; } - List->SystemDisk = NULL; List->SystemPartition = NULL; - List->OriginalSystemDisk = NULL; List->OriginalSystemPartition = NULL; DPRINT1("We are here (3)!\n"); @@ -3287,7 +3310,7 @@ CheckActiveSystemPartition( if (PartEntry->BootIndicator) { /* Yes, we found it */ - List->SystemDisk = DiskEntry; + ASSERT(DiskEntry == PartEntry->DiskEntry); List->SystemPartition = PartEntry; DPRINT1("Found active system partition %lu in disk %lu, drive letter %c\n", @@ -3300,15 +3323,14 @@ CheckActiveSystemPartition( } /* Check if we have found the system partition */ - if (List->SystemDisk == NULL || List->SystemPartition == NULL) + if (List->SystemPartition == NULL) { /* Nothing, use the alternative system partition */ DPRINT1("No system partition found, use the alternative partition!\n"); goto UseAlternativeSystemPartition; } - /* Save them */ - List->OriginalSystemDisk = List->SystemDisk; + /* Save it */ List->OriginalSystemPartition = List->SystemPartition; /* @@ -3332,7 +3354,7 @@ CheckActiveSystemPartition( { DPRINT1("System partition %lu in disk %lu with no FS?!\n", List->OriginalSystemPartition->PartitionNumber, - List->OriginalSystemDisk->DiskNumber); + List->OriginalSystemPartition->DiskEntry->DiskNumber); goto FindAndUseAlternativeSystemPartition; } // HACK: WARNING: We cannot write on this FS yet! @@ -3347,7 +3369,7 @@ CheckActiveSystemPartition( DPRINT1("Use existing active system partition %lu in disk %lu, drive letter %c\n", List->SystemPartition->PartitionNumber, - List->SystemDisk->DiskNumber, + List->SystemPartition->DiskEntry->DiskNumber, (List->SystemPartition->DriveLetter == 0) ? '-' : List->SystemPartition->DriveLetter); return; @@ -3364,25 +3386,24 @@ FindAndUseAlternativeSystemPartition: /* Unset the old system partition */ List->SystemPartition->BootIndicator = FALSE; - List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator = FALSE; - List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition = TRUE; - List->SystemDisk->Dirty = TRUE; + List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator = FALSE; + List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition = TRUE; + List->SystemPartition->DiskEntry->Dirty = TRUE; UseAlternativeSystemPartition: - List->SystemDisk = List->CurrentDisk; List->SystemPartition = List->CurrentPartition; DPRINT1("Use alternative active system partition %lu in disk %lu, drive letter %c\n", List->SystemPartition->PartitionNumber, - List->SystemDisk->DiskNumber, + List->SystemPartition->DiskEntry->DiskNumber, (List->SystemPartition->DriveLetter == 0) ? '-' : List->SystemPartition->DriveLetter); SetSystemPartition: /* Set the new active system partition */ List->SystemPartition->BootIndicator = TRUE; - List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator = TRUE; - List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition = TRUE; - List->SystemDisk->Dirty = TRUE; + List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator = TRUE; + List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition = TRUE; + List->SystemPartition->DiskEntry->Dirty = TRUE; } @@ -3449,6 +3470,16 @@ WritePartitions( if (FileHandle != NULL) NtClose(FileHandle); + // + // NOTE: Originally (see r40437), we used to install here also a new MBR + // for this disk (by calling InstallMbrBootCodeToDisk), only if: + // DiskEntry->NewDisk == TRUE and DiskEntry->BiosDiskNumber == 0. + // Then after that, both DiskEntry->NewDisk and DiskEntry->NoMbr were set + // to FALSE. In the other place (in usetup.c) where InstallMbrBootCodeToDisk + // was called too, the installation test was modified by checking whether + // DiskEntry->NoMbr was TRUE (instead of NewDisk). + // + return Status; } @@ -3522,12 +3553,47 @@ SetMountedDeviceValues( Entry2 = Entry2->Flink; } + Entry2 = DiskEntry->LogicalPartListHead.Flink; + while (Entry2 != &DiskEntry->LogicalPartListHead) + { + PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); + if (PartEntry->IsPartitioned) + { + /* Assign a "\DosDevices\#:" mount point to this partition */ + if (PartEntry->DriveLetter) + { + StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector; + if (!SetMountedDeviceValue(PartEntry->DriveLetter, + DiskEntry->LayoutBuffer->Signature, + StartingOffset)) + { + return FALSE; + } + } + } + + Entry2 = Entry2->Flink; + } + Entry1 = Entry1->Flink; } return TRUE; } +VOID +SetPartitionType( + IN PPARTENTRY PartEntry, + IN UCHAR PartitionType) +{ + PDISKENTRY DiskEntry = PartEntry->DiskEntry; + + PartEntry->PartitionType = PartitionType; + + DiskEntry->Dirty = TRUE; + DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartitionType; + DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition = TRUE; +} ULONG PrimaryPartitionCreationChecks( @@ -3618,9 +3684,10 @@ GetNextUnformattedPartition( PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); if (PartEntry->IsPartitioned && PartEntry->New) { - *pDiskEntry = DiskEntry; - *pPartEntry = PartEntry; - return TRUE; + ASSERT(DiskEntry == PartEntry->DiskEntry); + if (pDiskEntry) *pDiskEntry = DiskEntry; + *pPartEntry = PartEntry; + return TRUE; } Entry2 = Entry2->Flink; @@ -3632,9 +3699,10 @@ GetNextUnformattedPartition( PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); if (PartEntry->IsPartitioned && PartEntry->New) { - *pDiskEntry = DiskEntry; - *pPartEntry = PartEntry; - return TRUE; + ASSERT(DiskEntry == PartEntry->DiskEntry); + if (pDiskEntry) *pDiskEntry = DiskEntry; + *pPartEntry = PartEntry; + return TRUE; } Entry2 = Entry2->Flink; @@ -3643,7 +3711,7 @@ GetNextUnformattedPartition( Entry1 = Entry1->Flink; } - *pDiskEntry = NULL; + if (pDiskEntry) *pDiskEntry = NULL; *pPartEntry = NULL; return FALSE; @@ -3672,9 +3740,10 @@ GetNextUncheckedPartition( PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); if (PartEntry->NeedsCheck == TRUE) { - *pDiskEntry = DiskEntry; - *pPartEntry = PartEntry; - return TRUE; + ASSERT(DiskEntry == PartEntry->DiskEntry); + if (pDiskEntry) *pDiskEntry = DiskEntry; + *pPartEntry = PartEntry; + return TRUE; } Entry2 = Entry2->Flink; @@ -3686,9 +3755,10 @@ GetNextUncheckedPartition( PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); if (PartEntry->NeedsCheck == TRUE) { - *pDiskEntry = DiskEntry; - *pPartEntry = PartEntry; - return TRUE; + ASSERT(DiskEntry == PartEntry->DiskEntry); + if (pDiskEntry) *pDiskEntry = DiskEntry; + *pPartEntry = PartEntry; + return TRUE; } Entry2 = Entry2->Flink; @@ -3697,7 +3767,7 @@ GetNextUncheckedPartition( Entry1 = Entry1->Flink; } - *pDiskEntry = NULL; + if (pDiskEntry) *pDiskEntry = NULL; *pPartEntry = NULL; return FALSE; diff --git a/base/setup/usetup/partlist.h b/base/setup/usetup/partlist.h index 9787f94ae3..35c83b3f17 100644 --- a/base/setup/usetup/partlist.h +++ b/base/setup/usetup/partlist.h @@ -51,16 +51,18 @@ typedef struct _PARTENTRY { LIST_ENTRY ListEntry; + /* The disk this partition belongs to */ struct _DISKENTRY *DiskEntry; + /* Partition geometry */ ULARGE_INTEGER StartSector; ULARGE_INTEGER SectorCount; BOOLEAN BootIndicator; UCHAR PartitionType; ULONG HiddenSectors; - ULONG PartitionNumber; - ULONG PartitionIndex; + ULONG PartitionNumber; /* Enumerated partition number (primary partitions first -- excluding the extended partition container --, then the logical partitions) */ + ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */ CHAR DriveLetter; @@ -75,12 +77,12 @@ typedef struct _PARTENTRY /* Partition was created automatically */ BOOLEAN AutoCreate; - FORMATSTATE FormatState; - /* Partition must be checked */ BOOLEAN NeedsCheck; + FORMATSTATE FormatState; struct _FILE_SYSTEM_ITEM *FileSystem; + } PARTENTRY, *PPARTENTRY; @@ -100,6 +102,8 @@ typedef struct _DISKENTRY { LIST_ENTRY ListEntry; + /* Disk geometry */ + ULONGLONG Cylinders; ULONG TracksPerCylinder; ULONG SectorsPerTrack; @@ -109,11 +113,13 @@ typedef struct _DISKENTRY ULONG SectorAlignment; ULONG CylinderAlignment; + /* BIOS parameters */ BOOLEAN BiosFound; ULONG BiosDiskNumber; // ULONG Signature; // ULONG Checksum; + /* SCSI parameters */ ULONG DiskNumber; USHORT Port; USHORT Bus; @@ -123,12 +129,17 @@ typedef struct _DISKENTRY BOOLEAN Dirty; BOOLEAN NewDisk; - BOOLEAN NoMbr; /* MBR is absent */ + BOOLEAN NoMbr; /* MBR is absent */ // See r40437 UNICODE_STRING DriverName; PDRIVE_LAYOUT_INFORMATION LayoutBuffer; + // TODO: When adding support for GPT disks: + // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether + // the disk is MBR, GPT, or unknown (uninitialized). + // Depending on the style, either use the MBR or GPT partition info. + /* Pointer to the unique extended partition on this disk */ PPARTENTRY ExtendedPartition; LIST_ENTRY PrimaryPartListHead; @@ -139,6 +150,7 @@ typedef struct _DISKENTRY typedef struct _PARTLIST { + /* UI stuff */ SHORT Left; SHORT Top; SHORT Right; @@ -147,23 +159,32 @@ typedef struct _PARTLIST SHORT Line; SHORT Offset; + /* + * NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry + * must be the same as CurrentDisk. We should however keep the two members + * separated as we can have a current (selected) disk without any current + * partition, if the former does not contain any. + */ PDISKENTRY CurrentDisk; PPARTENTRY CurrentPartition; - /* The system disk and partition where the boot manager resides */ - PDISKENTRY SystemDisk; + /* + * The system partition where the boot manager resides. + * The corresponding system disk is obtained via: + * SystemPartition->DiskEntry. + */ PPARTENTRY SystemPartition; /* - * The original system disk and partition in case we are redefining them - * because we do not have write support on them. - * Please not that this is partly a HACK and MUST NEVER happen on + * The original system partition in case we are redefining it because + * we do not have write support on it. + * Please note that this is partly a HACK and MUST NEVER happen on * architectures where real system partitions are mandatory (because then * they are formatted in FAT FS and we support write operation on them). + * The corresponding original system disk is obtained via: + * OriginalSystemPartition->DiskEntry. */ - PDISKENTRY OriginalSystemDisk; PPARTENTRY OriginalSystemPartition; - PDISKENTRY TempDisk; PPARTENTRY TempPartition; FORMATMACHINESTATE FormatState; @@ -278,6 +299,11 @@ BOOLEAN SetMountedDeviceValues( IN PPARTLIST List); +VOID +SetPartitionType( + IN PPARTENTRY PartEntry, + IN UCHAR PartitionType); + ULONG PrimaryPartitionCreationChecks( IN PPARTLIST List); diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 234bfa45be..0fe4f16a57 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -2657,9 +2657,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) /* Find or set the active system partition */ CheckActiveSystemPartition(PartitionList, FileSystemList); - - if (PartitionList->SystemDisk == NULL || - PartitionList->SystemPartition == NULL) + if (PartitionList->SystemPartition == NULL) { /* FIXME: show an error dialog */ return QUIT_PAGE; @@ -2671,7 +2669,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir) case Start: if (PartitionList->CurrentPartition != PartitionList->SystemPartition) { - PartitionList->TempDisk = PartitionList->SystemDisk; PartitionList->TempPartition = PartitionList->SystemPartition; PartitionList->TempPartition->NeedsCheck = TRUE; @@ -2680,7 +2677,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir) } else { - PartitionList->TempDisk = PartitionList->CurrentDisk; PartitionList->TempPartition = PartitionList->CurrentPartition; PartitionList->TempPartition->NeedsCheck = TRUE; @@ -2690,7 +2686,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir) break; case FormatSystemPartition: - PartitionList->TempDisk = PartitionList->CurrentDisk; PartitionList->TempPartition = PartitionList->CurrentPartition; PartitionList->TempPartition->NeedsCheck = TRUE; @@ -2700,7 +2695,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) case FormatInstallPartition: if (GetNextUnformattedPartition(PartitionList, - &PartitionList->TempDisk, + NULL, &PartitionList->TempPartition)) { PartitionList->FormatState = FormatOtherPartition; @@ -2717,7 +2712,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) case FormatOtherPartition: if (GetNextUnformattedPartition(PartitionList, - &PartitionList->TempDisk, + NULL, &PartitionList->TempPartition)) { PartitionList->FormatState = FormatOtherPartition; @@ -2738,8 +2733,8 @@ SelectFileSystemPage(PINPUT_RECORD Ir) return QUIT_PAGE; } - DiskEntry = PartitionList->TempDisk; PartEntry = PartitionList->TempPartition; + DiskEntry = PartEntry->DiskEntry; /* Adjust disk size */ DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector; @@ -2970,15 +2965,14 @@ FormatPartitionPage(PINPUT_RECORD Ir) MUIDisplayPage(FORMAT_PARTITION_PAGE); if (PartitionList == NULL || - PartitionList->TempDisk == NULL || PartitionList->TempPartition == NULL) { /* FIXME: show an error dialog */ return QUIT_PAGE; } - DiskEntry = PartitionList->TempDisk; PartEntry = PartitionList->TempPartition; + DiskEntry = PartEntry->DiskEntry; while (TRUE) { @@ -3004,7 +2998,7 @@ FormatPartitionPage(PINPUT_RECORD Ir) if (PartEntry->SectorCount.QuadPart < 8192) { /* FAT12 CHS partition (disk is smaller than 4.1MB) */ - PartEntry->PartitionType = PARTITION_FAT_12; + SetPartitionType(PartEntry, PARTITION_FAT_12); } else if (PartEntry->StartSector.QuadPart < 1450560) { @@ -3013,17 +3007,17 @@ FormatPartitionPage(PINPUT_RECORD Ir) if (PartEntry->SectorCount.QuadPart < 65536) { /* FAT16 CHS partition (partition size < 32MB) */ - PartEntry->PartitionType = PARTITION_FAT_16; + SetPartitionType(PartEntry, PARTITION_FAT_16); } else if (PartEntry->SectorCount.QuadPart < 1048576) { /* FAT16 CHS partition (partition size < 512MB) */ - PartEntry->PartitionType = PARTITION_HUGE; + SetPartitionType(PartEntry, PARTITION_HUGE); } else { /* FAT32 CHS partition (partition size >= 512MB) */ - PartEntry->PartitionType = PARTITION_FAT32; + SetPartitionType(PartEntry, PARTITION_FAT32); } } else @@ -3033,35 +3027,23 @@ FormatPartitionPage(PINPUT_RECORD Ir) if (PartEntry->SectorCount.QuadPart < 1048576) { /* FAT16 LBA partition (partition size < 512MB) */ - PartEntry->PartitionType = PARTITION_XINT13; + SetPartitionType(PartEntry, PARTITION_XINT13); } else { /* FAT32 LBA partition (partition size >= 512MB) */ - PartEntry->PartitionType = PARTITION_FAT32_XINT13; + SetPartitionType(PartEntry, PARTITION_FAT32_XINT13); } } - - DiskEntry->Dirty = TRUE; - DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType; - DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition = TRUE; } #if 0 else if (wcscmp(PartEntry->FileSystem->FileSystemName, L"EXT2") == 0) { - PartEntry->PartitionType = PARTITION_EXT2; - - DiskEntry->Dirty = TRUE; - DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType; - DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition = TRUE; + SetPartitionType(PartEntry, PARTITION_EXT2); } else if (wcscmp(PartEntry->FileSystem->FileSystemName, L"NTFS") == 0) { - PartEntry->PartitionType = PARTITION_IFS; - - DiskEntry->Dirty = TRUE; - DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType; - DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition = TRUE; + SetPartitionType(PartEntry, PARTITION_IFS); } #endif else if (!PartEntry->FileSystem->FormatFunc) @@ -4284,7 +4266,7 @@ BootLoaderPage(PINPUT_RECORD Ir) RtlFreeUnicodeString(&SystemRootPath); swprintf(PathBuffer, L"\\Device\\Harddisk%lu\\Partition%lu", - PartitionList->SystemDisk->DiskNumber, + PartitionList->SystemPartition->DiskEntry->DiskNumber, PartitionList->SystemPartition->PartitionNumber); RtlCreateUnicodeString(&SystemRootPath, PathBuffer); DPRINT1("SystemRootPath: %wZ\n", &SystemRootPath); @@ -4557,7 +4539,7 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir) /* Step 2: Write the MBR */ swprintf(DestinationDevicePathBuffer, L"\\Device\\Harddisk%d\\Partition0", - PartitionList->SystemDisk->DiskNumber); + PartitionList->SystemPartition->DiskEntry->DiskNumber); wcscpy(SourceMbrPathBuffer, SourceRootPath.Buffer); wcscat(SourceMbrPathBuffer, L"\\loader\\dosmbr.bin");
6 years, 7 months
1
0
0
0
05/05: [USETUP] Code improvements for PartList.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=eaf7d6ebbe4bc2f3a6e71…
commit eaf7d6ebbe4bc2f3a6e71882d3fa53a3e8b74dee Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat May 13 16:32:53 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 19:09:39 2018 +0200 [USETUP] Code improvements for PartList. - Use explicit ansi string safe functions (where they are used ansi, but not explicitely); - Add (old-school) function parameters annotations; - Use PARTITION_ENTRY_UNUSED where needed (instead of hardcoding its value); - Turn some functions static to this module; - Turn the 2nd parameter of both GetNextUnformattedPartition() and GetNextUncheckedPartition() optional (for next commit); - Improve some comments; - Use NT types. svn path=/branches/setup_improvements/; revision=74531 --- base/setup/usetup/partlist.c | 181 ++++++++++++++++++++----------------------- base/setup/usetup/partlist.h | 64 +++++++-------- 2 files changed, 118 insertions(+), 127 deletions(-) diff --git a/base/setup/usetup/partlist.c b/base/setup/usetup/partlist.c index b047a227b5..22867b73a4 100644 --- a/base/setup/usetup/partlist.c +++ b/base/setup/usetup/partlist.c @@ -174,19 +174,19 @@ static PARTITION_TYPE PartitionTypes[] = VOID GetPartTypeStringFromPartitionType( - UCHAR partitionType, - PCHAR strPartType, - DWORD cchPartType) + IN UCHAR partitionType, + OUT PCHAR strPartType, + IN ULONG cchPartType) { /* Determine partition type */ if (IsContainerPartition(partitionType)) { - StringCchCopy(strPartType, cchPartType, MUIGetString(STRING_EXTENDED_PARTITION)); + RtlStringCchCopyA(strPartType, cchPartType, MUIGetString(STRING_EXTENDED_PARTITION)); } else if (partitionType == PARTITION_ENTRY_UNUSED) { - StringCchCopy(strPartType, cchPartType, MUIGetString(STRING_FORMATUNUSED)); + RtlStringCchCopyA(strPartType, cchPartType, MUIGetString(STRING_FORMATUNUSED)); } else { @@ -197,13 +197,13 @@ GetPartTypeStringFromPartitionType( { if (partitionType == PartitionTypes[i].Type) { - StringCchCopy(strPartType, cchPartType, PartitionTypes[i].Description); + RtlStringCchCopyA(strPartType, cchPartType, PartitionTypes[i].Description); return; } } /* We are here because the partition type is unknown */ - StringCchCopy(strPartType, cchPartType, MUIGetString(STRING_FORMATUNKNOWN)); + RtlStringCchCopyA(strPartType, cchPartType, MUIGetString(STRING_FORMATUNKNOWN)); } } @@ -253,7 +253,6 @@ AlignDown( return Temp * Alignment; } - ULONGLONG AlignUp( IN ULONGLONG Value, @@ -282,7 +281,7 @@ RoundingDivide( static VOID GetDriverName( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { RTL_QUERY_REGISTRY_TABLE QueryTable[2]; WCHAR KeyName[32]; @@ -317,7 +316,7 @@ GetDriverName( static VOID AssignDriveLetters( - PPARTLIST List) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -396,7 +395,7 @@ AssignDriveLetters( } -NTSTATUS +static NTSTATUS NTAPI DiskIdentifierQueryRoutine( PWSTR ValueName, @@ -426,7 +425,7 @@ DiskIdentifierQueryRoutine( } -NTSTATUS +static NTSTATUS NTAPI DiskConfigurationDataQueryRoutine( PWSTR ValueName, @@ -470,7 +469,7 @@ DiskConfigurationDataQueryRoutine( } -NTSTATUS +static NTSTATUS NTAPI SystemConfigurationDataQueryRoutine( PWSTR ValueName, @@ -522,7 +521,7 @@ SystemConfigurationDataQueryRoutine( static VOID EnumerateBiosDiskEntries( - PPARTLIST PartList) + IN PPARTLIST PartList) { RTL_QUERY_REGISTRY_TABLE QueryTable[3]; WCHAR Name[120]; @@ -663,16 +662,16 @@ EnumerateBiosDiskEntries( static VOID AddPartitionToDisk( - ULONG DiskNumber, - PDISKENTRY DiskEntry, - ULONG PartitionIndex, - BOOLEAN LogicalPartition) + IN ULONG DiskNumber, + IN PDISKENTRY DiskEntry, + IN ULONG PartitionIndex, + IN BOOLEAN LogicalPartition) { PPARTITION_INFORMATION PartitionInfo; PPARTENTRY PartEntry; PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartitionIndex]; - if (PartitionInfo->PartitionType == 0 || + if (PartitionInfo->PartitionType == PARTITION_ENTRY_UNUSED || ((LogicalPartition != FALSE) && IsContainerPartition(PartitionInfo->PartitionType))) return; @@ -773,7 +772,7 @@ AddPartitionToDisk( static VOID ScanForUnpartitionedDiskSpace( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { ULONGLONG LastStartSector; ULONGLONG LastSectorCount; @@ -788,7 +787,7 @@ ScanForUnpartitionedDiskSpace( { DPRINT1("No primary partition!\n"); - /* Create a partition table that represents the empty disk */ + /* Create a partition entry that represents the empty disk */ NewPartEntry = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); @@ -906,7 +905,7 @@ ScanForUnpartitionedDiskSpace( { DPRINT1("No logical partition!\n"); - /* Create a partition table entry that represents the empty extended partition */ + /* Create a partition entry that represents the empty extended partition */ NewPartEntry = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); @@ -1080,12 +1079,12 @@ SetDiskSignature( static VOID UpdateDiskSignatures( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry; PDISKENTRY DiskEntry; - /* Print partition lines*/ + /* Print partition lines */ Entry = List->DiskListHead.Flink; while (Entry != &List->DiskListHead) { @@ -1106,9 +1105,9 @@ UpdateDiskSignatures( static VOID AddDiskToList( - HANDLE FileHandle, - ULONG DiskNumber, - PPARTLIST List) + IN HANDLE FileHandle, + IN ULONG DiskNumber, + IN PPARTLIST List) { DISK_GEOMETRY DiskGeometry; SCSI_ADDRESS ScsiAddress; @@ -1138,9 +1137,7 @@ AddDiskToList( &DiskGeometry, sizeof(DISK_GEOMETRY)); if (!NT_SUCCESS(Status)) - { return; - } if (DiskGeometry.MediaType != FixedMedia && DiskGeometry.MediaType != RemovableMedia) @@ -1159,17 +1156,13 @@ AddDiskToList( &ScsiAddress, sizeof(SCSI_ADDRESS)); if (!NT_SUCCESS(Status)) - { return; - } Mbr = (PARTITION_SECTOR*)RtlAllocateHeap(ProcessHeap, 0, DiskGeometry.BytesPerSector); if (Mbr == NULL) - { return; - } FileOffset.QuadPart = 0; Status = NtReadFile(FileHandle, @@ -1219,7 +1212,7 @@ AddDiskToList( else DiskEntry->NoMbr = FALSE; - /* Free Mbr sector buffer */ + /* Free the MBR sector buffer */ RtlFreeHeap(ProcessHeap, 0, Mbr); ListEntry = List->BiosDiskListHead.Flink; @@ -1228,7 +1221,7 @@ AddDiskToList( BiosDiskEntry = CONTAINING_RECORD(ListEntry, BIOSDISKENTRY, ListEntry); /* FIXME: * Compare the size from bios and the reported size from driver. - * If we have more than one disk with a zero or with the same signatur + * If we have more than one disk with a zero or with the same signature * we must create new signatures and reboot. After the reboot, * it is possible to identify the disks. */ @@ -1348,7 +1341,7 @@ AddDiskToList( if (DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart != 0 && DiskEntry->LayoutBuffer->PartitionEntry[0].PartitionLength.QuadPart != 0 && - DiskEntry->LayoutBuffer->PartitionEntry[0].PartitionType != 0) + DiskEntry->LayoutBuffer->PartitionEntry[0].PartitionType != PARTITION_ENTRY_UNUSED) { if ((DiskEntry->LayoutBuffer->PartitionEntry[0].StartingOffset.QuadPart / DiskEntry->BytesPerSector) % DiskEntry->SectorsPerTrack == 0) { @@ -1499,7 +1492,7 @@ CreatePartitionList( if (IsListEmpty(&List->CurrentDisk->PrimaryPartListHead)) { - List->CurrentPartition = 0; + List->CurrentPartition = NULL; } else { @@ -1515,7 +1508,7 @@ CreatePartitionList( VOID DestroyPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PBIOSDISKENTRY BiosDiskEntry; @@ -1575,10 +1568,10 @@ DestroyPartitionList( static VOID PrintEmptyLine( - PPARTLIST List) + IN PPARTLIST List) { COORD coPos; - DWORD Written; + ULONG Written; USHORT Width; USHORT Height; @@ -1610,13 +1603,13 @@ PrintEmptyLine( static VOID PrintPartitionData( - PPARTLIST List, - PDISKENTRY DiskEntry, - PPARTENTRY PartEntry) + IN PPARTLIST List, + IN PDISKENTRY DiskEntry, + IN PPARTENTRY PartEntry) { CHAR LineBuffer[128]; COORD coPos; - DWORD Written; + ULONG Written; USHORT Width; USHORT Height; LARGE_INTEGER PartSize; @@ -1766,14 +1759,14 @@ PrintPartitionData( static VOID PrintDiskData( - PPARTLIST List, - PDISKENTRY DiskEntry) + IN PPARTLIST List, + IN PDISKENTRY DiskEntry) { PPARTENTRY PrimaryPartEntry, LogicalPartEntry; PLIST_ENTRY PrimaryEntry, LogicalEntry; CHAR LineBuffer[128]; COORD coPos; - DWORD Written; + ULONG Written; USHORT Width; USHORT Height; ULARGE_INTEGER DiskSize; @@ -1888,19 +1881,19 @@ PrintDiskData( VOID DrawPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry, Entry2; PDISKENTRY DiskEntry; PPARTENTRY PartEntry = NULL; COORD coPos; - DWORD Written; + ULONG Written; SHORT i; SHORT CurrentDiskLine; SHORT CurrentPartLine; SHORT LastLine; - BOOL CurrentPartLineFound = FALSE; - BOOL CurrentDiskLineFound = FALSE; + BOOLEAN CurrentPartLineFound = FALSE; + BOOLEAN CurrentDiskLineFound = FALSE; /* Calculate the line of the current disk and partition */ CurrentDiskLine = 0; @@ -2130,11 +2123,11 @@ DrawPartitionList( } -DWORD +ULONG SelectPartition( - PPARTLIST List, - ULONG DiskNumber, - ULONG PartitionNumber) + IN PPARTLIST List, + IN ULONG DiskNumber, + IN ULONG PartitionNumber) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2181,7 +2174,7 @@ SelectPartition( BOOL ScrollDownPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY DiskListEntry; PLIST_ENTRY PartListEntry; @@ -2277,7 +2270,7 @@ ScrollDownPartitionList( BOOL ScrollUpPartitionList( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY DiskListEntry; PLIST_ENTRY PartListEntry; @@ -2374,7 +2367,7 @@ ScrollUpPartitionList( static BOOLEAN IsEmptyLayoutEntry( - PPARTITION_INFORMATION PartitionInfo) + IN PPARTITION_INFORMATION PartitionInfo) { if (PartitionInfo->StartingOffset.QuadPart == 0 && PartitionInfo->PartitionLength.QuadPart == 0) @@ -2427,7 +2420,7 @@ GetPrimaryPartitionCount( static ULONG GetLogicalPartitionCount( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { PLIST_ENTRY ListEntry; PPARTENTRY PartEntry; @@ -2448,9 +2441,9 @@ GetLogicalPartitionCount( static -BOOL +BOOLEAN ReAllocateLayoutBuffer( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { PDRIVE_LAYOUT_INFORMATION NewLayoutBuffer; ULONG NewPartitionCount; @@ -2486,8 +2479,8 @@ ReAllocateLayoutBuffer( /* If the layout buffer grows, make sure the new (empty) entries are written to the disk */ if (NewPartitionCount > CurrentPartitionCount) { - for (i = CurrentPartitionCount; i < NewPartitionCount; i++) - NewLayoutBuffer->PartitionEntry[i].RewritePartition = TRUE; + for (i = CurrentPartitionCount; i < NewPartitionCount; i++) + NewLayoutBuffer->PartitionEntry[i].RewritePartition = TRUE; } DiskEntry->LayoutBuffer = NewLayoutBuffer; @@ -2556,7 +2549,7 @@ UpdateDiskLayout( ListEntry = ListEntry->Flink; } - /* Update the logical partition tables */ + /* Update the logical partition table */ Index = 4; ListEntry = DiskEntry->LogicalPartListHead.Flink; while (ListEntry != &DiskEntry->LogicalPartListHead) @@ -2581,7 +2574,7 @@ UpdateDiskLayout( PartEntry->PartitionNumber = PartitionNumber; PartEntry->PartitionIndex = Index; - /* Fill the link entry of the previous partition table */ + /* Fill the link entry of the previous partition entry */ if (LinkInfo != NULL) { LinkInfo->StartingOffset.QuadPart = (PartEntry->StartSector.QuadPart - DiskEntry->SectorAlignment) * DiskEntry->BytesPerSector; @@ -2595,7 +2588,7 @@ UpdateDiskLayout( LinkInfo->RewritePartition = TRUE; } - /* Save a pointer to the link entry of the current partition table */ + /* Save a pointer to the link entry of the current partition entry */ LinkInfo = &DiskEntry->LayoutBuffer->PartitionEntry[Index + 1]; PartitionNumber++; @@ -2605,7 +2598,7 @@ UpdateDiskLayout( ListEntry = ListEntry->Flink; } - /* Wipe unused primary partition table entries */ + /* Wipe unused primary partition entries */ for (Index = GetPrimaryPartitionCount(DiskEntry); Index < 4; Index++) { DPRINT1("Primary partition entry %lu\n", Index); @@ -2627,7 +2620,7 @@ UpdateDiskLayout( } } - /* Wipe unused logical partition table entries */ + /* Wipe unused logical partition entries */ for (Index = 4; Index < DiskEntry->LayoutBuffer->PartitionCount; Index++) { if (Index % 4 >= 2) @@ -2661,8 +2654,8 @@ UpdateDiskLayout( static PPARTENTRY GetPrevUnpartitionedEntry( - PDISKENTRY DiskEntry, - PPARTENTRY PartEntry) + IN PDISKENTRY DiskEntry, + IN PPARTENTRY PartEntry) { PPARTENTRY PrevPartEntry; PLIST_ENTRY ListHead; @@ -2688,8 +2681,8 @@ GetPrevUnpartitionedEntry( static PPARTENTRY GetNextUnpartitionedEntry( - PDISKENTRY DiskEntry, - PPARTENTRY PartEntry) + IN PDISKENTRY DiskEntry, + IN PPARTENTRY PartEntry) { PPARTENTRY NextPartEntry; PLIST_ENTRY ListHead; @@ -2714,9 +2707,9 @@ GetNextUnpartitionedEntry( VOID CreatePrimaryPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate) + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2800,13 +2793,13 @@ CreatePrimaryPartition( static VOID AddLogicalDiskSpace( - PDISKENTRY DiskEntry) + IN PDISKENTRY DiskEntry) { PPARTENTRY NewPartEntry; DPRINT1("AddLogicalDiskSpace()\n"); - /* Create a partition table entry that represents the empty space in the container partition */ + /* Create a partition entry that represents the empty space in the container partition */ NewPartEntry = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); @@ -2833,8 +2826,8 @@ AddLogicalDiskSpace( VOID CreateExtendedPartition( - PPARTLIST List, - ULONGLONG SectorCount) + IN PPARTLIST List, + IN ULONGLONG SectorCount) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2845,7 +2838,7 @@ CreateExtendedPartition( if (List == NULL || List->CurrentDisk == NULL || List->CurrentPartition == NULL || - (List->CurrentPartition->IsPartitioned != FALSE)) + List->CurrentPartition->IsPartitioned != FALSE) { return; } @@ -2942,9 +2935,9 @@ CreateExtendedPartition( VOID CreateLogicalPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate) + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -3029,7 +3022,7 @@ CreateLogicalPartition( VOID DeleteCurrentPartition( - PPARTLIST List) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -3046,7 +3039,7 @@ DeleteCurrentPartition( return; } - /* Clear the system disk and partition pointers if the system partition will be deleted */ + /* Clear the system disk and partition pointers if the system partition is being deleted */ if (List->SystemPartition == List->CurrentPartition) { List->SystemDisk = NULL; @@ -3462,7 +3455,7 @@ WritePartitions( BOOLEAN WritePartitionsToDisk( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry; PDISKENTRY DiskEntry; @@ -3488,9 +3481,9 @@ WritePartitionsToDisk( } -BOOL +BOOLEAN SetMountedDeviceValues( - PPARTLIST List) + IN PPARTLIST List) { PLIST_ENTRY Entry1, Entry2; PDISKENTRY DiskEntry; @@ -3498,9 +3491,7 @@ SetMountedDeviceValues( LARGE_INTEGER StartingOffset; if (List == NULL) - { return FALSE; - } Entry1 = List->DiskListHead.Flink; while (Entry1 != &List->DiskListHead) @@ -3515,6 +3506,7 @@ SetMountedDeviceValues( PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); if (PartEntry->IsPartitioned) { + /* Assign a "\DosDevices\#:" mount point to this partition */ if (PartEntry->DriveLetter) { StartingOffset.QuadPart = PartEntry->StartSector.QuadPart * DiskEntry->BytesPerSector; @@ -3603,10 +3595,10 @@ LogicalPartitionCreationChecks( } -BOOL +BOOLEAN GetNextUnformattedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry) { PLIST_ENTRY Entry1, Entry2; @@ -3657,11 +3649,10 @@ GetNextUnformattedPartition( return FALSE; } - -BOOL +BOOLEAN GetNextUncheckedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry) { PLIST_ENTRY Entry1, Entry2; diff --git a/base/setup/usetup/partlist.h b/base/setup/usetup/partlist.h index c42335a70a..9787f94ae3 100644 --- a/base/setup/usetup/partlist.h +++ b/base/setup/usetup/partlist.h @@ -209,6 +209,12 @@ typedef struct ULONG Signature; } BIOS_DISK, *PBIOS_DISK; +VOID +GetPartTypeStringFromPartitionType( + IN UCHAR partitionType, + OUT PCHAR strPartType, + IN ULONG cchPartType); + PPARTLIST CreatePartitionList( SHORT Left, @@ -218,50 +224,46 @@ CreatePartitionList( VOID DestroyPartitionList( - PPARTLIST List); + IN PPARTLIST List); VOID DrawPartitionList( - PPARTLIST List); + IN PPARTLIST List); -DWORD +ULONG SelectPartition( - PPARTLIST List, - ULONG DiskNumber, - ULONG PartitionNumber); - -BOOL -SetMountedDeviceValues( - PPARTLIST List); + IN PPARTLIST List, + IN ULONG DiskNumber, + IN ULONG PartitionNumber); BOOL ScrollDownPartitionList( - PPARTLIST List); + IN PPARTLIST List); BOOL ScrollUpPartitionList( - PPARTLIST List); + IN PPARTLIST List); VOID CreatePrimaryPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate); + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate); VOID CreateExtendedPartition( - PPARTLIST List, - ULONGLONG SectorCount); + IN PPARTLIST List, + IN ULONGLONG SectorCount); VOID CreateLogicalPartition( - PPARTLIST List, - ULONGLONG SectorCount, - BOOLEAN AutoCreate); + IN PPARTLIST List, + IN ULONGLONG SectorCount, + IN BOOLEAN AutoCreate); VOID DeleteCurrentPartition( - PPARTLIST List); + IN PPARTLIST List); VOID CheckActiveSystemPartition( @@ -270,7 +272,11 @@ CheckActiveSystemPartition( BOOLEAN WritePartitionsToDisk( - PPARTLIST List); + IN PPARTLIST List); + +BOOLEAN +SetMountedDeviceValues( + IN PPARTLIST List); ULONG PrimaryPartitionCreationChecks( @@ -284,22 +290,16 @@ ULONG LogicalPartitionCreationChecks( IN PPARTLIST List); -BOOL +BOOLEAN GetNextUnformattedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry); -BOOL +BOOLEAN GetNextUncheckedPartition( IN PPARTLIST List, - OUT PDISKENTRY *pDiskEntry, + OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry); -VOID -GetPartTypeStringFromPartitionType( - UCHAR partitionType, - PCHAR strPartType, - DWORD cchPartType); - /* EOF */
6 years, 7 months
1
0
0
0
04/05: [USETUP] Enhancements for filesystem utility functions.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=56ea51bbe498d126a61ba…
commit 56ea51bbe498d126a61bab93c7ae95860bd290f2 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat May 13 16:20:10 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 19:09:38 2018 +0200 [USETUP] Enhancements for filesystem utility functions. - Introduce code that detects the filesystem of a (mounted?) partition, using NtQueryVolumeInformationFile() with FileFsAttributeInformation class, aka. rely on ReactOS itself (kernel, storage stack, filesystem drivers...) to recognize the FS on a partition that should normally be seen by the system. This currently half-works for whatever reason (to be insvestigated), while it works on Windows. - Fix few comments & a function parameter name. - Use NT string pointer types. svn path=/branches/setup_improvements/; revision=74529 --- base/setup/usetup/fslist.c | 131 ++++++++++++++++++++++++++++++++++++++++----- base/setup/usetup/fslist.h | 10 ++-- 2 files changed, 122 insertions(+), 19 deletions(-) diff --git a/base/setup/usetup/fslist.c b/base/setup/usetup/fslist.c index 0b190d4a8b..1eb158b777 100644 --- a/base/setup/usetup/fslist.c +++ b/base/setup/usetup/fslist.c @@ -35,7 +35,7 @@ VOID AddProvider( IN OUT PFILE_SYSTEM_LIST List, - IN LPCWSTR FileSystemName, + IN PCWSTR FileSystemName, IN FORMATEX FormatFunc, IN CHKDSKEX ChkdskFunc) { @@ -69,7 +69,7 @@ AddProvider( PFILE_SYSTEM_ITEM GetFileSystemByName( IN PFILE_SYSTEM_LIST List, - IN LPWSTR FileSystemName) + IN PWSTR FileSystemName) { PLIST_ENTRY ListEntry; PFILE_SYSTEM_ITEM Item; @@ -87,6 +87,80 @@ GetFileSystemByName( return NULL; } +#if 0 // FIXME: To be fully enabled when our storage stack & al. will work better! + +/* NOTE: Ripped & adapted from base/system/autochk/autochk.c */ +static NTSTATUS +_MyGetFileSystem( + IN struct _PARTENTRY* PartEntry, + IN OUT PWSTR FileSystemName, + IN SIZE_T FileSystemNameSize) +{ + NTSTATUS Status; + HANDLE FileHandle; + IO_STATUS_BLOCK IoStatusBlock; + PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute; + UCHAR Buffer[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + MAX_PATH * sizeof(WCHAR)]; + + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING PartitionRootPath; + WCHAR PathBuffer[MAX_PATH]; + + FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer; + + /* Set PartitionRootPath */ + swprintf(PathBuffer, + // L"\\Device\\Harddisk%lu\\Partition%lu", // Should work! But because ReactOS sucks atm. it actually doesn't work!! + L"\\Device\\Harddisk%lu\\Partition%lu\\", // HACK: Use this as a temporary hack! + PartEntry->DiskEntry->DiskNumber, + PartEntry->PartitionNumber); + RtlInitUnicodeString(&PartitionRootPath, PathBuffer); + DPRINT("PartitionRootPath: %wZ\n", &PartitionRootPath); + + /* Open the partition */ + InitializeObjectAttributes(&ObjectAttributes, + &PartitionRootPath, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtOpenFile(&FileHandle, // PartitionHandle, + FILE_GENERIC_READ /* | SYNCHRONIZE */, + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ, + 0 /* FILE_SYNCHRONOUS_IO_NONALERT */); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to open partition %wZ, Status 0x%08lx\n", &PartitionRootPath, Status); + return Status; + } + + /* Retrieve the FS attributes */ + Status = NtQueryVolumeInformationFile(FileHandle, + &IoStatusBlock, + FileFsAttribute, + sizeof(Buffer), + FileFsAttributeInformation); + NtClose(FileHandle); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtQueryVolumeInformationFile failed for partition %wZ, Status 0x%08lx\n", &PartitionRootPath, Status); + return Status; + } + + if (FileSystemNameSize * sizeof(WCHAR) < FileFsAttribute->FileSystemNameLength + sizeof(WCHAR)) + return STATUS_BUFFER_TOO_SMALL; + + RtlCopyMemory(FileSystemName, + FileFsAttribute->FileSystemName, + FileFsAttribute->FileSystemNameLength); + FileSystemName[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = UNICODE_NULL; + + return STATUS_SUCCESS; +} + +#endif PFILE_SYSTEM_ITEM GetFileSystem( @@ -94,7 +168,11 @@ GetFileSystem( IN struct _PARTENTRY* PartEntry) { PFILE_SYSTEM_ITEM CurrentFileSystem; - LPWSTR FileSystemName = NULL; + PWSTR FileSystemName = NULL; +#if 0 // For code temporarily disabled below + NTSTATUS Status; + WCHAR FsRecFileSystemName[MAX_PATH]; +#endif CurrentFileSystem = PartEntry->FileSystem; @@ -106,6 +184,26 @@ GetFileSystem( CurrentFileSystem = NULL; +#if 0 // FIXME: To be fully enabled when our storage stack & al. will work better! + + /* + * We don't have one... + * + * Try to infer one using NT file system recognition. + */ + Status = _MyGetFileSystem(PartEntry, FsRecFileSystemName, ARRAYSIZE(FsRecFileSystemName)); + if (NT_SUCCESS(Status) && *FsRecFileSystemName) + { + /* Temporary HACK: map FAT32 back to FAT */ + if (wcscmp(FsRecFileSystemName, L"FAT32") == 0) + wcscpy(FsRecFileSystemName, L"FAT"); + + FileSystemName = FsRecFileSystemName; + goto Quit; + } + +#endif + /* * We don't have one... * @@ -141,12 +239,19 @@ GetFileSystem( FileSystemName = L"NTFS"; /* FIXME: Not quite correct! */ } +#if 0 +Quit: // For code temporarily disabled above +#endif + // HACK: WARNING: We cannot write on this FS yet! - if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS) - DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName); + if (FileSystemName) + { + if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS) + DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName); + } DPRINT1("GetFileSystem -- PartitionType: 0x%02X ; FileSystemName (guessed): %S\n", - PartEntry->PartitionType, FileSystemName); + PartEntry->PartitionType, FileSystemName ? FileSystemName : L"None"); if (FileSystemName != NULL) CurrentFileSystem = GetFileSystemByName(FileSystemList, FileSystemName); @@ -160,7 +265,7 @@ CreateFileSystemList( IN SHORT Left, IN SHORT Top, IN BOOLEAN ForceFormat, - IN LPCWSTR ForceFileSystem) + IN PCWSTR SelectFileSystem) { PFILE_SYSTEM_LIST List; PFILE_SYSTEM_ITEM Item; @@ -183,16 +288,16 @@ CreateFileSystemList( if (!ForceFormat) { - /* Add 'Keep' provider */ + /* Add the 'Keep existing filesystem' dummy provider */ AddProvider(List, NULL, NULL, NULL); } - /* Search for ForceFileSystem in list */ + /* Search for SelectFileSystem in list */ ListEntry = List->ListHead.Flink; while (ListEntry != &List->ListHead) { Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); - if (Item->FileSystemName && wcscmp(ForceFileSystem, Item->FileSystemName) == 0) + if (Item->FileSystemName && wcscmp(SelectFileSystem, Item->FileSystemName) == 0) { List->Selected = Item; break; @@ -205,7 +310,6 @@ CreateFileSystemList( return List; } - VOID DestroyFileSystemList( IN PFILE_SYSTEM_LIST List) @@ -226,7 +330,6 @@ DestroyFileSystemList( RtlFreeHeap(ProcessHeap, 0, List); } - VOID DrawFileSystemList( IN PFILE_SYSTEM_LIST List) @@ -264,7 +367,9 @@ DrawFileSystemList( snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK2), Item->FileSystemName); } else + { snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT)); + } if (ListEntry == &List->Selected->ListEntry) CONSOLE_SetInvertedTextXY(List->Left, @@ -279,7 +384,6 @@ DrawFileSystemList( } } - VOID ScrollDownFileSystemList( IN PFILE_SYSTEM_LIST List) @@ -291,7 +395,6 @@ ScrollDownFileSystemList( } } - VOID ScrollUpFileSystemList( IN PFILE_SYSTEM_LIST List) diff --git a/base/setup/usetup/fslist.h b/base/setup/usetup/fslist.h index 685a2cfe2e..4433d381ba 100644 --- a/base/setup/usetup/fslist.h +++ b/base/setup/usetup/fslist.h @@ -31,7 +31,7 @@ typedef struct _FILE_SYSTEM_ITEM { LIST_ENTRY ListEntry; - LPCWSTR FileSystemName; /* Not owned by the item */ + PCWSTR FileSystemName; /* Not owned by the item */ FORMATEX FormatFunc; CHKDSKEX ChkdskFunc; BOOLEAN QuickFormat; @@ -46,16 +46,16 @@ typedef struct _FILE_SYSTEM_LIST } FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST; VOID -FS_AddProvider( +AddProvider( IN OUT PFILE_SYSTEM_LIST List, - IN LPCWSTR FileSystemName, + IN PCWSTR FileSystemName, IN FORMATEX FormatFunc, IN CHKDSKEX ChkdskFunc); PFILE_SYSTEM_ITEM GetFileSystemByName( IN PFILE_SYSTEM_LIST List, - IN LPWSTR FileSystemName); + IN PWSTR FileSystemName); struct _PARTENTRY; // Defined in partlist.h PFILE_SYSTEM_ITEM @@ -68,7 +68,7 @@ CreateFileSystemList( IN SHORT Left, IN SHORT Top, IN BOOLEAN ForceFormat, - IN LPCWSTR ForceFileSystem); + IN PCWSTR SelectFileSystem); VOID DestroyFileSystemList(
6 years, 7 months
1
0
0
0
03/05: [USETUP] Add & modify some file utility functions that are going to be used next.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=60532e9c4394b0ee7860a…
commit 60532e9c4394b0ee7860a1fda2f6cc2435be610b Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat May 13 16:13:49 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 19:09:38 2018 +0200 [USETUP] Add & modify some file utility functions that are going to be used next. - ConcatPaths that concatenates paths (or a path and a file name); - OpenAndMapFile (resp. UnMapFile), whose purpose is to open a file and map it in memory (resp. unmap it from memory). - Add extra optional parameters to DoesPathExist and DoesFileExist: an optional "RootDirectory" handle and, for DoesFileExist only, an optional PathName. - Close the opened file handles only on success. svn path=/branches/setup_improvements/; revision=74528 svn path=/branches/setup_improvements/; revision=74538 svn path=/branches/setup_improvements/; revision=74549 --- base/setup/usetup/bootsup.c | 14 +- base/setup/usetup/filesup.c | 357 +++++++++++++++++++++++++++++++------------- base/setup/usetup/filesup.h | 35 ++++- base/setup/usetup/usetup.c | 4 +- base/setup/usetup/usetup.h | 4 +- 5 files changed, 293 insertions(+), 121 deletions(-) diff --git a/base/setup/usetup/bootsup.c b/base/setup/usetup/bootsup.c index 75319fba95..674808ace7 100644 --- a/base/setup/usetup/bootsup.c +++ b/base/setup/usetup/bootsup.c @@ -2275,7 +2275,7 @@ InstallFatBootcodeToPartition( wcscpy(DstPath, SystemRootPath->Buffer); wcscat(DstPath, L"\\freeldr.ini"); - DoesFreeLdrExist = DoesFileExist(SystemRootPath->Buffer, L"freeldr.ini"); + DoesFreeLdrExist = DoesFileExist(NULL, SystemRootPath->Buffer, L"freeldr.ini"); if (DoesFreeLdrExist) { /* Update existing 'freeldr.ini' */ @@ -2292,8 +2292,8 @@ InstallFatBootcodeToPartition( /* Check for NT and other bootloaders */ // FIXME: Check for Vista+ bootloader! - if (DoesFileExist(SystemRootPath->Buffer, L"ntldr") == TRUE || - DoesFileExist(SystemRootPath->Buffer, L"boot.ini") == TRUE) + if (DoesFileExist(NULL, SystemRootPath->Buffer, L"ntldr") == TRUE || + DoesFileExist(NULL, SystemRootPath->Buffer, L"boot.ini") == TRUE) { /* Search root directory for 'ntldr' and 'boot.ini' */ DPRINT1("Found Microsoft Windows NT/2000/XP boot loader\n"); @@ -2375,8 +2375,8 @@ InstallFatBootcodeToPartition( PWCHAR BootSector; PWCHAR BootSectorFileName; - if (DoesFileExist(SystemRootPath->Buffer, L"io.sys") == TRUE || - DoesFileExist(SystemRootPath->Buffer, L"msdos.sys") == TRUE) + if (DoesFileExist(NULL, SystemRootPath->Buffer, L"io.sys") == TRUE || + DoesFileExist(NULL, SystemRootPath->Buffer, L"msdos.sys") == TRUE) { /* Search for root directory for 'io.sys' and 'msdos.sys' */ DPRINT1("Found Microsoft DOS or Windows 9x boot loader\n"); @@ -2390,7 +2390,7 @@ InstallFatBootcodeToPartition( BootSectorFileName = L"\\bootsect.dos"; } else - if (DoesFileExist(SystemRootPath->Buffer, L"kernel.sys") == TRUE) + if (DoesFileExist(NULL, SystemRootPath->Buffer, L"kernel.sys") == TRUE) { /* Search for root directory for 'kernel.sys' */ DPRINT1("Found FreeDOS boot loader\n"); @@ -2529,7 +2529,7 @@ InstallExt2BootcodeToPartition( wcscpy(DstPath, SystemRootPath->Buffer); wcscat(DstPath, L"\\freeldr.ini"); - DoesFreeLdrExist = DoesFileExist(SystemRootPath->Buffer, L"freeldr.ini"); + DoesFreeLdrExist = DoesFileExist(NULL, SystemRootPath->Buffer, L"freeldr.ini"); if (DoesFreeLdrExist) { /* Update existing 'freeldr.ini' */ diff --git a/base/setup/usetup/filesup.c b/base/setup/usetup/filesup.c index 568525d095..293e590b76 100644 --- a/base/setup/usetup/filesup.c +++ b/base/setup/usetup/filesup.c @@ -93,90 +93,6 @@ SetupCreateSingleDirectory( return Status; } - -static -BOOLEAN -DoesPathExist( - PWSTR PathName) -{ - OBJECT_ATTRIBUTES ObjectAttributes; - IO_STATUS_BLOCK IoStatusBlock; - UNICODE_STRING Name; - HANDLE FileHandle; - NTSTATUS Status; - - RtlInitUnicodeString(&Name, - PathName); - - InitializeObjectAttributes(&ObjectAttributes, - &Name, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - - Status = NtOpenFile(&FileHandle, - GENERIC_READ | SYNCHRONIZE, - &ObjectAttributes, - &IoStatusBlock, - 0, - FILE_SYNCHRONOUS_IO_NONALERT); - if (!NT_SUCCESS(Status)) - { - return FALSE; - } - - NtClose(FileHandle); - - return TRUE; -} - - -BOOLEAN -IsValidPath( - PWCHAR InstallDir) -{ - UINT i, Length; - - Length = wcslen(InstallDir); - - // TODO: Add check for 8.3 too. - - /* Path must be at least 2 characters long */ -// if (Length < 2) -// return FALSE; - - /* Path must start with a backslash */ -// if (InstallDir[0] != L'\\') -// return FALSE; - - /* Path must not end with a backslash */ - if (InstallDir[Length - 1] == L'\\') - return FALSE; - - /* Path must not contain whitespace characters */ - for (i = 0; i < Length; i++) - { - if (isspace(InstallDir[i])) - return FALSE; - } - - /* Path component must not end with a dot */ - for (i = 0; i < Length; i++) - { - if (InstallDir[i] == L'\\' && i > 0) - { - if (InstallDir[i - 1] == L'.') - return FALSE; - } - } - - if (InstallDir[Length - 1] == L'.') - return FALSE; - - return TRUE; -} - - NTSTATUS SetupCreateDirectory( PWCHAR PathName) @@ -214,7 +130,7 @@ SetupCreateDirectory( *Ptr = 0; DPRINT("PathBuffer: %S\n", PathBuffer); - if (!DoesPathExist(PathBuffer)) + if (!DoesPathExist(NULL, PathBuffer)) { DPRINT("Create: %S\n", PathBuffer); Status = SetupCreateSingleDirectory(PathBuffer); @@ -228,7 +144,7 @@ SetupCreateDirectory( Ptr++; } - if (!DoesPathExist(PathBuffer)) + if (!DoesPathExist(NULL, PathBuffer)) { DPRINT("Create: %S\n", PathBuffer); Status = SetupCreateSingleDirectory(PathBuffer); @@ -244,7 +160,6 @@ done: return Status; } - NTSTATUS SetupCopyFile( PWCHAR SourceFileName, @@ -561,49 +476,279 @@ SetupExtractFile( } +BOOLEAN +IsValidPath( + IN PCWSTR InstallDir) +{ + UINT i, Length; + + Length = wcslen(InstallDir); + + // TODO: Add check for 8.3 too. + + /* Path must be at least 2 characters long */ +// if (Length < 2) +// return FALSE; + + /* Path must start with a backslash */ +// if (InstallDir[0] != L'\\') +// return FALSE; + + /* Path must not end with a backslash */ + if (InstallDir[Length - 1] == L'\\') + return FALSE; + + /* Path must not contain whitespace characters */ + for (i = 0; i < Length; i++) + { + if (isspace(InstallDir[i])) + return FALSE; + } + + /* Path component must not end with a dot */ + for (i = 0; i < Length; i++) + { + if (InstallDir[i] == L'\\' && i > 0) + { + if (InstallDir[i - 1] == L'.') + return FALSE; + } + } + + if (InstallDir[Length - 1] == L'.') + return FALSE; + + return TRUE; +} + +NTSTATUS +ConcatPaths( + IN OUT PWSTR PathElem1, + IN SIZE_T cchPathSize, + IN PCWSTR PathElem2 OPTIONAL) +{ + NTSTATUS Status; + SIZE_T cchPathLen; + + if (!PathElem2) + return STATUS_SUCCESS; + if (cchPathSize <= 1) + return STATUS_SUCCESS; + + cchPathLen = min(cchPathSize, wcslen(PathElem1)); + + if (PathElem2[0] != L'\\' && cchPathLen > 0 && PathElem1[cchPathLen-1] != L'\\') + { + /* PathElem2 does not start with '\' and PathElem1 does not end with '\' */ + Status = RtlStringCchCatW(PathElem1, cchPathSize, L"\\"); + if (!NT_SUCCESS(Status)) + return Status; + } + else if (PathElem2[0] == L'\\' && cchPathLen > 0 && PathElem1[cchPathLen-1] == L'\\') + { + /* PathElem2 starts with '\' and PathElem1 ends with '\' */ + while (*PathElem2 == L'\\') + ++PathElem2; // Skip any backslash + } + Status = RtlStringCchCatW(PathElem1, cchPathSize, PathElem2); + return Status; +} + +// +// NOTE: It may be possible to merge both DoesPathExist and DoesFileExist... +// +BOOLEAN +DoesPathExist( + IN HANDLE RootDirectory OPTIONAL, + IN PCWSTR PathName) +{ + NTSTATUS Status; + HANDLE FileHandle; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING Name; + + RtlInitUnicodeString(&Name, PathName); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + RootDirectory, + NULL); + + Status = NtOpenFile(&FileHandle, + FILE_LIST_DIRECTORY | SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE); + if (NT_SUCCESS(Status)) + NtClose(FileHandle); + else + DPRINT1("Failed to open directory %wZ, Status 0x%08lx\n", &Name, Status); + + return NT_SUCCESS(Status); +} + BOOLEAN DoesFileExist( - PWSTR PathName, - PWSTR FileName) + IN HANDLE RootDirectory OPTIONAL, + IN PCWSTR PathName OPTIONAL, + IN PCWSTR FileName) { + NTSTATUS Status; + HANDLE FileHandle; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; UNICODE_STRING Name; WCHAR FullName[MAX_PATH]; - HANDLE FileHandle; - NTSTATUS Status; - wcscpy(FullName, PathName); - if (FileName != NULL) - { - if (FileName[0] != L'\\') - wcscat(FullName, L"\\"); - wcscat(FullName, FileName); - } + if (PathName) + RtlStringCchCopyW(FullName, ARRAYSIZE(FullName), PathName); + else + FullName[0] = UNICODE_NULL; - RtlInitUnicodeString(&Name, - FullName); + if (FileName) + ConcatPaths(FullName, ARRAYSIZE(FullName), FileName); + + RtlInitUnicodeString(&Name, FullName); InitializeObjectAttributes(&ObjectAttributes, &Name, OBJ_CASE_INSENSITIVE, - NULL, + RootDirectory, NULL); Status = NtOpenFile(&FileHandle, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, - 0, - FILE_SYNCHRONOUS_IO_NONALERT); + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE); + if (NT_SUCCESS(Status)) + NtClose(FileHandle); + else + DPRINT1("Failed to open file %wZ, Status 0x%08lx\n", &Name, Status); + + return NT_SUCCESS(Status); +} + +NTSTATUS +OpenAndMapFile( + IN HANDLE RootDirectory OPTIONAL, + IN PCWSTR PathName OPTIONAL, + IN PCWSTR FileName, // OPTIONAL + OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL + OUT PHANDLE SectionHandle, + OUT PVOID* BaseAddress) +{ + NTSTATUS Status; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + SIZE_T ViewSize; + PVOID ViewBase; + UNICODE_STRING Name; + WCHAR FullName[MAX_PATH]; + + if (PathName) + RtlStringCchCopyW(FullName, ARRAYSIZE(FullName), PathName); + else + FullName[0] = UNICODE_NULL; + + if (FileName) + ConcatPaths(FullName, ARRAYSIZE(FullName), FileName); + + RtlInitUnicodeString(&Name, FullName); + + InitializeObjectAttributes(&ObjectAttributes, + &Name, + OBJ_CASE_INSENSITIVE, + RootDirectory, + NULL); + + *FileHandle = NULL; + *SectionHandle = NULL; + + Status = NtOpenFile(FileHandle, + GENERIC_READ | SYNCHRONIZE, + &ObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ, + FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE); if (!NT_SUCCESS(Status)) { - return FALSE; + DPRINT1("Failed to open file %wZ, Status 0x%08lx\n", &Name, Status); + return Status; } - NtClose(FileHandle); + /* Map the file in memory */ - return TRUE; + /* Create the section */ + Status = NtCreateSection(SectionHandle, + SECTION_MAP_READ, + NULL, + NULL, + PAGE_READONLY, + SEC_COMMIT /* | SEC_IMAGE (_NO_EXECUTE) */, + *FileHandle); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to create a memory section for file %wZ, Status 0x%08lx\n", &Name, Status); + NtClose(*FileHandle); + *FileHandle = NULL; + return Status; + } + + /* Map the section */ + ViewSize = 0; + ViewBase = NULL; + Status = NtMapViewOfSection(*SectionHandle, + NtCurrentProcess(), + &ViewBase, + 0, 0, + NULL, + &ViewSize, + ViewShare, + 0, + PAGE_READONLY); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to map a view for file %wZ, Status 0x%08lx\n", &Name, Status); + NtClose(*SectionHandle); + *SectionHandle = NULL; + NtClose(*FileHandle); + *FileHandle = NULL; + return Status; + } + + *BaseAddress = ViewBase; + return STATUS_SUCCESS; +} + +BOOLEAN +UnMapFile( + IN HANDLE SectionHandle, + IN PVOID BaseAddress) +{ + NTSTATUS Status; + BOOLEAN Success = TRUE; + + Status = NtUnmapViewOfSection(NtCurrentProcess(), BaseAddress); + if (!NT_SUCCESS(Status)) + { + DPRINT1("UnMapFile: NtUnmapViewOfSection(0x%p) failed with Status 0x%08lx\n", + BaseAddress, Status); + Success = FALSE; + } + Status = NtClose(SectionHandle); + if (!NT_SUCCESS(Status)) + { + DPRINT1("UnMapFile: NtClose(0x%p) failed with Status 0x%08lx\n", + SectionHandle, Status); + Success = FALSE; + } + + return Success; } /* EOF */ diff --git a/base/setup/usetup/filesup.h b/base/setup/usetup/filesup.h index e09a08c673..492dff0e87 100644 --- a/base/setup/usetup/filesup.h +++ b/base/setup/usetup/filesup.h @@ -41,13 +41,40 @@ SetupExtractFile( PWCHAR SourceFileName, PWCHAR DestinationFileName); + +BOOLEAN +IsValidPath( + IN PCWSTR InstallDir); + +NTSTATUS +ConcatPaths( + IN OUT PWSTR PathElem1, + IN SIZE_T cchPathSize, + IN PCWSTR PathElem2 OPTIONAL); + +BOOLEAN +DoesPathExist( + IN HANDLE RootDirectory OPTIONAL, + IN PCWSTR PathName); + BOOLEAN DoesFileExist( - PWSTR PathName, - PWSTR FileName); + IN HANDLE RootDirectory OPTIONAL, + IN PCWSTR PathName OPTIONAL, + IN PCWSTR FileName); + +NTSTATUS +OpenAndMapFile( + IN HANDLE RootDirectory OPTIONAL, + IN PCWSTR PathName OPTIONAL, + IN PCWSTR FileName, // OPTIONAL + OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL + OUT PHANDLE SectionHandle, + OUT PVOID* BaseAddress); BOOLEAN -IsValidPath( - PWCHAR InstallDir); +UnMapFile( + IN HANDLE SectionHandle, + IN PVOID BaseAddress); /* EOF */ diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 8c80812265..234bfa45be 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -424,7 +424,7 @@ CheckUnattendedSetup(VOID) INT IntValue; PWCHAR Value; - if (DoesFileExist(SourcePath.Buffer, L"unattend.inf") == FALSE) + if (DoesFileExist(NULL, SourcePath.Buffer, L"unattend.inf") == FALSE) { DPRINT("Does not exist: %S\\%S\n", SourcePath.Buffer, L"unattend.inf"); return; @@ -4462,7 +4462,7 @@ BootLoaderFloppyPage(PINPUT_RECORD Ir) } else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */ { - if (DoesFileExist(L"\\Device\\Floppy0", L"\\") == FALSE) + if (DoesFileExist(NULL, L"\\Device\\Floppy0", L"\\") == FALSE) { MUIDisplayError(ERROR_NO_FLOPPY, Ir, POPUP_WAIT_ENTER); return BOOT_LOADER_FLOPPY_PAGE; diff --git a/base/setup/usetup/usetup.h b/base/setup/usetup/usetup.h index 37cae20f7f..53be28b3dc 100644 --- a/base/setup/usetup/usetup.h +++ b/base/setup/usetup/usetup.h @@ -39,8 +39,6 @@ #include <winuser.h> #include <wincon.h> -#include <strsafe.h> - #define NTOS_MODE_USER #include <ndk/cmfuncs.h> #include <ndk/exfuncs.h> @@ -52,6 +50,8 @@ #include <ndk/rtlfuncs.h> #include <ndk/setypes.h> +#include <ntstrsafe.h> + /* Filesystem headers */ #include <reactos/rosioctl.h> #include <fslib/vfatlib.h>
6 years, 7 months
1
0
0
0
02/05: [USETUP] Fix some spacings in the french translation.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=14284ddc618661fc8c8e6…
commit 14284ddc618661fc8c8e64acde2238ca3dfd7897 Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Wed May 17 23:37:41 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 19:09:37 2018 +0200 [USETUP] Fix some spacings in the french translation. svn path=/branches/setup_improvements/; revision=74574 --- base/setup/usetup/lang/fr-FR.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/setup/usetup/lang/fr-FR.h b/base/setup/usetup/lang/fr-FR.h index 4bd09c239a..86d1be6bb6 100644 --- a/base/setup/usetup/lang/fr-FR.h +++ b/base/setup/usetup/lang/fr-FR.h @@ -1807,11 +1807,11 @@ MUI_STRING frFRStrings[] = {STRING_CHECKINGDISK, "Setup v�rifie votre disque"}, {STRING_FORMATDISK1, - " Formater la partition comme syst�me de fichiers %S(formatage rapide) "}, + " Formater la partition comme syst�me de fichiers %S (formatage rapide) "}, {STRING_FORMATDISK2, " Formater la partition comme syst�me de fichiers %S "}, {STRING_KEEPFORMAT, - " Garder le syst�me de fichiers courant(pas de changements) "}, + " Garder le syst�me de fichiers courant (pas de changements) "}, {STRING_HDINFOPARTCREATE, "%I64u %s Disque dur %lu (Port=%hu, Bus=%hu, Id=%hu) sur %wZ."}, {STRING_HDDINFOUNK1,
6 years, 7 months
1
0
0
0
01/05: [USETUP] Code formatting only.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=833c0e59da646393159ec…
commit 833c0e59da646393159ec7512b50957b286866ad Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sat May 13 16:23:08 2017 +0000 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sat May 26 19:09:35 2018 +0200 [USETUP] Code formatting only. svn path=/branches/setup_improvements/; revision=74530 --- base/setup/usetup/usetup.c | 57 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index d29f15d57c..8c80812265 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -1605,32 +1605,32 @@ SelectPartitionPage(PINPUT_RECORD Ir) } else if (PartitionList->CurrentPartition->LogicalPartition) { - if (PartitionList->CurrentPartition->IsPartitioned) - { - CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); - } - else - { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATELOGICAL)); - } + if (PartitionList->CurrentPartition->IsPartitioned) + { + CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); + } + else + { + CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATELOGICAL)); + } } else { - if (PartitionList->CurrentPartition->IsPartitioned) - { - if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType)) - { - CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); - } - else - { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLDELETEPARTITION)); - } - } - else - { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION)); - } + if (PartitionList->CurrentPartition->IsPartitioned) + { + if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType)) + { + CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); + } + else + { + CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLDELETEPARTITION)); + } + } + else + { + CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION)); + } } CONSOLE_ConInKey(Ir); @@ -1662,7 +1662,7 @@ SelectPartitionPage(PINPUT_RECORD Ir) else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */ { if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType)) - continue; //return SELECT_PARTITION_PAGE; + continue; // return SELECT_PARTITION_PAGE; if (PartitionList->CurrentPartition == NULL || PartitionList->CurrentPartition->IsPartitioned == FALSE) @@ -2741,7 +2741,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) DiskEntry = PartitionList->TempDisk; PartEntry = PartitionList->TempPartition; - /* adjust disk size */ + /* Adjust disk size */ DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector; if (DiskSize >= 10737418240) /* 10 GB */ { @@ -2754,7 +2754,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) DiskUnit = MUIGetString(STRING_MB); } - /* adjust partition size */ + /* Adjust partition size */ PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector; if (PartSize >= 10737418240) /* 10 GB */ { @@ -2767,7 +2767,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) PartUnit = MUIGetString(STRING_MB); } - /* adjust partition type */ + /* Adjust partition type */ GetPartTypeStringFromPartitionType(PartEntry->PartitionType, PartTypeString, ARRAYSIZE(PartTypeString)); @@ -2795,7 +2795,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir) CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_PARTFORMAT)); - PartEntry->AutoCreate = FALSE; } else if (PartEntry->New != FALSE) @@ -2920,7 +2919,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir) { if (!FileSystemList->Selected->FormatFunc) { - return SELECT_FILE_SYSTEM_PAGE; + return SELECT_FILE_SYSTEM_PAGE; } else {
6 years, 7 months
1
0
0
0
01/01: [MSV1_0] Add logon support for the LocalService and NetworkService accounts
by Eric Kohl
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f42b4bbe172be699323b3…
commit f42b4bbe172be699323b3b38e3ed43c178fdc662 Author: Eric Kohl <eric.kohl(a)reactos.org> AuthorDate: Sat May 26 18:42:31 2018 +0200 Commit: Eric Kohl <eric.kohl(a)reactos.org> CommitDate: Sat May 26 18:43:46 2018 +0200 [MSV1_0] Add logon support for the LocalService and NetworkService accounts --- dll/win32/msv1_0/msv1_0.c | 386 ++++++++++++++++++++++++++++++---------------- 1 file changed, 256 insertions(+), 130 deletions(-) diff --git a/dll/win32/msv1_0/msv1_0.c b/dll/win32/msv1_0/msv1_0.c index 624ea2b417..8c9a1b617b 100644 --- a/dll/win32/msv1_0/msv1_0.c +++ b/dll/win32/msv1_0/msv1_0.c @@ -22,7 +22,7 @@ LSA_DISPATCH_TABLE DispatchTable; static NTSTATUS -GetDomainSid(PRPC_SID *Sid) +GetAccountDomainSid(PRPC_SID *Sid) { LSAPR_HANDLE PolicyHandle = NULL; PLSAPR_POLICY_INFORMATION PolicyInfo = NULL; @@ -69,6 +69,27 @@ done: } +static +NTSTATUS +GetNtAuthorityDomainSid(PRPC_SID *Sid) +{ + SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY}; + ULONG Length = 0; + + Length = RtlLengthRequiredSid(0); + *Sid = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length); + if (*Sid == NULL) + { + ERR("Failed to allocate SID\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + + RtlInitializeSid(*Sid,&NtAuthority, 0); + + return STATUS_SUCCESS; +} + + static NTSTATUS BuildInteractiveProfileBuffer(IN PLSA_CLIENT_REQUEST ClientRequest, @@ -287,34 +308,72 @@ BuildTokenPrimaryGroup(OUT PTOKEN_PRIMARY_GROUP PrimaryGroup, static NTSTATUS BuildTokenGroups(OUT PTOKEN_GROUPS *Groups, - IN PSID AccountDomainSid) + IN PSID AccountDomainSid, + IN ULONG RelativeId, + IN BOOL SpecialAccount) { SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY}; PTOKEN_GROUPS TokenGroups; -#define MAX_GROUPS 2 DWORD GroupCount = 0; + DWORD MaxGroups = 2; PSID Sid; NTSTATUS Status = STATUS_SUCCESS; + if (SpecialAccount) + MaxGroups++; + TokenGroups = DispatchTable.AllocateLsaHeap(sizeof(TOKEN_GROUPS) + - MAX_GROUPS * sizeof(SID_AND_ATTRIBUTES)); + MaxGroups * sizeof(SID_AND_ATTRIBUTES)); if (TokenGroups == NULL) { return STATUS_INSUFFICIENT_RESOURCES; } - Sid = AppendRidToSid(AccountDomainSid, DOMAIN_GROUP_RID_USERS); - if (Sid == NULL) + if (SpecialAccount) { + /* Self */ + Sid = AppendRidToSid(AccountDomainSid, RelativeId); + if (Sid == NULL) + { + + } + TokenGroups->Groups[GroupCount].Sid = Sid; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + GroupCount++; + + /* Member of 'Users' alias */ + RtlAllocateAndInitializeSid(&SystemAuthority, + 2, + SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_USERS, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + SECURITY_NULL_RID, + &Sid); + TokenGroups->Groups[GroupCount].Sid = Sid; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + GroupCount++; } + else + { + /* Member of the domains users group */ + Sid = AppendRidToSid(AccountDomainSid, DOMAIN_GROUP_RID_USERS); + if (Sid == NULL) + { - /* Member of the domain */ - TokenGroups->Groups[GroupCount].Sid = Sid; - TokenGroups->Groups[GroupCount].Attributes = - SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; - GroupCount++; + } + TokenGroups->Groups[GroupCount].Sid = Sid; + TokenGroups->Groups[GroupCount].Attributes = + SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY; + GroupCount++; + } /* Member of 'Authenticated users' */ RtlAllocateAndInitializeSid(&SystemAuthority, @@ -334,7 +393,7 @@ BuildTokenGroups(OUT PTOKEN_GROUPS *Groups, GroupCount++; TokenGroups->GroupCount = GroupCount; - ASSERT(TokenGroups->GroupCount <= MAX_GROUPS); + ASSERT(TokenGroups->GroupCount <= MaxGroups); *Groups = TokenGroups; @@ -346,7 +405,8 @@ static NTSTATUS BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation, PRPC_SID AccountDomainSid, - PSAMPR_USER_INFO_BUFFER UserInfo) + PSAMPR_USER_INFO_BUFFER UserInfo, + BOOL SpecialAccount) { PLSA_TOKEN_INFORMATION_V1 Buffer = NULL; ULONG i; @@ -376,7 +436,9 @@ BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation, goto done; Status = BuildTokenGroups(&Buffer->Groups, - (PSID)AccountDomainSid); + (PSID)AccountDomainSid, + UserInfo->All.UserId, + SpecialAccount); if (!NT_SUCCESS(Status)) goto done; @@ -970,9 +1032,10 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest, // LARGE_INTEGER AccountExpires; LARGE_INTEGER PasswordMustChange; LARGE_INTEGER PasswordLastSet; + BOOL SpecialAccount = FALSE; NTSTATUS Status; - TRACE("()\n"); + TRACE("LsaApLogonUser()\n"); TRACE("LogonType: %lu\n", LogonType); TRACE("AuthenticationInformation: %p\n", AuthenticationInformation); @@ -1012,153 +1075,215 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest, /* Get the logon time */ NtQuerySystemTime(&LogonTime); - /* Get the domain SID */ - Status = GetDomainSid(&AccountDomainSid); - if (!NT_SUCCESS(Status)) - { - TRACE("GetDomainSid() failed (Status 0x%08lx)\n", Status); - return Status; - } - - /* Connect to the SAM server */ - Status = SamIConnect(NULL, - &ServerHandle, - SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN, - TRUE); - if (!NT_SUCCESS(Status)) + /* Check for special accounts */ + if (_wcsicmp(LogonInfo->LogonDomainName.Buffer, L"NT AUTHORITY") == 0) { - TRACE("SamIConnect() failed (Status 0x%08lx)\n", Status); - goto done; - } + SpecialAccount = TRUE; - /* Open the account domain */ - Status = SamrOpenDomain(ServerHandle, - DOMAIN_LOOKUP, - AccountDomainSid, - &DomainHandle); - if (!NT_SUCCESS(Status)) - { - TRACE("SamrOpenDomain failed (Status %08lx)\n", Status); - goto done; - } + /* Get the authority domain SID */ + Status = GetNtAuthorityDomainSid(&AccountDomainSid); + if (!NT_SUCCESS(Status)) + { + ERR("GetNtAuthorityDomainSid() failed (Status 0x%08lx)\n", Status); + return Status; + } - Names[0].Length = LogonInfo->UserName.Length; - Names[0].MaximumLength = LogonInfo->UserName.MaximumLength; - Names[0].Buffer = LogonInfo->UserName.Buffer; + if (_wcsicmp(LogonInfo->UserName.Buffer, L"LocalService") == 0) + { + TRACE("SpecialAccount: LocalService\n"); - /* Try to get the RID for the user name */ - Status = SamrLookupNamesInDomain(DomainHandle, - 1, - Names, - &RelativeIds, - &Use); - if (!NT_SUCCESS(Status)) - { - TRACE("SamrLookupNamesInDomain failed (Status %08lx)\n", Status); - Status = STATUS_NO_SUCH_USER; - goto done; - } + if (LogonType != Service) + return STATUS_LOGON_FAILURE; - /* Fail, if it is not a user account */ - if (Use.Element[0] != SidTypeUser) - { - TRACE("Account is not a user account!\n"); - Status = STATUS_NO_SUCH_USER; - goto done; - } + UserInfo = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(SAMPR_USER_ALL_INFORMATION)); + if (UserInfo == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto done; + } - /* Open the user object */ - Status = SamrOpenUser(DomainHandle, - USER_READ_GENERAL | USER_READ_LOGON | - USER_READ_ACCOUNT | USER_READ_PREFERENCES, /* FIXME */ - RelativeIds.Element[0], - &UserHandle); - if (!NT_SUCCESS(Status)) - { - TRACE("SamrOpenUser failed (Status %08lx)\n", Status); - goto done; - } + UserInfo->All.UserId = SECURITY_LOCAL_SERVICE_RID; + UserInfo->All.PrimaryGroupId = SECURITY_LOCAL_SERVICE_RID; + } + else if (_wcsicmp(LogonInfo->UserName.Buffer, L"NetworkService") == 0) + { + TRACE("SpecialAccount: NetworkService\n"); - Status = SamrQueryInformationUser(UserHandle, - UserAllInformation, - &UserInfo); - if (!NT_SUCCESS(Status)) - { - TRACE("SamrQueryInformationUser failed (Status %08lx)\n", Status); - goto done; - } + if (LogonType != Service) + return STATUS_LOGON_FAILURE; - TRACE("UserName: %S\n", UserInfo->All.UserName.Buffer); + UserInfo = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(SAMPR_USER_ALL_INFORMATION)); + if (UserInfo == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto done; + } - /* Check the password */ - if ((UserInfo->All.UserAccountControl & USER_PASSWORD_NOT_REQUIRED) == 0) - { - Status = MsvpCheckPassword(&(LogonInfo->Password), - UserInfo); - if (!NT_SUCCESS(Status)) + UserInfo->All.UserId = SECURITY_NETWORK_SERVICE_RID; + UserInfo->All.PrimaryGroupId = SECURITY_NETWORK_SERVICE_RID; + } + else { - TRACE("MsvpCheckPassword failed (Status %08lx)\n", Status); + Status = STATUS_NO_SUCH_USER; goto done; } } - - /* Check account restrictions for non-administrator accounts */ - if (RelativeIds.Element[0] != DOMAIN_USER_RID_ADMIN) + else { - /* Check if the account has been disabled */ - if (UserInfo->All.UserAccountControl & USER_ACCOUNT_DISABLED) + TRACE("NormalAccount\n"); + + /* Get the account domain SID */ + Status = GetAccountDomainSid(&AccountDomainSid); + if (!NT_SUCCESS(Status)) { - ERR("Account disabled!\n"); - *SubStatus = STATUS_ACCOUNT_DISABLED; - Status = STATUS_ACCOUNT_RESTRICTION; + ERR("GetAccountDomainSid() failed (Status 0x%08lx)\n", Status); + return Status; + } + + /* Connect to the SAM server */ + Status = SamIConnect(NULL, + &ServerHandle, + SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN, + TRUE); + if (!NT_SUCCESS(Status)) + { + TRACE("SamIConnect() failed (Status 0x%08lx)\n", Status); goto done; } - /* Check if the account has been locked */ - if (UserInfo->All.UserAccountControl & USER_ACCOUNT_AUTO_LOCKED) + /* Open the account domain */ + Status = SamrOpenDomain(ServerHandle, + DOMAIN_LOOKUP, + AccountDomainSid, + &DomainHandle); + if (!NT_SUCCESS(Status)) { - ERR("Account locked!\n"); - *SubStatus = STATUS_ACCOUNT_LOCKED_OUT; - Status = STATUS_ACCOUNT_RESTRICTION; + ERR("SamrOpenDomain failed (Status %08lx)\n", Status); goto done; } -#if 0 - /* Check if the account expired */ - AccountExpires.LowPart = UserInfo->All.AccountExpires.LowPart; - AccountExpires.HighPart = UserInfo->All.AccountExpires.HighPart; + Names[0].Length = LogonInfo->UserName.Length; + Names[0].MaximumLength = LogonInfo->UserName.MaximumLength; + Names[0].Buffer = LogonInfo->UserName.Buffer; - if (AccountExpires.QuadPart != 0 && - LogonTime.QuadPart >= AccountExpires.QuadPart) + /* Try to get the RID for the user name */ + Status = SamrLookupNamesInDomain(DomainHandle, + 1, + Names, + &RelativeIds, + &Use); + if (!NT_SUCCESS(Status)) { - ERR("Account expired!\n"); - *SubStatus = STATUS_ACCOUNT_EXPIRED; - Status = STATUS_ACCOUNT_RESTRICTION; + ERR("SamrLookupNamesInDomain failed (Status %08lx)\n", Status); + Status = STATUS_NO_SUCH_USER; goto done; } -#endif - /* Check if the password expired */ - PasswordMustChange.LowPart = UserInfo->All.PasswordMustChange.LowPart; - PasswordMustChange.HighPart = UserInfo->All.PasswordMustChange.HighPart; - PasswordLastSet.LowPart = UserInfo->All.PasswordLastSet.LowPart; - PasswordLastSet.HighPart = UserInfo->All.PasswordLastSet.HighPart; + /* Fail, if it is not a user account */ + if (Use.Element[0] != SidTypeUser) + { + ERR("Account is not a user account!\n"); + Status = STATUS_NO_SUCH_USER; + goto done; + } - if (LogonTime.QuadPart >= PasswordMustChange.QuadPart) + /* Open the user object */ + Status = SamrOpenUser(DomainHandle, + USER_READ_GENERAL | USER_READ_LOGON | + USER_READ_ACCOUNT | USER_READ_PREFERENCES, /* FIXME */ + RelativeIds.Element[0], + &UserHandle); + if (!NT_SUCCESS(Status)) { - ERR("Password expired!\n"); - if (PasswordLastSet.QuadPart == 0) - *SubStatus = STATUS_PASSWORD_MUST_CHANGE; - else - *SubStatus = STATUS_PASSWORD_EXPIRED; + ERR("SamrOpenUser failed (Status %08lx)\n", Status); + goto done; + } - Status = STATUS_ACCOUNT_RESTRICTION; + Status = SamrQueryInformationUser(UserHandle, + UserAllInformation, + &UserInfo); + if (!NT_SUCCESS(Status)) + { + ERR("SamrQueryInformationUser failed (Status %08lx)\n", Status); goto done; } - /* FIXME: more checks */ - // STATUS_INVALID_LOGON_HOURS; - // STATUS_INVALID_WORKSTATION; + TRACE("UserName: %S\n", UserInfo->All.UserName.Buffer); + + /* Check the password */ + if ((UserInfo->All.UserAccountControl & USER_PASSWORD_NOT_REQUIRED) == 0) + { + Status = MsvpCheckPassword(&(LogonInfo->Password), + UserInfo); + if (!NT_SUCCESS(Status)) + { + ERR("MsvpCheckPassword failed (Status %08lx)\n", Status); + goto done; + } + } + + /* Check account restrictions for non-administrator accounts */ + if (RelativeIds.Element[0] != DOMAIN_USER_RID_ADMIN) + { + /* Check if the account has been disabled */ + if (UserInfo->All.UserAccountControl & USER_ACCOUNT_DISABLED) + { + ERR("Account disabled!\n"); + *SubStatus = STATUS_ACCOUNT_DISABLED; + Status = STATUS_ACCOUNT_RESTRICTION; + goto done; + } + + /* Check if the account has been locked */ + if (UserInfo->All.UserAccountControl & USER_ACCOUNT_AUTO_LOCKED) + { + ERR("Account locked!\n"); + *SubStatus = STATUS_ACCOUNT_LOCKED_OUT; + Status = STATUS_ACCOUNT_RESTRICTION; + goto done; + } + +#if 0 + /* Check if the account expired */ + AccountExpires.LowPart = UserInfo->All.AccountExpires.LowPart; + AccountExpires.HighPart = UserInfo->All.AccountExpires.HighPart; + + if (AccountExpires.QuadPart != 0 && + LogonTime.QuadPart >= AccountExpires.QuadPart) + { + ERR("Account expired!\n"); + *SubStatus = STATUS_ACCOUNT_EXPIRED; + Status = STATUS_ACCOUNT_RESTRICTION; + goto done; + } +#endif + + /* Check if the password expired */ + PasswordMustChange.LowPart = UserInfo->All.PasswordMustChange.LowPart; + PasswordMustChange.HighPart = UserInfo->All.PasswordMustChange.HighPart; + PasswordLastSet.LowPart = UserInfo->All.PasswordLastSet.LowPart; + PasswordLastSet.HighPart = UserInfo->All.PasswordLastSet.HighPart; + + if (LogonTime.QuadPart >= PasswordMustChange.QuadPart) + { + ERR("Password expired!\n"); + if (PasswordLastSet.QuadPart == 0) + *SubStatus = STATUS_PASSWORD_MUST_CHANGE; + else + *SubStatus = STATUS_PASSWORD_EXPIRED; + + Status = STATUS_ACCOUNT_RESTRICTION; + goto done; + } + + /* FIXME: more checks */ + // STATUS_INVALID_LOGON_HOURS; + // STATUS_INVALID_WORKSTATION; + } } /* Return logon information */ @@ -1199,7 +1324,8 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest, /* Build and fill the token information buffer */ Status = BuildTokenInformationBuffer((PLSA_TOKEN_INFORMATION_V1*)TokenInformation, AccountDomainSid, - UserInfo); + UserInfo, + SpecialAccount); if (!NT_SUCCESS(Status)) { TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status);
6 years, 7 months
1
0
0
0
01/01: [FASTFAT] Lock DirResource when modifying an entry on disk.
by Pierre Schweitzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fc788cf2fde7551a8e506…
commit fc788cf2fde7551a8e5068f2b061c3cad2004e9a Author: Pierre Schweitzer <pierre(a)reactos.org> AuthorDate: Sat May 26 17:12:03 2018 +0200 Commit: Pierre Schweitzer <pierre(a)reactos.org> CommitDate: Sat May 26 17:13:08 2018 +0200 [FASTFAT] Lock DirResource when modifying an entry on disk. Likely not optimal, but fixes some races conditions where the directory is uninit in the middle of the write. --- drivers/filesystems/fastfat/finfo.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/filesystems/fastfat/finfo.c b/drivers/filesystems/fastfat/finfo.c index d860cd641b..af2e1ce62a 100644 --- a/drivers/filesystems/fastfat/finfo.c +++ b/drivers/filesystems/fastfat/finfo.c @@ -1552,6 +1552,7 @@ VfatSetInformation( PVFATFCB FCB; NTSTATUS Status = STATUS_SUCCESS; PVOID SystemBuffer; + BOOLEAN LockDir; /* PRECONDITION */ ASSERT(IrpContext); @@ -1593,7 +1594,14 @@ VfatSetInformation( DPRINT("Can set file size\n"); } - if (FileInformationClass == FileRenameInformation) + LockDir = FALSE; + if (FileInformationClass == FileRenameInformation || FileInformationClass == FileAllocationInformation || + FileInformationClass == FileEndOfFileInformation || FileInformationClass == FileBasicInformation) + { + LockDir = TRUE; + } + + if (LockDir) { if (!ExAcquireResourceExclusiveLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) @@ -1607,7 +1615,7 @@ VfatSetInformation( if (!ExAcquireResourceExclusiveLite(&FCB->MainResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT))) { - if (FileInformationClass == FileRenameInformation) + if (LockDir) { ExReleaseResourceLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource); } @@ -1662,7 +1670,7 @@ VfatSetInformation( ExReleaseResourceLite(&FCB->MainResource); } - if (FileInformationClass == FileRenameInformation) + if (LockDir) { ExReleaseResourceLite(&((PDEVICE_EXTENSION)IrpContext->DeviceObject->DeviceExtension)->DirResource); }
6 years, 7 months
1
0
0
0
← Newer
1
...
5
6
7
8
9
10
11
...
22
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Results per page:
10
25
50
100
200