diff --git a/setter/src/CMakeLists.txt b/setter/src/CMakeLists.txt index 3badd2f..85f88ac 100644 --- a/setter/src/CMakeLists.txt +++ b/setter/src/CMakeLists.txt @@ -22,6 +22,6 @@ # Copyright (C) 2011-2021 Natalia Portillo # *****************************************************************************/ -set(MAIN_SOURCES main.c main.h) +set(MAIN_SOURCES main.c main.h log.c log.h) add_library(core ${MAIN_SOURCES}) diff --git a/setter/src/dos/attr.c b/setter/src/dos/attr.c index a919626..bb3102b 100644 --- a/setter/src/dos/attr.c +++ b/setter/src/dos/attr.c @@ -33,6 +33,7 @@ Copyright (C) 2011-2021 Natalia Portillo #endif #include "../include/defs.h" +#include "../log.h" #include "attr.h" #include "dos.h" @@ -53,13 +54,13 @@ void FileAttributes(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } chdir("ATTRS"); - printf("Creating attributes files.\n"); + log_write("Creating attributes files.\n"); for(i = 0; i < KNOWN_DOS_ATTRS; i++) { @@ -72,11 +73,11 @@ void FileAttributes(const char* path) rc = _dos_setfileattr(dos_attrs[i].filename, dos_attrs[i].attr); } - printf("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", - dos_attrs[i].description, - dos_attrs[i].filename, - rc, - wRc, - cRc); + log_write("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", + dos_attrs[i].description, + dos_attrs[i].filename, + rc, + wRc, + cRc); } } diff --git a/setter/src/dos/deleted.c b/setter/src/dos/deleted.c index fffa95b..bf35932 100644 --- a/setter/src/dos/deleted.c +++ b/setter/src/dos/deleted.c @@ -33,6 +33,7 @@ Copyright (C) 2011-2021 Natalia Portillo #endif #include "../include/defs.h" +#include "../log.h" #include "dos.h" void DeleteFiles(const char* path) @@ -53,13 +54,13 @@ void DeleteFiles(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } chdir("DELETED"); - printf("Creating and deleting files.\n"); + log_write("Creating and deleting files.\n"); for(pos = 0; pos < 64; pos++) { diff --git a/setter/src/dos/dirdepth.c b/setter/src/dos/dirdepth.c index 6ddd3b6..23b2fca 100644 --- a/setter/src/dos/dirdepth.c +++ b/setter/src/dos/dirdepth.c @@ -33,6 +33,7 @@ Copyright (C) 2011-2021 Natalia Portillo #endif #include "../include/defs.h" +#include "../log.h" #include "dos.h" void DirectoryDepth(const char* path) @@ -52,13 +53,13 @@ void DirectoryDepth(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = chdir("DEPTH"); - printf("Creating deepest directory tree.\n"); + log_write("Creating deepest directory tree.\n"); while(!rc) { @@ -71,5 +72,5 @@ void DirectoryDepth(const char* path) pos++; } - printf("\tCreated %d levels of directory hierarchy\n", pos); + log_write("\tCreated %d levels of directory hierarchy\n", pos); } diff --git a/setter/src/dos/filename.c b/setter/src/dos/filename.c index a14f5a3..9653d20 100644 --- a/setter/src/dos/filename.c +++ b/setter/src/dos/filename.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "dos.h" void Filenames(const char* path) @@ -54,13 +55,13 @@ void Filenames(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } chdir("FILENAME"); - printf("Creating files with different filenames.\n"); + log_write("Creating files with different filenames.\n"); for(pos = 0; filenames[pos]; pos++) { @@ -74,6 +75,6 @@ void Filenames(const char* path) cRc = _dos_close(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); } } diff --git a/setter/src/dos/files.c b/setter/src/dos/files.c index 5725d74..8a93076 100644 --- a/setter/src/dos/files.c +++ b/setter/src/dos/files.c @@ -33,6 +33,7 @@ Copyright (C) 2011-2021 Natalia Portillo #endif #include "../include/defs.h" +#include "../log.h" #include "dos.h" void MillionFiles(const char* path) @@ -53,13 +54,13 @@ void MillionFiles(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } chdir("MILLION"); - printf("Creating lots of files.\n"); + log_write("Creating lots of files.\n"); for(pos = 0; pos < 1000; pos++) { @@ -71,5 +72,5 @@ void MillionFiles(const char* path) _dos_close(handle); } - printf("\tCreated %d files\n", pos); + log_write("\tCreated %d files\n", pos); } diff --git a/setter/src/dos/frag.c b/setter/src/dos/frag.c index 24525e1..5997778 100644 --- a/setter/src/dos/frag.c +++ b/setter/src/dos/frag.c @@ -36,6 +36,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "dos.h" void Fragmentation(const char* path, size_t clusterSize) @@ -61,7 +62,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } @@ -80,7 +81,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); rc = _dos_creatnew("QUARCLST", _A_NORMAL, &handle); if(!rc) @@ -95,7 +96,8 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); + log_write( + "\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); rc = _dos_creatnew("TWOCLST", _A_NORMAL, &handle); if(!rc) @@ -110,7 +112,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); rc = _dos_creatnew("TRQTCLST", _A_NORMAL, &handle); if(!rc) @@ -125,12 +127,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "TRQTCLST", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "TRQTCLST", + threeQuartersCluster, + rc, + wRc, + cRc); rc = _dos_creatnew("TWTQCLST", _A_NORMAL, &handle); if(!rc) @@ -145,12 +147,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "TWTQCLST", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "TWTQCLST", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); rc = _dos_creatnew("TWO1", _A_NORMAL, &handle); if(!rc) @@ -165,7 +167,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); rc = _dos_creatnew("TWO2", _A_NORMAL, &handle); if(!rc) @@ -180,7 +182,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); rc = _dos_creatnew("TWO3", _A_NORMAL, &handle); if(!rc) @@ -195,10 +197,10 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO2\".\n"); + log_write("\tDeleting \"TWO2\".\n"); rc = unlink("TWO2"); - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); rc = _dos_creatnew("FRAGTHRQ", _A_NORMAL, &handle); if(!rc) @@ -213,17 +215,17 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO1\".\n"); + log_write("\tDeleting \"TWO1\".\n"); unlink("TWO1"); - printf("\tDeleting \"TWO3\".\n"); + log_write("\tDeleting \"TWO3\".\n"); rc = unlink("TWO3"); - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "FRAGTHRQ", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "FRAGTHRQ", + threeQuartersCluster, + rc, + wRc, + cRc); rc = _dos_creatnew("FRAGSIXQ", _A_NORMAL, &handle); if(!rc) @@ -238,10 +240,10 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "FRAGSIXQ", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "FRAGSIXQ", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); } diff --git a/setter/src/dos/os.c b/setter/src/dos/os.c index 045061c..608934e 100644 --- a/setter/src/dos/os.c +++ b/setter/src/dos/os.c @@ -31,6 +31,7 @@ Copyright (C) 2011-2021 Natalia Portillo #endif #include "../include/defs.h" +#include "../log.h" #include "dos.h" #include "dosuname.h" @@ -45,55 +46,49 @@ void GetOsInfo() switch(dosuname_version.flavor) { case DOS_FLAVOR_UNKNOWN: - printf("OS information:\n"); - printf("\tRunning under DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_MSDOS: - printf("OS information:\n"); - printf("\tRunning under MS-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under MS-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_PCDOS: - printf("OS information:\n"); - printf("\tRunning under PC-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under PC-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_DRDOS: - printf("OS information:\n"); - printf("\tRunning under DR-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under DR-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_FREEDOS: - printf("OS information:\n"); - printf("\tRunning under FreeDOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under FreeDOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_WIN95: case DOS_FLAVOR_WIN9X: - case DOS_FLAVOR_WINME: - printf("Will not run under Windows 9x. Exiting...\n"); - exit(1); - case DOS_FLAVOR_WINNT: - printf("Will not run under Windows NT. Exiting...\n"); - exit(1); - case DOS_FLAVOR_OS2: - printf("Will not run under OS/2. Exiting...\n"); - exit(1); + case DOS_FLAVOR_WINME: log_write("Will not run under Windows 9x. Exiting...\n"); exit(1); + case DOS_FLAVOR_WINNT: log_write("Will not run under Windows NT. Exiting...\n"); exit(1); + case DOS_FLAVOR_OS2: log_write("Will not run under OS/2. Exiting...\n"); exit(1); case DOS_FLAVOR_PTSDOS: - printf("OS information:\n"); - printf("\tRunning under PTS-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under PTS-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_RXDOS: - printf("OS information:\n"); - printf("\tRunning under RxDOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under RxDOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_CONCURRENTDOS: - printf("OS information:\n"); - printf("\tRunning under Concurrent DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under Concurrent DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_NOVELLDOS: - printf("OS information:\n"); - printf("\tRunning under Novell DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under Novell DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; case DOS_FLAVOR_MSPCDOS: - printf("OS information:\n"); - printf("\tRunning under MS-DOS or PC-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); + log_write("OS information:\n"); + log_write("\tRunning under MS-DOS or PC-DOS %d.%d\n", dosuname_version.major, dosuname_version.minor); break; } } diff --git a/setter/src/dos/time.c b/setter/src/dos/time.c index fc9c622..2f8693c 100644 --- a/setter/src/dos/time.c +++ b/setter/src/dos/time.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #endif #include "../include/defs.h" +#include "../log.h" #include "dos.h" #include "time.h" @@ -56,13 +57,13 @@ void Timestamps(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } chdir("TIMES"); - printf("Creating timestamped files.\n"); + log_write("Creating timestamped files.\n"); for(i = 0; i < KNOWN_DOS_TIMES; i++) { @@ -92,7 +93,7 @@ void Timestamps(const char* path) cRc = _dos_close(handle); } - printf( + log_write( "\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", dos_times[i].filename, rc, wRc, cRc, tRc); } } diff --git a/setter/src/dos/volume.c b/setter/src/dos/volume.c index de768ae..d73f88a 100644 --- a/setter/src/dos/volume.c +++ b/setter/src/dos/volume.c @@ -29,6 +29,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "dos.h" void GetVolumeInfo(const char* path, size_t* clusterSize) @@ -57,23 +58,23 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) } else { - printf("Error %d requesting volume information.\n", _doserrno); + log_write("Error %d requesting volume information.\n", _doserrno); return; } } if(rc == 0) { - printf("\tBytes per sector: %lu\n", freeSpace.bytesPerSector); - printf("\tSectors per cluster: %lu (%lu bytes)\n", - freeSpace.sectorsPerCluster, - freeSpace.sectorsPerCluster * freeSpace.bytesPerSector); - printf("\tClusters: %lu (%lu bytes)\n", - freeSpace.totalClusters, - freeSpace.sectorsPerCluster * freeSpace.bytesPerSector * freeSpace.totalClusters); - printf("\tFree clusters: %lu (%lu bytes)\n", - freeSpace.freeClusters, - freeSpace.sectorsPerCluster * freeSpace.bytesPerSector * freeSpace.freeClusters); + log_write("\tBytes per sector: %lu\n", freeSpace.bytesPerSector); + log_write("\tSectors per cluster: %lu (%lu bytes)\n", + freeSpace.sectorsPerCluster, + freeSpace.sectorsPerCluster * freeSpace.bytesPerSector); + log_write("\tClusters: %lu (%lu bytes)\n", + freeSpace.totalClusters, + freeSpace.sectorsPerCluster * freeSpace.bytesPerSector * freeSpace.totalClusters); + log_write("\tFree clusters: %lu (%lu bytes)\n", + freeSpace.freeClusters, + freeSpace.sectorsPerCluster * freeSpace.bytesPerSector * freeSpace.freeClusters); *clusterSize = freeSpace.sectorsPerCluster * freeSpace.bytesPerSector; } diff --git a/setter/src/linux/attr.c b/setter/src/linux/attr.c index 35158be..8e78596 100644 --- a/setter/src/linux/attr.c +++ b/setter/src/linux/attr.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "attr.h" +#include "../log.h" #include "linux.h" void LinuxFileAttributes(const char* path) @@ -50,7 +51,7 @@ void LinuxFileAttributes(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -58,7 +59,7 @@ void LinuxFileAttributes(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -66,11 +67,11 @@ void LinuxFileAttributes(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating files with different flags (attributes).\n"); + log_write("Creating files with different flags (attributes).\n"); for(i = 0; i < KNOWN_LINUX_ATTRS; i++) { @@ -105,6 +106,6 @@ void LinuxFileAttributes(const char* path) ret = fclose(h); if(ret) { cRc = errno; } } - printf("\t%s, rc = %d, wRc = %d, sRc = %d, cRc = %d\n", linux_attrs[i].description, rc, wRc, sRc, cRc); + log_write("\t%s, rc = %d, wRc = %d, sRc = %d, cRc = %d\n", linux_attrs[i].description, rc, wRc, sRc, cRc); } } diff --git a/setter/src/linux/sparse.c b/setter/src/linux/sparse.c index 4a18a65..e8dffed 100644 --- a/setter/src/linux/sparse.c +++ b/setter/src/linux/sparse.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include +#include "../log.h" #include "linux.h" void LinuxSparse(const char* path) @@ -47,7 +48,7 @@ void LinuxSparse(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -55,7 +56,7 @@ void LinuxSparse(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -63,11 +64,11 @@ void LinuxSparse(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating sparse files.\n"); + log_write("Creating sparse files.\n"); h = fopen("SMALL", "w+"); rc = 0; @@ -99,13 +100,13 @@ void LinuxSparse(const char* path) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", - "SMALL", - 4096 * 3, - rc, - wRc, - cRc, - zRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", + "SMALL", + 4096 * 3, + rc, + wRc, + cRc, + zRc); h = fopen("BIG", "w+"); rc = 0; @@ -137,11 +138,11 @@ void LinuxSparse(const char* path) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", - "BIG", - 4096 * 30, - rc, - wRc, - cRc, - zRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d, sRc = %d\n", + "BIG", + 4096 * 30, + rc, + wRc, + cRc, + zRc); } diff --git a/setter/src/linux/xattr.c b/setter/src/linux/xattr.c index b2ab248..d541fa4 100644 --- a/setter/src/linux/xattr.c +++ b/setter/src/linux/xattr.c @@ -29,6 +29,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include +#include "../log.h" #include "linux.h" #if((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 3)) || (__GLIBC__ > 2) @@ -47,7 +48,7 @@ void LinuxExtendedAttributes(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -55,7 +56,7 @@ void LinuxExtendedAttributes(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -63,11 +64,11 @@ void LinuxExtendedAttributes(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating files with extended attributes.\n"); + log_write("Creating files with extended attributes.\n"); rc = 0; cRc = 0; @@ -81,7 +82,7 @@ void LinuxExtendedAttributes(const char* path) if(ret) cRc = errno; } - printf("\tFile with an extended attribute called \"com.ibm.os2.comment\", rc = %d, cRc = %d\n", rc, cRc); + log_write("\tFile with an extended attribute called \"com.ibm.os2.comment\", rc = %d, cRc = %d\n", rc, cRc); rc = 0; cRc = 0; @@ -95,6 +96,6 @@ void LinuxExtendedAttributes(const char* path) if(ret) cRc = errno; } - printf("\tFile with an extended attribute called \"com.ibm.os2.icon\", rc = %d, cRc = %d\n", rc, cRc); + log_write("\tFile with an extended attribute called \"com.ibm.os2.icon\", rc = %d, cRc = %d\n", rc, cRc); #endif } diff --git a/setter/src/log.c b/setter/src/log.c new file mode 100644 index 0000000..ce02ef2 --- /dev/null +++ b/setter/src/log.c @@ -0,0 +1,110 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#include +#include +#include +#include + +#include "log.h" + +#include "main.h" + +static int log_opened; +static int log_quiet; +FILE* log_file; + +int log_open(int quiet) +{ + time_t curtime; + + log_opened = 0; + log_quiet = 0; + + curtime = time(NULL); + + log_file = fopen("fssetter.log", "a+"); + + if(log_file == NULL) + { + fprintf(stderr, "Error %d opening log.\n", errno); + return 1; + } + + fprintf(log_file, "Aaru Filesystem Tester (Setter) %s\n", AARU_FSTESTER_VERSION); + fprintf(log_file, "%s\n", AARU_COPYRIGHT); + fprintf(log_file, "==============================================\n"); + fprintf(log_file, "Log started on %s\n\n", asctime(gmtime(&curtime))); + fflush(log_file); + + log_opened = 1; + log_quiet = quiet; + + return 0; +} + +void log_write(const char* fmt, ...) +{ + va_list args; + + if(log_opened) + { + va_start(args, fmt); + vfprintf(log_file, fmt, args); + va_end(args); + + fflush(log_file); + } + + if(!log_quiet) + { + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + } +} + +void log_close() +{ + time_t curtime; + if(!log_opened) return; + + curtime = time(NULL); + + fprintf(log_file, "==============================================\n"); + fprintf(log_file, "Log finished on %s\n", asctime(gmtime(&curtime))); + fprintf(log_file, "==============================================\n\n"); + + fclose(log_file); + + log_file = NULL; + log_opened = 0; + log_quiet = 0; +} + +void log_set_quiet(int quiet) +{ + log_file = NULL; + log_quiet = quiet; +} diff --git a/setter/src/log.h b/setter/src/log.h new file mode 100644 index 0000000..ebadfde --- /dev/null +++ b/setter/src/log.h @@ -0,0 +1,33 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#ifndef AARU_FSTESTER_ETTER_SRC_LOG_H_ +#define AARU_FSTESTER_SETTER_SRC_LOG_H_ + +int log_open(int quiet); +void log_write(const char* fmt, ...); +void log_set_quiet(int quiet); +void log_close(); + +#endif // AARU_FSTESTER_SETTER_SRC_LOG_H_ diff --git a/setter/src/macos/CMakeLists.txt b/setter/src/macos/CMakeLists.txt index 60aa8dc..5fa0ae2 100644 --- a/setter/src/macos/CMakeLists.txt +++ b/setter/src/macos/CMakeLists.txt @@ -72,4 +72,4 @@ set(EXECUTABLE_NAME "fssetter-macos-${PROCESSOR}") #target_link_libraries(${EXECUTABLE_NAME} core) -add_application(${EXECUTABLE_NAME} ../main.c ${PLATFORM_SOURCES}) \ No newline at end of file +add_application(${EXECUTABLE_NAME} ../main.c ../log.c ${PLATFORM_SOURCES}) \ No newline at end of file diff --git a/setter/src/macos/attr.c b/setter/src/macos/attr.c index 8090e64..112901c 100644 --- a/setter/src/macos/attr.c +++ b/setter/src/macos/attr.c @@ -33,6 +33,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "attr.h" #include "macos.h" @@ -57,7 +58,7 @@ void FileAttributes(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -73,13 +74,13 @@ void FileAttributes(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } dirId = dirPB.fileParam.ioDirID; - printf("Creating attribute files.\n"); + log_write("Creating attribute files.\n"); for(i = 0; i < KNOWN_MAC_ATTRS; i++) { @@ -115,11 +116,11 @@ void FileAttributes(const char* path) } } - printf("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", - mac_attrs[i].description, - mac_attrs[i].filename, - rc, - wRc, - cRc); + log_write("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", + mac_attrs[i].description, + mac_attrs[i].filename, + rc, + wRc, + cRc); } } diff --git a/setter/src/macos/deleted.c b/setter/src/macos/deleted.c index d6831a2..e4b6ef5 100644 --- a/setter/src/macos/deleted.c +++ b/setter/src/macos/deleted.c @@ -33,6 +33,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "macos.h" void DeleteFiles(const char* path) @@ -53,7 +54,7 @@ void DeleteFiles(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -69,13 +70,13 @@ void DeleteFiles(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } dirId = dirPB.fileParam.ioDirID; - printf("Creating and deleting files.\n"); + log_write("Creating and deleting files.\n"); for(pos = 0; pos < 64; pos++) { diff --git a/setter/src/macos/dirdepth.c b/setter/src/macos/dirdepth.c index 0ae38e1..bb704bb 100644 --- a/setter/src/macos/dirdepth.c +++ b/setter/src/macos/dirdepth.c @@ -29,6 +29,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "macos.h" void DirectoryDepth(const char* path) @@ -49,7 +50,7 @@ void DirectoryDepth(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -65,11 +66,11 @@ void DirectoryDepth(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } - printf("Creating deepest directory tree.\n"); + log_write("Creating deepest directory tree.\n"); while(!rc) { @@ -94,5 +95,5 @@ void DirectoryDepth(const char* path) if(pos == 500) break; } - printf("\tCreated %d levels of directory hierarchy\n", pos); + log_write("\tCreated %d levels of directory hierarchy\n", pos); } diff --git a/setter/src/macos/filename.c b/setter/src/macos/filename.c index 09b4273..c661d08 100644 --- a/setter/src/macos/filename.c +++ b/setter/src/macos/filename.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "macos.h" void Filenames(const char* path) @@ -56,7 +57,7 @@ void Filenames(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -72,13 +73,13 @@ void Filenames(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } dirId = dirPB.fileParam.ioDirID; - printf("Creating files with different filenames.\n"); + log_write("Creating files with different filenames.\n"); for(pos = 0; filenames[pos]; pos++) { @@ -102,6 +103,6 @@ void Filenames(const char* path) } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); } } diff --git a/setter/src/macos/files.c b/setter/src/macos/files.c index afe55d6..34bcc57 100644 --- a/setter/src/macos/files.c +++ b/setter/src/macos/files.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "macos.h" void MillionFiles(const char* path) @@ -54,7 +55,7 @@ void MillionFiles(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -72,11 +73,11 @@ void MillionFiles(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } - printf("Creating lots of files.\n"); + log_write("Creating lots of files.\n"); for(pos = 0; pos < 5000; pos++) { @@ -90,5 +91,5 @@ void MillionFiles(const char* path) if(rc) break; } - printf("\tCreated %d files\n", pos); + log_write("\tCreated %d files\n", pos); } diff --git a/setter/src/macos/frag.c b/setter/src/macos/frag.c index df2a03b..80be037 100644 --- a/setter/src/macos/frag.c +++ b/setter/src/macos/frag.c @@ -35,15 +35,16 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "macos.h" void Fragmentation(const char* path, size_t clusterSize) { - int32_t halfCluster = (int32_t)clusterSize / 2; - int32_t quarterCluster = (int32_t)clusterSize / 4; - int32_t twoCluster = (int32_t)clusterSize * 2; - int32_t threeQuartersCluster = halfCluster + quarterCluster; - int32_t twoAndThreeQuartCluster = threeQuartersCluster + twoCluster; + int32_t halfCluster = (int32_t)clusterSize / 2; + int32_t quarterCluster = (int32_t)clusterSize / 4; + int32_t twoCluster = (int32_t)clusterSize * 2; + int32_t threeQuartersCluster = halfCluster + quarterCluster; + int32_t twoAndThreeQuartCluster = threeQuartersCluster + twoCluster; unsigned char* buffer; OSErr rc, wRc, cRc; Str255 str255; @@ -62,7 +63,7 @@ void Fragmentation(const char* path, size_t clusterSize) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -80,7 +81,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } @@ -102,7 +103,7 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); rc = HCreate(refNum, dirId, "\pQUARCLST", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -122,7 +123,8 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); + log_write( + "\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); rc = HCreate(refNum, dirId, "\pTWOCLST", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -142,7 +144,7 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); rc = HCreate(refNum, dirId, "\pTRQTCLST", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -162,12 +164,12 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", - "TRQTCLST", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", + "TRQTCLST", + threeQuartersCluster, + rc, + wRc, + cRc); rc = HCreate(refNum, dirId, "\pTWOQCLST", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -187,12 +189,12 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", - "TWTQCLST", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", + "TWTQCLST", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); rc = HCreate(refNum, dirId, "\pTWO1", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -212,7 +214,7 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); rc = HCreate(refNum, dirId, "\pTWO2", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -232,7 +234,7 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); rc = HCreate(refNum, dirId, "\pTWO3", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -252,10 +254,10 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tDeleting \"TWO2\".\n"); + log_write("\tDeleting \"TWO2\".\n"); rc = HDelete(refNum, dirId, "\pTWO2"); - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); rc = HCreate(refNum, dirId, "\pFRAGTHRQ", ostUnknown, ftGenericDocumentPC); if(!rc) @@ -275,9 +277,9 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tDeleting \"TWO1\".\n"); + log_write("\tDeleting \"TWO1\".\n"); rc = HDelete(refNum, dirId, "\pTWO1"); - printf("\tDeleting \"TWO3\".\n"); + log_write("\tDeleting \"TWO3\".\n"); rc = HDelete(refNum, dirId, "\pTWO3"); rc = HCreate(refNum, dirId, "\pFRAGSIXQ", ostUnknown, ftGenericDocumentPC); @@ -298,10 +300,10 @@ void Fragmentation(const char* path, size_t clusterSize) } } - printf("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", - "FRAGSIXQ", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %ld, rc = %d, wRc = %d, cRc = %d\n", + "FRAGSIXQ", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); } diff --git a/setter/src/macos/links.c b/setter/src/macos/links.c index f849c13..71e85fb 100644 --- a/setter/src/macos/links.c +++ b/setter/src/macos/links.c @@ -40,6 +40,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "links.h" #include "macos.h" @@ -94,7 +95,7 @@ void Links(const char* path) rc = Gestalt(gestaltAliasMgrAttr, &gestaltResponse); if(rc || !(gestaltResponse & (1 << gestaltAliasMgrPresent))) { - printf("Alias Manager not present, cannot create aliases.\n"); + log_write("Alias Manager not present, cannot create aliases.\n"); return; } @@ -105,7 +106,7 @@ void Links(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -121,13 +122,13 @@ void Links(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } dirId = dirPB.fileParam.ioDirID; - printf("Creating aliases.\n"); + log_write("Creating aliases.\n"); for(pos = 0; pos < 64; pos++) { @@ -166,5 +167,5 @@ void Links(const char* path) if(aRc) break; } - printf("pos = %d, rc = %d, wRc = %d, cRc = %d, oRc = %d, aRc = %d\n", pos, rc, wRc, cRc, oRc, aRc); + log_write("pos = %d, rc = %d, wRc = %d, cRc = %d, oRc = %d, aRc = %d\n", pos, rc, wRc, cRc, oRc, aRc); } diff --git a/setter/src/macos/os.c b/setter/src/macos/os.c index c84b4e8..fa1a298 100644 --- a/setter/src/macos/os.c +++ b/setter/src/macos/os.c @@ -28,6 +28,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "macos.h" void GetOsInfo() @@ -35,35 +36,35 @@ void GetOsInfo() int32_t gestaltResponse; OSErr rc; - printf("OS information:\n"); + log_write("OS information:\n"); rc = Gestalt(gestaltAUXVersion, &gestaltResponse); - if(!rc) { printf("Running under A/UX version 0x%08lX\n", gestaltResponse); } + if(!rc) { log_write("Running under A/UX version 0x%08lX\n", gestaltResponse); } else { rc = Gestalt(gestaltSystemVersion, &gestaltResponse); - if(rc) { printf("Could not get Mac OS version.\n"); } + if(rc) { log_write("Could not get Mac OS version.\n"); } else { - printf("Running under Mac OS version %ld.%ld.%ld", - (gestaltResponse & 0xF00) >> 8, - (gestaltResponse & 0xF0) >> 4, - gestaltResponse & 0xF); + log_write("Running under Mac OS version %ld.%ld.%ld", + (gestaltResponse & 0xF00) >> 8, + (gestaltResponse & 0xF0) >> 4, + gestaltResponse & 0xF); rc = Gestalt(gestaltSysArchitecture, &gestaltResponse); if(!rc) { - printf(" for "); + log_write(" for "); switch(gestaltResponse) { - case 1: printf("Motorola 68k architecture."); break; - case 2: printf("PowerPC architecture."); break; - case 3: printf("x86 architecture."); break; - default: printf("unknown architecture code %ld.", gestaltResponse); break; + case 1: log_write("Motorola 68k architecture."); break; + case 2: log_write("PowerPC architecture."); break; + case 3: log_write("x86 architecture."); break; + default: log_write("unknown architecture code %ld.", gestaltResponse); break; } } - printf("\n"); + log_write("\n"); } rc = Gestalt(gestaltMacOSCompatibilityBoxAttr, &gestaltResponse); - if(!rc) { printf("Running under Classic.\n"); } + if(!rc) { log_write("Running under Classic.\n"); } } } diff --git a/setter/src/macos/rsrcfork.c b/setter/src/macos/rsrcfork.c index 1528548..3de819d 100644 --- a/setter/src/macos/rsrcfork.c +++ b/setter/src/macos/rsrcfork.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "macos.h" #include "rsrcfork.h" @@ -95,7 +96,7 @@ void ResourceFork(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -111,13 +112,13 @@ void ResourceFork(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } dirId = dirPB.fileParam.ioDirID; - printf("Creating resource forks.\n"); + log_write("Creating resource forks.\n"); memset(&finderInfo, 0, sizeof(FInfo)); rc = HCreate(refNum, dirId, "\pICON", ostUnknown, ftGenericDocumentPC); @@ -150,12 +151,12 @@ void ResourceFork(const char* path) rc = PBHSetFInfoSync(&fpb); } } - printf("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", - "ICON", - rc, - wRc, - cRc, - rRc); + log_write("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", + "ICON", + rc, + wRc, + cRc, + rRc); memset(&finderInfo, 0, sizeof(FInfo)); rc = HCreate(refNum, dirId, "\pPICT", ostUnknown, ftGenericDocumentPC); @@ -189,12 +190,12 @@ void ResourceFork(const char* path) rc = PBHSetFInfoSync(&fpb); } } - printf("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", - "PICT", - rc, - wRc, - cRc, - rRc); + log_write("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", + "PICT", + rc, + wRc, + cRc, + rRc); memset(&finderInfo, 0, sizeof(FInfo)); rc = HCreate(refNum, dirId, "\pVERSION", ostUnknown, ftGenericDocumentPC); @@ -226,12 +227,12 @@ void ResourceFork(const char* path) rc = PBHSetFInfoSync(&fpb); } } - printf("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", - "VERSION", - rc, - wRc, - cRc, - rRc); + log_write("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d\n", + "VERSION", + rc, + wRc, + cRc, + rRc); memset(&finderInfo, 0, sizeof(FInfo)); rc = HCreate(refNum, dirId, "\pALL", ostUnknown, ftGenericDocumentPC); @@ -280,13 +281,14 @@ void ResourceFork(const char* path) rc = PBHSetFInfoSync(&fpb); } } - printf("\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d, rRc2 = " - "%d, rRc3 = %d\n", - "ALL", - rc, - wRc, - cRc, - rRc, - rRc2, - rRc3); + log_write( + "\tFile with three items in the resource fork: name = \"%s\", rc = %d, wRc = %d, cRc = %d, rRc = %d, rRc2 = " + "%d, rRc3 = %d\n", + "ALL", + rc, + wRc, + cRc, + rRc, + rRc2, + rRc3); } diff --git a/setter/src/macos/time.c b/setter/src/macos/time.c index 1331dbd..1b6e591 100644 --- a/setter/src/macos/time.c +++ b/setter/src/macos/time.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "macos.h" #include "time.h" @@ -57,7 +58,7 @@ void Timestamps(const char* path) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } refNum = hpb.ioVRefNum; @@ -73,13 +74,13 @@ void Timestamps(const char* path) if(rc) { - printf("Error %d creating working directory.\n", rc); + log_write("Error %d creating working directory.\n", rc); return; } dirId = dirPB.fileParam.ioDirID; - printf("Creating timestamped files.\n"); + log_write("Creating timestamped files.\n"); for(i = 0; i < KNOWN_MAC_TIMES; i++) { @@ -116,6 +117,6 @@ void Timestamps(const char* path) tRc = PBSetCatInfoSync(&cipbr); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", str255, rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", str255, rc, wRc, cRc, tRc); } } diff --git a/setter/src/macos/volume.c b/setter/src/macos/volume.c index 11750ce..0a70b79 100644 --- a/setter/src/macos/volume.c +++ b/setter/src/macos/volume.c @@ -29,6 +29,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "macos.h" void GetVolumeInfo(const char* path, size_t* clusterSize) @@ -57,8 +58,8 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) rc = Gestalt(gestaltFSAttr, &gestaltResponse); if(!rc) { - hfsPlusApis = (gestaltResponse & (1 << gestaltHasHFSPlusAPIs))!= 0; - bigVol = (gestaltResponse & (1 << gestaltFSSupports2TBVols))!=0; + hfsPlusApis = (gestaltResponse & (1 << gestaltHasHFSPlusAPIs)) != 0; + bigVol = (gestaltResponse & (1 << gestaltFSSupports2TBVols)) != 0; } if(!bigVol) @@ -69,7 +70,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) rc = PBHGetVInfoSync((HParmBlkPtr)&hpb); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } drvInfo = hpb.ioVDrvInfo; @@ -93,7 +94,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) rc = PBXGetVolInfo((XVolumeParamPtr)&xpb, 0); if(rc) { - printf("Could not get volume information.\n"); + log_write("Could not get volume information.\n"); return; } drvInfo = xpb.ioVDrvInfo; @@ -110,31 +111,31 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(xpb.ioVFSID != 0) { fsId = xpb.ioVFSID; } } - printf("Volume information:\n"); - printf("\tPath: %s\n", path); - if(bigVol) { printf("\tVolume supports up to 2Tb disks.\n"); } - if(hfsPlusApis) { printf("\tVolume supports HFS Plus APIs.\n"); } - printf("\tDrive number: %d\n", drvInfo); - printf("\tVolume number: %d\n", refNum); - printf("\tVolume name: %#s\n", str255); - printf("\t%llu allocation blocks in volume, %llu free\n", totalBlocks, freeBlocks); - printf("\t%llu bytes in volume, %llu free\n", totalBytes, freeBytes); - printf("\t%lu bytes per allocation block.\n", *clusterSize); - printf("\tVolume created on 0x%08lX\n", crDate); - printf("\tVolume last written on 0x%08lX\n", lwDate); - printf("\tVolume last backed up on 0x%08lX\n", bkDate); - printf("\tFilesystem type: "); + log_write("Volume information:\n"); + log_write("\tPath: %s\n", path); + if(bigVol) { log_write("\tVolume supports up to 2Tb disks.\n"); } + if(hfsPlusApis) { log_write("\tVolume supports HFS Plus APIs.\n"); } + log_write("\tDrive number: %d\n", drvInfo); + log_write("\tVolume number: %d\n", refNum); + log_write("\tVolume name: %#s\n", str255); + log_write("\t%llu allocation blocks in volume, %llu free\n", totalBlocks, freeBlocks); + log_write("\t%llu bytes in volume, %llu free\n", totalBytes, freeBytes); + log_write("\t%lu bytes per allocation block.\n", *clusterSize); + log_write("\tVolume created on 0x%08lX\n", crDate); + log_write("\tVolume last written on 0x%08lX\n", lwDate); + log_write("\tVolume last backed up on 0x%08lX\n", bkDate); + log_write("\tFilesystem type: "); switch(fsId) { - case 0xD2D7: printf("MFS\n"); break; - case 0x4244: printf("HFS\n"); break; - case 0x482B: printf("HFS Plus\n"); break; - case 0x4147: printf("ISO9660\n"); break; - case 0x55DF: printf("UDF\n"); break; - case 0x4242: printf("High Sierra\n"); break; - case 0x4A48: printf("Audio CD\n"); break; - case 0x0100: printf("ProDOS\n"); break; - case 0x4953: printf("FAT\n"); break; - default: printf("unknown id 0x%04X\n", fsId); break; + case 0xD2D7: log_write("MFS\n"); break; + case 0x4244: log_write("HFS\n"); break; + case 0x482B: log_write("HFS Plus\n"); break; + case 0x4147: log_write("ISO9660\n"); break; + case 0x55DF: log_write("UDF\n"); break; + case 0x4242: log_write("High Sierra\n"); break; + case 0x4A48: log_write("Audio CD\n"); break; + case 0x0100: log_write("ProDOS\n"); break; + case 0x4953: log_write("FAT\n"); break; + default: log_write("unknown id 0x%04X\n", fsId); break; } } diff --git a/setter/src/main.c b/setter/src/main.c index f3102fe..e5692a3 100644 --- a/setter/src/main.c +++ b/setter/src/main.c @@ -24,10 +24,12 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include +#include #include "main.h" #include "include/defs.h" +#include "log.h" #if defined(macintosh) && defined(__MWERKS__) #include @@ -37,23 +39,56 @@ Copyright (C) 2011-2021 Natalia Portillo int main(int argc, char** argv) { size_t clusterSize = 0; + int i; + int quiet = 0; + int log = 0; + char* target = NULL; #if defined(macintosh) && defined(__MWERKS__) argc = ccommand(&argv); #endif - printf("Aaru Filesystem Tester (Setter) %s\n", AARU_FSTESTER_VERSION); - printf("%s\n", AARU_COPYRIGHT); + log_write("Aaru Filesystem Tester (Setter) %s\n", AARU_FSTESTER_VERSION); + log_write("%s\n", AARU_COPYRIGHT); - printf("Running in %s (%s)\n", OS_NAME, OS_ARCH); - printf("\n"); - - if(argc != 2) + for(i = 1; i < argc; i++) { - printf("Usage %s \n", argv[0]); - return -1; + if(strncmp(argv[i], "--log", 5) == 0 || strncmp(argv[i], "-l", 2) == 0) log = 1; + else if(strncmp(argv[i], "--quiet", 7) == 0 || strncmp(argv[i], "-q", 2) == 0) + quiet = 1; + else if(argv[i][0] == '-') + { + fprintf(stderr, "Unknown parameter %s.\n", argv[i]); + fprintf(stderr, "Usage %s [--log] [--quiet] \n", argv[0]); + return -1; + } + else if(target != NULL) + { + fprintf(stderr, "Cannot set more than one target.\n"); + fprintf(stderr, "Usage %s [--log] [--quiet] \n", argv[0]); + return -2; + } + else + target = argv[i]; } + log_set_quiet(quiet); + + if(log) + { + log = !log_open(quiet); + + if(log) + { + log_write("Parameters:"); + for(i = 0; i < argc; i++) log_write(" %s", argv[i]); + log_write("\n"); + } + } + + log_write("Running in %s (%s)\n", OS_NAME, OS_ARCH); + log_write("\n"); + GetOsInfo(); GetVolumeInfo(argv[1], &clusterSize); FileAttributes(argv[1]); @@ -70,5 +105,6 @@ int main(int argc, char** argv) DeleteFiles(argv[1]); GetVolumeInfo(argv[1], &clusterSize); + log_close(); return 0; } diff --git a/setter/src/os2/16bit/os.c b/setter/src/os2/16bit/os.c index 2f344a9..4d32562 100644 --- a/setter/src/os2/16bit/os.c +++ b/setter/src/os2/16bit/os.c @@ -30,9 +30,10 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include -#include "../os2.h" #include "../../include/consts.h" #include "../../include/defs.h" +#include "../../log.h" +#include "../os2.h" void GetOsInfo() { @@ -46,7 +47,7 @@ void GetOsInfo() if(rc) { - printf("Error %d querying OS/2 version.\n", rc); + log_write("Error %d querying OS/2 version.\n", rc); return; } @@ -59,10 +60,10 @@ void GetOsInfo() MinorVer = 0; } - printf("OS information:\n"); - printf("\tRunning under OS/2 %d.%d\n", MajorVer, MinorVer); + log_write("OS information:\n"); + log_write("\tRunning under OS/2 %d.%d\n", MajorVer, MinorVer); rc = DosQSysInfo(0, (PBYTE)pathLen, sizeof(USHORT)); - printf("\tMaximum path is %d bytes.\n", pathLen[0]); + log_write("\tMaximum path is %d bytes.\n", pathLen[0]); } diff --git a/setter/src/os2/16bit/xattr.c b/setter/src/os2/16bit/xattr.c index 5732174..4d268f4 100644 --- a/setter/src/os2/16bit/xattr.c +++ b/setter/src/os2/16bit/xattr.c @@ -32,9 +32,10 @@ Copyright (C) 2011-2021 Natalia Portillo #include "xattr.h" -#include "../os2.h" #include "../../include/consts.h" #include "../../include/defs.h" +#include "../../log.h" +#include "../os2.h" void ExtendedAttributes(const char* path) { @@ -54,7 +55,7 @@ void ExtendedAttributes(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -62,13 +63,13 @@ void ExtendedAttributes(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = DosChDir("XATTRS", 0); - printf("Creating files with extended attributes.\n"); + log_write("Creating files with extended attributes.\n"); rc = DosOpen("COMMENTS", &handle, @@ -91,7 +92,7 @@ void ExtendedAttributes(const char* path) cRc = DosClose(handle); } - printf("\tFile with comments = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "COMMENTS", rc, wRc, cRc); + log_write("\tFile with comments = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "COMMENTS", rc, wRc, cRc); rc = DosOpen("COMMENTS.CRT", &handle, @@ -114,7 +115,7 @@ void ExtendedAttributes(const char* path) cRc = DosClose(handle); } - printf("\tFile with comments = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "COMMENTS.CRT", rc, wRc, cRc); + log_write("\tFile with comments = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "COMMENTS.CRT", rc, wRc, cRc); rc = DosOpen("ICON", &handle, @@ -137,5 +138,5 @@ void ExtendedAttributes(const char* path) cRc = DosClose(handle); } - printf("\tFile with icon = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "ICON", rc, wRc, cRc); + log_write("\tFile with icon = \"%s\", rc = %d, wRc = %d, cRc = %d\n", "ICON", rc, wRc, cRc); } diff --git a/setter/src/os2/32bit/os.c b/setter/src/os2/32bit/os.c index 500b7a4..0f04c84 100644 --- a/setter/src/os2/32bit/os.c +++ b/setter/src/os2/32bit/os.c @@ -30,9 +30,10 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include -#include "../os2.h" #include "../../include/consts.h" #include "../../include/defs.h" +#include "../../log.h" +#include "../os2.h" void GetOsInfo() { @@ -46,7 +47,7 @@ void GetOsInfo() if(rc) { - printf("Error %d querying OS/2 version.\n", rc); + log_write("Error %d querying OS/2 version.\n", rc); return; } @@ -61,13 +62,13 @@ void GetOsInfo() MinorVer = aulBuffer[1]; } - printf("OS information:\n"); + log_write("OS information:\n"); - if(aulBuffer[2] > 0x20) printf("\tRunning under OS/2 %d.%d revision %c.\n", MajorVer, MinorVer, aulBuffer[2]); + if(aulBuffer[2] > 0x20) log_write("\tRunning under OS/2 %d.%d revision %c.\n", MajorVer, MinorVer, aulBuffer[2]); else - printf("\tRunning under OS/2 %d.%d\n", MajorVer, MinorVer); + log_write("\tRunning under OS/2 %d.%d\n", MajorVer, MinorVer); rc = DosQuerySysInfo(QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, (PVOID)pathLen, sizeof(ULONG)); - printf("\tMaximum path is %lu bytes.\n", pathLen[0]); + log_write("\tMaximum path is %lu bytes.\n", pathLen[0]); } diff --git a/setter/src/os2/attr.c b/setter/src/os2/attr.c index cc641b8..f9de58e 100644 --- a/setter/src/os2/attr.c +++ b/setter/src/os2/attr.c @@ -34,19 +34,20 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void FileAttributes(const char* path) { - char drivePath[4]; - APIRET rc = 0, wRc = 0, cRc = 0; - HFILE handle; + char drivePath[4]; + APIRET rc = 0, wRc = 0, cRc = 0; + HFILE handle; int i; ACTION_RET actionTaken = 0; // 32 bit #if(defined(__I386__) || defined(__i386__) || defined(__THW_INTEL) || defined(_M_I386)) - FILESTATUS3 fileStatus = {{0}}; + FILESTATUS3 fileStatus = {{0}}; #endif drivePath[0] = path[0]; @@ -58,7 +59,7 @@ void FileAttributes(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -66,13 +67,13 @@ void FileAttributes(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = __os2_chdir("ATTRS"); - printf("Creating attributes files.\n"); + log_write("Creating attributes files.\n"); for(i = 0; i < KNOWN_OS2_ATTRS; i++) { @@ -102,11 +103,11 @@ void FileAttributes(const char* path) #endif } - printf("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", - os2_attrs[i].description, - os2_attrs[i].filename, - rc, - wRc, - cRc); + log_write("\t%s: name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", + os2_attrs[i].description, + os2_attrs[i].filename, + rc, + wRc, + cRc); } } diff --git a/setter/src/os2/deleted.c b/setter/src/os2/deleted.c index ccc6477..7afe788 100644 --- a/setter/src/os2/deleted.c +++ b/setter/src/os2/deleted.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void DeleteFiles(const char* path) @@ -52,7 +53,7 @@ void DeleteFiles(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -60,13 +61,13 @@ void DeleteFiles(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = __os2_chdir("DELETED"); - printf("Creating and deleting files.\n"); + log_write("Creating and deleting files.\n"); for(pos = 0; pos < 64; pos++) { diff --git a/setter/src/os2/dirdepth.c b/setter/src/os2/dirdepth.c index f038e4d..6cc8a1b 100644 --- a/setter/src/os2/dirdepth.c +++ b/setter/src/os2/dirdepth.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void DirectoryDepth(const char* path) @@ -50,7 +51,7 @@ void DirectoryDepth(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -58,13 +59,13 @@ void DirectoryDepth(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = __os2_chdir("DEPTH"); - printf("Creating deepest directory tree.\n"); + log_write("Creating deepest directory tree.\n"); while(!rc) { @@ -77,5 +78,5 @@ void DirectoryDepth(const char* path) pos++; } - printf("\tCreated %d levels of directory hierarchy\n", pos); + log_write("\tCreated %d levels of directory hierarchy\n", pos); } diff --git a/setter/src/os2/filename.c b/setter/src/os2/filename.c index 8695aaf..6140804 100644 --- a/setter/src/os2/filename.c +++ b/setter/src/os2/filename.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void Filenames(const char* path) @@ -52,7 +53,7 @@ void Filenames(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -60,13 +61,13 @@ void Filenames(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = __os2_chdir("FILENAME"); - printf("Creating files with different filenames.\n"); + log_write("Creating files with different filenames.\n"); for(pos = 0; filenames[pos]; pos++) { @@ -87,6 +88,6 @@ void Filenames(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); } } diff --git a/setter/src/os2/files.c b/setter/src/os2/files.c index 6634b45..74670a9 100644 --- a/setter/src/os2/files.c +++ b/setter/src/os2/files.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void MillionFiles(const char* path) @@ -52,7 +53,7 @@ void MillionFiles(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -60,13 +61,13 @@ void MillionFiles(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = __os2_chdir("MILLION"); - printf("Creating lots of files.\n"); + log_write("Creating lots of files.\n"); for(pos = 0; pos < 1000; pos++) { @@ -85,5 +86,5 @@ void MillionFiles(const char* path) DosClose(handle); } - printf("\tCreated %lu files\n", pos); + log_write("\tCreated %lu files\n", pos); } diff --git a/setter/src/os2/frag.c b/setter/src/os2/frag.c index a4d099b..289fd30 100644 --- a/setter/src/os2/frag.c +++ b/setter/src/os2/frag.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void Fragmentation(const char* path, size_t clusterSize) @@ -57,7 +58,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -65,7 +66,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } @@ -91,7 +92,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); rc = DosOpen((PSZ) "QUARCLST", &handle, @@ -113,7 +114,8 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); + log_write( + "\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); rc = DosOpen((PSZ) "TWOCLST", &handle, @@ -135,7 +137,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); rc = DosOpen((PSZ) "TRQTCLST", &handle, @@ -157,12 +159,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "TRQTCLST", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "TRQTCLST", + threeQuartersCluster, + rc, + wRc, + cRc); rc = DosOpen((PSZ) "TWTQCLST", &handle, @@ -184,12 +186,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "TWTQCLST", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "TWTQCLST", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); rc = DosOpen((PSZ) "TWO1", &handle, @@ -211,7 +213,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); rc = DosOpen((PSZ) "TWO2", &handle, @@ -233,7 +235,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); rc = DosOpen((PSZ) "TWO3", &handle, @@ -255,10 +257,10 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO2\".\n"); + log_write("\tDeleting \"TWO2\".\n"); rc = __os2_delete((PSZ) "TWO2", 0); - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); rc = DosOpen((PSZ) "FRAGTHRQ", &handle, @@ -280,17 +282,17 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO1\".\n"); + log_write("\tDeleting \"TWO1\".\n"); rc = __os2_delete((PSZ) "TWO1", 0); - printf("\tDeleting \"TWO3\".\n"); + log_write("\tDeleting \"TWO3\".\n"); rc = __os2_delete((PSZ) "TWO3", 0); - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "FRAGTHRQ", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "FRAGTHRQ", + threeQuartersCluster, + rc, + wRc, + cRc); rc = DosOpen((PSZ) "FRAGSIXQ", &handle, @@ -312,10 +314,10 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "FRAGSIXQ", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "FRAGSIXQ", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); } diff --git a/setter/src/os2/time.c b/setter/src/os2/time.c index 810dcf0..7f66e4e 100644 --- a/setter/src/os2/time.c +++ b/setter/src/os2/time.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" #define DATETIME_FORMAT "This file is dated %04d/%02d/%02d %02d:%02d:%02d for %s\n" @@ -62,7 +63,7 @@ void Timestamps(const char* path) if(rc) { - printf("Cannot change to specified path, not continuing.\n"); + log_write("Cannot change to specified path, not continuing.\n"); return; } @@ -70,13 +71,13 @@ void Timestamps(const char* path) if(rc) { - printf("Cannot create working directory.\n"); + log_write("Cannot create working directory.\n"); return; } rc = __os2_chdir("TIMES"); - printf("Creating timestamped files.\n"); + log_write("Creating timestamped files.\n"); rc = DosOpen((PSZ) "MAXCTIME", &handle, @@ -112,7 +113,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXCTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXCTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MINCTIME", &handle, @@ -148,7 +149,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINCTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINCTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y19CTIME", &handle, @@ -184,7 +185,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19CTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19CTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y2KCTIME", &handle, @@ -220,7 +221,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19CTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19CTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MAXWTIME", &handle, @@ -256,7 +257,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXWTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXWTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MINWTIME", &handle, @@ -292,7 +293,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINWTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINWTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y19WTIME", &handle, @@ -328,7 +329,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19WTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19WTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y2KWTIME", &handle, @@ -364,7 +365,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KWTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KWTIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MAXATIME", &handle, @@ -400,7 +401,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXATIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MINATIME", &handle, @@ -436,7 +437,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINATIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y19ATIME", &handle, @@ -472,7 +473,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19ATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19ATIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y2KATIME", &handle, @@ -508,7 +509,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KATIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MAX_TIME", &handle, @@ -548,7 +549,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAX_TIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAX_TIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "MIN_TIME", &handle, @@ -588,7 +589,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MIN_TIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MIN_TIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y19_TIME", &handle, @@ -628,7 +629,7 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19_TIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19_TIME", rc, wRc, cRc, tRc); rc = DosOpen((PSZ) "Y2K_TIME", &handle, @@ -668,5 +669,5 @@ void Timestamps(const char* path) cRc = DosClose(handle); } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2K_TIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2K_TIME", rc, wRc, cRc, tRc); } diff --git a/setter/src/os2/volume.c b/setter/src/os2/volume.c index ae8b92d..1541e8d 100644 --- a/setter/src/os2/volume.c +++ b/setter/src/os2/volume.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" #include "os2.h" void GetVolumeInfo(const char* path, size_t* clusterSize) @@ -59,14 +60,14 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) #if(defined(__I86__) || defined(__i86__) || defined(_M_I86)) rc = DosQFSAttach((PSZ)path, 0, FSAIL_QUERYNAME, (PVOID)&bData, &cbData, 0); #else // 32 bit - rc = DosQueryFSAttach((PSZ)path, 0, FSAIL_QUERYNAME, (PVOID)&bData, &cbData); + rc = DosQueryFSAttach((PSZ)path, 0, FSAIL_QUERYNAME, (PVOID)&bData, &cbData); #endif - printf("Volume information:\n"); - printf("\tPath: %s\n", path); - printf("\tDrive number: %d\n", driveNo - 1); + log_write("Volume information:\n"); + log_write("\tPath: %s\n", path); + log_write("\tDrive number: %d\n", driveNo - 1); - if(rc) printf("Error %d requesting volume information.\n", rc); + if(rc) log_write("Error %d requesting volume information.\n", rc); else { // 16 bit @@ -75,7 +76,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) #else // 32 bit fsdName = &bData[8 + (USHORT)bData[2] + 1]; #endif - printf("\tFSD name: %s\n", fsdName); + log_write("\tFSD name: %s\n", fsdName); } pfsAllocateBuffer = (PFSALLOCATE)malloc(sizeof(FSALLOCATE)); @@ -87,19 +88,19 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) rc = DosQueryFSInfo(driveNo, FSIL_ALLOC, (PBYTE)pfsAllocateBuffer, sizeof(FSALLOCATE)); #endif - if(rc) printf("Error %d requesting volume information.\n", rc); + if(rc) log_write("Error %d requesting volume information.\n", rc); else { - printf("\tBytes per sector: %u\n", pfsAllocateBuffer->cbSector); - printf("\tSectors per cluster: %lu (%lu bytes)\n", - pfsAllocateBuffer->cSectorUnit, - pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector); - printf("\tClusters: %lu (%lu bytes)\n", - pfsAllocateBuffer->cUnit, - pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector * pfsAllocateBuffer->cUnit); - printf("\tFree clusters: %lu (%lu bytes)\n", - pfsAllocateBuffer->cUnitAvail, - pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector * pfsAllocateBuffer->cUnitAvail); + log_write("\tBytes per sector: %u\n", pfsAllocateBuffer->cbSector); + log_write("\tSectors per cluster: %lu (%lu bytes)\n", + pfsAllocateBuffer->cSectorUnit, + pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector); + log_write("\tClusters: %lu (%lu bytes)\n", + pfsAllocateBuffer->cUnit, + pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector * pfsAllocateBuffer->cUnit); + log_write("\tFree clusters: %lu (%lu bytes)\n", + pfsAllocateBuffer->cUnitAvail, + pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector * pfsAllocateBuffer->cUnitAvail); *clusterSize = pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector; } @@ -115,17 +116,17 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) rc = DosQueryFSInfo(driveNo, FSIL_VOLSER, (PBYTE)pfsInfo, sizeof(FSINFO)); #endif - if(rc) printf("Error %d requesting volume information.\n", rc); + if(rc) log_write("Error %d requesting volume information.\n", rc); else { - printf("\tVolume label: %s\n", pfsInfo->vol.szVolLabel); - printf("\tVolume created on %d/%02d/%02d %02d:%02d:%02d\n", - pfsInfo->fdateCreation.year + 1980, - pfsInfo->fdateCreation.month - 1, - pfsInfo->fdateCreation.day, - pfsInfo->ftimeCreation.hours, - pfsInfo->ftimeCreation.minutes, - pfsInfo->ftimeCreation.twosecs * 2); + log_write("\tVolume label: %s\n", pfsInfo->vol.szVolLabel); + log_write("\tVolume created on %d/%02d/%02d %02d:%02d:%02d\n", + pfsInfo->fdateCreation.year + 1980, + pfsInfo->fdateCreation.month - 1, + pfsInfo->fdateCreation.day, + pfsInfo->ftimeCreation.hours, + pfsInfo->ftimeCreation.minutes, + pfsInfo->ftimeCreation.twosecs * 2); } free(pfsInfo); diff --git a/setter/src/unix/deleted.c b/setter/src/unix/deleted.c index 0d934c2..eff6bed 100644 --- a/setter/src/unix/deleted.c +++ b/setter/src/unix/deleted.c @@ -30,6 +30,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" void DeleteFiles(const char* path) { @@ -42,7 +43,7 @@ void DeleteFiles(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -50,7 +51,7 @@ void DeleteFiles(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -58,11 +59,11 @@ void DeleteFiles(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating and deleting files.\n"); + log_write("Creating and deleting files.\n"); for(pos = 0; pos < 64; pos++) { diff --git a/setter/src/unix/dirdepth.c b/setter/src/unix/dirdepth.c index ca33237..4f48a22 100644 --- a/setter/src/unix/dirdepth.c +++ b/setter/src/unix/dirdepth.c @@ -29,6 +29,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" void DirectoryDepth(const char* path) { @@ -40,7 +41,7 @@ void DirectoryDepth(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -48,7 +49,7 @@ void DirectoryDepth(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -56,11 +57,11 @@ void DirectoryDepth(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating deepest directory tree.\n"); + log_write("Creating deepest directory tree.\n"); while(!ret) { @@ -76,5 +77,5 @@ void DirectoryDepth(const char* path) if(pos >= 1000) break; } - printf("\tCreated %ld levels of directory hierarchy\n", pos); + log_write("\tCreated %ld levels of directory hierarchy\n", pos); } diff --git a/setter/src/unix/filename.c b/setter/src/unix/filename.c index 04ac109..f73130d 100644 --- a/setter/src/unix/filename.c +++ b/setter/src/unix/filename.c @@ -30,6 +30,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" void Filenames(const char* path) { @@ -43,7 +44,7 @@ void Filenames(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -51,7 +52,7 @@ void Filenames(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -59,11 +60,11 @@ void Filenames(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating files with different filenames.\n"); + log_write("Creating files with different filenames.\n"); for(pos = 0; filenames[pos]; pos++) { @@ -85,6 +86,6 @@ void Filenames(const char* path) if(ret) { cRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d\n", filenames[pos], rc, wRc, cRc); } } diff --git a/setter/src/unix/files.c b/setter/src/unix/files.c index 2d84cfa..7dd3e40 100644 --- a/setter/src/unix/files.c +++ b/setter/src/unix/files.c @@ -30,6 +30,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" void MillionFiles(const char* path) { @@ -42,7 +43,7 @@ void MillionFiles(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -50,7 +51,7 @@ void MillionFiles(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -58,11 +59,11 @@ void MillionFiles(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating lots of files.\n"); + log_write("Creating lots of files.\n"); for(pos = 0; pos < 1000; pos++) { @@ -75,5 +76,5 @@ void MillionFiles(const char* path) fclose(h); } - printf("\tCreated %ld files\n", pos); + log_write("\tCreated %ld files\n", pos); } diff --git a/setter/src/unix/frag.c b/setter/src/unix/frag.c index 5f3aba6..a7b9e3f 100644 --- a/setter/src/unix/frag.c +++ b/setter/src/unix/frag.c @@ -32,6 +32,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" void Fragmentation(const char* path, size_t clusterSize) { @@ -50,7 +51,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -58,7 +59,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -66,11 +67,11 @@ void Fragmentation(const char* path, size_t clusterSize) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Writing fragmented files:\n"); + log_write("Writing fragmented files:\n"); h = fopen("HALFCLST", "w+"); rc = 0; @@ -92,7 +93,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "HALFCLST", halfCluster, rc, wRc, cRc); h = fopen("QUARCLST", "w+"); rc = 0; @@ -114,7 +115,8 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); + log_write( + "\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "QUARCLST", quarterCluster, rc, wRc, cRc); h = fopen("TWOCLST", "w+"); rc = 0; @@ -136,7 +138,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWOCLST", twoCluster, rc, wRc, cRc); h = fopen("TRQTCLST", "w+"); rc = 0; @@ -158,12 +160,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "TRQTCLST", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "TRQTCLST", + threeQuartersCluster, + rc, + wRc, + cRc); h = fopen("TWTQCLST", "w+"); rc = 0; @@ -185,12 +187,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "TWTQCLST", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "TWTQCLST", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); h = fopen("TWO1", "w+"); rc = 0; @@ -212,7 +214,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO1", twoCluster, rc, wRc, cRc); h = fopen("TWO2", "w+"); rc = 0; @@ -234,7 +236,7 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO2", twoCluster, rc, wRc, cRc); h = fopen("TWO3", "w+"); rc = 0; @@ -256,11 +258,11 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO2\".\n"); + log_write("\tDeleting \"TWO2\".\n"); ret = unlink("TWO2"); if(!ret) { rc = errno; } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "TWO3", twoCluster, rc, wRc, cRc); h = fopen("FRAGTHRQ", "w+"); rc = 0; @@ -282,19 +284,19 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO1\".\n"); + log_write("\tDeleting \"TWO1\".\n"); ret = unlink("TWO1"); if(!ret) { rc = errno; } - printf("\tDeleting \"TWO3\".\n"); + log_write("\tDeleting \"TWO3\".\n"); ret = unlink("TWO3"); if(!ret) { rc = errno; } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "FRAGTHRQ", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "FRAGTHRQ", + threeQuartersCluster, + rc, + wRc, + cRc); h = fopen("FRAGSIXQ", "w+"); rc = 0; @@ -316,10 +318,10 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", - "FRAGSIXQ", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", + "FRAGSIXQ", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); } diff --git a/setter/src/unix/links.c b/setter/src/unix/links.c index 3d58b5c..c06c29d 100644 --- a/setter/src/unix/links.c +++ b/setter/src/unix/links.c @@ -29,6 +29,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" void Links(const char* path) { @@ -39,7 +40,7 @@ void Links(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -47,7 +48,7 @@ void Links(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -55,17 +56,17 @@ void Links(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating links.\n"); + log_write("Creating links.\n"); h = fopen("TARGET", "w+"); if(h == NULL) { - printf("Error %d creating target file.\n", errno); + log_write("Error %d creating target file.\n", errno); return; } @@ -75,9 +76,9 @@ void Links(const char* path) ret = link("TARGET", "HARD"); - if(ret) { printf("Error %d creating hard link.\n", errno); } + if(ret) { log_write("Error %d creating hard link.\n", errno); } ret = symlink("TARGET", "SYMBOLIC"); - if(ret) { printf("Error %d creating symbolic link.\n", errno); } + if(ret) { log_write("Error %d creating symbolic link.\n", errno); } } diff --git a/setter/src/unix/os.c b/setter/src/unix/os.c index 162452f..9cd4579 100644 --- a/setter/src/unix/os.c +++ b/setter/src/unix/os.c @@ -27,6 +27,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" void GetOsInfo() { @@ -37,13 +38,13 @@ void GetOsInfo() if(ret) { - printf("Error %d retrieving OS information.\n", errno); + log_write("Error %d retrieving OS information.\n", errno); return; } - printf("OS information:\n"); - printf("\tOS name: %s\n", buf.sysname); - printf("\tRelease: %s\n", buf.release); - printf("\tVersion: %s\n", buf.version); - printf("\tMachine: %s\n", buf.machine); + log_write("OS information:\n"); + log_write("\tOS name: %s\n", buf.sysname); + log_write("\tRelease: %s\n", buf.release); + log_write("\tVersion: %s\n", buf.version); + log_write("\tMachine: %s\n", buf.machine); } diff --git a/setter/src/unix/perms.c b/setter/src/unix/perms.c index 3304e92..93c0c9c 100644 --- a/setter/src/unix/perms.c +++ b/setter/src/unix/perms.c @@ -30,6 +30,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "perms.h" #include "../include/defs.h" +#include "../log.h" void FilePermissions(const char* path) { @@ -43,7 +44,7 @@ void FilePermissions(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -51,7 +52,7 @@ void FilePermissions(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -59,11 +60,11 @@ void FilePermissions(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating attributes files.\n"); + log_write("Creating attributes files.\n"); for(i = 0; i < KNOWN_UNIX_PERMS; i++) { @@ -79,6 +80,7 @@ void FilePermissions(const char* path) cRc = chmod(unix_perms[i].filename, unix_perms[i].mode); } - printf("\t%s: name = \"%s\", rc = %d, cRc = %d\n", unix_perms[i].description, unix_perms[i].filename, rc, cRc); + log_write( + "\t%s: name = \"%s\", rc = %d, cRc = %d\n", unix_perms[i].description, unix_perms[i].filename, rc, cRc); } } diff --git a/setter/src/unix/time.c b/setter/src/unix/time.c index 6110d30..d5b3008 100644 --- a/setter/src/unix/time.c +++ b/setter/src/unix/time.c @@ -31,6 +31,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "unix.h" void Timestamps(const char* path) @@ -47,7 +48,7 @@ void Timestamps(const char* path) if(ret) { - printf("Error %d changing to specified path.\n", errno); + log_write("Error %d changing to specified path.\n", errno); return; } @@ -55,7 +56,7 @@ void Timestamps(const char* path) if(ret) { - printf("Error %d creating working directory.\n", errno); + log_write("Error %d creating working directory.\n", errno); return; } @@ -63,11 +64,11 @@ void Timestamps(const char* path) if(ret) { - printf("Error %d changing to working directory.\n", errno); + log_write("Error %d changing to working directory.\n", errno); return; } - printf("Creating timestamped files.\n"); + log_write("Creating timestamped files.\n"); memset(×, 0, sizeof(struct utimbuf)); h = fopen("MAXATIME", "w+"); @@ -91,7 +92,7 @@ void Timestamps(const char* path) ret = utime("MAXATIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXATIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("MAXMTIME", "w+"); @@ -115,7 +116,7 @@ void Timestamps(const char* path) ret = utime("MAXMTIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXMTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXMTIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("MINATIME", "w+"); @@ -139,7 +140,7 @@ void Timestamps(const char* path) ret = utime("MINATIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINATIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("MINMTIME", "w+"); @@ -163,7 +164,7 @@ void Timestamps(const char* path) ret = utime("MINMTIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINMTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINMTIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("Y1KATIME", "w+"); @@ -187,7 +188,7 @@ void Timestamps(const char* path) ret = utime("Y1KATIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y1KATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y1KATIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("Y1KMTIME", "w+"); @@ -211,7 +212,7 @@ void Timestamps(const char* path) ret = utime("Y1KMTIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y1KMTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y1KMTIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("Y2KATIME", "w+"); @@ -235,7 +236,7 @@ void Timestamps(const char* path) ret = utime("Y2KATIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KATIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("Y2KMTIME", "w+"); @@ -259,7 +260,7 @@ void Timestamps(const char* path) ret = utime("Y2KMTIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KMTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KMTIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("LESSATIME", "w+"); @@ -283,7 +284,7 @@ void Timestamps(const char* path) ret = utime("LESSATIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "LESSATIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "LESSATIME", rc, wRc, cRc, tRc); memset(×, 0, sizeof(struct utimbuf)); h = fopen("LESSMTIME", "w+"); @@ -307,5 +308,5 @@ void Timestamps(const char* path) ret = utime("LESSMTIME", ×); if(ret) { tRc = errno; } } - printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "LESSMTIME", rc, wRc, cRc, tRc); + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "LESSMTIME", rc, wRc, cRc, tRc); } diff --git a/setter/src/unix/volume.c b/setter/src/unix/volume.c index c2e7c08..22239f4 100644 --- a/setter/src/unix/volume.c +++ b/setter/src/unix/volume.c @@ -28,6 +28,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "../include/defs.h" +#include "../log.h" #include "unix.h" void GetVolumeInfo(const char* path, size_t* clusterSize) @@ -39,177 +40,177 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(ret) { - printf("Error %d querying volume information.\n", errno); + log_write("Error %d querying volume information.\n", errno); return; } - printf("Volume information:\n"); - printf("\tPath: %s\n", path); + log_write("Volume information:\n"); + log_write("\tPath: %s\n", path); - printf("\tFilesystem: "); + log_write("\tFilesystem: "); switch(buf.f_type) { - case ADFS_SUPER_MAGIC: printf("ADFS"); break; - case AFFS_SUPER_MAGIC: printf("Amiga FFS"); break; - case AFS_SUPER_MAGIC: printf("AFS"); break; - case ANON_INODE_FS_MAGIC: printf("anonymous inode fs"); break; - case AUTOFS_SUPER_MAGIC: printf("autofs"); break; - case BDEVFS_MAGIC: printf("bdevfs"); break; - case BEFS_SUPER_MAGIC: printf("BeFS"); break; - case BFS_MAGIC: printf("bfs"); break; - case BINFMTFS_MAGIC: printf("binfmtfs"); break; - case BPF_FS_MAGIC: printf("bpffs"); break; + case ADFS_SUPER_MAGIC: log_write("ADFS"); break; + case AFFS_SUPER_MAGIC: log_write("Amiga FFS"); break; + case AFS_SUPER_MAGIC: log_write("AFS"); break; + case ANON_INODE_FS_MAGIC: log_write("anonymous inode fs"); break; + case AUTOFS_SUPER_MAGIC: log_write("autofs"); break; + case BDEVFS_MAGIC: log_write("bdevfs"); break; + case BEFS_SUPER_MAGIC: log_write("BeFS"); break; + case BFS_MAGIC: log_write("bfs"); break; + case BINFMTFS_MAGIC: log_write("binfmtfs"); break; + case BPF_FS_MAGIC: log_write("bpffs"); break; case BTRFS_SUPER_MAGIC: - case BTRFS_TEST_MAGIC: printf("btrfs"); break; - case CGROUP_SUPER_MAGIC: printf("cgroup"); break; - case CGROUP2_SUPER_MAGIC: printf("cgroup2"); break; - case CIFS_MAGIC_NUMBER: printf("CIFS"); break; - case CODA_SUPER_MAGIC: printf("CODA"); break; - case COH_SUPER_MAGIC: printf("Coherent"); break; - case CRAMFS_MAGIC: printf("cramfs"); break; - case DEBUGFS_MAGIC: printf("debufs"); break; - case DEVFS_SUPER_MAGIC: printf("devfs"); break; - case DEVPTS_SUPER_MAGIC: printf("devpts"); break; - case ECRYPTFS_SUPER_MAGIC: printf("ecryptfs"); break; - case EFIVARFS_MAGIC: printf("efivars"); break; - case EFS_SUPER_MAGIC: printf("EFS"); break; - case EXT_SUPER_MAGIC: printf("ext"); break; - case EXT2_OLD_SUPER_MAGIC: printf("ext2"); break; - case EXT2_SUPER_MAGIC: printf("ext2/3/4"); break; - case F2FS_SUPER_MAGIC: printf("f2fs"); break; - case FUSE_SUPER_MAGIC: printf("fuse"); break; - case FUTEXFS_SUPER_MAGIC: printf("futexfs"); break; - case HFS_SUPER_MAGIC: printf("HFS"); break; - case HOSTFS_SUPER_MAGIC: printf("hostfs"); break; - case HPFS_SUPER_MAGIC: printf("HPFS"); break; - case HUGETLBFS_MAGIC: printf("hugetlbfs"); break; - case ISOFS_SUPER_MAGIC: printf("ISO9660"); break; - case JFFS2_SUPER_MAGIC: printf("jffs2"); break; - case JFS_SUPER_MAGIC: printf("JFS"); break; + case BTRFS_TEST_MAGIC: log_write("btrfs"); break; + case CGROUP_SUPER_MAGIC: log_write("cgroup"); break; + case CGROUP2_SUPER_MAGIC: log_write("cgroup2"); break; + case CIFS_MAGIC_NUMBER: log_write("CIFS"); break; + case CODA_SUPER_MAGIC: log_write("CODA"); break; + case COH_SUPER_MAGIC: log_write("Coherent"); break; + case CRAMFS_MAGIC: log_write("cramfs"); break; + case DEBUGFS_MAGIC: log_write("debufs"); break; + case DEVFS_SUPER_MAGIC: log_write("devfs"); break; + case DEVPTS_SUPER_MAGIC: log_write("devpts"); break; + case ECRYPTFS_SUPER_MAGIC: log_write("ecryptfs"); break; + case EFIVARFS_MAGIC: log_write("efivars"); break; + case EFS_SUPER_MAGIC: log_write("EFS"); break; + case EXT_SUPER_MAGIC: log_write("ext"); break; + case EXT2_OLD_SUPER_MAGIC: log_write("ext2"); break; + case EXT2_SUPER_MAGIC: log_write("ext2/3/4"); break; + case F2FS_SUPER_MAGIC: log_write("f2fs"); break; + case FUSE_SUPER_MAGIC: log_write("fuse"); break; + case FUTEXFS_SUPER_MAGIC: log_write("futexfs"); break; + case HFS_SUPER_MAGIC: log_write("HFS"); break; + case HOSTFS_SUPER_MAGIC: log_write("hostfs"); break; + case HPFS_SUPER_MAGIC: log_write("HPFS"); break; + case HUGETLBFS_MAGIC: log_write("hugetlbfs"); break; + case ISOFS_SUPER_MAGIC: log_write("ISO9660"); break; + case JFFS2_SUPER_MAGIC: log_write("jffs2"); break; + case JFS_SUPER_MAGIC: log_write("JFS"); break; case MINIX_SUPER_MAGIC: - case MINIX_SUPER_MAGIC2: printf("minix"); break; + case MINIX_SUPER_MAGIC2: log_write("minix"); break; case MINIX2_SUPER_MAGIC: - case MINIX2_SUPER_MAGIC2: printf("minix2"); break; - case MINIX3_SUPER_MAGIC: printf("minix3"); break; - case MQUEUE_MAGIC: printf("mqueue"); break; - case MSDOS_SUPER_MAGIC: printf("msdos/vfat"); break; - case MTD_INODE_FS_MAGIC: printf("mtd inodefs"); break; - case NCP_SUPER_MAGIC: printf("NCP"); break; - case NFS_SUPER_MAGIC: printf("NFS"); break; - case NILFS_SUPER_MAGIC: printf("nilfs"); break; - case NSFS_MAGIC: printf("nsfs"); break; - case NTFS_SB_MAGIC: printf("NTFS"); break; - case OCFS2_SUPER_MAGIC: printf("OCFS2"); break; - case OPENPROM_SUPER_MAGIC: printf("OpenPROM"); break; - case OVERLAYFS_SUPER_MAGIC: printf("overlayfs"); break; - case PIPEFS_MAGIC: printf("pipefs"); break; - case PROC_SUPER_MAGIC: printf("proc"); break; - case PSTOREFS_MAGIC: printf("pstorefs"); break; - case QNX4_SUPER_MAGIC: printf("qnx4"); break; - case QNX6_SUPER_MAGIC: printf("qnx6"); break; - case RAMFS_MAGIC: printf("ramfs"); break; - case REISERFS_SUPER_MAGIC: printf("Reiser"); break; - case ROMFS_MAGIC: printf("romfs"); break; - case SECURITYFS_MAGIC: printf("securityfs"); break; - case SELINUX_MAGIC: printf("SELinux"); break; - case SMACK_MAGIC: printf("smack"); break; - case SMB_SUPER_MAGIC: printf("SMB"); break; - case SOCKFS_MAGIC: printf("sockfs"); break; - case SQUASHFS_MAGIC: printf("squashfs"); break; - case SYSFS_MAGIC: printf("sysfs"); break; - case SYSV2_SUPER_MAGIC: printf("System V Release 2"); break; - case SYSV4_SUPER_MAGIC: printf("System V Release 4"); break; - case TMPFS_MAGIC: printf("tmpfs"); break; - case TRACEFS_MAGIC: printf("tracefs"); break; - case UDF_SUPER_MAGIC: printf("UDF"); break; - case UFS_MAGIC: printf("UFS"); break; - case USBDEVICE_SUPER_MAGIC: printf("usbdevice"); break; - case V9FS_MAGIC: printf("V9"); break; - case VXFS_SUPER_MAGIC: printf("vxfs"); break; - case XENFS_SUPER_MAGIC: printf("xenfs"); break; - case XENIX_SUPER_MAGIC: printf("XENIX"); break; - case XFS_SUPER_MAGIC: printf("XFS"); break; - case _XIAFS_SUPER_MAGIC: printf("xia"); break; - default: printf("unknown type -> 0x%lX", buf.f_type); + case MINIX2_SUPER_MAGIC2: log_write("minix2"); break; + case MINIX3_SUPER_MAGIC: log_write("minix3"); break; + case MQUEUE_MAGIC: log_write("mqueue"); break; + case MSDOS_SUPER_MAGIC: log_write("msdos/vfat"); break; + case MTD_INODE_FS_MAGIC: log_write("mtd inodefs"); break; + case NCP_SUPER_MAGIC: log_write("NCP"); break; + case NFS_SUPER_MAGIC: log_write("NFS"); break; + case NILFS_SUPER_MAGIC: log_write("nilfs"); break; + case NSFS_MAGIC: log_write("nsfs"); break; + case NTFS_SB_MAGIC: log_write("NTFS"); break; + case OCFS2_SUPER_MAGIC: log_write("OCFS2"); break; + case OPENPROM_SUPER_MAGIC: log_write("OpenPROM"); break; + case OVERLAYFS_SUPER_MAGIC: log_write("overlayfs"); break; + case PIPEFS_MAGIC: log_write("pipefs"); break; + case PROC_SUPER_MAGIC: log_write("proc"); break; + case PSTOREFS_MAGIC: log_write("pstorefs"); break; + case QNX4_SUPER_MAGIC: log_write("qnx4"); break; + case QNX6_SUPER_MAGIC: log_write("qnx6"); break; + case RAMFS_MAGIC: log_write("ramfs"); break; + case REISERFS_SUPER_MAGIC: log_write("Reiser"); break; + case ROMFS_MAGIC: log_write("romfs"); break; + case SECURITYFS_MAGIC: log_write("securityfs"); break; + case SELINUX_MAGIC: log_write("SELinux"); break; + case SMACK_MAGIC: log_write("smack"); break; + case SMB_SUPER_MAGIC: log_write("SMB"); break; + case SOCKFS_MAGIC: log_write("sockfs"); break; + case SQUASHFS_MAGIC: log_write("squashfs"); break; + case SYSFS_MAGIC: log_write("sysfs"); break; + case SYSV2_SUPER_MAGIC: log_write("System V Release 2"); break; + case SYSV4_SUPER_MAGIC: log_write("System V Release 4"); break; + case TMPFS_MAGIC: log_write("tmpfs"); break; + case TRACEFS_MAGIC: log_write("tracefs"); break; + case UDF_SUPER_MAGIC: log_write("UDF"); break; + case UFS_MAGIC: log_write("UFS"); break; + case USBDEVICE_SUPER_MAGIC: log_write("usbdevice"); break; + case V9FS_MAGIC: log_write("V9"); break; + case VXFS_SUPER_MAGIC: log_write("vxfs"); break; + case XENFS_SUPER_MAGIC: log_write("xenfs"); break; + case XENIX_SUPER_MAGIC: log_write("XENIX"); break; + case XFS_SUPER_MAGIC: log_write("XFS"); break; + case _XIAFS_SUPER_MAGIC: log_write("xia"); break; + default: log_write("unknown type -> 0x%lX", buf.f_type); } - printf("\n"); + log_write("\n"); - printf("\tBytes per block: %ld\n", buf.f_bsize); - printf("\tVolume size: %llu bytes\n", ((unsigned long long)buf.f_blocks) * buf.f_bsize); - printf("\tVolume free: %llu bytes\n", ((unsigned long long)buf.f_bfree) * buf.f_bsize); - printf("\tMaximum component length: %ld\n", buf.f_namelen); + log_write("\tBytes per block: %ld\n", buf.f_bsize); + log_write("\tVolume size: %llu bytes\n", ((unsigned long long)buf.f_blocks) * buf.f_bsize); + log_write("\tVolume free: %llu bytes\n", ((unsigned long long)buf.f_bfree) * buf.f_bsize); + log_write("\tMaximum component length: %ld\n", buf.f_namelen); if(buf.f_flags) { - printf("\tFlags:\n"); + log_write("\tFlags:\n"); if(buf.f_flags & ST_RDONLY) { - printf("\t\tVolume is read-only.\n"); + log_write("\t\tVolume is read-only.\n"); buf.f_flags -= ST_RDONLY; } if(buf.f_flags & ST_NOSUID) { - printf("\t\tVolume ignores suid and sgid bits.\n"); + log_write("\t\tVolume ignores suid and sgid bits.\n"); buf.f_flags -= ST_NOSUID; } if(buf.f_flags & ST_NODEV) { - printf("\t\tVolume disallows access to device special files.\n"); + log_write("\t\tVolume disallows access to device special files.\n"); buf.f_flags -= ST_NODEV; } if(buf.f_flags & ST_NOEXEC) { - printf("\t\tVolume disallows program execution.\n"); + log_write("\t\tVolume disallows program execution.\n"); buf.f_flags -= ST_NOEXEC; } if(buf.f_flags & ST_SYNCHRONOUS) { - printf("\t\tVolume writes are synced at once.\n"); + log_write("\t\tVolume writes are synced at once.\n"); buf.f_flags -= ST_SYNCHRONOUS; } if(buf.f_flags & ST_MANDLOCK) { - printf("\t\tVolume allows mandatory locks.\n"); + log_write("\t\tVolume allows mandatory locks.\n"); buf.f_flags -= ST_MANDLOCK; } if(buf.f_flags & ST_WRITE) { - printf("\t\tVolume writes on file/directory/symlink.\n"); + log_write("\t\tVolume writes on file/directory/symlink.\n"); buf.f_flags -= ST_WRITE; } if(buf.f_flags & ST_APPEND) { - printf("\t\tVolume appends.\n"); + log_write("\t\tVolume appends.\n"); buf.f_flags -= ST_APPEND; } if(buf.f_flags & ST_IMMUTABLE) { - printf("\t\tVolume is immutable.\n"); + log_write("\t\tVolume is immutable.\n"); buf.f_flags -= ST_IMMUTABLE; } if(buf.f_flags & ST_NOATIME) { - printf("\t\tVolume does not update access times.\n"); + log_write("\t\tVolume does not update access times.\n"); buf.f_flags -= ST_NOATIME; } if(buf.f_flags & ST_NODIRATIME) { - printf("\t\tVolume does not update directory access times.\n"); + log_write("\t\tVolume does not update directory access times.\n"); buf.f_flags -= ST_NODIRATIME; } - if(buf.f_flags) { printf("\t\tRemaining flags: 0x%08lX\n", buf.f_flags); } + if(buf.f_flags) { log_write("\t\tRemaining flags: 0x%08lX\n", buf.f_flags); } } *clusterSize = buf.f_bsize; diff --git a/setter/src/win32/attr.c b/setter/src/win32/attr.c index 000562f..b480ea5 100644 --- a/setter/src/win32/attr.c +++ b/setter/src/win32/attr.c @@ -37,6 +37,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "attr.h" #include "../include/defs.h" +#include "../log.h" extern DWORD oldVersion; @@ -59,7 +60,7 @@ void FileAttributes(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -73,7 +74,7 @@ void FileAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -82,7 +83,7 @@ void FileAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -91,11 +92,11 @@ void FileAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating attributes files.\n"); + log_write("Creating attributes files.\n"); for(i = 0; i < KNOWN_WIN32_ATTRS; i++) { @@ -119,12 +120,12 @@ void FileAttributes(const char* path) if(!ret) cRc = GetLastError(); } - printf("\t%s: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - win32_attrs[i].description, - win32_attrs[i].filename, - rc, - wRc, - cRc); + log_write("\t%s: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + win32_attrs[i].description, + win32_attrs[i].filename, + rc, + wRc, + cRc); } if(WinGetVersionExA) @@ -135,7 +136,7 @@ void FileAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu querying Windows version.\n", error); + log_write("Error %lu querying Windows version.\n", error); free(lpRootPathName); return; } @@ -164,7 +165,7 @@ void FileAttributes(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile is compressed: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", "COMPRESS", rc, wRc, cRc); + log_write("\tFile is compressed: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", "COMPRESS", rc, wRc, cRc); } advapi32 = LoadLibraryA("ADVAPI32.DLL"); @@ -205,14 +206,14 @@ void FileAttributes(const char* path) ret = SetFileAttributesA(encrypted_win32_attrs[i].filename, encrypted_win32_attrs[i].attr); if(!ret) aRc = GetLastError(); } - printf("\t%s: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu, aRc = %lu, eRc = %lu\n", - encrypted_win32_attrs[i].description, - encrypted_win32_attrs[i].filename, - rc, - wRc, - cRc, - aRc, - eRc); + log_write("\t%s: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu, aRc = %lu, eRc = %lu\n", + encrypted_win32_attrs[i].description, + encrypted_win32_attrs[i].filename, + rc, + wRc, + cRc, + aRc, + eRc); } FreeLibrary(advapi32); diff --git a/setter/src/win32/deleted.c b/setter/src/win32/deleted.c index cb57119..1a92df9 100644 --- a/setter/src/win32/deleted.c +++ b/setter/src/win32/deleted.c @@ -38,6 +38,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "win32.h" #include "../include/defs.h" +#include "../log.h" void DeleteFiles(const char* path) { @@ -53,7 +54,7 @@ void DeleteFiles(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -67,7 +68,7 @@ void DeleteFiles(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -76,7 +77,7 @@ void DeleteFiles(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -85,11 +86,11 @@ void DeleteFiles(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating and deleting files.\n"); + log_write("Creating and deleting files.\n"); for(pos = 0; pos < 64; pos++) { diff --git a/setter/src/win32/dirdepth.c b/setter/src/win32/dirdepth.c index 6145e2d..413200f 100644 --- a/setter/src/win32/dirdepth.c +++ b/setter/src/win32/dirdepth.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "win32.h" #include "../include/defs.h" +#include "../log.h" void DirectoryDepth(const char* path) { @@ -48,7 +49,7 @@ void DirectoryDepth(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -62,7 +63,7 @@ void DirectoryDepth(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -71,7 +72,7 @@ void DirectoryDepth(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -80,11 +81,11 @@ void DirectoryDepth(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating deepest directory tree.\n"); + log_write("Creating deepest directory tree.\n"); while(ret) { @@ -97,5 +98,5 @@ void DirectoryDepth(const char* path) pos++; } - printf("\tCreated %ld levels of directory hierarchy\n", pos); + log_write("\tCreated %ld levels of directory hierarchy\n", pos); } diff --git a/setter/src/win32/filename.c b/setter/src/win32/filename.c index 544ef8c..51e854d 100644 --- a/setter/src/win32/filename.c +++ b/setter/src/win32/filename.c @@ -35,6 +35,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "win32.h" #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" void Filenames(const char* path) { @@ -52,7 +53,7 @@ void Filenames(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -66,7 +67,7 @@ void Filenames(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -75,7 +76,7 @@ void Filenames(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -84,11 +85,11 @@ void Filenames(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating files with different filenames.\n"); + log_write("Creating files with different filenames.\n"); for(pos = 0; filenames[pos]; pos++) { @@ -110,6 +111,6 @@ void Filenames(const char* path) if(!ret) cRc = GetLastError(); } - printf("\tFile name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", filenames[pos], rc, wRc, cRc); + log_write("\tFile name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", filenames[pos], rc, wRc, cRc); } } diff --git a/setter/src/win32/files.c b/setter/src/win32/files.c index 4d859e9..ece5b06 100644 --- a/setter/src/win32/files.c +++ b/setter/src/win32/files.c @@ -34,6 +34,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "win32.h" #include "../include/defs.h" +#include "../log.h" void MillionFiles(const char* path) { @@ -49,7 +50,7 @@ void MillionFiles(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -63,7 +64,7 @@ void MillionFiles(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -72,7 +73,7 @@ void MillionFiles(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -81,11 +82,11 @@ void MillionFiles(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating lots of files.\n"); + log_write("Creating lots of files.\n"); for(pos = 0; pos < 1000; pos++) { @@ -98,5 +99,5 @@ void MillionFiles(const char* path) CloseHandle(h); } - printf("\tCreated %lu files\n", pos); + log_write("\tCreated %lu files\n", pos); } diff --git a/setter/src/win32/frag.c b/setter/src/win32/frag.c index 058855c..d04d59e 100644 --- a/setter/src/win32/frag.c +++ b/setter/src/win32/frag.c @@ -35,6 +35,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "win32.h" #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" void Fragmentation(const char* path, size_t clusterSize) { @@ -57,7 +58,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -71,7 +72,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -80,7 +81,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -89,7 +90,7 @@ void Fragmentation(const char* path, size_t clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } @@ -113,7 +114,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", "HALFCLST", halfCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "HALFCLST", + halfCluster, + rc, + wRc, + cRc); h = CreateFileA("QUARCLST", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -135,8 +141,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf( - "\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", "QUARCLST", quarterCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "QUARCLST", + quarterCluster, + rc, + wRc, + cRc); h = CreateFileA("TWOCLST", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -158,7 +168,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", "TWOCLST", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "TWOCLST", + twoCluster, + rc, + wRc, + cRc); h = CreateFileA("TRQTCLST", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -180,12 +195,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", - "TRQTCLST", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "TRQTCLST", + threeQuartersCluster, + rc, + wRc, + cRc); h = CreateFileA("TWTQCLST", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -207,12 +222,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", - "TWTQCLST", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "TWTQCLST", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); h = CreateFileA("TWO1", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -234,7 +249,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", "TWO1", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "TWO1", + twoCluster, + rc, + wRc, + cRc); h = CreateFileA("TWO2", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -256,7 +276,12 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", "TWO2", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "TWO2", + twoCluster, + rc, + wRc, + cRc); h = CreateFileA("TWO3", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -278,11 +303,16 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO2\".\n"); + log_write("\tDeleting \"TWO2\".\n"); ret = DeleteFileA("TWO2"); if(!ret) { rc = GetLastError(); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", "TWO3", twoCluster, rc, wRc, cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "TWO3", + twoCluster, + rc, + wRc, + cRc); h = CreateFileA("FRAGTHRQ", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -304,19 +334,19 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tDeleting \"TWO1\".\n"); + log_write("\tDeleting \"TWO1\".\n"); ret = DeleteFileA("TWO1"); if(!ret) { rc = GetLastError(); } - printf("\tDeleting \"TWO3\".\n"); + log_write("\tDeleting \"TWO3\".\n"); ret = DeleteFileA("TWO3"); if(!ret) { rc = GetLastError(); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", - "FRAGTHRQ", - threeQuartersCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "FRAGTHRQ", + threeQuartersCluster, + rc, + wRc, + cRc); h = CreateFileA("FRAGSIXQ", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -338,10 +368,10 @@ void Fragmentation(const char* path, size_t clusterSize) free(buffer); } - printf("\tFile name = \"%s\", size = "SIZE_T_FORMAT", rc = %lu, wRc = %lu, cRc = %lu\n", - "FRAGSIXQ", - twoAndThreeQuartCluster, - rc, - wRc, - cRc); + log_write("\tFile name = \"%s\", size = " SIZE_T_FORMAT ", rc = %lu, wRc = %lu, cRc = %lu\n", + "FRAGSIXQ", + twoAndThreeQuartCluster, + rc, + wRc, + cRc); } diff --git a/setter/src/win32/links.c b/setter/src/win32/links.c index 6440f8d..0905f6d 100644 --- a/setter/src/win32/links.c +++ b/setter/src/win32/links.c @@ -37,6 +37,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "links.h" #include "../include/defs.h" +#include "../log.h" extern DWORD oldVersion; @@ -62,7 +63,7 @@ void Links(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu querying Windows version.\n", error); + log_write("Error %lu querying Windows version.\n", error); return; } } @@ -79,7 +80,7 @@ void Links(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -93,7 +94,7 @@ void Links(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -102,7 +103,7 @@ void Links(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -111,7 +112,7 @@ void Links(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } @@ -120,7 +121,7 @@ void Links(const char* path) if(!kernel32) { error = GetLastError(); - printf("Error %lu loading KERNEL32.DLL.\n", error); + log_write("Error %lu loading KERNEL32.DLL.\n", error); return; } @@ -129,12 +130,12 @@ void Links(const char* path) if(!func) { error = GetLastError(); - printf("Error %lu finding CreateSymbolicLinkA.\n", error); + log_write("Error %lu finding CreateSymbolicLinkA.\n", error); } else { WinNtCreateSymbolicLinkA = func; - printf("Creating symbolic links.\n"); + log_write("Creating symbolic links.\n"); h = CreateFileA("TARGET", dwFilePermissions, @@ -162,7 +163,7 @@ void Links(const char* path) if(!ret) lRc = GetLastError(); } - printf("\tSymbolic link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc); + log_write("\tSymbolic link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc); } func = GetProcAddress(kernel32, "CreateHardLinkA"); @@ -170,12 +171,12 @@ void Links(const char* path) if(!func) { error = GetLastError(); - printf("Error %lu finding CreateHardLinkA.\n", error); + log_write("Error %lu finding CreateHardLinkA.\n", error); } else { WinNtCreateHardLinkA = func; - printf("Creating hard links.\n"); + log_write("Creating hard links.\n"); h = CreateFileA("HARDTRGT", dwFilePermissions, @@ -203,7 +204,7 @@ void Links(const char* path) if(!ret) lRc = GetLastError(); } - printf("\tHard link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc); + log_write("\tHard link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc); } FreeLibrary(kernel32); diff --git a/setter/src/win32/os.c b/setter/src/win32/os.c index 984c6f3..0c61b63 100644 --- a/setter/src/win32/os.c +++ b/setter/src/win32/os.c @@ -36,6 +36,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "os.h" #include "../include/defs.h" +#include "../log.h" DWORD oldVersion; @@ -59,9 +60,10 @@ void GetOsInfo() oldVersion &= 0x80000000; if(oldVersion == 0) - printf("\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write( + "\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); else - printf("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); return; } @@ -77,9 +79,10 @@ void GetOsInfo() oldVersion &= 0x80000000; if(oldVersion == 0) - printf("\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write( + "\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); else - printf("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); FreeLibrary(kernel32); @@ -94,49 +97,49 @@ void GetOsInfo() if(!ret) { error = GetLastError(); - printf("Error %lu querying Windows version.\n", error); + log_write("Error %lu querying Windows version.\n", error); FreeLibrary(kernel32); return; } - printf("OS information:\n"); + log_write("OS information:\n"); if(verInfo.dwPlatformId == VER_PLATFORM_WIN32s) - printf("\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write("\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); else if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if(verInfo.dwMinorVersion == 10) { - if(verInfo.dwBuildNumber == 2222) printf("\tRunning under Windows 98 SE"); + if(verInfo.dwBuildNumber == 2222) log_write("\tRunning under Windows 98 SE"); else - printf("\tRunning under Windows 98"); + log_write("\tRunning under Windows 98"); } else if(verInfo.dwMinorVersion == 90) - printf("\tRunning under Windows Me"); + log_write("\tRunning under Windows Me"); else if(verInfo.dwMinorVersion < 10) - printf("\tRunning under Windows 95"); + log_write("\tRunning under Windows 95"); else - printf("\tRunning under Windows"); + log_write("\tRunning under Windows"); if(verInfo.dwBuildNumber > 0) { if(strlen(verInfo.szCSDVersion) > 0) - printf(" version %lu.%02lu.%lu%ss.\n", - verInfo.dwMajorVersion, - verInfo.dwMinorVersion, - verInfo.dwBuildNumber, - verInfo.szCSDVersion); + log_write(" version %lu.%02lu.%lu%ss.\n", + verInfo.dwMajorVersion, + verInfo.dwMinorVersion, + verInfo.dwBuildNumber, + verInfo.szCSDVersion); else - printf( + log_write( " version %lu.%02lu%lud.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion, verInfo.dwBuildNumber); } else { if(strlen(verInfo.szCSDVersion) > 0) - printf( + log_write( " version %lu.%02lu %s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion, verInfo.szCSDVersion); else - printf(" version %lu.%02lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write(" version %lu.%02lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); } } else if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) @@ -146,24 +149,24 @@ void GetOsInfo() case 5: switch(verInfo.dwMinorVersion) { - case 0: printf("\tRunning under Windows 2000"); break; - case 1: printf("\tRunning under Windows XP"); break; - case 2: printf("\tRunning under Windows Server 2003"); break; - default: printf("\tRunning under Windows NT"); + case 0: log_write("\tRunning under Windows 2000"); break; + case 1: log_write("\tRunning under Windows XP"); break; + case 2: log_write("\tRunning under Windows Server 2003"); break; + default: log_write("\tRunning under Windows NT"); } break; case 6: switch(verInfo.dwMinorVersion) { - case 0: printf("\tRunning under Windows Vista"); break; - case 1: printf("\tRunning under Windows 7"); break; - case 2: printf("\tRunning under Windows 8"); break; - case 3: printf("\tRunning under Windows 8.1"); break; - default: printf("\tRunning under Windows NT"); break; + case 0: log_write("\tRunning under Windows Vista"); break; + case 1: log_write("\tRunning under Windows 7"); break; + case 2: log_write("\tRunning under Windows 8"); break; + case 3: log_write("\tRunning under Windows 8.1"); break; + default: log_write("\tRunning under Windows NT"); break; } break; - case 10: printf("\tRunning under Windows 10"); break; - default: printf("\tRunning under Windows NT"); break; + case 10: log_write("\tRunning under Windows 10"); break; + default: log_write("\tRunning under Windows NT"); break; } if(verInfo.dwMinorVersion < 10) verInfo.dwMinorVersion = verInfo.dwMinorVersion * 10; @@ -171,22 +174,22 @@ void GetOsInfo() if(verInfo.dwBuildNumber > 0) { if(strlen(verInfo.szCSDVersion) > 0) - printf(" version %lu.%02lu.%lu %s.\n", - verInfo.dwMajorVersion, - verInfo.dwMinorVersion, - verInfo.dwBuildNumber, - verInfo.szCSDVersion); + log_write(" version %lu.%02lu.%lu %s.\n", + verInfo.dwMajorVersion, + verInfo.dwMinorVersion, + verInfo.dwBuildNumber, + verInfo.szCSDVersion); else - printf( + log_write( " version %lu.%02lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion, verInfo.dwBuildNumber); } else { if(strlen(verInfo.szCSDVersion) > 0) - printf( + log_write( " version %lu.%02lu %s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion, verInfo.szCSDVersion); else - printf(" version %lu%02lud.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + log_write(" version %lu%02lud.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); } } diff --git a/setter/src/win32/rsrcfork.c b/setter/src/win32/rsrcfork.c index e63f61c..d7730f5 100644 --- a/setter/src/win32/rsrcfork.c +++ b/setter/src/win32/rsrcfork.c @@ -37,6 +37,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "rsrcfork.h" #include "../include/defs.h" +#include "../log.h" extern DWORD oldVersion; @@ -60,7 +61,7 @@ void ResourceFork(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu querying Windows version.\n", error); + log_write("Error %lu querying Windows version.\n", error); return; } } @@ -77,7 +78,7 @@ void ResourceFork(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -91,7 +92,7 @@ void ResourceFork(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -100,7 +101,7 @@ void ResourceFork(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -109,11 +110,11 @@ void ResourceFork(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating alternate data streams.\n"); + log_write("Creating alternate data streams.\n"); h = CreateFileA("TINY:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -128,11 +129,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with tiny alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "TINY:ADS", - rc, - wRc, - cRc); + log_write("\tFile with tiny alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "TINY:ADS", + rc, + wRc, + cRc); maxLoop = (4095 - strlen(smallAdsText)) / strlen(smallAdsRepeatText); h = CreateFileA("SMALL:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -158,11 +159,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with small alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "SMALL:ADS", - rc, - wRc, - cRc); + log_write("\tFile with small alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "SMALL:ADS", + rc, + wRc, + cRc); maxLoop = (65535 - strlen(mediumAdsText)) / strlen(mediumAdsRepeatText); h = CreateFileA("MEDIUM:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -189,11 +190,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with medium alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "MEDIUM:ADS", - rc, - wRc, - cRc); + log_write("\tFile with medium alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "MEDIUM:ADS", + rc, + wRc, + cRc); maxLoop = (67584 - strlen(bigAdsText)) / strlen(bigAdsRepeatText); h = CreateFileA("BIG:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -219,11 +220,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with big alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "BIG:ADS", - rc, - wRc, - cRc); + log_write("\tFile with big alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "BIG:ADS", + rc, + wRc, + cRc); h = CreateFileA("MULTIPLE:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -238,11 +239,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with tiny alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "MULTIPLE:ADS", - rc, - wRc, - cRc); + log_write("\tFile with tiny alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "MULTIPLE:ADS", + rc, + wRc, + cRc); maxLoop = (4095 - strlen(smallAdsText)) / strlen(smallAdsRepeatText); h = CreateFileA("MULTIPLE:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -269,11 +270,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with small alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "MULTIPLE:ADS", - rc, - wRc, - cRc); + log_write("\tFile with small alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "MULTIPLE:ADS", + rc, + wRc, + cRc); maxLoop = (65535 - strlen(mediumAdsText)) / strlen(mediumAdsRepeatText); h = CreateFileA("MULTIPLE:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -301,11 +302,11 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with medium alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "MULTIPLE:ADS", - rc, - wRc, - cRc); + log_write("\tFile with medium alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "MULTIPLE:ADS", + rc, + wRc, + cRc); maxLoop = (67584 - strlen(bigAdsText)) / strlen(bigAdsRepeatText); h = CreateFileA("MULTIPLE:ADS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -332,9 +333,9 @@ void ResourceFork(const char* path) ret = CloseHandle(h); if(!ret) cRc = GetLastError(); } - printf("\tFile with medium alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", - "MULTIPLE:ADS", - rc, - wRc, - cRc); + log_write("\tFile with medium alternate data stream: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", + "MULTIPLE:ADS", + rc, + wRc, + cRc); } diff --git a/setter/src/win32/sparse.c b/setter/src/win32/sparse.c index 463294a..2bb955a 100644 --- a/setter/src/win32/sparse.c +++ b/setter/src/win32/sparse.c @@ -38,6 +38,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" void Sparse(const char* path) { @@ -60,7 +61,7 @@ void Sparse(const char* path) if(lpVolumeNameBuffer == NULL) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -68,7 +69,7 @@ void Sparse(const char* path) if(lpFileSystemNameBuffer == NULL) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); free(lpVolumeNameBuffer); return; } @@ -77,7 +78,7 @@ void Sparse(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); free(lpVolumeNameBuffer); free(lpFileSystemNameBuffer); return; @@ -100,7 +101,7 @@ void Sparse(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu querying volume information.\n", error); + log_write("Error %lu querying volume information.\n", error); free(lpVolumeNameBuffer); free(lpFileSystemNameBuffer); free(lpRootPathName); @@ -121,7 +122,7 @@ void Sparse(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -130,7 +131,7 @@ void Sparse(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -139,13 +140,13 @@ void Sparse(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } free(lpRootPathName); - printf("Creating sparse files.\n"); + log_write("Creating sparse files.\n"); h = CreateFileA("SMALL", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -213,14 +214,14 @@ void Sparse(const char* path) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %lu, wRc = %lu, cRc = %lu, sRc = %lu, zRc = %lu\n", - "SMALL", - 4096 * 3, - rc, - wRc, - cRc, - sRc, - zRc); + log_write("\tFile name = \"%s\", size = %d, rc = %lu, wRc = %lu, cRc = %lu, sRc = %lu, zRc = %lu\n", + "SMALL", + 4096 * 3, + rc, + wRc, + cRc, + sRc, + zRc); h = CreateFileA("BIG", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); rc = 0; @@ -288,12 +289,12 @@ void Sparse(const char* path) free(buffer); } - printf("\tFile name = \"%s\", size = %d, rc = %lu, wRc = %lu, cRc = %lu, sRc = %lu, zRc = %lu\n", - "BIG", - 4096 * 30, - rc, - wRc, - cRc, - sRc, - zRc); + log_write("\tFile name = \"%s\", size = %d, rc = %lu, wRc = %lu, cRc = %lu, sRc = %lu, zRc = %lu\n", + "BIG", + 4096 * 30, + rc, + wRc, + cRc, + sRc, + zRc); } diff --git a/setter/src/win32/time.c b/setter/src/win32/time.c index cae8f7f..1a24d02 100644 --- a/setter/src/win32/time.c +++ b/setter/src/win32/time.c @@ -37,24 +37,25 @@ Copyright (C) 2011-2021 Natalia Portillo #include "time.h" #include "../include/defs.h" +#include "../log.h" void Timestamps(const char* path) { - char message[300]; - BOOL ret; - DWORD error; - LPSTR lpRootPathName; - size_t pathSize = strlen(path); - HANDLE h; - DWORD rc, wRc, cRc, tRc; - DWORD dwNumberOfBytesWritten; - int i; + char message[300]; + BOOL ret; + DWORD error; + LPSTR lpRootPathName; + size_t pathSize = strlen(path); + HANDLE h; + DWORD rc, wRc, cRc, tRc; + DWORD dwNumberOfBytesWritten; + int i; lpRootPathName = malloc(dwMaxNameSize); if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -68,7 +69,7 @@ void Timestamps(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); return; } @@ -77,7 +78,7 @@ void Timestamps(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); return; } @@ -86,11 +87,11 @@ void Timestamps(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); return; } - printf("Creating timestamped files.\n"); + log_write("Creating timestamped files.\n"); for(i = 0; i < KNOWN_WIN32_TIMESTAMPS; i++) { @@ -125,11 +126,11 @@ void Timestamps(const char* path) if(!ret) cRc = GetLastError(); } - printf("\tFile name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu, tRc = %lu\n", - win32_timestamps[i].filename, - rc, - wRc, - cRc, - tRc); + log_write("\tFile name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu, tRc = %lu\n", + win32_timestamps[i].filename, + rc, + wRc, + cRc, + tRc); } } diff --git a/setter/src/win32/volume.c b/setter/src/win32/volume.c index ea7b3b7..36352e5 100644 --- a/setter/src/win32/volume.c +++ b/setter/src/win32/volume.c @@ -37,6 +37,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "volume.h" #include "../include/defs.h" +#include "../log.h" extern DWORD oldVersion; @@ -63,14 +64,14 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) *clusterSize = 0; - printf("Volume information:\n"); - printf("\tPath: %s\n", path); + log_write("Volume information:\n"); + log_write("\tPath: %s\n", path); lpVolumeNameBuffer = malloc(dwMaxNameSize); if(lpVolumeNameBuffer == NULL) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); return; } @@ -78,7 +79,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(lpFileSystemNameBuffer == NULL) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); free(lpVolumeNameBuffer); return; } @@ -87,7 +88,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); free(lpVolumeNameBuffer); free(lpFileSystemNameBuffer); return; @@ -110,160 +111,160 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu querying volume information.\n", error); + log_write("Error %lu querying volume information.\n", error); free(lpVolumeNameBuffer); free(lpFileSystemNameBuffer); free(lpRootPathName); return; } - printf("\tFilesystem: %s\n", lpFileSystemNameBuffer); - printf("\tVolume name: %s\n", lpVolumeNameBuffer); - printf("\tMaximum component size: %lu\n", dwMaximumComponentLength); + log_write("\tFilesystem: %s\n", lpFileSystemNameBuffer); + log_write("\tVolume name: %s\n", lpVolumeNameBuffer); + log_write("\tMaximum component size: %lu\n", dwMaximumComponentLength); if(dwFileSystemFlags > 0) { - printf("\tFlags:\n"); + log_write("\tFlags:\n"); if(dwFileSystemFlags & (DWORD)FILE_CASE_PRESERVED_NAMES) { - printf("\t\tVolume preserves file name case.\n"); + log_write("\t\tVolume preserves file name case.\n"); dwFileSystemFlags -= FILE_CASE_PRESERVED_NAMES; } if(dwFileSystemFlags & (DWORD)FILE_CASE_SENSITIVE_SEARCH) { - printf("\t\tVolume supports case sensitiveness.\n"); + log_write("\t\tVolume supports case sensitiveness.\n"); dwFileSystemFlags -= FILE_CASE_SENSITIVE_SEARCH; } if(dwFileSystemFlags & (DWORD)FILE_DAX_VOLUME) { - printf("\t\tDirect access volume.\n"); + log_write("\t\tDirect access volume.\n"); dwFileSystemFlags -= FILE_DAX_VOLUME; } if(dwFileSystemFlags & (DWORD)FILE_FILE_COMPRESSION) { - printf("\t\tVolume supports per-file compression.\n"); + log_write("\t\tVolume supports per-file compression.\n"); dwFileSystemFlags -= FILE_FILE_COMPRESSION; } if(dwFileSystemFlags & (DWORD)FILE_NAMED_STREAMS) { - printf("\t\tVolume supports Alternate Data Streams.\n"); + log_write("\t\tVolume supports Alternate Data Streams.\n"); dwFileSystemFlags -= FILE_NAMED_STREAMS; } if(dwFileSystemFlags & (DWORD)FILE_PERSISTENT_ACLS) { - printf("\t\tVolume supports persistent Access Control Lists.\n"); + log_write("\t\tVolume supports persistent Access Control Lists.\n"); dwFileSystemFlags -= FILE_PERSISTENT_ACLS; } if(dwFileSystemFlags & (DWORD)FILE_READ_ONLY_VOLUME) { - printf("\t\tVolume is read-only.\n"); + log_write("\t\tVolume is read-only.\n"); dwFileSystemFlags -= FILE_READ_ONLY_VOLUME; } if(dwFileSystemFlags & (DWORD)FILE_SEQUENTIAL_WRITE_ONCE) { - printf("\t\tVolume supports a single sequential write.\n"); + log_write("\t\tVolume supports a single sequential write.\n"); dwFileSystemFlags -= FILE_SEQUENTIAL_WRITE_ONCE; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_ENCRYPTION) { - printf("\t\tVolume supports per-file encryption.\n"); + log_write("\t\tVolume supports per-file encryption.\n"); dwFileSystemFlags -= FILE_SUPPORTS_ENCRYPTION; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_EXTENDED_ATTRIBUTES) { - printf("\t\tVolume supports extended attributes.\n"); + log_write("\t\tVolume supports extended attributes.\n"); dwFileSystemFlags -= FILE_SUPPORTS_EXTENDED_ATTRIBUTES; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_HARD_LINKS) { - printf("\t\tVolume supports hard links.\n"); + log_write("\t\tVolume supports hard links.\n"); dwFileSystemFlags -= FILE_SUPPORTS_HARD_LINKS; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_OBJECT_IDS) { - printf("\t\tVolume supports object IDs.\n"); + log_write("\t\tVolume supports object IDs.\n"); dwFileSystemFlags -= FILE_SUPPORTS_OBJECT_IDS; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_OPEN_BY_FILE_ID) { - printf("\t\tVolume can open files by ID.\n"); + log_write("\t\tVolume can open files by ID.\n"); dwFileSystemFlags -= FILE_SUPPORTS_OPEN_BY_FILE_ID; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_REPARSE_POINTS) { - printf("\t\tVolume supports reparse points.\n"); + log_write("\t\tVolume supports reparse points.\n"); dwFileSystemFlags -= FILE_SUPPORTS_REPARSE_POINTS; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_SPARSE_FILES) { - printf("\t\tVolume supports sparse files.\n"); + log_write("\t\tVolume supports sparse files.\n"); dwFileSystemFlags -= FILE_SUPPORTS_SPARSE_FILES; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_TRANSACTIONS) { - printf("\t\tVolume supports transactions.\n"); + log_write("\t\tVolume supports transactions.\n"); dwFileSystemFlags -= FILE_SUPPORTS_TRANSACTIONS; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_USN_JOURNAL) { - printf("\t\tVolume has an USN journal.\n"); + log_write("\t\tVolume has an USN journal.\n"); dwFileSystemFlags -= FILE_SUPPORTS_USN_JOURNAL; } if(dwFileSystemFlags & (DWORD)FILE_UNICODE_ON_DISK) { - printf("\t\tVolume stores filenames as Unicode.\n"); + log_write("\t\tVolume stores filenames as Unicode.\n"); dwFileSystemFlags -= FILE_UNICODE_ON_DISK; } if(dwFileSystemFlags & (DWORD)FILE_VOLUME_IS_COMPRESSED) { - printf("\t\tVolume is compressed.\n"); + log_write("\t\tVolume is compressed.\n"); dwFileSystemFlags -= FILE_VOLUME_IS_COMPRESSED; } if(dwFileSystemFlags & (DWORD)FILE_VOLUME_QUOTAS) { - printf("\t\tVolume supports user quotas.\n"); + log_write("\t\tVolume supports user quotas.\n"); dwFileSystemFlags -= FILE_VOLUME_QUOTAS; } if(dwFileSystemFlags & (DWORD)FILE_RETURNS_CLEANUP_RESULT_INFO) { - printf("\t\tOn a clean operation, volume returns additional information.\n"); + log_write("\t\tOn a clean operation, volume returns additional information.\n"); dwFileSystemFlags -= FILE_RETURNS_CLEANUP_RESULT_INFO; } if(dwFileSystemFlags & (DWORD)FILE_SUPPORTS_POSIX_UNLINK_RENAME) { - printf("\t\tVolume supports POSIX-style delete and rename operations.\n"); + log_write("\t\tVolume supports POSIX-style delete and rename operations.\n"); dwFileSystemFlags -= FILE_SUPPORTS_POSIX_UNLINK_RENAME; } if(dwFileSystemFlags & (DWORD)FS_LFN_APIS) { - printf("\t\tVolume supports LFN API.\n"); + log_write("\t\tVolume supports LFN API.\n"); dwFileSystemFlags -= FS_LFN_APIS; } - if(dwFileSystemFlags > 0) printf("Unknown flags: 0x%08lx.\n", dwFileSystemFlags); + if(dwFileSystemFlags > 0) log_write("Unknown flags: 0x%08lx.\n", dwFileSystemFlags); } free(lpVolumeNameBuffer); @@ -275,14 +276,14 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu querying volume space.\n", error); + log_write("Error %lu querying volume space.\n", error); free(lpRootPathName); return; } *clusterSize = dwSectorsPerCluster * dwBytesPerSector; - printf("\tBytes per sector: %lu\n", dwBytesPerSector); - printf("\tSectors per cluster: %lu ("SIZE_T_FORMAT" bytes)\n", dwSectorsPerCluster, *clusterSize); + log_write("\tBytes per sector: %lu\n", dwBytesPerSector); + log_write("\tSectors per cluster: %lu (" SIZE_T_FORMAT " bytes)\n", dwSectorsPerCluster, *clusterSize); if(WinGetVersionExA) { @@ -292,7 +293,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu querying Windows version.\n", error); + log_write("Error %lu querying Windows version.\n", error); free(lpRootPathName); return; } @@ -320,13 +321,13 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(!ret) { error = GetLastError(); - printf("Error %lu querying extended volume space.\n", error); + log_write("Error %lu querying extended volume space.\n", error); free(lpRootPathName); return; } - printf("\tVolume size: %I64d bytes\n", qwTotalNumberOfBytes.QuadPart); - printf("\tVolume free: %I64d bytes\n", qwTotalNumberOfFreeBytes.QuadPart); + log_write("\tVolume size: %I64d bytes\n", qwTotalNumberOfBytes.QuadPart); + log_write("\tVolume free: %I64d bytes\n", qwTotalNumberOfFreeBytes.QuadPart); } else { @@ -335,8 +336,8 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) qwTotalNumberOfBytes.QuadPart *= *clusterSize; qwTotalNumberOfFreeBytes.QuadPart *= *clusterSize; - printf("\tClusters: %lu (%I64d bytes)\n", dwTotalNumberOfClusters, qwTotalNumberOfBytes.QuadPart); - printf("\tFree clusters: %lu (%I64d bytes)\n", dwNumberOfFreeClusters, qwTotalNumberOfFreeBytes.QuadPart); + log_write("\tClusters: %lu (%I64d bytes)\n", dwTotalNumberOfClusters, qwTotalNumberOfBytes.QuadPart); + log_write("\tFree clusters: %lu (%I64d bytes)\n", dwNumberOfFreeClusters, qwTotalNumberOfFreeBytes.QuadPart); } free(lpRootPathName); diff --git a/setter/src/win32/xattr.c b/setter/src/win32/xattr.c index 2b4719b..2c89502 100644 --- a/setter/src/win32/xattr.c +++ b/setter/src/win32/xattr.c @@ -37,6 +37,7 @@ Copyright (C) 2011-2021 Natalia Portillo #include "xattr.h" #include "../include/defs.h" +#include "../log.h" extern DWORD oldVersion; @@ -66,7 +67,7 @@ void ExtendedAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu querying Windows version.\n", error); + log_write("Error %lu querying Windows version.\n", error); return; } } @@ -84,7 +85,7 @@ void ExtendedAttributes(const char* path) if(ntdll == NULL) { error = GetLastError(); - printf("Error %lu loading NTDLL.DLL.\n", error); + log_write("Error %lu loading NTDLL.DLL.\n", error); return; } @@ -93,7 +94,7 @@ void ExtendedAttributes(const char* path) if(func == NULL) { error = GetLastError(); - printf("Error %lu finding NtSetEaFile.\n", error); + log_write("Error %lu finding NtSetEaFile.\n", error); FreeLibrary(ntdll); return; } @@ -105,7 +106,7 @@ void ExtendedAttributes(const char* path) if(func == NULL) { error = GetLastError(); - printf("Error %lu finding NtQueryEaFile.\n", error); + log_write("Error %lu finding NtQueryEaFile.\n", error); FreeLibrary(ntdll); return; } @@ -116,7 +117,7 @@ void ExtendedAttributes(const char* path) if(!lpRootPathName) { - printf("Could not allocate memory.\n"); + log_write("Could not allocate memory.\n"); FreeLibrary(ntdll); return; } @@ -131,7 +132,7 @@ void ExtendedAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to specified path.\n", error); + log_write("Error %lu changing to specified path.\n", error); FreeLibrary(ntdll); return; } @@ -141,7 +142,7 @@ void ExtendedAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu creating working directory.\n", error); + log_write("Error %lu creating working directory.\n", error); FreeLibrary(ntdll); return; } @@ -151,12 +152,12 @@ void ExtendedAttributes(const char* path) if(!ret) { error = GetLastError(); - printf("Error %lu changing to working directory.\n", error); + log_write("Error %lu changing to working directory.\n", error); FreeLibrary(ntdll); return; } - printf("Creating files with extended attributes.\n"); + log_write("Creating files with extended attributes.\n"); rRc = 0; cmp = TRUE; @@ -209,13 +210,13 @@ void ExtendedAttributes(const char* path) if(!ret) cRc = GetLastError(); } - printf("\tFile with comments = \"%s\", rc = 0x%08lx, wRc = %lu, cRc = %lu, rRc = %lu, cmp = %d\n", - "COMMENTS", - rc, - wRc, - cRc, - rRc, - cmp); + log_write("\tFile with comments = \"%s\", rc = 0x%08lx, wRc = %lu, cRc = %lu, rRc = %lu, cmp = %d\n", + "COMMENTS", + rc, + wRc, + cRc, + rRc, + cmp); rRc = 0; cmp = TRUE; @@ -268,13 +269,13 @@ void ExtendedAttributes(const char* path) if(!ret) cRc = GetLastError(); } - printf("\tFile with comments = \"%s\", rc = 0x%08lx, wRc = %lu, cRc = %lu, rRc = %lu, cmp = %d\n", - "COMMENTS.CRT", - rc, - wRc, - cRc, - rRc, - cmp); + log_write("\tFile with comments = \"%s\", rc = 0x%08lx, wRc = %lu, cRc = %lu, rRc = %lu, cmp = %d\n", + "COMMENTS.CRT", + rc, + wRc, + cRc, + rRc, + cmp); rRc = 0; cmp = TRUE; @@ -327,13 +328,13 @@ void ExtendedAttributes(const char* path) if(!ret) cRc = GetLastError(); } - printf("\tFile with icon = \"%s\", rc = 0x%08lx, wRc = %lu, cRc = %lu, rRc = %lu, cmp = %d\n", - "ICON", - rc, - wRc, - cRc, - rRc, - cmp); + log_write("\tFile with icon = \"%s\", rc = 0x%08lx, wRc = %lu, cRc = %lu, rRc = %lu, cmp = %d\n", + "ICON", + rc, + wRc, + cRc, + rRc, + cmp); FreeLibrary(ntdll); }