1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 Michael Smith.
|
|
|
|
* 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 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1998-08-20 08:19:55 +00:00
|
|
|
* From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. 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.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1998-08-20 08:19:55 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* @(#)stand.h 8.1 (Berkeley) 6/11/93
|
|
|
|
*/
|
|
|
|
|
2005-05-17 17:46:29 +00:00
|
|
|
#ifndef STAND_H
|
|
|
|
#define STAND_H
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/stat.h>
|
2000-04-29 20:47:10 +00:00
|
|
|
#include <sys/dirent.h>
|
2021-07-31 08:09:48 +00:00
|
|
|
#include <sys/queue.h>
|
2011-07-10 07:25:34 +00:00
|
|
|
|
|
|
|
/* this header intentionally exports NULL from <string.h> */
|
2000-08-03 09:08:29 +00:00
|
|
|
#include <string.h>
|
2018-02-02 21:18:32 +00:00
|
|
|
#define strcoll(a, b) strcmp((a), (b))
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2004-09-22 16:56:49 +00:00
|
|
|
#define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
|
|
|
|
#define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
|
1998-09-26 01:42:40 +00:00
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
/* special stand error codes */
|
|
|
|
#define EADAPT (ELAST+1) /* bad adaptor */
|
|
|
|
#define ECTLR (ELAST+2) /* bad controller */
|
|
|
|
#define EUNIT (ELAST+3) /* bad unit */
|
|
|
|
#define ESLICE (ELAST+4) /* bad slice */
|
|
|
|
#define EPART (ELAST+5) /* bad partition */
|
|
|
|
#define ERDLAB (ELAST+6) /* can't read disk label */
|
|
|
|
#define EUNLAB (ELAST+7) /* unlabeled disk */
|
|
|
|
#define EOFFSET (ELAST+8) /* relative seek not supported */
|
|
|
|
#define ESALAST (ELAST+8) /* */
|
|
|
|
|
2017-12-08 19:56:35 +00:00
|
|
|
/* Partial signal emulation for sig_atomic_t */
|
|
|
|
#include <machine/signal.h>
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
struct open_file;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure is used to define file system operations in a file system
|
|
|
|
* independent way.
|
|
|
|
*
|
|
|
|
* XXX note that filesystem providers should export a pointer to their fs_ops
|
|
|
|
* struct, so that consumers can reference this and thus include the
|
|
|
|
* filesystems that they require.
|
|
|
|
*/
|
|
|
|
struct fs_ops {
|
1998-09-18 22:58:01 +00:00
|
|
|
const char *fs_name;
|
|
|
|
int (*fo_open)(const char *path, struct open_file *f);
|
1998-08-20 08:19:55 +00:00
|
|
|
int (*fo_close)(struct open_file *f);
|
|
|
|
int (*fo_read)(struct open_file *f, void *buf,
|
|
|
|
size_t size, size_t *resid);
|
2018-02-23 20:18:09 +00:00
|
|
|
int (*fo_write)(struct open_file *f, const void *buf,
|
1998-08-20 08:19:55 +00:00
|
|
|
size_t size, size_t *resid);
|
|
|
|
off_t (*fo_seek)(struct open_file *f, off_t offset, int where);
|
|
|
|
int (*fo_stat)(struct open_file *f, struct stat *sb);
|
2000-04-29 20:47:10 +00:00
|
|
|
int (*fo_readdir)(struct open_file *f, struct dirent *d);
|
2021-12-10 09:33:43 +00:00
|
|
|
int (*fo_preload)(struct open_file *f);
|
2021-08-12 05:45:52 +00:00
|
|
|
int (*fo_mount)(const char *, const char *, void **);
|
|
|
|
int (*fo_unmount)(const char *, void *);
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libstand-supplied filesystems
|
|
|
|
*/
|
|
|
|
extern struct fs_ops ufs_fsops;
|
|
|
|
extern struct fs_ops tftp_fsops;
|
|
|
|
extern struct fs_ops nfs_fsops;
|
|
|
|
extern struct fs_ops cd9660_fsops;
|
2002-12-19 19:34:59 +00:00
|
|
|
extern struct fs_ops gzipfs_fsops;
|
2001-09-18 13:01:12 +00:00
|
|
|
extern struct fs_ops bzipfs_fsops;
|
1998-08-20 08:19:55 +00:00
|
|
|
extern struct fs_ops dosfs_fsops;
|
2000-04-29 20:47:10 +00:00
|
|
|
extern struct fs_ops ext2fs_fsops;
|
2002-03-17 12:18:05 +00:00
|
|
|
extern struct fs_ops splitfs_fsops;
|
2014-07-31 23:25:13 +00:00
|
|
|
extern struct fs_ops pkgfs_fsops;
|
2019-06-24 23:18:42 +00:00
|
|
|
extern struct fs_ops efihttp_fsops;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* where values for lseek(2) */
|
|
|
|
#define SEEK_SET 0 /* set file offset to offset */
|
|
|
|
#define SEEK_CUR 1 /* set file offset to current plus offset */
|
|
|
|
#define SEEK_END 2 /* set file offset to EOF plus offset */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device switch
|
|
|
|
*/
|
|
|
|
struct devsw {
|
1998-09-18 22:58:01 +00:00
|
|
|
const char dv_name[8];
|
1998-08-20 08:19:55 +00:00
|
|
|
int dv_type; /* opaque type constant, arch-dependant */
|
2018-03-12 21:39:27 +00:00
|
|
|
#define DEVT_NONE 0
|
|
|
|
#define DEVT_DISK 1
|
|
|
|
#define DEVT_NET 2
|
|
|
|
#define DEVT_CD 3
|
|
|
|
#define DEVT_ZFS 4
|
|
|
|
#define DEVT_FD 5
|
1998-08-20 08:19:55 +00:00
|
|
|
int (*dv_init)(void); /* early probe call */
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
int (*dv_strategy)(void *devdata, int rw, daddr_t blk,
|
2016-12-30 19:06:29 +00:00
|
|
|
size_t size, char *buf, size_t *rsize);
|
1998-08-20 08:19:55 +00:00
|
|
|
int (*dv_open)(struct open_file *f, ...);
|
|
|
|
int (*dv_close)(struct open_file *f);
|
|
|
|
int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
|
2016-11-08 06:50:18 +00:00
|
|
|
int (*dv_print)(int verbose); /* print device information */
|
2000-08-03 09:08:29 +00:00
|
|
|
void (*dv_cleanup)(void);
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
2000-04-29 20:47:10 +00:00
|
|
|
/*
|
|
|
|
* libstand-supplied device switch
|
|
|
|
*/
|
|
|
|
extern struct devsw netdev;
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int errno;
|
|
|
|
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
/*
|
|
|
|
* Generic device specifier; architecture-dependent
|
|
|
|
* versions may be larger, but should be allowed to
|
|
|
|
* overlap.
|
|
|
|
*/
|
2018-03-12 21:39:27 +00:00
|
|
|
struct devdesc {
|
A new implementation of the loader block cache
The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy.
Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks.
Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device.
The cache also implements limited read-ahead to increase performance.
To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache.
Booting from a virtual CD over IPMI:
0ms latency, before: 27 second, after: 7 seconds
60ms latency, before: over 12 minutes, after: under 5 minutes.
Submitted by: Toomas Soome <tsoome@me.com>
Reviewed by: delphij (previous version), emaste (previous version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D4713
2016-04-18 23:09:22 +00:00
|
|
|
struct devsw *d_dev;
|
|
|
|
int d_unit;
|
|
|
|
void *d_opendata;
|
|
|
|
};
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
struct open_file {
|
|
|
|
int f_flags; /* see F_* below */
|
|
|
|
struct devsw *f_dev; /* pointer to device operations */
|
|
|
|
void *f_devdata; /* device specific data */
|
|
|
|
struct fs_ops *f_ops; /* pointer to file system operations */
|
|
|
|
void *f_fsdata; /* file system specific data */
|
2000-09-05 09:52:50 +00:00
|
|
|
off_t f_offset; /* current file offset */
|
|
|
|
char *f_rabuf; /* readahead buffer pointer */
|
|
|
|
size_t f_ralen; /* valid data in readahead buffer */
|
|
|
|
off_t f_raoffset; /* consumer offset in readahead buffer */
|
2021-07-31 08:09:48 +00:00
|
|
|
int f_id; /* file number */
|
|
|
|
TAILQ_ENTRY(open_file) f_link; /* next entry */
|
2000-09-05 09:52:50 +00:00
|
|
|
#define SOPEN_RASIZE 512
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
2021-07-31 08:09:48 +00:00
|
|
|
typedef TAILQ_HEAD(file_list, open_file) file_list_t;
|
|
|
|
extern file_list_t files;
|
|
|
|
extern struct open_file *fd2open_file(int);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* f_flags values */
|
|
|
|
#define F_READ 0x0001 /* file opened for reading */
|
|
|
|
#define F_WRITE 0x0002 /* file opened for writing */
|
|
|
|
#define F_RAW 0x0004 /* raw device open - no file system */
|
|
|
|
#define F_NODEV 0x0008 /* network open - no device */
|
2017-04-06 15:57:53 +00:00
|
|
|
#define F_MASK 0xFFFF
|
|
|
|
/* Mode modifier for strategy() */
|
|
|
|
#define F_NORA (0x01 << 16) /* Disable Read-Ahead */
|
1998-08-20 08:19:55 +00:00
|
|
|
|
1999-12-28 11:48:23 +00:00
|
|
|
#define isascii(c) (((c) & ~0x7F) == 0)
|
2001-05-14 16:49:20 +00:00
|
|
|
|
|
|
|
static __inline int isupper(int c)
|
|
|
|
{
|
|
|
|
return c >= 'A' && c <= 'Z';
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int islower(int c)
|
|
|
|
{
|
|
|
|
return c >= 'a' && c <= 'z';
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int isspace(int c)
|
|
|
|
{
|
|
|
|
return c == ' ' || (c >= 0x9 && c <= 0xd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int isdigit(int c)
|
|
|
|
{
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int isxdigit(int c)
|
|
|
|
{
|
|
|
|
return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int isalpha(int c)
|
|
|
|
{
|
|
|
|
return isupper(c) || islower(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int isalnum(int c)
|
|
|
|
{
|
|
|
|
return isalpha(c) || isdigit(c);
|
|
|
|
}
|
1999-09-11 17:54:37 +00:00
|
|
|
|
2017-12-08 19:57:02 +00:00
|
|
|
static __inline int iscntrl(int c)
|
|
|
|
{
|
|
|
|
return (c >= 0 && c < ' ') || c == 127;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int isgraph(int c)
|
|
|
|
{
|
|
|
|
return c >= '!' && c <= '~';
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int ispunct(int c)
|
|
|
|
{
|
|
|
|
return (c >= '!' && c <= '/') || (c >= ':' && c <= '@') ||
|
|
|
|
(c >= '[' && c <= '`') || (c >= '{' && c <= '~');
|
|
|
|
}
|
|
|
|
|
1999-09-11 17:54:37 +00:00
|
|
|
static __inline int toupper(int c)
|
|
|
|
{
|
|
|
|
return islower(c) ? c - 'a' + 'A' : c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int tolower(int c)
|
|
|
|
{
|
|
|
|
return isupper(c) ? c - 'A' + 'a' : c;
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
1998-09-26 01:42:40 +00:00
|
|
|
/* sbrk emulation */
|
|
|
|
extern void setheap(void *base, void *top);
|
|
|
|
extern char *sbrk(int incr);
|
|
|
|
|
2002-07-20 03:55:06 +00:00
|
|
|
extern int printf(const char *fmt, ...) __printflike(1, 2);
|
2019-01-17 22:00:02 +00:00
|
|
|
extern int asprintf(char **buf, const char *cfmt, ...) __printflike(2, 3);
|
2002-07-20 03:55:06 +00:00
|
|
|
extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3);
|
2014-05-30 09:43:32 +00:00
|
|
|
extern int snprintf(char *buf, size_t size, const char *cfmt, ...) __printflike(3, 4);
|
2018-06-05 17:18:10 +00:00
|
|
|
extern int vprintf(const char *fmt, __va_list);
|
|
|
|
extern int vsprintf(char *buf, const char *cfmt, __va_list);
|
|
|
|
extern int vsnprintf(char *buf, size_t size, const char *cfmt, __va_list);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2014-12-22 20:42:36 +00:00
|
|
|
extern void twiddle(u_int callerdiv);
|
|
|
|
extern void twiddle_divisor(u_int globaldiv);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
extern void ngets(char *, int);
|
|
|
|
#define gets(x) ngets((x), 0)
|
|
|
|
extern int fgetstr(char *buf, int size, int fd);
|
|
|
|
|
2021-08-12 05:45:52 +00:00
|
|
|
extern int mount(const char *dev, const char *path, int flags, void *data);
|
|
|
|
extern int unmount(const char *dev, int flags);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int open(const char *, int);
|
|
|
|
#define O_RDONLY 0x0
|
2001-12-11 00:04:28 +00:00
|
|
|
#define O_WRONLY 0x1
|
1998-08-20 08:19:55 +00:00
|
|
|
#define O_RDWR 0x2
|
2019-05-24 19:43:38 +00:00
|
|
|
#define O_ACCMODE 0x3
|
2018-02-24 02:57:24 +00:00
|
|
|
/* NOT IMPLEMENTED */
|
|
|
|
#define O_CREAT 0x0200 /* create if nonexistent */
|
|
|
|
#define O_TRUNC 0x0400 /* truncate to zero length */
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int close(int);
|
|
|
|
extern void closeall(void);
|
|
|
|
extern ssize_t read(int, void *, size_t);
|
2018-02-24 01:58:53 +00:00
|
|
|
extern ssize_t write(int, const void *, size_t);
|
2000-04-29 20:47:10 +00:00
|
|
|
extern struct dirent *readdirfd(int);
|
2021-12-10 09:33:43 +00:00
|
|
|
extern void preload(int);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2017-12-02 00:07:19 +00:00
|
|
|
extern void srandom(unsigned int);
|
2017-12-06 02:00:09 +00:00
|
|
|
extern long random(void);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* imports from stdlib, locally modified */
|
|
|
|
extern char *optarg; /* getopt(3) external variables */
|
1999-01-11 06:01:29 +00:00
|
|
|
extern int optind, opterr, optopt, optreset;
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int getopt(int, char * const [], const char *);
|
|
|
|
|
|
|
|
/* pager.c */
|
|
|
|
extern void pager_open(void);
|
|
|
|
extern void pager_close(void);
|
|
|
|
extern int pager_output(const char *lines);
|
1998-09-18 22:58:01 +00:00
|
|
|
extern int pager_file(const char *fname);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
1998-11-04 07:39:53 +00:00
|
|
|
/* No signal state to preserve */
|
|
|
|
#define setjmp _setjmp
|
|
|
|
#define longjmp _longjmp
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/* environment.c */
|
|
|
|
#define EV_DYNAMIC (1<<0) /* value was dynamically allocated, free if changed/unset */
|
|
|
|
#define EV_VOLATILE (1<<1) /* value is volatile, make a copy of it */
|
|
|
|
#define EV_NOHOOK (1<<2) /* don't call hook when setting */
|
|
|
|
|
|
|
|
struct env_var;
|
|
|
|
typedef char *(ev_format_t)(struct env_var *ev);
|
2003-10-26 04:04:12 +00:00
|
|
|
typedef int (ev_sethook_t)(struct env_var *ev, int flags,
|
|
|
|
const void *value);
|
1998-08-20 08:19:55 +00:00
|
|
|
typedef int (ev_unsethook_t)(struct env_var *ev);
|
|
|
|
|
|
|
|
struct env_var
|
|
|
|
{
|
|
|
|
char *ev_name;
|
|
|
|
int ev_flags;
|
|
|
|
void *ev_value;
|
|
|
|
ev_sethook_t *ev_sethook;
|
|
|
|
ev_unsethook_t *ev_unsethook;
|
|
|
|
struct env_var *ev_next, *ev_prev;
|
|
|
|
};
|
|
|
|
extern struct env_var *environ;
|
|
|
|
|
|
|
|
extern struct env_var *env_getenv(const char *name);
|
2000-08-03 09:08:29 +00:00
|
|
|
extern int env_setenv(const char *name, int flags,
|
|
|
|
const void *value, ev_sethook_t sethook,
|
|
|
|
ev_unsethook_t unsethook);
|
2020-08-19 15:27:09 +00:00
|
|
|
extern void env_discard(struct env_var *);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern char *getenv(const char *name);
|
2000-08-03 09:08:29 +00:00
|
|
|
extern int setenv(const char *name, const char *value,
|
|
|
|
int overwrite);
|
2017-12-06 02:00:00 +00:00
|
|
|
extern int putenv(char *string);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int unsetenv(const char *name);
|
|
|
|
|
|
|
|
extern ev_sethook_t env_noset; /* refuse set operation */
|
|
|
|
extern ev_unsethook_t env_nounset; /* refuse unset operation */
|
|
|
|
|
2018-01-26 17:13:04 +00:00
|
|
|
/* stdlib.h routines */
|
2018-01-26 17:13:09 +00:00
|
|
|
extern int abs(int a);
|
2018-01-26 17:40:13 +00:00
|
|
|
extern void abort(void) __dead2;
|
2018-01-31 05:07:43 +00:00
|
|
|
extern long strtol(const char * __restrict, char ** __restrict, int);
|
|
|
|
extern long long strtoll(const char * __restrict, char ** __restrict, int);
|
|
|
|
extern unsigned long strtoul(const char * __restrict, char ** __restrict, int);
|
|
|
|
extern unsigned long long strtoull(const char * __restrict, char ** __restrict, int);
|
2018-01-26 17:13:04 +00:00
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/* BCD conversions (undocumented) */
|
|
|
|
extern u_char const bcd2bin_data[];
|
|
|
|
extern u_char const bin2bcd_data[];
|
|
|
|
extern char const hex2ascii_data[];
|
|
|
|
|
|
|
|
#define bcd2bin(bcd) (bcd2bin_data[bcd])
|
|
|
|
#define bin2bcd(bin) (bin2bcd_data[bin])
|
|
|
|
#define hex2ascii(hex) (hex2ascii_data[hex])
|
2017-12-31 22:43:24 +00:00
|
|
|
#define validbcd(bcd) (bcd == 0 || (bcd > 0 && bcd <= 0x99 && bcd2bin_data[bcd] != 0))
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* min/max (undocumented) */
|
|
|
|
static __inline int imax(int a, int b) { return (a > b ? a : b); }
|
|
|
|
static __inline int imin(int a, int b) { return (a < b ? a : b); }
|
|
|
|
static __inline long lmax(long a, long b) { return (a > b ? a : b); }
|
|
|
|
static __inline long lmin(long a, long b) { return (a < b ? a : b); }
|
|
|
|
static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); }
|
|
|
|
static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
|
|
|
|
static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); }
|
|
|
|
static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
|
|
|
|
static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); }
|
|
|
|
static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); }
|
|
|
|
|
|
|
|
/* null functions for device/filesystem switches (undocumented) */
|
|
|
|
extern int nodev(void);
|
|
|
|
extern int noioctl(struct open_file *, u_long, void *);
|
|
|
|
extern void nullsys(void);
|
|
|
|
|
1998-09-18 22:58:01 +00:00
|
|
|
extern int null_open(const char *path, struct open_file *f);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int null_close(struct open_file *f);
|
1999-12-27 08:45:14 +00:00
|
|
|
extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid);
|
2018-02-23 20:18:09 +00:00
|
|
|
extern int null_write(struct open_file *f, const void *buf, size_t size, size_t *resid);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern off_t null_seek(struct open_file *f, off_t offset, int where);
|
|
|
|
extern int null_stat(struct open_file *f, struct stat *sb);
|
2000-04-29 20:47:10 +00:00
|
|
|
extern int null_readdir(struct open_file *f, struct dirent *d);
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Machine dependent functions and data, must be provided or stubbed by
|
|
|
|
* the consumer
|
|
|
|
*/
|
2018-01-26 17:13:00 +00:00
|
|
|
extern void exit(int) __dead2;
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int getchar(void);
|
|
|
|
extern int ischar(void);
|
|
|
|
extern void putchar(int);
|
1998-09-26 10:48:50 +00:00
|
|
|
extern int devopen(struct open_file *, const char *, const char **);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern int devclose(struct open_file *f);
|
2004-01-15 18:35:32 +00:00
|
|
|
extern void panic(const char *, ...) __dead2 __printflike(1, 2);
|
2018-01-26 17:13:00 +00:00
|
|
|
extern void panic_action(void) __weak_symbol __dead2;
|
2018-01-12 16:28:51 +00:00
|
|
|
extern time_t getsecs(void);
|
1998-08-20 08:19:55 +00:00
|
|
|
extern struct fs_ops *file_system[];
|
Provide a means for loaders to control which file system to use. This
to counteract the default behaviour of always trying each and every
file system until one succeeds, or the open fails. The problem with the
loader is that we've implemented features based on this behavior. The
handling of compressed files is a good example of this. However, it is
in general highly undesirable to not have a one-time probe (or taste
in the geom lingo), followed by something similar to a mount whenever
we (first) read from a device. Everytime we go to the same device, we
can reasonably assume it (still) has the same file system. For file
systems that need to do far more that a trivial read of a super block,
not having something similar to a mount operation is disastrous from
a performance (and thus usability) perspective.
But, again, since we've implemented features based on this stateless
approach, things can get complicated quickly if and when we want to
change this. And yet, we sometimes do need stateful behaviour.
For this reason, this change simply introduces exclusive_file_system.
When set to the fsops of the file system to use, the open call will
only try this file system. Setting it to NULL restores the default
behaviour. It's a low-cost (low-brow?) approach to provide enough
control without re-implementing the guts of the loader.
A good example of when this is useful is when we're trying to load
files out of a container (say, a software packaga) that itself lives
on a file system or is fetched over the network. While opening the
container can be done in the normal stateless manner, once it is
opened, subsequent opens should only consider the container.
Obtained from: Juniper Networks, Inc.
2014-07-30 16:08:16 +00:00
|
|
|
extern struct fs_ops *exclusive_file_system;
|
1998-08-20 08:19:55 +00:00
|
|
|
extern struct devsw *devsw[];
|
|
|
|
|
2020-08-28 05:40:02 +00:00
|
|
|
/*
|
|
|
|
* Time routines
|
|
|
|
*/
|
|
|
|
time_t time(time_t *);
|
|
|
|
|
2002-02-18 20:35:27 +00:00
|
|
|
/*
|
|
|
|
* Expose byteorder(3) functions.
|
|
|
|
*/
|
2002-03-09 21:02:16 +00:00
|
|
|
#ifndef _BYTEORDER_PROTOTYPED
|
|
|
|
#define _BYTEORDER_PROTOTYPED
|
2002-02-18 20:35:27 +00:00
|
|
|
extern uint32_t htonl(uint32_t);
|
|
|
|
extern uint16_t htons(uint16_t);
|
|
|
|
extern uint32_t ntohl(uint32_t);
|
|
|
|
extern uint16_t ntohs(uint16_t);
|
2002-03-09 21:02:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _BYTEORDER_FUNC_DEFINED
|
|
|
|
#define _BYTEORDER_FUNC_DEFINED
|
|
|
|
#define htonl(x) __htonl(x)
|
|
|
|
#define htons(x) __htons(x)
|
|
|
|
#define ntohl(x) __ntohl(x)
|
|
|
|
#define ntohs(x) __ntohs(x)
|
|
|
|
#endif
|
2002-02-18 20:35:27 +00:00
|
|
|
|
2002-07-20 04:18:20 +00:00
|
|
|
void *Malloc(size_t, const char *, int);
|
2019-09-17 13:15:27 +00:00
|
|
|
void *Memalign(size_t, size_t, const char *, int);
|
2002-07-20 04:18:20 +00:00
|
|
|
void *Calloc(size_t, size_t, const char *, int);
|
|
|
|
void *Realloc(void *, size_t, const char *, int);
|
2019-09-17 13:15:27 +00:00
|
|
|
void *Reallocf(void *, size_t, const char *, int);
|
2002-07-20 04:18:20 +00:00
|
|
|
void Free(void *, const char *, int);
|
2019-09-17 13:07:02 +00:00
|
|
|
extern void mallocstats(void);
|
2002-07-20 04:18:20 +00:00
|
|
|
|
2019-10-24 20:02:48 +00:00
|
|
|
const char *x86_hypervisor(void);
|
|
|
|
|
2020-03-28 21:47:44 +00:00
|
|
|
#ifdef USER_MALLOC
|
|
|
|
extern void *malloc(size_t);
|
|
|
|
extern void *memalign(size_t, size_t);
|
|
|
|
extern void *calloc(size_t, size_t);
|
|
|
|
extern void free(void *);
|
|
|
|
extern void *realloc(void *, size_t);
|
|
|
|
extern void *reallocf(void *, size_t);
|
2020-03-29 06:48:59 +00:00
|
|
|
#elif defined(DEBUG_MALLOC)
|
2002-07-20 04:18:20 +00:00
|
|
|
#define malloc(x) Malloc(x, __FILE__, __LINE__)
|
2019-09-17 13:15:27 +00:00
|
|
|
#define memalign(x, y) Memalign(x, y, __FILE__, __LINE__)
|
2002-07-20 04:18:20 +00:00
|
|
|
#define calloc(x, y) Calloc(x, y, __FILE__, __LINE__)
|
|
|
|
#define free(x) Free(x, __FILE__, __LINE__)
|
|
|
|
#define realloc(x, y) Realloc(x, y, __FILE__, __LINE__)
|
2019-09-17 13:07:02 +00:00
|
|
|
#define reallocf(x, y) Reallocf(x, y, __FILE__, __LINE__)
|
2002-07-20 04:18:20 +00:00
|
|
|
#else
|
2002-08-21 09:30:45 +00:00
|
|
|
#define malloc(x) Malloc(x, NULL, 0)
|
2019-09-17 13:15:27 +00:00
|
|
|
#define memalign(x, y) Memalign(x, y, NULL, 0)
|
2002-07-20 04:18:20 +00:00
|
|
|
#define calloc(x, y) Calloc(x, y, NULL, 0)
|
|
|
|
#define free(x) Free(x, NULL, 0)
|
|
|
|
#define realloc(x, y) Realloc(x, y, NULL, 0)
|
2019-09-17 13:07:02 +00:00
|
|
|
#define reallocf(x, y) Reallocf(x, y, NULL, 0)
|
1998-09-26 10:48:50 +00:00
|
|
|
#endif
|
2005-05-17 17:46:29 +00:00
|
|
|
|
2020-02-20 00:46:16 +00:00
|
|
|
/*
|
|
|
|
* va <-> pa routines. MD code must supply.
|
|
|
|
*/
|
|
|
|
caddr_t ptov(uintptr_t);
|
|
|
|
|
2020-08-29 21:05:43 +00:00
|
|
|
/* hexdump.c */
|
|
|
|
void hexdump(caddr_t region, size_t len);
|
|
|
|
|
2021-05-30 20:20:50 +00:00
|
|
|
/* tslog.c */
|
|
|
|
#define TSRAW(a, b, c) tslog(a, b, c)
|
|
|
|
#define TSENTER() TSRAW("ENTER", __func__, NULL)
|
2021-12-30 14:49:24 +00:00
|
|
|
#define TSENTER2(x) TSRAW("ENTER", __func__, x)
|
2021-05-30 20:20:50 +00:00
|
|
|
#define TSEXIT() TSRAW("EXIT", __func__, NULL)
|
|
|
|
#define TSLINE() TSRAW("EVENT", __FILE__, __XSTRING(__LINE__))
|
|
|
|
void tslog(const char *, const char *, const char *);
|
|
|
|
void tslog_setbuf(void * buf, size_t len);
|
|
|
|
void tslog_getbuf(void ** buf, size_t * len);
|
|
|
|
|
2005-05-17 17:46:29 +00:00
|
|
|
#endif /* STAND_H */
|