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
September 2015
----- 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
17 participants
535 discussions
Start a n
N
ew thread
[hbelusca] 69070: [CDMAKE] - Factor out the code that writes data from a file. - Use BOOL type where needed.
by hbelusca@svn.reactos.org
Author: hbelusca Date: Sun Sep 6 20:42:08 2015 New Revision: 69070 URL:
http://svn.reactos.org/svn/reactos?rev=69070&view=rev
Log: [CDMAKE] - Factor out the code that writes data from a file. - Use BOOL type where needed. Modified: trunk/reactos/tools/cdmake/cdmake.c Modified: trunk/reactos/tools/cdmake/cdmake.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/cdmake.c?rev=…
============================================================================== --- trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] (original) +++ trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] Sun Sep 6 20:42:08 2015 @@ -166,11 +166,11 @@ DWORD number_of_directories; DWORD bytes_in_directories; -char bootimage[512]; BOOL eltorito; DWORD boot_catalog_sector; DWORD boot_image_sector; WORD boot_image_size; // counted in 512 byte sectors +char bootimage[512]; BOOL joliet; DWORD joliet_path_table_size; @@ -575,7 +575,7 @@ #define strcasecmp stricmp #endif//_WIN32 -int cdname_exists(PDIR_RECORD d) +BOOL cdname_exists(PDIR_RECORD d) { PDIR_RECORD p = d->parent->first_record; while (p) @@ -583,10 +583,10 @@ if ( p != d && !strcasecmp(p->name_on_cd, d->name_on_cd) && !strcasecmp(p->extension_on_cd, d->extension_on_cd) ) - return 1; + return TRUE; p = p->next_in_directory; } - return 0; + return FALSE; } void parse_filename_into_dirrecord(const char* filename, PDIR_RECORD d, BOOL dir) @@ -809,7 +809,7 @@ d->first_record = NULL; strcpy(end_source, "*.*"); - findhandle =_findfirst(source, &f); + findhandle = _findfirst(source, &f); if (findhandle != 0) { do @@ -839,7 +839,7 @@ } strcpy(end_source, "*.*"); - findhandle= _findfirst(source, &f); + findhandle = _findfirst(source, &f); if (findhandle) { do @@ -1121,14 +1121,14 @@ } #if _WIN32 -static int +static BOOL get_cd_file_time(HANDLE handle, PDATE_AND_TIME cd_time_info) { FILETIME file_time; SYSTEMTIME sys_time; if (!GetFileTime(handle, NULL, NULL, &file_time)) - return -1; + return FALSE; FileTimeToSystemTime(&file_time, &sys_time); memset(cd_time_info, 0, sizeof(*cd_time_info)); @@ -1140,7 +1140,7 @@ cd_time_info->minute = sys_time.wMinute; cd_time_info->second = sys_time.wSecond; - return 0; + return TRUE; } #endif @@ -1175,7 +1175,7 @@ error_exit("Can't open timestamp file %s\n", file->source_name); } - if (get_cd_file_time(open_file, &d->date_and_time) == -1) + if (!get_cd_file_time(open_file, &d->date_and_time)) { error_exit("Can't stat timestamp file %s\n", file->source_name); } @@ -1210,7 +1210,7 @@ { error_exit("Can't open file %s\n", file->source_name); } - if (get_cd_file_time(open_file, &new_d->date_and_time) == -1) + if (!get_cd_file_time(open_file, &new_d->date_and_time)) { error_exit("Can't stat file %s\n", file->source_name); } @@ -1294,6 +1294,31 @@ root.date_and_time.second); } +static BOOL write_from_file(FILE *file, DWORD size) +{ + int n; + + fseek(file, 0, SEEK_SET); + while (size > 0) + { + n = BUFFER_SIZE - cd.count; + if ((DWORD)n > size) + n = size; + + if (fread(cd.buffer + cd.count, n, 1, file) < 1) + return FALSE; + + cd.count += n; + if (cd.count == BUFFER_SIZE) + flush_buffer(); + cd.sector += n / SECTOR_SIZE; + cd.offset += n % SECTOR_SIZE; + size -= n; + } + + return TRUE; +} + static void pass(void) { PDIR_RECORD d; @@ -1303,15 +1328,14 @@ DWORD size; DWORD number_of_sectors; char *old_end_source; - int n; FILE *file; char timestring[17]; get_time_string(timestring); // first 16 sectors are zeros - write_block(16 * SECTOR_SIZE, 0); + // Primary Volume Descriptor @@ -1356,7 +1380,6 @@ // Boot Volume Descriptor - if (eltorito) { write_byte(0); @@ -1369,7 +1392,6 @@ } // Supplementary Volume Descriptor - if (joliet) { write_string("\2CD001\1"); @@ -1413,7 +1435,6 @@ fill_sector(); } - // Volume Descriptor Set Terminator write_string("\377CD001\1"); fill_sector(); @@ -1429,7 +1450,7 @@ write_little_endian_word(0); // reserved write_string("ReactOS Foundation"); write_block(6, 0); // padding - write_little_endian_word(0x62E); // checksum + write_little_endian_word(0x62E); // checksum // FIXME: This is hardcoded!! write_little_endian_word(0xAA55); // signature // default entry @@ -1454,29 +1475,16 @@ error_exit("Can't open %s\n", bootimage); fseek(file, 0, SEEK_END); size = ftell(file); - fseek(file, 0, SEEK_SET); if (size == 0 || (size % 2048)) { fclose(file); error_exit("Invalid boot image size (%lu bytes)\n", size); } boot_image_size = size / 512; - while (size > 0) - { - n = BUFFER_SIZE - cd.count; - if ((DWORD) n > size) - n = size; - if (fread(cd.buffer + cd.count, n, 1, file) < 1) - { - fclose(file); - error_exit("Read error in file %s\n", bootimage); - } - cd.count += n; - if (cd.count == BUFFER_SIZE) - flush_buffer(); - cd.sector += n / SECTOR_SIZE; - cd.offset += n % SECTOR_SIZE; - size -= n; + if (!write_from_file(file, size)) + { + fclose(file); + error_exit("Read error in file %s\n", bootimage); } fclose(file); // fill_sector(); @@ -1581,7 +1589,7 @@ fill_sector(); } - // directories and files + // Directories and files for (d = &root; d != NULL; d = d->next_in_path_table) { // write directory @@ -1652,23 +1660,10 @@ file = fopen(file_source, "rb"); if (file == NULL) error_exit("Can't open %s\n", file_source); - fseek(file, 0, SEEK_SET); - while (size > 0) + if (!write_from_file(file, size)) { - n = BUFFER_SIZE - cd.count; - if ((DWORD) n > size) - n = size; - if (fread(cd.buffer + cd.count, n, 1, file) < 1) - { - fclose(file); - error_exit("Read error in file %s\n", file_source); - } - cd.count += n; - if (cd.count == BUFFER_SIZE) - flush_buffer(); - cd.sector += n / SECTOR_SIZE; - cd.offset += n % SECTOR_SIZE; - size -= n; + fclose(file); + error_exit("Read error in file %s\n", file_source); } fclose(file); end_source = old_end_source;
9 years, 3 months
1
0
0
0
[akhaldi] 69069: [SERVMAN] Introduce the ability to sort the services list-view by any column in ascending and descending order. Brought to you by Joachim Henze. CORE-10122
by akhaldi@svn.reactos.org
Author: akhaldi Date: Sun Sep 6 20:19:58 2015 New Revision: 69069 URL:
http://svn.reactos.org/svn/reactos?rev=69069&view=rev
Log: [SERVMAN] Introduce the ability to sort the services list-view by any column in ascending and descending order. Brought to you by Joachim Henze. CORE-10122 Modified: trunk/reactos/base/applications/mscutils/servman/mainwnd.c Modified: trunk/reactos/base/applications/mscutils/servman/mainwnd.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
============================================================================== --- trunk/reactos/base/applications/mscutils/servman/mainwnd.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mscutils/servman/mainwnd.c [iso-8859-1] Sun Sep 6 20:19:58 2015 @@ -15,6 +15,8 @@ BOOL bSortAscending = TRUE; +/* Temporary copy for access from list-view sort CompareFunc */ +HWND hListView; /* Toolbar buttons */ static const TBBUTTON Buttons [] = @@ -23,7 +25,7 @@ {TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */ {TBICON_EXPORT, ID_EXPORT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* export */ - /* Note: First item for a seperator is its width in pixels */ + /* Note: First item for a separator is its width in pixels */ {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */ {TBICON_CREATE, ID_CREATE, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* create */ @@ -244,20 +246,21 @@ static INT CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { - ENUM_SERVICE_STATUS_PROCESS *Param1; - ENUM_SERVICE_STATUS_PROCESS *Param2; -// INT iSubItem = (LPARAM)lParamSort; - - if (bSortAscending) { - Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1; - Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2; - } - else - { - Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2; - Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1; - } - return _wcsicmp(Param1->lpDisplayName, Param2->lpDisplayName); + WCHAR Item1[256], Item2[256]; + LVFINDINFO IndexInfo; + INT Index; + + IndexInfo.flags = LVFI_PARAM; + + IndexInfo.lParam = lParam1; + Index = ListView_FindItem(hListView, -1, &IndexInfo); + ListView_GetItemText(hListView, Index, (INT)lParamSort, Item1, sizeof(Item1) / sizeof(WCHAR)); + + IndexInfo.lParam = lParam2; + Index = ListView_FindItem(hListView, -1, &IndexInfo); + ListView_GetItemText(hListView, Index, (INT)lParamSort, Item2, sizeof(Item2) / sizeof(WCHAR)); + + return bSortAscending ? wcscmp(Item1, Item2) : wcscmp(Item2, Item1); } @@ -732,15 +735,25 @@ case LVN_COLUMNCLICK: { + static int iLastSortColumn = 0; LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; + /* get new sort parameters */ + if (pnmv->iSubItem == iLastSortColumn) + bSortAscending = !bSortAscending; + else + { + iLastSortColumn = pnmv->iSubItem; + bSortAscending = TRUE; + } + + /* store a copy to have access from callback */ + hListView = Info->hListView; (void)ListView_SortItems(Info->hListView, CompareFunc, pnmv->iSubItem); - bSortAscending = !bSortAscending; } break; - case LVN_ITEMCHANGED: { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
9 years, 3 months
1
0
0
0
[ion] 69068: [BOOTMGFW]: - Add heap implementation, continuing from my work last year. Seems to be pretty broken, next steps are fixing it. - Implement block allocator initialization (needs heap). ...
by ion@svn.reactos.org
Author: ion Date: Sun Sep 6 19:56:47 2015 New Revision: 69068 URL:
http://svn.reactos.org/svn/reactos?rev=69068&view=rev
Log: [BOOTMGFW]: - Add heap implementation, continuing from my work last year. Seems to be pretty broken, next steps are fixing it. - Implement block allocator initialization (needs heap). - Implement a few other missing initialization paths. Modified: trunk/reactos/boot/environ/include/bl.h trunk/reactos/boot/environ/lib/mm/blkalloc.c trunk/reactos/boot/environ/lib/mm/heapalloc.c trunk/reactos/boot/environ/lib/mm/i386/mmx86.c trunk/reactos/boot/environ/lib/mm/mm.c Modified: trunk/reactos/boot/environ/include/bl.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
============================================================================== --- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original) +++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Sep 6 19:56:47 2015 @@ -75,6 +75,7 @@ #define BL_LIBRARY_FLAG_REINITIALIZE 0x02 #define BL_LIBRARY_FLAG_REINITIALIZE_ALL 0x04 +#define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE 0x10 #define BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED 0x20 #define BL_MEMORY_CLASS_SHIFT 28 @@ -481,43 +482,6 @@ _In_ PBL_LIBRARY_PARAMETERS LibraryParameters ); -/* FIRMWARE ROUTINES *********************************************************/ - -NTSTATUS -EfiAllocatePages ( - _In_ ULONG Type, - _In_ ULONG Pages, - _Inout_ EFI_PHYSICAL_ADDRESS* Memory - ); - -/* UTILITY ROUTINES **********************************************************/ - -EFI_STATUS -EfiGetEfiStatusCode( - _In_ NTSTATUS Status - ); - -NTSTATUS -EfiGetNtStatusCode ( - _In_ EFI_STATUS EfiStatus - ); - -/* BCD ROUTINES **************************************************************/ - -ULONG -BlGetBootOptionSize ( - _In_ PBL_BCD_OPTION BcdOption - ); - -/* CONTEXT ROUTINES **********************************************************/ - -VOID -BlpArchSwitchContext ( - _In_ BL_ARCH_MODE NewMode - ); - -/* MEMORY MANAGER ROUTINES ***************************************************/ - NTSTATUS MmBaInitialize ( VOID @@ -549,11 +513,42 @@ _In_ PBL_LIBRARY_PARAMETERS LibraryParameters ); -NTSTATUS -MmFwGetMemoryMap ( - _Out_ PBL_MEMORY_DESCRIPTOR_LIST MemoryMap, - _In_ ULONG Flags - ); +/* FIRMWARE ROUTINES *********************************************************/ + +NTSTATUS +EfiAllocatePages ( + _In_ ULONG Type, + _In_ ULONG Pages, + _Inout_ EFI_PHYSICAL_ADDRESS* Memory + ); + +/* UTILITY ROUTINES **********************************************************/ + +EFI_STATUS +EfiGetEfiStatusCode( + _In_ NTSTATUS Status + ); + +NTSTATUS +EfiGetNtStatusCode ( + _In_ EFI_STATUS EfiStatus + ); + +/* BCD ROUTINES **************************************************************/ + +ULONG +BlGetBootOptionSize ( + _In_ PBL_BCD_OPTION BcdOption + ); + +/* CONTEXT ROUTINES **********************************************************/ + +VOID +BlpArchSwitchContext ( + _In_ BL_ARCH_MODE NewMode + ); + +/* MEMORY DESCRIPTOR ROUTINES ************************************************/ VOID MmMdFreeList( @@ -614,6 +609,8 @@ _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor ); +/* PAGE ALLOCATOR ROUTINES ***************************************************/ + NTSTATUS MmPapAllocatePagesInRange ( _Inout_ PULONG PhysicalAddress, @@ -625,6 +622,19 @@ _In_ ULONG Type ); +NTSTATUS +MmFwGetMemoryMap ( + _Out_ PBL_MEMORY_DESCRIPTOR_LIST MemoryMap, + _In_ ULONG Flags + ); + +/* HEAP ALLOCATOR ROUTINES ***************************************************/ + +PVOID +BlMmAllocateHeap ( + _In_ ULONG Size + ); + extern ULONG MmDescriptorCallTreeCount; extern ULONG BlpApplicationFlags; extern BL_LIBRARY_PARAMETERS BlpLibraryParameters; Modified: trunk/reactos/boot/environ/lib/mm/blkalloc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/blkall…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/blkalloc.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/blkalloc.c [iso-8859-1] Sun Sep 6 19:56:47 2015 @@ -12,6 +12,15 @@ /* DATA VARIABLES ************************************************************/ +PVOID MmBlockAllocatorTable; +ULONG MmBlockAllocatorTableEntries; +BOOLEAN MmBlockAllocatorInitialized; + +typedef struct _BL_BLOCK_DESCRIPTOR +{ + LIST_ENTRY NextEntry; + UCHAR Unknown[50 - sizeof(LIST_ENTRY)]; +} BL_BLOCK_DESCRIPTOR, *PBL_BLOCK_DESCRIPTOR; /* FUNCTIONS *****************************************************************/ @@ -20,5 +29,27 @@ VOID ) { - return STATUS_NOT_IMPLEMENTED; + NTSTATUS Status; + ULONG Size; + + /* Allocate 8 table entries */ + MmBlockAllocatorTableEntries = 8; + Size = sizeof(BL_BLOCK_DESCRIPTOR) * MmBlockAllocatorTableEntries; + MmBlockAllocatorTable = BlMmAllocateHeap(Size); + if (MmBlockAllocatorTable) + { + /* Zero them out -- we're all done */ + Status = STATUS_SUCCESS; + RtlZeroMemory(MmBlockAllocatorTable, Size); + MmBlockAllocatorInitialized = 1; + } + else + { + /* Bail out since we're out of memory */ + Status = STATUS_NO_MEMORY; + MmBlockAllocatorInitialized = 0; + } + + /* Return initialization status */ + return Status; } Modified: trunk/reactos/boot/environ/lib/mm/heapalloc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/heapal…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/heapalloc.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/heapalloc.c [iso-8859-1] Sun Sep 6 19:56:47 2015 @@ -59,6 +59,30 @@ ULONG HapAllocationAttributes; PBL_FREE_HEAP_ENTRY* MmFreeList; +/* INLINES *******************************************************************/ + +FORCEINLINE +PBL_FREE_HEAP_ENTRY +MmHapDecodeLink ( + _In_ BL_HEAP_POINTER Link + ) +{ + /* Decode the buffer pointer by ignoring the flags */ + return (PBL_FREE_HEAP_ENTRY)(Link.BufferPointer << BL_HEAP_POINTER_FLAG_BITS); +} + +FORCEINLINE +ULONG +MmHapBufferSize ( + _In_ PVOID FreeEntry + ) +{ + PBL_FREE_HEAP_ENTRY Entry = FreeEntry; + + /* The space between the next buffer header and this one is the size */ + return (ULONG_PTR)MmHapDecodeLink(Entry->BufferNext) - (ULONG_PTR)Entry; +} + /* FUNCTIONS *****************************************************************/ NTSTATUS @@ -103,7 +127,7 @@ HeapLimit = Heap->HeapLimit + PAGE_SIZE; if (HeapLimit <= Heap->HeapHigh) { - EarlyPrint(L"TODO\n"); + EarlyPrint(L"Heap extension TODO\n"); return STATUS_INSUFFICIENT_RESOURCES; } } @@ -156,6 +180,339 @@ return STATUS_SUCCESS; } +ULONG +MmHapGetBucketId ( + _In_ ULONG Size + ) +{ + ULONG BucketIndex = 0; + + /* Use the last bucket if this is a large allocation */ + if (Size >= PAGE_SIZE) return 7; + + /* Otherwise, use a higher index for each new power of two */ + while (Size >> BucketIndex) + { + BucketIndex++; + } + + /* Allocations are at least 8 bytes (2^3 = 4th index) */ + return BucketIndex - 5; +} + +VOID +MmHapReportHeapCorruption ( + _In_ PBL_FREE_HEAP_ENTRY BufferEntry + ) +{ +#if 0 + BOOLEAN DebuggerEnabled; + + BlStatusPrint(L"Heap corruption in the links surrounding %p!\n", BufferEntry); + + DebuggerEnabled = BlBdDebuggerEnabled(); + if (DebuggerEnabled) + { + BlStatusPrint(L"\n*** Fatal Error 0x%08x :\n (0x%p, 0x%p, 0x%p, 0x%p)\n\n", 2, BufferEntry, NULL, NULL, NULL); + __debugbreak(); + } +#else + EarlyPrint(L"Heap corruption in the links surrounding %p!\n", BufferEntry); +#endif +} + +PVOID +MmHapCheckFreeLinks ( + _In_ PVOID BufferEntry + ) +{ + PBL_FREE_HEAP_ENTRY Prev, Next; + PBL_FREE_HEAP_ENTRY Entry = BufferEntry; + + /* Get the previous and next free pointers */ + Prev = MmHapDecodeLink(Entry->FreePrevious); + Next = MmHapDecodeLink(Entry->FreeNext); + + /* Make sure that both the previous and next entries point to this one */ + if (((Next) && (MmHapDecodeLink(Next->FreePrevious)) != Entry) || + ((Prev) && (MmHapDecodeLink(Prev->FreeNext)) != Entry)) + { + /* They don't, so the free headers are corrupted */ + MmHapReportHeapCorruption(Entry); + return NULL; + } + + /* They do, return the free entry as valid */ + return Entry; +} + +PVOID +MmHapCheckBufferLinks ( + _In_ PVOID BufferEntry + ) +{ + PBL_FREE_HEAP_ENTRY Prev, Next; + PBL_FREE_HEAP_ENTRY Entry = BufferEntry; + + /* Get the previous and next buffer pointers */ + Prev = MmHapDecodeLink(Entry->BufferPrevious); + Next = MmHapDecodeLink(Entry->BufferNext); + + /* Make sure that both the previous and next entries point to this one */ + if (((Next) && (MmHapDecodeLink(Next->BufferPrevious)) != Entry) || + ((Prev) && (MmHapDecodeLink(Prev->BufferNext)) != Entry)) + { + /* They don't, so the heap headers are corrupted */ + MmHapReportHeapCorruption(Entry); + return NULL; + } + + /* They, do the entry is valid */ + return Entry; +} + +PBL_FREE_HEAP_ENTRY +MmHapRemoveBufferFromFreeList ( + _In_ PBL_FREE_HEAP_ENTRY FreeEntry + ) +{ + PBL_FREE_HEAP_ENTRY Prev, Next; + + /* Firest, make sure the free entry is valid */ + FreeEntry = MmHapCheckFreeLinks(FreeEntry); + if (!FreeEntry) + { + return FreeEntry; + } + + /* Get the previous and next entry */ + Prev = MmHapDecodeLink(FreeEntry->FreePrevious); + Next = MmHapDecodeLink(FreeEntry->FreeNext); + + /* Update the next entry to point to our previous entry */ + if (Next) + { + Next->FreePrevious.P = Prev; + } + + /* Are we at the head? */ + if (Prev) + { + /* Nope, so update our previous entry to point to our next entry */ + Prev->FreeNext.P = Next; + } + else + { + /* Yep, so update the appropriate bucket listhead */ + MmFreeList[MmHapGetBucketId(MmHapBufferSize(FreeEntry))] = Prev; + } + + /* Return the (now removed) entry */ + return FreeEntry; +} + +PBL_FREE_HEAP_ENTRY +MmHapCoalesceFreeBuffer ( + _In_ PBL_FREE_HEAP_ENTRY FreeEntry + ) +{ + PBL_FREE_HEAP_ENTRY Prev, Next; + + /* First make sure that this is a valid buffer entry */ + if (!MmHapCheckBufferLinks(FreeEntry)) + { + return NULL; + } + + /* Get the next entry and check if it's free */ + Next = MmHapDecodeLink(FreeEntry->BufferNext); + if (!(Next->BufferNext.BufferOnHeap) && (Next->BufferNext.BufferFree)) + { + /* Remove the next buffer from the free list since we're coalescing */ + Next = MmHapRemoveBufferFromFreeList(Next); + if (!Next) + { + return NULL; + } + + /* The forward link of the *new* free buffer should now point to us */ + MmHapDecodeLink(Next->BufferNext)->BufferPrevious.P = FreeEntry; + + /* Our forward link should point to the *new* free buffer as well */ + FreeEntry->BufferNext.P = MmHapDecodeLink(Next->BufferNext); + + /* Mark our buffer as free */ + FreeEntry->BufferNext.BufferFree = 1; + } + + /* Get the previous entry and check if it's free */ + Prev = MmHapDecodeLink(FreeEntry->BufferPrevious); + if (!(Prev) || !(Prev->BufferNext.BufferFree)) return FreeEntry; + + /* It's free, so remove it */ + Prev = MmHapRemoveBufferFromFreeList(Prev); + if (!Prev) + { + return NULL; + } + + /* The previous link of our next buffer should now point to our *previous* */ + MmHapDecodeLink(FreeEntry->BufferNext)->BufferPrevious.P = Prev; + + /* Our previous link should point the next free buffer now */ + Prev->BufferNext.P = MmHapDecodeLink(FreeEntry->BufferNext); + + /* Set the new freed buffer as the previous buffer, and mark it free */ + FreeEntry = Prev; + FreeEntry->BufferNext.BufferFree = 1; + return FreeEntry; +} + +PBL_FREE_HEAP_ENTRY +MmHapAddToFreeList ( + _In_ PBL_BUSY_HEAP_ENTRY Entry, + _In_ ULONG Flags + ) +{ + PBL_FREE_HEAP_ENTRY FreeEntry, Head; + ULONG BucketId; + BL_LIBRARY_PARAMETERS LocalParameters; + + /* First, check if the entry is valid */ + Entry = MmHapCheckBufferLinks(Entry); + if (!Entry) + { + return NULL; + } + + /* Check if we should zero the entry */ + LocalParameters = BlpLibraryParameters; + if ((LocalParameters.LibraryFlags & BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE) && + !(Flags)) + { + /* Yep, zero it out */ + RtlZeroMemory(Entry->Buffer, MmHapBufferSize(Entry)); + } + + /* Now mark the entry as free */ + Entry->BufferNext.BufferFree = 1; + + /* Now that this buffer is free, try to coalesce it */ + FreeEntry = MmHapCoalesceFreeBuffer((PBL_FREE_HEAP_ENTRY)Entry); + if (!FreeEntry) + { + return FreeEntry; + } + + /* Compute the bucket ID for the free list */ + BucketId = MmHapGetBucketId(MmHapBufferSize(Entry)); + + /* Get the current head for this bucket, if one exists */ + Head = MmFreeList ? MmFreeList[BucketId] : NULL; + + /* Update the head's backlink to point to this newly freed entry */ + if (Head) + { + Head->FreePrevious.P = FreeEntry; + } + + /* Nobody behind us, the old head in front of us */ + FreeEntry->FreePrevious.P = NULL; + FreeEntry->FreeNext.P = Head; + + /* Put us at the head of list now, and return the entry */ + MmFreeList[BucketId] = FreeEntry; + return FreeEntry; +} + +PBL_BUSY_HEAP_ENTRY +MmHapFindBufferInFreeList ( + _In_ ULONG Size + ) +{ + PBL_FREE_HEAP_ENTRY FreeEntry = NULL; + PBL_BUSY_HEAP_ENTRY NextEntry; + ULONG BucketId; + + /* Get the appropriate bucket for our size */ + BucketId = MmHapGetBucketId(Size); + if (BucketId >= 8) + { + return NULL; + } + + /* Keep going as long as we don't have a free entry */ + while (!FreeEntry) + { + /* Fet the first free entry in this list */ + FreeEntry = MmFreeList ? MmFreeList[BucketId] : NULL; + + /* Loop as long as there's entries in the list */ + while (FreeEntry) + { + /* Can this free entry satisfy our needs? */ + if (MmHapBufferSize(FreeEntry) >= Size) + { + /* All good */ + break; + } + + /* It cannot, keep going to the next one */ + FreeEntry = MmHapDecodeLink(FreeEntry->FreeNext); + } + + /* Try the next list -- have we exhausted all the lists? */ + if (++BucketId >= 8) + { + /* Have we not found an entry yet? Fail if so... */ + if (!FreeEntry) + { + return NULL; + } + } + } + + /* We should have an entry if we're here. Remove it from the free list */ + NT_ASSERT(FreeEntry != NULL); + FreeEntry = MmHapRemoveBufferFromFreeList(FreeEntry); + if (!FreeEntry) + { + return NULL; + } + + /* Make sure it's not corrupted */ + FreeEntry = MmHapCheckBufferLinks(FreeEntry); + if (!FreeEntry) + { + return NULL; + } + + /* Do we have space for at least another buffer? */ + if ((MmHapBufferSize(FreeEntry) - Size) >= sizeof(BL_FREE_HEAP_ENTRY)) + { + /* Go to where the new next buffer will start */ + NextEntry = (PBL_BUSY_HEAP_ENTRY)((ULONG_PTR)FreeEntry + Size); + + /* Make the new next buffer point to the next buffer */ + NextEntry->BufferNext.P = MmHapDecodeLink(FreeEntry->BufferNext); + + /* Make the old next buffer point back to the new one */ + MmHapDecodeLink(FreeEntry->BufferNext)->BufferPrevious.P = NextEntry; + + /* Point the new next buffer point back to us */ + NextEntry->BufferPrevious.P = FreeEntry; + + /* Point us to the new next buffer */ + FreeEntry->BufferNext.P = NextEntry; + + /* And insert the new next buffer into the free list */ + MmHapAddToFreeList(NextEntry, 1); + } + + /* Return the entry, which is now allocated */ + return (PBL_BUSY_HEAP_ENTRY)FreeEntry; +} + NTSTATUS MmHaInitialize ( _In_ ULONG HeapSize, @@ -180,9 +537,156 @@ { /* The heap is ready! */ HapInitializationStatus = 1; + EarlyPrint(L"Heap Allocator Initialized!\n"); Status = STATUS_SUCCESS; } /* Return initialization status */ return Status; } + +PVOID +BlMmAllocateHeap ( + _In_ ULONG Size + ) +{ + ULONG BufferSize; + PBL_HEAP_BOUNDARIES Heap; + PBL_BUSY_HEAP_ENTRY BusyEntry, FreeEntry, NextEntry; + + /* Ignore heap allocation if the heap allocator isn't ready yet */ + if (HapInitializationStatus != 1) + { + return NULL; + } + + /* Align the buffer size to the minimum size required */ + BufferSize = ALIGN_UP(Size + sizeof(BL_BUSY_HEAP_ENTRY), + sizeof(BL_BUSY_HEAP_ENTRY)); + + /* Watch out for overflow */ + if (BufferSize <= Size) + { + return NULL; + } + + /* Make sure it's at least big enough to hold a free entry later on */ + if (BufferSize < sizeof(BL_FREE_HEAP_ENTRY)) + { + BufferSize = sizeof(BL_FREE_HEAP_ENTRY); + } + + /* Loop while we try to allocate memory */ + while (1) + { + /* Find a free buffer for this allocation */ + BusyEntry = MmHapFindBufferInFreeList(BufferSize); + if (BusyEntry) + { + break; + } + + /* We couldn't find a free buffer. Do we have any heaps? */ + if (!IsListEmpty(&MmHeapBoundaries)) + { + /* Get the current heap */ + Heap = CONTAINING_RECORD(MmHeapBoundaries.Flink, + BL_HEAP_BOUNDARIES, + ListEntry); + + /* Check if we have space in the heap page for this allocation? */ + FreeEntry = Heap->HeapTop; + NextEntry = (PBL_BUSY_HEAP_ENTRY)((ULONG_PTR)FreeEntry + BufferSize); + + EarlyPrint(L"Free Entry: %p Size: %lx Next: %p\n", FreeEntry, BufferSize, NextEntry); + + EarlyPrint(L"Heap Limit: %p\n", Heap->HeapLimit); + EarlyPrint(L"Minus one busy entry: %p\n", Heap->HeapLimit - sizeof(BL_BUSY_HEAP_ENTRY)); + + if ((NextEntry >= FreeEntry) && + ((ULONG_PTR)NextEntry <= Heap->HeapLimit - sizeof(BL_BUSY_HEAP_ENTRY))) + { + /* Update the heap top pointer past this allocation */ + Heap->HeapTop = NextEntry; + + /* Make this allocation point to the slot */ + FreeEntry->BufferNext.P = Heap->HeapTop; + + /* And make the free heap entry point back to us */ + Heap->HeapTop->BufferNext.P = FreeEntry; + + /* Mark the heap entry as being free and on the heap */ + Heap->HeapTop->BufferNext.BufferFree = 1; + Heap->HeapTop->BufferNext.BufferOnHeap = 1; + + /* The previously freed entry on the heap page is now ours */ + BusyEntry = FreeEntry; + break; + } + } + + /* We have no heaps or space on any heap -- extend the heap and retry */ + if (!NT_SUCCESS(MmHapHeapAllocatorExtend(BufferSize))) + { + EarlyPrint(L"Heap extension failed!\n"); + return NULL; + } + + EarlyPrint(L"Heap extended -- trying again\n"); + } + + /* Clear all the bits, marking this entry as allocated */ + BusyEntry->BufferNext.P = MmHapDecodeLink(BusyEntry->BufferNext); + + /* Return the entry's data buffer */ + return &BusyEntry->Buffer; +} + +NTSTATUS +BlMmFreeHeap ( + _In_ PVOID Buffer + ) +{ + PBL_BUSY_HEAP_ENTRY BusyEntry; + PBL_HEAP_BOUNDARIES Heap; + PLIST_ENTRY NextEntry; + + /* If the heap is not initialized, fail */ + if (HapInitializationStatus != 1) + { + return STATUS_UNSUCCESSFUL; + } + + /* Get the heap header */ + BusyEntry = CONTAINING_RECORD(Buffer, BL_BUSY_HEAP_ENTRY, Buffer); + + /* Loop all the heaps */ + NextEntry = MmHeapBoundaries.Flink; + while (NextEntry != &MmHeapBoundaries) + { + /* Get the current heap in the list */ + Heap = CONTAINING_RECORD(NextEntry, BL_HEAP_BOUNDARIES, ListEntry); + + /* Is this entry part of this heap? */ + if (((ULONG_PTR)Heap->HeapBottom <= (ULONG_PTR)BusyEntry) && + ((ULONG_PTR)BusyEntry < (ULONG_PTR)Heap->HeapTop)) + { + /* Ignore double-free */ + if (BusyEntry->BufferNext.BufferFree) + { + return STATUS_INVALID_PARAMETER; + } + + /* It is -- add it to the free list */ + MmHapAddToFreeList(BusyEntry, 0); + return STATUS_SUCCESS; + } + + /* It isn't, move to the next heap */ + NextEntry = NextEntry->Flink; + } + + /* The entry is not on any valid heap */ + return STATUS_INVALID_PARAMETER; +} + Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Sun Sep 6 19:56:47 2015 @@ -32,6 +32,8 @@ PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap; PBL_MM_FLUSH_TLB BlMmFlushTlb; +ULONG MmDeferredMappingCount; + /* FUNCTIONS *****************************************************************/ VOID @@ -41,6 +43,39 @@ { /* Nothing to do */ return; +} + +NTSTATUS +Mmx86pMapMemoryRegions ( + _In_ ULONG Phase, + _In_ PBL_MEMORY_DATA MemoryData + ) +{ + BOOLEAN DoDeferred; + + /* In phase 1 we don't initialize deferred mappings*/ + if (Phase == 1) + { + DoDeferred = 0; + } + else + { + /* Don't do anything if there's nothing to initialize */ + if (!MmDeferredMappingCount) + { + return STATUS_SUCCESS; + } + + DoDeferred = 1; + } + + if (DoDeferred) + { + EarlyPrint(L"Deferred todo\n"); + } + + EarlyPrint(L"Phase 1 TODO\n"); + return STATUS_NOT_IMPLEMENTED; } NTSTATUS @@ -56,8 +91,7 @@ /* For phase 2, just map deferred regions */ if (Phase != 1) { - //return Mmx86pMapMemoryRegions(2, MemoryData); - return STATUS_NOT_IMPLEMENTED; + return Mmx86pMapMemoryRegions(2, MemoryData); } /* What translation type are we switching to? */ Modified: trunk/reactos/boot/environ/lib/mm/mm.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?r…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] Sun Sep 6 19:56:47 2015 @@ -116,6 +116,9 @@ if (LibraryParameters->DescriptorCount > 512) { /* Switch to using a dynamic buffer instead */ + EarlyPrint(L"Warning: too many descriptors\n"); + Status = STATUS_NOT_IMPLEMENTED; + goto Quickie; //MmMdpSwitchToDynamicDescriptors(LibraryParameters->DescriptorCount); }
9 years, 3 months
1
0
0
0
[ion] 69067: [BOOTMGFW] - Implement most of the physical memory allocator. The heap manager now gets its page allocation fulfilled.
by ion@svn.reactos.org
Author: ion Date: Sun Sep 6 19:22:37 2015 New Revision: 69067 URL:
http://svn.reactos.org/svn/reactos?rev=69067&view=rev
Log: [BOOTMGFW] - Implement most of the physical memory allocator. The heap manager now gets its page allocation fulfilled. Modified: trunk/reactos/boot/environ/include/bl.h trunk/reactos/boot/environ/lib/mm/descriptor.c trunk/reactos/boot/environ/lib/mm/pagealloc.c Modified: trunk/reactos/boot/environ/include/bl.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
============================================================================== --- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original) +++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Sep 6 19:22:37 2015 @@ -61,8 +61,15 @@ #define BL_MM_ADD_DESCRIPTOR_NEVER_TRUNCATE_FLAG 0x20 #define BL_MM_ADD_DESCRIPTOR_UPDATE_LIST_POINTER_FLAG 0x2000 +#define BL_MM_DESCRIPTOR_REQUIRES_FIXED_FLAG 0x40000 #define BL_MM_DESCRIPTOR_REQUIRES_COALESCING_FLAG 0x2000000 #define BL_MM_DESCRIPTOR_REQUIRES_UPDATING_FLAG 0x4000000 +#define BL_MM_DESCRIPTOR_NEVER_USE_FIRMWARE_FLAG 0x8000000 +#define BL_MM_DESCRIPTOR_SPECIAL_PAGES_FLAG 0x20000000 +#define BL_MM_DESCRIPTOR_CAME_FROM_FIRMWARE_FLAG 0x80000000 + +#define BL_MM_REQUEST_DEFAULT_TYPE 1 +#define BL_MM_REQUEST_TOP_DOWN_TYPE 2 #define BL_MM_REMOVE_VIRTUAL_REGION_FLAG 0x80000000 @@ -474,6 +481,15 @@ _In_ PBL_LIBRARY_PARAMETERS LibraryParameters ); +/* FIRMWARE ROUTINES *********************************************************/ + +NTSTATUS +EfiAllocatePages ( + _In_ ULONG Type, + _In_ ULONG Pages, + _Inout_ EFI_PHYSICAL_ADDRESS* Memory + ); + /* UTILITY ROUTINES **********************************************************/ EFI_STATUS @@ -553,11 +569,35 @@ _In_ ULONGLONG PageCount ); +VOID +MmMdFreeGlobalDescriptors ( + VOID + ); + NTSTATUS MmMdAddDescriptorToList ( _In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor, _In_ ULONG Flags + ); + +VOID +MmMdRemoveDescriptorFromList ( + _In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, + _In_ PBL_MEMORY_DESCRIPTOR Entry + ); + +BOOLEAN +MmMdFindSatisfyingRegion ( + _In_ PBL_MEMORY_DESCRIPTOR Descriptor, + _Out_ PBL_MEMORY_DESCRIPTOR NewDescriptor, + _In_ ULONGLONG Pages, + _In_ PBL_ADDRESS_RANGE BaseRange, + _In_ PBL_ADDRESS_RANGE VirtualRange, + _In_ BOOLEAN TopDown, + _In_ BL_MEMORY_TYPE MemoryType, + _In_ ULONG Flags, + _In_ ULONG Alignment ); NTSTATUS @@ -567,6 +607,11 @@ __in ULONGLONG BasePage, __in ULONGLONG PageCount, __in PBL_MEMORY_DESCRIPTOR_LIST NewMdList + ); + +NTSTATUS +MmMdFreeDescriptor ( + _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor ); NTSTATUS Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descri…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/descriptor.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/descriptor.c [iso-8859-1] Sun Sep 6 19:22:37 2015 @@ -646,6 +646,151 @@ return Status; } +BOOLEAN +MmMdFindSatisfyingRegion ( + _In_ PBL_MEMORY_DESCRIPTOR Descriptor, + _Out_ PBL_MEMORY_DESCRIPTOR NewDescriptor, + _In_ ULONGLONG Pages, + _In_ PBL_ADDRESS_RANGE BaseRange, + _In_ PBL_ADDRESS_RANGE VirtualRange, + _In_ BOOLEAN TopDown, + _In_ BL_MEMORY_TYPE MemoryType, + _In_ ULONG Flags, + _In_ ULONG Alignment + ) +{ + ULONGLONG BaseMin, BaseMax; + ULONGLONG VirtualPage, BasePage; + + /* Extract the minimum and maximum range */ + BaseMin = BaseRange->Minimum; + BaseMax = BaseRange->Maximum; + + /* Don't go below where the descriptor starts */ + if (BaseMin < Descriptor->BasePage) + { + BaseMin = Descriptor->BasePage; + } + + /* Don't go beyond where the descriptor ends */ + if (BaseMax > (Descriptor->BasePage + Descriptor->PageCount - 1)) + { + BaseMax = (Descriptor->BasePage + Descriptor->PageCount - 1); + } + + /* Check for start overflow */ + if (BaseMin > BaseMax) + { + EarlyPrint(L"Descriptor overflow\n"); + return FALSE; + } + + /* Align the base as required */ + if (Alignment != 1) + { + BaseMin = ALIGN_UP_BY(BaseMin, Alignment); + } + + /* Check for range overflow */ + if (((BaseMin + Pages - 1) < BaseMin) || ((BaseMin + Pages - 1) > BaseMax)) + { + return FALSE; + } + + /* Check if this was a top-down request */ + if (TopDown) + { + /* Then get the highest page possible */ + BasePage = BaseMax - Pages + 1; + if (Alignment != 1) + { + /* Align it as needed */ + BasePage = ALIGN_DOWN_BY(BasePage, Alignment); + } + } + else + { + /* Otherwise, get the lowest page possible */ + BasePage = BaseMin; + } + + /* If a virtual address range was passed in, this must be a virtual descriptor */ + if (((VirtualRange->Minimum) || (VirtualRange->Maximum)) && + !(Descriptor->VirtualPage)) + { + return FALSE; + } + + /* Any mapped page already? */ + if (Descriptor->VirtualPage) + { + EarlyPrint(L"Virtual memory not yet supported\n"); + return FALSE; + } + else + { + /* Nothing to worry about */ + VirtualPage = 0; + } + + /* Bail out if the memory type attributes don't match */ + if ((((Flags & 0xFF) & (Descriptor->Flags & 0xFF)) != (Flags & 0xFF)) || + (((Flags & 0xFF00) & (Descriptor->Flags & 0xFF00)) != (Flags & 0xFF00))) + { + EarlyPrint(L"Incorrect memory attributes\n"); + return FALSE; + } + + /* Bail out if the allocation flags don't match */ + if (((Flags ^ Descriptor->Flags) & 0x190000)) + { + EarlyPrint(L"Incorrect memory allocation flags\n"); + return FALSE; + } + + /* Bail out if the type doesn't match */ + if (Descriptor->Type != MemoryType) + { + //EarlyPrint(L"Incorrect descriptor type\n"); + return FALSE; + } + + /* We have a matching region, fill out the descriptor for it */ + NewDescriptor->BasePage = BasePage; + NewDescriptor->PageCount = Pages; + NewDescriptor->Type = Descriptor->Type; + NewDescriptor->VirtualPage = VirtualPage; + NewDescriptor->Flags = Descriptor->Flags; + //EarlyPrint(L"Found a matching descriptor: %08I64X with %08I64X pages\n", BasePage, Pages); + return TRUE; +} + +VOID +MmMdFreeGlobalDescriptors ( + VOID + ) +{ + ULONG Index = 0; + + /* Make sure we're not int middle of a call using a descriptor */ + if (MmDescriptorCallTreeCount != 1) + { + return; + } + + /* Loop every current global descriptor */ + while (Index < MmGlobalMemoryDescriptorsUsed) + { + EarlyPrint(L"Global descriptors not yet supported\n"); + + /* Keep going */ + Index++; + } + + /* All global descriptors freed */ + MmGlobalMemoryDescriptorsUsed = 0; +} + VOID MmMdInitialize ( _In_ ULONG Phase, Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pageal…
============================================================================== --- trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] (original) +++ trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] Sun Sep 6 19:22:37 2015 @@ -9,6 +9,18 @@ /* INCLUDES ******************************************************************/ #include "bl.h" + + +typedef struct _BL_PA_REQUEST +{ + BL_ADDRESS_RANGE BaseRange; + BL_ADDRESS_RANGE VirtualRange; + ULONG Type; + ULONGLONG Pages; + ULONG MemoryType; + ULONG Alignment; + ULONG Flags; +} BL_PA_REQUEST, *PBL_PA_REQUEST; /* DATA VARIABLES ************************************************************/ @@ -43,6 +55,341 @@ } NTSTATUS +MmPapAllocateRegionFromMdl ( + _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, + _Out_opt_ PBL_MEMORY_DESCRIPTOR Descriptor, + _In_ PBL_MEMORY_DESCRIPTOR_LIST CurrentList, + _In_ PBL_PA_REQUEST Request, + _In_ BL_MEMORY_TYPE Type + ) +{ + NTSTATUS Status; + BL_MEMORY_DESCRIPTOR LocalDescriptor = {{0}}; + PBL_MEMORY_DESCRIPTOR FoundDescriptor, TempDescriptor; + PLIST_ENTRY ListHead, NextEntry; + BOOLEAN TopDown, GotFwPages; + EFI_PHYSICAL_ADDRESS EfiAddress; + ULONGLONG LocalEndPage, FoundEndPage, LocalVirtualEndPage; + + /* Check if any parameters were not passed in correctly */ + if ( !(CurrentList) || !(Request) || (!(NewList) && !(Descriptor))) + { + return STATUS_INVALID_PARAMETER; + } + + /* Set failure by default */ + Status = STATUS_NO_MEMORY; + + /* Take the head and next entry in the list, as appropriate */ + ListHead = CurrentList->First; + if (Request->Type & BL_MM_REQUEST_TOP_DOWN_TYPE) + { + NextEntry = ListHead->Flink; + TopDown = FALSE; + } + else + { + NextEntry = ListHead->Blink; + TopDown = TRUE; + } + + /* Loop through the list */ + GotFwPages = FALSE; + while (NextEntry != ListHead) + { + /* Grab a descriptor */ + FoundDescriptor = CONTAINING_RECORD(NextEntry, + BL_MEMORY_DESCRIPTOR, + ListEntry); + + /* See if it matches the request */ + if (MmMdFindSatisfyingRegion(FoundDescriptor, + &LocalDescriptor, + Request->Pages, + &Request->BaseRange, + &Request->VirtualRange, + TopDown, + Request->MemoryType, + Request->Flags, + Request->Alignment)) + { + /* It does, get out */ + break; + } + + /* It doesn't, move to the next appropriate entry */ + if (TopDown) + { + NextEntry = NextEntry->Blink; + } + else + { + NextEntry = NextEntry->Flink; + } + } + + /* Check if we exhausted the list */ + if (NextEntry == ListHead) + { + EarlyPrint(L"No matching memory found\n"); + return Status; + } + + /* Copy all the flags that are not request flag */ + LocalDescriptor.Flags = (Request->Flags & 0xFFFF0000) | + (LocalDescriptor.Flags & 0x0000FFFF); + + /* Are we using the physical memory list, and are we OK with using firmware? */ + if ((CurrentList == &MmMdlUnmappedUnallocated) && + !((Request->Flags & BL_MM_DESCRIPTOR_NEVER_USE_FIRMWARE_FLAG) || + (LocalDescriptor.Flags & BL_MM_DESCRIPTOR_NEVER_USE_FIRMWARE_FLAG))) + { + /* Allocate the requested address from EFI */ + EfiAddress = LocalDescriptor.BasePage << PAGE_SHIFT; + Status = EfiAllocatePages(AllocateAddress, + (ULONG)LocalDescriptor.PageCount, + &EfiAddress); + if (!NT_SUCCESS(Status)) + { + EarlyPrint(L"EFI memory allocation failure\n"); + return Status; + } + + /* Remember we got memory from EFI */ + GotFwPages = TRUE; + } + + /* Remove the descriptor from the original list it was on */ + MmMdRemoveDescriptorFromList(CurrentList, FoundDescriptor); + + /* Are we allocating from the virtual memory list? */ + if (CurrentList == &MmMdlMappedUnallocated) + { + EarlyPrint(L"Virtual memory not yet supported\n"); + return STATUS_NOT_IMPLEMENTED; + } + + /* Does the memory we received not exactly fall onto the beginning of its descriptor? */ + if (LocalDescriptor.BasePage != FoundDescriptor->BasePage) + { + EarlyPrint(L"Local Page: %08I64X Found Page: %08I64X\n", LocalDescriptor.BasePage, FoundDescriptor->BasePage); + TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags, + FoundDescriptor->Type, + FoundDescriptor->BasePage, + FoundDescriptor->VirtualPage, + LocalDescriptor.BasePage - + FoundDescriptor->BasePage); + Status = MmMdAddDescriptorToList(CurrentList, TempDescriptor, 0); + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + + /* Does the memory we received not exactly fall onto the end of its descriptor? */ + LocalEndPage = LocalDescriptor.PageCount + LocalDescriptor.BasePage; + FoundEndPage = FoundDescriptor->PageCount + FoundDescriptor->BasePage; + LocalVirtualEndPage = LocalDescriptor.VirtualPage ? + LocalDescriptor.VirtualPage + LocalDescriptor.PageCount : 0; + if (LocalEndPage != FoundEndPage) + { + EarlyPrint(L"Local Page: %08I64X Found Page: %08I64X\n", LocalEndPage, FoundEndPage); + TempDescriptor = MmMdInitByteGranularDescriptor(FoundDescriptor->Flags, + FoundDescriptor->Type, + LocalEndPage, + LocalVirtualEndPage, + FoundEndPage - LocalEndPage); + Status = MmMdAddDescriptorToList(CurrentList, TempDescriptor, 0); + if (!NT_SUCCESS(Status)) + { + return Status; + } + } + + /* We got the memory we needed */ + Status = STATUS_SUCCESS; + + /* Are we supposed to insert it into a new list? */ + if (NewList) + { + /* Copy the allocated region descriptor into the one we found */ + FoundDescriptor->BaseAddress = LocalDescriptor.BaseAddress; + FoundDescriptor->VirtualPage = LocalDescriptor.VirtualPage; + FoundDescriptor->PageCount = LocalDescriptor.PageCount; + FoundDescriptor->Type = Type; + FoundDescriptor->Flags = LocalDescriptor.Flags; + + /* Remember if it came from EFI */ + if (GotFwPages) + { + FoundDescriptor->Flags |= BL_MM_DESCRIPTOR_CAME_FROM_FIRMWARE_FLAG; + } + + /* Add the descriptor to the requested list */ + Status = MmMdAddDescriptorToList(NewList, FoundDescriptor, 0); + } + else + { + /* Free the descriptor, nobody wants to know about it anymore */ + MmMdFreeDescriptor(FoundDescriptor); + } + + /* Return the allocation region back */ + RtlCopyMemory(Descriptor, &LocalDescriptor, sizeof(LocalDescriptor)); + return Status; +} + +NTSTATUS +MmPaAllocatePages ( + _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, + _In_ PBL_MEMORY_DESCRIPTOR Descriptor, + _In_ PBL_MEMORY_DESCRIPTOR_LIST CurrentList, + _In_ PBL_PA_REQUEST Request, + _In_ BL_MEMORY_TYPE MemoryType + ) +{ + NTSTATUS Status; + + /* Heap and page directory/table pages have a special flag */ + if ((MemoryType >= BlLoaderHeap) && (MemoryType <= BlLoaderReferencePage)) + { + Request->Flags |= BL_MM_DESCRIPTOR_SPECIAL_PAGES_FLAG; + } + + /* Try to find a free region of RAM matching this range and request */ + Request->MemoryType = BlConventionalMemory; + Status = MmPapAllocateRegionFromMdl(NewList, + Descriptor, + CurrentList, + Request, + MemoryType); + if (Status == STATUS_NOT_FOUND) + { + /* Need to re-synchronize the memory map and check other lists */ + EarlyPrint(L"No RAM found -- backup plan not yet implemented\n"); + } + + /* Did we get the region we wanted? */ + if (NT_SUCCESS(Status)) + { + /* All good, return back */ + return Status; + } + + /* Nope, we have to hunt for it elsewhere */ + EarlyPrint(L"TODO\n"); + return Status; +} + +NTSTATUS +MmPapAllocatePhysicalPagesInRange ( + _Inout_ PPHYSICAL_ADDRESS BaseAddress, + _In_ BL_MEMORY_TYPE MemoryType, + _In_ ULONGLONG Pages, + _In_ ULONG Attributes, + _In_ ULONG Alignment, + _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, + _In_opt_ PBL_ADDRESS_RANGE Range, + _In_ ULONG RangeType + ) +{ + NTSTATUS Status; + BL_PA_REQUEST Request; + BL_MEMORY_DESCRIPTOR Descriptor; + + /* Increase nesting depth */ + ++MmDescriptorCallTreeCount; + + /* Bail out if no address was specified */ + if (!BaseAddress) + { + Status = STATUS_INVALID_PARAMETER; + goto Quickie; + } + + /* Bail out if no page count was passed in, or a bad list was specified */ + if (!(Pages) || + ((NewList != &MmMdlUnmappedAllocated) && + (NewList != &MmMdlPersistentMemory))) + { + Status = STATUS_INVALID_PARAMETER; + goto Quickie; + } + + /* Bail out if the passed in range is invalid */ + if ((Range) && (Range->Minimum >= Range->Maximum)) + { + Status = STATUS_INVALID_PARAMETER; + goto Quickie; + } + + /* Adjust alignment as needed */ + if (!Alignment) + { + Alignment = 1; + } + + /* Clear the virtual range */ + Request.VirtualRange.Minimum = 0; + Request.VirtualRange.Maximum = 0; + + /* Check if a fixed allocation was requested*/ + if (Attributes & BL_MM_DESCRIPTOR_REQUIRES_FIXED_FLAG) + { + /* Force the only available range to be the passed in address */ + Request.BaseRange.Minimum = BaseAddress->QuadPart >> PAGE_SHIFT; + Request.BaseRange.Maximum = Request.BaseRange.Minimum + Pages - 1; + } + else if (Range) + { + /* Otherwise, a manual range was specified, use it */ + Request.BaseRange.Minimum = Range->Minimum >> PAGE_SHIFT; + Request.BaseRange.Maximum = Request.BaseRange.Minimum + + (Range->Maximum >> PAGE_SHIFT) - 1; + } + else + { + /* Otherwise, use any possible range of pages */ + Request.BaseRange.Minimum = PapMinimumPhysicalPage; + Request.BaseRange.Maximum = MAXULONG >> PAGE_SHIFT; + } + + /* Check if no type was specified, or if it was invalid */ + if (!(RangeType) || + (RangeType & ~(BL_MM_REQUEST_TOP_DOWN_TYPE | BL_MM_REQUEST_DEFAULT_TYPE))) + { + /* Use default type */ + Request.Type = BL_MM_REQUEST_DEFAULT_TYPE; + } + else + { + /* Use the requested type */ + Request.Type = RangeType; + } + + /* Capture the other request parameters */ + Request.Alignment = Alignment; + Request.Pages = Pages; + Request.Flags = Attributes; + Status = MmPaAllocatePages(NewList, + &Descriptor, + &MmMdlUnmappedUnallocated, + &Request, + MemoryType); + if (NT_SUCCESS(Status)) + { + /* We got a descriptor back, return its address */ + BaseAddress->QuadPart = Descriptor.BasePage << PAGE_SHIFT; + } + +Quickie: + /* Restore the nesting depth */ + MmMdFreeGlobalDescriptors(); + --MmDescriptorCallTreeCount; + return Status; +} + +NTSTATUS MmPapAllocatePagesInRange ( _Inout_ PULONG PhysicalAddress, _In_ BL_MEMORY_TYPE MemoryType, @@ -53,7 +400,56 @@ _In_ ULONG Type ) { - return STATUS_NOT_IMPLEMENTED; + NTSTATUS Status; + PHYSICAL_ADDRESS BaseAddress; + + /* Increment nesting depth */ + ++MmDescriptorCallTreeCount; + + /* Check for missing parameters or invalid range */ + if (!(PhysicalAddress) || + !(Pages) || + ((Range) && (Range->Minimum >= Range->Maximum))) + { + Status = STATUS_INVALID_PARAMETER; + goto Exit; + } + + /* What translation mode are we using? */ + if (MmTranslationType != BlNone) + { + /* We don't support virtual memory yet */ + Status = STATUS_NOT_IMPLEMENTED; + goto Exit; + } + else + { + /* Check if this is a fixed allocation */ + BaseAddress.QuadPart = (Attributes & BL_MM_DESCRIPTOR_REQUIRES_FIXED_FLAG) ? + *PhysicalAddress : 0; + + /* Allocate the pages */ + Status = MmPapAllocatePhysicalPagesInRange(&BaseAddress, + MemoryType, + Pages, + Attributes, + Alignment, + (&MmMdlMappedAllocated != + &MmMdlPersistentMemory) ? + &MmMdlUnmappedAllocated : + &MmMdlMappedAllocated, + Range, + Type); + + /* Return the allocated address */ + *PhysicalAddress = BaseAddress.LowPart; + } + +Exit: + /* Restore the nesting depth */ + MmMdFreeGlobalDescriptors(); + --MmDescriptorCallTreeCount; + return Status; } NTSTATUS
9 years, 3 months
1
0
0
0
[tfaber] 69066: [ACPI] - Remove the no longer needed HPET hack. VMware works fine now.
by tfaber@svn.reactos.org
Author: tfaber Date: Sun Sep 6 18:51:09 2015 New Revision: 69066 URL:
http://svn.reactos.org/svn/reactos?rev=69066&view=rev
Log: [ACPI] - Remove the no longer needed HPET hack. VMware works fine now. Modified: trunk/reactos/drivers/bus/acpi/busmgr/bus.c Modified: trunk/reactos/drivers/bus/acpi/busmgr/bus.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/acpi/busmgr/bu…
============================================================================== --- trunk/reactos/drivers/bus/acpi/busmgr/bus.c [iso-8859-1] (original) +++ trunk/reactos/drivers/bus/acpi/busmgr/bus.c [iso-8859-1] Sun Sep 6 18:51:09 2015 @@ -1192,14 +1192,6 @@ snprintf(device->pnp.bus_id, sizeof(device->pnp.bus_id), "%s", bus_id); buffer.Pointer = NULL; - /* HACK: Skip HPET */ - if (strstr(device->pnp.bus_id, "HPET")) - { - DPRINT("Using HPET hack\n"); - result = -1; - goto end; - } - break; }
9 years, 3 months
1
0
0
0
[dquintana] 69065: [FATTEN] Change tabs to spaces, but only for the files I write. The rest come directly from the fatfs package and are best left untouched.
by dquintana@svn.reactos.org
Author: dquintana Date: Sun Sep 6 18:24:44 2015 New Revision: 69065 URL:
http://svn.reactos.org/svn/reactos?rev=69065&view=rev
Log: [FATTEN] Change tabs to spaces, but only for the files I write. The rest come directly from the fatfs package and are best left untouched. Modified: trunk/reactos/tools/fatten/fatfs/diskio.c trunk/reactos/tools/fatten/fatten.c Modified: trunk/reactos/tools/fatten/fatfs/diskio.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.…
============================================================================== --- trunk/reactos/tools/fatten/fatfs/diskio.c [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatfs/diskio.c [iso-8859-1] Sun Sep 6 18:24:44 2015 @@ -14,28 +14,28 @@ /*-----------------------------------------------------------------------*/ /* Correspondence between physical drive number and image file handles. */ -FILE* driveHandle[1] = {NULL}; +FILE* driveHandle[1] = { NULL }; const int driveHandleCount = sizeof(driveHandle) / sizeof(FILE*); /*-----------------------------------------------------------------------*/ /* Inidialize a Drive */ /*-----------------------------------------------------------------------*/ -DSTATUS disk_initialize ( - BYTE pdrv /* Physical drive nmuber (0..) */ -) +DSTATUS disk_initialize( + BYTE pdrv /* Physical drive nmuber (0..) */ + ) { - if(pdrv == 0) // only one drive (image file) supported atm. - { - if(driveHandle[0]!=NULL) - return 0; + if (pdrv == 0) /* only one drive (image file) supported atm. */ + { + if (driveHandle[0] != NULL) + return 0; - driveHandle[0]=fopen(imageFileName, "r+b"); + driveHandle[0] = fopen(imageFileName, "r+b"); - if(driveHandle[0]!=NULL) - return 0; - } - return STA_NOINIT; + if (driveHandle[0] != NULL) + return 0; + } + return STA_NOINIT; } @@ -44,16 +44,16 @@ /* Get Disk Status */ /*-----------------------------------------------------------------------*/ -DSTATUS disk_status ( - BYTE pdrv /* Physical drive nmuber (0..) */ -) +DSTATUS disk_status( + BYTE pdrv /* Physical drive nmuber (0..) */ + ) { - if(pdrv < driveHandleCount) - { - if(driveHandle[pdrv] != NULL) - return 0; - } - return STA_NOINIT; + if (pdrv < driveHandleCount) + { + if (driveHandle[pdrv] != NULL) + return 0; + } + return STA_NOINIT; } @@ -62,32 +62,32 @@ /* Read Sector(s) */ /*-----------------------------------------------------------------------*/ -DRESULT disk_read ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - BYTE *buff, /* Data buffer to store read data */ - DWORD sector, /* Sector address (LBA) */ - UINT count /* Number of sectors to read (1..128) */ -) +DRESULT disk_read( + BYTE pdrv, /* Physical drive nmuber (0..) */ + BYTE *buff, /* Data buffer to store read data */ + DWORD sector, /* Sector address (LBA) */ + UINT count /* Number of sectors to read (1..128) */ + ) { - DWORD result; + DWORD result; - if(pdrv < driveHandleCount) - { - if(driveHandle[pdrv] != NULL) - { - if(fseek(driveHandle[pdrv], sector * 512, SEEK_SET)) - return RES_ERROR; + if (pdrv < driveHandleCount) + { + if (driveHandle[pdrv] != NULL) + { + if (fseek(driveHandle[pdrv], sector * 512, SEEK_SET)) + return RES_ERROR; - result = fread(buff, 512, count, driveHandle[pdrv]); + result = fread(buff, 512, count, driveHandle[pdrv]); - if(result == count) - return RES_OK; + if (result == count) + return RES_OK; - return RES_ERROR; - } - } + return RES_ERROR; + } + } - return RES_PARERR; + return RES_PARERR; } @@ -97,33 +97,33 @@ /*-----------------------------------------------------------------------*/ #if _USE_WRITE -DRESULT disk_write ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - const BYTE *buff, /* Data to be written */ - DWORD sector, /* Sector address (LBA) */ - UINT count /* Number of sectors to write (1..128) */ -) +DRESULT disk_write( + BYTE pdrv, /* Physical drive nmuber (0..) */ + const BYTE *buff, /* Data to be written */ + DWORD sector, /* Sector address (LBA) */ + UINT count /* Number of sectors to write (1..128) */ + ) { - DWORD result; + DWORD result; - if(pdrv < driveHandleCount) - { - if(driveHandle[pdrv] != NULL) - { - if(fseek(driveHandle[pdrv], sector * 512, SEEK_SET)) - return RES_ERROR; + if (pdrv < driveHandleCount) + { + if (driveHandle[pdrv] != NULL) + { + if (fseek(driveHandle[pdrv], sector * 512, SEEK_SET)) + return RES_ERROR; - result = fwrite(buff, 512, count, driveHandle[pdrv]); - return RES_ERROR; + result = fwrite(buff, 512, count, driveHandle[pdrv]); + return RES_ERROR; - if(result != (512 * count)) - return RES_ERROR; + if (result != (512 * count)) + return RES_ERROR; - return RES_OK; - } - } + return RES_OK; + } + } - return RES_PARERR; + return RES_PARERR; } #endif @@ -133,58 +133,58 @@ /*-----------------------------------------------------------------------*/ #if _USE_IOCTL -DRESULT disk_ioctl ( - BYTE pdrv, /* Physical drive nmuber (0..) */ - BYTE cmd, /* Control code */ - void *buff /* Buffer to send/receive control data */ -) +DRESULT disk_ioctl( + BYTE pdrv, /* Physical drive nmuber (0..) */ + BYTE cmd, /* Control code */ + void *buff /* Buffer to send/receive control data */ + ) { - if(pdrv < driveHandleCount) - { - if(driveHandle[pdrv] != NULL) - { - switch(cmd) - { - case CTRL_SYNC: - fflush(driveHandle[pdrv]); - return RES_OK; - case GET_SECTOR_SIZE: - *(DWORD*)buff = 512; - return RES_OK; - case GET_BLOCK_SIZE: - *(DWORD*)buff = 512; - return RES_OK; - case GET_SECTOR_COUNT: - fseek(driveHandle[pdrv], 0, SEEK_END); - *(DWORD*)buff = ftell(driveHandle[pdrv]) / 512; - return RES_OK; - case SET_SECTOR_COUNT: - { - int count = *(DWORD*)buff; - long size; - - fseek(driveHandle[pdrv], 0, SEEK_END); - size = ftell(driveHandle[pdrv]) / 512; - - if(size < count) - { - if(fseek(driveHandle[pdrv], count * 512 - 1, SEEK_SET)) - return RES_ERROR; + if (pdrv < driveHandleCount) + { + if (driveHandle[pdrv] != NULL) + { + switch (cmd) + { + case CTRL_SYNC: + fflush(driveHandle[pdrv]); + return RES_OK; + case GET_SECTOR_SIZE: + *(DWORD*)buff = 512; + return RES_OK; + case GET_BLOCK_SIZE: + *(DWORD*)buff = 512; + return RES_OK; + case GET_SECTOR_COUNT: + fseek(driveHandle[pdrv], 0, SEEK_END); + *(DWORD*)buff = ftell(driveHandle[pdrv]) / 512; + return RES_OK; + case SET_SECTOR_COUNT: + { + int count = *(DWORD*)buff; + long size; - fwrite(buff, 1, 1, driveHandle[pdrv]); + fseek(driveHandle[pdrv], 0, SEEK_END); + size = ftell(driveHandle[pdrv]) / 512; - return RES_OK; - } - else - { - // SHRINKING NOT IMPLEMENTED - return RES_OK; - } - } - } - } - } + if (size < count) + { + if (fseek(driveHandle[pdrv], count * 512 - 1, SEEK_SET)) + return RES_ERROR; - return RES_PARERR; + fwrite(buff, 1, 1, driveHandle[pdrv]); + + return RES_OK; + } + else + { + // SHRINKING NOT IMPLEMENTED + return RES_OK; + } + } + } + } + } + + return RES_PARERR; } #endif Modified: trunk/reactos/tools/fatten/fatten.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatten.c?rev=…
============================================================================== --- trunk/reactos/tools/fatten/fatten.c [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatten.c [iso-8859-1] Sun Sep 6 18:24:44 2015 @@ -20,344 +20,344 @@ // tool needed by fatfs DWORD get_fattime() { - /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ - /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ - - time_t rawtime; - struct tm * timeinfo; - - time (&rawtime); - timeinfo = localtime (&rawtime); - - union FatTime { - struct { - DWORD Second : 5; // div 2 - DWORD Minute : 6; - DWORD Hour : 5; - DWORD Day : 5; - DWORD Month : 4; - DWORD Year : 7; // year-1980 - }; - DWORD whole; - } myTime = { - { - timeinfo->tm_sec / 2, - timeinfo->tm_min, - timeinfo->tm_hour, - timeinfo->tm_mday, - timeinfo->tm_mon, - timeinfo->tm_year - 1980, - } - }; - - return myTime.whole; + /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ + /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ + + time_t rawtime; + struct tm * timeinfo; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + union FatTime { + struct { + DWORD Second : 5; // div 2 + DWORD Minute : 6; + DWORD Hour : 5; + DWORD Day : 5; + DWORD Month : 4; + DWORD Year : 7; // year-1980 + }; + DWORD whole; + } myTime = { + { + timeinfo->tm_sec / 2, + timeinfo->tm_min, + timeinfo->tm_hour, + timeinfo->tm_mday, + timeinfo->tm_mon, + timeinfo->tm_year - 1980, + } + }; + + return myTime.whole; } BOOL is_command(const char* parg) { - return (parg[0]=='/') || (parg[0] == '-'); + return (parg[0] == '/') || (parg[0] == '-'); } #define NEED_PARAMS(_min_,_max_) \ - do {\ - if(nargs<_min_) { printf("Too few args for command %s.\n",argv[-1]); goto print_help; } \ - if(nargs>_max_) { printf("Too many args for command %s.\n",argv[-1]); goto print_help; } \ - } while(0) + do {\ + if(nargs<_min_) { printf("Too few args for command %s.\n",argv[-1]); goto print_help; } \ + if(nargs>_max_) { printf("Too many args for command %s.\n",argv[-1]); goto print_help; } \ + } while(0) BOOL need_mount() { - if(isMounted) - return FR_OK; - - int r = f_mount(&g_Filesystem, "0:", 0); - if(r) - return r; - - isMounted = 1; - return FR_OK; + if (isMounted) + return FR_OK; + + int r = f_mount(&g_Filesystem, "0:", 0); + if (r) + return r; + + isMounted = 1; + return FR_OK; } #define NEED_MOUNT() \ - do { ret = need_mount(); if(ret) \ - {\ - printf("Error: could not mount image file '%s' (%d). \n", imageFileName, ret); \ - goto print_help; \ - } } while(0) + do { ret = need_mount(); if(ret) \ + {\ + printf("Error: could not mount image file '%s' (%d). \n", imageFileName, ret); \ + goto print_help; \ + } } while(0) int main(int oargc, char* oargv[]) { - int ret; - int argc = oargc-1; - char** argv = oargv+1; - - // first parameter must be the image file. - if(argc == 0) - { - goto print_help; - } - - if(is_command(argv[0])) - { - printf("Error: first parameter must be a filename, found '%s' instead. \n", argv[0]); - goto print_help; - } - - imageFileName = argv[0]; - - if(disk_initialize(0)) - { - printf("Error: could not open image file '%s'. \n", imageFileName); - goto print_help; - } - - argc--; - argv++; - - while(argc>0) - { - char *parg = *argv; - - if(!is_command(parg)) - { - printf("Error: Expected a command, found '%s' instead. \n",parg); - goto print_help; - } - - parg++; - argv++; - argc--; - - // find next command, to calculare number of args - int nargs = 0; - int i=0; - while((argv[i] != NULL) && !is_command(argv[i++])) - nargs++; - - if(strcmp(parg,"format")==0) - { - // NOTE: The fs driver detects which FAT format fits best based on size - - NEED_PARAMS(1,1); - - NEED_MOUNT(); - - // Arg 1: number of sectors - int sectors = atoi(argv[0]); - - if(sectors <= 0) - { - printf("Error: Sectors must be > 0\n"); - return 1; - } - - disk_ioctl(0, SET_SECTOR_COUNT, §ors); - - ret = f_mkfs("0:", 1, 4096); - if (ret) - { - printf("ERROR: Formatting drive: %d.\n", ret); - goto print_help; - } - } - else if(strcmp(parg,"boot")==0) - { - NEED_PARAMS(1,1); - - // Arg 1: boot file - printf("Not Implemented."); - } - else if(strcmp(parg,"add")==0) - { - NEED_PARAMS(2,2); - - NEED_MOUNT(); - - // Arg 1: external file to add - // Arg 2: virtual filename - - FILE* fe; - FIL fv = {0}; - - if(fopen_s(&fe, argv[0],"rb")) - { - printf("Error: unable to open external file '%s' for reading.", argv[0]); - return 1; - } - if(f_open(&fv, argv[1], FA_WRITE | FA_CREATE_ALWAYS)) - { - printf("Error: unable to open file '%s' for writing.", argv[1]); - return 1; - } - - char buff[32768]; - UINT rdlen = 0; - UINT wrlen = 0; - - while( (rdlen = fread(buff,1,32768,fe)) > 0 ) - { - f_write(&fv,buff, rdlen, &wrlen); - } - - fclose(fe); - f_close(&fv); - } - else if(strcmp(parg,"extract")==0) - { - NEED_PARAMS(2,2); - - NEED_MOUNT(); - - // Arg 1: virtual file to extract - // Arg 2: external filename - - FIL fe = {0}; - FILE* fv; - - if(f_open(&fe, argv[0], FA_READ)) - { - printf("Error: unable to open file '%s' for reading.", argv[0]); - return 1; - } - if(fopen_s(&fv, argv[1],"wb")) - { - printf("Error: unable to open external file '%s' for writing.", argv[1]); - return 1; - } - - char buff[32768]; - UINT rdlen = 0; - UINT wrlen = 0; - - while( (f_read(&fe, buff, 32768, &rdlen) == 0 ) && ( rdlen > 0) ) - { - fwrite(buff, 1, rdlen, fv); - } - - f_close(&fe); - fclose(fv); - } - else if(strcmp(parg,"move")==0) - { - NEED_PARAMS(2,2); - - NEED_MOUNT(); - // Arg 1: src path & filename - // Arg 2: new path & filename - - if(f_rename(argv[0], argv[1])) - printf("Error moving/renaming '%s' to '%s'", argv[0],argv[1]); - } - else if(strcmp(parg,"copy")==0) - { - NEED_PARAMS(2,2) - - NEED_MOUNT(); - // Arg 1: src path & filename - // Arg 2: new path & filename - - FIL fe = {0}; - FIL fv = {0}; - - if(f_open(&fe, argv[0], FA_READ)) - { - printf("Error: unable to open file '%s' for reading.", argv[0]); - return 1; - } - if(f_open(&fv, argv[1], FA_WRITE|FA_CREATE_ALWAYS)) - { - printf("Error: unable to open file '%s' for writing.", argv[1]); - return 1; - } - - char buff[32768]; - UINT rdlen = 0; - UINT wrlen = 0; - - while( (f_read(&fe, buff, 32768, &rdlen) == 0) && (rdlen > 0) ) - { - f_write(&fv, buff, rdlen, &wrlen); - } - - f_close(&fe); - f_close(&fv); - } - else if(strcmp(parg,"mkdir")==0) - { - NEED_PARAMS(1,1); - - NEED_MOUNT(); - // Arg 1: folder path - f_mkdir(argv[1]); - } - else if(strcmp(parg,"delete")==0) - { - NEED_PARAMS(1,1); - - NEED_MOUNT(); - // Arg 1: file/folder path (cannot delete non-empty folders) - f_unlink(argv[1]); - } - else if(strcmp(parg,"list")==0) - { - NEED_PARAMS(0,1); - - // Arg 1: folder path (optional) - char* root = "/"; - - if(nargs == 1) - { - root = argv[0]; - } - - DIR dir = {0}; - - if(f_opendir(&dir, root)) - { - printf("Error opening directory '%s'.\n",root); - return 1; - } - - printf("Listing directory contents of: %s\n", root); - - FILINFO info = {0}; - CHAR lfname[257]; - info.lfname = lfname; - info.lfsize = 256; - while( (!f_readdir(&dir,&info)) && (strlen(info.fname)>0)) - { - if(strlen(info.lfname) > 0) - printf(" - %s (%s)\n", info.lfname, info.fname); - else - printf(" - %s\n", info.fname); - } - } - else - { - printf("Error: Unknown or invalid command: %s\n",argv[-1]); - goto print_help; - } - argv+=nargs; - argc-=nargs; - } - - return 0; + int ret; + int argc = oargc - 1; + char** argv = oargv + 1; + + // first parameter must be the image file. + if (argc == 0) + { + goto print_help; + } + + if (is_command(argv[0])) + { + printf("Error: first parameter must be a filename, found '%s' instead. \n", argv[0]); + goto print_help; + } + + imageFileName = argv[0]; + + if (disk_initialize(0)) + { + printf("Error: could not open image file '%s'. \n", imageFileName); + goto print_help; + } + + argc--; + argv++; + + while (argc > 0) + { + char *parg = *argv; + + if (!is_command(parg)) + { + printf("Error: Expected a command, found '%s' instead. \n", parg); + goto print_help; + } + + parg++; + argv++; + argc--; + + // find next command, to calculare number of args + int nargs = 0; + int i = 0; + while ((argv[i] != NULL) && !is_command(argv[i++])) + nargs++; + + if (strcmp(parg, "format") == 0) + { + // NOTE: The fs driver detects which FAT format fits best based on size + + NEED_PARAMS(1, 1); + + NEED_MOUNT(); + + // Arg 1: number of sectors + int sectors = atoi(argv[0]); + + if (sectors <= 0) + { + printf("Error: Sectors must be > 0\n"); + return 1; + } + + disk_ioctl(0, SET_SECTOR_COUNT, §ors); + + ret = f_mkfs("0:", 1, 4096); + if (ret) + { + printf("ERROR: Formatting drive: %d.\n", ret); + goto print_help; + } + } + else if (strcmp(parg, "boot") == 0) + { + NEED_PARAMS(1, 1); + + // Arg 1: boot file + printf("Not Implemented."); + } + else if (strcmp(parg, "add") == 0) + { + NEED_PARAMS(2, 2); + + NEED_MOUNT(); + + // Arg 1: external file to add + // Arg 2: virtual filename + + FILE* fe; + FIL fv = { 0 }; + + if (fopen_s(&fe, argv[0], "rb")) + { + printf("Error: unable to open external file '%s' for reading.", argv[0]); + return 1; + } + if (f_open(&fv, argv[1], FA_WRITE | FA_CREATE_ALWAYS)) + { + printf("Error: unable to open file '%s' for writing.", argv[1]); + return 1; + } + + char buff[32768]; + UINT rdlen = 0; + UINT wrlen = 0; + + while ((rdlen = fread(buff, 1, 32768, fe)) > 0) + { + f_write(&fv, buff, rdlen, &wrlen); + } + + fclose(fe); + f_close(&fv); + } + else if (strcmp(parg, "extract") == 0) + { + NEED_PARAMS(2, 2); + + NEED_MOUNT(); + + // Arg 1: virtual file to extract + // Arg 2: external filename + + FIL fe = { 0 }; + FILE* fv; + + if (f_open(&fe, argv[0], FA_READ)) + { + printf("Error: unable to open file '%s' for reading.", argv[0]); + return 1; + } + if (fopen_s(&fv, argv[1], "wb")) + { + printf("Error: unable to open external file '%s' for writing.", argv[1]); + return 1; + } + + char buff[32768]; + UINT rdlen = 0; + UINT wrlen = 0; + + while ((f_read(&fe, buff, 32768, &rdlen) == 0) && (rdlen > 0)) + { + fwrite(buff, 1, rdlen, fv); + } + + f_close(&fe); + fclose(fv); + } + else if (strcmp(parg, "move") == 0) + { + NEED_PARAMS(2, 2); + + NEED_MOUNT(); + // Arg 1: src path & filename + // Arg 2: new path & filename + + if (f_rename(argv[0], argv[1])) + printf("Error moving/renaming '%s' to '%s'", argv[0], argv[1]); + } + else if (strcmp(parg, "copy") == 0) + { + NEED_PARAMS(2, 2); + + NEED_MOUNT(); + // Arg 1: src path & filename + // Arg 2: new path & filename + + FIL fe = { 0 }; + FIL fv = { 0 }; + + if (f_open(&fe, argv[0], FA_READ)) + { + printf("Error: unable to open file '%s' for reading.", argv[0]); + return 1; + } + if (f_open(&fv, argv[1], FA_WRITE | FA_CREATE_ALWAYS)) + { + printf("Error: unable to open file '%s' for writing.", argv[1]); + return 1; + } + + char buff[32768]; + UINT rdlen = 0; + UINT wrlen = 0; + + while ((f_read(&fe, buff, 32768, &rdlen) == 0) && (rdlen > 0)) + { + f_write(&fv, buff, rdlen, &wrlen); + } + + f_close(&fe); + f_close(&fv); + } + else if (strcmp(parg, "mkdir") == 0) + { + NEED_PARAMS(1, 1); + + NEED_MOUNT(); + // Arg 1: folder path + f_mkdir(argv[1]); + } + else if (strcmp(parg, "delete") == 0) + { + NEED_PARAMS(1, 1); + + NEED_MOUNT(); + // Arg 1: file/folder path (cannot delete non-empty folders) + f_unlink(argv[1]); + } + else if (strcmp(parg, "list") == 0) + { + NEED_PARAMS(0, 1); + + // Arg 1: folder path (optional) + char* root = "/"; + + if (nargs == 1) + { + root = argv[0]; + } + + DIR dir = { 0 }; + + if (f_opendir(&dir, root)) + { + printf("Error opening directory '%s'.\n", root); + return 1; + } + + printf("Listing directory contents of: %s\n", root); + + FILINFO info = { 0 }; + CHAR lfname[257]; + info.lfname = lfname; + info.lfsize = 256; + while ((!f_readdir(&dir, &info)) && (strlen(info.fname) > 0)) + { + if (strlen(info.lfname) > 0) + printf(" - %s (%s)\n", info.lfname, info.fname); + else + printf(" - %s\n", info.fname); + } + } + else + { + printf("Error: Unknown or invalid command: %s\n", argv[-1]); + goto print_help; + } + argv += nargs; + argc -= nargs; + } + + return 0; print_help: - printf("Syntax: %s image_file [list of commands]\n\n", oargv[0]); - printf("Commands: [Note: both '/' and '-' are accepted as command prefixes.] \n"); - printf(" /format <sectors> [<filesystem>] Formats the disk image.\n"); - printf(" /boot <sector file> Writes a new boot sector.\n"); - printf(" /add <src path> <dst path> Copies an external file or directory\n" - " into the image.\n"); - printf(" /extract <src path> <dst path> Copies a file or directory from the image\n" - " into an external file or directory.\n"); - printf(" /move <src path> <new path> Moves/renames a file or directory.\n"); - printf(" /copy <src path> <new path> Copies a file or directory.\n"); - printf(" /mkdir <src path> <new path> Creates a directory.\n"); - printf(" /rmdir <src path> <new path> Creates a directory.\n"); - printf(" /list [<pattern>] Lists files a directory (defaults to root).\n"); - //printf(" /recursive Enables recursive processing for directories.\n"); - - return 1; + printf("Syntax: %s image_file [list of commands]\n\n", oargv[0]); + printf("Commands: [Note: both '/' and '-' are accepted as command prefixes.] \n"); + printf(" /format <sectors> [<filesystem>] Formats the disk image.\n"); + printf(" /boot <sector file> Writes a new boot sector.\n"); + printf(" /add <src path> <dst path> Copies an external file or directory\n" + " into the image.\n"); + printf(" /extract <src path> <dst path> Copies a file or directory from the image\n" + " into an external file or directory.\n"); + printf(" /move <src path> <new path> Moves/renames a file or directory.\n"); + printf(" /copy <src path> <new path> Copies a file or directory.\n"); + printf(" /mkdir <src path> <new path> Creates a directory.\n"); + printf(" /rmdir <src path> <new path> Creates a directory.\n"); + printf(" /list [<pattern>] Lists files a directory (defaults to root).\n"); + //printf(" /recursive Enables recursive processing for directories.\n"); + + return 1; }
9 years, 3 months
1
0
0
0
[dquintana] 69064: [FATTEN] * Improve crossplatformness. * Turn back some indentations into tabs (temporarily).
by dquintana@svn.reactos.org
Author: dquintana Date: Sun Sep 6 18:10:59 2015 New Revision: 69064 URL:
http://svn.reactos.org/svn/reactos?rev=69064&view=rev
Log: [FATTEN] * Improve crossplatformness. * Turn back some indentations into tabs (temporarily). Removed: trunk/reactos/tools/fatten/FAT.h Modified: trunk/reactos/tools/fatten/fatfs/diskio.c trunk/reactos/tools/fatten/fatten.c Removed: trunk/reactos/tools/fatten/FAT.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/FAT.h?rev=690…
============================================================================== --- trunk/reactos/tools/fatten/FAT.h [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/FAT.h (removed) @@ -1,42 +0,0 @@ -#ifndef _FAT_H_INCLUDED -#define _FAT_H_INCLUDED - -typedef unsigned __int8 u8; -typedef unsigned __int16 u16; -typedef unsigned __int32 UInt32; -typedef unsigned __int64 u64; -typedef signed __int8 s8; -typedef signed __int16 s16; -typedef signed __int32 s32; -typedef signed __int64 s64; - -#if 0 -struct Fat_Bootrecord { - u8 Jump[3]; - u8 OEMID[8]; - u8 BytesPerSector; - u8 SectorsPerCluster; // 1 - u16 ReservedSectors; // 1 - u8 FATs; - u16 RootEntries; - u16 Sectors16; - u8 MediaDescriptor; // F0h = 1.44 MB, 3.5", 2-sided, 18-sectors per track - u16 SectorsPerFAT; - u16 SectorsPerTrack; // 18 - u16 Heads; - u32 HiddenSectors; - u32 Sectors32; - u8 PhysicalDriveNo; // 00h for floppy, 80h for HDD - u8 CurrentHead; - u8 NTSignature; //for WinNT: 28h or 29h - u32 SerialNumber; - u8 VolumeLabel[11]; - u8 SystemID[8]; - u8 BootCode[510 - 62]; - u16 Signature; // 0xAA55 -}; -#endif - -extern char* imageFileName; - -#endif//_FAT_H_INCLUDED Modified: trunk/reactos/tools/fatten/fatfs/diskio.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.…
============================================================================== --- trunk/reactos/tools/fatten/fatfs/diskio.c [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatfs/diskio.c [iso-8859-1] Sun Sep 6 18:10:59 2015 @@ -7,13 +7,14 @@ /* storage control module to the FatFs module with a defined API. */ /*-----------------------------------------------------------------------*/ #include "diskio.h" -#include "../FAT.h" #include <stdio.h> + +extern char* imageFileName; /*-----------------------------------------------------------------------*/ /* Correspondence between physical drive number and image file handles. */ -HANDLE driveHandle[1] = {INVALID_HANDLE_VALUE}; +FILE* driveHandle[1] = {NULL}; const int driveHandleCount = sizeof(driveHandle) / sizeof(FILE*); /*-----------------------------------------------------------------------*/ @@ -26,12 +27,12 @@ { if(pdrv == 0) // only one drive (image file) supported atm. { - if(driveHandle[0]!=INVALID_HANDLE_VALUE) + if(driveHandle[0]!=NULL) return 0; - driveHandle[0]=CreateFile(imageFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL /* | FILE_FLAG_RANDOM_ACCESS */, NULL); + driveHandle[0]=fopen(imageFileName, "r+b"); - if(driveHandle[0]!=INVALID_HANDLE_VALUE) + if(driveHandle[0]!=NULL) return 0; } return STA_NOINIT; @@ -49,7 +50,7 @@ { if(pdrv < driveHandleCount) { - if(driveHandle[pdrv] != INVALID_HANDLE_VALUE) + if(driveHandle[pdrv] != NULL) return 0; } return STA_NOINIT; @@ -72,15 +73,14 @@ if(pdrv < driveHandleCount) { - if(driveHandle[pdrv] != INVALID_HANDLE_VALUE) + if(driveHandle[pdrv] != NULL) { - if(SetFilePointer(driveHandle[pdrv], sector * 512, NULL, SEEK_SET) == INVALID_SET_FILE_POINTER) + if(fseek(driveHandle[pdrv], sector * 512, SEEK_SET)) return RES_ERROR; - if(!ReadFile(driveHandle[pdrv], buff, 512 * count, &result, NULL)) - return RES_ERROR; + result = fread(buff, 512, count, driveHandle[pdrv]); - if(result == (512 * count)) + if(result == count) return RES_OK; return RES_ERROR; @@ -108,18 +108,18 @@ if(pdrv < driveHandleCount) { - if(driveHandle[pdrv] != INVALID_HANDLE_VALUE) + if(driveHandle[pdrv] != NULL) { - if(SetFilePointer(driveHandle[pdrv], sector * 512, NULL, SEEK_SET) == INVALID_SET_FILE_POINTER) + if(fseek(driveHandle[pdrv], sector * 512, SEEK_SET)) return RES_ERROR; - if(!WriteFile(driveHandle[pdrv], buff, 512 * count, &result, NULL)) + result = fwrite(buff, 512, count, driveHandle[pdrv]); return RES_ERROR; - if(result == (512 * count)) - return RES_OK; + if(result != (512 * count)) + return RES_ERROR; - return RES_ERROR; + return RES_OK; } } @@ -141,11 +141,12 @@ { if(pdrv < driveHandleCount) { - if(driveHandle[pdrv] != INVALID_HANDLE_VALUE) + if(driveHandle[pdrv] != NULL) { switch(cmd) { case CTRL_SYNC: + fflush(driveHandle[pdrv]); return RES_OK; case GET_SECTOR_SIZE: *(DWORD*)buff = 512; @@ -154,15 +155,32 @@ *(DWORD*)buff = 512; return RES_OK; case GET_SECTOR_COUNT: - { - *(DWORD*)buff = GetFileSize(driveHandle[pdrv], NULL) / 512; - } + fseek(driveHandle[pdrv], 0, SEEK_END); + *(DWORD*)buff = ftell(driveHandle[pdrv]) / 512; return RES_OK; case SET_SECTOR_COUNT: + { + int count = *(DWORD*)buff; + long size; + + fseek(driveHandle[pdrv], 0, SEEK_END); + size = ftell(driveHandle[pdrv]) / 512; + + if(size < count) { - SetFilePointer(driveHandle[pdrv], (*(DWORD*)buff)*512, NULL, SEEK_SET); - SetEndOfFile(driveHandle[pdrv]); + if(fseek(driveHandle[pdrv], count * 512 - 1, SEEK_SET)) + return RES_ERROR; + + fwrite(buff, 1, 1, driveHandle[pdrv]); + + return RES_OK; } + else + { + // SHRINKING NOT IMPLEMENTED + return RES_OK; + } + } } } } Modified: trunk/reactos/tools/fatten/fatten.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatten.c?rev=…
============================================================================== --- trunk/reactos/tools/fatten/fatten.c [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatten.c [iso-8859-1] Sun Sep 6 18:10:59 2015 @@ -7,8 +7,7 @@ */ #include <stdio.h> #include <string.h> -#include <windows.h> -#include "FAT.h" +#include <time.h> #include "fatfs/ff.h" #include "fatfs/diskio.h" @@ -16,7 +15,7 @@ FATFS g_Filesystem; -BOOL isMounted; +int isMounted = 0; // tool needed by fatfs DWORD get_fattime() @@ -24,9 +23,11 @@ /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ - SYSTEMTIME stm; - - GetLocalTime(&stm); + time_t rawtime; + struct tm * timeinfo; + + time (&rawtime); + timeinfo = localtime (&rawtime); union FatTime { struct { @@ -40,12 +41,12 @@ DWORD whole; } myTime = { { - stm.wSecond / 2, - stm.wMinute, - stm.wHour, - stm.wDay, - stm.wMonth, - stm.wYear - 1980, + timeinfo->tm_sec / 2, + timeinfo->tm_min, + timeinfo->tm_hour, + timeinfo->tm_mday, + timeinfo->tm_mon, + timeinfo->tm_year - 1980, } }; @@ -58,34 +59,34 @@ } #define NEED_PARAMS(_min_,_max_) \ - do {\ - if(nargs<_min_) { printf("Too few args for command %s.\n",argv[-1]); goto print_help; } \ - if(nargs>_max_) { printf("Too many args for command %s.\n",argv[-1]); goto print_help; } \ - } while(0) + do {\ + if(nargs<_min_) { printf("Too few args for command %s.\n",argv[-1]); goto print_help; } \ + if(nargs>_max_) { printf("Too many args for command %s.\n",argv[-1]); goto print_help; } \ + } while(0) BOOL need_mount() -{ - if(isMounted) - return FR_OK; - - int r = f_mount(&g_Filesystem, "0:", 0); +{ + if(isMounted) + return FR_OK; + + int r = f_mount(&g_Filesystem, "0:", 0); if(r) - return r; - - isMounted = TRUE; - return FR_OK; + return r; + + isMounted = 1; + return FR_OK; } #define NEED_MOUNT() \ - do { ret = need_mount(); if(ret) \ - {\ - printf("Error: could not mount image file '%s' (%d). \n", imageFileName, ret); \ - goto print_help; \ - } } while(0) + do { ret = need_mount(); if(ret) \ + {\ + printf("Error: could not mount image file '%s' (%d). \n", imageFileName, ret); \ + goto print_help; \ + } } while(0) int main(int oargc, char* oargv[]) { - int ret; + int ret; int argc = oargc-1; char** argv = oargv+1; @@ -135,10 +136,10 @@ if(strcmp(parg,"format")==0) { // NOTE: The fs driver detects which FAT format fits best based on size - + NEED_PARAMS(1,1); - NEED_MOUNT(); + NEED_MOUNT(); // Arg 1: number of sectors int sectors = atoi(argv[0]); @@ -150,13 +151,13 @@ } disk_ioctl(0, SET_SECTOR_COUNT, §ors); - - ret = f_mkfs("0:", 1, 4096); + + ret = f_mkfs("0:", 1, 4096); if (ret) - { - printf("ERROR: Formatting drive: %d.\n", ret); - goto print_help; - } + { + printf("ERROR: Formatting drive: %d.\n", ret); + goto print_help; + } } else if(strcmp(parg,"boot")==0) { @@ -168,8 +169,8 @@ else if(strcmp(parg,"add")==0) { NEED_PARAMS(2,2); - - NEED_MOUNT(); + + NEED_MOUNT(); // Arg 1: external file to add // Arg 2: virtual filename @@ -204,8 +205,8 @@ { NEED_PARAMS(2,2); - NEED_MOUNT(); - + NEED_MOUNT(); + // Arg 1: virtual file to extract // Arg 2: external filename @@ -239,8 +240,7 @@ { NEED_PARAMS(2,2); - NEED_MOUNT(); - + NEED_MOUNT(); // Arg 1: src path & filename // Arg 2: new path & filename @@ -249,10 +249,9 @@ } else if(strcmp(parg,"copy")==0) { - NEED_PARAMS(2,2); - - NEED_MOUNT(); - + NEED_PARAMS(2,2) + + NEED_MOUNT(); // Arg 1: src path & filename // Arg 2: new path & filename @@ -286,8 +285,7 @@ { NEED_PARAMS(1,1); - NEED_MOUNT(); - + NEED_MOUNT(); // Arg 1: folder path f_mkdir(argv[1]); } @@ -295,8 +293,7 @@ { NEED_PARAMS(1,1); - NEED_MOUNT(); - + NEED_MOUNT(); // Arg 1: file/folder path (cannot delete non-empty folders) f_unlink(argv[1]); }
9 years, 3 months
1
0
0
0
[dquintana] 69063: [FATTEN] Introduce a tool I wrote some years ago, that helps create and manage a FAT disk image from the command-line. It is built using parts of the isofs embedded library, with...
by dquintana@svn.reactos.org
Author: dquintana Date: Sun Sep 6 17:21:22 2015 New Revision: 69063 URL:
http://svn.reactos.org/svn/reactos?rev=69063&view=rev
Log: [FATTEN] Introduce a tool I wrote some years ago, that helps create and manage a FAT disk image from the command-line. It is built using parts of the isofs embedded library, with win32 bindings for file access. Should be helpful in order to create the EFI boot images needed for EFI-bootable isos. Because the code is not really portable (yet), it's currently not included in the build process. Added: trunk/reactos/tools/fatten/ trunk/reactos/tools/fatten/CMakeLists.txt (with props) trunk/reactos/tools/fatten/FAT.h (with props) trunk/reactos/tools/fatten/fatfs/ trunk/reactos/tools/fatten/fatfs/00readme.txt (with props) trunk/reactos/tools/fatten/fatfs/diskio.c (with props) trunk/reactos/tools/fatten/fatfs/diskio.h (with props) trunk/reactos/tools/fatten/fatfs/ff.c (with props) trunk/reactos/tools/fatten/fatfs/ff.h (with props) trunk/reactos/tools/fatten/fatfs/ffconf.h (with props) trunk/reactos/tools/fatten/fatfs/integer.h (with props) trunk/reactos/tools/fatten/fatfs/option/ trunk/reactos/tools/fatten/fatfs/option/ccsbcs.c (with props) trunk/reactos/tools/fatten/fatfs/option/syscall.c (with props) trunk/reactos/tools/fatten/fatten.c (with props) Modified: trunk/reactos/tools/CMakeLists.txt [This mail would be too long, it was shortened to contain the URLs only.] Modified: trunk/reactos/tools/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/CMakeLists.txt?rev=6…
Added: trunk/reactos/tools/fatten/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/CMakeLists.tx…
Added: trunk/reactos/tools/fatten/FAT.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/FAT.h?rev=690…
Added: trunk/reactos/tools/fatten/fatfs/00readme.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/00readm…
Added: trunk/reactos/tools/fatten/fatfs/diskio.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.…
Added: trunk/reactos/tools/fatten/fatfs/diskio.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.…
Added: trunk/reactos/tools/fatten/fatfs/ff.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/ff.c?re…
Added: trunk/reactos/tools/fatten/fatfs/ff.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/ff.h?re…
Added: trunk/reactos/tools/fatten/fatfs/ffconf.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/ffconf.…
Added: trunk/reactos/tools/fatten/fatfs/integer.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/integer…
Added: trunk/reactos/tools/fatten/fatfs/option/ccsbcs.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/option/…
Added: trunk/reactos/tools/fatten/fatfs/option/syscall.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/option/…
Added: trunk/reactos/tools/fatten/fatten.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatten.c?rev=…
9 years, 3 months
1
0
0
0
[hbelusca] 69062: [MSCONFIG_NEW] - Convert msconfig to a fully property-sheet-oriented app. - Start converting the general page to a property page (serves as a model for the other pages). - Sync tr...
by hbelusca@svn.reactos.org
Author: hbelusca Date: Sun Sep 6 17:19:40 2015 New Revision: 69062 URL:
http://svn.reactos.org/svn/reactos?rev=69062&view=rev
Log: [MSCONFIG_NEW] - Convert msconfig to a fully property-sheet-oriented app. - Start converting the general page to a property page (serves as a model for the other pages). - Sync translations for the general page. - Temporarily remove the other pages from compilation. Modified: trunk/reactos/base/applications/msconfig_new/CMakeLists.txt trunk/reactos/base/applications/msconfig_new/generalpage.c trunk/reactos/base/applications/msconfig_new/lang/bg-BG.rc trunk/reactos/base/applications/msconfig_new/lang/ca-ES.rc trunk/reactos/base/applications/msconfig_new/lang/cs-CZ.rc trunk/reactos/base/applications/msconfig_new/lang/de-DE.rc trunk/reactos/base/applications/msconfig_new/lang/el-GR.rc trunk/reactos/base/applications/msconfig_new/lang/en-US.rc trunk/reactos/base/applications/msconfig_new/lang/es-ES.rc trunk/reactos/base/applications/msconfig_new/lang/fr-FR.rc trunk/reactos/base/applications/msconfig_new/lang/he-IL.rc trunk/reactos/base/applications/msconfig_new/lang/hu-HU.rc trunk/reactos/base/applications/msconfig_new/lang/id-ID.rc trunk/reactos/base/applications/msconfig_new/lang/it-IT.rc trunk/reactos/base/applications/msconfig_new/lang/ko-KR.rc trunk/reactos/base/applications/msconfig_new/lang/nl-NL.rc trunk/reactos/base/applications/msconfig_new/lang/no-NO.rc trunk/reactos/base/applications/msconfig_new/lang/pl-PL.rc trunk/reactos/base/applications/msconfig_new/lang/pt-BR.rc trunk/reactos/base/applications/msconfig_new/lang/ro-RO.rc trunk/reactos/base/applications/msconfig_new/lang/ru-RU.rc trunk/reactos/base/applications/msconfig_new/lang/sk-SK.rc trunk/reactos/base/applications/msconfig_new/lang/sq-AL.rc trunk/reactos/base/applications/msconfig_new/lang/sv-SE.rc trunk/reactos/base/applications/msconfig_new/lang/th-TH.rc trunk/reactos/base/applications/msconfig_new/lang/tr-TR.rc trunk/reactos/base/applications/msconfig_new/lang/uk-UA.rc trunk/reactos/base/applications/msconfig_new/lang/zh-CN.rc trunk/reactos/base/applications/msconfig_new/lang/zh-TW.rc trunk/reactos/base/applications/msconfig_new/msconfig.c trunk/reactos/base/applications/msconfig_new/msconfig.h trunk/reactos/base/applications/msconfig_new/msconfig.rc trunk/reactos/base/applications/msconfig_new/precomp.h trunk/reactos/base/applications/msconfig_new/resource.h trunk/reactos/base/applications/msconfig_new/utils.c trunk/reactos/base/applications/msconfig_new/utils.h [This mail would be too long, it was shortened to contain the URLs only.] Modified: trunk/reactos/base/applications/msconfig_new/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/generalpage.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/bg-BG.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/ca-ES.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/cs-CZ.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/de-DE.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/el-GR.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/en-US.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/es-ES.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/fr-FR.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/he-IL.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/hu-HU.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/id-ID.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/it-IT.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/ko-KR.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/nl-NL.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/no-NO.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/pl-PL.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/pt-BR.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/ro-RO.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/ru-RU.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/sk-SK.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/sq-AL.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/sv-SE.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/th-TH.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/tr-TR.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/uk-UA.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/zh-CN.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/lang/zh-TW.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/msconfig.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/msconfig.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/msconfig.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/resource.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/utils.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
Modified: trunk/reactos/base/applications/msconfig_new/utils.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/msconfig…
9 years, 3 months
1
0
0
0
[tfaber] 69061: [NTOS:PNP] - Handle power IRPs for the PNP root device CORE-10117
by tfaber@svn.reactos.org
Author: tfaber Date: Sun Sep 6 17:13:48 2015 New Revision: 69061 URL:
http://svn.reactos.org/svn/reactos?rev=69061&view=rev
Log: [NTOS:PNP] - Handle power IRPs for the PNP root device CORE-10117 Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnproot…
============================================================================== --- trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c [iso-8859-1] Sun Sep 6 17:13:48 2015 @@ -1234,6 +1234,51 @@ return Status; } +/* + * FUNCTION: Handle Power IRPs + * ARGUMENTS: + * DeviceObject = Pointer to PDO or FDO + * Irp = Pointer to IRP that should be handled + * RETURNS: + * Status + */ +static NTSTATUS NTAPI +PnpRootPowerControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) +{ + PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension; + PIO_STACK_LOCATION IrpSp; + NTSTATUS Status; + + DeviceExtension = DeviceObject->DeviceExtension; + Status = Irp->IoStatus.Status; + IrpSp = IoGetCurrentIrpStackLocation(Irp); + + if (DeviceExtension->Common.IsFDO) + { + ASSERT(!DeviceExtension->Common.IsFDO); + PoStartNextPowerIrp(Irp); + IoCopyCurrentIrpStackLocationToNext(Irp); + Status = PoCallDriver(DeviceExtension->Ldo, Irp); + } + else + { + switch (IrpSp->MinorFunction) + { + case IRP_MN_QUERY_POWER: + case IRP_MN_SET_POWER: + Status = STATUS_SUCCESS; + break; + } + Irp->IoStatus.Status = Status; + PoStartNextPowerIrp(Irp); + IoCompleteRequest(Irp, IO_NO_INCREMENT); + } + + return Status; +} + NTSTATUS NTAPI PnpRootAddDevice( @@ -1305,7 +1350,7 @@ DriverObject->DriverExtension->AddDevice = PnpRootAddDevice; DriverObject->MajorFunction[IRP_MJ_PNP] = PnpRootPnpControl; - //DriverObject->MajorFunction[IRP_MJ_POWER] = PnpRootPowerControl; + DriverObject->MajorFunction[IRP_MJ_POWER] = PnpRootPowerControl; return STATUS_SUCCESS; }
9 years, 3 months
1
0
0
0
← Newer
1
...
33
34
35
36
37
38
39
...
54
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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Results per page:
10
25
50
100
200