Version v0.2.64 - Fixed OTP thumb drive detection logic for /media/[username]/[drive_name] pattern

This commit is contained in:
2025-08-14 09:40:45 -04:00
parent f979789c11
commit 0dbd81d1cc

54
otp.c
View File

@@ -2305,14 +2305,39 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
while ((mount_entry = readdir(mount_dir)) != NULL) { while ((mount_entry = readdir(mount_dir)) != NULL) {
if (mount_entry->d_name[0] == '.') continue; if (mount_entry->d_name[0] == '.') continue;
// Check if drive name starts with "OTP"
if (strncmp(mount_entry->d_name, "OTP", 3) != 0) continue;
char mount_path[512]; char mount_path[512];
snprintf(mount_path, sizeof(mount_path), "%s/%s", mount_dirs[mount_idx], mount_entry->d_name); snprintf(mount_path, sizeof(mount_path), "%s/%s", mount_dirs[mount_idx], mount_entry->d_name);
// For /run/media, we need to go one level deeper (skip username) // For /media, we need to go one level deeper (user directories)
if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) { if (strcmp(mount_dirs[mount_idx], "/media") == 0) {
// This is /media/[username] - look inside for drives
DIR* user_dir = opendir(mount_path);
if (!user_dir) continue;
struct dirent* user_entry;
while ((user_entry = readdir(user_dir)) != NULL) {
if (user_entry->d_name[0] == '.') continue;
// Check if drive name starts with "OTP"
if (strncmp(user_entry->d_name, "OTP", 3) != 0) continue;
char user_mount_path[512];
snprintf(user_mount_path, sizeof(user_mount_path), "%s/%s", mount_path, user_entry->d_name);
// Check if this is a readable directory
DIR* drive_dir = opendir(user_mount_path);
if (drive_dir) {
closedir(drive_dir);
strncpy(otp_drive_path, user_mount_path, path_size - 1);
otp_drive_path[path_size - 1] = '\0';
closedir(user_dir);
closedir(mount_dir);
return 1; // Found OTP drive
}
}
closedir(user_dir);
} else if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) {
// For /run/media, we need to go one level deeper (skip username)
DIR* user_dir = opendir(mount_path); DIR* user_dir = opendir(mount_path);
if (!user_dir) continue; if (!user_dir) continue;
@@ -2339,14 +2364,17 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) {
} }
closedir(user_dir); closedir(user_dir);
} else { } else {
// Direct mount point (like /media/OTP_DRIVE or /mnt/OTP_DRIVE) // Direct mount point (like /mnt/OTP_DRIVE)
DIR* drive_dir = opendir(mount_path); // Check if drive name starts with "OTP"
if (drive_dir) { if (strncmp(mount_entry->d_name, "OTP", 3) == 0) {
closedir(drive_dir); DIR* drive_dir = opendir(mount_path);
strncpy(otp_drive_path, mount_path, path_size - 1); if (drive_dir) {
otp_drive_path[path_size - 1] = '\0'; closedir(drive_dir);
closedir(mount_dir); strncpy(otp_drive_path, mount_path, path_size - 1);
return 1; // Found OTP drive otp_drive_path[path_size - 1] = '\0';
closedir(mount_dir);
return 1; // Found OTP drive
}
} }
} }
} }