1998-08-21 03:17:42 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1998-10-21 20:07:05 +00:00
|
|
|
#include <sys/queue.h>
|
2001-06-14 01:23:57 +00:00
|
|
|
#include <sys/linker_set.h>
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic device specifier; architecture-dependant
|
|
|
|
* versions may be larger, but should be allowed to
|
|
|
|
* overlap.
|
|
|
|
*/
|
|
|
|
struct devdesc
|
|
|
|
{
|
|
|
|
struct devsw *d_dev;
|
|
|
|
int d_type;
|
|
|
|
#define DEVT_NONE 0
|
|
|
|
#define DEVT_DISK 1
|
|
|
|
#define DEVT_NET 2
|
2001-11-05 18:51:47 +00:00
|
|
|
#define DEVT_CD 3
|
Update ZFS from version 6 to 13 and bring some FreeBSD-specific changes.
This bring huge amount of changes, I'll enumerate only user-visible changes:
- Delegated Administration
Allows regular users to perform ZFS operations, like file system
creation, snapshot creation, etc.
- L2ARC
Level 2 cache for ZFS - allows to use additional disks for cache.
Huge performance improvements mostly for random read of mostly
static content.
- slog
Allow to use additional disks for ZFS Intent Log to speed up
operations like fsync(2).
- vfs.zfs.super_owner
Allows regular users to perform privileged operations on files stored
on ZFS file systems owned by him. Very careful with this one.
- chflags(2)
Not all the flags are supported. This still needs work.
- ZFSBoot
Support to boot off of ZFS pool. Not finished, AFAIK.
Submitted by: dfr
- Snapshot properties
- New failure modes
Before if write requested failed, system paniced. Now one
can select from one of three failure modes:
- panic - panic on write error
- wait - wait for disk to reappear
- continue - serve read requests if possible, block write requests
- Refquota, refreservation properties
Just quota and reservation properties, but don't count space consumed
by children file systems, clones and snapshots.
- Sparse volumes
ZVOLs that don't reserve space in the pool.
- External attributes
Compatible with extattr(2).
- NFSv4-ACLs
Not sure about the status, might not be complete yet.
Submitted by: trasz
- Creation-time properties
- Regression tests for zpool(8) command.
Obtained from: OpenSolaris
2008-11-17 20:49:29 +00:00
|
|
|
#define DEVT_ZFS 4
|
2006-11-02 01:23:18 +00:00
|
|
|
int d_unit;
|
2010-01-09 22:54:29 +00:00
|
|
|
void *d_opendata;
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Commands and return values; nonzero return sets command_errmsg != NULL */
|
|
|
|
typedef int (bootblk_cmd_t)(int argc, char *argv[]);
|
|
|
|
extern char *command_errmsg;
|
|
|
|
extern char command_errbuf[]; /* XXX blah, length */
|
|
|
|
#define CMD_OK 0
|
|
|
|
#define CMD_ERROR 1
|
|
|
|
|
|
|
|
/* interp.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
void interact(void);
|
|
|
|
int include(const char *filename);
|
|
|
|
|
|
|
|
/* interp_backslash.c */
|
|
|
|
char *backslash(char *str);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* interp_parse.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
int parse(int *argc, char ***argv, char *str);
|
1998-09-14 18:27:06 +00:00
|
|
|
|
1999-02-04 17:06:46 +00:00
|
|
|
/* interp_forth.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
void bf_init(void);
|
|
|
|
int bf_run(char *line);
|
1999-02-04 17:06:46 +00:00
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/* boot.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
int autoboot(int timeout, char *prompt);
|
|
|
|
void autoboot_maybe(void);
|
|
|
|
int getrootmount(char *rootdev);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/* misc.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
char *unargv(int argc, char *argv[]);
|
|
|
|
void hexdump(caddr_t region, size_t len);
|
|
|
|
size_t strlenout(vm_offset_t str);
|
|
|
|
char *strdupout(vm_offset_t str);
|
2004-08-28 14:57:34 +00:00
|
|
|
void kern_bzero(vm_offset_t dest, size_t len);
|
|
|
|
int kern_pread(int fd, vm_offset_t dest, size_t len, off_t off);
|
|
|
|
void *alloc_pread(int fd, off_t off, size_t len);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
1999-02-04 17:06:46 +00:00
|
|
|
/* bcache.c */
|
2000-08-03 09:14:02 +00:00
|
|
|
int bcache_init(u_int nblks, size_t bsize);
|
|
|
|
void bcache_flush(void);
|
|
|
|
int bcache_strategy(void *devdata, int unit, int rw, daddr_t blk,
|
|
|
|
size_t size, char *buf, size_t *rsize);
|
1999-02-04 17:06:46 +00:00
|
|
|
|
1998-11-02 23:28:11 +00:00
|
|
|
/*
|
|
|
|
* Disk block cache
|
|
|
|
*/
|
|
|
|
struct bcache_devdata
|
|
|
|
{
|
2000-08-03 09:14:02 +00:00
|
|
|
int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, char *buf, size_t *rsize);
|
1998-11-02 23:28:11 +00:00
|
|
|
void *dv_devdata;
|
|
|
|
};
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
|
|
|
* Modular console support.
|
|
|
|
*/
|
|
|
|
struct console
|
|
|
|
{
|
2000-08-03 09:14:02 +00:00
|
|
|
const char *c_name;
|
|
|
|
const char *c_desc;
|
1998-08-21 03:17:42 +00:00
|
|
|
int c_flags;
|
|
|
|
#define C_PRESENTIN (1<<0)
|
|
|
|
#define C_PRESENTOUT (1<<1)
|
|
|
|
#define C_ACTIVEIN (1<<2)
|
|
|
|
#define C_ACTIVEOUT (1<<3)
|
|
|
|
void (* c_probe)(struct console *cp); /* set c_flags to match hardware */
|
|
|
|
int (* c_init)(int arg); /* reinit XXX may need more args */
|
|
|
|
void (* c_out)(int c); /* emit c */
|
|
|
|
int (* c_in)(void); /* wait for and return input */
|
|
|
|
int (* c_ready)(void); /* return nonzer if input waiting */
|
|
|
|
};
|
|
|
|
extern struct console *consoles[];
|
2000-08-03 09:14:02 +00:00
|
|
|
void cons_probe(void);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
1998-09-04 02:43:26 +00:00
|
|
|
/*
|
|
|
|
* Plug-and-play enumerator/configurator interface.
|
|
|
|
*/
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnphandler
|
1998-09-14 18:27:06 +00:00
|
|
|
{
|
2000-08-03 09:14:02 +00:00
|
|
|
const char *pp_name; /* handler/bus name */
|
1998-10-21 20:07:05 +00:00
|
|
|
void (* pp_enumerate)(void); /* enumerate PnP devices, add to chain */
|
1998-09-14 18:27:06 +00:00
|
|
|
};
|
|
|
|
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnpident
|
1998-09-04 02:43:26 +00:00
|
|
|
{
|
1998-10-21 20:07:05 +00:00
|
|
|
char *id_ident; /* ASCII identifier, actual format varies with bus/handler */
|
2000-05-26 02:09:24 +00:00
|
|
|
STAILQ_ENTRY(pnpident) id_link;
|
1998-09-14 18:27:06 +00:00
|
|
|
};
|
1998-09-04 02:43:26 +00:00
|
|
|
|
1998-10-21 20:07:05 +00:00
|
|
|
struct pnpinfo
|
1998-09-04 02:43:26 +00:00
|
|
|
{
|
1998-10-21 20:07:05 +00:00
|
|
|
char *pi_desc; /* ASCII description, optional */
|
|
|
|
int pi_revision; /* optional revision (or -1) if not supported */
|
|
|
|
char *pi_module; /* module/args nominated to handle device */
|
|
|
|
int pi_argc; /* module arguments */
|
|
|
|
char **pi_argv;
|
|
|
|
struct pnphandler *pi_handler; /* handler which detected this device */
|
2000-05-26 02:09:24 +00:00
|
|
|
STAILQ_HEAD(,pnpident) pi_ident; /* list of identifiers */
|
|
|
|
STAILQ_ENTRY(pnpinfo) pi_link;
|
1998-09-04 02:43:26 +00:00
|
|
|
};
|
|
|
|
|
2000-09-08 16:51:29 +00:00
|
|
|
STAILQ_HEAD(pnpinfo_stql, pnpinfo);
|
|
|
|
|
|
|
|
extern struct pnpinfo_stql pnp_devices;
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
extern struct pnphandler *pnphandlers[]; /* provided by MD code */
|
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
void pnp_addident(struct pnpinfo *pi, char *ident);
|
|
|
|
struct pnpinfo *pnp_allocinfo(void);
|
|
|
|
void pnp_freeinfo(struct pnpinfo *pi);
|
|
|
|
void pnp_addinfo(struct pnpinfo *pi);
|
|
|
|
char *pnp_eisaformat(u_int8_t *data);
|
1998-10-22 20:20:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* < 0 - No ISA in system
|
|
|
|
* == 0 - Maybe ISA, search for read data port
|
|
|
|
* > 0 - ISA in system, value is read data port address
|
|
|
|
*/
|
|
|
|
extern int isapnp_readport;
|
1998-09-04 02:43:26 +00:00
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Preloaded file metadata header.
|
1998-08-21 03:17:42 +00:00
|
|
|
*
|
|
|
|
* Metadata are allocated on our heap, and copied into kernel space
|
|
|
|
* before executing the kernel.
|
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
|
|
|
size_t md_size;
|
|
|
|
u_int16_t md_type;
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_metadata *md_next;
|
2000-08-03 09:14:02 +00:00
|
|
|
char md_data[1]; /* data are immediately appended */
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file;
|
2001-09-11 01:09:24 +00:00
|
|
|
struct mod_depend;
|
2000-05-01 17:41:25 +00:00
|
|
|
|
|
|
|
struct kernel_module
|
|
|
|
{
|
|
|
|
char *m_name; /* module name */
|
2001-09-11 01:09:24 +00:00
|
|
|
int m_version; /* module version */
|
2000-05-01 17:41:25 +00:00
|
|
|
/* char *m_args;*/ /* arguments for the module */
|
|
|
|
struct preloaded_file *m_fp;
|
|
|
|
struct kernel_module *m_next;
|
|
|
|
};
|
|
|
|
|
1998-08-21 03:17:42 +00:00
|
|
|
/*
|
2000-05-01 17:41:25 +00:00
|
|
|
* Preloaded file information. Depending on type, file can contain
|
|
|
|
* additional units called 'modules'.
|
1998-08-21 03:17:42 +00:00
|
|
|
*
|
2000-05-01 17:41:25 +00:00
|
|
|
* At least one file (the kernel) must be loaded in order to boot.
|
1998-08-21 03:17:42 +00:00
|
|
|
* The kernel is always loaded first.
|
1998-08-31 21:10:43 +00:00
|
|
|
*
|
|
|
|
* String fields (m_name, m_type) should be dynamically allocated.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
2000-05-01 17:41:25 +00:00
|
|
|
struct preloaded_file
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
2000-05-01 17:41:25 +00:00
|
|
|
char *f_name; /* file name */
|
|
|
|
char *f_type; /* verbose file type, eg 'ELF kernel', 'pnptable', etc. */
|
|
|
|
char *f_args; /* arguments for the file */
|
|
|
|
struct file_metadata *f_metadata; /* metadata that will be placed in the module directory */
|
|
|
|
int f_loader; /* index of the loader that read the file */
|
|
|
|
vm_offset_t f_addr; /* load address */
|
|
|
|
size_t f_size; /* file size */
|
|
|
|
struct kernel_module *f_modules; /* list of modules if any */
|
|
|
|
struct preloaded_file *f_next; /* next file */
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
|
2000-05-01 17:41:25 +00:00
|
|
|
struct file_format
|
1998-08-21 03:17:42 +00:00
|
|
|
{
|
|
|
|
/* Load function must return EFTYPE if it can't handle the module supplied */
|
2003-05-01 03:56:30 +00:00
|
|
|
int (* l_load)(char *filename, u_int64_t dest, struct preloaded_file **result);
|
1998-08-31 21:10:43 +00:00
|
|
|
/* Only a loader that will load a kernel (first module) should have an exec handler */
|
2000-05-01 17:41:25 +00:00
|
|
|
int (* l_exec)(struct preloaded_file *mp);
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
2000-05-01 17:41:25 +00:00
|
|
|
|
|
|
|
extern struct file_format *file_formats[]; /* supplied by consumer */
|
|
|
|
extern struct preloaded_file *preloaded_files;
|
|
|
|
|
2001-09-11 01:09:24 +00:00
|
|
|
int mod_load(char *name, struct mod_depend *verinfo, int argc, char *argv[]);
|
|
|
|
int mod_loadkld(const char *name, int argc, char *argv[]);
|
2000-05-01 17:41:25 +00:00
|
|
|
|
|
|
|
struct preloaded_file *file_alloc(void);
|
|
|
|
struct preloaded_file *file_findfile(char *name, char *type);
|
|
|
|
struct file_metadata *file_findmetadata(struct preloaded_file *fp, int type);
|
|
|
|
void file_discard(struct preloaded_file *fp);
|
|
|
|
void file_addmetadata(struct preloaded_file *fp, int type, size_t size, void *p);
|
2001-09-11 01:09:24 +00:00
|
|
|
int file_addmodule(struct preloaded_file *fp, char *modname, int version,
|
2000-05-01 17:41:25 +00:00
|
|
|
struct kernel_module **newmp);
|
1998-09-14 18:27:06 +00:00
|
|
|
|
|
|
|
/* MI module loaders */
|
2003-05-01 03:56:30 +00:00
|
|
|
#ifdef __elfN
|
2004-08-28 23:03:05 +00:00
|
|
|
/* Relocation types. */
|
|
|
|
#define ELF_RELOC_REL 1
|
|
|
|
#define ELF_RELOC_RELA 2
|
|
|
|
|
2008-02-23 18:33:50 +00:00
|
|
|
/* Relocation offset for some architectures */
|
|
|
|
extern u_int64_t __elfN(relocation_offset);
|
|
|
|
|
2004-08-28 23:03:05 +00:00
|
|
|
struct elf_file;
|
2005-12-18 04:52:37 +00:00
|
|
|
typedef Elf_Addr (symaddr_fn)(struct elf_file *ef, Elf_Size symidx);
|
2004-08-28 23:03:05 +00:00
|
|
|
|
2003-05-01 03:56:30 +00:00
|
|
|
int __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result);
|
2004-08-29 00:48:42 +00:00
|
|
|
int __elfN(obj_loadfile)(char *filename, u_int64_t dest,
|
|
|
|
struct preloaded_file **result);
|
2004-08-28 23:03:05 +00:00
|
|
|
int __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr,
|
|
|
|
const void *reldata, int reltype, Elf_Addr relbase,
|
|
|
|
Elf_Addr dataaddr, void *data, size_t len);
|
2003-05-01 03:56:30 +00:00
|
|
|
#endif
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for commands
|
|
|
|
*/
|
|
|
|
struct bootblk_command
|
|
|
|
{
|
|
|
|
const char *c_name;
|
|
|
|
const char *c_desc;
|
|
|
|
bootblk_cmd_t *c_fn;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define COMMAND_SET(tag, key, desc, func) \
|
|
|
|
static bootblk_cmd_t func; \
|
|
|
|
static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
|
2000-08-03 09:14:02 +00:00
|
|
|
DATA_SET(Xcommand_set, _cmd_ ## tag)
|
1998-08-21 03:17:42 +00:00
|
|
|
|
2001-06-14 01:23:57 +00:00
|
|
|
SET_DECLARE(Xcommand_set, struct bootblk_command);
|
1998-08-21 03:17:42 +00:00
|
|
|
|
|
|
|
/*
|
1998-08-31 21:10:43 +00:00
|
|
|
* The intention of the architecture switch is to provide a convenient
|
|
|
|
* encapsulation of the interface between the bootstrap MI and MD code.
|
|
|
|
* MD code may selectively populate the switch at runtime based on the
|
|
|
|
* actual configuration of the target system.
|
1998-08-21 03:17:42 +00:00
|
|
|
*/
|
|
|
|
struct arch_switch
|
|
|
|
{
|
|
|
|
/* Automatically load modules as required by detected hardware */
|
2000-08-03 09:14:02 +00:00
|
|
|
int (*arch_autoload)(void);
|
1998-08-21 03:17:42 +00:00
|
|
|
/* Locate the device for (name), return pointer to tail in (*path) */
|
2000-08-03 09:14:02 +00:00
|
|
|
int (*arch_getdev)(void **dev, const char *name, const char **path);
|
1998-08-31 21:10:43 +00:00
|
|
|
/* Copy from local address space to module address space, similar to bcopy() */
|
2000-08-03 09:14:02 +00:00
|
|
|
ssize_t (*arch_copyin)(const void *src, vm_offset_t dest,
|
|
|
|
const size_t len);
|
1998-09-03 02:10:09 +00:00
|
|
|
/* Copy to local address space from module address space, similar to bcopy() */
|
2000-08-03 09:14:02 +00:00
|
|
|
ssize_t (*arch_copyout)(const vm_offset_t src, void *dest,
|
|
|
|
const size_t len);
|
1998-08-31 21:10:43 +00:00
|
|
|
/* Read from file to module address space, same semantics as read() */
|
2000-08-03 09:14:02 +00:00
|
|
|
ssize_t (*arch_readin)(const int fd, vm_offset_t dest,
|
|
|
|
const size_t len);
|
1998-09-14 18:27:06 +00:00
|
|
|
/* Perform ISA byte port I/O (only for systems with ISA) */
|
2000-08-03 09:14:02 +00:00
|
|
|
int (*arch_isainb)(int port);
|
|
|
|
void (*arch_isaoutb)(int port, int value);
|
1998-08-21 03:17:42 +00:00
|
|
|
};
|
|
|
|
extern struct arch_switch archsw;
|
|
|
|
|
1998-09-14 18:27:06 +00:00
|
|
|
/* This must be provided by the MD code, but should it be in the archsw? */
|
2000-08-03 09:14:02 +00:00
|
|
|
void delay(int delay);
|
2000-06-14 10:34:29 +00:00
|
|
|
|
2000-08-03 09:14:02 +00:00
|
|
|
void dev_cleanup(void);
|
2002-02-25 04:31:25 +00:00
|
|
|
|
|
|
|
time_t time(time_t *tloc);
|