#include <iostream>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <string>
int main() {
std::string mountPoint = "/mnt/external_drive"; // Define the mount point directory
std::string devicePath = "/dev/sda1"; // Replace with the correct device path of the external hard drive
// Check if the mount point exists, create if not
std::ifstream mountCheck(mountPoint);
if (mountCheck.fail()) {
std::stringstream mkdirCommand;
mkdirCommand << "sudo mkdir " << mountPoint;
system(mkdirCommand.str().c_str());
}
mountCheck.close();
// Mount the external hard drive
std::stringstream mountCommand;
mountCommand << "sudo mount " << devicePath << " " << mountPoint;
system(mountCommand.str().c_str());
// Check if the mount was successful
std::ifstream mountResultCheck(mountPoint);
if (mountResultCheck.fail()) {
std::cerr << "Mounting failed. Check the device path and permissions." << std::endl;
return EXIT_FAILURE;
}
mountResultCheck.close();
// Display success message
std::cout << "External hard drive mounted successfully at: " << mountPoint << std::endl;
return EXIT_SUCCESS;
}