From db07c0df92eca4f17270894cd41e96e72f5ea40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 31 Oct 2007 15:31:46 +0000 Subject: [PATCH] Remove LIST_ITEM structure, and replace it by well-known LIST_ENTRY Do according changes in callers Fix a bug in IniGetSectionSettingNameSize/IniGetSectionSettingValueSize, which were expecting memory to be allocated contiguously svn path=/trunk/; revision=30016 --- reactos/boot/freeldr/freeldr/bootmgr.c | 20 +- .../boot/freeldr/freeldr/cache/blocklist.c | 51 ++--- reactos/boot/freeldr/freeldr/cache/cache.c | 13 +- .../boot/freeldr/freeldr/freeldr_base.rbuild | 1 - reactos/boot/freeldr/freeldr/include/cache.h | 4 +- .../boot/freeldr/freeldr/include/inifile.h | 9 +- reactos/boot/freeldr/freeldr/include/rtl.h | 30 --- .../boot/freeldr/freeldr/inifile/ini_init.c | 5 +- .../boot/freeldr/freeldr/inifile/inifile.c | 139 +++++++------- reactos/boot/freeldr/freeldr/inifile/parse.c | 28 ++- reactos/boot/freeldr/freeldr/rtl/list.c | 176 ------------------ 11 files changed, 123 insertions(+), 353 deletions(-) delete mode 100644 reactos/boot/freeldr/freeldr/rtl/list.c diff --git a/reactos/boot/freeldr/freeldr/bootmgr.c b/reactos/boot/freeldr/freeldr/bootmgr.c index 4c74a1d8e15..878ed85025b 100644 --- a/reactos/boot/freeldr/freeldr/bootmgr.c +++ b/reactos/boot/freeldr/freeldr/bootmgr.c @@ -33,37 +33,33 @@ VOID RunLoader(VOID) if (!FsOpenBootVolume()) { - printf("Error opening boot partition for file access.\n"); - MachConsGetCh(); + UiMessageBoxCritical("Error opening boot partition for file access."); return; } if (!IniFileInitialize()) { - printf("Press any key to reboot.\n"); - MachConsGetCh(); + UiMessageBoxCritical("Error initializing .ini file"); return; } if (!IniOpenSection("FreeLoader", &SectionId)) { - printf("Section [FreeLoader] not found in freeldr.ini.\n"); - MachConsGetCh(); + UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini."); return; } TimeOut = GetTimeOut(); if (!UiInitialize(TimeOut)) { - printf("Press any key to reboot.\n"); - MachConsGetCh(); + UiMessageBoxCritical("Unable to initialize UI."); return; } if (!InitOperatingSystemList(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, &OperatingSystemCount)) { - UiMessageBox("Press ENTER to reboot.\n"); + UiMessageBox("Press ENTER to reboot."); goto reboot; } @@ -89,7 +85,7 @@ VOID RunLoader(VOID) // Show the operating system list menu if (!UiDisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem, FALSE, MainBootMenuKeyPressFilter)) { - UiMessageBox("Press ENTER to reboot.\n"); + UiMessageBox("Press ENTER to reboot."); goto reboot; } @@ -98,7 +94,7 @@ VOID RunLoader(VOID) // Try to open the operating system section in the .ini file if (!IniOpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId)) { - sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]); + sprintf(SettingName, "Section [%s] not found in freeldr.ini.", OperatingSystemSectionNames[SelectedOperatingSystem]); UiMessageBox(SettingName); continue; } @@ -106,7 +102,7 @@ VOID RunLoader(VOID) // Try to read the boot type if (!IniReadSettingByName(SectionId, "BootType", SettingValue, sizeof(SettingValue))) { - sprintf(SettingName, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]); + sprintf(SettingName, "BootType= line not found in section [%s] in freeldr.ini.", OperatingSystemSectionNames[SelectedOperatingSystem]); UiMessageBox(SettingName); continue; } diff --git a/reactos/boot/freeldr/freeldr/cache/blocklist.c b/reactos/boot/freeldr/freeldr/cache/blocklist.c index a7af67bf7ab..422eb7434fc 100644 --- a/reactos/boot/freeldr/freeldr/cache/blocklist.c +++ b/reactos/boot/freeldr/freeldr/cache/blocklist.c @@ -57,14 +57,14 @@ PCACHE_BLOCK CacheInternalFindBlock(PCACHE_DRIVE CacheDrive, ULONG BlockNumber) // // Make sure the block list has entries before I start searching it. // - if (!RtlListIsEmpty((PLIST_ITEM)CacheDrive->CacheBlockHead)) + if (!IsListEmpty(&CacheDrive->CacheBlockHead)) { // // Search the list and find the BIOS drive number // - CacheBlock = CacheDrive->CacheBlockHead; + CacheBlock = CONTAINING_RECORD(CacheDrive->CacheBlockHead.Flink, CACHE_BLOCK, ListEntry); - while (CacheBlock != NULL) + while (&CacheBlock->ListEntry != &CacheDrive->CacheBlockHead) { // // We found the block, so return it @@ -79,7 +79,7 @@ PCACHE_BLOCK CacheInternalFindBlock(PCACHE_DRIVE CacheDrive, ULONG BlockNumber) return CacheBlock; } - CacheBlock = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheBlock); + CacheBlock = CONTAINING_RECORD(CacheBlock->ListEntry.Flink, CACHE_BLOCK, ListEntry); } } @@ -125,14 +125,7 @@ PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNu RtlCopyMemory(CacheBlock->BlockData, (PVOID)DISKREADBUFFER, CacheDrive->BlockSize * CacheDrive->BytesPerSector); // Add it to our list of blocks managed by the cache - if (CacheDrive->CacheBlockHead == NULL) - { - CacheDrive->CacheBlockHead = CacheBlock; - } - else - { - RtlListInsertTail((PLIST_ITEM)CacheDrive->CacheBlockHead, (PLIST_ITEM)CacheBlock); - } + InsertTailList(&CacheDrive->CacheBlockHead, &CacheBlock->ListEntry); // Update the cache data CacheBlockCount++; @@ -152,28 +145,20 @@ BOOLEAN CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive) // Get a pointer to the last item in the block list // that isn't forced to be in the cache and remove // it from the list - CacheBlockToFree = (PCACHE_BLOCK)RtlListGetTail((PLIST_ITEM)CacheDrive->CacheBlockHead); - while (CacheBlockToFree != NULL && CacheBlockToFree->LockedInCache == TRUE) + CacheBlockToFree = CONTAINING_RECORD(CacheDrive->CacheBlockHead.Blink, CACHE_BLOCK, ListEntry); + while (&CacheBlockToFree->ListEntry != &CacheDrive->CacheBlockHead && CacheBlockToFree->LockedInCache == TRUE) { - CacheBlockToFree = (PCACHE_BLOCK)RtlListGetPrevious((PLIST_ITEM)CacheBlockToFree); + CacheBlockToFree = CONTAINING_RECORD(CacheBlockToFree->ListEntry.Blink, CACHE_BLOCK, ListEntry); } // No blocks left in cache that can be freed // so just return - if (CacheBlockToFree == NULL) + if (IsListEmpty(&CacheDrive->CacheBlockHead)) { return FALSE; } - // - // If we are freeing the head of the list then update it's pointer - // - if (CacheBlockToFree == CacheDrive->CacheBlockHead) - { - CacheDrive->CacheBlockHead = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheBlockToFree); - } - - RtlListRemoveEntry((PLIST_ITEM)CacheBlockToFree); + RemoveEntryList(&CacheBlockToFree->ListEntry); // Free the block memory and the block structure MmFreeMemory(CacheBlockToFree->BlockData); @@ -213,10 +198,9 @@ VOID CacheInternalDumpBlockList(PCACHE_DRIVE CacheDrive) DbgPrint((DPRINT_CACHE, "CacheSizeLimit: %d.\n", CacheSizeLimit)); DbgPrint((DPRINT_CACHE, "CacheSizeCurrent: %d.\n", CacheSizeCurrent)); DbgPrint((DPRINT_CACHE, "CacheBlockCount: %d.\n", CacheBlockCount)); - DbgPrint((DPRINT_CACHE, "Dumping %d cache blocks.\n", RtlListCountEntries((PLIST_ITEM)CacheDrive->CacheBlockHead))); - CacheBlock = CacheDrive->CacheBlockHead; - while (CacheBlock != NULL) + CacheBlock = CONTAINING_RECORD(CacheDrive->CacheBlockHead.Flink, CACHE_BLOCK, ListEntry); + while (&CacheBlock->ListEntry != &CacheDrive->CacheBlockHead) { DbgPrint((DPRINT_CACHE, "Cache Block: CacheBlock: 0x%x\n", CacheBlock)); DbgPrint((DPRINT_CACHE, "Cache Block: Block Number: %d\n", CacheBlock->BlockNumber)); @@ -229,7 +213,7 @@ VOID CacheInternalDumpBlockList(PCACHE_DRIVE CacheDrive) BugCheck((DPRINT_CACHE, "What the heck?!?\n")); } - CacheBlock = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheBlock); + CacheBlock = CONTAINING_RECORD(CacheBlock->ListEntry.Flink, CACHE_BLOCK, ListEntry); } } @@ -239,15 +223,12 @@ VOID CacheInternalOptimizeBlockList(PCACHE_DRIVE CacheDrive, PCACHE_BLOCK CacheB DbgPrint((DPRINT_CACHE, "CacheInternalOptimizeBlockList()\n")); // Don't do this if this block is already at the head of the list - if (CacheBlock != CacheDrive->CacheBlockHead) + if (&CacheBlock->ListEntry != CacheDrive->CacheBlockHead.Flink) { // Remove this item from the block list - RtlListRemoveEntry((PLIST_ITEM)CacheBlock); + RemoveEntryList(&CacheBlock->ListEntry); // Re-insert it at the head of the list - RtlListInsertHead((PLIST_ITEM)CacheDrive->CacheBlockHead, (PLIST_ITEM)CacheBlock); - - // Update the head pointer - CacheDrive->CacheBlockHead = CacheBlock; + InsertHeadList(&CacheDrive->CacheBlockHead, &CacheBlock->ListEntry); } } diff --git a/reactos/boot/freeldr/freeldr/cache/cache.c b/reactos/boot/freeldr/freeldr/cache/cache.c index c8b600342ea..153ed598cd0 100644 --- a/reactos/boot/freeldr/freeldr/cache/cache.c +++ b/reactos/boot/freeldr/freeldr/cache/cache.c @@ -64,19 +64,20 @@ BOOLEAN CacheInitializeDrive(ULONG DriveNumber) // // Loop through and free the cache blocks // - while (CacheManagerDrive.CacheBlockHead != NULL) + while (!IsListEmpty(&CacheManagerDrive.CacheBlockHead)) { - NextCacheBlock = (PCACHE_BLOCK)RtlListGetNext((PLIST_ITEM)CacheManagerDrive.CacheBlockHead); + NextCacheBlock = CONTAINING_RECORD(RemoveHeadList(&CacheManagerDrive.CacheBlockHead), + CACHE_BLOCK, + ListEntry); - MmFreeMemory(CacheManagerDrive.CacheBlockHead->BlockData); - MmFreeMemory(CacheManagerDrive.CacheBlockHead); - - CacheManagerDrive.CacheBlockHead = NextCacheBlock; + MmFreeMemory(NextCacheBlock->BlockData); + MmFreeMemory(NextCacheBlock); } } // Initialize the structure RtlZeroMemory(&CacheManagerDrive, sizeof(CACHE_DRIVE)); + InitializeListHead(&CacheManagerDrive.CacheBlockHead); CacheManagerDrive.DriveNumber = DriveNumber; if (!MachDiskGetDriveGeometry(DriveNumber, &DriveGeometry)) { diff --git a/reactos/boot/freeldr/freeldr/freeldr_base.rbuild b/reactos/boot/freeldr/freeldr/freeldr_base.rbuild index c8634d46176..802847b834c 100644 --- a/reactos/boot/freeldr/freeldr/freeldr_base.rbuild +++ b/reactos/boot/freeldr/freeldr/freeldr_base.rbuild @@ -51,7 +51,6 @@ libsupp.c - list.c gui.c diff --git a/reactos/boot/freeldr/freeldr/include/cache.h b/reactos/boot/freeldr/freeldr/include/cache.h index 7c5db270dc6..605e5c37207 100644 --- a/reactos/boot/freeldr/freeldr/include/cache.h +++ b/reactos/boot/freeldr/freeldr/include/cache.h @@ -32,7 +32,7 @@ /////////////////////////////////////////////////////////////////////////////////////// typedef struct { - LIST_ITEM ListEntry; // Doubly linked list synchronization member + LIST_ENTRY ListEntry; // Doubly linked list synchronization member ULONG BlockNumber; // Track index for CHS, 64k block index for LBA BOOLEAN LockedInCache; // Indicates that this block is locked in cache memory @@ -55,7 +55,7 @@ typedef struct ULONG BytesPerSector; ULONG BlockSize; // Block size (in sectors) - PCACHE_BLOCK CacheBlockHead; + LIST_ENTRY CacheBlockHead; // Contains CACHE_BLOCK structures } CACHE_DRIVE, *PCACHE_DRIVE; diff --git a/reactos/boot/freeldr/freeldr/include/inifile.h b/reactos/boot/freeldr/freeldr/include/inifile.h index d3a5bc7f2e7..aebf1f38ab1 100644 --- a/reactos/boot/freeldr/freeldr/include/inifile.h +++ b/reactos/boot/freeldr/freeldr/include/inifile.h @@ -29,7 +29,7 @@ // Name=Value typedef struct { - LIST_ITEM ListEntry; + LIST_ENTRY ListEntry; PCHAR ItemName; PCHAR ItemValue; @@ -42,14 +42,15 @@ typedef struct // one INI_SECTION_ITEM for each line in the section typedef struct { - LIST_ITEM ListEntry; + LIST_ENTRY ListEntry; PCHAR SectionName; ULONG SectionItemCount; - PINI_SECTION_ITEM SectionItemList; + LIST_ENTRY SectionItemList; // Contains PINI_SECTION_ITEM structures } INI_SECTION, *PINI_SECTION; -extern PINI_SECTION IniFileSectionListHead; +extern LIST_ENTRY IniFileSectionListHead; +extern BOOLEAN IniFileSectionInitialized; extern ULONG IniFileSectionCount; extern ULONG IniFileSettingCount; diff --git a/reactos/boot/freeldr/freeldr/include/rtl.h b/reactos/boot/freeldr/freeldr/include/rtl.h index 6567f0b0178..cab7c5f7290 100644 --- a/reactos/boot/freeldr/freeldr/include/rtl.h +++ b/reactos/boot/freeldr/freeldr/include/rtl.h @@ -29,34 +29,4 @@ void beep(void); void delay(unsigned msec); void sound(int freq); -/////////////////////////////////////////////////////////////////////////////////////// -// -// List Functions -// -/////////////////////////////////////////////////////////////////////////////////////// - -typedef struct _LIST_ITEM -{ - struct _LIST_ITEM* ListPrev; - struct _LIST_ITEM* ListNext; - -} LIST_ITEM, *PLIST_ITEM; - -VOID RtlListInitializeHead(PLIST_ITEM ListHead); // Initializes a doubly linked list -VOID RtlListInsertHead(PLIST_ITEM ListHead, PLIST_ITEM Entry); // Inserts an entry at the head of the list -VOID RtlListInsertTail(PLIST_ITEM ListHead, PLIST_ITEM Entry); // Inserts an entry at the tail of the list -PLIST_ITEM RtlListRemoveHead(PLIST_ITEM ListHead); // Removes the entry at the head of the list -PLIST_ITEM RtlListRemoveTail(PLIST_ITEM ListHead); // Removes the entry at the tail of the list -PLIST_ITEM RtlListGetHead(PLIST_ITEM ListHead); // Returns the entry at the head of the list -PLIST_ITEM RtlListGetTail(PLIST_ITEM ListHead); // Returns the entry at the tail of the list -BOOLEAN RtlListIsEmpty(PLIST_ITEM ListHead); // Indicates whether a doubly linked list is empty -ULONG RtlListCountEntries(PLIST_ITEM ListHead); // Counts the entries in a doubly linked list -PLIST_ITEM RtlListGetPrevious(PLIST_ITEM ListEntry); // Returns the previous item in the list -PLIST_ITEM RtlListGetNext(PLIST_ITEM ListEntry); // Returns the next item in the list -PLIST_ITEM RtlListRemoveEntry(PLIST_ITEM ListEntry); // Removes the entry from the list -VOID RtlListInsertEntry(PLIST_ITEM InsertAfter, PLIST_ITEM ListEntry); // Inserts a new list entry right after the specified one -VOID RtlListMoveEntryPrevious(PLIST_ITEM ListEntry); // Moves the list entry to before the previous entry -VOID RtlListMoveEntryNext(PLIST_ITEM ListEntry); // Moves the list entry to after the next entry - - #endif // defined __STDLIB_H diff --git a/reactos/boot/freeldr/freeldr/inifile/ini_init.c b/reactos/boot/freeldr/freeldr/inifile/ini_init.c index 9af92cdadc7..2eaa1d3a1e8 100644 --- a/reactos/boot/freeldr/freeldr/inifile/ini_init.c +++ b/reactos/boot/freeldr/freeldr/inifile/ini_init.c @@ -31,8 +31,7 @@ BOOLEAN IniFileInitialize(VOID) if (Freeldr_Ini == NULL) { - printf("Error opening freeldr.ini or file not found.\n"); - printf("You need to re-install FreeLoader.\n"); + UiMessageBoxCritical("Error opening freeldr.ini or file not found.\nYou need to re-install FreeLoader."); return FALSE; } @@ -43,7 +42,7 @@ BOOLEAN IniFileInitialize(VOID) // If we are out of memory then return FALSE if (FreeLoaderIniFileData == NULL) { - printf("Out of memory while loading freeldr.ini.\n"); + UiMessageBoxCritical("Out of memory while loading freeldr.ini."); FsCloseFile(Freeldr_Ini); return FALSE; } diff --git a/reactos/boot/freeldr/freeldr/inifile/inifile.c b/reactos/boot/freeldr/freeldr/inifile/inifile.c index 71ad20680fb..2241caf1ba2 100644 --- a/reactos/boot/freeldr/freeldr/inifile/inifile.c +++ b/reactos/boot/freeldr/freeldr/inifile/inifile.c @@ -26,12 +26,12 @@ BOOLEAN IniOpenSection(PCSTR SectionName, ULONG* SectionId) DbgPrint((DPRINT_INIFILE, "IniOpenSection() SectionName = %s\n", SectionName)); - if (!IniFileSectionListHead) + if (!IniFileSectionInitialized) return FALSE; // Loop through each section and find the one they want - Section = (PINI_SECTION)RtlListGetHead((PLIST_ITEM)IniFileSectionListHead); - while (Section != NULL) + Section = CONTAINING_RECORD(IniFileSectionListHead.Flink, INI_SECTION, ListEntry); + while (&Section->ListEntry != &IniFileSectionListHead) { // Compare against the section name if (_stricmp(SectionName, Section->SectionName) == 0) @@ -43,7 +43,7 @@ BOOLEAN IniOpenSection(PCSTR SectionName, ULONG* SectionId) } // Get the next section in the list - Section = (PINI_SECTION)RtlListGetNext((PLIST_ITEM)Section); + Section = CONTAINING_RECORD(Section->ListEntry.Flink, INI_SECTION, ListEntry); } DbgPrint((DPRINT_INIFILE, "IniOpenSection() Section not found.\n")); @@ -61,68 +61,87 @@ ULONG IniGetNumSectionItems(ULONG SectionId) return Section->SectionItemCount; } -ULONG IniGetSectionSettingNameSize(ULONG SectionId, ULONG SettingIndex) -{ - PINI_SECTION Section = (PINI_SECTION)SectionId; - - // Return the size of the string plus 1 for the null-terminator - return (strlen(Section->SectionItemList[SettingIndex].ItemName) + 1); -} - -ULONG IniGetSectionSettingValueSize(ULONG SectionId, ULONG SettingIndex) -{ - PINI_SECTION Section = (PINI_SECTION)SectionId; - - // Return the size of the string plus 1 for the null-terminator - return (strlen(Section->SectionItemList[SettingIndex].ItemValue) + 1); -} - -BOOLEAN IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize) +PINI_SECTION_ITEM IniGetSettingByNumber(ULONG SectionId, ULONG SettingNumber) { PINI_SECTION Section = (PINI_SECTION)SectionId; PINI_SECTION_ITEM SectionItem; - ULONG RealSettingNumber = SettingNumber; - DbgPrint((DPRINT_INIFILE, ".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); - - DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId)); // Loop through each section item and find the one they want - DbgPrint((DPRINT_INIFILE, ".01 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); - SectionItem = (PINI_SECTION_ITEM)RtlListGetHead((PLIST_ITEM)Section->SectionItemList); - while (SectionItem != NULL) + SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry); + while (&SectionItem->ListEntry != &Section->SectionItemList) { - DbgPrint((DPRINT_INIFILE, ".1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); // Check to see if this is the setting they want if (SettingNumber == 0) { - DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d found.\n", RealSettingNumber)); - DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName)); - DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue)); - - DbgPrint((DPRINT_INIFILE, "1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); - DbgPrint((DPRINT_INIFILE, "2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); - strncpy(SettingName, SectionItem->ItemName, NameSize - 1); - SettingName[NameSize - 1] = '\0'; - DbgPrint((DPRINT_INIFILE, "3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); - strncpy(SettingValue, SectionItem->ItemValue, ValueSize - 1); - SettingValue[ValueSize - 1] = '\0'; - DbgPrint((DPRINT_INIFILE, "4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); - DbgDumpBuffer(DPRINT_INIFILE, SettingName, NameSize); - DbgDumpBuffer(DPRINT_INIFILE, SettingValue, ValueSize); - - return TRUE; + return SectionItem; } // Nope, keep going SettingNumber--; // Get the next section item in the list - SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem); + SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry); + } + return NULL; +} + +ULONG IniGetSectionSettingNameSize(ULONG SectionId, ULONG SettingIndex) +{ + PINI_SECTION_ITEM SectionItem; + + // Retrieve requested setting + SectionItem = IniGetSettingByNumber(SectionId, SettingIndex); + if (!SectionItem) + return 0; + + // Return the size of the string plus 1 for the null-terminator + return (strlen(SectionItem->ItemName) + 1); +} + +ULONG IniGetSectionSettingValueSize(ULONG SectionId, ULONG SettingIndex) +{ + PINI_SECTION_ITEM SectionItem; + + // Retrieve requested setting + SectionItem = IniGetSettingByNumber(SectionId, SettingIndex); + if (!SectionItem) + return 0; + + // Return the size of the string plus 1 for the null-terminator + return (strlen(SectionItem->ItemValue) + 1); +} + +BOOLEAN IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize) +{ + PINI_SECTION_ITEM SectionItem; + DbgPrint((DPRINT_INIFILE, ".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); + + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId)); + + // Retrieve requested setting + SectionItem = IniGetSettingByNumber(SectionId, SettingNumber); + if (!SectionItem) + { + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d not found.\n", SettingNumber)); + return FALSE; } - DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d not found.\n", RealSettingNumber)); + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d found.\n", SettingNumber)); + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName)); + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue)); - return FALSE; + DbgPrint((DPRINT_INIFILE, "1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); + DbgPrint((DPRINT_INIFILE, "2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); + strncpy(SettingName, SectionItem->ItemName, NameSize - 1); + SettingName[NameSize - 1] = '\0'; + DbgPrint((DPRINT_INIFILE, "3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); + strncpy(SettingValue, SectionItem->ItemValue, ValueSize - 1); + SettingValue[ValueSize - 1] = '\0'; + DbgPrint((DPRINT_INIFILE, "4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize)); + DbgDumpBuffer(DPRINT_INIFILE, SettingName, NameSize); + DbgDumpBuffer(DPRINT_INIFILE, SettingValue, ValueSize); + + return TRUE; } BOOLEAN IniReadSettingByName(ULONG SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize) @@ -133,8 +152,8 @@ BOOLEAN IniReadSettingByName(ULONG SectionId, PCSTR SettingName, PCHAR Buffer, U DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() SectionId = 0x%x\n", SectionId)); // Loop through each section item and find the one they want - SectionItem = (PINI_SECTION_ITEM)RtlListGetHead((PLIST_ITEM)Section->SectionItemList); - while (SectionItem != NULL) + SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry); + while (&SectionItem->ListEntry != &Section->SectionItemList) { // Check to see if this is the setting they want if (_stricmp(SettingName, SectionItem->ItemName) == 0) @@ -149,7 +168,7 @@ BOOLEAN IniReadSettingByName(ULONG SectionId, PCSTR SettingName, PCHAR Buffer, U } // Get the next section item in the list - SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem); + SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry); } DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' not found.\n", SettingName)); @@ -183,14 +202,7 @@ BOOLEAN IniAddSection(PCSTR SectionName, ULONG* SectionId) // Add it to the section list head IniFileSectionCount++; - if (IniFileSectionListHead == NULL) - { - IniFileSectionListHead = Section; - } - else - { - RtlListInsertTail((PLIST_ITEM)IniFileSectionListHead, (PLIST_ITEM)Section); - } + InsertHeadList(&IniFileSectionListHead, &Section->ListEntry); *SectionId = (ULONG)Section; @@ -233,14 +245,7 @@ BOOLEAN IniAddSettingValueToSection(ULONG SectionId, PCSTR SettingName, PCSTR Se // Add it to the current section Section->SectionItemCount++; - if (Section->SectionItemList == NULL) - { - Section->SectionItemList = SectionItem; - } - else - { - RtlListInsertTail((PLIST_ITEM)Section->SectionItemList, (PLIST_ITEM)SectionItem); - } + InsertTailList(&Section->SectionItemList, &SectionItem->ListEntry); return TRUE; } diff --git a/reactos/boot/freeldr/freeldr/inifile/parse.c b/reactos/boot/freeldr/freeldr/inifile/parse.c index 1427957f29a..83fd93d8546 100644 --- a/reactos/boot/freeldr/freeldr/inifile/parse.c +++ b/reactos/boot/freeldr/freeldr/inifile/parse.c @@ -20,7 +20,8 @@ #include #include -PINI_SECTION IniFileSectionListHead = NULL; +LIST_ENTRY IniFileSectionListHead; +BOOLEAN IniFileSectionInitialized = FALSE; ULONG IniFileSectionCount = 0; ULONG IniFileSettingCount = 0; @@ -37,6 +38,12 @@ BOOLEAN IniParseFile(PCHAR IniFileData, ULONG IniFileSize) DbgPrint((DPRINT_INIFILE, "IniParseFile() IniFileSize: %d\n", IniFileSize)); + if (!IniFileSectionInitialized) + { + InitializeListHead(&IniFileSectionListHead); + IniFileSectionInitialized = TRUE; + } + // Start with an 80-byte buffer IniFileLineSize = 80; IniFileLine = MmAllocateMemory(IniFileLineSize); @@ -97,17 +104,11 @@ BOOLEAN IniParseFile(PCHAR IniFileData, ULONG IniFileSize) // Get the section name IniExtractSectionName(CurrentSection->SectionName, IniFileLine, LineLength); + InitializeListHead(&CurrentSection->SectionItemList); // Add it to the section list head IniFileSectionCount++; - if (IniFileSectionListHead == NULL) - { - IniFileSectionListHead = CurrentSection; - } - else - { - RtlListInsertTail((PLIST_ITEM)IniFileSectionListHead, (PLIST_ITEM)CurrentSection); - } + InsertTailList(&IniFileSectionListHead, &CurrentSection->ListEntry); CurrentLineNumber++; continue; @@ -162,14 +163,7 @@ BOOLEAN IniParseFile(PCHAR IniFileData, ULONG IniFileSize) // Add it to the current section IniFileSettingCount++; CurrentSection->SectionItemCount++; - if (CurrentSection->SectionItemList == NULL) - { - CurrentSection->SectionItemList = CurrentItem; - } - else - { - RtlListInsertTail((PLIST_ITEM)CurrentSection->SectionItemList, (PLIST_ITEM)CurrentItem); - } + InsertTailList(&CurrentSection->SectionItemList, &CurrentItem->ListEntry); CurrentLineNumber++; continue; diff --git a/reactos/boot/freeldr/freeldr/rtl/list.c b/reactos/boot/freeldr/freeldr/rtl/list.c deleted file mode 100644 index d6b2db84968..00000000000 --- a/reactos/boot/freeldr/freeldr/rtl/list.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2003 Brian Palmer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include - -VOID RtlListInitializeHead(PLIST_ITEM ListHead) -{ - ListHead->ListPrev = NULL; - ListHead->ListNext = NULL; -} - -VOID RtlListInsertHead(PLIST_ITEM ListHead, PLIST_ITEM Entry) -{ - ListHead = RtlListGetHead(ListHead); - ListHead->ListPrev = Entry; - Entry->ListNext = ListHead; - Entry->ListPrev = NULL; -} - -VOID RtlListInsertTail(PLIST_ITEM ListHead, PLIST_ITEM Entry) -{ - ListHead = RtlListGetTail(ListHead); - ListHead->ListNext = Entry; - Entry->ListNext = NULL; - Entry->ListPrev = ListHead; -} - -PLIST_ITEM RtlListRemoveHead(PLIST_ITEM ListHead) -{ - PLIST_ITEM OldListHead = RtlListGetHead(ListHead); - - ListHead = ListHead->ListNext; - ListHead->ListPrev = NULL; - - return OldListHead; -} - -PLIST_ITEM RtlListRemoveTail(PLIST_ITEM ListHead) -{ - PLIST_ITEM ListTail; - - ListTail = RtlListGetTail(ListHead); - ListHead = ListTail->ListPrev; - ListHead->ListNext = NULL; - - return ListTail; -} - -PLIST_ITEM RtlListGetHead(PLIST_ITEM ListHead) -{ - while (ListHead->ListPrev != NULL) - { - ListHead = ListHead->ListPrev; - } - - return ListHead; -} - -PLIST_ITEM RtlListGetTail(PLIST_ITEM ListHead) -{ - while (ListHead->ListNext != NULL) - { - ListHead = ListHead->ListNext; - } - - return ListHead; -} - -BOOLEAN RtlListIsEmpty(PLIST_ITEM ListHead) -{ - if (ListHead == NULL) - { - return TRUE; - } - - return (ListHead->ListNext == NULL); -} - -ULONG RtlListCountEntries(PLIST_ITEM ListHead) -{ - ULONG Count = 0; - - while (ListHead != NULL) - { - Count++; - ListHead = ListHead->ListNext; - } - - return Count; -} - -PLIST_ITEM RtlListGetPrevious(PLIST_ITEM ListEntry) -{ - return ListEntry->ListPrev; -} - -PLIST_ITEM RtlListGetNext(PLIST_ITEM ListEntry) -{ - return ListEntry->ListNext; -} - -PLIST_ITEM RtlListRemoveEntry(PLIST_ITEM ListEntry) -{ - PLIST_ITEM ListNext = RtlListGetNext(ListEntry); - PLIST_ITEM ListPrev = RtlListGetPrevious(ListEntry); - - if (ListPrev != NULL) - { - ListPrev->ListNext = ListNext; - } - - if (ListNext != NULL) - { - ListNext->ListPrev = ListPrev; - } - - return ListNext; -} - -VOID RtlListInsertEntry(PLIST_ITEM InsertAfter, PLIST_ITEM ListEntry) -{ - PLIST_ITEM ListNext = RtlListGetNext(InsertAfter); - - InsertAfter->ListNext = ListEntry; - ListEntry->ListPrev = InsertAfter; - ListEntry->ListNext = ListNext; -} - -VOID RtlListMoveEntryPrevious(PLIST_ITEM ListEntry) -{ - PLIST_ITEM ListPrev = RtlListGetPrevious(ListEntry); - - if (ListPrev == NULL) - { - return; - } - - // - // Move the previous entry after this one - // - RtlListRemoveEntry(ListPrev); - RtlListInsertEntry(ListEntry, ListPrev); -} - -VOID RtlListMoveEntryNext(PLIST_ITEM ListEntry) -{ - PLIST_ITEM ListNext = RtlListGetNext(ListEntry); - - if (ListNext == NULL) - { - return; - } - - // - // Move this entry after the next entry - // - RtlListRemoveEntry(ListEntry); - RtlListInsertEntry(ListNext, ListEntry); -} -