long long int cPartition::GetFreeSpace() //const { DiskFree(); if(used_ == -1) return -1; else return size_ - used_; }
int main(INT iArgc, PSZ Argv[]) { APIRET rc; ULONG ulDiskSize, ulDiskFree; INT iArg; INT iPartType; PSZ pEnd; PSZ p; for (iArg = 1; iArg < iArgc; iArg++) { strupr(Argv[iArg]); if (Argv[iArg][0] == '/') { switch (Argv[iArg][1]) { case 'V': fDetailed = 1; if (Argv[iArg][2] == ':' && Argv[iArg][3] == '2') fDetailed = 2; if (Argv[iArg][2] == ':' && Argv[iArg][3] == '3') fDetailed = 3; if (Argv[iArg][2] == ':' && Argv[iArg][3] == '4') fDetailed = 4; break; case 'B': fShowBootSector = TRUE; break; case 'P': p = &Argv[iArg][2]; for (;;) { while (*p) { while (isspace(*p)) p++; if (!(*p)) { printf("ERROR: Expected partition types not found!\n"); exit(1); break; } iPartType = strtol(p, &pEnd, 16); if (iPartType > 255) { printf("ERROR: Partition type %X is not valid\n", iPartType); exit(1); } printf("Also including partition types %2.2X.\n", iPartType); rgfFakePart[iPartType] = TRUE; // if (iPartType & PARTITION_HIDDEN) // { // printf("Also including partition types %2.2X.\n", iPartType & ~PARTITION_HIDDEN); // rgfFakePart[iPartType & ~PARTITION_HIDDEN] = TRUE; // } p = pEnd; while (isspace(*p)) p++; if (*p != ',') break; p++; } if (iArg + 1 < iArgc && Argv[iArg+1][0] != '/') { iArg++; p = Argv[iArg]; } else break; } break; default : printf("Unknown option %s ignored.\n", Argv[iArg]); break; } } else printf("Invalid argument %s ignored.\n", Argv[iArg]); } rc = InitProg(); if (rc) return rc; if (usDriveCount > 0 && fDetailed > 2) { PDRIVEINFO pDrive = rgDrives; USHORT usDrive; for (usDrive = 0; usDrive < usDriveCount; usDrive++) { pDrive = &rgDrives[usDrive]; printf("\n=== Directory structure of FAT32 DRIVE #%d===\n", pDrive->DiskNum); rc = OpenDisk(pDrive->DiskNum, &pDrive->hDisk); DumpDirectory(pDrive, pDrive->bpb.RootDirStrtClus, "X:"); CheckSpace(pDrive); #ifdef HENK ulDiskSize = DiskSize('F'); ulDiskFree = DiskFree('F'); #endif printf("\n"); printf("Found:\n"); printf("Disk size = %13lu\n", pDrive->ulTotalClusters); printf("In use = %13ld\n", ulTotalClusters); printf("Free = %13ld\n", ulTotalFree); #ifdef HENK printf("Reported by DOS:\n"); printf("Disk size = %13lu\n", ulDiskSize / 4096); printf("In Use = %13lu\n", (ulDiskSize - ulDiskFree)/4096); printf("Free = %13lu\n", ulDiskFree / 4096); printf("Difference = %13ld\n", (ulDiskSize - ulDiskFree)/4096 - ulTotalClusters); #endif CloseDisk(pDrive->hDisk); pDrive->hDisk = 0; } } return 0; }
// --- Class cPartition -------------------------------------------------------------- cPartition::cPartition(char letter, int number) : letter_(letter) { number_ = number; resizable_ = false; mountpoint_ = NULL; uuid_ = NULL; size_ = 0; used_ = -1; std::stringstream command; FILE *file = NULL; char *buffer = NULL; //char buffer2[256]; char trash[512]; // for strings that are not needed filesystem_ = eUnknownFS; OnlyRecording_ = false; DiskFree(); // get information about size if it is still not available if((mountpoint_ == NULL) && (size_ == 0) && ((int)used_ == -1)) { command << "/sys/block/sd" << letter << "/sd" << letter << number << "/size"; file = fopen(command.str().c_str(), "r"); command.str(""); if(file) { cReadLine readline; size_ = atoll(readline.Read(file))/2; fclose(file); } } if(size_ == 0) // TB: very strange things have happened, no need to continue return; // check if this partition is a swap if(!mountpoint_) { command << "LANG=\"C\" cat /proc/swaps | grep sd" << letter << number; file = popen(command.str().c_str(), "r"); command.str(""); if(file) { cReadLine readline; buffer = readline.Read(file); if(buffer) { mountpoint_ = strdup("SWAP"); sscanf(buffer, "%s %s %llu %llu", trash, trash, &size_, &used_); } buffer = NULL; } pclose(file); } // Get information about filesystem command << "LANG=\"C\" blkid /dev/sd" << letter << number; file = popen(command.str().c_str(), "r"); if(file) { cReadLine readline; buffer = readline.Read(file); if(buffer) { static const char *keyword = " TYPE=\""; if(strstr(buffer, keyword)) { char *type = strstr(buffer, keyword) + strlen(keyword); *(strchr(type, '\"')) = '\0'; if(strcmp(type, "jfs") == 0) filesystem_ = eJFS; else if(strcmp(type, "ext2") == 0) filesystem_ = eEXT2; else if(strcmp(type, "ext3") == 0) filesystem_ = eEXT3; else if(strcmp(type, "swap") == 0) filesystem_ = eSWAP; else filesystem_ = eUnknownFS; } else filesystem_ = eUnknownFS; static const char *keyword2 = " UUID=\""; if(strstr(buffer, keyword2)) { char *uuid = strstr(buffer, keyword2) + strlen(keyword2); *(strchr(uuid, '\"')) = '\0'; uuid_ = strdup(uuid); } else uuid_ = NULL; } buffer = NULL; } pclose(file); // Check if partition is resizable if(filesystem_ == eJFS || filesystem_ == eEXT3) CheckResizable(); }