diff --git a/include/nilfs.h b/include/nilfs.h index 111a7e6..893fb2f 100644 --- a/include/nilfs.h +++ b/include/nilfs.h @@ -76,6 +76,7 @@ struct nilfs_layout { #define NILFS_OPEN_WRONLY 0x0004 /* Open NILFS API in write only mode */ #define NILFS_OPEN_RDWR 0x0008 /* Open NILFS API in read/write mode */ #define NILFS_OPEN_GCLK 0x1000 /* Open GC lock primitive */ +#define NILFS_OPEN_SRCHDEV 0x2000 /* Search device bound to the node */ struct nilfs *nilfs_open(const char *dev, const char *dir, int flags); diff --git a/lib/Makefile.am b/lib/Makefile.am index ca6c5db..dcfb495 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -27,7 +27,7 @@ libnilfs_REVISION = 0 libnilfs_AGE = 0 libnilfs_VERSIONINFO = $(libnilfs_CURRENT):$(libnilfs_REVISION):$(libnilfs_AGE) -libnilfs_la_SOURCES = nilfs.c sb.c +libnilfs_la_SOURCES = nilfs.c sb.c lookup_device.c libnilfs_la_LDFLAGS = -version-info $(libnilfs_VERSIONINFO) libnilfs_la_LIBADD = librealpath.la libcrc32.la $(LIB_POSIX_SEM) diff --git a/lib/nilfs.c b/lib/nilfs.c index 25bc95d..90821e4 100644 --- a/lib/nilfs.c +++ b/lib/nilfs.c @@ -82,6 +82,7 @@ #include "util.h" #include "pathnames.h" #include "realpath.h" +#include "lookup_device.h" /* nilfs_lookup_device() */ /** * struct nilfs - nilfs object @@ -408,6 +409,7 @@ static int nilfs_open_sem(struct nilfs *nilfs) struct nilfs *nilfs_open(const char *dev, const char *dir, int flags) { struct nilfs *nilfs; + char *backdev; uint64_t features; int ret; @@ -429,6 +431,15 @@ struct nilfs *nilfs_open(const char *dev, const char *dir, int flags) nilfs->n_opts = 0; nilfs->n_mincno = NILFS_CNO_MIN; memset(nilfs->n_sems, 0, sizeof(nilfs->n_sems)); + backdev = NULL; + + if ((flags & NILFS_OPEN_SRCHDEV) && dev) { + ret = nilfs_lookup_device(dev, &backdev); + if (unlikely(ret < 0)) + goto out_fd; + else if (ret > 0) + dev = backdev; /* replace dev in this function */ + } if (flags & NILFS_OPEN_RAW) { if (dev == NULL) { @@ -499,6 +510,7 @@ struct nilfs *nilfs_open(const char *dev, const char *dir, int flags) } /* success */ + free(backdev); return nilfs; /* error */ @@ -508,6 +520,7 @@ out_fd: if (nilfs->n_iocfd >= 0) close(nilfs->n_iocfd); + free(backdev); free(nilfs->n_dev); free(nilfs->n_ioc); free(nilfs->n_sb);