示例#1
0
文件: blocklist.c 项目: GYGit/reactos
BOOLEAN CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive)
{
    PCACHE_BLOCK    CacheBlockToFree;

    TRACE("CacheInternalFreeBlock()\n");

    // Get a pointer to the last item in the block list
    // that isn't forced to be in the cache and remove
    // it from the list
    CacheBlockToFree = CONTAINING_RECORD(CacheDrive->CacheBlockHead.Blink, CACHE_BLOCK, ListEntry);
    while (&CacheBlockToFree->ListEntry != &CacheDrive->CacheBlockHead && CacheBlockToFree->LockedInCache)
    {
        CacheBlockToFree = CONTAINING_RECORD(CacheBlockToFree->ListEntry.Blink, CACHE_BLOCK, ListEntry);
    }

    // No blocks left in cache that can be freed
    // so just return
    if (IsListEmpty(&CacheDrive->CacheBlockHead))
    {
        return FALSE;
    }

    RemoveEntryList(&CacheBlockToFree->ListEntry);

    // Free the block memory and the block structure
    FrLdrTempFree(CacheBlockToFree->BlockData, TAG_CACHE_DATA);
    FrLdrTempFree(CacheBlockToFree, TAG_CACHE_BLOCK);

    // Update the cache data
    CacheBlockCount--;
    CacheSizeCurrent = CacheBlockCount * (CacheDrive->BlockSize * CacheDrive->BytesPerSector);

    return TRUE;
}
示例#2
0
文件: inffile.c 项目: RPG-7/reactos
static
PINFCACHELINE
InfpCacheFreeLine(
    PINFCACHELINE Line)
{
    PINFCACHELINE Next;
    PINFCACHEFIELD Field;

    if (Line == NULL)
    {
        return NULL;
    }

    Next = Line->Next;
    if (Line->Key != NULL)
    {
        FrLdrTempFree(Line->Key, TAG_INF_KEY);
        Line->Key = NULL;
    }

    /* Remove data fields */
    while (Line->FirstField != NULL)
    {
        Field = Line->FirstField->Next;
        FrLdrTempFree(Line->FirstField, TAG_INF_FIELD);
        Line->FirstField = Field;
    }
    Line->LastField = NULL;

    FrLdrTempFree(Line, TAG_INF_LINE);

    return Next;
}
示例#3
0
文件: blocklist.c 项目: GYGit/reactos
PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNumber)
{
    PCACHE_BLOCK    CacheBlock = NULL;

    TRACE("CacheInternalAddBlockToCache() BlockNumber = %d\n", BlockNumber);

    // Check the size of the cache so we don't exceed our limits
    CacheInternalCheckCacheSizeLimits(CacheDrive);

    // We will need to add the block to the
    // drive's list of cached blocks. So allocate
    // the block memory.
    CacheBlock = FrLdrTempAlloc(sizeof(CACHE_BLOCK), TAG_CACHE_BLOCK);
    if (CacheBlock == NULL)
    {
        return NULL;
    }

    // Now initialize the structure and
    // allocate room for the block data
    RtlZeroMemory(CacheBlock, sizeof(CACHE_BLOCK));
    CacheBlock->BlockNumber = BlockNumber;
    CacheBlock->BlockData = FrLdrTempAlloc(CacheDrive->BlockSize * CacheDrive->BytesPerSector,
                                           TAG_CACHE_DATA);
    if (CacheBlock->BlockData ==NULL)
    {
        FrLdrTempFree(CacheBlock, TAG_CACHE_BLOCK);
        return NULL;
    }

    // Now try to read in the block
    if (!MachDiskReadLogicalSectors(CacheDrive->DriveNumber, (BlockNumber * CacheDrive->BlockSize), CacheDrive->BlockSize, DiskReadBuffer))
    {
        FrLdrTempFree(CacheBlock->BlockData, TAG_CACHE_DATA);
        FrLdrTempFree(CacheBlock, TAG_CACHE_BLOCK);
        return NULL;
    }
    RtlCopyMemory(CacheBlock->BlockData, DiskReadBuffer, CacheDrive->BlockSize * CacheDrive->BytesPerSector);

    // Add it to our list of blocks managed by the cache
    InsertTailList(&CacheDrive->CacheBlockHead, &CacheBlock->ListEntry);

    // Update the cache data
    CacheBlockCount++;
    CacheSizeCurrent = CacheBlockCount * (CacheDrive->BlockSize * CacheDrive->BytesPerSector);

    CacheInternalDumpBlockList(CacheDrive);

    return CacheBlock;
}
示例#4
0
文件: ui.c 项目: GYGit/reactos
VOID UiShowMessageBoxesInSection(PCSTR SectionName)
{
    ULONG    Idx;
    CHAR    SettingName[80];
    CHAR    SettingValue[80];
    PCHAR    MessageBoxText;
    ULONG        MessageBoxTextSize;
    ULONG_PTR    SectionId;

    if (!IniOpenSection(SectionName, &SectionId))
    {
        return;
    }

    //
    // Find all the message box settings and run them
    //
    for (Idx=0; Idx<IniGetNumSectionItems(SectionId); Idx++)
    {
        IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue));

        if (_stricmp(SettingName, "MessageBox") == 0)
        {
            // Get the real length of the MessageBox text
            MessageBoxTextSize = IniGetSectionSettingValueSize(SectionId, Idx);

            //if (MessageBoxTextSize > 0)
            {
                // Allocate enough memory to hold the text
                MessageBoxText = FrLdrTempAlloc(MessageBoxTextSize, TAG_UI_TEXT);

                if (MessageBoxText)
                {
                    // Get the MessageBox text
                    IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), MessageBoxText, MessageBoxTextSize);

                    // Fix it up
                    UiEscapeString(MessageBoxText);

                    // Display it
                    UiMessageBox(MessageBoxText);

                    // Free the memory
                    FrLdrTempFree(MessageBoxText, TAG_UI_TEXT);
                }
            }
        }
    }
}
示例#5
0
文件: pxe.c 项目: ariscop/reactos
static ARC_STATUS PxeClose(ULONG FileId)
{
    t_PXENV_TFTP_CLOSE closeData;

    if (_OpenFile == NO_FILE || FileId != _OpenFile)
        return EBADF;

    RtlZeroMemory(&closeData, sizeof(closeData));
    if (!CallPxe(PXENV_TFTP_CLOSE, &closeData))
        return EIO;

    _OpenFile = NO_FILE;
    if (_CachedFile)
    {
        FrLdrTempFree(_CachedFile, TAG_PXE_FILE);
        _CachedFile = NULL;
    }
    return ESUCCESS;
}
示例#6
0
文件: inffile.c 项目: RPG-7/reactos
VOID
InfCloseFile(HINF InfHandle)
{
    PINFCACHE Cache;

    Cache = (PINFCACHE)InfHandle;

    if (Cache == NULL)
    {
        return;
    }

    while (Cache->FirstSection != NULL)
    {
        Cache->FirstSection = InfpCacheFreeSection(Cache->FirstSection);
    }
    Cache->LastSection = NULL;

    FrLdrTempFree(Cache, TAG_INF_CACHE);
}
示例#7
0
文件: inffile.c 项目: RPG-7/reactos
static
PINFCACHESECTION
InfpCacheFreeSection(
    PINFCACHESECTION Section)
{
    PINFCACHESECTION Next;

    if (Section == NULL)
    {
        return NULL;
    }

    /* Release all keys */
    Next = Section->Next;
    while (Section->FirstLine != NULL)
    {
        Section->FirstLine = InfpCacheFreeLine(Section->FirstLine);
    }
    Section->LastLine = NULL;

    FrLdrTempFree(Section, TAG_INF_SECTION);

    return Next;
}
示例#8
0
BOOLEAN CacheInitializeDrive(UCHAR DriveNumber)
{
    PCACHE_BLOCK    NextCacheBlock;
    GEOMETRY    DriveGeometry;

    // If we already have a cache for this drive then
    // by all means lets keep it, unless it is a removable
    // drive, in which case we'll invalidate the cache
    if ((CacheManagerInitialized == TRUE) &&
        (DriveNumber == CacheManagerDrive.DriveNumber) &&
        (DriveNumber >= 0x80) &&
        (CacheManagerDataInvalid != TRUE))
    {
        return TRUE;
    }

    CacheManagerDataInvalid = FALSE;

    //
    // If we have already been initialized then free
    // the old data
    //
    if (CacheManagerInitialized)
    {
        CacheManagerInitialized = FALSE;

        TRACE("CacheBlockCount: %d\n", CacheBlockCount);
        TRACE("CacheSizeLimit: %d\n", CacheSizeLimit);
        TRACE("CacheSizeCurrent: %d\n", CacheSizeCurrent);
        //
        // Loop through and free the cache blocks
        //
        while (!IsListEmpty(&CacheManagerDrive.CacheBlockHead))
        {
            NextCacheBlock = CONTAINING_RECORD(RemoveHeadList(&CacheManagerDrive.CacheBlockHead),
                                               CACHE_BLOCK,
                                               ListEntry);

            FrLdrTempFree(NextCacheBlock->BlockData, TAG_CACHE_DATA);
            FrLdrTempFree(NextCacheBlock, TAG_CACHE_BLOCK);
        }
    }

    // Initialize the structure
    RtlZeroMemory(&CacheManagerDrive, sizeof(CACHE_DRIVE));
    InitializeListHead(&CacheManagerDrive.CacheBlockHead);
    CacheManagerDrive.DriveNumber = DriveNumber;
    if (!MachDiskGetDriveGeometry(DriveNumber, &DriveGeometry))
    {
        return FALSE;
    }
    CacheManagerDrive.BytesPerSector = DriveGeometry.BytesPerSector;

    // Get the number of sectors in each cache block
    CacheManagerDrive.BlockSize = MachDiskGetCacheableBlockCount(DriveNumber);

    CacheBlockCount = 0;
    CacheSizeLimit = TotalPagesInLookupTable / 8 * MM_PAGE_SIZE;
    CacheSizeCurrent = 0;
    if (CacheSizeLimit > TEMP_HEAP_SIZE - (128 * 1024))
    {
        CacheSizeLimit = TEMP_HEAP_SIZE - (128 * 1024);
    }

    CacheManagerInitialized = TRUE;

    TRACE("Initializing BIOS drive 0x%x.\n", DriveNumber);
    TRACE("BytesPerSector: %d.\n", CacheManagerDrive.BytesPerSector);
    TRACE("BlockSize: %d.\n", CacheManagerDrive.BlockSize);
    TRACE("CacheSizeLimit: %d.\n", CacheSizeLimit);

    return TRUE;
}
示例#9
0
文件: pxe.c 项目: ariscop/reactos
static ARC_STATUS PxeOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
{
    t_PXENV_TFTP_GET_FSIZE sizeData;
    t_PXENV_TFTP_OPEN openData;
    SIZE_T PathLen, i;

    if (_OpenFile != NO_FILE)
        return EIO;
    if (OpenMode != OpenReadOnly)
        return EACCES;

    /* Retrieve the path length without NULL terminator */
    PathLen = (Path ? min(strlen(Path), sizeof(_OpenFileName) - 1) : 0);

    /* Lowercase the path and always use slashes as separators */
    for (i = 0; i < PathLen; i++)
    {
        if (Path[i] == '\\')
            _OpenFileName[i] = '/';
        else
            _OpenFileName[i] = tolower(Path[i]);
    }

    /* Zero out rest of the file name */
    RtlZeroMemory(_OpenFileName + PathLen, sizeof(_OpenFileName) - PathLen);

    RtlZeroMemory(&sizeData, sizeof(sizeData));
    sizeData.ServerIPAddress = _ServerIP;
    RtlCopyMemory(sizeData.FileName, _OpenFileName, sizeof(_OpenFileName));
    if (!CallPxe(PXENV_TFTP_GET_FSIZE, &sizeData))
    {
        ERR("Failed to get '%s' size\n", Path);
        return EIO;
    }

    _FileSize = sizeData.FileSize;
    if (_FileSize < 1024 * 1024)
    {
        _CachedFile = FrLdrTempAlloc(_FileSize, TAG_PXE_FILE);
        // Don't check for allocation failure, we support _CachedFile == NULL
    }
    _CachedLength = 0;

    RtlZeroMemory(&openData, sizeof(openData));
    openData.ServerIPAddress = _ServerIP;
    RtlCopyMemory(openData.FileName, _OpenFileName, sizeof(_OpenFileName));
    openData.PacketSize = sizeof(_Packet);

    if (!CallPxe(PXENV_TFTP_OPEN, &openData))
    {
        if (_CachedFile)
        {
            FrLdrTempFree(_CachedFile, TAG_PXE_FILE);
            _CachedFile = NULL;
        }
        return ENOENT;
    }

    _FilePosition = 0;
    _PacketPosition = 0;

    _OpenFile = *FileId;
    return ESUCCESS;
}
示例#10
0
文件: inffile.c 项目: RPG-7/reactos
BOOLEAN
InfOpenFile(
    PHINF InfHandle,
    PCSTR FileName,
    PULONG ErrorLine)
{
    FILEINFORMATION Information;
    ULONG FileId;
    PCHAR FileBuffer;
    ULONG FileSize, Count;
    PINFCACHE Cache;
    BOOLEAN Success;
    ARC_STATUS Status;

    *InfHandle = NULL;
    *ErrorLine = (ULONG) - 1;

    //
    // Open the .inf file
    //
    Status = ArcOpen((PCHAR)FileName, OpenReadOnly, &FileId);
    if (Status != ESUCCESS)
    {
        return FALSE;
    }

    //
    // Query file size
    //
    Status = ArcGetFileInformation(FileId, &Information);
    if ((Status != ESUCCESS) || (Information.EndingAddress.HighPart != 0))
    {
        ArcClose(FileId);
        return FALSE;
    }
    FileSize = Information.EndingAddress.LowPart;

    //
    // Allocate buffer to cache the file
    //
    FileBuffer = FrLdrTempAlloc(FileSize + 1, TAG_INF_FILE);
    if (!FileBuffer)
    {
        ArcClose(FileId);
        return FALSE;
    }

    //
    // Read file into memory
    //
    Status = ArcRead(FileId, FileBuffer, FileSize, &Count);
    if ((Status != ESUCCESS) || (Count != FileSize))
    {
        ArcClose(FileId);
        FrLdrTempFree(FileBuffer, TAG_INF_FILE);
        return FALSE;
    }

    //
    // We don't need the file anymore. Close it
    //
    ArcClose(FileId);

    //
    // Append string terminator
    //
    FileBuffer[FileSize] = 0;

    //
    // Allocate infcache header
    //
    Cache = (PINFCACHE)FrLdrTempAlloc(sizeof(INFCACHE), TAG_INF_CACHE);
    if (!Cache)
    {
        FrLdrTempFree(FileBuffer, TAG_INF_FILE);
        return FALSE;
    }

    //
    // Initialize inicache header
    //
    RtlZeroMemory(Cache, sizeof(INFCACHE));

    //
    // Parse the inf buffer
    //
    Success = InfpParseBuffer(Cache,
                              FileBuffer,
                              FileBuffer + FileSize,
                              ErrorLine);
    if (!Success)
    {
        FrLdrTempFree(Cache, TAG_INF_CACHE);
        Cache = NULL;
    }

    //
    // Free file buffer, as it has been parsed
    //
    FrLdrTempFree(FileBuffer, TAG_INF_FILE);

    //
    // Return .inf parsed contents
    //
    *InfHandle = (HINF)Cache;

    return Success;
}
示例#11
0
文件: binhive.c 项目: rmallof/reactos
static
BOOLEAN
RegImportValue (
    PHHIVE Hive,
    PCM_KEY_VALUE ValueCell,
    FRLDRHKEY Key)
{
    PVOID DataCell;
    PWCHAR wName;
    LONG Error;
    ULONG DataLength;
    ULONG i;

    if (ValueCell->Signature != CM_KEY_VALUE_SIGNATURE)
    {
        ERR("Invalid key cell!\n");
        return FALSE;
    }

    if (ValueCell->Flags & VALUE_COMP_NAME)
    {
        wName = FrLdrTempAlloc((ValueCell->NameLength + 1) * sizeof(WCHAR), TAG_REG_NAME);
        for (i = 0; i < ValueCell->NameLength; i++)
        {
            wName[i] = ((PCHAR)ValueCell->Name)[i];
        }
        wName[ValueCell->NameLength] = 0;
    }
    else
    {
        wName = FrLdrTempAlloc(ValueCell->NameLength + sizeof(WCHAR), TAG_REG_NAME);
        memcpy(wName, ValueCell->Name, ValueCell->NameLength);
        wName[ValueCell->NameLength / sizeof(WCHAR)] = 0;
    }

    DataLength = ValueCell->DataLength & REG_DATA_SIZE_MASK;

    TRACE("ValueName: '%S'\n", wName);
    TRACE("DataLength: %u\n", DataLength);

    if (DataLength <= sizeof(HCELL_INDEX) && (ValueCell->DataLength & REG_DATA_IN_OFFSET))
    {
        Error = RegSetValue(Key,
                            wName,
                            ValueCell->Type,
                            (PCHAR)&ValueCell->Data,
                            DataLength);
        if (Error != ERROR_SUCCESS)
        {
            ERR("RegSetValue() failed!\n");
            FrLdrTempFree(wName, TAG_REG_NAME);
            return FALSE;
        }
    }
    else
    {
        DataCell = (PVOID)HvGetCell(Hive, ValueCell->Data);
        TRACE("DataCell: %x\n", DataCell);

        Error = RegSetValue(Key,
                            wName,
                            ValueCell->Type,
                            DataCell,
                            DataLength);

        if (Error != ERROR_SUCCESS)
        {
            ERR("RegSetValue() failed!\n");
            FrLdrTempFree(wName, TAG_REG_NAME);
            return FALSE;
        }
    }

    FrLdrTempFree(wName, TAG_REG_NAME);

    return TRUE;
}
示例#12
0
文件: binhive.c 项目: rmallof/reactos
static
BOOLEAN
RegImportSubKey(
    PHHIVE Hive,
    PCM_KEY_NODE KeyCell,
    FRLDRHKEY ParentKey)
{
    PCM_KEY_INDEX IndexCell;
    PVALUE_LIST_CELL ValueListCell;
    PCM_KEY_VALUE ValueCell = NULL;
    PWCHAR wName;
    FRLDRHKEY SubKey;
    LONG Error;
    ULONG i;

    TRACE("KeyCell: %x\n", KeyCell);
    TRACE("KeyCell->Signature: %x\n", KeyCell->Signature);
    if (KeyCell->Signature != CM_KEY_NODE_SIGNATURE)
    {
        ERR("Invalid key cell Signature!\n");
        return FALSE;
    }

    if (KeyCell->Flags & KEY_COMP_NAME)
    {
        wName = FrLdrTempAlloc((KeyCell->NameLength + 1) * sizeof(WCHAR), TAG_REG_NAME);
        for (i = 0; i < KeyCell->NameLength; i++)
        {
            wName[i] = ((PCHAR)KeyCell->Name)[i];
        }
        wName[KeyCell->NameLength] = 0;
    }
    else
    {
        wName = FrLdrTempAlloc(KeyCell->NameLength + sizeof(WCHAR), TAG_REG_NAME);
        memcpy(wName, KeyCell->Name, KeyCell->NameLength);
        wName[KeyCell->NameLength / sizeof(WCHAR)] = 0;
    }

    TRACE("KeyName: '%S'\n", wName);

    /* Create new sub key */
    Error = RegCreateKey(ParentKey, wName, &SubKey);
    FrLdrTempFree(wName, TAG_REG_NAME);
    if (Error != ERROR_SUCCESS)
    {
        ERR("RegCreateKey() failed!\n");
        return FALSE;
    }
    TRACE("Subkeys: %u\n", KeyCell->SubKeyCounts);
    TRACE("Values: %u\n", KeyCell->ValueList.Count);

    /* Enumerate and add values */
    if (KeyCell->ValueList.Count > 0)
    {
        ValueListCell = (PVALUE_LIST_CELL)HvGetCell(Hive, KeyCell->ValueList.List);
        TRACE("ValueListCell: %x\n", ValueListCell);

        for (i = 0; i < KeyCell->ValueList.Count; i++)
        {
            TRACE("ValueOffset[%d]: %x\n", i, ValueListCell->ValueOffset[i]);

            ValueCell = (PCM_KEY_VALUE) HvGetCell (Hive, ValueListCell->ValueOffset[i]);

            TRACE("ValueCell[%d]: %x\n", i, ValueCell);

            if (!RegImportValue(Hive, ValueCell, SubKey))
                return FALSE;
        }
    }

    /* Enumerate and add subkeys */
    if (KeyCell->SubKeyCounts[Stable] > 0)
    {
        IndexCell = HvGetCell (Hive, KeyCell->SubKeyLists[Stable]);

        if (!RegImportIndexSubKey(Hive, IndexCell, SubKey))
            return FALSE;
    }

    return TRUE;
}