// checks if a video dir is 'valid' bool cVideoDirectory::IsVidDirOK(int nVid, int *freeMB) { char *dn; int fMB; if (nVid >= Setup.nVidPrefer) return false; if (Setup.VidPreferSize[ nVid ] == -1) return false; dn = GetVidPath(nVid); if (dn == NULL) return false; fMB = FreeDiskSpaceMB(dn, NULL); if (freeMB != NULL) *freeMB = fMB; free(dn); if (Setup.VidPreferSize[ nVid ] >= fMB) return false; return true; }
bool cLiveRecorder::RunningLowOnDiskSpace(void) { if(!BufferDirectoryMinFree) return cRecorder::RunningLowOnDiskSpace(); if (time(NULL) > lastDiskSpaceCheck + DISKCHECKINTERVAL) { int Free = FreeDiskSpaceMB(fileName->Name()); lastDiskSpaceCheck = time(NULL); if (Free < BufferDirectoryMinFree) return true; } // if return false; } // cLiveRecorder::RunningLowOnDiskSpace
bool cFileWriter::RunningLowOnDiskSpace(void) { if (time(NULL) > lastDiskSpaceCheck + DISKCHECKINTERVAL) { int Free = FreeDiskSpaceMB(fileName->Name()); lastDiskSpaceCheck = time(NULL); if (Free < MINFREEDISKSPACE) { dsyslog("low disk space (%d MB, limit is %d MB)", Free, MINFREEDISKSPACE); return true; } } return false; }
int cVideoDirectory::FreeMB(int *UsedMB) { return FreeDiskSpaceMB(name ? name : VideoDirectory, UsedMB); }
// calculates which video dir to use bool cVideoDirectory::GetPreferedVideoDir(void) { cVideoDirectory d; int nDirs = 1, vidUse = Setup.nVidPrefer; int i, top, topFree, x; if (name == NULL) return(false); // count available video dirs while (d.Next() == true) nDirs++; if (vidUse > nDirs) vidUse = nDirs; // check for prefered video dir for (i = 0, top = -1, topFree = 0; i < vidUse; i++) { if (IsVidDirOK(i, &x) == true) { if (top == -1) { // nothing set yet, use first 'ok' dir top = i; topFree = x; } else { // check if we got a higher priority if (Setup.VidPreferPrio[ i ] >= Setup.VidPreferPrio[ top ]) { top = i; topFree = x; } // check if we got same priority but more space else if (Setup.VidPreferPrio[ i ] == Setup.VidPreferPrio[ top ] && x >= topFree) { top = i; topFree = x; } } } } if (top == -1) { isyslog("VidPrefer: no prefered video directory could be determined!"); // something went wrong here... // let VDR determine the video directory int MaxFree = FreeMB(); while (Next()) { int Free = FreeDiskSpaceMB(Name()); if (Free > MaxFree) { Store(); MaxFree = Free; } } } else { isyslog("VidPrefer: prefered video directory '%d' set.", top); if (stored != NULL) free(stored); stored = GetVidPath(top); } return true; }
cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags) { const char *ActualFileName = FileName; // Incoming name must be in base video directory: #ifdef USE_LIVEBUFFER if ((strstr(FileName, VideoDirectory ) != FileName) && (strstr(FileName, BufferDirectory) != FileName)) { #else if (strstr(FileName, VideoDirectory) != FileName) { #endif /*USE_LIVEBUFFER*/ esyslog("ERROR: %s not in %s", FileName, VideoDirectory); errno = ENOENT; // must set 'errno' - any ideas for a better value? return NULL; } // Are we going to create a new file? if ((Flags & O_CREAT) != 0) { cVideoDirectory Dir; if (Dir.IsDistributed()) { #ifdef USE_DVLVIDPREFER if (Setup.UseVidPrefer == 0) { #endif /* DVLVIDPREFER */ // Find the directory with the most free space: int MaxFree = Dir.FreeMB(); while (Dir.Next()) { int Free = FreeDiskSpaceMB(Dir.Name()); if (Free > MaxFree) { Dir.Store(); MaxFree = Free; } } #ifdef USE_DVLVIDPREFER } else Dir.GetPreferedVideoDir(); #endif /* DVLVIDPREFER */ if (Dir.Stored()) { ActualFileName = Dir.Adjust(FileName); if (!MakeDirs(ActualFileName, false)) return NULL; // errno has been set by MakeDirs() #ifdef USE_DVLVIDPREFER if (strcmp(ActualFileName, FileName) != 0) { #endif /* DVLVIDPREFER */ if (symlink(ActualFileName, FileName) < 0) { LOG_ERROR_STR(FileName); return NULL; } #ifdef USE_DVLVIDPREFER } #endif /* DVLVIDPREFER */ ActualFileName = strdup(ActualFileName); // must survive Dir! } } } cUnbufferedFile *File = cUnbufferedFile::Create(ActualFileName, Flags, DEFFILEMODE); if (ActualFileName != FileName) free((char *)ActualFileName); return File; } int CloseVideoFile(cUnbufferedFile *File) { int Result = File->Close(); delete File; return Result; }
int cVideoDirectory::FreeMB(int *UsedMB) { return FreeDiskSpaceMB(Name(), UsedMB); }