Skip to content

Commit aaf65a1

Browse files
committed
stand: add fs_ops.fs_flag
To avoid a layering violation in open() allow fs_ops to indicate that devopen() should be skipped. This is only true for pkgfs. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51684
1 parent 095e23b commit aaf65a1

File tree

12 files changed

+32
-14
lines changed

12 files changed

+32
-14
lines changed

stand/libsa/bzipfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static int bzf_stat(struct open_file *f, struct stat *sb);
6868
#ifndef REGRESSION
6969
struct fs_ops bzipfs_fsops = {
7070
.fs_name = "bzip",
71+
.fs_flags = 0,
7172
.fo_open = bzf_open,
7273
.fo_close = bzf_close,
7374
.fo_read = bzf_read,

stand/libsa/cd9660.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static ISO_SUSP_HEADER *susp_lookup_record(struct open_file *f,
8181

8282
struct fs_ops cd9660_fsops = {
8383
.fs_name = "cd9660",
84+
.fs_flags = 0,
8485
.fo_open = cd9660_open,
8586
.fo_close = cd9660_close,
8687
.fo_read = cd9660_read,

stand/libsa/dosfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static int dos_unmount(const char *dev, void *data);
6161

6262
struct fs_ops dosfs_fsops = {
6363
.fs_name = "dosfs",
64+
.fs_flags = 0,
6465
.fo_open = dos_open,
6566
.fo_close = dos_close,
6667
.fo_read = dos_read,

stand/libsa/ext2fs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static int dtmap[] = { DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR,
106106

107107
struct fs_ops ext2fs_fsops = {
108108
.fs_name = "ext2fs",
109+
.fs_flags = 0,
109110
.fo_open = ext2fs_open,
110111
.fo_close = ext2fs_close,
111112
.fo_read = ext2fs_read,

stand/libsa/gzipfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static int zf_stat(struct open_file *f, struct stat *sb);
5050

5151
struct fs_ops gzipfs_fsops = {
5252
.fs_name = "zip",
53+
.fs_flags = 0,
5354
.fo_open = zf_open,
5455
.fo_close = zf_close,
5556
.fo_read = zf_read,

stand/libsa/nfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct nfs_iodesc nfs_root_node;
131131

132132
struct fs_ops nfs_fsops = {
133133
.fs_name = "nfs",
134+
.fs_flags = 0,
134135
.fo_open = nfs_open,
135136
.fo_close = nfs_close,
136137
.fo_read = nfs_read,

stand/libsa/open.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,32 @@ open(const char *fname, int mode)
154154
f->f_devdata = NULL;
155155
file = NULL;
156156

157+
if (exclusive_file_system == NULL ||
158+
(exclusive_file_system->fs_flags & FS_OPS_NO_DEVOPEN) == 0) {
159+
error = devopen(f, fname, &file);
160+
if (error ||
161+
(((f->f_flags & F_NODEV) == 0) && f->f_dev == NULL))
162+
goto err;
163+
164+
/* see if we opened a raw device; otherwise, 'file' is the file name. */
165+
if (file == NULL || *file == '\0') {
166+
f->f_flags |= F_RAW;
167+
f->f_rabuf = NULL;
168+
TSEXIT();
169+
return (fd);
170+
}
171+
} else
172+
file = fname;
173+
157174
if (exclusive_file_system != NULL) {
175+
/* loader is forcing the filesystem to be used */
158176
fs = exclusive_file_system;
159-
error = (fs->fo_open)(fname, f);
177+
error = (fs->fo_open)(file, f);
160178
if (error == 0)
161179
goto ok;
162180
goto err;
163181
}
164182

165-
error = devopen(f, fname, &file);
166-
if (error ||
167-
(((f->f_flags & F_NODEV) == 0) && f->f_dev == NULL))
168-
goto err;
169-
170-
/* see if we opened a raw device; otherwise, 'file' is the file name. */
171-
if (file == NULL || *file == '\0') {
172-
f->f_flags |= F_RAW;
173-
f->f_rabuf = NULL;
174-
TSEXIT();
175-
return (fd);
176-
}
177-
178183
/* pass file name to the different filesystem open routines */
179184
besterror = ENOENT;
180185
for (i = 0; file_system[i] != NULL; i++) {

stand/libsa/pkgfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static off_t pkg_atol(const char *, unsigned);
4141

4242
struct fs_ops pkgfs_fsops = {
4343
.fs_name = "pkg",
44+
.fs_flags = FS_OPS_NO_DEVOPEN,
4445
.fo_open = pkg_open,
4546
.fo_close = pkg_close,
4647
.fo_read = pkg_read,

stand/libsa/splitfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static int splitfs_stat(struct open_file *f, struct stat *sb);
5050

5151
struct fs_ops splitfs_fsops = {
5252
.fs_name = "split",
53+
.fs_flags = 0,
5354
.fo_open = splitfs_open,
5455
.fo_close = splitfs_close,
5556
.fo_read = splitfs_read,

stand/libsa/stand.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ __BEGIN_DECLS
9494

9595
struct open_file;
9696

97+
#define FS_OPS_NO_DEVOPEN 1
98+
9799
/*
98100
* This structure is used to define file system operations in a file system
99101
* independent way.
@@ -104,6 +106,7 @@ struct open_file;
104106
*/
105107
struct fs_ops {
106108
const char *fs_name;
109+
int fs_flags;
107110
int (*fo_open)(const char *path, struct open_file *f);
108111
int (*fo_close)(struct open_file *f);
109112
int (*fo_read)(struct open_file *f, void *buf,

0 commit comments

Comments
 (0)