diff --git a/lib/libstand/open.c b/lib/libstand/open.c index 49dc6608ff43..0d90433800a2 100644 --- a/lib/libstand/open.c +++ b/lib/libstand/open.c @@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$"); #include "stand.h" +struct fs_ops *exclusive_file_system; + struct open_file files[SOPEN_MAX]; static int @@ -89,6 +91,7 @@ o_rainit(struct open_file *f) int open(const char *fname, int mode) { + struct fs_ops *fs; struct open_file *f; int fd, i, error, besterror; const char *file; @@ -105,6 +108,15 @@ open(const char *fname, int mode) f->f_offset = 0; f->f_devdata = NULL; file = (char *)0; + + if (exclusive_file_system != NULL) { + fs = exclusive_file_system; + error = (fs->fo_open)(fname, f); + if (error == 0) + goto ok; + goto fail; + } + error = devopen(f, fname, &file); if (error || (((f->f_flags & F_NODEV) == 0) && f->f_dev == (struct devsw *)0)) @@ -120,20 +132,17 @@ open(const char *fname, int mode) /* pass file name to the different filesystem open routines */ besterror = ENOENT; for (i = 0; file_system[i] != NULL; i++) { - - error = ((*file_system[i]).fo_open)(file, f); - if (error == 0) { - - f->f_ops = file_system[i]; - o_rainit(f); - return (fd); - } + fs = file_system[i]; + error = (fs->fo_open)(file, f); + if (error == 0) + goto ok; if (error != EINVAL) besterror = error; } error = besterror; - if ((f->f_flags & F_NODEV) == 0) + fail: + if ((f->f_flags & F_NODEV) == 0 && f->f_dev != NULL) f->f_dev->dv_close(f); if (error) devclose(f); @@ -142,4 +151,9 @@ open(const char *fname, int mode) f->f_flags = 0; errno = error; return (-1); + + ok: + f->f_ops = fs; + o_rainit(f); + return (fd); } diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h index 28087226a526..6c7e12d4ff11 100644 --- a/lib/libstand/stand.h +++ b/lib/libstand/stand.h @@ -364,6 +364,7 @@ extern int devopen(struct open_file *, const char *, const char **); extern int devclose(struct open_file *f); extern void panic(const char *, ...) __dead2 __printflike(1, 2); extern struct fs_ops *file_system[]; +extern struct fs_ops *exclusive_file_system; extern struct devsw *devsw[]; /*