From: Matthias Koenig Date: Thu, 6 Nov 2008 13:45:38 +0000 (+0100) Subject: losetup: try to set up loop readonly if EACCES X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b23a771db18751a12bf4a7fb32f6dacb5a23938c;p=util-linux losetup: try to set up loop readonly if EACCES Currently mounting/losetup an image fails if it is accessable readonly. There are no problems if it is a file on a local filesystem. It seems only to happen if it is a NFS mounted image, which is read-write in permission but with root_squash option. set_loop checks only for EROFS to retry open with readonly mode, but in this case we get EACCES. Signed-off-by: Matthias Koenig --- diff --git a/mount/lomount.c b/mount/lomount.c index 18f2edfb..f1d74820 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -659,7 +659,8 @@ set_loop(const char *device, const char *file, unsigned long long offset, mode = (*options & SETLOOP_RDONLY) ? O_RDONLY : O_RDWR; if ((ffd = open(file, mode)) < 0) { - if (!(*options & SETLOOP_RDONLY) && errno == EROFS) + if (!(*options & SETLOOP_RDONLY) && + (errno == EROFS || errno == EACCES)) ffd = open(file, mode = O_RDONLY); if (ffd < 0) { perror(file);