diff options
author | Tobias Grimm <tobias@e-tobi.loc> | 2009-03-01 23:50:11 +0100 |
---|---|---|
committer | Tobias Grimm <tobias@e-tobi.loc> | 2009-03-01 23:50:11 +0100 |
commit | 41f3a108fd60f083b4c1b64dd249c606b55e2720 (patch) | |
tree | 46ea648abeda3bd3ce901012410f3dd4c208cca7 | |
parent | 1072f8978350e57f7aa35aaa79081e5031a12901 (diff) | |
download | xeatre-vdr-patches-patches/xeatre/1.6/extend-maxvideofilesize.tar.gz xeatre-vdr-patches-patches/xeatre/1.6/extend-maxvideofilesize.tar.bz2 |
initial commit of the extend-maxvideofilesize patchpatches/xeatre/1.6/extend-maxvideofilesize
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README.patch.extend-maxvideofilesize | 17 | ||||
-rw-r--r-- | config.c | 9 | ||||
-rw-r--r-- | config.h | 3 | ||||
-rw-r--r-- | cutter.c | 5 | ||||
-rw-r--r-- | dvbplayer.c | 13 | ||||
-rw-r--r-- | menu.c | 10 | ||||
-rw-r--r-- | menuitems.c | 74 | ||||
-rw-r--r-- | menuitems.h | 12 | ||||
-rw-r--r-- | recorder.c | 2 | ||||
-rw-r--r-- | recording.c | 55 | ||||
-rw-r--r-- | recording.h | 29 | ||||
-rw-r--r-- | svdrp.c | 4 | ||||
-rw-r--r-- | tools.c | 18 | ||||
-rw-r--r-- | tools.h | 4 | ||||
-rw-r--r-- | videodir.c | 14 | ||||
-rw-r--r-- | videodir.h | 4 |
17 files changed, 199 insertions, 75 deletions
@@ -59,6 +59,7 @@ RCU_DEVICE ?= /dev/ttyS1 DEFINES += -DLIRC_DEVICE=\"$(LIRC_DEVICE)\" -DRCU_DEVICE=\"$(RCU_DEVICE)\" DEFINES += -D_GNU_SOURCE +DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE DEFINES += -DVIDEODIR=\"$(VIDEODIR)\" DEFINES += -DCONFDIR=\"$(CONFDIR)\" diff --git a/README.patch.extend-maxvideofilesize b/README.patch.extend-maxvideofilesize new file mode 100644 index 0000000..491caea --- /dev/null +++ b/README.patch.extend-maxvideofilesize @@ -0,0 +1,17 @@ +DESCRIPTION +----------- + +This patch extends the maximum possible video file size by using the "reserved" +field in the index as extension to the offset. + +AUTHOR +------ + +Andreas Pickart <apickart@opensourcefactory.com> + + +HISTORY +------- + +2009-03-01 + - initial public release @@ -324,6 +324,11 @@ void cSetup::Store(const char *Name, int Value, const char *Plugin) Store(Name, cString::sprintf("%d", Value), Plugin); } +void cSetup::Store(const char *Name, int64_t Value, const char *Plugin) +{ + Store(Name, cString::sprintf("%lld", Value), Plugin); +} + bool cSetup::Load(const char *FileName) { if (cConfig<cSetupLine>::Load(FileName, true)) { @@ -448,7 +453,7 @@ bool cSetup::Parse(const char *Name, const char *Value) else if (!strcasecmp(Name, "FontOsdSize")) FontOsdSize = atoi(Value); else if (!strcasecmp(Name, "FontSmlSize")) FontSmlSize = atoi(Value); else if (!strcasecmp(Name, "FontFixSize")) FontFixSize = atoi(Value); - else if (!strcasecmp(Name, "MaxVideoFileSize")) MaxVideoFileSize = atoi(Value); + else if (!strcasecmp(Name, "MaxVideoFileSize")) MaxVideoFileSize = atoll(Value); else if (!strcasecmp(Name, "SplitEditedFiles")) SplitEditedFiles = atoi(Value); else if (!strcasecmp(Name, "MinEventTimeout")) MinEventTimeout = atoi(Value); else if (!strcasecmp(Name, "MinUserInactivity")) MinUserInactivity = atoi(Value); @@ -535,7 +540,7 @@ bool cSetup::Save(void) Store("SplitEditedFiles", SplitEditedFiles); Store("MinEventTimeout", MinEventTimeout); Store("MinUserInactivity", MinUserInactivity); - Store("NextWakeupTime", NextWakeupTime); + Store("NextWakeupTime", (int64_t)NextWakeupTime); Store("MultiSpeedMode", MultiSpeedMode); Store("ShowReplayMode", ShowReplayMode); Store("ResumeID", ResumeID); @@ -196,6 +196,7 @@ private: cSetupLine *Get(const char *Name, const char *Plugin = NULL); void Store(const char *Name, const char *Value, const char *Plugin = NULL, bool AllowMultiple = false); void Store(const char *Name, int Value, const char *Plugin = NULL); + void Store(const char *Name, int64_t Value, const char *Plugin = NULL); public: // Also adjust cMenuSetup (menu.c) when adding parameters here! int __BeginData__; @@ -254,7 +255,7 @@ public: int FontOsdSize; int FontSmlSize; int FontFixSize; - int MaxVideoFileSize; + int64_t MaxVideoFileSize; int SplitEditedFiles; int MinEventTimeout, MinUserInactivity; time_t NextWakeupTime; @@ -69,7 +69,7 @@ void cCuttingThread::Action(void) fromFile->SetReadAhead(MEGABYTE(20)); int Index = Mark->position; Mark = fromMarks.Next(Mark); - int FileSize = 0; + off_t FileSize = 0; int CurrentFileNumber = 0; int LastIFrame = 0; toMarks.Add(0); @@ -79,7 +79,8 @@ void cCuttingThread::Action(void) bool cutIn = true; while (Running()) { uchar FileNumber; - int FileOffset, Length; + off_t FileOffset; + int Length; uchar PictureType; // Make sure there is enough disk space: diff --git a/dvbplayer.c b/dvbplayer.c index 64fa559..452a699 100644 --- a/dvbplayer.c +++ b/dvbplayer.c @@ -206,7 +206,7 @@ private: cFrame *playFrame; void TrickSpeed(int Increment); void Empty(void); - bool NextFile(uchar FileNumber = 0, int FileOffset = -1); + bool NextFile(uchar FileNumber = 0, off_t FileOffset = -1); int Resume(void); bool Save(void); protected: @@ -312,7 +312,7 @@ void cDvbPlayer::Empty(void) firstPacket = true; } -bool cDvbPlayer::NextFile(uchar FileNumber, int FileOffset) +bool cDvbPlayer::NextFile(uchar FileNumber, off_t FileOffset) { if (FileNumber > 0) replayFile = fileName->SetOffset(FileNumber, FileOffset); @@ -328,7 +328,7 @@ int cDvbPlayer::Resume(void) int Index = index->GetResume(); if (Index >= 0) { uchar FileNumber; - int FileOffset; + off_t FileOffset; if (index->Get(Index, &FileNumber, &FileOffset) && NextFile(FileNumber, FileOffset)) return Index; } @@ -398,7 +398,7 @@ void cDvbPlayer::Action(void) if (!nonBlockingFileReader->Reading()) { if (playMode == pmFast || (playMode == pmSlow && playDir == pdBackward)) { uchar FileNumber; - int FileOffset; + off_t FileOffset; bool TimeShiftMode = index->IsStillRecording(); int Index = -1; if (DeviceHasIBPTrickSpeed() && playDir == pdForward) { @@ -436,7 +436,7 @@ void cDvbPlayer::Action(void) } else if (index) { uchar FileNumber; - int FileOffset; + off_t FileOffset; readIndex++; if (!(index->Get(readIndex, &FileNumber, &FileOffset, NULL, &Length) && NextFile(FileNumber, FileOffset))) { readIndex = -1; @@ -696,7 +696,8 @@ void cDvbPlayer::Goto(int Index, bool Still) if (++Index <= 0) Index = 1; // not '0', to allow GetNextIFrame() below to work! uchar FileNumber; - int FileOffset, Length; + off_t FileOffset; + int Length; Index = index->GetNextIFrame(Index, false, &FileNumber, &FileOffset, &Length); if (Index >= 0 && NextFile(FileNumber, FileOffset) && Still) { uchar b[MAXFRAMESIZE + 4 + 5 + 4]; @@ -54,7 +54,7 @@ class cFreeDiskSpace { private: static time_t lastDiskSpaceCheck; - static int lastFreeMB; + static int64_t lastFreeMB; static cString freeDiskSpaceString; public: static bool HasChanged(bool ForceCheck = false); @@ -62,7 +62,7 @@ public: }; time_t cFreeDiskSpace::lastDiskSpaceCheck = 0; -int cFreeDiskSpace::lastFreeMB = 0; +int64_t cFreeDiskSpace::lastFreeMB = 0; cString cFreeDiskSpace::freeDiskSpaceString; cFreeDiskSpace FreeDiskSpace; @@ -70,7 +70,7 @@ cFreeDiskSpace FreeDiskSpace; bool cFreeDiskSpace::HasChanged(bool ForceCheck) { if (ForceCheck || time(NULL) - lastDiskSpaceCheck > DISKSPACECHEK) { - int FreeMB; + int64_t FreeMB; int Percent = VideoDiskSpace(&FreeMB); lastDiskSpaceCheck = time(NULL); if (ForceCheck || FreeMB != lastFreeMB) { @@ -2756,7 +2756,7 @@ cMenuSetupRecord::cMenuSetupRecord(void) Add(new cMenuEditBoolItem(tr("Setup.Recording$Mark instant recording"), &data.MarkInstantRecord)); Add(new cMenuEditStrItem( tr("Setup.Recording$Name instant recording"), data.NameInstantRecord, sizeof(data.NameInstantRecord))); Add(new cMenuEditIntItem( tr("Setup.Recording$Instant rec. time (min)"), &data.InstantRecordTime, 1, MAXINSTANTRECTIME)); - Add(new cMenuEditIntItem( tr("Setup.Recording$Max. video file size (MB)"), &data.MaxVideoFileSize, MINVIDEOFILESIZE, MAXVIDEOFILESIZE)); + Add(new cMenuEditInt64Item(tr("Setup.Recording$Max. video file size (MB)"), &data.MaxVideoFileSize, MINVIDEOFILESIZE, MAXVIDEOFILESIZE)); Add(new cMenuEditBoolItem(tr("Setup.Recording$Split edited files"), &data.SplitEditedFiles)); } @@ -3896,7 +3896,7 @@ int cRecordControls::state = 0; bool cRecordControls::Start(cTimer *Timer, bool Pause) { static time_t LastNoDiskSpaceMessage = 0; - int FreeMB = 0; + int64_t FreeMB = 0; if (Timer) { AssertFreeDiskSpace(Timer->Priority(), !Timer->Pending()); Timer->SetPending(true); diff --git a/menuitems.c b/menuitems.c index 4aba66c..5fc4ea9 100644 --- a/menuitems.c +++ b/menuitems.c @@ -112,6 +112,80 @@ eOSState cMenuEditIntItem::ProcessKey(eKeys Key) return state; } +// --- cMenuEditInt64Item ------------------------------------------------------ + +cMenuEditInt64Item::cMenuEditInt64Item(const char *Name, int64_t *Value, int64_t Min, int64_t Max, const char *MinString, const char *MaxString) +:cMenuEditItem(Name) +{ + value = Value; + min = Min; + max = Max; + minString = MinString; + maxString = MaxString; + if (*value < min) + *value = min; + else if (*value > max) + *value = max; + Set(); +} + +void cMenuEditInt64Item::Set(void) +{ + if (minString && *value == min) + SetValue(minString); + else if (maxString && *value == max) + SetValue(maxString); + else { + char buf[32]; + snprintf(buf, sizeof(buf), "%lld", *value); + SetValue(buf); + } +} + +eOSState cMenuEditInt64Item::ProcessKey(eKeys Key) +{ + eOSState state = cMenuEditItem::ProcessKey(Key); + + if (state == osUnknown) { + int64_t newValue = *value; + bool IsRepeat = Key & k_Repeat; + Key = NORMALKEY(Key); + switch (Key) { + case kNone: break; + case k0 ... k9: + if (fresh) { + newValue = 0; + fresh = false; + } + newValue = newValue * 10 + (Key - k0); + break; + case kLeft: // TODO might want to increase the delta if repeated quickly? + newValue = *value - 1; + fresh = true; + if (!IsRepeat && newValue < min && max != 9223372036854775807LL) + newValue = max; + break; + case kRight: + newValue = *value + 1; + fresh = true; + if (!IsRepeat && newValue > max && min != -9223372036854775807LL - 1) + newValue = min; + break; + default: + if (*value < min) { *value = min; Set(); } + if (*value > max) { *value = max; Set(); } + return state; + } + if (newValue != *value && (!fresh || min <= newValue) && newValue <= max) { + *value = newValue; + Set(); + } + state = osContinue; + } + return state; +} + + // --- cMenuEditBoolItem ----------------------------------------------------- cMenuEditBoolItem::cMenuEditBoolItem(const char *Name, int *Value, const char *FalseString, const char *TrueString) diff --git a/menuitems.h b/menuitems.h index 0170f9b..18cb0ca 100644 --- a/menuitems.h +++ b/menuitems.h @@ -10,6 +10,7 @@ #ifndef __MENUITEMS_H #define __MENUITEMS_H +#include <stdint.h> #include <limits.h> #include "osdbase.h" @@ -35,6 +36,17 @@ public: virtual eOSState ProcessKey(eKeys Key); }; +class cMenuEditInt64Item : public cMenuEditItem { +protected: + int64_t *value; + int64_t min, max; + const char *minString, *maxString; + virtual void Set(void); +public: + cMenuEditInt64Item(const char *Name, int64_t *Value, int64_t Min = 0, int64_t Max = 9223372036854775807LL, const char *MinString = NULL, const char *MaxString = NULL); + virtual eOSState ProcessKey(eKeys Key); + }; + class cMenuEditBoolItem : public cMenuEditIntItem { protected: const char *falseString, *trueString; @@ -30,7 +30,7 @@ private: cFileName *fileName; cIndexFile *index; uchar pictureType; - int fileSize; + off_t fileSize; cUnbufferedFile *recordFile; time_t lastDiskSpaceCheck; bool RunningLowOnDiskSpace(void); diff --git a/recording.c b/recording.c index 1535b46..d8c1f96 100644 --- a/recording.c +++ b/recording.c @@ -1036,9 +1036,9 @@ void cRecordings::DelByName(const char *FileName) } } -int cRecordings::TotalFileSizeMB(void) +int64_t cRecordings::TotalFileSizeMB(void) { - int size = 0; + int64_t size = 0; LOCK_THREAD; for (cRecording *recording = First(); recording; recording = Next(recording)) { if (recording->fileSizeMB > 0 && IsOnVideoDirectoryFileSystem(recording->FileName())) @@ -1201,10 +1201,17 @@ cIndexFile::cIndexFile(const char *FileName, bool Record) if (access(fileName, R_OK) == 0) { struct stat buf; if (stat(fileName, &buf) == 0) { + off_t max_size = (off_t)INT_MAX * sizeof(tIndex); + if(sizeof(ssize_t) == sizeof(int32_t)) + max_size = 2147483640; + if(buf.st_size > max_size) { + esyslog("ERROR: file size (%lld) too large for file '%s'", buf.st_size, fileName); + buf.st_size = max_size; + } delta = buf.st_size % sizeof(tIndex); if (delta) { delta = sizeof(tIndex) - delta; - esyslog("ERROR: invalid file size (%ld) in '%s'", buf.st_size, fileName); + esyslog("ERROR: invalid file size (%lld) in '%s'", buf.st_size, fileName); } last = (buf.st_size + delta) / sizeof(tIndex) - 1; if (!Record && last >= 0) { @@ -1213,7 +1220,7 @@ cIndexFile::cIndexFile(const char *FileName, bool Record) if (index) { f = open(fileName, O_RDONLY); if (f >= 0) { - if ((int)safe_read(f, index, buf.st_size) != buf.st_size) { + if (safe_read(f, index, buf.st_size) != (ssize_t)buf.st_size) { esyslog("ERROR: can't read from file '%s'", fileName); free(index); index = NULL; @@ -1282,8 +1289,8 @@ bool cIndexFile::CatchUp(int Index) } index = (tIndex *)realloc(index, size * sizeof(tIndex)); if (index) { - int offset = (last + 1) * sizeof(tIndex); - int delta = (newLast - last) * sizeof(tIndex); + off_t offset = ((off_t)last + 1) * sizeof(tIndex); + ssize_t delta = (newLast - last) * sizeof(tIndex); if (lseek(f, offset, SEEK_SET) == offset) { if (safe_read(f, &index[last + 1], delta) != delta) { esyslog("ERROR: can't read from index"); @@ -1312,32 +1319,38 @@ bool cIndexFile::CatchUp(int Index) return index != NULL; } -bool cIndexFile::Write(uchar PictureType, uchar FileNumber, int FileOffset) +bool cIndexFile::Write(uchar PictureType, uchar FileNumber, off_t FileOffset) { if (f >= 0) { - tIndex i = { FileOffset, PictureType, FileNumber, 0 }; + tIndex i = { (uint32_t) FileOffset, PictureType, FileNumber, (uint16_t) (FileOffset>>32) }; if (safe_write(f, &i, sizeof(i)) < 0) { LOG_ERROR_STR(fileName); close(f); f = -1; return false; } - last++; + if(++last < 0) { + esyslog("ERROR: index file '%s' grew too large", fileName); + close(f); + f = -1; + last--; + return false; + } } return f >= 0; } -bool cIndexFile::Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType, int *Length) +bool cIndexFile::Get(int Index, uchar *FileNumber, off_t *FileOffset, uchar *PictureType, int *Length) { if (CatchUp(Index)) { if (Index >= 0 && Index < last) { *FileNumber = index[Index].number; - *FileOffset = index[Index].offset; + *FileOffset = (off_t) index[Index].offset_hi << 32 | index[Index].offset_lo; if (PictureType) *PictureType = index[Index].type; if (Length) { int fn = index[Index + 1].number; - int fo = index[Index + 1].offset; + off_t fo = (off_t) index[Index + 1].offset_hi << 32 | index[Index + 1].offset_lo; if (fn == *FileNumber) *Length = fo - *FileOffset; else @@ -1349,7 +1362,7 @@ bool cIndexFile::Get(int Index, uchar *FileNumber, int *FileOffset, uchar *Pictu return false; } -int cIndexFile::GetNextIFrame(int Index, bool Forward, uchar *FileNumber, int *FileOffset, int *Length, bool StayOffEnd) +int cIndexFile::GetNextIFrame(int Index, bool Forward, uchar *FileNumber, off_t *FileOffset, int *Length, bool StayOffEnd) { if (CatchUp()) { int d = Forward ? 1 : -1; @@ -1361,16 +1374,15 @@ int cIndexFile::GetNextIFrame(int Index, bool Forward, uchar *FileNumber, int *F *FileNumber = index[Index].number; else FileNumber = &index[Index].number; + off_t cur_fo = (off_t) index[Index].offset_hi << 32 | index[Index].offset_lo; if (FileOffset) - *FileOffset = index[Index].offset; - else - FileOffset = &index[Index].offset; + *FileOffset = cur_fo; if (Length) { // all recordings end with a non-I_FRAME, so the following should be safe: int fn = index[Index + 1].number; - int fo = index[Index + 1].offset; + off_t fo = (off_t) index[Index + 1].offset_hi << 32 | index[Index + 1].offset_lo; if (fn == *FileNumber) - *Length = fo - *FileOffset; + *Length = fo - cur_fo; else { esyslog("ERROR: 'I' frame at end of file #%d", *FileNumber); *Length = -1; @@ -1386,13 +1398,14 @@ int cIndexFile::GetNextIFrame(int Index, bool Forward, uchar *FileNumber, int *F return -1; } -int cIndexFile::Get(uchar FileNumber, int FileOffset) +int cIndexFile::Get(uchar FileNumber, off_t FileOffset) { if (CatchUp()) { //TODO implement binary search! int i; for (i = 0; i < last; i++) { - if (index[i].number > FileNumber || (index[i].number == FileNumber) && index[i].offset >= FileOffset) + if (index[i].number > FileNumber || (index[i].number == FileNumber) && + ((off_t) index[i].offset_hi << 32 | index[i].offset_lo) >= FileOffset) break; } return i; @@ -1467,7 +1480,7 @@ void cFileName::Close(void) } } -cUnbufferedFile *cFileName::SetOffset(int Number, int Offset) +cUnbufferedFile *cFileName::SetOffset(int Number, off_t Offset) { if (fileNumber != Number) Close(); diff --git a/recording.h b/recording.h index 4bdcd1b..4621a16 100644 --- a/recording.h +++ b/recording.h @@ -70,7 +70,7 @@ private: mutable char *sortBuffer; mutable char *fileName; mutable char *name; - mutable int fileSizeMB; + mutable int64_t fileSizeMB; cRecordingInfo *info; cRecording(const cRecording&); // can't copy cRecording cRecording &operator=(const cRecording &); // can't assign cRecording @@ -143,7 +143,7 @@ public: cRecording *GetByName(const char *FileName); void AddByName(const char *FileName, bool TriggerUpdate = true); void DelByName(const char *FileName); - int TotalFileSizeMB(void); ///< Only for deleted recordings! + int64_t TotalFileSizeMB(void); ///< Only for deleted recordings! }; extern cRecordings Recordings; @@ -188,18 +188,17 @@ public: // The maximum size of a single frame (up to HDTV 1920x1080): #define MAXFRAMESIZE KILOBYTE(512) + // The maximum file size is limited by the range that can be covered -// with 'int'. 4GB might be possible (if the range is considered -// 'unsigned'), 2GB should be possible (even if the range is considered -// 'signed'), so let's use 2000MB for absolute safety (the actual file size -// may be slightly higher because we stop recording only before the next -// 'I' frame, to have a complete Group Of Pictures): -#define MAXVIDEOFILESIZE 2000 // MB -#define MINVIDEOFILESIZE 100 // MB +// with 32+16 bits unsigned. Let's use somewhat less for absolute safety +// (the actual file size may be slightly higher because we stop recording +// only before the next 'I' frame, to have a complete Group Of Pictures): +#define MAXVIDEOFILESIZE 274877906000ULL // MB +#define MINVIDEOFILESIZE 100 // MB class cIndexFile { private: - struct tIndex { int offset; uchar type; uchar number; short reserved; }; + struct tIndex { uint32_t offset_lo; uchar type; uchar number; uint16_t offset_hi; }; int f; char *fileName; int size, last; @@ -211,10 +210,10 @@ public: cIndexFile(const char *FileName, bool Record); ~cIndexFile(); bool Ok(void) { return index != NULL; } - bool Write(uchar PictureType, uchar FileNumber, int FileOffset); - bool Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType = NULL, int *Length = NULL); - int GetNextIFrame(int Index, bool Forward, uchar *FileNumber = NULL, int *FileOffset = NULL, int *Length = NULL, bool StayOffEnd = false); - int Get(uchar FileNumber, int FileOffset); + bool Write(uchar PictureType, uchar FileNumber, off_t FileOffset); + bool Get(int Index, uchar *FileNumber, off_t *FileOffset, uchar *PictureType = NULL, int *Length = NULL); + int GetNextIFrame(int Index, bool Forward, uchar *FileNumber = NULL, off_t *FileOffset = NULL, int *Length = NULL, bool StayOffEnd = false); + int Get(uchar FileNumber, off_t FileOffset); int Last(void) { CatchUp(); return last; } int GetResume(void) { return resumeFile.Read(); } bool StoreResume(int Index) { return resumeFile.Save(Index); } @@ -235,7 +234,7 @@ public: int Number(void) { return fileNumber; } cUnbufferedFile *Open(void); void Close(void); - cUnbufferedFile *SetOffset(int Number, int Offset = 0); + cUnbufferedFile *SetOffset(int Number, off_t Offset = 0); cUnbufferedFile *NextFile(void); }; @@ -1476,9 +1476,9 @@ void cSVDRP::CmdSTAT(const char *Option) { if (*Option) { if (strcasecmp(Option, "DISK") == 0) { - int FreeMB, UsedMB; + int64_t FreeMB, UsedMB; int Percent = VideoDiskSpace(&FreeMB, &UsedMB); - Reply(250, "%dMB %dMB %d%%", FreeMB + UsedMB, FreeMB, Percent); + Reply(250, "%lldMB %lldMB %d%%", FreeMB + UsedMB, FreeMB, Percent); } else Reply(501, "Invalid Option \"%s\"", Option); @@ -292,17 +292,17 @@ bool EntriesOnSameFileSystem(const char *File1, const char *File2) return false; } -int FreeDiskSpaceMB(const char *Directory, int *UsedMB) +int64_t FreeDiskSpaceMB(const char *Directory, int64_t *UsedMB) { if (UsedMB) *UsedMB = 0; - int Free = 0; + int64_t Free = 0; struct statfs statFs; if (statfs(Directory, &statFs) == 0) { double blocksPerMeg = 1024.0 * 1024.0 / statFs.f_bsize; if (UsedMB) - *UsedMB = int((statFs.f_blocks - statFs.f_bfree) / blocksPerMeg); - Free = int(statFs.f_bavail / blocksPerMeg); + *UsedMB = int64_t((statFs.f_blocks - statFs.f_bfree) / blocksPerMeg); + Free = int64_t(statFs.f_bavail / blocksPerMeg); } else LOG_ERROR_STR(Directory); @@ -446,11 +446,11 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis) return false; } -int DirSizeMB(const char *DirName) +int64_t DirSizeMB(const char *DirName) { cReadDir d(DirName); if (d.Ok()) { - int size = 0; + int64_t size = 0; struct dirent *e; while (size >= 0 && (e = d.Next()) != NULL) { if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { @@ -458,7 +458,7 @@ int DirSizeMB(const char *DirName) struct stat st; if (stat(buffer, &st) == 0) { if (S_ISDIR(st.st_mode)) { - int n = DirSizeMB(buffer); + off_t n = DirSizeMB(buffer); if (n >= 0) size += n; else @@ -1589,7 +1589,7 @@ ssize_t cUnbufferedFile::Write(const void *Data, size_t Size) // last (partial) page might be skipped, writeback will start only after // second call; the third call will still include this page and finally // drop it from cache. - off_t headdrop = min(begin, WRITE_BUFFER * 2L); + off_t headdrop = min(begin, (off_t)WRITE_BUFFER * 2L); posix_fadvise(fd, begin - headdrop, lastpos - begin + headdrop, POSIX_FADV_DONTNEED); } begin = lastpos = curpos; @@ -1608,7 +1608,7 @@ ssize_t cUnbufferedFile::Write(const void *Data, size_t Size) // kind of write gathering enabled), but the syncs cause (io) load.. // Uncomment the next line if you think you need them. //fdatasync(fd); - off_t headdrop = min(curpos - totwritten, totwritten * 2L); + off_t headdrop = min((off_t)(curpos - totwritten), (off_t)totwritten * 2L); posix_fadvise(fd, curpos - totwritten - headdrop, totwritten + headdrop, POSIX_FADV_DONTNEED); totwritten = 0; } @@ -195,12 +195,12 @@ bool isnumber(const char *s); cString itoa(int n); cString AddDirectory(const char *DirName, const char *FileName); bool EntriesOnSameFileSystem(const char *File1, const char *File2); -int FreeDiskSpaceMB(const char *Directory, int *UsedMB = NULL); +int64_t FreeDiskSpaceMB(const char *Directory, int64_t *UsedMB = NULL); bool DirectoryOk(const char *DirName, bool LogErrors = false); bool MakeDirs(const char *FileName, bool IsDirectory = false); bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks = false); bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis = false); -int DirSizeMB(const char *DirName); ///< returns the total size of the files in the given directory, or -1 in case of an error +int64_t DirSizeMB(const char *DirName); ///< returns the total size of the files in the given directory, or -1 in case of an error char *ReadLink(const char *FileName); ///< returns a new string allocated on the heap, which the caller must delete (or NULL in case of an error) bool SpinUpDisk(const char *FileName); void TouchFile(const char *FileName); @@ -28,7 +28,7 @@ private: public: cVideoDirectory(void); ~cVideoDirectory(); - int FreeMB(int *UsedMB = NULL); + int64_t FreeMB(off_t *UsedMB = NULL); const char *Name(void) { return name ? name : VideoDirectory; } const char *Stored(void) { return stored; } int Length(void) { return length; } @@ -54,7 +54,7 @@ cVideoDirectory::~cVideoDirectory() free(adjusted); } -int cVideoDirectory::FreeMB(int *UsedMB) +int64_t cVideoDirectory::FreeMB(int64_t *UsedMB) { return FreeDiskSpaceMB(name ? name : VideoDirectory, UsedMB); } @@ -168,7 +168,7 @@ bool RemoveVideoFile(const char *FileName) return RemoveFileOrDir(FileName, true); } -bool VideoFileSpaceAvailable(int SizeMB) +bool VideoFileSpaceAvailable(int64_t SizeMB) { cVideoDirectory Dir; if (Dir.IsDistributed()) { @@ -183,13 +183,13 @@ bool VideoFileSpaceAvailable(int SizeMB) return Dir.FreeMB() >= SizeMB; } -int VideoDiskSpace(int *FreeMB, int *UsedMB) +int64_t VideoDiskSpace(int64_t *FreeMB, int64_t *UsedMB) { - int free = 0, used = 0; - int deleted = DeletedRecordings.TotalFileSizeMB(); + int64_t free = 0, used = 0; + int64_t deleted = DeletedRecordings.TotalFileSizeMB(); cVideoDirectory Dir; do { - int u; + int64_t u; free += Dir.FreeMB(&u); used += u; } while (Dir.Next()); @@ -19,8 +19,8 @@ cUnbufferedFile *OpenVideoFile(const char *FileName, int Flags); int CloseVideoFile(cUnbufferedFile *File); bool RenameVideoFile(const char *OldName, const char *NewName); bool RemoveVideoFile(const char *FileName); -bool VideoFileSpaceAvailable(int SizeMB); -int VideoDiskSpace(int *FreeMB = NULL, int *UsedMB = NULL); // returns the used disk space in percent +bool VideoFileSpaceAvailable(int64_t SizeMB); +int64_t VideoDiskSpace(int64_t *FreeMB = NULL, int64_t *UsedMB = NULL); // returns the used disk space in percent cString PrefixVideoFileName(const char *FileName, char Prefix); void RemoveEmptyVideoDirectories(void); bool IsOnVideoDirectoryFileSystem(const char *FileName); |