39 int FreeMB(
int *UsedMB = NULL);
46 const char *
Adjust(
const char *FileName);
75 while (l-- > 0 && isdigit(
name[l]))
79 int n = atoi(&
name[l]);
116 const char *ActualFileName = FileName;
125 if ((Flags & O_CREAT) != 0) {
129 int MaxFree = Dir.
FreeMB();
132 if (Free > MaxFree) {
138 ActualFileName = Dir.
Adjust(FileName);
139 if (!
MakeDirs(ActualFileName,
false))
141 if (symlink(ActualFileName, FileName) < 0) {
145 ActualFileName = strdup(ActualFileName);
150 if (ActualFileName != FileName)
151 free((
char *)ActualFileName);
157 int Result = File->
Close();
167 if (rename(OldName, NewName) == -1) {
183 while ((p = strrchr((
char*)(
const char*)Name + 1,
'/')) != NULL) {
185 if (stat(Name, Stat) == 0) {
186 isyslog(
"StatNearestDir: Stating %s", (
const char*)Name);
205 const char *ActualNewName = NewName;
209 struct stat StatOldName;
210 if (lstat(ActualOldName, &StatOldName) == 0) {
211 if (S_ISLNK(StatOldName.st_mode)) {
212 esyslog(
"HardLinkVideoFile: Failed to resolve symbolic link %s", (
const char*)ActualOldName);
217 esyslog(
"HardLinkVideoFile: lstat failed on %s", (
const char*)ActualOldName);
220 isyslog(
"HardLinkVideoFile: %s is on %i", (
const char*)ActualOldName, (
int)StatOldName.st_dev);
227 esyslog(
"HardLinkVideoFile: stat failed on %s", NewName);
231 isyslog(
"HardLinkVideoFile: %s is on %i", NewName, (
int)StatDir.st_dev);
232 if (StatDir.st_dev != StatOldName.st_dev) {
236 esyslog(
"HardLinkVideoFile: No matching video folder to hard link %s", (
const char*)ActualOldName);
244 const char *TmpNewName = Dir.
Adjust(NewName);
245 if (
StatNearestDir(TmpNewName, &StatDir) && StatDir.st_dev == StatOldName.st_dev) {
246 isyslog(
"HardLinkVideoFile: %s is on %i (match)", TmpNewName, (
int)StatDir.st_dev);
247 ActualNewName = TmpNewName;
251 isyslog(
"HardLinkVideoFile: %s is on %i", TmpNewName, (
int)StatDir.st_dev);
253 if (ActualNewName == NewName) {
254 esyslog(
"HardLinkVideoFile: No matching video folder to hard link %s", (
const char*)ActualOldName);
259 if (!
MakeDirs(ActualNewName,
false))
266 #ifdef HARDLINK_TEST_ONLY
269 asprintf(&name,
"%s_",ActualNewName);
270 link(ActualOldName, name);
273 #endif // HARDLINK_TEST_ONLY
276 if (link(ActualOldName, ActualNewName) != 0) {
279 isyslog(
"HardLinkVideoFile: failed to hard link from %s to %s", (
const char*)ActualOldName, ActualNewName);
283 if (ActualNewName != NewName) {
285 if (symlink(ActualNewName, NewName) < 0) {
297 if (Dir.
FreeMB() >= SizeMB * 2)
300 if (Dir.
FreeMB() >= SizeMB)
305 return Dir.
FreeMB() >= SizeMB;
310 int free = 0, used = 0;
317 }
while (Dir.
Next());
326 return (free + used) ? used * 100 / (free + used) : 0;
331 char PrefixedName[strlen(FileName) + 2];
333 const char *p = FileName + strlen(FileName);
335 while (p-- > FileName && n > 0) {
338 int l = p - FileName + 1;
339 strncpy(PrefixedName, FileName, l);
340 PrefixedName[l] = Prefix;
341 strcpy(PrefixedName + l + 1, p + 1);
353 const char *p = FileName + strlen(FileName);
354 while (p-- > FileName) {
370 }
while (Dir.
Next());
379 }
while (Dir.
Next());
385 #define DISKSPACECHEK 5 // seconds between disk space checks
386 #define MB_PER_MINUTE 25.75 // this is just an estimate!
403 if (MBperMinute <= 0)
410 if (State !=
state) {