if (lc->config.info.lo_flags & LO_FLAGS_DIRECT_IO)
flags |= O_DIRECT;
if (lc->flags & LOOPDEV_FL_NOFOLLOW)
- flags |= O_NOFOLLOW;
-
- if ((file_fd = open(lc->filename, mode | flags)) < 0) {
- if (mode != O_RDONLY && (errno == EROFS || errno == EACCES))
- file_fd = open(lc->filename, (mode = O_RDONLY) | flags);
+ file_fd = ul_open_no_symlinks(lc->filename, mode | flags, 0);
+ else
+ file_fd = open(lc->filename, mode | flags);
- if (file_fd < 0) {
- DBG_OBJ(SETUP, lc, ul_debug("open backing file failed: %m"));
- return -errno;
- }
+ if (file_fd < 0 && mode != O_RDONLY
+ && (errno == EROFS || errno == EACCES)) {
+ mode = O_RDONLY;
+ if (lc->flags & LOOPDEV_FL_NOFOLLOW)
+ file_fd = ul_open_no_symlinks(lc->filename, mode | flags, 0);
+ else
+ file_fd = open(lc->filename, mode | flags);
+ }
+ if (file_fd < 0) {
+ DBG_OBJ(SETUP, lc, ul_debug("open backing file failed: %m"));
+ return -errno;
}
DBG_OBJ(SETUP, lc, ul_debug("backing file open: OK"));