92 #include <sys/types.h>
96 #include <sys/param.h>
97 #include <sys/mount.h>
99 #include <sys/statfs.h>
111 #define BUFSIZE_SMALL 80
123 char cModule[32]=
"rawGetDirEntries";
130 struct dirent *pEntry;
133 "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
135 pDir = opendir(pcStageFS);
139 "-E- %s: cannot open directory %s\n", cModule, pcStageFS);
142 fprintf(
fLogFile,
" %s\n", strerror(errno));
149 while ( (pEntry = readdir(pDir)) != NULL)
151 if ( (strcmp(pEntry->d_name,
".") == 0) ||
152 (strcmp(pEntry->d_name,
"..") == 0) )
158 fprintf(
fLogFile,
" %d: %s\n", iEntries, pEntry->d_name);
161 iRC = closedir(pDir);
164 fprintf(
fLogFile,
" rc(closedir) = %d\n-D- end %s\n\n", iRC, cModule);
194 char cModule[32] =
"rawGetDirEntryList";
198 int ilen, iloc, ii, jj;
203 char cEntryType[32] =
"";
205 int iEntriesMatch = 0;
207 int iFileEntryMax = 0;
208 int iFileEntryRem = 0;
209 int iFileEntries = 0;
210 int iFileEntriesOld = 0;
211 int iFileEntriesNew = 0;
220 int iDirEntryMax = 0;
221 int iDirEntryRem = 0;
223 int iDirEntriesOld = 0;
224 int iDirEntriesNew = 0;
235 struct dirent *pEntry;
237 struct stat sEntryStatus, *pEntryStatus;
240 fprintf(
fLogFile,
"\n-D- begin %s\n", cModule);
242 pEntryStatus = &sEntryStatus;
244 if (strlen(pcDirName) <= 0)
246 fprintf(
fLogFile,
"-E- %s: empty directory name\n", cModule);
249 goto gEndDirEntryList;
252 if (iEntryType >= 10)
254 if (strlen(pcEntryMask) <= 0)
257 "-E- %s: empty mask for entry name\n", cModule);
260 goto gEndDirEntryList;
265 if (strcmp(pcEntryMask,
"*") != 0)
270 strcpy(cEntryType,
"entries");
271 else if (iEntryType == 1)
272 strcpy(cEntryType,
"files");
273 else if (iEntryType == 2)
274 strcpy(cEntryType,
"subdirs");
278 "-E- %s: invalid EntryType %d (allowed 0-2, 10-12)\n",
279 cModule, iEntryType);
282 goto gEndDirEntryList;
286 if ( (iEntryType == 0) || (iEntryType == 1) )
288 if (ppFileList == NULL)
291 "-E- %s: invalid pointer for entry list\n", cModule);
294 goto gEndDirEntryList;
297 piFileNo = (
int *) *ppFileList;
298 piFileList = piFileNo;
299 iFileEntriesOld = *piFileNo;
305 if (iFileEntriesOld) fprintf(
fLogFile,
306 " %d files already available in list:\n",
309 " still no files in list\n");
314 if (iFileEntriesOld) fprintf(
fLogFile,
315 "-W- %s: no entry loop, but %d files already available in list\n",
316 cModule, iFileEntriesOld);
321 psFileList0 = psFileList;
328 for (ii=1; ii<=iFileEntriesOld; ii++)
336 psFileList += iFileEntriesOld;
338 iFileEntries = iFileEntriesOld;
343 if (iFileEntriesOld > iFileEntryMax)
345 ii = iFileEntriesOld / iFileEntryMax;
349 iFileEntryRem = iFileEntryMax - iFileEntriesOld;
352 " space available for %d file entries (max %d)\n",
353 iFileEntryRem, iFileEntryMax);
358 if ( (iEntryType == 0) || (iEntryType == 2) )
360 if (ppDirList == NULL)
363 "-E- %s: invalid pointer for subdir list\n", cModule);
366 goto gEndDirEntryList;
369 piDirNo = (
int *) *ppDirList;
371 iDirEntriesOld = *piDirNo;
377 if (iDirEntriesOld) fprintf(
fLogFile,
378 " %d subdirectories already available in list:\n",
381 " still no subdirectories in list\n");
384 else if (iDirEntriesOld) fprintf(
fLogFile,
385 "-W- %s: no entry loop, but %d subdirectories available in list\n",
386 cModule, iDirEntriesOld);
390 psDirList0 = psDirList;
392 for (ii=1; ii<=iDirEntriesOld; ii++)
397 fprintf(
fLogFile,
"previous subdirs:\n");
405 iDirEntries = iDirEntriesOld;
409 if (iDirEntriesOld > iDirEntryMax)
411 ii = iDirEntriesOld / iDirEntryMax;
415 iDirEntryRem = iDirEntryMax - iDirEntriesOld;
418 " space available for %d subdir entries (max %d)\n",
419 iDirEntryRem, iDirEntryMax);
425 if ( (iEntryType == 0) && (iMatch) )
428 " provide all files matching with %s and all subdirs in directory %s\n",
429 pcEntryMask, pcDirName);
433 fprintf(
fLogFile,
" provide all %s", cEntryType);
435 " matching with %s", pcEntryMask);
436 fprintf(
fLogFile,
" in directory %s\n", pcDirName);
440 pDir = opendir(pcDirName);
444 "-E- %s: cannot open directory %s\n", cModule, pcDirName);
447 fprintf(
fLogFile,
"%s\n", strerror(errno));
452 goto gEndDirEntryList;
455 while ( (pEntry = readdir(pDir)) != NULL)
457 if ( (strcmp(pEntry->d_name,
".") == 0) ||
458 (strcmp(pEntry->d_name,
"..") == 0) )
466 if (pEntry->d_type == DT_UNKNOWN)
468 if ( (iEntries == 1) && (iDebug) ) fprintf(
fLogFile,
469 " %s: of type DT_UNKNOWN (1st entry)\n",
472 strcpy(cTemp, pcDirName);
474 strcat(cTemp, pEntry->d_name);
476 iRC = stat(cTemp, pEntryStatus);
481 fprintf(
fLogFile,
"-E- stat %s: %s\n",
482 cTemp, strerror(errno));
485 if (strcmp(strerror(errno),
486 "Value too large for defined data type") == 0)
489 "-E- %s: filesize of %s > 2 GByte: use 64 bit gStore client\n",
498 "-W- %s: entry %s unavailable\n", cModule, pEntry->d_name);
503 if (S_ISREG(pEntryStatus->st_mode))
505 else if (S_ISDIR(pEntryStatus->st_mode))
510 "-W- %s: entry %s neither file nor directory, ignored\n",
511 cModule, pEntry->d_name);
520 if ( (pEntry->d_type == DT_REG) || (iTypeFound == 1) )
522 if ( (iEntryType == 0) || (iEntryType == 1) )
530 else if ( (pEntry->d_type == DT_DIR) || (iTypeFound == 2) )
532 if ( (iEntryType == 0) || (iEntryType == 2) )
534 if ( (iMatch) && (iEntryType == 2) )
542 " %d: entry %s (check %d, store %d, type %d) \n",
543 iEntries, pEntry->d_name, iCheck, iStore, pEntry->d_type);
549 if (fnmatch(pcEntryMask, pEntry->d_name, FNM_PATHNAME) == 0)
561 if ( (pEntry->d_type == DT_REG) ||
562 (pEntry->d_type == DT_UNKNOWN) )
566 strcpy(psFileList->
cFile, pcDirName);
567 strcat(psFileList->
cFile,
"/");
568 strcat(psFileList->
cFile, pEntry->d_name);
571 strcpy(psFileList->
cFile, pEntry->d_name);
578 if (iFileEntriesNew == 1)
581 iFileEntriesNew, iFileEntries, psFileList->
cFile);
584 if (iFileEntryRem <= 0)
589 ii =
sizeof(int) + iFileEntryMax*
iFileList;
590 if ((pcFileList2 = (
char *) calloc((
unsigned) ii, 1)) == NULL)
593 "-E- %s: allocating new filelist buffer (%d byte, %d entries)\n",
594 cModule, ii, iFileEntryMax);
597 fprintf(
fLogFile,
" %s\n", strerror(errno));
602 goto gEndDirEntryList;
606 " new filelist buffer allocated (%d byte, %d entries)\n",
609 iFileEntryRem = iFileEntryMax - iFileEntries;
610 piFileList2 = (
int *) pcFileList2;
611 *piFileList2 = iFileEntries;
612 *ppFileList = (
char *) piFileList2;
616 memcpy(piFileList2, piFileList, ii);
619 psFileList0 = psFileList;
622 " %d filelist entries copied, first %s\n",
623 iFileEntries, psFileList->
cFile);
626 psFileList += iFileEntries;
627 piFileList = piFileList2;
629 piFileNo = piFileList2;
640 if (pEntry->d_type == DT_DIR)
642 strcpy(psDirList->
cFile, pEntry->d_name);
649 if (iDirEntriesNew == 1)
650 fprintf(
fLogFile,
"new subdirs:\n");
652 iDirEntriesNew, iDirEntries, psDirList->
cFile);
655 if (iDirEntryRem <= 0)
657 fprintf(
fLogFile,
"DDD2 new space must be allocated\n");
667 iRC = closedir(pDir);
670 fprintf(
fLogFile,
" rc(closedir) = %d\n", iRC);
675 " %d entries in directory %s found\n",
676 iEntries, pcDirName);
678 " %d entries matching with %s\n", iEntriesMatch, pcEntryMask);
684 " thereof %d files (%d new)\n",
685 iFileEntries, iFileEntriesNew);
687 " thereof %d subdirectories (%d new)\n",
688 iDirEntries, iDirEntriesNew);
691 if ( (iEntryType == 0) || (iEntryType == 1) )
692 *piFileNo = iFileEntries;
693 if ( (iEntryType == 0) || (iEntryType == 2) )
694 *piDirNo = iDirEntries;
699 " %d files provided in list, first %s\n",
700 iFileEntries, psFileList0->
cFile);
701 else if ( (iEntryType == 0) || (iEntryType == 1) )
703 fprintf(
fLogFile,
" no files in %s found",
706 " matching with %s\n", pcEntryMask);
712 " %d subdirs provided in list, first %s\n",
713 iDirEntries, psDirList0->
cFile);
714 else if ( (iEntryType == 0) || (iEntryType == 2) )
716 fprintf(
fLogFile,
" no subdirs in %s found",
718 if ( (iMatch) && (iEntryType == 2) ) fprintf(
fLogFile,
719 " matching with %s\n", pcEntryMask);
728 fprintf(
fLogFile,
"\n-D- end %s\n\n", cModule);
734 return iEntriesMatch;
770 char cModule[32] =
"rawGetRecEntryList";
774 int ilen, iloc, ii, jj;
775 char *pcc, *pcc1, *pcc2, *pcc3;
784 char cEntryType[32] =
"";
788 int iMaskDirLevel = 0;
789 int icurDirLevel = 0;
790 int iaMaskSubdirLen[100];
791 int iacurSubdirLen[100];
794 int iFileEntryMax = 0;
795 int iFileEntryRem = 0;
796 int iFileEntries = 0;
797 int iFileEntriesOld = 0;
798 int iFileEntriesNew = 0;
805 int iDirEntryMax = 0;
806 int iDirEntryRem = 0;
808 int iDirEntriesOld = 0;
809 int iDirEntriesNew = 0;
827 struct dirent *pEntry;
831 if (strlen(pcDirName) <= 0)
833 fprintf(
fLogFile,
"-E- %s: empty directory name\n", cModule);
836 goto gEndRecEntryList;
838 strcpy(cDirName, pcDirName);
839 strcpy(cDirNameOrig, cDirName);
840 strncat(cDirNameOrig,
"/", 1);
843 "\n-D- begin %s:\n top dir %s, entry type %d, max %d files, max %d dirs\n",
844 cModule, cDirName, iEntryType, iMaxFiles, iMaxDirs);
847 if (iEntryType >= 10)
849 ii = strlen(pcEntryMask);
853 "-E- %s: empty mask for entry name\n", cModule);
856 goto gEndRecEntryList;
862 if (strncmp(pcc,
"/", 1) == 0)
864 strncpy(pcc,
"\0", 1);
867 " trailing '/' in file mask removed: %s\n", pcEntryMask);
870 strcpy(cEntryMask, pcEntryMask);
872 if (iEntryType >= 20)
876 pcc = strrchr(cEntryMask,
'/');
880 "-E- %s: invalid file mask %s: must be fully qualified for type %d\n",
881 cModule, cEntryMask, iEntryType);
884 goto gEndRecEntryList;
888 strcpy(cDirMask, cEntryMask);
889 pcc1 = strrchr(cDirMask,
'/');
890 strncpy(pcc1,
"\0", 1);
892 strcpy(cFileMask, pcc1);
894 pcc1 = strrchr(cDirMask,
'/');
898 "-E- %s: invalid file mask: must be fully qualified for type %d\n",
899 cModule, iEntryType);
902 goto gEndRecEntryList;
906 " dir mask %s, file mask %s\n", cDirMask, cFileMask);
908 if ( (strchr(cDirMask, *
pcStar) == NULL) &&
909 (strchr(cDirMask, *
pcQM) == NULL) &&
910 (strchr(cDirMask, *
pcPerc) == NULL) )
913 if (strcmp(cDirMask, cDirName) == 0)
917 " last dir %s\n", cDirName);
923 pcc = strchr(cDirMask,
'/');
927 iaMaskSubdirLen[iMaskDirLevel] = pcc - pcc2 + 1;
931 ii = iaMaskSubdirLen[iMaskDirLevel];
935 strcpy(cTemp, cDirMask);
938 strncpy(pcc3,
"\0", 1);
939 fprintf(
fLogFile,
" mask dir level %d: %s (%d byte)\n",
940 iMaskDirLevel, cTemp, ii);
944 pcc1 = strchr(pcc,
'/');
952 ii = iaMaskSubdirLen[iMaskDirLevel-1] + jj;
953 iaMaskSubdirLen[iMaskDirLevel] = ii;
956 " mask dir level %d: %s (%d byte)\n",
957 iMaskDirLevel, cDirMask, ii);
960 " mask dir has %d levels\n", iMaskDirLevel);
962 if (iEntryType == 30)
966 " action not recursive - no handling of subdirs below mask\n");
976 strcpy(cFileMask, pcEntryMask);
979 " mask %s for relative file/subdir names\n", cEntryMask);
984 strcpy(cEntryType,
"entries");
985 else if (iEntryType == 1)
986 strcpy(cEntryType,
"files");
987 else if (iEntryType == 2)
988 strcpy(cEntryType,
"subdirs");
992 "-E- %s: invalid EntryType %d (allowed 0-2, 10-12, 20, 30)\n",
993 cModule, iEntryType);
996 goto gEndRecEntryList;
1000 if ( (iEntryType == 0) || (iEntryType == 1) )
1002 if (ppFileList == NULL)
1005 "-E- %s: invalid pointer for entry list\n", cModule);
1008 goto gEndRecEntryList;
1011 piFileNo = (
int *) *ppFileList;
1012 piFileList = piFileNo;
1013 iFileEntriesOld = *piFileNo;
1017 if (iFileEntriesOld) fprintf(
fLogFile,
1018 " %d files already available in list:\n",
1021 " still no files in list\n");
1026 psFileList0 = psFileList;
1028 for (ii=1; ii<=iFileEntriesOld; ii++)
1033 fprintf(
fLogFile,
"previous files:\n");
1041 iFileEntries = iFileEntriesOld;
1042 iFileEntryMax = iMaxFiles;
1044 iFileEntryRem = iFileEntryMax - iFileEntriesOld;
1047 " space available for %d file entries (max %d)\n",
1048 iFileEntryRem, iFileEntryMax);
1053 if ( (iEntryType == 0) || (iEntryType == 2) )
1055 if (ppDirList == NULL)
1058 "-E- %s: invalid pointer for subdir list\n", cModule);
1061 goto gEndRecEntryList;
1064 piDirNo = (
int *) *ppDirList;
1065 piDirList = piDirNo;
1066 iDirEntriesOld = *piDirNo;
1070 if (iDirEntriesOld) fprintf(
fLogFile,
1071 " %d subdirectories already available in list:\n",
1074 " still no subdirectories in list\n");
1079 psDirList0 = psDirList;
1081 for (ii=1; ii<=iDirEntriesOld; ii++)
1086 fprintf(
fLogFile,
"previous subdirs:\n");
1094 iDirEntries = iDirEntriesOld;
1095 iDirEntryMax = iMaxDirs;
1098 if (iDirEntriesOld > iDirEntryMax)
1100 ii = iDirEntriesOld / iDirEntryMax;
1104 else if (iDirEntriesOld == iDirEntryMax)
1106 fprintf(
fLogFile,
"DDD1 new space must be allocated\n");
1109 iDirEntryRem = iDirEntryMax - iDirEntriesOld;
1112 " space available for %d subdir entries (max %d)\n",
1113 iDirEntryRem, iDirEntryMax);
1122 " provide all %s matching with %s",
1123 cEntryType, cEntryMask);
1125 " in dir %s", cDirName);
1128 " provide all %s in dir %s", cEntryType, cDirName);
1131 " and all subdirs\n");
1136 pDir = opendir(cDirName);
1140 "-E- %s: cannot open directory %s\n", cModule, cDirName);
1142 fprintf(
fLogFile,
"%s\n", strerror(errno));
1145 goto gEndRecEntryList;
1149 " new dir %s opened\n", cDirName);
1155 pcc = strchr(cDirName,
'/');
1159 iacurSubdirLen[icurDirLevel] = pcc - pcc2 + 1;
1163 ii = iacurSubdirLen[icurDirLevel];
1167 strcpy(cTemp, cDirName);
1170 strncpy(pcc3,
"\0", 1);
1172 fprintf(
fLogFile,
" cur dir level %d: %s (%d byte)\n",
1173 icurDirLevel, cTemp, ii);
1176 if (icurDirLevel > iMaskDirLevel)
1180 pcc1 = strchr(pcc,
'/');
1188 ii = iacurSubdirLen[icurDirLevel-1] + jj;
1189 iacurSubdirLen[icurDirLevel] = ii;
1192 " cur dir level %d: %s (%d byte)\n",
1193 icurDirLevel, cDirName, ii);
1196 " cur dir has %d levels\n", icurDirLevel);
1200 if ( (iFullMatch) && (iRecursive == 0) &&
1201 (icurDirLevel == iMaskDirLevel) )
1204 " last subdir level (%d), check only for files\n",
1210 if ( (iFullMatch) && (iDebug) ) fprintf(
fLogFile,
1211 " comparisons on subdir level %d (mask) - %d (new dir)\n",
1212 iMaskDirLevel, icurDirLevel);
1214 iDirNameLen = strlen(cDirName);
1215 psDirListNew = psDirList;
1216 strcat(cDirName,
"/");
1218 while ( (pEntry = readdir(pDir)) != NULL)
1220 if ( (strcmp(pEntry->d_name,
".") == 0) ||
1221 (strcmp(pEntry->d_name,
"..") == 0) )
1231 if (icurDirLevel < iMaskDirLevel)
1234 if (pEntry->d_type == DT_DIR)
1239 "%d: check dir %s (short)\n",
1240 iEntries, pEntry->d_name);
1242 else if (iDebug == 2) fprintf(
fLogFile,
1243 "%d: ignore file %s (short)\n",
1244 iEntries, pEntry->d_name);
1246 else if (icurDirLevel == iMaskDirLevel)
1252 if (pEntry->d_type == DT_DIR) fprintf(
fLogFile,
1253 "%d: check dir %s (last level)\n",
1254 iEntries, pEntry->d_name);
1256 "%d: check file %s (last subdir)\n",
1257 iEntries, pEntry->d_name);
1263 if (pEntry->d_type == DT_REG)
1267 "%d: check file %s\n",
1268 iEntries, pEntry->d_name);
1274 "%d: store dir %s\n",
1275 iEntries, pEntry->d_name);
1281 if (pEntry->d_type == DT_REG)
1283 if ( (iEntryType == 0) || (iEntryType == 1) )
1289 "%d: check file %s\n", iEntries, pEntry->d_name);
1295 "%d: store file %s\n", iEntries, pEntry->d_name);
1299 else if (pEntry->d_type == DT_DIR)
1301 if ( (iEntryType == 0) || (iEntryType == 2) )
1305 "%d: store dir %s\n", iEntries, pEntry->d_name);
1308 else if (iDebug == 2) fprintf(
fLogFile,
1309 "ignore %s%s (entry type %d)\n",
1310 cDirName, pEntry->d_name, pEntry->d_type);
1321 if (icurDirLevel < iMaskDirLevel)
1324 strcpy(cDirName, cDirNameOrig);
1325 strcat(cDirName, pEntry->d_name);
1327 strncpy(cFullEntryCheck, cEntryMask,
1328 iaMaskSubdirLen[icurDirLevel]-1);
1331 " compare dirs: '%s' - '%s'\n",
1332 cFullEntryCheck, cDirName);
1334 if (fnmatch(cFullEntryCheck, cDirName, FNM_PATHNAME) == 0)
1337 else if (icurDirLevel == iMaskDirLevel)
1339 strcpy(cFullEntryCheck, cDirName);
1340 strcat(cFullEntryCheck, pEntry->d_name);
1342 if (pEntry->d_type == DT_REG)
1345 " compare files: '%s' - '%s'\n",
1346 cEntryMask, cFullEntryCheck);
1348 if (fnmatch(cEntryMask, cFullEntryCheck, FNM_PATHNAME) == 0)
1354 " compare dirs: '%s' - '%s'\n",
1355 cDirMask, cFullEntryCheck);
1357 if (fnmatch(cDirMask, cFullEntryCheck, FNM_PATHNAME) == 0)
1365 " compare files: '%s' - '%s'\n",
1366 cFileMask, pEntry->d_name);
1368 if (fnmatch(cFileMask, pEntry->d_name, FNM_PATHNAME) == 0)
1376 " compare entries: '%s' - '%s'\n",
1377 cEntryMask, pEntry->d_name);
1379 if (fnmatch(cEntryMask, pEntry->d_name, FNM_PATHNAME) == 0)
1387 if (pEntry->d_type == DT_REG)
1389 strcpy(psFileList->
cFile, cDirName);
1390 strcat(psFileList->
cFile, pEntry->d_name);
1398 if (iFileEntriesNew == 1)
1401 iFileEntriesNew, iFileEntries, psFileList->
cFile);
1404 if (iFileEntryRem <= 0)
1407 "-W- dir %s: max no. of %d file entries reached\n",
1408 cDirName, iMaxFiles);
1418 if ( (pEntry->d_type == DT_DIR) && (iLastDir == 0) )
1420 if ( (iFullMatch) && (icurDirLevel < iMaskDirLevel) )
1421 strcpy(psDirList->
cFile, cDirName);
1424 strcpy(psDirList->
cFile, cDirName);
1425 strcat(psDirList->
cFile, pEntry->d_name);
1434 if (iDirEntriesNew == 1)
1435 fprintf(
fLogFile,
"new subdir(s):\n");
1437 iDirEntriesNew, iDirEntries, psDirList->
cFile);
1440 if (iDirEntryRem <= 0)
1443 "-W- dir %s: max no. of %d subdir entries reached\n",
1444 cDirName, iMaxDirs);
1455 iRC = closedir(pDir);
1459 fprintf(
fLogFile,
" rc(closedir) = %d\n", iRC);
1462 " %d entries in directory %s found\n",
1463 iEntries, cDirName);
1465 if (iFileEntriesNew == 0)
1467 if ( (iMatch) || (iFullMatch) )
1468 fprintf(
fLogFile,
" no new matching files found\n");
1470 fprintf(
fLogFile,
" no new files found\n");
1472 if (iDirEntriesNew == 0)
1474 if ( (iMatch) || (iFullMatch) )
1475 fprintf(
fLogFile,
" no new matching subdirs found\n");
1477 fprintf(
fLogFile,
" no new subdirs found\n");
1482 if ( (iMatch) || (iFullMatch) ) fprintf(
fLogFile,
1483 " overall %d matching files (%d new)\n",
1484 iFileEntries, iFileEntriesNew);
1486 " overall %d files (%d new)\n",
1487 iFileEntries, iFileEntriesNew);
1492 if ( (iMatch) || (iFullMatch) ) fprintf(
fLogFile,
1493 " overall %d matching subdirectories (%d new)\n",
1494 iDirEntries, iDirEntriesNew);
1496 " overall %d subdirectories (%d new)\n",
1497 iDirEntries, iDirEntriesNew);
1501 if ( (iEntryType == 0) || (iEntryType == 1) )
1502 *piFileNo = iFileEntries;
1503 if ( (iEntryType == 0) || (iEntryType == 2) )
1505 *piDirNo = iDirEntries;
1509 if ( (iRecursive == 0) && (iFullMatch) &&
1510 ( ((icurDirLevel == iMaskDirLevel) && (iDirEntriesNew == 0)) ||
1511 (icurDirLevel > iMaskDirLevel) ) )
1514 "-D- stop searching\n");
1516 goto gEndRecEntryList;
1519 strcpy(cDirNameOrig, cDirName);
1521 if ( (iDirEntriesNew) && (iLastDir == 0) &&
1522 (iRCE != -101) && (iRCE != -102) )
1524 psDirList = psDirListNew;
1525 for (iDirLoop=1; iDirLoop<=iDirEntriesNew; iDirLoop++)
1527 strcpy(cDirName, psDirList->
cFile);
1529 " next dir: %s\n", cDirName);
1538 else if ( (iMatch) && (iEntryType < 10) )
1542 iMaxFiles, ppFileList, iMaxDirs, ppDirList);
1544 if ( (iRC == -101) || (iRC == -102) )
1547 fprintf(
fLogFile,
"-W- stop scanning\n");
1556 else if ( (iRCE == -101) || (iRCE == -102) )
1559 fprintf(
fLogFile,
"-W- stop scanning\n");
1565 "-D- end %s for dir %s\n\n", cModule, cDirNameOrig);
1586 char cModule[32]=
"rawGetFSEntries";
1593 struct dirent **fEntryList;
1596 "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
1598 iRC = scandir(pcStageFS, &fEntryList, NULL, NULL);
1602 "-E- %s: calling system function scandir, rc=%d\n",
1606 fprintf(
fLogFile,
" %s\n", strerror(errno));
1614 for (ii=0; ii<iRC; ii++)
1617 " %d: %s\n", ii, fEntryList[ii]->d_name);
1619 if ( (strcmp(fEntryList[ii]->d_name,
".") == 0) ||
1620 (strcmp(fEntryList[ii]->d_name,
"..") == 0) )
1627 fprintf(
fLogFile,
"-D- end %s\n\n", cModule);
1642 char cModule[32]=
"rawGetFSfree";
1646 unsigned int itemsize, itemno;
1654 char cCmd[256] =
"/home/rawserv/rawdf.sh ";
1661 strcpy(cTempFile, pcStageFS);
1665 sprintf(cName,
"/size.t%d.p%d", (
int) tTime, pstr);
1666 strcat(cTempFile, pName);
1668 strcat(cCmd, pcStageFS);
1670 strcat(cCmd, cTempFile);
1673 fprintf(
fLogFile,
"\n-D- begin %s: execute\n '%s'\n",
1681 fprintf(
fLogFile,
"-W- %s: system() failed, rc = %d\n",
1689 " shell command successfully executed\n");
1694 fprintf(
fLogFile,
"-W- %s: system() not available\n",
1700 fPipe = fopen(cTempFile,
"r");
1703 fprintf(
fLogFile,
"-E- %s: opening file %s\n",
1704 cModule, cTempFile);
1707 fprintf(
fLogFile,
" %s\n", strerror(errno));
1715 fprintf(
fLogFile,
" file %s opened\n", cTempFile);
1717 itemsize =
sizeof(char);
1719 iBuf = fread(pBuf, itemsize, itemno, fPipe);
1722 fprintf(
fLogFile,
"-E- %s: fread, rc = %d\n", cModule, iBuf);
1725 fprintf(
fLogFile,
" %s\n", strerror(errno));
1729 fprintf(
fLogFile,
" NO status buffer sent\n");
1737 fprintf(
fLogFile,
" %d bytes in file: %s", iBuf, pBuf);
1738 fprintf(
fLogFile,
" free kB: %d\n", iFree);
1742 iRC = fclose(fPipe);
1745 fprintf(
fLogFile,
"-E- %s: rc = %d closing file\n",
1749 fprintf(
fLogFile,
" %s\n", strerror(errno));
1757 fprintf(
fLogFile,
" file %s closed\n", cTempFile);
1759 iRC = remove(cTempFile);
1762 fprintf(
fLogFile,
"-E- %s: rc = %d removing file %s\n",
1763 cModule, iRC, cTempFile);
1766 fprintf(
fLogFile,
" %s\n", strerror(errno));
1773 fprintf(
fLogFile,
" file %s removed\n", cTempFile);
1776 fprintf(
fLogFile,
"-D- end %s\n\n", cModule);
1799 char cModule[32] =
"rawGetFSSpace";
1810 struct statfs sFSstatus, *pFSstatus;
1813 "\n-D- begin %s: FS %s\n", cModule, pcFileSystem);
1815 pFSstatus = &sFSstatus;
1817 iRC = statfs(pcFileSystem, pFSstatus);
1821 "-E- %s: calling system function statfs, rc=%d\n",
1825 fprintf(
fLogFile,
" %s\n", strerror(errno));
1832 iBlockSize = (int) pFSstatus->f_bsize;
1833 if (iBlockSize == 0)
1836 "-W- unexpected blocksize found: 0 byte\n");
1842 " blocksize found %d byte\n", iBlockSize);
1843 if (iBlockSize >= 1024)
1848 "-W- unexpected blocksize found: %d byte\n", iBlockSize);
1854 iSizeAll = (int) (pFSstatus->f_blocks/1000)*iBlockSize;
1855 iSizeFree = (int) (pFSstatus->f_bfree/1000)*iBlockSize;
1856 iSizeAvail = (int) (pFSstatus->f_bavail/1000)*iBlockSize;
1858 iNodeAll = (int) pFSstatus->f_files;
1859 iNodeAvail = (
int) pFSstatus->f_ffree;
1864 " overall space %d MB, free %d MB, available %d MB\n",
1865 iSizeAll, iSizeFree, iSizeAvail);
1867 " overall file nodes %d, available %d\n",
1868 iNodeAll, iNodeAvail);
1871 *piSizeAll = iSizeAll;
1872 *piSizeAvail = iSizeAvail;
1873 *piNodeAll = iNodeAll;
1874 *piNodeAvail = iNodeAvail;
1877 fprintf(
fLogFile,
"-D- end %s\n\n", cModule);
1892 char cModule[32] =
"rawGetFileAttr";
1897 unsigned long lFileSize;
1905 char cCmd[
CMDLEN] =
"ls -l ";
1907 const char *pType =
"r";
1909 const char *pcDollar =
"$";
1913 const char *pcblank =
" ";
1922 "\n-D- begin %s: file %s\n", cModule, pcFile);
1929 ploc = strchr(pcFile, *pcDollar);
1934 fprintf(
fLogFile,
"-D- $ in file name found: %s\n", pcFile);
1937 ilen = strlen(pcFile);
1939 for (ii = 1; ii <= ilen; ii++)
1941 iloc = strncmp(pcc, pcDollar, 1);
1942 if (iloc == 0) strncat(cCmd,
"\\", 1);
1943 strncat(cCmd, pcc++, 1);
1946 else strcat(cCmd, pcFile);
1950 fprintf(
fLogFile,
"-D- %s: ex '%s'\n", cModule, cCmd);
1955 f_ifile = popen(pCmd, pType);
1956 if (f_ifile == NULL)
1958 fprintf(
fLogFile,
"-E- %s: opening pipe\n", cModule);
1963 fprintf(
fLogFile,
" %s: pipe opened\n", cModule);
1967 if ( !(pBuf0 = (
char *) malloc(
BUFSIZE)) )
1969 fprintf(
fLogFile,
"-E- %s: allocation buffer failed\n", cModule);
1975 fprintf(
fLogFile,
" %s: buffer allocated\n", cModule);
1980 lr = fread(pBuf,
sizeof(
char),
BUFSIZE, f_ifile);
1983 fprintf(
fLogFile,
"-E- %s: reading from pipe failed\n", cModule);
1989 strncpy(pBuf,
"\0", 1);
1993 fprintf(
fLogFile,
" %s: complete string: (%lu bytes): \n%s\n",
1994 cModule, lr, pBuf0);
1999 while ( (pctoken = strtok(pBuf, pcblank)) != NULL)
2004 fprintf(
fLogFile,
" token %d: %s\n", icount, pctoken);
2012 iRC = strcmp(pctoken,
".kshrc");
2015 fprintf(
fLogFile,
" %s: token %d: %s found\n",
2016 cModule, icount, pctoken);
2022 if (icount == ilocSize)
2028 if ( ( iRC = sscanf( pctoken,
"%lu", &lFileSize) ) <= 0 )
2030 fprintf(
fLogFile,
"-E- %s: filesize %lu (%s) invalid\n",
2031 cModule, lFileSize, pctoken);
2034 fprintf(
fLogFile,
" %s\n", strerror(errno));
2043 fprintf(
fLogFile,
" file size %lu\n", lFileSize);
2047 if ( (lFileSize == 0) && (iDebug) )
2048 fprintf(
fLogFile,
" file %s empty\n", pcFile);
2053 "-E- %s: file %s too large (%lu byte), max allowed 2GB -1\n",
2054 cModule, pcFile, lFileSize);
2060 if (icount == ilocFile)
2062 if ( (iRC = strcmp(pctoken, pcFile) ) != 0)
2065 "-E- %s: file name check: %s\n", cModule, pctoken);
2081 *plFileSize = lFileSize;
2084 fprintf(
fLogFile,
"-D- end %s\n\n", cModule);
2104 char cModule[32] =
"rawGetFileList";
2110 int ilen, iloc, ii, jj;
2111 int ird, ipc, ipc1, irem, grem = 0;
2112 int iFileno, iFilenoo;
2116 char *pcc, *pcc0, *ploc;
2121 char cCmd[
CMDLEN] =
"ls -L ";
2127 const char *pcDollar =
"$";
2136 fprintf(
fLogFile,
"\n-D- begin %s\n", cModule);
2138 ploc = strchr(pcFile, *pcDollar);
2142 fprintf(
fLogFile,
" '$' in file name found: %s\n", pcFile);
2143 ilen = strlen(pcFile);
2145 for (ii=1; ii<=ilen; ii++)
2147 iloc = strncmp(pcc, pcDollar, 1);
2148 if (iloc == 0) strncat(cCmd,
"\\", 1);
2149 strncat(cCmd, pcc++, 1);
2152 else strcat(cCmd, pcFile);
2153 strcat(cCmd,
" 2>/dev/null");
2156 fprintf(
fLogFile,
" command: %s\n", cCmd);
2158 piFileList = (
int *) *ppFileList;
2159 piFileno = piFileList++;
2160 iFilenoo = *piFileno;
2162 psFileList0 = psFileList;
2167 " %d old files in list\n", iFilenoo);
2169 for (ii=1; ii<=iFilenoo; ii++)
2172 " %d (old): %s\n", ii, psFileList->
cFile);
2178 f_ifile = popen(pCmd,
"r");
2179 if (f_ifile == NULL)
2181 fprintf(
fLogFile,
"-E- %s: opening pipe\n", cModule);
2184 if (iDebug) fprintf(
fLogFile,
" pipe opened\n");
2186 if ( !(pBuf = (
char *) malloc(
BUFSIZE)) )
2189 "-E- %s: allocation buffer failed\n", cModule);
2194 fprintf(
fLogFile,
" buffer allocated\n");
2203 lr = fread(pBuf,
sizeof(
char),
BUFSIZE, f_ifile);
2211 fprintf(
fLogFile,
"-D- received %d bytes:\n", ird);
2217 ipc = strcspn(pcc0,
"\n");
2218 irem = strlen(pcc0);
2219 pcc = strchr(pcc0,
'\n');
2221 "\n first length %d, total %d, remainder %d\n",
2228 strncat(cBuf, pcc0, (
unsigned) ipc);
2230 " last concatenated: %s\n", cBuf);
2236 if (strncmp(&(cBuf[ii-1]),
":", 1) == 0)
2239 "\n stop checking, ignore subdirectory %s\n",
2245 if ( (strcmp(cBuf,
"./")) &&
2247 (strncmp(&(cBuf[ii-1]),
":", 1)) )
2252 ( (iRC == 1) && (iAccept >= 1) ) )
2256 psFileList0c = psFileList0;
2259 for (jj=1; jj<=iFilenoo; jj++)
2261 iRC = strcmp(cBuf, psFileList0c->
cFile);
2266 " entry %s already available(1)\n",
2276 strcpy(psFileList->
cFile, cBuf);
2279 " %s stored(1), addr %p\n",
2280 psFileList->
cFile, psFileList);
2290 "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
2291 cModule, --iFileno);
2293 " %s: NOT ALL files handled\n",
2303 "-W- file name %s has uppercase letters - ignored\n",
2310 "-W- directory %s ignored\n", cBuf);
2315 memset(&cBuf,
'\0', strlen(cBuf));
2320 strncpy(cBuf, pcc0, (
unsigned) ipc);
2322 if (irem - ipc == 0)
2324 ipc1 = strlen(cBuf);
2326 " grem set, cBuf: %s (%d byte) \n", cBuf, ipc1);
2334 if (strncmp(&(cBuf[ii-1]),
":", 1) == 0)
2337 "\n stop checking, ignore subdirectory %s\n",
2343 if ( (strcmp(cBuf,
"./")) &&
2345 (strncmp(&(cBuf[ii-1]),
":", 1)) )
2350 ( (iRC == 1) && (iAccept >= 1) ) )
2354 psFileList0c = psFileList0;
2357 for (jj=1; jj<=iFilenoo; jj++)
2359 if (ipc == (
int) strlen(psFileList0c->
cFile))
2362 psFileList0c->
cFile,
2368 " entry %s already available(2)\n",
2379 strncpy(psFileList->
cFile, cBuf, (
unsigned) ipc);
2383 " %s stored(2), addr %p\n",
2384 psFileList->
cFile, psFileList);
2393 "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
2394 cModule, --iFileno);
2396 " %s: NOT ALL files handled\n",
2406 "-W- file name %s has uppercase letters - ignored\n",
2412 "-W- directory %s ignored\n", cBuf);
2416 memset(&cBuf,
'\0', strlen(cBuf));
2433 fprintf(
fLogFile,
"-I- no (new) files found\n");
2434 else if (iFileno > 1)
2435 fprintf(
fLogFile,
"-I- %d (new) files found\n", iFileno);
2438 if ( (iDebug) && (iFileno) )
2442 for (ii=1; ii<=iFilenoo; ii++)
2445 " %d (old): %s\n", ii, psFileList->
cFile); psFileList++;
2447 for (ii=iFilenoo+1; ii<=iFilenoo+iFileno; ii++)
2450 " %d: %s\n", ii, psFileList->
cFile); psFileList++;
2454 iFileno += iFilenoo;
2455 piFileno[0] = iFileno;
2457 iRC = pclose(f_ifile);
2462 fprintf(
fLogFile,
"-E- %s: iRC = %d closing pipe\n",
2466 fprintf(
fLogFile,
" %s\n", strerror(errno));
2471 fprintf(
fLogFile,
" pipe closed\n");
2473 fprintf(
fLogFile,
"-D- end %s\n\n", cModule);
2494 char cModule[32] =
"rawGetHostConn";
2507 char cToken[16] =
"", *pToken;
2508 char cheadName[16], *pheadName;
2509 char cheadMtu[16] =
"mtu", *pheadMtu;
2510 char cName[16] =
"", *pName;
2511 char cMtu[16] =
"", *pMtu;
2512 char cNameRef1[16] =
"";
2513 char cNameRef2[16] =
"";
2515 char cCmd[
CMDLEN] =
"netstat -i", *pCmd;
2516 char cBuf[1024] =
"", *pBuf;
2522 fprintf(
fLogFile,
"\n-D- in %s\n", cModule);
2525 strcpy(cheadName,
"name");
2527 strcpy(cheadName,
"iface");
2530 iRC = gethostname(cNode,
MAX_NODE);
2534 "-E- %s: getting client host name: %s\n",
2535 cModule, strerror(iRC));
2539 " %s: client host %s\n", cModule, cNode);
2541 if (strncmp(cNode,
"lx", 2) == 0)
2543 if (strncmp(cNode,
"linux", 5) == 0)
2545 if (strncmp(cNode,
"sp2", 3) == 0)
2548 pToken = &cToken[0];
2549 pheadName = &cheadName[0];
2550 pheadMtu = &cheadMtu[0];
2556 f_ifile = popen(pCmd,
"r");
2557 if (f_ifile == NULL)
2559 fprintf(
fLogFile,
"-E- %s: opening pipe\n", cModule);
2563 fprintf(
fLogFile,
" %s: pipe opened\n", cModule);
2565 iBuf = fread(pBuf,
sizeof(
char), 1024, f_ifile);
2568 fprintf(
fLogFile,
"-E- %s: reading from pipe failed\n", cModule);
2573 fprintf(
fLogFile,
" %s command output: \n%s", cModule, cBuf);
2575 pToken = strtok(pBuf,
" \n");
2577 while (*pcc !=
'\0')
2579 *pcc = tolower(*pcc);
2583 if (strcmp(pToken, pheadName))
2585 fprintf(
fLogFile,
"-E- %s: invalid name heading (%s, expected %s)\n",
2586 cModule, pToken, pheadName);
2590 pToken = strtok(NULL,
" \n");
2592 while (*pcc !=
'\0')
2594 *pcc = tolower(*pcc);
2598 if (strcmp(pToken, pheadMtu))
2600 fprintf(
fLogFile,
"-E- %s: invalid mtu heading (%s, expected %s)\n",
2601 cModule, pToken, pheadMtu);
2607 strcpy(cNameRef1,
"en0");
2608 strcpy(cNameRef2,
"fi0");
2612 strcpy(cNameRef1,
"eth0");
2613 strcpy(cNameRef2,
"fdd0");
2616 for (ii=1; ii<=iCol-2; ii++)
2617 { pToken = strtok(NULL,
" \n"); }
2621 pToken = strtok(NULL,
" \n");
2622 if (pToken == NULL)
break;
2624 while (*pcc !=
'\0')
2626 *pcc = tolower(*pcc);
2631 fprintf(
fLogFile,
"DDD %s: %s\n", cModule, pToken);
2633 if (strcmp(pToken, cNameRef1) == 0)
2637 fprintf(
fLogFile,
" %s: ethernet available\n", cModule);
2639 else if (strcmp(pToken, cNameRef2) == 0)
2647 if ( (iType != 3) && (iType != 1) )
2650 "-E- %s: invalid network connection type (%d)\n",
2655 fprintf(
fLogFile,
"-D- end %s: network connection type %d\n\n",
2678 char cModule[32] =
"rawGetBaseDir";
2681 char *pcc, *pcc1, *pcc2;
2687 strcpy(cBaseDir, pcVarDir);
2689 pcc = strchr(cBaseDir, *
pcStar);
2690 pcc1 = strchr(cBaseDir, *
pcQM);
2691 pcc2 = strchr(cBaseDir, *
pcPerc);
2695 fprintf(
fLogFile,
"\n-D- begin %s\n", cModule);
2699 fprintf(
fLogFile,
" %s contains '%s'\n", cBaseDir,
pcQM);
2774 "-E- dir %s: generic flag set, but no wildcard chars found\n",
2784 strncpy(pcc,
"\0", 1);
2786 strncpy(pcc1,
"\0", 1);
2788 strncpy(pcc2,
"\0", 1);
2790 pcc = strrchr(cBaseDir,
'/');
2793 fprintf(
fLogFile,
"-E- invalid top directory %s\n", cBaseDir);
2799 if (pcc == cBaseDir)
2801 strncpy(pcc,
"\0", 1);
2804 " top directory above wildcard chars: %s\n", cBaseDir);
2807 strcpy(pcBaseDir, cBaseDir);
2812 fprintf(
fLogFile,
"-D- end %s\n\n", cModule);
2825 char cModule[32] =
"rawGetUserid";
2831 char cCmd[
CMDLEN] =
"whoami";
2836 f_ifile = popen(pCmd,
"r");
2837 if (f_ifile == NULL)
2839 fprintf(
fLogFile,
"-E- %s: opening pipe\n", cModule);
2843 fprintf(
fLogFile,
" %s: pipe opened\n", cModule);
2845 if ( !(pBuf0 = (
char *) malloc(
BUFSIZE)) )
2847 fprintf(
fLogFile,
"-E- %s: allocation buffer failed\n", cModule);
2852 fprintf(
fLogFile,
" %s: buffer allocated\n", cModule);
2855 lr = fread(pBuf,
sizeof(
char),
BUFSIZE, f_ifile);
2858 fprintf(
fLogFile,
"-E- %s: reading from pipe failed\n", cModule);
2864 strncpy(pBuf,
"\0", 1);
2868 if (iDebug) fprintf(
fLogFile,
"-D- %s: user name (%u bytes): %s\n", cModule, lr, pBuf0);
int rawGetFileList(char *pcFile, int iAccept, int iEntryLoop, char **ppFileList)
int rawGetDirEntryList(char *pcDirName, char *pcEntryMask, int iEntryType, int iEntryLoop, int iPrefixDir, char **ppFileList, char **ppDirList)
int rawGetFSfree(char *pcStageFS)
int rawGetRecEntryList(char *pcDirName, char *pcEntryMask, int iEntryType, int iMaxFiles, char **ppFileList, int iMaxDirs, char **ppDirList)
int rawGetFSSpace(char *pcFileSystem, int *piSizeAll, int *piSizeAvail, int *piNodeAll, int *piNodeAvail)
int rawGetFSEntries(char *pcStageFS)
int rawGetBaseDir(char *pcVarDir, char *pcBaseDir)
int rawGetFileAttr(char *pcFile, unsigned long *plFileSize)
int rawGetDirEntries(char *pcStageFS)
static const char * pcPerc
static const char * pcStar
int rawTestFileName(char *)
char cFile[MAX_FULL_FILE]