diff options
-rw-r--r-- | include/blkdev.h | 3 | ||||
-rw-r--r-- | mount/fsprobe_volumeid.c | 11 | ||||
-rw-r--r-- | mount/mount.c | 13 |
3 files changed, 26 insertions, 1 deletions
diff --git a/include/blkdev.h b/include/blkdev.h index 1b10569b..409b5e43 100644 --- a/include/blkdev.h +++ b/include/blkdev.h @@ -6,6 +6,9 @@ #define DEFAULT_SECTOR_SIZE 512 +/* open() retries when errno is ENOMEDIUM */ +#define CRDOM_NOMEDIUM_RETRIES 5 + #if !defined(BLKROSET) && defined(__linux__) #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c index 7c98dc6e..949db829 100644 --- a/mount/fsprobe_volumeid.c +++ b/mount/fsprobe_volumeid.c @@ -3,6 +3,7 @@ #include <unistd.h> #include <string.h> #include <stddef.h> +#include <errno.h> #include <sys/mount.h> #include <sys/ioctl.h> #include <fcntl.h> @@ -30,10 +31,18 @@ static char struct volume_id *id; const char *val; char *value = NULL; + int retries = 0; +retry: fd = open(device, O_RDONLY); - if (fd < 0) + if (fd < 0) { + if (errno == ENOMEDIUM && retries < CRDOM_NOMEDIUM_RETRIES) { + ++retries; + sleep(3); + goto retry; + } return NULL; + } id = volume_id_open_fd(fd); if (!id) { diff --git a/mount/mount.c b/mount/mount.c index 39a9bd85..be051355 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -1071,6 +1071,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, int loop = 0; const char *loopdev = 0, *loopfile = 0; struct stat statbuf; + int retries = 0; /* Nr of retries for mount in case of ENOMEDIUM */ /* copies for freeing on exit */ const char *opts1, *spec1, *node1, *types1, *extra_opts1; @@ -1133,6 +1134,7 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, goto out; } +mount_retry: block_signals (SIG_BLOCK); if (!fake) { @@ -1362,6 +1364,17 @@ try_mount_one (const char *spec0, const char *node0, const char *types0, } break; } + case ENOMEDIUM: + if (retries < CRDOM_NOMEDIUM_RETRIES) { + if (verbose) + printf(_("mount: no medium found on %s ...trying again\n"), + spec); + sleep(3); + ++retries; + goto mount_retry; + } + error(_("mount: no medium found on %s"), spec); + break; default: error ("mount: %s", strerror (mnt_err)); break; } |