From 0dbd81d1cc45ccdad0a23e696085c2a743ef8467 Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Thu, 14 Aug 2025 09:40:45 -0400 Subject: [PATCH] Version v0.2.64 - Fixed OTP thumb drive detection logic for /media/[username]/[drive_name] pattern --- otp.c | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/otp.c b/otp.c index 6558743..78a6bc8 100644 --- a/otp.c +++ b/otp.c @@ -2305,14 +2305,39 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) { while ((mount_entry = readdir(mount_dir)) != NULL) { 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]; 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) - if (strcmp(mount_dirs[mount_idx], "/run/media") == 0) { + // For /media, we need to go one level deeper (user directories) + 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); if (!user_dir) continue; @@ -2339,14 +2364,17 @@ int detect_otp_thumb_drive(char* otp_drive_path, size_t path_size) { } closedir(user_dir); } else { - // Direct mount point (like /media/OTP_DRIVE or /mnt/OTP_DRIVE) - DIR* drive_dir = opendir(mount_path); - if (drive_dir) { - closedir(drive_dir); - strncpy(otp_drive_path, mount_path, path_size - 1); - otp_drive_path[path_size - 1] = '\0'; - closedir(mount_dir); - return 1; // Found OTP drive + // Direct mount point (like /mnt/OTP_DRIVE) + // Check if drive name starts with "OTP" + if (strncmp(mount_entry->d_name, "OTP", 3) == 0) { + DIR* drive_dir = opendir(mount_path); + if (drive_dir) { + closedir(drive_dir); + strncpy(otp_drive_path, mount_path, path_size - 1); + otp_drive_path[path_size - 1] = '\0'; + closedir(mount_dir); + return 1; // Found OTP drive + } } } }