#include <fcntl.h>
#include <dirent.h>
#include <mntent.h>
+#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/select.h>
{
int umount = !!device->mount_point;
char mount_point[1024];
- int len;
int pos = 0;
int status = 0;
fd_set fds;
struct timeval timeout;
int pid;
int pipe_fd[2];
+ char suffix = 0;
out_buf[0] = 0;
- len = snprintf(mount_point, sizeof(mount_point), "/media/%s", device->label);
- if(len>=(int)sizeof(mount_point))
- return -1;
+ /* Find a mount point that does not exist yet. */
+ while(1)
+ {
+ int len;
+
+ len = snprintf(mount_point, sizeof(mount_point), "/media/%s", device->label);
+ if(len+2>=(int)sizeof(mount_point))
+ return -1;
+
+ if(suffix)
+ len += snprintf(mount_point+len, sizeof(mount_point)-len, "_%c", suffix);
+
+ if(access(mount_point, F_OK)<0 && errno==ENOENT)
+ break;
+
+ if(suffix==0)
+ suffix = '1';
+ else if(suffix<'9')
+ ++suffix;
+ else
+ return -1;
+ }
pipe(pipe_fd);