void * cdecl malloc(size_t tSize) #endif { USHORT usSel; void * pRet; /* CheckHeap();*/ GetMemAccess(); if (tSize % 2) tSize++; if( tSize > 0 ) { for (usSel = 0; usSel < MAX_SELECTORS; usSel++) { if (rgpSegment[usSel] && rgpSegment[usSel] != RESERVED_SEGMENT) { pRet = FindFreeSpace(rgpSegment[usSel], tSize); if (pRet) goto malloc_exit; } } for (usSel = 0; usSel < MAX_SELECTORS; usSel++) { if (!rgpSegment[usSel]) { rgpSegment[usSel] = RESERVED_SEGMENT; rgpSegment[usSel] = gdtAlloc(HEAP_SIZE, TRUE); if (!rgpSegment[usSel]) { CritMessage("FAT32: No gdtSelector for heap!"); pRet = NULL; goto malloc_exit; } SetBlockSize(rgpSegment[usSel], HEAP_SIZE - sizeof (ULONG)); SetFree(rgpSegment[usSel]); pRet = FindFreeSpace(rgpSegment[usSel], tSize); if (pRet) goto malloc_exit; } } } if (f32Parms.fMessageActive & LOG_MEM) Message("Malloc failed, calling gdtAlloc"); pRet = gdtAlloc(tSize ? ( ULONG )tSize : 65536L, TRUE); malloc_exit: if (f32Parms.fMessageActive & LOG_MEM) Message("malloc %lu bytes at %lX", tSize ? ( ULONG )tSize : 65536L, pRet); ReleaseMemAccess(); return pRet; }
/********************************************************************* * Malloc *********************************************************************/ void * cdecl Malloc(size_t tSize) { USHORT usSel; void * pRet; if (tSize % 2) tSize++; for (usSel = 0; usSel < MAX_SELECTORS; usSel++) { if (rgpSegment[usSel]) { pRet = FindFreeSpace(rgpSegment[usSel], tSize); if (pRet) goto Malloc_exit; } } for (usSel = 0; usSel < MAX_SELECTORS; usSel++) { if (!rgpSegment[usSel]) { rgpSegment[usSel] = gdtAlloc(HEAP_SIZE, TRUE); if (!rgpSegment[usSel]) { errmsg("FAT32: No gdtSelector for heap!"); return NULL; } SetBlockSize(rgpSegment[usSel], HEAP_SIZE - sizeof (ULONG)); SetFree(rgpSegment[usSel]); pRet = FindFreeSpace(rgpSegment[usSel], tSize); if (pRet) goto Malloc_exit; } } pRet = NULL; Malloc_exit: if (pRet) ulMem += tSize; sprintf(szLast, "malloc %u bytes %p", tSize, pRet); printf("%s\n", szLast); return pRet; }
void StartupLogFreeRamAndStorage() { unsigned long freeram = CheckFreeRam()/1024; TCHAR buffer[MAX_PATH]; LocalPath(buffer); unsigned long freestorage = FindFreeSpace(buffer); StartupStore(TEXT(". Free ram=%ld K storage=%ld K%s"), freeram,freestorage,NEWLINE); }
bool IGCFileCleanup(unsigned current_year) { const auto pathname = GetPrimaryDataPath(); int numtries = 0; do { // Find out how much space is available unsigned long kbfree = FindFreeSpace(pathname.c_str()); if (kbfree >= LOGGER_MINFREESTORAGE) { // if enough space is available we return happily return true; } // if we don't have enough space yet we try to delete old IGC files if (!DeleteOldestIGCFile(current_year, pathname)) break; // but only 100 times numtries++; } while (numtries < 100); // if we get to this point we don't have any IGC files left or deleted // 100 old IGC files already return false; }
void StartupLogFreeRamAndStorage() { int freeram = SystemFreeRAM() / 1024; int freestorage = FindFreeSpace(GetPrimaryDataPath()); LogStartUp(_T("Free ram %d; free storage %d"), freeram, freestorage); }
void StartupLogFreeRamAndStorage() { size_t freeram = CheckFreeRam()/1024; TCHAR buffer[MAX_PATH]; LocalPath(buffer); size_t freestorage = FindFreeSpace(buffer); StartupStore(TEXT(". Free ram=%u K storage=%u K") NEWLINE, (unsigned int)freeram,(unsigned int)freestorage); }
void StartupLogFreeRamAndStorage() { #ifdef HAVE_MEM_INFO unsigned long freeram = SystemFreeRAM() / 1024; LogFormat("Free ram %lu KB", freeram); #endif unsigned long freestorage = FindFreeSpace(GetPrimaryDataPath()); LogFormat("Free storage %lu KB", freestorage); }
bool LoggerImpl::LoggerClearFreeSpace(const NMEA_INFO &gps_info) { bool found = true; unsigned long kbfree=0; TCHAR pathname[MAX_PATH]; TCHAR subpathname[MAX_PATH]; int numtries = 0; LocalPath(pathname); #ifdef GNAV LocalPath(subpathname,TEXT("logs")); #else LocalPath(subpathname); #endif #ifdef DEBUG_IGCFILENAME bool retval; retval = LogFileIsOlder(testtext1, testtext2); retval = LogFileIsOlder(testtext1, testtext3); retval = LogFileIsOlder(testtext4, testtext5); retval = LogFileIsOlder(testtext6, testtext7); #endif while (found && ((kbfree = FindFreeSpace(pathname))<LOGGER_MINFREESTORAGE) && (numtries++ <100)) { /* JMW asking for deleting old files is disabled now --- system automatically deletes old files as required */ // search for IGC files, and delete the oldest one found = DeleteOldIGCFile(gps_info, pathname); if (!found) { found = DeleteOldIGCFile(gps_info, subpathname); } } if (kbfree>=LOGGER_MINFREESTORAGE) { StartupStore(TEXT("LoggerFreeSpace returned: true\r\n")); return true; } else { StartupStore(TEXT("LoggerFreeSpace returned: false\r\n")); return false; } }
bool LoggerClearFreeSpace(void) { bool found = true; unsigned long kbfree=0; TCHAR pathname[MAX_PATH+1]; TCHAR subpathname[MAX_PATH+1]; int numtries = 0; LocalPath(pathname); LocalPath(subpathname,TEXT(LKD_LOGS)); #ifdef DEBUG_IGCFILENAME bool retval; retval = LogFileIsOlder(testtext1, testtext2); retval = LogFileIsOlder(testtext1, testtext3); retval = LogFileIsOlder(testtext4, testtext5); retval = LogFileIsOlder(testtext6, testtext7); #endif while (found && ((kbfree = FindFreeSpace(pathname))<LOGGER_MINFREESTORAGE) && (numtries++ <100)) { /* JMW asking for deleting old files is disabled now --- system automatically deletes old files as required */ // search for IGC files, and delete the oldest one found = DeleteOldIGCFile(pathname); if (!found) { found = DeleteOldIGCFile(subpathname); } } if (kbfree>=LOGGER_MINFREESTORAGE) { #if TESTBENCH StartupStore(TEXT("... LoggerFreeSpace returned: true%s"),NEWLINE); #endif return true; } else { StartupStore(TEXT("--- LoggerFreeSpace returned: false%s"),NEWLINE); return false; } }
// Fill the queue. long CPegasusInputDevice::FillQueue(QUEUE* pQueue) { // Make sure we have a queue. if (pQueue->Start == NULL) { // Queue is not allocated. ASSERT(FALSE); return ERR_GET_BUFF_ERR; } // Make sure we have a device. if (m_pDevice == NULL) { // Device is not set ASSERT(FALSE); return ERR_GET_BUFF_ERR; } // Add data to the queue until full or we exhaust the source. long lFreeSpace; while ((lFreeSpace = FindFreeSpace(pQueue)) != 0) { DWORD dwSizeRead; if (m_pDevice->huge_read(pQueue->Rear, lFreeSpace, &dwSizeRead) != ERRORCODE_None) { // Some sort of non-EOF error. return ERR_BAD_READ; } // We read something (maybe zero bytes). pQueue->Rear += dwSizeRead; if ((long)dwSizeRead < lFreeSpace) { // Out of source data. pQueue->QFlags |= Q_EOF; break; } } return ERR_NONE; }
static void OnSplashPaint(WindowControl * Sender, HDC hDC){ TCHAR srcfile[MAX_PATH]; TCHAR fprefix[20]; if (RUN_MODE==RUN_SHUTDOWN) return; if (RUN_MODE==RUN_WELCOME) _tcscpy(fprefix,_T("LKSTART")); else _tcscpy(fprefix,_T("LKPROFILE")); LoadSplash(hDC,fprefix); if (RUN_MODE==RUN_WELCOME) { TCHAR mes[100]; int pos=0; switch (ScreenSize) { case ss800x480: pos=12; break; case ss400x240: pos=12; break; case ss480x272: if (ScreenSizeX==854) pos=14; else pos=11; break; case ss640x480: pos=12; break; case ss320x240: pos=12; break; case ss896x672: pos=14; break; // --------- portrait ------------- case ss240x320: pos=17; break; case ss480x640: pos=17; break; case ss272x480: pos=18; break; case ss240x400: pos=16; break; case ss480x800: pos=18; break; default: pos=11; break; } if (fullresetasked) { _stprintf(mes,_T("*** %s ***"),gettext(_T("_@M1757_"))); RawWrite(hDC,mes,pos,1, RGB_DARKWHITE,WTMODE_NORMAL); } else { #ifndef LKCOMPETITION _stprintf(mes,_T("Version %S.%S (%S)"),LKVERSION,LKRELEASE,__DATE__); #else _stprintf(mes,_T("V%S.%S COMPETITION"),LKVERSION,LKRELEASE,__DATE__); #endif RawWrite(hDC,mes,pos,1, RGB_DARKWHITE,WTMODE_NORMAL); } } if (RUN_MODE!=RUN_WELCOME) { // FillRect(hDC,&ScreenSizeR, LKBrush_Black); // REMOVE TCHAR mes[100]; #ifndef LKCOMPETITION _stprintf(mes,_T("%S v%S.%S - %s"),LKFORK,LKVERSION,LKRELEASE,gettext(_T("_@M2054_"))); #else _stprintf(mes,_T("%SC v%S.%S - %s"),LKFORK,LKVERSION,LKRELEASE,gettext(_T("_@M2054_"))); #endif RawWrite(hDC,mes,1,1, RGB_LIGHTGREY,WTMODE_NORMAL); unsigned long freeram = CheckFreeRam()/1024; TCHAR buffer[MAX_PATH]; LocalPath(buffer); unsigned long freestorage = FindFreeSpace(buffer); _stprintf(mes,_T("free ram %.1ldM storage %.1ldM"), freeram/1024,freestorage/1024); RawWrite(hDC,mes,3,0, RGB_LIGHTGREY,WTMODE_NORMAL); if ( ScreenSize != ss320x240 && ScreenLandscape ) RawWrite(hDC,_T("_______________________"),2,2, RGB_LIGHTGREY,WTMODE_NORMAL); if (fullresetasked) { _stprintf(mes,_T("%s"),gettext(_T("_@M1757_"))); // LK8000 PROFILES RESET RawWrite(hDC,mes,5,2, RGB_ICEWHITE, WTMODE_OUTLINED); _stprintf(mes,_T("%s"),gettext(_T("_@M1759_"))); // SELECTED IN SYSTEM RawWrite(hDC,mes,6,2, RGB_ICEWHITE, WTMODE_OUTLINED); } else { _stprintf(mes,_T("%s"),PilotName_Config); RawWrite(hDC,mes,4,2, RGB_ICEWHITE, WTMODE_OUTLINED); _stprintf(mes,_T("%s"),AircraftRego_Config); RawWrite(hDC,mes,5,2, RGB_AMBER, WTMODE_OUTLINED); _stprintf(mes,_T("%s"),AircraftType_Config); RawWrite(hDC,mes,6,2, RGB_AMBER, WTMODE_OUTLINED); LKASSERT(szPolarFile[0]); extern void LK_wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext); LK_wsplitpath(szPolarFile, (WCHAR*) NULL, (WCHAR*) NULL, srcfile, (WCHAR*) NULL); _stprintf(mes,_T("%s %s"),gettext(_T("_@M528_")),srcfile); // polar file RawWrite(hDC,mes,7,2, RGB_AMBER, WTMODE_OUTLINED); LKASSERT(startProfileFile[0]); LK_wsplitpath(startProfileFile, (WCHAR*) NULL, (WCHAR*) NULL, srcfile, (WCHAR*) NULL); _stprintf(mes,_T("%s: %s"),MsgToken(1746),srcfile); RawWrite(hDC,mes,11,1, RGB_ICEWHITE, WTMODE_NORMAL); } // RawWrite(hDC,_T("_______________________"),8,2, RGB_LIGHTGREY,WTMODE_NORMAL); // REMOVE FOR THE 3.0 return; } }
static void OnSplashPaint(WindowControl * Sender, LKSurface& Surface) { TCHAR srcfile[MAX_PATH]; if (RUN_MODE == RUN_SHUTDOWN) return; if(RUN_MODE == RUN_WELCOME) { if(!StartBitmap) { StartBitmap = LoadSplash(_T("LKSTART")); } if(StartBitmap) { DrawSplash(Surface, StartBitmap); } } else { if(!ProfileBitmap) { ProfileBitmap = LoadSplash(_T("LKPROFILE")); } if(ProfileBitmap) { DrawSplash(Surface, ProfileBitmap); } } if (RUN_MODE == RUN_WELCOME) { TCHAR mes[100]; int pos = 0; switch (ScreenSize) { case ss480x272: if (ScreenSizeX == 854) pos = 14; else #ifdef __linux__ pos = 12; #else pos = 11; #endif break; // --------- portrait ------------- case ss240x320: #ifdef __linux__ pos = 19; #else pos = 17; #endif break; default: // customized definition if (ScreenLandscape) { switch (ScreenGeometry) { case SCREEN_GEOMETRY_43: pos = 12; break; case SCREEN_GEOMETRY_53: pos = 12; break; case SCREEN_GEOMETRY_169: pos = 11; break; default: pos = 11; break; } } else { // Portrait // try to get a rule for text position... switch (ScreenGeometry) { case SCREEN_GEOMETRY_43: #ifdef __linux__ pos = 18; #else pos = 17; #endif break; case SCREEN_GEOMETRY_53: pos = 20; break; case SCREEN_GEOMETRY_169: #ifdef __linux__ pos = 22; #else pos = 20; #endif break; default: pos = 21; break; } } break; } if (FullResetAsked) { _stprintf(mes, _T("*** %s ***"), MsgToken(1757)); RawWrite(Surface, mes, pos, 1, RGBDARKWHITE, WTMODE_NORMAL); } else { #ifndef LKCOMPETITION _stprintf(mes, _T("Version %s.%s (%s)"), _T(LKVERSION), _T(LKRELEASE), _T(__DATE__)); #else _stprintf(mes, _T("V%s.%s (%s) COMPETITION"), _T(LKVERSION), _T(LKRELEASE), _T(__DATE__)); #endif RawWrite(Surface, mes, pos, 1, RGBDARKWHITE, WTMODE_NORMAL); #ifdef KOBO if(IsKoboOTGKernel()) { RawWrite(Surface, _T("- USB host kernel -"), pos+1, 1, RGBDARKWHITE, WTMODE_NORMAL); } #endif } } if (RUN_MODE != RUN_WELCOME) { // FillRect(hDC,&ScreenSizeR, LKBrush_Black); // REMOVE TCHAR mes[100]; #ifndef LKCOMPETITION _stprintf(mes, _T("%s v%s.%s - %s"), _T(LKFORK), _T(LKVERSION), _T(LKRELEASE), MsgToken(2054)); #else _stprintf(mes, _T("%sC v%s.%s - %s"), _T(LKFORK), _T(LKVERSION), _T(LKRELEASE), MsgToken(2054)); #endif #ifdef DITHER RawWrite(Surface, mes, 1, 1, RGBLIGHTGREY, WTMODE_OUTLINED); #else RawWrite(Surface, mes, 1, 1, RGBLIGHTGREY, WTMODE_NORMAL); #endif size_t freeram = CheckFreeRam() / 1024; TCHAR buffer[MAX_PATH]; LocalPath(buffer); size_t freestorage = FindFreeSpace(buffer); _stprintf(mes, _T("free ram %.1uM storage %.1uM"), (unsigned int) freeram / 1024, (unsigned int) freestorage / 1024); #ifdef DITHER RawWrite(Surface, mes, 3, 0, RGBLIGHTGREY, WTMODE_OUTLINED); #else RawWrite(Surface, mes, 3, 0, RGBLIGHTGREY, WTMODE_NORMAL); #endif if (ScreenSize != ss320x240 && ScreenLandscape) RawWrite(Surface, _T("_______________________"), 2, 2, RGBLIGHTGREY, WTMODE_NORMAL); if (FullResetAsked) { _stprintf(mes, _T("%s"), MsgToken(1757)); // LK8000 PROFILES RESET RawWrite(Surface, mes, 5, 2, RGBICEWHITE, WTMODE_OUTLINED); _stprintf(mes, _T("%s"), MsgToken(1759)); // SELECTED IN SYSTEM RawWrite(Surface, mes, 6, 2, RGBICEWHITE, WTMODE_OUTLINED); } else { _stprintf(mes, _T("%s"), PilotName_Config); RawWrite(Surface, mes, 4, 2, RGBICEWHITE, WTMODE_OUTLINED); _stprintf(mes, _T("%s"), AircraftRego_Config); RawWrite(Surface, mes, 5, 2, RGBAMBER, WTMODE_OUTLINED); _stprintf(mes, _T("%s"), AircraftType_Config); RawWrite(Surface, mes, 6, 2, RGBAMBER, WTMODE_OUTLINED); LKASSERT(szPolarFile[0]); extern void LK_tsplitpath(const TCHAR* path, TCHAR* drv, TCHAR* dir, TCHAR* name, TCHAR * ext); LK_tsplitpath(szPolarFile, (TCHAR*) NULL, (TCHAR*) NULL, srcfile, (TCHAR*) NULL); _stprintf(mes, _T("%s %s"), MsgToken(528), srcfile); // polar file RawWrite(Surface, mes, 7, 2, RGBAMBER, WTMODE_OUTLINED); LKASSERT(startProfileFile[0]); LK_tsplitpath(startProfileFile, (TCHAR*) NULL, (TCHAR*) NULL, srcfile, (TCHAR*) NULL); _stprintf(mes, _T("%s: %s"), MsgToken(1746), srcfile); RawWrite(Surface, mes, 11, 1, RGBICEWHITE, WTMODE_NORMAL); } // RawWrite(hDC,_T("_______________________"),8,2, RGB_LIGHTGREY,WTMODE_NORMAL); // REMOVE FOR THE 3.0 return; } }