- 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;
+ }