1*63279Smckusick /*- 2*63279Smckusick * Copyright (c) 1993 The Regents of the University of California. 3*63279Smckusick * All rights reserved. 4*63279Smckusick * 5*63279Smckusick * %sccs.include.redist.c% 6*63279Smckusick * 7*63279Smckusick * @(#)stand.h 7.1 (Berkeley) 06/11/93 8*63279Smckusick */ 9*63279Smckusick 10*63279Smckusick #include <sys/types.h> 11*63279Smckusick #include <sys/cdefs.h> 12*63279Smckusick #include <sys/errno.h> 13*63279Smckusick #include <sys/stat.h> 14*63279Smckusick #include <stand/saioctl.h> 15*63279Smckusick 16*63279Smckusick #define UNIX "/vmunix" 17*63279Smckusick 18*63279Smckusick #ifndef NULL 19*63279Smckusick #define NULL 0 20*63279Smckusick #endif 21*63279Smckusick 22*63279Smckusick extern int errno; 23*63279Smckusick 24*63279Smckusick struct open_file; 25*63279Smckusick 26*63279Smckusick /* 27*63279Smckusick * This structure is used to define file system operations in a file system 28*63279Smckusick * independent way. 29*63279Smckusick */ 30*63279Smckusick struct fs_ops { 31*63279Smckusick int (*open) __P((char *path, struct open_file *f)); 32*63279Smckusick int (*close) __P((struct open_file *f)); 33*63279Smckusick int (*read) __P((struct open_file *f, char *buf, 34*63279Smckusick u_int size, u_int *resid)); 35*63279Smckusick int (*write) __P((struct open_file *f, char *buf, 36*63279Smckusick u_int size, u_int *resid)); 37*63279Smckusick off_t (*seek) __P((struct open_file *f, off_t offset, int where)); 38*63279Smckusick int (*stat) __P((struct open_file *f, struct stat *sb)); 39*63279Smckusick }; 40*63279Smckusick 41*63279Smckusick extern struct fs_ops file_system[]; 42*63279Smckusick 43*63279Smckusick /* where values for lseek(2) */ 44*63279Smckusick #define SEEK_SET 0 /* set file offset to offset */ 45*63279Smckusick #define SEEK_CUR 1 /* set file offset to current plus offset */ 46*63279Smckusick #define SEEK_END 2 /* set file offset to EOF plus offset */ 47*63279Smckusick 48*63279Smckusick /* Device switch */ 49*63279Smckusick struct devsw { 50*63279Smckusick char *dv_name; 51*63279Smckusick int (*dv_strategy) __P((void *devdata, int rw, 52*63279Smckusick daddr_t blk, u_int size, char *buf, u_int *rsize)); 53*63279Smckusick int (*dv_open)(); /* (struct open_file *f, ...) */ 54*63279Smckusick int (*dv_close) __P((struct open_file *f)); 55*63279Smckusick int (*dv_ioctl) __P((struct open_file *f, int cmd, void *data)); 56*63279Smckusick }; 57*63279Smckusick 58*63279Smckusick extern struct devsw devsw[]; /* device array */ 59*63279Smckusick extern int ndevs; /* number of elements in devsw[] */ 60*63279Smckusick 61*63279Smckusick struct open_file { 62*63279Smckusick int f_flags; /* see F_* below */ 63*63279Smckusick struct devsw *f_dev; /* pointer to device operations */ 64*63279Smckusick void *f_devdata; /* device specific data */ 65*63279Smckusick struct fs_ops *f_ops; /* pointer to file system operations */ 66*63279Smckusick void *f_fsdata; /* file system specific data */ 67*63279Smckusick }; 68*63279Smckusick 69*63279Smckusick #define SOPEN_MAX 4 70*63279Smckusick extern struct open_file files[SOPEN_MAX]; 71*63279Smckusick 72*63279Smckusick /* f_flags values */ 73*63279Smckusick #define F_READ 0x0001 /* file opened for reading */ 74*63279Smckusick #define F_WRITE 0x0002 /* file opened for writing */ 75*63279Smckusick #define F_RAW 0x0004 /* raw device open - no file system */ 76*63279Smckusick 77*63279Smckusick int devopen __P((struct open_file *f, char *fname, char **file)); 78*63279Smckusick void *alloc __P((unsigned size)); 79*63279Smckusick void free __P((void *ptr, unsigned size)); 80*63279Smckusick struct disklabel; 81*63279Smckusick char *getdisklabel __P((const char *buf, struct disklabel *lp)); 82