From d1f1e614f0ed30647e4d9d7cadbed6e7a52cc63f Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Tue, 23 Jun 2015 19:00:24 -0700 Subject: [PATCH] Kernel sources reformated with 4 space indent, no tabs. Unused file include/trace.h deleted. --- rootfs.manifest | 1 - src/man/man6/Makefile | 2 +- sys/include/adc.h | 4 +- sys/include/buf.h | 154 +-- sys/include/callout.h | 12 +- sys/include/clist.h | 8 +- sys/include/dir.h | 66 +- sys/include/disk.h | 59 +- sys/include/dk.h | 32 +- sys/include/dkbad.h | 26 +- sys/include/errno.h | 184 +-- sys/include/exec.h | 92 +- sys/include/exec_aout.h | 115 +- sys/include/exec_elf.h | 626 +++++---- sys/include/fcntl.h | 94 +- sys/include/file.h | 70 +- sys/include/fonts/vga.h | 192 +-- sys/include/fs.h | 102 +- sys/include/gpio.h | 40 +- sys/include/hx8357.h | 2 - sys/include/inode.h | 356 ++--- sys/include/ioctl.h | 356 ++--- sys/include/kernel.h | 22 +- sys/include/map.h | 12 +- sys/include/mount.h | 86 +- sys/include/msgbuf.h | 16 +- sys/include/mtio.h | 82 +- sys/include/namei.h | 86 +- sys/include/param.h | 78 +- sys/include/picga.h | 14 +- sys/include/proc.h | 202 +-- sys/include/ptrace.h | 28 +- sys/include/pty.h | 14 +- sys/include/pwm.h | 12 +- sys/include/rdisk.h | 100 +- sys/include/reboot.h | 34 +- sys/include/resource.h | 110 +- sys/include/select.h | 32 +- sys/include/signal.h | 210 ++- sys/include/signalvar.h | 117 +- sys/include/spi.h | 20 +- sys/include/spi_bus.h | 18 +- sys/include/stat.h | 118 +- sys/include/sysctl.h | 382 ++--- sys/include/syslog.h | 176 +-- sys/include/systm.h | 165 +-- sys/include/time.h | 71 +- sys/include/times.h | 10 +- sys/include/trace.h | 85 -- sys/include/tty.h | 170 +-- sys/include/ttychars.h | 68 +- sys/include/ttydev.h | 70 +- sys/include/types.h | 58 +- sys/include/uart.h | 46 +- sys/include/uio.h | 24 +- sys/include/user.h | 118 +- sys/include/utsname.h | 22 +- sys/include/vmmac.h | 6 +- sys/include/vmmeter.h | 76 +- sys/include/vmparam.h | 18 +- sys/include/vmsystm.h | 23 +- sys/include/wait.h | 78 +- sys/kernel/exec_aout.c | 128 +- sys/kernel/exec_conf.c | 8 +- sys/kernel/exec_elf.c | 200 ++- sys/kernel/exec_script.c | 154 +-- sys/kernel/exec_subr.c | 618 ++++----- sys/kernel/init_main.c | 524 +++---- sys/kernel/init_sysent.c | 336 ++--- sys/kernel/kern_clock.c | 526 +++---- sys/kernel/kern_descrip.c | 658 ++++----- sys/kernel/kern_exec.c | 192 +-- sys/kernel/kern_exit.c | 396 +++--- sys/kernel/kern_fork.c | 382 ++--- sys/kernel/kern_glob.c | 64 +- sys/kernel/kern_mman.c | 38 +- sys/kernel/kern_proc.c | 52 +- sys/kernel/kern_prot.c | 154 +-- sys/kernel/kern_prot2.c | 100 +- sys/kernel/kern_resource.c | 400 +++--- sys/kernel/kern_sig.c | 1048 +++++++------- sys/kernel/kern_sig2.c | 462 +++---- sys/kernel/kern_subr.c | 154 +-- sys/kernel/kern_synch.c | 728 +++++----- sys/kernel/kern_sysctl.c | 1208 ++++++++-------- sys/kernel/kern_time.c | 448 +++--- sys/kernel/rdisk.c | 824 ++++++----- sys/kernel/subr_log.c | 444 +++--- sys/kernel/subr_prf.c | 681 ++++----- sys/kernel/subr_rmap.c | 288 ++-- sys/kernel/sys_generic.c | 724 +++++----- sys/kernel/sys_inode.c | 1112 +++++++-------- sys/kernel/sys_pipe.c | 448 +++--- sys/kernel/sys_process.c | 190 +-- sys/kernel/syscalls.c | 312 ++--- sys/kernel/tty.c | 2522 +++++++++++++++++----------------- sys/kernel/tty_pty.c | 776 +++++------ sys/kernel/tty_subr.c | 598 ++++---- sys/kernel/tty_tty.c | 74 +- sys/kernel/ufs_alloc.c | 428 +++--- sys/kernel/ufs_bio.c | 582 ++++---- sys/kernel/ufs_bmap.c | 220 +-- sys/kernel/ufs_dsort.c | 98 +- sys/kernel/ufs_fio.c | 246 ++-- sys/kernel/ufs_inode.c | 992 ++++++------- sys/kernel/ufs_mount.c | 456 +++--- sys/kernel/ufs_namei.c | 2014 +++++++++++++-------------- sys/kernel/ufs_subr.c | 168 +-- sys/kernel/ufs_syscalls.c | 1987 +++++++++++++------------- sys/kernel/ufs_syscalls2.c | 366 ++--- sys/kernel/vfs_vnops.c | 214 +-- sys/kernel/vm_sched.c | 353 +++-- sys/kernel/vm_swap.c | 134 +- sys/kernel/vm_swp.c | 224 ++- sys/pic32/clock.c | 8 +- sys/pic32/cpu.h | 36 +- sys/pic32/elf_machdep.h | 126 +- sys/pic32/glcd.c | 578 ++++---- sys/pic32/gpio.c | 714 +++++----- sys/pic32/hx8357.c | 466 ++++--- sys/pic32/io.h | 148 +- sys/pic32/limits.h | 38 +- sys/pic32/machparam.h | 100 +- sys/pic32/mem.c | 106 +- sys/pic32/pic32mx.h | 1440 +++++++++---------- sys/pic32/power_control.c | 19 +- sys/pic32/pwm.c | 222 ++- sys/pic32/rd_flash.c | 36 +- sys/pic32/rd_mrams.c | 294 ++-- sys/pic32/rd_sdramp.c | 488 ++++--- sys/pic32/rd_sdramp_config.h | 86 +- sys/pic32/rd_spirams.c | 441 +++--- sys/pic32/rd_sramc.c | 171 ++- sys/pic32/sdram.S | 664 +++++---- sys/pic32/sdram.h | 11 +- sys/pic32/signal.c | 272 ++-- sys/pic32/skel.c | 4 +- sys/pic32/ssd1926.h | 2 +- sys/pic32/startup.S | 550 ++++---- sys/pic32/swap.c | 152 +- sys/pic32/sysctl.c | 500 +++---- sys/pic32/usb_boot.c | 34 +- sys/pic32/usb_ch9.h | 280 ++-- sys/pic32/usb_console.c | 58 +- sys/pic32/usb_device.c | 86 +- sys/pic32/usb_device.h | 202 +-- sys/pic32/usb_function_cdc.c | 10 +- sys/pic32/usb_function_cdc.h | 14 +- sys/pic32/usb_hal_pic32.h | 24 +- sys/pic32/usb_uart.c | 96 +- 150 files changed, 20217 insertions(+), 20382 deletions(-) delete mode 100644 sys/include/trace.h diff --git a/rootfs.manifest b/rootfs.manifest index ece7fff..562d7b0 100644 --- a/rootfs.manifest +++ b/rootfs.manifest @@ -863,7 +863,6 @@ file /include/sys/syslog.h file /include/sys/systm.h file /include/sys/time.h file /include/sys/times.h -file /include/sys/trace.h file /include/sys/ttychars.h file /include/sys/ttydev.h file /include/sys/tty.h diff --git a/src/man/man6/Makefile b/src/man/man6/Makefile index f4aeb67..00c3573 100644 --- a/src/man/man6/Makefile +++ b/src/man/man6/Makefile @@ -36,5 +36,5 @@ clean: FRC rm -f ${OBJS} install: _make_01 - cp ${OBJS} ${DESTDIR}${MDIR} +# cp ${OBJS} ${DESTDIR}${MDIR} FRC: diff --git a/sys/include/adc.h b/sys/include/adc.h index bfa2923..dbe1ff8 100644 --- a/sys/include/adc.h +++ b/sys/include/adc.h @@ -3,10 +3,10 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)adc.h 1.4 (2.11BSD GTE) 1997/3/28 + * @(#)adc.h 1.4 (2.11BSD GTE) 1997/3/28 */ -#ifndef _ADC_H +#ifndef _ADC_H #define _ADC_H #include diff --git a/sys/include/buf.h b/sys/include/buf.h index 9265b12..8ac98d0 100644 --- a/sys/include/buf.h +++ b/sys/include/buf.h @@ -14,9 +14,9 @@ * doubly linked for easy removal. * * There are currently two queues for buffers: - * one for buffers containing ``useful'' information (the cache) - * one for buffers containing ``non-useful'' information - * (and empty buffers, pushed onto the front) + * one for buffers containing ``useful'' information (the cache) + * one for buffers containing ``non-useful'' information + * (and empty buffers, pushed onto the front) * These queues contain the buffers which are available for * reallocation, are kept in lru order. When not on one of these queues, * the buffers are ``checked out'' to drivers which use the available list @@ -30,26 +30,26 @@ */ struct bufhd { - int b_flags; /* see defines below */ - struct buf *b_forw, *b_back; /* fwd/bkwd pointer in chain */ + int b_flags; /* see defines below */ + struct buf *b_forw, *b_back; /* fwd/bkwd pointer in chain */ }; struct buf { - int b_flags; /* see defines below */ - struct buf *b_forw, *b_back; /* hash chain (2 way street) */ - struct buf *av_forw, *av_back; /* position on free list if not BUSY */ -#define b_actf av_forw /* alternate names for driver queue */ -#define b_actl av_back /* head - isn't history wonderful */ - u_int b_bcount; /* transfer count */ -#define b_active b_bcount /* driver queue head: drive active */ - int b_error; /* returned after I/O */ - dev_t b_dev; /* major+minor device name */ - caddr_t b_addr; /* core address */ - daddr_t b_blkno; /* block # on device */ - u_int b_resid; /* words not transferred after error */ -#define b_cylin b_resid /* disksort */ -#define b_errcnt b_resid /* while i/o in progress: # retries */ + int b_flags; /* see defines below */ + struct buf *b_forw, *b_back; /* hash chain (2 way street) */ + struct buf *av_forw, *av_back; /* position on free list if not BUSY */ +#define b_actf av_forw /* alternate names for driver queue */ +#define b_actl av_back /* head - isn't history wonderful */ + u_int b_bcount; /* transfer count */ +#define b_active b_bcount /* driver queue head: drive active */ + int b_error; /* returned after I/O */ + dev_t b_dev; /* major+minor device name */ + caddr_t b_addr; /* core address */ + daddr_t b_blkno; /* block # on device */ + u_int b_resid; /* words not transferred after error */ +#define b_cylin b_resid /* disksort */ +#define b_errcnt b_resid /* while i/o in progress: # retries */ }; /* @@ -57,30 +57,30 @@ struct buf * code to drop in, you have to have BQ_AGE and BQ_LRU *after* the first * queue, and it only costs 6 bytes of data space. */ -#define BQUEUES 3 /* number of free buffer queues */ +#define BQUEUES 3 /* number of free buffer queues */ -#define BQ_LOCKED 0 /* super-blocks &c */ -#define BQ_LRU 1 /* lru, useful buffers */ -#define BQ_AGE 2 /* rubbish */ -#define BQ_EMPTY 3 /* buffer headers with no memory */ +#define BQ_LOCKED 0 /* super-blocks &c */ +#define BQ_LRU 1 /* lru, useful buffers */ +#define BQ_AGE 2 /* rubbish */ +#define BQ_EMPTY 3 /* buffer headers with no memory */ /* Flags to low-level allocation routines. */ -#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */ -#define B_SYNC 0x02 /* Do all allocations synchronously. */ +#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */ +#define B_SYNC 0x02 /* Do all allocations synchronously. */ -#define bawrite(bp) { (bp)->b_flags |= B_ASYNC; bwrite(bp); } -#define bfree(bp) (bp)->b_bcount = 0 +#define bawrite(bp) { (bp)->b_flags |= B_ASYNC; bwrite(bp); } +#define bfree(bp) (bp)->b_bcount = 0 #ifdef KERNEL struct inode; -#define BUFHSZ 16 /* must be power of 2 */ -#define BUFHASH(dev,bn) ((struct buf*) &bufhash [((dev) + bn) & (BUFHSZ - 1)]) +#define BUFHSZ 16 /* must be power of 2 */ +#define BUFHASH(dev,bn) ((struct buf*) &bufhash [((dev) + bn) & (BUFHSZ - 1)]) -extern struct buf buf[]; /* the buffer pool itself */ -extern char bufdata[]; /* core data */ -extern struct bufhd bufhash[]; /* heads of hash lists */ -extern struct buf bfreelist[]; /* heads of available lists */ +extern struct buf buf[]; /* the buffer pool itself */ +extern char bufdata[]; /* core data */ +extern struct bufhd bufhash[]; /* heads of hash lists */ +extern struct buf bfreelist[]; /* heads of available lists */ /* * Assign a buffer for the given block. If the appropriate @@ -163,65 +163,65 @@ int geterror (struct buf *bp); /* * These flags are kept in b_flags. */ -#define B_WRITE 0x00000 /* non-read pseudo-flag */ -#define B_READ 0x00001 /* read when I/O occurs */ -#define B_DONE 0x00002 /* transaction finished */ -#define B_ERROR 0x00004 /* transaction aborted */ -#define B_BUSY 0x00008 /* not on av_forw/back list */ -#define B_PHYS 0x00010 /* physical IO */ -#define B_MAP 0x00020 /* alloc UNIBUS */ -#define B_WANTED 0x00040 /* issue wakeup when BUSY goes off */ -#define B_AGE 0x00080 /* delayed write for correct aging */ -#define B_ASYNC 0x00100 /* don't wait for I/O completion */ -#define B_DELWRI 0x00200 /* write at exit of avail list */ -#define B_TAPE 0x00400 /* this is a magtape (no bdwrite) */ -#define B_INVAL 0x00800 /* does not contain valid info */ -#define B_BAD 0x01000 /* bad block revectoring in progress */ -#define B_LOCKED 0x02000 /* locked in core (not reusable) */ -#define B_UBAREMAP 0x04000 /* addr UNIBUS virtual, not physical */ -#define B_RAMREMAP 0x08000 /* remapped into ramdisk */ +#define B_WRITE 0x00000 /* non-read pseudo-flag */ +#define B_READ 0x00001 /* read when I/O occurs */ +#define B_DONE 0x00002 /* transaction finished */ +#define B_ERROR 0x00004 /* transaction aborted */ +#define B_BUSY 0x00008 /* not on av_forw/back list */ +#define B_PHYS 0x00010 /* physical IO */ +#define B_MAP 0x00020 /* alloc UNIBUS */ +#define B_WANTED 0x00040 /* issue wakeup when BUSY goes off */ +#define B_AGE 0x00080 /* delayed write for correct aging */ +#define B_ASYNC 0x00100 /* don't wait for I/O completion */ +#define B_DELWRI 0x00200 /* write at exit of avail list */ +#define B_TAPE 0x00400 /* this is a magtape (no bdwrite) */ +#define B_INVAL 0x00800 /* does not contain valid info */ +#define B_BAD 0x01000 /* bad block revectoring in progress */ +#define B_LOCKED 0x02000 /* locked in core (not reusable) */ +#define B_UBAREMAP 0x04000 /* addr UNIBUS virtual, not physical */ +#define B_RAMREMAP 0x08000 /* remapped into ramdisk */ /* * Insq/Remq for the buffer hash lists. */ -#define bremhash(bp) { \ - (bp)->b_back->b_forw = (bp)->b_forw; \ - (bp)->b_forw->b_back = (bp)->b_back; \ +#define bremhash(bp) { \ + (bp)->b_back->b_forw = (bp)->b_forw; \ + (bp)->b_forw->b_back = (bp)->b_back; \ } -#define binshash(bp, dp) { \ - (bp)->b_forw = (dp)->b_forw; \ - (bp)->b_back = (dp); \ - (dp)->b_forw->b_back = (bp); \ - (dp)->b_forw = (bp); \ +#define binshash(bp, dp) { \ + (bp)->b_forw = (dp)->b_forw; \ + (bp)->b_back = (dp); \ + (dp)->b_forw->b_back = (bp); \ + (dp)->b_forw = (bp); \ } /* * Insq/Remq for the buffer free lists. */ -#define bremfree(bp) { \ - (bp)->av_back->av_forw = (bp)->av_forw; \ - (bp)->av_forw->av_back = (bp)->av_back; \ +#define bremfree(bp) { \ + (bp)->av_back->av_forw = (bp)->av_forw; \ + (bp)->av_forw->av_back = (bp)->av_back; \ } -#define binsheadfree(bp, dp) { \ - (dp)->av_forw->av_back = (bp); \ - (bp)->av_forw = (dp)->av_forw; \ - (dp)->av_forw = (bp); \ - (bp)->av_back = (dp); \ +#define binsheadfree(bp, dp) { \ + (dp)->av_forw->av_back = (bp); \ + (bp)->av_forw = (dp)->av_forw; \ + (dp)->av_forw = (bp); \ + (bp)->av_back = (dp); \ } -#define binstailfree(bp, dp) { \ - (dp)->av_back->av_forw = (bp); \ - (bp)->av_back = (dp)->av_back; \ - (dp)->av_back = (bp); \ - (bp)->av_forw = (dp); \ +#define binstailfree(bp, dp) { \ + (dp)->av_back->av_forw = (bp); \ + (bp)->av_back = (dp)->av_back; \ + (dp)->av_back = (bp); \ + (bp)->av_forw = (dp); \ } /* * Take a buffer off the free list it's on and * mark it as being use (B_BUSY) by a device. */ -#define notavail(bp) { \ - register int x = splbio(); \ - bremfree(bp); \ - (bp)->b_flags |= B_BUSY; \ - splx(x); \ +#define notavail(bp) { \ + register int x = splbio(); \ + bremfree(bp); \ + (bp)->b_flags |= B_BUSY; \ + splx(x); \ } diff --git a/sys/include/callout.h b/sys/include/callout.h index a2a0ebb..838b086 100644 --- a/sys/include/callout.h +++ b/sys/include/callout.h @@ -19,13 +19,13 @@ * forced to use a long, you might as well start doing the real-time * timer as a timeout like 4.3BSD. */ -struct callout { - int c_time; /* incremental time */ - caddr_t c_arg; /* argument to routine */ - void (*c_func) (caddr_t); /* routine */ - struct callout *c_next; +struct callout { + int c_time; /* incremental time */ + caddr_t c_arg; /* argument to routine */ + void (*c_func) (caddr_t); /* routine */ + struct callout *c_next; }; #ifdef KERNEL -extern struct callout *callfree, callout[], calltodo; +extern struct callout *callfree, callout[], calltodo; #endif diff --git a/sys/include/clist.h b/sys/include/clist.h index ca0dd7b..da6d926 100644 --- a/sys/include/clist.h +++ b/sys/include/clist.h @@ -6,12 +6,12 @@ * specifies the terms and conditions for redistribution. */ struct cblock { - struct cblock *c_next; - char c_info [CBSIZE]; + struct cblock *c_next; + char c_info [CBSIZE]; }; #ifdef KERNEL extern struct cblock cfree[]; -struct cblock *cfreelist; -int cfreecount; +struct cblock *cfreelist; +int cfreecount; #endif diff --git a/sys/include/dir.h b/sys/include/dir.h index b645a7e..ce795f6 100644 --- a/sys/include/dir.h +++ b/sys/include/dir.h @@ -3,14 +3,14 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#ifndef _DIR_ -#define _DIR_ +#ifndef _DIR_ +#define _DIR_ #ifndef MAXNAMLEN -#define MAXNAMLEN 63 +#define MAXNAMLEN 63 #endif -#define DIRBLKSIZ 1024 +#define DIRBLKSIZ 1024 /* * inode numbers are ino_t rather than u_long now. before, when v7direct @@ -19,11 +19,11 @@ * like a good idea to change the "real direct structure". SMS */ -struct direct { - ino_t d_ino; /* inode number of entry */ - u_short d_reclen; /* length of this record */ - u_short d_namlen; /* length of string in d_name */ - char d_name[MAXNAMLEN+1]; /* name must be no longer than this */ +struct direct { + ino_t d_ino; /* inode number of entry */ + u_short d_reclen; /* length of this record */ + u_short d_namlen; /* length of string in d_name */ + char d_name[MAXNAMLEN+1]; /* name must be no longer than this */ }; /* @@ -60,27 +60,27 @@ struct direct { * Definitions for library routines operating on directories. */ typedef struct _dirdesc { - int dd_fd; - long dd_loc; - long dd_size; - char dd_buf[DIRBLKSIZ]; - struct direct dd_cur; + int dd_fd; + long dd_loc; + long dd_size; + char dd_buf[DIRBLKSIZ]; + struct direct dd_cur; } DIR; #ifndef NULL #define NULL 0 #endif -#ifndef KERNEL +#ifndef KERNEL -extern DIR *opendir (const char *); -extern struct direct *readdir (DIR *); -extern long telldir (DIR *); -extern void seekdir (DIR *, long); -extern void closedir (DIR *); +extern DIR *opendir (const char *); +extern struct direct *readdir (DIR *); +extern long telldir (DIR *); +extern void seekdir (DIR *, long); +extern void closedir (DIR *); -#define rewinddir(dirp) seekdir ((dirp), (long)0) -#define dirfd(dirp) ((dirp)->dd_fd) +#define rewinddir(dirp) seekdir ((dirp), (long)0) +#define dirfd(dirp) ((dirp)->dd_fd) #endif /* !KERNEL */ @@ -89,17 +89,17 @@ extern void closedir (DIR *); * Should use struct direct's, but the name field * is MAXNAMLEN - 1, and this just won't do. */ -#define dotdot_ino dtdt_ino -#define dotdot_reclen dtdt_rec -#define dotdot_name dtdt_name +#define dotdot_ino dtdt_ino +#define dotdot_reclen dtdt_rec +#define dotdot_name dtdt_name struct dirtemplate { - ino_t dot_ino; - u_short dot_reclen; - u_short dot_namlen; - char dot_name[4]; /* must be multiple of 4 */ - ino_t dotdot_ino; - u_short dotdot_reclen; - u_short dotdot_namlen; - char dotdot_name[4]; /* ditto */ + ino_t dot_ino; + u_short dot_reclen; + u_short dot_namlen; + char dot_name[4]; /* must be multiple of 4 */ + ino_t dotdot_ino; + u_short dotdot_reclen; + u_short dotdot_namlen; + char dotdot_name[4]; /* ditto */ }; #endif /* _DIR_ */ diff --git a/sys/include/disk.h b/sys/include/disk.h index d96a9ab..e10e2b9 100644 --- a/sys/include/disk.h +++ b/sys/include/disk.h @@ -1,6 +1,6 @@ /* * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and @@ -8,8 +8,8 @@ * * All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Lawrence Berkeley Laboratory. + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratory. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -21,8 +21,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -39,8 +39,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#ifndef _SYS_DISK_H_ -#define _SYS_DISK_H_ +#ifndef _SYS_DISK_H_ +#define _SYS_DISK_H_ #include /* @@ -51,7 +51,7 @@ * * Note: the 2.11BSD version is very different. The 4.4 version served * as the inspiration. I needed something similar but for slightly - * different purposes. + * different purposes. */ /* @@ -76,38 +76,33 @@ */ struct dkdevice { - int dk_bopenmask; /* block devices open */ - int dk_copenmask; /* character devices open */ - int dk_openmask; /* composite (bopen|copen) */ - int dk_flags; /* label state see below */ - size_t dk_label; /* sector containing label */ - struct partition dk_parts[MAXPARTITIONS]; /* inkernel portion */ + int dk_bopenmask; /* block devices open */ + int dk_copenmask; /* character devices open */ + int dk_openmask; /* composite (bopen|copen) */ + int dk_flags; /* label state - see below */ + size_t dk_label; /* sector containing label */ + struct partition dk_parts[MAXPARTITIONS]; /* inkernel portion */ }; -#define DKF_OPENING 0x0001 /* drive is being opened */ -#define DKF_CLOSING 0x0002 /* drive is being closed */ -#define DKF_WANTED 0x0004 /* drive is being waited for */ -#define DKF_ALIVE 0x0008 /* drive is alive */ -#define DKF_ONLINE 0x0010 /* drive is online */ -#define DKF_WLABEL 0x0020 /* label area is being written */ -#define DKF_SEEK 0x0040 /* drive is seeking */ -#define DKF_SWAIT 0x0080 /* waiting for seek to complete */ +#define DKF_OPENING 0x0001 /* drive is being opened */ +#define DKF_CLOSING 0x0002 /* drive is being closed */ +#define DKF_WANTED 0x0004 /* drive is being waited for */ +#define DKF_ALIVE 0x0008 /* drive is alive */ +#define DKF_ONLINE 0x0010 /* drive is online */ +#define DKF_WLABEL 0x0020 /* label area is being written */ +#define DKF_SEEK 0x0040 /* drive is seeking */ +#define DKF_SWAIT 0x0080 /* waiting for seek to complete */ /* encoding of disk minor numbers, should be elsewhere... but better * here than in ufs_disksubr.c * * Note: the controller number in bits 6 and 7 of the minor device are NOT - * removed. It is the responsibility of the driver to extract or mask - * these bits. + * removed. It is the responsibility of the driver to extract or mask + * these bits. */ -#define dkunit(dev) (minor(dev) >> 3) -#define dkpart(dev) (minor(dev) & 07) -#define dkminor(unit, part) (((unit) << 3) | (part)) +#define dkunit(dev) (minor(dev) >> 3) +#define dkpart(dev) (minor(dev) & 07) +#define dkminor(unit, part) (((unit) << 3) | (part)) -#ifdef KERNEL -//char *readdisklabel(); -//int setdisklabel(); -//int writedisklabel(); -#endif #endif /* _SYS_DISK_H_ */ diff --git a/sys/include/dk.h b/sys/include/dk.h index ec6723d..02024e4 100644 --- a/sys/include/dk.h +++ b/sys/include/dk.h @@ -7,25 +7,25 @@ /* * Instrumentation */ -#define CPUSTATES 4 +#define CPUSTATES 4 -#define CP_USER 0 -#define CP_NICE 1 -#define CP_SYS 2 -#define CP_IDLE 3 +#define CP_USER 0 +#define CP_NICE 1 +#define CP_SYS 2 +#define CP_IDLE 3 -#define DK_NDRIVE 4 +#define DK_NDRIVE 4 #if defined(KERNEL) && defined(UCB_METER) -long cp_time[CPUSTATES]; /* number of ticks spent in each cpu state */ -int dk_ndrive; /* number of drives being monitored */ -int dk_busy; /* bit array of drive busy flags */ -long dk_xfer[DK_NDRIVE]; /* number of transfers */ -long dk_bytes[DK_NDRIVE]; /* number of bytes transfered */ -char *dk_name[DK_NDRIVE]; /* names of monitored drives */ -int dk_unit[DK_NDRIVE]; /* unit numbers of monitored drives */ -int dk_n; /* number of dk numbers assigned so far */ +long cp_time[CPUSTATES]; /* number of ticks spent in each cpu state */ +int dk_ndrive; /* number of drives being monitored */ +int dk_busy; /* bit array of drive busy flags */ +long dk_xfer[DK_NDRIVE]; /* number of transfers */ +long dk_bytes[DK_NDRIVE]; /* number of bytes transfered */ +char *dk_name[DK_NDRIVE]; /* names of monitored drives */ +int dk_unit[DK_NDRIVE]; /* unit numbers of monitored drives */ +int dk_n; /* number of dk numbers assigned so far */ -long tk_nin; /* number of tty characters input */ -long tk_nout; /* number of tty characters output */ +long tk_nin; /* number of tty characters input */ +long tk_nout; /* number of tty characters output */ #endif diff --git a/sys/include/dkbad.h b/sys/include/dkbad.h index 0707260..812c078 100644 --- a/sys/include/dkbad.h +++ b/sys/include/dkbad.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)dkbad.h 1.1 (2.10BSD Berkeley) 12/1/86 + * @(#)dkbad.h 1.1 (2.10BSD Berkeley) 12/1/86 */ /* @@ -39,19 +39,19 @@ * there are exceptions to this rule. Note, this value is also present * in the bad144 program. */ -#define MAXBAD 32 /* Maximum bad sectors supported */ +#define MAXBAD 32 /* Maximum bad sectors supported */ struct dkbad { - long bt_csn; /* cartridge serial number */ - u_short bt_mbz; /* unused; should be 0 */ - u_short bt_flag; /* -1 => alignment cartridge */ - struct bt_bad { - u_short bt_cyl; /* cylinder number of bad sector */ - u_short bt_trksec; /* track and sector number */ - } bt_bad[MAXBAD]; + long bt_csn; /* cartridge serial number */ + u_short bt_mbz; /* unused; should be 0 */ + u_short bt_flag; /* -1 => alignment cartridge */ + struct bt_bad { + u_short bt_cyl; /* cylinder number of bad sector */ + u_short bt_trksec; /* track and sector number */ + } bt_bad[MAXBAD]; }; -#define ECC 0 -#define SSE 1 -#define BSE 2 -#define CONT 3 +#define ECC 0 +#define SSE 1 +#define BSE 2 +#define CONT 3 diff --git a/sys/include/errno.h b/sys/include/errno.h index 0f8c998..c97ae67 100644 --- a/sys/include/errno.h +++ b/sys/include/errno.h @@ -3,119 +3,119 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)errno.h 7.1.3 (2.11BSD) 1999/9/6 + * @(#)errno.h 7.1.3 (2.11BSD) 1999/9/6 */ -#ifndef KERNEL -extern int errno; /* global error number */ +#ifndef KERNEL +extern int errno; /* global error number */ #endif -#define EPERM 1 /* Not owner */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* I/O error */ -#define ENXIO 6 /* No such device or address */ -#define E2BIG 7 /* Arg list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file number */ -#define ECHILD 10 /* No children */ -#define EAGAIN 11 /* No more processes */ -#define ENOMEM 12 /* Not enough core */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Mount device busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory*/ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* File table overflow */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ +#define EPERM 1 /* Not owner */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No children */ +#define EAGAIN 11 /* No more processes */ +#define ENOMEM 12 /* Not enough core */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Mount device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory*/ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ /* math software */ -#define EDOM 33 /* Argument too large */ -#define ERANGE 34 /* Result too large */ +#define EDOM 33 /* Argument too large */ +#define ERANGE 34 /* Result too large */ /* non-blocking and interrupt i/o */ -#define EWOULDBLOCK 35 /* Operation would block */ -#define EDEADLK EWOULDBLOCK /* ditto */ -#define EINPROGRESS 36 /* Operation now in progress */ -#define EALREADY 37 /* Operation already in progress */ +#define EWOULDBLOCK 35 /* Operation would block */ +#define EDEADLK EWOULDBLOCK /* ditto */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ /* ipc/network software */ - /* argument errors */ -#define ENOTSOCK 38 /* Socket operation on non-socket */ -#define EDESTADDRREQ 39 /* Destination address required */ -#define EMSGSIZE 40 /* Message too long */ -#define EPROTOTYPE 41 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 42 /* Protocol not available */ -#define EPROTONOSUPPORT 43 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ -#define EOPNOTSUPP 45 /* Operation not supported on socket */ -#define EPFNOSUPPORT 46 /* Protocol family not supported */ -#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ -#define EADDRINUSE 48 /* Address already in use */ -#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + /* argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define EOPNOTSUPP 45 /* Operation not supported on socket */ +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ - /* operational errors */ -#define ENETDOWN 50 /* Network is down */ -#define ENETUNREACH 51 /* Network is unreachable */ -#define ENETRESET 52 /* Network dropped connection on reset */ -#define ECONNABORTED 53 /* Software caused connection abort */ -#define ECONNRESET 54 /* Connection reset by peer */ -#define ENOBUFS 55 /* No buffer space available */ -#define EISCONN 56 /* Socket is already connected */ -#define ENOTCONN 57 /* Socket is not connected */ -#define ESHUTDOWN 58 /* Can't send after socket shutdown */ -#define ETOOMANYREFS 59 /* Too many references: can't splice */ -#define ETIMEDOUT 60 /* Connection timed out */ -#define ECONNREFUSED 61 /* Connection refused */ + /* operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#define ETIMEDOUT 60 /* Connection timed out */ +#define ECONNREFUSED 61 /* Connection refused */ - /* */ -#define ELOOP 62 /* Too many levels of symbolic links */ -#define ENAMETOOLONG 63 /* File name too long */ + /* */ +#define ELOOP 62 /* Too many levels of symbolic links */ +#define ENAMETOOLONG 63 /* File name too long */ /* should be rearranged */ -#define EHOSTDOWN 64 /* Host is down */ -#define EHOSTUNREACH 65 /* No route to host */ -#define ENOTEMPTY 66 /* Directory not empty */ +#define EHOSTDOWN 64 /* Host is down */ +#define EHOSTUNREACH 65 /* No route to host */ +#define ENOTEMPTY 66 /* Directory not empty */ /* quotas & mush */ -#define EPROCLIM 67 /* Too many processes */ -#define EUSERS 68 /* Too many users */ -#define EDQUOT 69 /* Disc quota exceeded */ +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#define EDQUOT 69 /* Disc quota exceeded */ /* Network File System */ -#define ESTALE 70 /* Stale NFS file handle */ -#define EREMOTE 71 /* Too many levels of remote in path */ -#define EBADRPC 72 /* RPC struct is bad */ -#define ERPCMISMATCH 73 /* RPC version wrong */ -#define EPROGUNAVAIL 74 /* RPC prog. not avail */ -#define EPROGMISMATCH 75 /* Program version wrong */ -#define EPROCUNAVAIL 76 /* Bad procedure for program */ +#define ESTALE 70 /* Stale NFS file handle */ +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC prog. not avail */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ -#define ENOLCK 77 /* No locks available */ -#define ENOSYS 78 /* Function not implemented */ +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ -#define EFTYPE 79 /* Inappropriate file type or format */ -#define EAUTH 80 /* Authentication error */ -#define ENEEDAUTH 81 /* Need authenticator */ -#define ELAST 81 /* Must be equal largest errno */ +#define EFTYPE 79 /* Inappropriate file type or format */ +#define EAUTH 80 /* Authentication error */ +#define ENEEDAUTH 81 /* Need authenticator */ +#define ELAST 81 /* Must be equal largest errno */ -#ifdef KERNEL +#ifdef KERNEL /* pseudo-errors returned inside kernel to modify return back to user mode */ -#define ERESTART -1 /* restart syscall */ -#define EJUSTRETURN -2 /* don't modify regs, just return */ +#define ERESTART -1 /* restart syscall */ +#define EJUSTRETURN -2 /* don't modify regs, just return */ #endif diff --git a/sys/include/exec.h b/sys/include/exec.h index 13c5880..3d1011a 100644 --- a/sys/include/exec.h +++ b/sys/include/exec.h @@ -9,11 +9,11 @@ #ifdef KERNEL #ifdef EXEC_SCRIPT -#define SHSIZE 64 -#define SHPATHLEN 64 +#define SHSIZE 64 +#define SHPATHLEN 64 #endif #ifdef EXEC_ELF -#define STRLEN 32 +#define STRLEN 32 #endif #ifdef EXEC_AOUT #include "exec_aout.h" @@ -22,70 +22,70 @@ #include "exec_elf.h" #endif -#define NO_ADDR ((caddr_t)(~0U)) /* Indicates addr. not yet filled in */ +#define NO_ADDR ((caddr_t)(~0U)) /* Indicates addr. not yet filled in */ struct memsect { - caddr_t vaddr; - unsigned len; + caddr_t vaddr; + unsigned len; }; struct exec_params { - char *userfname; /* The arguments to the exec() call */ - char **userargp; - char **userenvp; - union { + char *userfname; /* The arguments to the exec() call */ + char **userargp; + char **userenvp; + union { #ifdef EXEC_SCRIPT - char sh[SHSIZE]; + char sh[SHSIZE]; #endif #ifdef EXEC_AOUT - struct exec aout; + struct exec aout; #endif #ifdef EXEC_ELF - struct elf_ehdr elf; + struct elf_ehdr elf; #endif - } hdr; /* head of file to exec */ - int hdr_len; /* number of bytes valid in image_header */ - char **argp, **envp; - u_short argc, envc; /* count of argument and environment strings */ - u_short argbc, envbc; /* total number of chars in argc and envc string pool */ - union { + } hdr; /* head of file to exec */ + int hdr_len; /* number of bytes valid in image_header */ + char **argp, **envp; + u_short argc, envc; /* count of argument and environment strings */ + u_short argbc, envbc; /* total number of chars in argc and envc string pool */ + union { #ifdef EXEC_SCRIPT - struct { - char interpname[20]; /* real name of the script interpreter */ - char interparg[SHPATHLEN]; /* interpreter arg */ - char interpreted; /* flag - this executable is interpreted */ - } sh; + struct { + char interpname[20]; /* real name of the script interpreter */ + char interparg[SHPATHLEN]; /* interpreter arg */ + char interpreted; /* flag - this executable is interpreted */ + } sh; #endif #ifdef EXEC_ELF - struct { - struct buf *stbp; /* String table buffer pointer */ - int stbpos; /* String table pos in buffer */ - int stsize; /* String table size */ - int stoffset; /* String table file pos */ - char str[STRLEN]; - } elf; + struct { + struct buf *stbp; /* String table buffer pointer */ + int stbpos; /* String table pos in buffer */ + int stsize; /* String table size */ + int stoffset; /* String table file pos */ + char str[STRLEN]; + } elf; #endif #ifdef EXEC_AOUT - struct { - } aout; + struct { + } aout; #endif - }; + }; - gid_t gid; - uid_t uid; -#define MAXALLOCBUF 6 - struct { - struct buf *bp; /* Memory allocator buffer */ - u_short fill; /* Memory allocator "free" pointer */ - } alloc[MAXALLOCBUF]; - u_long ep_taddr, ep_tsize, ep_daddr, ep_dsize; - struct inode *ip; /* executable file ip */ - struct memsect text, data, bss, heap, stack; + gid_t gid; + uid_t uid; +#define MAXALLOCBUF 6 + struct { + struct buf *bp; /* Memory allocator buffer */ + u_short fill; /* Memory allocator "free" pointer */ + } alloc[MAXALLOCBUF]; + u_long ep_taddr, ep_tsize, ep_daddr, ep_dsize; + struct inode *ip; /* executable file ip */ + struct memsect text, data, bss, heap, stack; }; struct execsw { - int (*es_check)(struct exec_params *epp); - const char* es_name; + int (*es_check)(struct exec_params *epp); + const char* es_name; }; extern const struct execsw execsw[]; extern int nexecs, exec_maxhdrsz; diff --git a/sys/include/exec_aout.h b/sys/include/exec_aout.h index 5afbcf0..a144cdb 100644 --- a/sys/include/exec_aout.h +++ b/sys/include/exec_aout.h @@ -4,99 +4,98 @@ /* * Header prepended to each a.out file. */ -struct exec { - unsigned a_midmag; /* magic number */ - unsigned a_text; /* size of text segment */ - unsigned a_data; /* size of initialized data */ - unsigned a_bss; /* size of uninitialized data */ - unsigned a_reltext; /* size of text relocation info */ - unsigned a_reldata; /* size of data relocation info */ - unsigned a_syms; /* size of symbol table */ - unsigned a_entry; /* entry point */ +struct exec { + unsigned a_midmag; /* magic number */ + unsigned a_text; /* size of text segment */ + unsigned a_data; /* size of initialized data */ + unsigned a_bss; /* size of uninitialized data */ + unsigned a_reltext; /* size of text relocation info */ + unsigned a_reldata; /* size of data relocation info */ + unsigned a_syms; /* size of symbol table */ + unsigned a_entry; /* entry point */ }; -#define a_magic a_midmag & 0xffff +#define a_magic a_midmag & 0xffff /* a_magic (a_midmag & 0x0000ffff) */ -#define RMAGIC 0406 /* relocatable object file */ -#define OMAGIC 0407 /* old impure format */ -#define NMAGIC 0410 /* read-only text */ +#define RMAGIC 0406 /* relocatable object file */ +#define OMAGIC 0407 /* old impure format */ +#define NMAGIC 0410 /* read-only text */ /* * a_mid ((a_midmag & 0x03ff0000) >> 16) */ -#define MID_ZERO 0 /* unknown - implementation dependent */ -#define MID_SUN010 1 /* sun 68010/68020 binary */ -#define MID_SUN020 2 /* sun 68020-only binary */ -#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */ -#define MID_HP200 200 /* hp200 (68010) BSD binary */ -#define MID_I386 134 /* i386 BSD binary */ -#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */ -#define MID_M68K4K 136 /* m68k BSD binary with 4K page sizes */ -#define MID_NS32532 137 /* ns32532 */ -#define MID_SPARC 138 /* sparc */ -#define MID_PMAX 139 /* pmax */ -#define MID_VAX1K 140 /* vax 1K page size binaries */ -#define MID_ALPHA 141 /* Alpha BSD binary */ -#define MID_MIPS 142 /* big-endian MIPS */ -#define MID_ARM6 143 /* ARM6 */ -#define MID_SH3 145 /* SH3 */ -#define MID_POWERPC 149 /* big-endian PowerPC */ -#define MID_VAX 150 /* vax */ -#define MID_SPARC64 151 /* LP64 sparc */ -#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ -#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ -#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ +#define MID_ZERO 0 /* unknown - implementation dependent */ +#define MID_SUN010 1 /* sun 68010/68020 binary */ +#define MID_SUN020 2 /* sun 68020-only binary */ +#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */ +#define MID_HP200 200 /* hp200 (68010) BSD binary */ +#define MID_I386 134 /* i386 BSD binary */ +#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */ +#define MID_M68K4K 136 /* m68k BSD binary with 4K page sizes */ +#define MID_NS32532 137 /* ns32532 */ +#define MID_SPARC 138 /* sparc */ +#define MID_PMAX 139 /* pmax */ +#define MID_VAX1K 140 /* vax 1K page size binaries */ +#define MID_ALPHA 141 /* Alpha BSD binary */ +#define MID_MIPS 142 /* big-endian MIPS */ +#define MID_ARM6 143 /* ARM6 */ +#define MID_SH3 145 /* SH3 */ +#define MID_POWERPC 149 /* big-endian PowerPC */ +#define MID_VAX 150 /* vax */ +#define MID_SPARC64 151 /* LP64 sparc */ +#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ +#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ +#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ /* * a_flags ((a_midmag & 0xfc000000 ) << 26) */ -#define EX_PIC 0x10 -#define EX_DYNAMIC 0x20 -#define EX_DPMASK 0x30 +#define EX_PIC 0x10 +#define EX_DYNAMIC 0x20 +#define EX_DPMASK 0x30 /* * Interpretation of the (a_flags & EX_DPMASK) bits: * - * 00 traditional executable or object file - * 01 object file contains PIC code (set by `as -k') - * 10 dynamic executable - * 11 position independent executable image - * (eg. a shared library) + * 00 traditional executable or object file + * 01 object file contains PIC code (set by `as -k') + * 10 dynamic executable + * 11 position independent executable image + * (eg. a shared library) */ /* * The a.out structure's a_midmag field is a network-byteorder encoding * of this int - * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM + * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM * Where `F' is 6 bits of flag like EX_DYNAMIC, * `m' is 10 bits of machine-id like MID_I386, and * `M' is 16 bits worth of magic number, ie. ZMAGIC. * The macros below will set/get the needed fields. */ -#define N_GETMAGIC(ex) (((ex).a_midmag)&0x0000ffff) -#define N_GETMID(ex) ((((ex).a_midmag)&0x03ff0000) >> 16) -#define N_GETFLAG(ex) ((((ex).a_midmag)&0xfc000000 ) << 26) +#define N_GETMAGIC(ex) (((ex).a_midmag)&0x0000ffff) +#define N_GETMID(ex) ((((ex).a_midmag)&0x03ff0000) >> 16) +#define N_GETFLAG(ex) ((((ex).a_midmag)&0xfc000000 ) << 26) /* Valid magic number check. */ -#define N_BADMAG(x) (N_GETMAGIC(x) != RMAGIC && \ - N_GETMAGIC(x) != OMAGIC && \ - N_GETMAGIC(x) != NMAGIC) +#define N_BADMAG(x) (N_GETMAGIC(x) != RMAGIC && \ + N_GETMAGIC(x) != OMAGIC && \ + N_GETMAGIC(x) != NMAGIC) /* Text segment offset. */ -#define N_TXTOFF(x) sizeof(struct exec) +#define N_TXTOFF(x) sizeof(struct exec) /* Data segment offset. */ -#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) +#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) /* Text relocation table offset. */ -#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data) +#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data) /* Data relocation table offset. */ -#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_reltext) +#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_reltext) /* Symbol table offset. */ -#define N_SYMOFF(x) (N_GETMAGIC(x) == RMAGIC ? \ - N_DRELOFF(x) + (x).a_reldata : \ - N_DATOFF(x) + (x).a_data) - +#define N_SYMOFF(x) (N_GETMAGIC(x) == RMAGIC ? \ + N_DRELOFF(x) + (x).a_reldata : \ + N_DATOFF(x) + (x).a_data) #endif diff --git a/sys/include/exec_elf.h b/sys/include/exec_elf.h index ccaded0..6663299 100644 --- a/sys/include/exec_elf.h +++ b/sys/include/exec_elf.h @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.h,v 1.37.4.1 2000/07/26 23:57:06 mycroft Exp $ */ +/* $NetBSD: exec_elf.h,v 1.37.4.1 2000/07/26 23:57:06 mycroft Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. @@ -37,7 +37,7 @@ */ #ifndef _SYS_EXEC_ELF_H_ -#define _SYS_EXEC_ELF_H_ +#define _SYS_EXEC_ELF_H_ #ifndef _SYS_TYPES_H_ #include @@ -46,434 +46,430 @@ /* * ELF Header */ -#define ELF_NIDENT 16 +#define ELF_NIDENT 16 struct elf_ehdr { - unsigned char e_ident[ELF_NIDENT]; /* Id bytes */ - unsigned short e_type; /* file type */ - unsigned short e_machine; /* machine type */ - unsigned int e_version; /* version number */ - unsigned int e_entry; /* entry point */ - unsigned int e_phoff; /* Program header table offset */ - unsigned int e_shoff; /* Section header table offset */ - unsigned int e_flags; /* Processor flags (currently unused, should be 0) */ - unsigned short e_ehsize; /* sizeof elf_ehdr */ - unsigned short e_phentsize; /* Program header entry size */ - unsigned short e_phnum; /* Number of program headers */ - unsigned short e_shentsize; /* Section header entry size */ - unsigned short e_shnum; /* Number of section headers */ - unsigned short e_shstrndx; /* String table index */ + unsigned char e_ident[ELF_NIDENT]; /* Id bytes */ + unsigned short e_type; /* file type */ + unsigned short e_machine; /* machine type */ + unsigned int e_version; /* version number */ + unsigned int e_entry; /* entry point */ + unsigned int e_phoff; /* Program header table offset */ + unsigned int e_shoff; /* Section header table offset */ + unsigned int e_flags; /* Processor flags (currently unused, should be 0) */ + unsigned short e_ehsize; /* sizeof elf_ehdr */ + unsigned short e_phentsize; /* Program header entry size */ + unsigned short e_phnum; /* Number of program headers */ + unsigned short e_shentsize; /* Section header entry size */ + unsigned short e_shnum; /* Number of section headers */ + unsigned short e_shstrndx; /* String table index */ }; /* e_ident offsets */ -#define EI_MAG0 0 /* first byte of magic number */ -#define ELFMAG0 0x7f -#define EI_MAG1 1 /* second byte of magic number */ -#define ELFMAG1 'E' -#define EI_MAG2 2 /* third byte of magic number */ -#define ELFMAG2 'L' -#define EI_MAG3 3 /* fourth byte of magic number */ -#define ELFMAG3 'F' +#define EI_MAG0 0 /* first byte of magic number */ +#define ELFMAG0 0x7f +#define EI_MAG1 1 /* second byte of magic number */ +#define ELFMAG1 'E' +#define EI_MAG2 2 /* third byte of magic number */ +#define ELFMAG2 'L' +#define EI_MAG3 3 /* fourth byte of magic number */ +#define ELFMAG3 'F' -#define EI_CLASS 4 /* 5:th byte: File class */ -#define ELFCLASSNONE 0 /* Invalid class */ -#define ELFCLASS32 1 /* 32-bit objects */ -#define ELFCLASS64 2 /* 64-bit objects */ -#define ELFCLASSNUM 3 +#define EI_CLASS 4 /* 5:th byte: File class */ +#define ELFCLASSNONE 0 /* Invalid class */ +#define ELFCLASS32 1 /* 32-bit objects */ +#define ELFCLASS64 2 /* 64-bit objects */ +#define ELFCLASSNUM 3 -#define EI_DATA 5 /* 6:th byte: Data encoding */ -#define ELFDATANONE 0 /* Unknown data format */ -#define ELFDATA2LSB 1 /* two's complement, little-endian */ -#define ELFDATA2MSB 2 /* two's complement, big-endian */ +#define EI_DATA 5 /* 6:th byte: Data encoding */ +#define ELFDATANONE 0 /* Unknown data format */ +#define ELFDATA2LSB 1 /* two's complement, little-endian */ +#define ELFDATA2MSB 2 /* two's complement, big-endian */ -#define EI_VERSION 6 /* Version number of the ELF specification */ -#define EV_NONE 0 /* Invalid version */ -#define EV_CURRENT 1 /* Current version */ -#define EV_NUM 2 +#define EI_VERSION 6 /* Version number of the ELF specification */ +#define EV_NONE 0 /* Invalid version */ +#define EV_CURRENT 1 /* Current version */ +#define EV_NUM 2 -#define EI_OSABI 7 /* Operating system/ABI identification */ -#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ -#define ELFOSABI_HPUX 1 /* HP-UX operating system */ -#define ELFOSABI_NETBSD /* NetBSD ABI */ -#define ELFOSABI_LINUX /* Linux ABI */ -#define ELFOSABI_SOLARIS /* Solaris ABI */ -#define ELFOSABI_FREEBSD /* FreeBSD ABI */ -#define ELFOSABI_ARM /* ARM architecture ABI */ -#define ELFOSABI_STANDALONE 255 /* Stand-alone (embedded) application */ +#define EI_OSABI 7 /* Operating system/ABI identification */ +#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD /* NetBSD ABI */ +#define ELFOSABI_LINUX /* Linux ABI */ +#define ELFOSABI_SOLARIS /* Solaris ABI */ +#define ELFOSABI_FREEBSD /* FreeBSD ABI */ +#define ELFOSABI_ARM /* ARM architecture ABI */ +#define ELFOSABI_STANDALONE 255 /* Stand-alone (embedded) application */ -#define EI_ABIVERSION 8 /* ABI version */ +#define EI_ABIVERSION 8 /* ABI version */ -#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/ +#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/ -#define ELFMAG "\177ELF" -#define SELFMAG 4 +#define ELFMAG "\177ELF" +#define SELFMAG 4 /* e_type */ -#define ET_NONE 0 /* Unknown file type */ -#define ET_REL 1 /* A Relocatable file */ -#define ET_EXEC 2 /* An Executable file */ -#define ET_DYN 3 /* A Shared object file */ -#define ET_CORE 4 /* A Core file */ -#define ET_NUM 5 +#define ET_NONE 0 /* Unknown file type */ +#define ET_REL 1 /* A Relocatable file */ +#define ET_EXEC 2 /* An Executable file */ +#define ET_DYN 3 /* A Shared object file */ +#define ET_CORE 4 /* A Core file */ +#define ET_NUM 5 -#define ET_LOOS 0xfe00 /* Operating system specific range */ -#define ET_HIOS 0xfeff -#define ET_LOPROC 0xff00 /* Processor-specific range */ -#define ET_HIPROC 0xffff +#define ET_LOOS 0xfe00 /* Operating system specific range */ +#define ET_HIOS 0xfeff +#define ET_LOPROC 0xff00 /* Processor-specific range */ +#define ET_HIPROC 0xffff /* e_machine */ -#define EM_NONE 0 /* No machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola 68000 */ -#define EM_88K 5 /* Motorola 88000 */ -#define EM_486 6 /* Intel 80486 */ -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS I Architecture */ -#define EM_S370 9 /* Amdahl UTS on System/370 */ -#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ -#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */ -#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ -#define EM_NCUBE 16 /* NCube XXX reserved */ -#define EM_VPP500 17 /* Fujitsu VPP500 */ -#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ -#define EM_960 19 /* Intel 80960 */ -#define EM_PPC 20 /* PowerPC */ -#define EM_V800 36 /* NEC V800 */ -#define EM_FR20 37 /* Fujitsu FR20 */ -#define EM_RH32 38 /* TRW RH-32 */ -#define EM_RCE 39 /* Motorola RCE */ -#define EM_ARM 40 /* Advanced RISC Machines ARM */ -#define EM_ALPHA 41 /* DIGITAL Alpha */ -#define EM_SH 42 /* Hitachi Super-H */ -#define EM_SPARCV9 43 /* SPARC Version 9 */ -#define EM_TRICORE 44 /* Siemens Tricore */ -#define EM_ARC 45 /* Argonaut RISC Core */ -#define EM_H8_300 46 /* Hitachi H8/300 */ -#define EM_H8_300H 47 /* Hitachi H8/300H */ -#define EM_H8S 48 /* Hitachi H8S */ -#define EM_H8_500 49 /* Hitachi H8/500 */ -#define EM_IA_64 50 /* Intel Merced Processor */ -#define EM_MIPS_X 51 /* Stanford MIPS-X */ -#define EM_COLDFIRE 52 /* Motorola Coldfire */ -#define EM_68HC12 53 /* Motorola MC68HC12 */ -#define EM_VAX 75 /* DIGITAL VAX */ -#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */ -#define EM_NUM 36903 +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel 80486 */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS I Architecture */ +#define EM_S370 9 /* Amdahl UTS on System/370 */ +#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ +#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */ +#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ +#define EM_NCUBE 16 /* NCube XXX reserved */ +#define EM_VPP500 17 /* Fujitsu VPP500 */ +#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ +#define EM_960 19 /* Intel 80960 */ +#define EM_PPC 20 /* PowerPC */ +#define EM_V800 36 /* NEC V800 */ +#define EM_FR20 37 /* Fujitsu FR20 */ +#define EM_RH32 38 /* TRW RH-32 */ +#define EM_RCE 39 /* Motorola RCE */ +#define EM_ARM 40 /* Advanced RISC Machines ARM */ +#define EM_ALPHA 41 /* DIGITAL Alpha */ +#define EM_SH 42 /* Hitachi Super-H */ +#define EM_SPARCV9 43 /* SPARC Version 9 */ +#define EM_TRICORE 44 /* Siemens Tricore */ +#define EM_ARC 45 /* Argonaut RISC Core */ +#define EM_H8_300 46 /* Hitachi H8/300 */ +#define EM_H8_300H 47 /* Hitachi H8/300H */ +#define EM_H8S 48 /* Hitachi H8S */ +#define EM_H8_500 49 /* Hitachi H8/500 */ +#define EM_IA_64 50 /* Intel Merced Processor */ +#define EM_MIPS_X 51 /* Stanford MIPS-X */ +#define EM_COLDFIRE 52 /* Motorola Coldfire */ +#define EM_68HC12 53 /* Motorola MC68HC12 */ +#define EM_VAX 75 /* DIGITAL VAX */ +#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */ +#define EM_NUM 36903 /* * ELF Program Header */ struct elf_phdr { - unsigned int p_type; /* entry type */ - unsigned int p_offset; /* file offset */ - unsigned int p_vaddr; /* virtual address */ - unsigned int p_paddr; /* physical address (reserved, 0) */ - unsigned int p_filesz; /* file size of segment (may be 0) */ - unsigned int p_memsz; /* memory size of segment (may be 0) */ - unsigned int p_flags; /* flags */ - unsigned int p_align; /* memory & file alignment */ + unsigned int p_type; /* entry type */ + unsigned int p_offset; /* file offset */ + unsigned int p_vaddr; /* virtual address */ + unsigned int p_paddr; /* physical address (reserved, 0) */ + unsigned int p_filesz; /* file size of segment (may be 0) */ + unsigned int p_memsz; /* memory size of segment (may be 0) */ + unsigned int p_flags; /* flags */ + unsigned int p_align; /* memory & file alignment */ }; /* p_type */ -#define PT_NULL 0 /* Program header table entry unused */ -#define PT_LOAD 1 /* Loadable program segment */ -#define PT_DYNAMIC 2 /* Dynamic linking information */ -#define PT_INTERP 3 /* Program interpreter */ -#define PT_NOTE 4 /* Auxiliary information */ -#define PT_SHLIB 5 /* Reserved, unspecified semantics */ -#define PT_PHDR 6 /* Entry for header table itself */ -#define PT_NUM 7 -#define PT_LOPROC 0x70000000 /* Start of processor-specific semantics */ -#define PT_HIPROC 0x7fffffff /* end of processor-specific semantics */ -#define PT_GNU_STACK /* GNU stack extension */ +#define PT_NULL 0 /* Program header table entry unused */ +#define PT_LOAD 1 /* Loadable program segment */ +#define PT_DYNAMIC 2 /* Dynamic linking information */ +#define PT_INTERP 3 /* Program interpreter */ +#define PT_NOTE 4 /* Auxiliary information */ +#define PT_SHLIB 5 /* Reserved, unspecified semantics */ +#define PT_PHDR 6 /* Entry for header table itself */ +#define PT_NUM 7 +#define PT_LOPROC 0x70000000 /* Start of processor-specific semantics */ +#define PT_HIPROC 0x7fffffff /* end of processor-specific semantics */ +#define PT_GNU_STACK /* GNU stack extension */ /* p_flags */ -#define PF_R 0x4 /* Segment is readable */ -#define PF_W 0x2 /* Segment is writable */ -#define PF_X 0x1 /* Segment is executable */ +#define PF_R 0x4 /* Segment is readable */ +#define PF_W 0x2 /* Segment is writable */ +#define PF_X 0x1 /* Segment is executable */ /* A text segment commonly have PF_X|PF_R, a data segment PF_X|PF_W and PF_R */ -#define PF_MASKOS 0x0ff00000 /* Opersting system specific values */ -#define PF_MASKPROC 0xf0000000 /* Processor-specific values */ +#define PF_MASKOS 0x0ff00000 /* Opersting system specific values */ +#define PF_MASKPROC 0xf0000000 /* Processor-specific values */ -#define PT_MIPS_REGINFO 0x70000000 +#define PT_MIPS_REGINFO 0x70000000 /* * Section Headers */ struct elf_shdr { - unsigned int sh_name; /* section name (.shstrtab index) */ - unsigned int sh_type; /* section type */ - unsigned int sh_flags; /* section flags */ - unsigned int sh_addr; /* virtual address */ - unsigned int sh_offset; /* file offset */ - unsigned int sh_size; /* section size */ - unsigned int sh_link; /* link to another */ - unsigned int sh_info; /* misc info */ - unsigned int sh_addralign; /* memory alignment */ - unsigned int sh_entsize; /* table entry size */ + unsigned int sh_name; /* section name (.shstrtab index) */ + unsigned int sh_type; /* section type */ + unsigned int sh_flags; /* section flags */ + unsigned int sh_addr; /* virtual address */ + unsigned int sh_offset; /* file offset */ + unsigned int sh_size; /* section size */ + unsigned int sh_link; /* link to another */ + unsigned int sh_info; /* misc info */ + unsigned int sh_addralign; /* memory alignment */ + unsigned int sh_entsize; /* table entry size */ }; /* sh_type */ -#define SHT_NULL 0 /* inactive */ -#define SHT_PROGBITS 1 /* program defined contents */ -#define SHT_SYMTAB 2 /* holds symbol table */ -#define SHT_STRTAB 3 /* holds string table */ -#define SHT_RELA 4 /* holds relocation info with explicit addends */ -#define SHT_HASH 5 /* holds symbol hash table */ -#define SHT_DYNAMIC 6 /* holds dynamic linking information */ -#define SHT_NOTE 7 /* holds information marking */ -#define SHT_NOBITS 8 /* holds a section that does not occupy space */ -#define SHT_REL 9 /* holds relocation info without explicit addends */ -#define SHT_SHLIB 10 /* reserved with unspecified semantics */ -#define SHT_DYNSYM 11 /* holds a minimal set of dynamic linking symbols */ -#define SHT_NUM 12 +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined contents */ +#define SHT_SYMTAB 2 /* holds symbol table */ +#define SHT_STRTAB 3 /* holds string table */ +#define SHT_RELA 4 /* holds relocation info with explicit addends */ +#define SHT_HASH 5 /* holds symbol hash table */ +#define SHT_DYNAMIC 6 /* holds dynamic linking information */ +#define SHT_NOTE 7 /* holds information marking */ +#define SHT_NOBITS 8 /* holds a section that does not occupy space */ +#define SHT_REL 9 /* holds relocation info without explicit addends */ +#define SHT_SHLIB 10 /* reserved with unspecified semantics */ +#define SHT_DYNSYM 11 /* holds a minimal set of dynamic linking symbols */ +#define SHT_NUM 12 -#define SHT_LOOS 0x60000000 /* Operating system specific range */ -#define SHT_HIOS 0x6fffffff -#define SHT_LOPROC 0x70000000 /* Processor-specific range */ -#define SHT_HIPROC 0x7fffffff -#define SHT_LOUSER 0x80000000 /* Application-specific range */ -#define SHT_HIUSER 0xffffffff +#define SHT_LOOS 0x60000000 /* Operating system specific range */ +#define SHT_HIOS 0x6fffffff +#define SHT_LOPROC 0x70000000 /* Processor-specific range */ +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 /* Application-specific range */ +#define SHT_HIUSER 0xffffffff /* sh_flags */ -#define SHF_WRITE 0x1 /* Section contains writable data */ -#define SHF_ALLOC 0x2 /* Section occupies memory */ -#define SHF_EXECINSTR 0x4 /* Section contains executable insns */ +#define SHF_WRITE 0x1 /* Section contains writable data */ +#define SHF_ALLOC 0x2 /* Section occupies memory */ +#define SHF_EXECINSTR 0x4 /* Section contains executable insns */ -#define SHF_MASKOS 0x0f000000 /* Operating system specific values */ -#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */ +#define SHF_MASKOS 0x0f000000 /* Operating system specific values */ +#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */ /* * Symbol Table */ struct elf_sym { - unsigned int st_name; /* Symbol name (.symtab index) */ - unsigned int st_value; /* value of symbol */ - unsigned int st_size; /* size of symbol */ - unsigned char st_info; /* type / binding attrs */ - unsigned char st_other; /* unused */ - unsigned short st_shndx; /* section index of symbol */ + unsigned int st_name; /* Symbol name (.symtab index) */ + unsigned int st_value; /* value of symbol */ + unsigned int st_size; /* size of symbol */ + unsigned char st_info; /* type / binding attrs */ + unsigned char st_other; /* unused */ + unsigned short st_shndx; /* section index of symbol */ }; /* Symbol Table index of the undefined symbol */ -#define ELF_SYM_UNDEFINED 0 +#define ELF_SYM_UNDEFINED 0 /* st_info: Symbol Bindings */ -#define STB_LOCAL 0 /* local symbol */ -#define STB_GLOBAL 1 /* global symbol */ -#define STB_WEAK 2 /* weakly defined global symbol */ -#define STB_NUM 3 +#define STB_LOCAL 0 /* local symbol */ +#define STB_GLOBAL 1 /* global symbol */ +#define STB_WEAK 2 /* weakly defined global symbol */ +#define STB_NUM 3 -#define STB_LOOS 10 /* Operating system specific range */ -#define STB_HIOS 12 -#define STB_LOPROC 13 /* Processor-specific range */ -#define STB_HIPROC 15 +#define STB_LOOS 10 /* Operating system specific range */ +#define STB_HIOS 12 +#define STB_LOPROC 13 /* Processor-specific range */ +#define STB_HIPROC 15 /* st_info: Symbol Types */ -#define STT_NOTYPE 0 /* Type not specified */ -#define STT_OBJECT 1 /* Associated with a data object */ -#define STT_FUNC 2 /* Associated with a function */ -#define STT_SECTION 3 /* Associated with a section */ -#define STT_FILE 4 /* Associated with a file name */ -#define STT_NUM 5 +#define STT_NOTYPE 0 /* Type not specified */ +#define STT_OBJECT 1 /* Associated with a data object */ +#define STT_FUNC 2 /* Associated with a function */ +#define STT_SECTION 3 /* Associated with a section */ +#define STT_FILE 4 /* Associated with a file name */ +#define STT_NUM 5 -#define STT_LOOS 10 /* Operating system specific range */ -#define STT_HIOS 12 -#define STT_LOPROC 13 /* Processor-specific range */ -#define STT_HIPROC 15 +#define STT_LOOS 10 /* Operating system specific range */ +#define STT_HIOS 12 +#define STT_LOPROC 13 /* Processor-specific range */ +#define STT_HIPROC 15 /* st_info utility macros */ -#define ELF_ST_BIND(info) ((unsigned int)(info) >> 4) -#define ELF_ST_TYPE(info) ((unsigned int)(info) & 0xf) -#define ELF_ST_INFO(bind,type) ((unsigned char)(((bind) << 4) | ((type) & 0xf))) +#define ELF_ST_BIND(info) ((unsigned int)(info) >> 4) +#define ELF_ST_TYPE(info) ((unsigned int)(info) & 0xf) +#define ELF_ST_INFO(bind,type) ((unsigned char)(((bind) << 4) | ((type) & 0xf))) /* * Special section indexes */ -#define SHN_UNDEF 0 /* Undefined section */ +#define SHN_UNDEF 0 /* Undefined section */ -#define SHN_LORESERVE 0xff00 /* Start of Reserved range */ -#define SHN_ABS 0xfff1 /* Absolute symbols */ -#define SHN_COMMON 0xfff2 /* Common symbols */ -#define SHN_HIRESERVE 0xffff +#define SHN_LORESERVE 0xff00 /* Start of Reserved range */ +#define SHN_ABS 0xfff1 /* Absolute symbols */ +#define SHN_COMMON 0xfff2 /* Common symbols */ +#define SHN_HIRESERVE 0xffff -#define SHN_LOPROC 0xff00 /* Start of Processor-specific range */ -#define SHN_HIPROC 0xff1f -#define SHN_LOOS 0xff20 /* Operating system specific range */ -#define SHN_HIOS 0xff3f +#define SHN_LOPROC 0xff00 /* Start of Processor-specific range */ +#define SHN_HIPROC 0xff1f +#define SHN_LOOS 0xff20 /* Operating system specific range */ +#define SHN_HIOS 0xff3f -#define SHN_MIPS_ACOMMON 0xff00 -#define SHN_MIPS_TEXT 0xff01 -#define SHN_MIPS_DATA 0xff02 -#define SHN_MIPS_SCOMMON 0xff03 +#define SHN_MIPS_ACOMMON 0xff00 +#define SHN_MIPS_TEXT 0xff01 +#define SHN_MIPS_DATA 0xff02 +#define SHN_MIPS_SCOMMON 0xff03 /* * Relocation Entries */ struct elf_rel { - unsigned int r_offset; /* where to do it */ - unsigned int r_info; /* index & type of relocation */ + unsigned int r_offset; /* where to do it */ + unsigned int r_info; /* index & type of relocation */ }; struct elf_rela { - unsigned int r_offset; /* where to do it */ - unsigned int r_info; /* index & type of relocation */ - int r_addend; /* adjustment value */ + unsigned int r_offset; /* where to do it */ + unsigned int r_info; /* index & type of relocation */ + int r_addend; /* adjustment value */ }; /* r_info utility macros */ -#define ELF_R_SYM(info) ((info) >> 8) -#define ELF_R_TYPE(info) ((info) & 0xff) -#define ELF_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) +#define ELF_R_SYM(info) ((info) >> 8) +#define ELF_R_TYPE(info) ((info) & 0xff) +#define ELF_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) /* * Dynamic Section structure array */ struct elf_dyn { - unsigned int d_tag; /* entry tag value */ - union { - unsigned int d_ptr; - unsigned int d_val; - } d_un; + unsigned int d_tag; /* entry tag value */ + union { + unsigned int d_ptr; + unsigned int d_val; + } d_un; }; /* d_tag */ -#define DT_NULL 0 /* Marks end of dynamic array */ -#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */ -#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */ -#define DT_PLTGOT 3 /* Address of PLT and/or GOT */ -#define DT_HASH 4 /* Address of symbol hash table */ -#define DT_STRTAB 5 /* Address of string table */ -#define DT_SYMTAB 6 /* Address of symbol table */ -#define DT_RELA 7 /* Address of Rela relocation table */ -#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */ -#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */ -#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */ -#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */ -#define DT_INIT 12 /* Address of initialization function */ -#define DT_FINI 13 /* Address of termination function */ -#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */ -#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */ -#define DT_SYMBOLIC 16 /* Start symbol search within local object */ -#define DT_REL 17 /* Address of Rel relocation table */ -#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */ -#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */ -#define DT_PLTREL 20 /* Type of PLT relocation entries */ -#define DT_DEBUG 21 /* Used for debugging; unspecified */ -#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */ -#define DT_JMPREL 23 /* Address of relocations associated with PLT */ -#define DT_BIND_NOW 24 /* Process all relocations at load-time */ -#define DT_INIT_ARRAY 25 /* Address of initialization function array */ -#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */ -#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */ -#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/ -#define DT_NUM 29 +#define DT_NULL 0 /* Marks end of dynamic array */ +#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */ +#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */ +#define DT_PLTGOT 3 /* Address of PLT and/or GOT */ +#define DT_HASH 4 /* Address of symbol hash table */ +#define DT_STRTAB 5 /* Address of string table */ +#define DT_SYMTAB 6 /* Address of symbol table */ +#define DT_RELA 7 /* Address of Rela relocation table */ +#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */ +#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */ +#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */ +#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */ +#define DT_INIT 12 /* Address of initialization function */ +#define DT_FINI 13 /* Address of termination function */ +#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */ +#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */ +#define DT_SYMBOLIC 16 /* Start symbol search within local object */ +#define DT_REL 17 /* Address of Rel relocation table */ +#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */ +#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */ +#define DT_PLTREL 20 /* Type of PLT relocation entries */ +#define DT_DEBUG 21 /* Used for debugging; unspecified */ +#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */ +#define DT_JMPREL 23 /* Address of relocations associated with PLT */ +#define DT_BIND_NOW 24 /* Process all relocations at load-time */ +#define DT_INIT_ARRAY 25 /* Address of initialization function array */ +#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */ +#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */ +#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/ +#define DT_NUM 29 -#define DT_LOOS 0x60000000 /* Operating system specific range */ -#define DT_HIOS 0x6fffffff -#define DT_LOPROC 0x70000000 /* Processor-specific range */ -#define DT_HIPROC 0x7fffffff +#define DT_LOOS 0x60000000 /* Operating system specific range */ +#define DT_HIOS 0x6fffffff +#define DT_LOPROC 0x70000000 /* Processor-specific range */ +#define DT_HIPROC 0x7fffffff /* * Auxiliary Vectors */ struct elf_auxinfo { - unsigned int a_type; /* 32-bit id */ - unsigned int a_v; /* 32-bit id */ + unsigned int a_type; /* 32-bit id */ + unsigned int a_v; /* 32-bit id */ }; /* a_type */ -#define AT_NULL 0 /* Marks end of array */ -#define AT_IGNORE 1 /* No meaning, a_un is undefined */ -#define AT_EXECFD 2 /* Open file descriptor of object file */ -#define AT_PHDR 3 /* &phdr[0] */ -#define AT_PHENT 4 /* sizeof(phdr[0]) */ -#define AT_PHNUM 5 /* # phdr entries */ -#define AT_PAGESZ 6 /* PAGESIZE */ -#define AT_BASE 7 /* Interpreter base addr */ -#define AT_FLAGS 8 /* Processor flags */ -#define AT_ENTRY 9 /* Entry address of executable */ -#define AT_DCACHEBSIZE 10 /* Data cache block size */ -#define AT_ICACHEBSIZE 11 /* Instruction cache block size */ -#define AT_UCACHEBSIZE 12 /* Unified cache block size */ +#define AT_NULL 0 /* Marks end of array */ +#define AT_IGNORE 1 /* No meaning, a_un is undefined */ +#define AT_EXECFD 2 /* Open file descriptor of object file */ +#define AT_PHDR 3 /* &phdr[0] */ +#define AT_PHENT 4 /* sizeof(phdr[0]) */ +#define AT_PHNUM 5 /* # phdr entries */ +#define AT_PAGESZ 6 /* PAGESIZE */ +#define AT_BASE 7 /* Interpreter base addr */ +#define AT_FLAGS 8 /* Processor flags */ +#define AT_ENTRY 9 /* Entry address of executable */ +#define AT_DCACHEBSIZE 10 /* Data cache block size */ +#define AT_ICACHEBSIZE 11 /* Instruction cache block size */ +#define AT_UCACHEBSIZE 12 /* Unified cache block size */ - /* Vendor specific */ -#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */ + /* Vendor specific */ +#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */ -#define AT_SUN_UID 2000 /* euid */ -#define AT_SUN_RUID 2001 /* ruid */ -#define AT_SUN_GID 2002 /* egid */ -#define AT_SUN_RGID 2003 /* rgid */ +#define AT_SUN_UID 2000 /* euid */ +#define AT_SUN_RUID 2001 /* ruid */ +#define AT_SUN_GID 2002 /* egid */ +#define AT_SUN_RGID 2003 /* rgid */ - /* Solaris kernel specific */ -#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */ -#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */ -#define AT_SUN_LDNAME 2006 /* dynamic linker's name */ -#define AT_SUN_LPGSIZE 2007 /* large pagesize */ + /* Solaris kernel specific */ +#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */ +#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */ +#define AT_SUN_LDNAME 2006 /* dynamic linker's name */ +#define AT_SUN_LPGSIZE 2007 /* large pagesize */ - /* Other information */ -#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */ -#define AT_SUN_HWCAP 2009 /* process hardware capabilities */ -#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */ -#define AT_SUN_CPU 2011 /* cpu name */ - /* ibcs2 emulation band aid */ -#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */ -#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */ - /* Executable's fully resolved name */ -#define AT_SUN_EXECNAME 2014 + /* Other information */ +#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */ +#define AT_SUN_HWCAP 2009 /* process hardware capabilities */ +#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */ +#define AT_SUN_CPU 2011 /* cpu name */ + /* ibcs2 emulation band aid */ +#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */ +#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */ + /* Executable's fully resolved name */ +#define AT_SUN_EXECNAME 2014 /* * Note Headers */ struct elf_nhdr { - unsigned int n_namesz; - unsigned int n_descsz; - unsigned int n_type; + unsigned int n_namesz; + unsigned int n_descsz; + unsigned int n_type; }; -#define ELF_NOTE_TYPE_OSVERSION 1 +#define ELF_NOTE_TYPE_OSVERSION 1 /* NetBSD-specific note type: Emulation name. desc is emul name string. */ -#define ELF_NOTE_NETBSD_TYPE_EMULNAME 2 +#define ELF_NOTE_NETBSD_TYPE_EMULNAME 2 /* NetBSD-specific note name and description sizes */ -#define ELF_NOTE_NETBSD_NAMESZ 7 -#define ELF_NOTE_NETBSD_DESCSZ 4 +#define ELF_NOTE_NETBSD_NAMESZ 7 +#define ELF_NOTE_NETBSD_DESCSZ 4 /* NetBSD-specific note name */ -#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0" +#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0" /* GNU-specific note name and description sizes */ -#define ELF_NOTE_GNU_NAMESZ 4 -#define ELF_NOTE_GNU_DESCSZ 4 +#define ELF_NOTE_GNU_NAMESZ 4 +#define ELF_NOTE_GNU_DESCSZ 4 /* GNU-specific note name */ -#define ELF_NOTE_GNU_NAME "GNU\0" +#define ELF_NOTE_GNU_NAME "GNU\0" /* GNU-specific OS/version value stuff */ -#define ELF_NOTE_GNU_OSMASK (unsigned int)0xff000000 -#define ELF_NOTE_GNU_OSLINUX (unsigned int)0x01000000 -#define ELF_NOTE_GNU_OSMACH (unsigned int)0x00000000 - -//#define CONCAT(x,y) __CONCAT(x,y) - +#define ELF_NOTE_GNU_OSMASK (unsigned int)0xff000000 +#define ELF_NOTE_GNU_OSLINUX (unsigned int)0x01000000 +#define ELF_NOTE_GNU_OSMACH (unsigned int)0x00000000 #include - #ifdef _KERNEL -#define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */ +#define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */ struct elf_args { - unsigned int arg_entry; /* program entry point */ - unsigned int arg_interp; /* Interpreter load address */ - unsigned int arg_phaddr; /* program header address */ - unsigned int arg_phentsize; /* Size of program header */ - unsigned int arg_phnum; /* Number of program headers */ + unsigned int arg_entry; /* program entry point */ + unsigned int arg_interp; /* Interpreter load address */ + unsigned int arg_phaddr; /* program header address */ + unsigned int arg_phentsize; /* Size of program header */ + unsigned int arg_phnum; /* Number of program headers */ }; #ifndef _LKM @@ -481,15 +477,15 @@ struct elf_args { #endif #ifdef EXEC_ELF -int exec_elf_makecmds __P((struct proc *, struct exec_package *)); -int elf_read_from __P((struct proc *, struct vnode *, u_long, - caddr_t, int)); -void *elf_copyargs __P((struct exec_package *, struct ps_strings *, - void *, void *)); +int exec_elf_makecmds __P((struct proc *, struct exec_package *)); +int elf_read_from __P((struct proc *, struct vnode *, u_long, + caddr_t, int)); +void *elf_copyargs __P((struct exec_package *, struct ps_strings *, + void *, void *)); #endif /* common */ -int exec_elf_setup_stack __P((struct proc *, struct exec_package *)); +int exec_elf_setup_stack __P((struct proc *, struct exec_package *)); #endif /* _KERNEL */ diff --git a/sys/include/fcntl.h b/sys/include/fcntl.h index b66ec7c..2de442d 100644 --- a/sys/include/fcntl.h +++ b/sys/include/fcntl.h @@ -1,6 +1,6 @@ /*- * Copyright (c) 1983, 1990, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -35,7 +35,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)fcntl.h 8.3.1 (2.11BSD GTE) 11/25/94 + * @(#)fcntl.h 8.3.1 (2.11BSD GTE) 11/25/94 * * Copied from 4.4-Lite and modified for 2.11BSD. The modifications consisted * of removing: function prototypes (I don't like them, the compiler does not @@ -46,7 +46,7 @@ */ #ifndef _FCNTL_H_ -#define _FCNTL_H_ +#define _FCNTL_H_ /* * This file includes the definitions for open and fcntl @@ -66,10 +66,10 @@ * Open/fcntl flags begin with O_; kernel-internal flags begin with F. */ /* open-only flags */ -#define O_RDONLY 0x0000 /* open for reading only */ -#define O_WRONLY 0x0001 /* open for writing only */ -#define O_RDWR 0x0002 /* open for reading and writing */ -#define O_ACCMODE 0x0003 /* mask for above modes */ +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ /* * Kernel encoding of open mode; separate read and write bits that are @@ -79,35 +79,35 @@ * FREAD and FWRITE are excluded from the #ifdef KERNEL so that TIOCFLUSH, * which was documented to use FREAD/FWRITE, continues to work. */ -#define FREAD 0x0001 -#define FWRITE 0x0002 -#define O_NONBLOCK 0x0004 /* no delay */ -#define O_APPEND 0x0008 /* set append mode */ -#define O_SHLOCK 0x0010 /* open with shared file lock */ -#define O_EXLOCK 0x0020 /* open with exclusive file lock */ -#define O_ASYNC 0x0040 /* signal pgrp when data ready */ -#define O_FSYNC 0x0080 /* synchronous writes */ -#define O_CREAT 0x0200 /* create if nonexistant */ -#define O_TRUNC 0x0400 /* truncate to zero length */ -#define O_EXCL 0x0800 /* error if already exists */ +#define FREAD 0x0001 +#define FWRITE 0x0002 +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* synchronous writes */ +#define O_CREAT 0x0200 /* create if nonexistant */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ #ifdef KERNEL -#define FMARK 0x1000 /* mark during gc() */ -#define FDEFER 0x2000 /* defer for next gc pass */ +#define FMARK 0x1000 /* mark during gc() */ +#define FDEFER 0x2000 /* defer for next gc pass */ #endif /* defined by POSIX 1003.1; not 2.11BSD default, so bit is required */ /* Not currently implemented but it may be placed on the TODO list shortly */ -#define O_NOCTTY 0x4000 /* don't assign controlling terminal */ +#define O_NOCTTY 0x4000 /* don't assign controlling terminal */ #ifdef KERNEL /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ -#define FFLAGS(oflags) ((oflags) + 1) -#define OFLAGS(fflags) ((fflags) - 1) +#define FFLAGS(oflags) ((oflags) + 1) +#define OFLAGS(fflags) ((fflags) - 1) /* bits to save after open */ -#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK) +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK) /* bits settable by fcntl(F_SETFL, ...) */ -#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK) +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK) #endif /* @@ -115,35 +115,35 @@ * and by fcntl. We retain the F* names for the kernel f_flags field * and for backward compatibility for fcntl. */ -#define FAPPEND O_APPEND /* kernel/compat */ -#define FASYNC O_ASYNC /* kernel/compat */ -#define FFSYNC O_FSYNC /* kernel */ -#define FEXLOCK O_EXLOCK /* kernel */ -#define FSHLOCK O_SHLOCK /* kernel */ -#define FNONBLOCK O_NONBLOCK /* kernel */ -#define FNDELAY O_NONBLOCK /* compat */ -#define O_NDELAY O_NONBLOCK /* compat */ +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_FSYNC /* kernel */ +#define FEXLOCK O_EXLOCK /* kernel */ +#define FSHLOCK O_SHLOCK /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ /* * Constants used for fcntl(2) */ /* command values */ -#define F_DUPFD 0 /* duplicate file descriptor */ -#define F_GETFD 1 /* get file descriptor flags */ -#define F_SETFD 2 /* set file descriptor flags */ -#define F_GETFL 3 /* get file status flags */ -#define F_SETFL 4 /* set file status flags */ -#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ -#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ /* file descriptor flags (F_GETFD, F_SETFD) */ -#define FD_CLOEXEC 1 /* close-on-exec flag */ +#define FD_CLOEXEC 1 /* close-on-exec flag */ /* lock operations for flock(2) */ -#define LOCK_SH 0x01 /* shared file lock */ -#define LOCK_EX 0x02 /* exclusive file lock */ -#define LOCK_NB 0x04 /* don't block when locking */ -#define LOCK_UN 0x08 /* unlock file */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ #endif /* !_FCNTL_H_ */ diff --git a/sys/include/file.h b/sys/include/file.h index faaf052..515b274 100644 --- a/sys/include/file.h +++ b/sys/include/file.h @@ -5,37 +5,37 @@ */ #include -#ifndef _SYS_FILE_H_ -#define _SYS_FILE_H_ +#ifndef _SYS_FILE_H_ +#define _SYS_FILE_H_ /* * Descriptor table entry. * One for each kernel object. */ -struct file { - int f_flag; /* see below */ - int f_type; /* descriptor type */ - u_int f_count; /* reference count */ - int f_msgcount; /* references from message queue */ - union { - caddr_t f_Data; - struct socket *f_Socket; - } f_un; - off_t f_offset; +struct file { + int f_flag; /* see below */ + int f_type; /* descriptor type */ + u_int f_count; /* reference count */ + int f_msgcount; /* references from message queue */ + union { + caddr_t f_Data; + struct socket *f_Socket; + } f_un; + off_t f_offset; }; #ifdef KERNEL struct uio; -struct fileops { - int (*fo_rw) (struct file *fp, struct uio *uio); - int (*fo_ioctl) (struct file *fp, u_int com, char *data); - int (*fo_select) (struct file *fp, int flag); - int (*fo_close) (struct file *fp); +struct fileops { + int (*fo_rw) (struct file *fp, struct uio *uio); + int (*fo_ioctl) (struct file *fp, u_int com, char *data); + int (*fo_select) (struct file *fp, int flag); + int (*fo_close) (struct file *fp); }; -#define f_data f_un.f_Data -#define f_socket f_un.f_Socket +#define f_data f_un.f_Data +#define f_socket f_un.f_Socket extern struct file file[]; extern const struct fileops *const Fops[]; @@ -94,27 +94,27 @@ int flock(int fd, int operation); /* * Access call. */ -#define F_OK 0 /* does file exist */ -#define X_OK 1 /* is it executable by caller */ -#define W_OK 2 /* writable by caller */ -#define R_OK 4 /* readable by caller */ +#define F_OK 0 /* does file exist */ +#define X_OK 1 /* is it executable by caller */ +#define W_OK 2 /* writable by caller */ +#define R_OK 4 /* readable by caller */ /* * Lseek call. */ -#define L_SET 0 /* absolute offset */ -#define L_INCR 1 /* relative to current offset */ -#define L_XTND 2 /* relative to end of file */ +#define L_SET 0 /* absolute offset */ +#define L_INCR 1 /* relative to current offset */ +#define L_XTND 2 /* relative to end of file */ #ifdef KERNEL -#define GETF(fp, fd) { \ - if ((unsigned)(fd) >= NOFILE || ((fp) = u.u_ofile[fd]) == NULL) { \ - u.u_error = EBADF; \ - return; \ - } \ +#define GETF(fp, fd) { \ + if ((unsigned)(fd) >= NOFILE || ((fp) = u.u_ofile[fd]) == NULL) { \ + u.u_error = EBADF; \ + return; \ + } \ } -#define DTYPE_INODE 1 /* file */ -#define DTYPE_SOCKET 2 /* communications endpoint */ -#define DTYPE_PIPE 3 /* I don't want to hear it, okay? */ +#define DTYPE_INODE 1 /* file */ +#define DTYPE_SOCKET 2 /* communications endpoint */ +#define DTYPE_PIPE 3 /* I don't want to hear it, okay? */ #endif -#endif /* _SYS_FILE_H_ */ +#endif /* _SYS_FILE_H_ */ diff --git a/sys/include/fonts/vga.h b/sys/include/fonts/vga.h index afa0a10..7566806 100644 --- a/sys/include/fonts/vga.h +++ b/sys/include/fonts/vga.h @@ -7,7 +7,7 @@ static const unsigned char vga[] = { 1, // bpp // 32 $20 'space' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -26,7 +26,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 33 $21 'exclam' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -45,7 +45,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 34 $22 'quotedbl' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b01100110, @@ -64,7 +64,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 35 $23 'numbersign' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -83,7 +83,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 36 $24 'dollar' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00011000, 0b00011000, @@ -102,7 +102,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 37 $25 'percent' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -121,7 +121,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 38 $26 'ampersand' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -140,7 +140,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 39 $27 'quotesingle' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00001100, @@ -159,7 +159,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 40 $28 'parenleft' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -178,7 +178,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 41 $29 'parenright' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -197,7 +197,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 42 $2a 'asterisk' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -216,7 +216,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 43 $2b 'plus' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -235,7 +235,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 44 $2c 'comma' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -254,7 +254,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 45 $2d 'hyphen' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -273,7 +273,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 46 $2e 'period' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -292,7 +292,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 47 $2f 'slash' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -311,7 +311,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 48 $30 'zero' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -330,7 +330,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 49 $31 'one' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -349,7 +349,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 50 $32 'two' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -368,7 +368,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 51 $33 'three' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -387,7 +387,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 52 $34 'four' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -406,7 +406,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 53 $35 'five' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -425,7 +425,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 54 $36 'six' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -444,7 +444,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 55 $37 'seven' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -463,7 +463,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 56 $38 'eight' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -482,7 +482,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 57 $39 'nine' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -501,7 +501,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 58 $3a 'colon' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -520,7 +520,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 59 $3b 'semicolon' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -539,7 +539,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 60 $3c 'less' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -558,7 +558,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 61 $3d 'equal' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -577,7 +577,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 62 $3e 'greater' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -596,7 +596,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 63 $3f 'question' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -615,7 +615,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 64 $40 'at' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -634,7 +634,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 65 $41 'A' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -653,7 +653,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 66 $42 'B' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -672,7 +672,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 67 $43 'C' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -691,7 +691,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 68 $44 'D' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -710,7 +710,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 69 $45 'E' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -729,7 +729,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 70 $46 'F' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -748,7 +748,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 71 $47 'G' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -767,7 +767,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 72 $48 'H' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -786,7 +786,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 73 $49 'I' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -805,7 +805,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 74 $4a 'J' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -824,7 +824,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 75 $4b 'K' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -843,7 +843,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 76 $4c 'L' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -862,7 +862,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 77 $4d 'M' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -881,7 +881,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 78 $4e 'N' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -900,7 +900,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 79 $4f 'O' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -919,7 +919,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 80 $50 'P' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -938,7 +938,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 81 $51 'Q' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -957,7 +957,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 82 $52 'R' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -976,7 +976,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 83 $53 'S' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -995,7 +995,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 84 $54 'T' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1014,7 +1014,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 85 $55 'U' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1033,7 +1033,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 86 $56 'V' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1052,7 +1052,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 87 $57 'W' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1071,7 +1071,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 88 $58 '1' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1090,7 +1090,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 89 $59 'Y' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1109,7 +1109,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 90 $5a 'Z' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1128,7 +1128,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 91 $5b 'bracketleft' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1147,7 +1147,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 92 $5c 'backslash' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1166,7 +1166,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 93 $5d 'bracketright' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1185,7 +1185,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 94 $5e 'asciicircum' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00001000, 0b00011100, @@ -1204,7 +1204,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 95 $5f 'underscore' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1223,7 +1223,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 96 $60 'grave' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00001100, 0b00001100, @@ -1242,7 +1242,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 97 $61 'a' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1261,7 +1261,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 98 $62 'b' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1280,7 +1280,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 99 $63 'c' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1299,7 +1299,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 100 $64 'd' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1318,7 +1318,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 101 $65 'e' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1337,7 +1337,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 102 $66 'f' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1356,7 +1356,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 103 $67 'g' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1375,7 +1375,7 @@ static const unsigned char vga[] = { 0b00011110, 0b00000000, // 104 $68 'h' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1394,7 +1394,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 105 $69 'i' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1413,7 +1413,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 106 $6a 'j' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1432,7 +1432,7 @@ static const unsigned char vga[] = { 0b00111100, 0b00000000, // 107 $6b 'k' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1451,7 +1451,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 108 $6c 'l' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1470,7 +1470,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 109 $6d 'm' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1489,7 +1489,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 110 $6e 'n' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1508,7 +1508,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 111 $6f 'o' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1527,7 +1527,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 112 $70 'p' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1546,7 +1546,7 @@ static const unsigned char vga[] = { 0b00001111, 0b00000000, // 113 $71 'q' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1565,7 +1565,7 @@ static const unsigned char vga[] = { 0b01111000, 0b00000000, // 114 $72 'r' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1584,7 +1584,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 115 $73 's' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1603,7 +1603,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 116 $74 't' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1622,7 +1622,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 117 $75 'u' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1641,7 +1641,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 118 $76 'v' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1660,7 +1660,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 119 $77 'w' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1679,7 +1679,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 120 $78 'x' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1698,7 +1698,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 121 $79 'y' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1717,7 +1717,7 @@ static const unsigned char vga[] = { 0b00011111, 0b00000000, // 122 $7a 'z' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1736,7 +1736,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 123 $7b 'braceleft' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1755,7 +1755,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 124 $7c 'bar' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1774,7 +1774,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 125 $7d 'braceright' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1793,7 +1793,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 126 $7e 'asciitilde' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, @@ -1812,7 +1812,7 @@ static const unsigned char vga[] = { 0b00000000, 0b00000000, // 127 $7f 'char127' -// width 8, bbx 0, bby -4, bbw 8, bbh 16 +// width 8, bbx 0, bby -4, bbw 8, bbh 16 8, 0b00000000, 0b00000000, diff --git a/sys/include/fs.h b/sys/include/fs.h index d634cbf..339d96d 100644 --- a/sys/include/fs.h +++ b/sys/include/fs.h @@ -3,8 +3,8 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#ifndef _SYS_FS_H_ -#define _SYS_FS_H_ +#ifndef _SYS_FS_H_ +#define _SYS_FS_H_ /* * The root inode is the root of the file system. @@ -16,104 +16,104 @@ * The lost+found directory is given the next available * inode when it is created by ``mkfs''. */ -#define SBSIZE DEV_BSIZE -#define SUPERB ((daddr_t)0) /* block number of the super block */ +#define SBSIZE DEV_BSIZE +#define SUPERB ((daddr_t)0) /* block number of the super block */ -#define ROOTINO ((ino_t)2) /* i number of all roots */ -#define LOSTFOUNDINO (ROOTINO + 1) +#define ROOTINO ((ino_t)2) /* i number of all roots */ +#define LOSTFOUNDINO (ROOTINO + 1) -#define NICINOD 32 /* number of superblock inodes */ -#define NICFREE 200 /* number of superblock free blocks */ +#define NICINOD 32 /* number of superblock inodes */ +#define NICFREE 200 /* number of superblock free blocks */ /* * The path name on which the file system is mounted is maintained * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in * the super block for this name. */ -#define MAXMNTLEN 28 +#define MAXMNTLEN 28 /* * Super block for a file system. NOTE: The 'fs_flock' and 'fs_ilock' * fields MUST be on an even byte boundary because they are used as sleep() * channels and odd values specify a network sleep(). */ -struct fs +struct fs { - u_int fs_magic1; /* magic word */ - u_int fs_isize; /* first block after i-list */ - u_int fs_fsize; /* size in blocks of entire volume */ - u_int fs_swapsz; /* size in blocks of swap area */ - int fs_nfree; /* number of addresses in fs_free */ - daddr_t fs_free [NICFREE]; /* free block list */ - int fs_ninode; /* number of inodes in fs_inode */ - ino_t fs_inode [NICINOD]; /* free inode list */ - int fs_flock; /* lock during free list manipulation */ - int fs_fmod; /* super block modified flag */ - int fs_ilock; /* lock during i-list manipulation */ - int fs_ronly; /* mounted read-only flag */ - time_t fs_time; /* last super block update */ - u_int fs_tfree; /* total free blocks */ - ino_t fs_tinode; /* total free inodes */ - char fs_fsmnt [MAXMNTLEN]; /* ordinary file mounted on */ - ino_t fs_lasti; /* start place for circular search */ - ino_t fs_nbehind; /* est # free inodes before s_lasti */ - u_int fs_flags; /* mount time flags */ - u_int fs_magic2; /* magic word */ + u_int fs_magic1; /* magic word */ + u_int fs_isize; /* first block after i-list */ + u_int fs_fsize; /* size in blocks of entire volume */ + u_int fs_swapsz; /* size in blocks of swap area */ + int fs_nfree; /* number of addresses in fs_free */ + daddr_t fs_free [NICFREE]; /* free block list */ + int fs_ninode; /* number of inodes in fs_inode */ + ino_t fs_inode [NICINOD]; /* free inode list */ + int fs_flock; /* lock during free list manipulation */ + int fs_fmod; /* super block modified flag */ + int fs_ilock; /* lock during i-list manipulation */ + int fs_ronly; /* mounted read-only flag */ + time_t fs_time; /* last super block update */ + u_int fs_tfree; /* total free blocks */ + ino_t fs_tinode; /* total free inodes */ + char fs_fsmnt [MAXMNTLEN]; /* ordinary file mounted on */ + ino_t fs_lasti; /* start place for circular search */ + ino_t fs_nbehind; /* est # free inodes before s_lasti */ + u_int fs_flags; /* mount time flags */ + u_int fs_magic2; /* magic word */ /* actually longer */ }; -struct fblk { - int df_nfree; /* number of addresses in df_free */ - daddr_t df_free [NICFREE]; /* free block list */ +struct fblk { + int df_nfree; /* number of addresses in df_free */ + daddr_t df_free [NICFREE]; /* free block list */ }; -#define FSMAGIC1 ('F' | 'S'<<8 | '<'<<16 | '<'<<24) -#define FSMAGIC2 ('>' | '>'<<8 | 'F'<<16 | 'S'<<24) +#define FSMAGIC1 ('F' | 'S'<<8 | '<'<<16 | '<'<<24) +#define FSMAGIC2 ('>' | '>'<<8 | 'F'<<16 | 'S'<<24) /* * Turn file system block numbers into disk block addresses. * This maps file system blocks to device size blocks. */ -#define fsbtodb(b) ((daddr_t) (b)) -#define dbtofsb(b) ((daddr_t) (b)) +#define fsbtodb(b) ((daddr_t) (b)) +#define dbtofsb(b) ((daddr_t) (b)) /* * Macros for handling inode numbers: * inode number to file system block offset. * inode number to file system block address. */ -#define itoo(x) ((int)(((x) + INOPB - 1) % INOPB)) -#define itod(x) ((daddr_t)((((u_int)(x) + INOPB - 1) / INOPB))) +#define itoo(x) ((int)(((x) + INOPB - 1) % INOPB)) +#define itod(x) ((daddr_t)((((u_int)(x) + INOPB - 1) / INOPB))) /* * The following macros optimize certain frequently calculated * quantities by using shifts and masks in place of divisions * modulos and multiplications. */ -#define blkoff(loc) /* calculates (loc % fs->fs_bsize) */ \ - ((loc) & DEV_BMASK) -#define lblkno(loc) /* calculates (loc / fs->fs_bsize) */ \ - ((unsigned) (loc) >> DEV_BSHIFT) +#define blkoff(loc) /* calculates (loc % fs->fs_bsize) */ \ + ((loc) & DEV_BMASK) +#define lblkno(loc) /* calculates (loc / fs->fs_bsize) */ \ + ((unsigned) (loc) >> DEV_BSHIFT) /* * Determine the number of available blocks given a * percentage to hold in reserve */ #define freespace(fs, percentreserved) \ - ((fs)->fs_tfree - ((fs)->fs_fsize - \ - (fs)->fs_isize) * (percentreserved) / 100) + ((fs)->fs_tfree - ((fs)->fs_fsize - \ + (fs)->fs_isize) * (percentreserved) / 100) /* * INOPB is the number of inodes in a secondary storage block. */ -#define INOPB 16 /* MAXBSIZE / sizeof(dinode) */ +#define INOPB 16 /* MAXBSIZE / sizeof(dinode) */ /* * NINDIR is the number of indirects in a file system block. */ -#define NINDIR (DEV_BSIZE / sizeof(daddr_t)) -#define NSHIFT 8 /* log2(NINDIR) */ -#define NMASK 0377L /* NINDIR - 1 */ +#define NINDIR (DEV_BSIZE / sizeof(daddr_t)) +#define NSHIFT 8 /* log2(NINDIR) */ +#define NMASK 0377L /* NINDIR - 1 */ /* * We continue to implement pipes within the file system because it would @@ -124,7 +124,7 @@ struct fblk { * bigger than 4096, pipes will be implemented with large files, which is * probably not good. */ -#define MAXPIPSIZ (NDADDR * MAXBSIZE) +#define MAXPIPSIZ (NDADDR * MAXBSIZE) #ifdef KERNEL struct inode; @@ -140,7 +140,7 @@ struct fs *getfs (dev_t dev); struct fs *mountfs (dev_t dev, int flags, struct inode *ip); void mount_updname (struct fs *fs, char *on, char *from, - int lenon, int lenfrom); + int lenon, int lenfrom); /* * Sync a single filesystem. diff --git a/sys/include/gpio.h b/sys/include/gpio.h index af3e83a..528c140 100644 --- a/sys/include/gpio.h +++ b/sys/include/gpio.h @@ -3,38 +3,38 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)gpio.h 1.4 (2.11BSD GTE) 1997/3/28 + * @(#)gpio.h 1.4 (2.11BSD GTE) 1997/3/28 */ /* * Ioctl definitions */ -#ifndef _GPIO_H +#ifndef _GPIO_H #define _GPIO_H #include #include /* control general-purpose i/o pins */ -#define GPIO_PORT(n) ((n) & 0xff) /* port number */ -#define GPIO_PORTA GPIO_PORT(0) -#define GPIO_PORTB GPIO_PORT(1) -#define GPIO_PORTC GPIO_PORT(2) -#define GPIO_PORTD GPIO_PORT(3) -#define GPIO_PORTE GPIO_PORT(4) -#define GPIO_PORTF GPIO_PORT(5) -#define GPIO_PORTG GPIO_PORT(6) -#define GPIO_COMMAND 0x1fff0000 /* command mask */ -#define GPIO_CONFIN (IOC_VOID | 1 << 16 | 'g'<<8) /* configure as input */ +#define GPIO_PORT(n) ((n) & 0xff) /* port number */ +#define GPIO_PORTA GPIO_PORT(0) +#define GPIO_PORTB GPIO_PORT(1) +#define GPIO_PORTC GPIO_PORT(2) +#define GPIO_PORTD GPIO_PORT(3) +#define GPIO_PORTE GPIO_PORT(4) +#define GPIO_PORTF GPIO_PORT(5) +#define GPIO_PORTG GPIO_PORT(6) +#define GPIO_COMMAND 0x1fff0000 /* command mask */ +#define GPIO_CONFIN (IOC_VOID | 1 << 16 | 'g'<<8) /* configure as input */ #define GPIO_CONFOUT (IOC_VOID | 1 << 17 | 'g'<<8) /* configure as output */ -#define GPIO_CONFOD (IOC_VOID | 1 << 18 | 'g'<<8) /* configure as open drain */ -#define GPIO_DECONF (IOC_VOID | 1 << 19 | 'g'<<8) /* deconfigure */ -#define GPIO_STORE (IOC_VOID | 1 << 20 | 'g'<<8) /* store all outputs */ -#define GPIO_SET (IOC_VOID | 1 << 21 | 'g'<<8) /* set to 1 by mask */ -#define GPIO_CLEAR (IOC_VOID | 1 << 22 | 'g'<<8) /* set to 0 by mask */ -#define GPIO_INVERT (IOC_VOID | 1 << 23 | 'g'<<8) /* invert by mask */ -#define GPIO_POLL (IOC_VOID | 1 << 24 | 'g'<<8) /* poll */ -#define GPIO_LOL (IOC_IN | 1 << 25 | 'g'<<8) /* display lol picture */ +#define GPIO_CONFOD (IOC_VOID | 1 << 18 | 'g'<<8) /* configure as open drain */ +#define GPIO_DECONF (IOC_VOID | 1 << 19 | 'g'<<8) /* deconfigure */ +#define GPIO_STORE (IOC_VOID | 1 << 20 | 'g'<<8) /* store all outputs */ +#define GPIO_SET (IOC_VOID | 1 << 21 | 'g'<<8) /* set to 1 by mask */ +#define GPIO_CLEAR (IOC_VOID | 1 << 22 | 'g'<<8) /* set to 0 by mask */ +#define GPIO_INVERT (IOC_VOID | 1 << 23 | 'g'<<8) /* invert by mask */ +#define GPIO_POLL (IOC_VOID | 1 << 24 | 'g'<<8) /* poll */ +#define GPIO_LOL (IOC_IN | 1 << 25 | 'g'<<8) /* display lol picture */ #ifdef KERNEL diff --git a/sys/include/hx8357.h b/sys/include/hx8357.h index 9562826..accb269 100644 --- a/sys/include/hx8357.h +++ b/sys/include/hx8357.h @@ -14,8 +14,6 @@ extern void hx8357_putc(dev_t dev, char c); extern char hx8357_getc(dev_t dev); extern void hx8357_init(); - extern struct tty hx8357_ttys[1]; - #endif diff --git a/sys/include/inode.h b/sys/include/inode.h index 0d03342..25fdc59 100644 --- a/sys/include/inode.h +++ b/sys/include/inode.h @@ -16,68 +16,68 @@ * 28 of the di_addr address bytes are used; 7 addresses of 4 * bytes each: 4 direct (4Kb directly accessible) and 3 indirect. */ -#define NDADDR 4 /* direct addresses in inode */ -#define NIADDR 3 /* indirect addresses in inode */ -#define NADDR (NDADDR + NIADDR) /* total addresses in inode */ +#define NDADDR 4 /* direct addresses in inode */ +#define NIADDR 3 /* indirect addresses in inode */ +#define NADDR (NDADDR + NIADDR) /* total addresses in inode */ struct icommon1 { - u_short ic_mode; /* mode and type of file */ - u_short ic_nlink; /* number of links to file */ - uid_t ic_uid; /* owner's user id */ - gid_t ic_gid; /* owner's group id */ - off_t ic_size; /* number of bytes in file */ + u_short ic_mode; /* mode and type of file */ + u_short ic_nlink; /* number of links to file */ + uid_t ic_uid; /* owner's user id */ + gid_t ic_gid; /* owner's group id */ + off_t ic_size; /* number of bytes in file */ }; struct icommon2 { - time_t ic_atime; /* time last accessed */ - time_t ic_mtime; /* time last modified */ - time_t ic_ctime; /* time created */ + time_t ic_atime; /* time last accessed */ + time_t ic_mtime; /* time last modified */ + time_t ic_ctime; /* time created */ }; struct inode { - struct inode *i_chain[2]; /* must be first */ - u_int i_flag; - u_int i_count; /* reference count */ - dev_t i_dev; /* device where inode resides */ - ino_t i_number; /* i number, 1-to-1 with device address */ - u_int i_id; /* unique identifier */ - struct fs *i_fs; /* file sys associated with this inode */ - union { - struct { - u_short I_shlockc; /* count of shared locks */ - u_short I_exlockc; /* count of exclusive locks */ - } i_l; - struct proc *I_rsel; /* pipe read select */ - } i_un0; - union { - struct proc *I_wsel; /* pipe write select */ - } i_un1; - union { - daddr_t I_addr[NADDR]; /* normal file/directory */ - struct { - daddr_t I_db[NDADDR]; /* normal file/directory */ - daddr_t I_ib[NIADDR]; - } i_f; - struct { - /* - * the dummy field is here so that the de/compression - * part of the iget/iput routines works for special - * files. - */ - u_int I_dummy; - dev_t I_rdev; /* dev type */ - } i_d; - } i_un2; - union { - daddr_t if_lastr; /* last read (read-ahead) */ - struct { - struct inode *if_freef; /* free list forward */ - struct inode **if_freeb; /* free list back */ - } i_fr; - } i_un3; - struct icommon1 i_ic1; - u_int i_flags; /* user changeable flags */ - struct icommon2 i_ic2; + struct inode *i_chain[2]; /* must be first */ + u_int i_flag; + u_int i_count; /* reference count */ + dev_t i_dev; /* device where inode resides */ + ino_t i_number; /* i number, 1-to-1 with device address */ + u_int i_id; /* unique identifier */ + struct fs *i_fs; /* file sys associated with this inode */ + union { + struct { + u_short I_shlockc; /* count of shared locks */ + u_short I_exlockc; /* count of exclusive locks */ + } i_l; + struct proc *I_rsel; /* pipe read select */ + } i_un0; + union { + struct proc *I_wsel; /* pipe write select */ + } i_un1; + union { + daddr_t I_addr[NADDR]; /* normal file/directory */ + struct { + daddr_t I_db[NDADDR]; /* normal file/directory */ + daddr_t I_ib[NIADDR]; + } i_f; + struct { + /* + * the dummy field is here so that the de/compression + * part of the iget/iput routines works for special + * files. + */ + u_int I_dummy; + dev_t I_rdev; /* dev type */ + } i_d; + } i_un2; + union { + daddr_t if_lastr; /* last read (read-ahead) */ + struct { + struct inode *if_freef; /* free list forward */ + struct inode **if_freeb; /* free list back */ + } i_fr; + } i_un3; + struct icommon1 i_ic1; + u_int i_flags; /* user changeable flags */ + struct icommon2 i_ic2; }; /* @@ -85,46 +85,46 @@ struct inode { * a disk block. */ struct dinode { - struct icommon1 di_icom1; - daddr_t di_addr[NADDR]; /* 7 block addresses 4 bytes each */ - u_int di_reserved[1]; /* pad of 4 to make total size 64 */ - u_int di_flags; - struct icommon2 di_icom2; + struct icommon1 di_icom1; + daddr_t di_addr[NADDR]; /* 7 block addresses 4 bytes each */ + u_int di_reserved[1]; /* pad of 4 to make total size 64 */ + u_int di_flags; + struct icommon2 di_icom2; }; -#define i_mode i_ic1.ic_mode -#define i_nlink i_ic1.ic_nlink -#define i_uid i_ic1.ic_uid -#define i_gid i_ic1.ic_gid -#define i_size i_ic1.ic_size -#define i_shlockc i_un0.i_l.I_shlockc -#define i_exlockc i_un0.i_l.I_exlockc -#define i_rsel i_un0.I_rsel -#define i_wsel i_un1.I_wsel -#define i_db i_un2.i_f.I_db -#define i_ib i_un2.i_f.I_ib -#define i_atime i_ic2.ic_atime -#define i_mtime i_ic2.ic_mtime -#define i_ctime i_ic2.ic_ctime -#define i_rdev i_un2.i_d.I_rdev -#define i_addr i_un2.I_addr -#define i_dummy i_un2.i_d.I_dummy -#define i_lastr i_un3.if_lastr -#define i_forw i_chain[0] -#define i_back i_chain[1] -#define i_freef i_un3.i_fr.if_freef -#define i_freeb i_un3.i_fr.if_freeb +#define i_mode i_ic1.ic_mode +#define i_nlink i_ic1.ic_nlink +#define i_uid i_ic1.ic_uid +#define i_gid i_ic1.ic_gid +#define i_size i_ic1.ic_size +#define i_shlockc i_un0.i_l.I_shlockc +#define i_exlockc i_un0.i_l.I_exlockc +#define i_rsel i_un0.I_rsel +#define i_wsel i_un1.I_wsel +#define i_db i_un2.i_f.I_db +#define i_ib i_un2.i_f.I_ib +#define i_atime i_ic2.ic_atime +#define i_mtime i_ic2.ic_mtime +#define i_ctime i_ic2.ic_ctime +#define i_rdev i_un2.i_d.I_rdev +#define i_addr i_un2.I_addr +#define i_dummy i_un2.i_d.I_dummy +#define i_lastr i_un3.if_lastr +#define i_forw i_chain[0] +#define i_back i_chain[1] +#define i_freef i_un3.i_fr.if_freef +#define i_freeb i_un3.i_fr.if_freeb -#define di_ic1 di_icom1 -#define di_ic2 di_icom2 -#define di_mode di_ic1.ic_mode -#define di_nlink di_ic1.ic_nlink -#define di_uid di_ic1.ic_uid -#define di_gid di_ic1.ic_gid -#define di_size di_ic1.ic_size -#define di_atime di_ic2.ic_atime -#define di_mtime di_ic2.ic_mtime -#define di_ctime di_ic2.ic_ctime +#define di_ic1 di_icom1 +#define di_ic2 di_icom2 +#define di_mode di_ic1.ic_mode +#define di_nlink di_ic1.ic_nlink +#define di_uid di_ic1.ic_uid +#define di_gid di_ic1.ic_gid +#define di_size di_ic1.ic_size +#define di_atime di_ic2.ic_atime +#define di_mtime di_ic2.ic_mtime +#define di_ctime di_ic2.ic_ctime #ifdef KERNEL struct stat; @@ -140,14 +140,14 @@ struct stat; void cinvalall (void); #define cacheinval(ip) \ - (ip)->i_id = ++nextinodeid; \ - if (nextinodeid == 0) \ - cinvalall(); + (ip)->i_id = ++nextinodeid; \ + if (nextinodeid == 0) \ + cinvalall(); -u_int nextinodeid; /* unique id generator */ +u_int nextinodeid; /* unique id generator */ -extern struct inode inode[]; /* the inode table itself */ -struct inode *rootdir; /* pointer to inode of root directory */ +extern struct inode inode[]; /* the inode table itself */ +struct inode *rootdir; /* pointer to inode of root directory */ /* * Initialize hash links for inodes and build inode free list. @@ -198,7 +198,7 @@ struct inode *namei (struct nameidata *ndp); enum uio_rw; int rdwri (enum uio_rw rw, struct inode *ip, caddr_t base, int len, - off_t offset, int ioflg, int *aresid); + off_t offset, int ioflg, int *aresid); struct uio; int rwip (struct inode *ip, struct uio *uio, int ioflag); @@ -239,7 +239,7 @@ void itrunc (struct inode *oip, u_long length, int ioflags); */ struct timeval; void iupdat (struct inode *ip, struct timeval *ta, struct timeval *tm, - int waitfor); + int waitfor); void irele (struct inode *ip); @@ -303,52 +303,52 @@ void nchinval (dev_t dev); #endif /* KERNEL */ /* i_flag */ -#define ILOCKED 0x1 /* inode is locked */ -#define IUPD 0x2 /* file has been modified */ -#define IACC 0x4 /* inode access time to be updated */ -#define IMOUNT 0x8 /* inode is mounted on */ -#define IWANT 0x10 /* some process waiting on lock */ -#define ITEXT 0x20 /* inode is pure text prototype */ -#define ICHG 0x40 /* inode has been changed */ -#define ISHLOCK 0x80 /* file has shared lock */ -#define IEXLOCK 0x100 /* file has exclusive lock */ -#define ILWAIT 0x200 /* someone waiting on file lock */ -#define IMOD 0x400 /* inode has been modified */ -#define IRENAME 0x800 /* inode is being renamed */ -#define IPIPE 0x1000 /* inode is a pipe */ -#define IRCOLL 0x2000 /* read select collision on pipe */ -#define IWCOLL 0x4000 /* write select collision on pipe */ -#define IXMOD 0x8000 /* inode is text, but impure (XXX) */ +#define ILOCKED 0x1 /* inode is locked */ +#define IUPD 0x2 /* file has been modified */ +#define IACC 0x4 /* inode access time to be updated */ +#define IMOUNT 0x8 /* inode is mounted on */ +#define IWANT 0x10 /* some process waiting on lock */ +#define ITEXT 0x20 /* inode is pure text prototype */ +#define ICHG 0x40 /* inode has been changed */ +#define ISHLOCK 0x80 /* file has shared lock */ +#define IEXLOCK 0x100 /* file has exclusive lock */ +#define ILWAIT 0x200 /* someone waiting on file lock */ +#define IMOD 0x400 /* inode has been modified */ +#define IRENAME 0x800 /* inode is being renamed */ +#define IPIPE 0x1000 /* inode is a pipe */ +#define IRCOLL 0x2000 /* read select collision on pipe */ +#define IWCOLL 0x4000 /* write select collision on pipe */ +#define IXMOD 0x8000 /* inode is text, but impure (XXX) */ /* i_mode */ -#define IFMT 0170000 /* type of file */ -#define IFCHR 0020000 /* character special */ -#define IFDIR 0040000 /* directory */ -#define IFBLK 0060000 /* block special */ -#define IFREG 0100000 /* regular */ -#define IFLNK 0120000 /* symbolic link */ -#define IFSOCK 0140000 /* socket */ -#define ISUID 04000 /* set user id on execution */ -#define ISGID 02000 /* set group id on execution */ -#define ISVTX 01000 /* save swapped text even after use */ -#define IREAD 0400 /* read, write, execute permissions */ -#define IWRITE 0200 -#define IEXEC 0100 +#define IFMT 0170000 /* type of file */ +#define IFCHR 0020000 /* character special */ +#define IFDIR 0040000 /* directory */ +#define IFBLK 0060000 /* block special */ +#define IFREG 0100000 /* regular */ +#define IFLNK 0120000 /* symbolic link */ +#define IFSOCK 0140000 /* socket */ +#define ISUID 04000 /* set user id on execution */ +#define ISGID 02000 /* set group id on execution */ +#define ISVTX 01000 /* save swapped text even after use */ +#define IREAD 0400 /* read, write, execute permissions */ +#define IWRITE 0200 +#define IEXEC 0100 #ifdef KERNEL /* * Flags for va_cflags. */ -#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ +#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ /* * Flags for ioflag. */ -#define IO_UNIT 0x01 /* do I/O as atomic unit */ -#define IO_APPEND 0x02 /* append write to end */ -#define IO_SYNC 0x04 /* do I/O synchronously */ -/*#define IO_NODELOCKED 0x08 not implemented */ -#define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ +#define IO_UNIT 0x01 /* do I/O as atomic unit */ +#define IO_APPEND 0x02 /* append write to end */ +#define IO_SYNC 0x04 /* do I/O synchronously */ +/*#define IO_NODELOCKED 0x08 not implemented */ +#define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ /* @@ -361,33 +361,33 @@ void nchinval (dev_t dev); * do not have vnodes why initialize (and carry around) un-used members. */ struct vattr { - mode_t va_mode; - uid_t va_uid; - gid_t va_gid; - off_t va_size; - time_t va_atime; - time_t va_mtime; - u_int va_flags; - u_int va_vaflags; + mode_t va_mode; + uid_t va_uid; + gid_t va_gid; + off_t va_size; + time_t va_atime; + time_t va_mtime; + u_int va_flags; + u_int va_vaflags; }; /* * Token indicating no attribute value yet assigned. */ -#define VNOVAL (-1) +#define VNOVAL (-1) /* * Initialize a inode attribute structure. */ -#define VATTR_NULL(vp) { \ - (vp)->va_mode = VNOVAL; \ - (vp)->va_uid = VNOVAL; \ - (vp)->va_gid = VNOVAL; \ - (vp)->va_size = VNOVAL; \ - (vp)->va_atime = VNOVAL; \ - (vp)->va_mtime = VNOVAL; \ - (vp)->va_flags = VNOVAL; \ - (vp)->va_vaflags = VNOVAL; } +#define VATTR_NULL(vp) { \ + (vp)->va_mode = VNOVAL; \ + (vp)->va_uid = VNOVAL; \ + (vp)->va_gid = VNOVAL; \ + (vp)->va_size = VNOVAL; \ + (vp)->va_atime = VNOVAL; \ + (vp)->va_mtime = VNOVAL; \ + (vp)->va_flags = VNOVAL; \ + (vp)->va_vaflags = VNOVAL; } /* * N.B: If the above structure changes be sure to modify the function @@ -395,36 +395,36 @@ struct vattr { */ #endif -#define ILOCK(ip) { \ - while ((ip)->i_flag & ILOCKED) { \ - (ip)->i_flag |= IWANT; \ - sleep((caddr_t)(ip), PINOD); \ - } \ - (ip)->i_flag |= ILOCKED; \ +#define ILOCK(ip) { \ + while ((ip)->i_flag & ILOCKED) { \ + (ip)->i_flag |= IWANT; \ + sleep((caddr_t)(ip), PINOD); \ + } \ + (ip)->i_flag |= ILOCKED; \ } -#define IUNLOCK(ip) { \ - (ip)->i_flag &= ~ILOCKED; \ - if ((ip)->i_flag&IWANT) { \ - (ip)->i_flag &= ~IWANT; \ - wakeup((caddr_t)(ip)); \ - } \ +#define IUNLOCK(ip) { \ + (ip)->i_flag &= ~ILOCKED; \ + if ((ip)->i_flag&IWANT) { \ + (ip)->i_flag &= ~IWANT; \ + wakeup((caddr_t)(ip)); \ + } \ } -#define IUPDAT(ip, t1, t2, waitfor) { \ - if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ - iupdat(ip, t1, t2, waitfor); \ +#define IUPDAT(ip, t1, t2, waitfor) { \ + if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \ + iupdat(ip, t1, t2, waitfor); \ } -#define ITIMES(ip, t1, t2) { \ - if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ - (ip)->i_flag |= IMOD; \ - if ((ip)->i_flag&IACC) \ - (ip)->i_atime = (t1)->tv_sec; \ - if ((ip)->i_flag&IUPD) \ - (ip)->i_mtime = (t2)->tv_sec; \ - if ((ip)->i_flag&ICHG) \ - (ip)->i_ctime = time.tv_sec; \ - (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ - } \ +#define ITIMES(ip, t1, t2) { \ + if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \ + (ip)->i_flag |= IMOD; \ + if ((ip)->i_flag&IACC) \ + (ip)->i_atime = (t1)->tv_sec; \ + if ((ip)->i_flag&IUPD) \ + (ip)->i_mtime = (t2)->tv_sec; \ + if ((ip)->i_flag&ICHG) \ + (ip)->i_ctime = time.tv_sec; \ + (ip)->i_flag &= ~(IACC|IUPD|ICHG); \ + } \ } diff --git a/sys/include/ioctl.h b/sys/include/ioctl.h index 7db0f14..4497311 100644 --- a/sys/include/ioctl.h +++ b/sys/include/ioctl.h @@ -3,13 +3,13 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)ioctl.h 1.4 (2.11BSD GTE) 1997/3/28 + * @(#)ioctl.h 1.4 (2.11BSD GTE) 1997/3/28 */ /* * Ioctl definitions */ -#ifndef _IOCTL_ +#ifndef _IOCTL_ #define _IOCTL_ #ifdef KERNEL #include "ttychars.h" @@ -23,20 +23,20 @@ int ioctl (int d, int request, ...); #endif struct tchars { - char t_intrc; /* interrupt */ - char t_quitc; /* quit */ - char t_startc; /* start output */ - char t_stopc; /* stop output */ - char t_eofc; /* end-of-file */ - char t_brkc; /* input delimiter (like nl) */ + char t_intrc; /* interrupt */ + char t_quitc; /* quit */ + char t_startc; /* start output */ + char t_stopc; /* stop output */ + char t_eofc; /* end-of-file */ + char t_brkc; /* input delimiter (like nl) */ }; struct ltchars { - char t_suspc; /* stop process signal */ - char t_dsuspc; /* delayed stop process signal */ - char t_rprntc; /* reprint line */ - char t_flushc; /* flush output (toggles) */ - char t_werasc; /* word erase */ - char t_lnextc; /* literal next character */ + char t_suspc; /* stop process signal */ + char t_dsuspc; /* delayed stop process signal */ + char t_rprntc; /* reprint line */ + char t_flushc; /* flush output (toggles) */ + char t_werasc; /* word erase */ + char t_lnextc; /* literal next character */ }; /* @@ -46,11 +46,11 @@ struct ltchars { #ifndef _SGTTYB_ #define _SGTTYB_ struct sgttyb { - char sg_ispeed; /* input speed */ - char sg_ospeed; /* output speed */ - char sg_erase; /* erase character */ - char sg_kill; /* kill character */ - short sg_flags; /* mode flags */ + char sg_ispeed; /* input speed */ + char sg_ospeed; /* output speed */ + char sg_erase; /* erase character */ + char sg_kill; /* kill character */ + short sg_flags; /* mode flags */ }; #endif @@ -63,23 +63,23 @@ struct sgttyb { * Type must be "unsigned short" so that types.h not required. */ struct winsize { - unsigned short ws_row; /* rows, in characters */ - unsigned short ws_col; /* columns, in characters */ - unsigned short ws_xpixel; /* horizontal size, pixels */ - unsigned short ws_ypixel; /* vertical size, pixels */ + unsigned short ws_row; /* rows, in characters */ + unsigned short ws_col; /* columns, in characters */ + unsigned short ws_xpixel; /* horizontal size, pixels */ + unsigned short ws_ypixel; /* vertical size, pixels */ }; /* * Pun for SUN. */ struct ttysize { - unsigned short ts_lines; - unsigned short ts_cols; - unsigned short ts_xxx; - unsigned short ts_yyy; + unsigned short ts_lines; + unsigned short ts_cols; + unsigned short ts_xxx; + unsigned short ts_yyy; }; -#define TIOCGSIZE TIOCGWINSZ -#define TIOCSSIZE TIOCSWINSZ +#define TIOCGSIZE TIOCGWINSZ +#define TIOCSSIZE TIOCSWINSZ #ifndef _IO /* @@ -89,171 +89,171 @@ struct ttysize { * to encode the in/out status of the parameter; for now * we restrict parameters to at most 256 bytes (disklabels are 216 bytes). */ -#define IOCPARM_MASK 0xff /* parameters must be < 256 bytes */ -#define IOC_VOID 0x20000000 /* no parameters */ -#define IOC_OUT 0x40000000 /* copy out parameters */ -#define IOC_IN 0x80000000 /* copy in parameters */ -#define IOC_INOUT (IOC_IN|IOC_OUT) +#define IOCPARM_MASK 0xff /* parameters must be < 256 bytes */ +#define IOC_VOID 0x20000000 /* no parameters */ +#define IOC_OUT 0x40000000 /* copy out parameters */ +#define IOC_IN 0x80000000 /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) -#define _IO(x,y) (IOC_VOID | ((x)<<8)|y) -#define _IOR(x,y,t) (IOC_OUT |((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) -#define _IOW(x,y,t) (IOC_IN |((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) +#define _IO(x,y) (IOC_VOID | ((x)<<8)|y) +#define _IOR(x,y,t) (IOC_OUT |((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) +#define _IOW(x,y,t) (IOC_IN |((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) /* this should be _IORW, but stdio got there first */ -#define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) -#define _ION(x,y,n) (IOC_INOUT| (((n)&IOCPARM_MASK)<<16)|((x)<<8)|y) +#define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) +#define _ION(x,y,n) (IOC_INOUT| (((n)&IOCPARM_MASK)<<16)|((x)<<8)|y) #endif /* * tty ioctl commands */ -#define TIOCGETD _IOR('t', 0, int) /* get line discipline */ -#define TIOCSETD _IOW('t', 1, int) /* set line discipline */ -#define TIOCHPCL _IO ('t', 2) /* hang up on last close */ -#define TIOCMODG _IOR('t', 3, int) /* get modem control state */ -#define TIOCMODS _IOW('t', 4, int) /* set modem control state */ -#define TIOCM_LE 0001 /* line enable */ -#define TIOCM_DTR 0002 /* data terminal ready */ -#define TIOCM_RTS 0004 /* request to send */ -#define TIOCM_ST 0010 /* secondary transmit */ -#define TIOCM_SR 0020 /* secondary receive */ -#define TIOCM_CTS 0040 /* clear to send */ -#define TIOCM_CAR 0100 /* carrier detect */ -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RNG 0200 /* ring */ -#define TIOCM_RI TIOCM_RNG -#define TIOCM_DSR 0400 /* data set ready */ -#define TIOCGETP _IOR('t', 8,struct sgttyb)/* get parameters -- gtty */ -#define TIOCSETP _IOW('t', 9,struct sgttyb)/* set parameters -- stty */ -#define TIOCSETN _IOW('t', 10,struct sgttyb)/* as above, but no flushtty */ -#define TIOCEXCL _IO ('t', 13) /* set exclusive use of tty */ -#define TIOCNXCL _IO ('t', 14) /* reset exclusive use of tty */ -#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ -#define TIOCSETC _IOW('t', 17,struct tchars)/* set special characters */ -#define TIOCGETC _IOR('t', 18,struct tchars)/* get special characters */ -#define TANDEM 0x00000001 /* send stopc on out q full */ -#define CBREAK 0x00000002 /* half-cooked mode */ - /* 0x4 (old LCASE) */ -#define ECHO 0x00000008 /* echo input */ -#define CRMOD 0x00000010 /* map \r to \r\n on output */ -#define RAW 0x00000020 /* no i/o processing */ -#define ODDP 0x00000040 /* get/send odd parity */ -#define EVENP 0x00000080 /* get/send even parity */ -#define ANYP 0x000000c0 /* get any parity/send none */ - /* 0x100 (old NLDELAY) */ - /* 0x200 */ -#define XTABS 0x00000400 /* expand tabs on output */ - /* 0x0800 (part of old XTABS) */ - /* 0x1000 (old CRDELAY) */ - /* 0x2000 */ - /* 0x4000 (old VTDELAY) */ - /* 0x8000 (old BSDELAY) */ -#define CRTBS 0x00010000 /* do backspacing for crt */ -#define PRTERA 0x00020000 /* \ ... / erase */ -#define CRTERA 0x00040000 /* " \b " to wipe out char */ - /* 0x00080000 (old TILDE) */ -#define MDMBUF 0x00100000 /* start/stop output on carrier intr */ -#define LITOUT 0x00200000 /* literal output */ -#define TOSTOP 0x00400000 /* SIGSTOP on background output */ -#define FLUSHO 0x00800000 /* flush output to terminal */ -#define NOHANG 0x01000000 /* no SIGHUP on carrier drop */ -#define RTSCTS 0x02000000 /* use RTS/CTS flow control */ -#define CRTKIL 0x04000000 /* kill line with " \b " */ -#define PASS8 0x08000000 -#define CTLECH 0x10000000 /* echo control chars as ^X */ -#define PENDIN 0x20000000 /* tp->t_rawq needs reread */ -#define DECCTQ 0x40000000 /* only ^Q starts after ^S */ -#define NOFLSH 0x80000000 /* no output flush on signal */ +#define TIOCGETD _IOR('t', 0, int) /* get line discipline */ +#define TIOCSETD _IOW('t', 1, int) /* set line discipline */ +#define TIOCHPCL _IO ('t', 2) /* hang up on last close */ +#define TIOCMODG _IOR('t', 3, int) /* get modem control state */ +#define TIOCMODS _IOW('t', 4, int) /* set modem control state */ +#define TIOCM_LE 0001 /* line enable */ +#define TIOCM_DTR 0002 /* data terminal ready */ +#define TIOCM_RTS 0004 /* request to send */ +#define TIOCM_ST 0010 /* secondary transmit */ +#define TIOCM_SR 0020 /* secondary receive */ +#define TIOCM_CTS 0040 /* clear to send */ +#define TIOCM_CAR 0100 /* carrier detect */ +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RNG 0200 /* ring */ +#define TIOCM_RI TIOCM_RNG +#define TIOCM_DSR 0400 /* data set ready */ +#define TIOCGETP _IOR('t', 8,struct sgttyb)/* get parameters -- gtty */ +#define TIOCSETP _IOW('t', 9,struct sgttyb)/* set parameters -- stty */ +#define TIOCSETN _IOW('t', 10,struct sgttyb)/* as above, but no flushtty */ +#define TIOCEXCL _IO ('t', 13) /* set exclusive use of tty */ +#define TIOCNXCL _IO ('t', 14) /* reset exclusive use of tty */ +#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ +#define TIOCSETC _IOW('t', 17,struct tchars)/* set special characters */ +#define TIOCGETC _IOR('t', 18,struct tchars)/* get special characters */ +#define TANDEM 0x00000001 /* send stopc on out q full */ +#define CBREAK 0x00000002 /* half-cooked mode */ + /* 0x4 (old LCASE) */ +#define ECHO 0x00000008 /* echo input */ +#define CRMOD 0x00000010 /* map \r to \r\n on output */ +#define RAW 0x00000020 /* no i/o processing */ +#define ODDP 0x00000040 /* get/send odd parity */ +#define EVENP 0x00000080 /* get/send even parity */ +#define ANYP 0x000000c0 /* get any parity/send none */ + /* 0x100 (old NLDELAY) */ + /* 0x200 */ +#define XTABS 0x00000400 /* expand tabs on output */ + /* 0x0800 (part of old XTABS) */ + /* 0x1000 (old CRDELAY) */ + /* 0x2000 */ + /* 0x4000 (old VTDELAY) */ + /* 0x8000 (old BSDELAY) */ +#define CRTBS 0x00010000 /* do backspacing for crt */ +#define PRTERA 0x00020000 /* \ ... / erase */ +#define CRTERA 0x00040000 /* " \b " to wipe out char */ + /* 0x00080000 (old TILDE) */ +#define MDMBUF 0x00100000 /* start/stop output on carrier intr */ +#define LITOUT 0x00200000 /* literal output */ +#define TOSTOP 0x00400000 /* SIGSTOP on background output */ +#define FLUSHO 0x00800000 /* flush output to terminal */ +#define NOHANG 0x01000000 /* no SIGHUP on carrier drop */ +#define RTSCTS 0x02000000 /* use RTS/CTS flow control */ +#define CRTKIL 0x04000000 /* kill line with " \b " */ +#define PASS8 0x08000000 +#define CTLECH 0x10000000 /* echo control chars as ^X */ +#define PENDIN 0x20000000 /* tp->t_rawq needs reread */ +#define DECCTQ 0x40000000 /* only ^Q starts after ^S */ +#define NOFLSH 0x80000000 /* no output flush on signal */ /* locals, from 127 down */ -#define TIOCLBIS _IOW('t', 127, int) /* bis local mode bits */ -#define TIOCLBIC _IOW('t', 126, int) /* bic local mode bits */ -#define TIOCLSET _IOW('t', 125, int) /* set entire local mode word */ -#define TIOCLGET _IOR('t', 124, int) /* get local modes */ -#define LCRTBS ((int)(CRTBS>>16)) -#define LPRTERA ((int)(PRTERA>>16)) -#define LCRTERA ((int)(CRTERA>>16)) -#define LMDMBUF ((int)(MDMBUF>>16)) -#define LLITOUT ((int)(LITOUT>>16)) -#define LTOSTOP ((int)(TOSTOP>>16)) -#define LFLUSHO ((int)(FLUSHO>>16)) -#define LNOHANG ((int)(NOHANG>>16)) -#define LRTSCTS ((int)(RTSCTS>>16)) -#define LCRTKIL ((int)(CRTKIL>>16)) -#define LPASS8 ((int)(PASS8>>16)) -#define LCTLECH ((int)(CTLECH>>16)) -#define LPENDIN ((int)(PENDIN>>16)) -#define LDECCTQ ((int)(DECCTQ>>16)) -#define LNOFLSH ((int)(NOFLSH>>16)) -#define TIOCSBRK _IO ('t', 123) /* set break bit */ -#define TIOCCBRK _IO ('t', 122) /* clear break bit */ -#define TIOCSDTR _IO ('t', 121) /* set data terminal ready */ -#define TIOCCDTR _IO ('t', 120) /* clear data terminal ready */ -#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ -#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ -#define TIOCSLTC _IOW('t', 117,struct ltchars)/* set local special chars */ -#define TIOCGLTC _IOR('t', 116,struct ltchars)/* get local special chars */ -#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ -#define TIOCSTI _IOW('t', 114, char) /* simulate terminal input */ -#define TIOCNOTTY _IO ('t', 113) /* void tty association */ -#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ -#define TIOCPKT_DATA 0x00 /* data packet */ -#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ -#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ -#define TIOCPKT_STOP 0x04 /* stop output */ -#define TIOCPKT_START 0x08 /* start output */ -#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ -#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ -#define TIOCSTOP _IO ('t', 111) /* stop output, like ^S */ -#define TIOCSTART _IO ('t', 110) /* start output, like ^Q */ -#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ -#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ -#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ -#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ -#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */ -#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ -#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ -#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ -#define UIOCCMD(n) _IO ('u', n) /* usr cntl op "n" */ +#define TIOCLBIS _IOW('t', 127, int) /* bis local mode bits */ +#define TIOCLBIC _IOW('t', 126, int) /* bic local mode bits */ +#define TIOCLSET _IOW('t', 125, int) /* set entire local mode word */ +#define TIOCLGET _IOR('t', 124, int) /* get local modes */ +#define LCRTBS ((int)(CRTBS>>16)) +#define LPRTERA ((int)(PRTERA>>16)) +#define LCRTERA ((int)(CRTERA>>16)) +#define LMDMBUF ((int)(MDMBUF>>16)) +#define LLITOUT ((int)(LITOUT>>16)) +#define LTOSTOP ((int)(TOSTOP>>16)) +#define LFLUSHO ((int)(FLUSHO>>16)) +#define LNOHANG ((int)(NOHANG>>16)) +#define LRTSCTS ((int)(RTSCTS>>16)) +#define LCRTKIL ((int)(CRTKIL>>16)) +#define LPASS8 ((int)(PASS8>>16)) +#define LCTLECH ((int)(CTLECH>>16)) +#define LPENDIN ((int)(PENDIN>>16)) +#define LDECCTQ ((int)(DECCTQ>>16)) +#define LNOFLSH ((int)(NOFLSH>>16)) +#define TIOCSBRK _IO ('t', 123) /* set break bit */ +#define TIOCCBRK _IO ('t', 122) /* clear break bit */ +#define TIOCSDTR _IO ('t', 121) /* set data terminal ready */ +#define TIOCCDTR _IO ('t', 120) /* clear data terminal ready */ +#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ +#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ +#define TIOCSLTC _IOW('t', 117,struct ltchars)/* set local special chars */ +#define TIOCGLTC _IOR('t', 116,struct ltchars)/* get local special chars */ +#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ +#define TIOCSTI _IOW('t', 114, char)/* simulate terminal input */ +#define TIOCNOTTY _IO ('t', 113) /* void tty association */ +#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ +#define TIOCPKT_DATA 0x00 /* data packet */ +#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ +#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ +#define TIOCPKT_STOP 0x04 /* stop output */ +#define TIOCPKT_START 0x08 /* start output */ +#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ +#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ +#define TIOCSTOP _IO ('t', 111) /* stop output, like ^S */ +#define TIOCSTART _IO ('t', 110) /* start output, like ^Q */ +#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ +#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ +#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ +#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ +#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */ +#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ +#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ +#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ +#define UIOCCMD(n) _IO ('u', n) /* usr cntl op "n" */ -#define NTTYDISC 0 /* new tty discipline */ +#define NTTYDISC 0 /* new tty discipline */ -#define FIOCLEX _IO('f', 1) /* set exclusive use on fd */ -#define FIONCLEX _IO('f', 2) /* remove exclusive use */ +#define FIOCLEX _IO('f', 1) /* set exclusive use on fd */ +#define FIONCLEX _IO('f', 2) /* remove exclusive use */ /* another local */ /* should use off_t for FIONREAD but that would require types.h */ -#define FIONREAD _IOR('f', 97, long) /* get # bytes to read */ -#define FIONBIO _IOW('f', 96, int) /* set/clear non-blocking i/o */ -#define FIOASYNC _IOW('f', 95, int) /* set/clear async i/o */ -#define FIOSETOWN _IOW('f', 94, int) /* set owner */ -#define FIOGETOWN _IOR('f', 93, int) /* get owner */ +#define FIONREAD _IOR('f', 97, long) /* get # bytes to read */ +#define FIONBIO _IOW('f', 96, int) /* set/clear non-blocking i/o */ +#define FIOASYNC _IOW('f', 95, int) /* set/clear async i/o */ +#define FIOSETOWN _IOW('f', 94, int) /* set owner */ +#define FIOGETOWN _IOR('f', 93, int) /* get owner */ /* socket i/o controls */ -#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ -#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ -#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ -#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ -#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ -#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ -#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ +#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ +#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ +#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ +#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ +#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ +#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ +#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ -#define SIOCADDRT _IOW('r', 10, struct rtentry) /* add route */ -#define SIOCDELRT _IOW('r', 11, struct rtentry) /* delete route */ +#define SIOCADDRT _IOW('r', 10, struct rtentry) /* add route */ +#define SIOCDELRT _IOW('r', 11, struct rtentry) /* delete route */ -#define SIOCSIFADDR _IOW ('i',12, struct ifreq) /* set ifnet address */ -#define SIOCGIFADDR _IOWR('i',13, struct ifreq) /* get ifnet address */ -#define SIOCSIFDSTADDR _IOW ('i',14, struct ifreq) /* set p-p address */ -#define SIOCGIFDSTADDR _IOWR('i',15, struct ifreq) /* get p-p address */ -#define SIOCSIFFLAGS _IOW ('i',16, struct ifreq) /* set ifnet flags */ -#define SIOCGIFFLAGS _IOWR('i',17, struct ifreq) /* get ifnet flags */ -#define SIOCGIFBRDADDR _IOWR('i',18, struct ifreq) /* get broadcast addr */ -#define SIOCSIFBRDADDR _IOW ('i',19, struct ifreq) /* set broadcast addr */ -#define SIOCGIFCONF _IOWR('i',20, struct ifconf) /* get ifnet list */ -#define SIOCGIFNETMASK _IOWR('i',21, struct ifreq) /* get net addr mask */ -#define SIOCSIFNETMASK _IOW ('i',22, struct ifreq) /* set net addr mask */ -#define SIOCGIFMETRIC _IOWR('i',23, struct ifreq) /* get IF metric */ -#define SIOCSIFMETRIC _IOW ('i',24, struct ifreq) /* set IF metric */ +#define SIOCSIFADDR _IOW ('i',12, struct ifreq) /* set ifnet address */ +#define SIOCGIFADDR _IOWR('i',13, struct ifreq) /* get ifnet address */ +#define SIOCSIFDSTADDR _IOW ('i',14, struct ifreq) /* set p-p address */ +#define SIOCGIFDSTADDR _IOWR('i',15, struct ifreq) /* get p-p address */ +#define SIOCSIFFLAGS _IOW ('i',16, struct ifreq) /* set ifnet flags */ +#define SIOCGIFFLAGS _IOWR('i',17, struct ifreq) /* get ifnet flags */ +#define SIOCGIFBRDADDR _IOWR('i',18, struct ifreq) /* get broadcast addr */ +#define SIOCSIFBRDADDR _IOW ('i',19, struct ifreq) /* set broadcast addr */ +#define SIOCGIFCONF _IOWR('i',20, struct ifconf) /* get ifnet list */ +#define SIOCGIFNETMASK _IOWR('i',21, struct ifreq) /* get net addr mask */ +#define SIOCSIFNETMASK _IOW ('i',22, struct ifreq) /* set net addr mask */ +#define SIOCGIFMETRIC _IOWR('i',23, struct ifreq) /* get IF metric */ +#define SIOCSIFMETRIC _IOW ('i',24, struct ifreq) /* set IF metric */ -#define SIOCSARP _IOW ('i',30, struct arpreq) /* set arp entry */ -#define SIOCGARP _IOWR('i',31, struct arpreq) /* get arp entry */ -#define SIOCDARP _IOW ('i',32, struct arpreq) /* delete arp entry */ +#define SIOCSARP _IOW ('i',30, struct arpreq) /* set arp entry */ +#define SIOCGARP _IOWR('i',31, struct arpreq) /* get arp entry */ +#define SIOCDARP _IOW ('i',32, struct arpreq) /* delete arp entry */ #endif diff --git a/sys/include/kernel.h b/sys/include/kernel.h index e766599..4b9015a 100644 --- a/sys/include/kernel.h +++ b/sys/include/kernel.h @@ -9,19 +9,19 @@ */ /* 1.1 */ -long hostid; -char hostname[MAXHOSTNAMELEN]; -int hostnamelen; +long hostid; +char hostname[MAXHOSTNAMELEN]; +int hostnamelen; /* 1.2 */ #include -struct timeval boottime; -struct timeval time; -struct timezone tz; /* XXX */ -int adjdelta; -int hz; -int usechz; /* # microseconds per hz */ -int lbolt; /* awoken once a second */ +struct timeval boottime; +struct timeval time; +struct timezone tz; /* XXX */ +int adjdelta; +int hz; +int usechz; /* # microseconds per hz */ +int lbolt; /* awoken once a second */ -short avenrun[3]; +short avenrun[3]; diff --git a/sys/include/map.h b/sys/include/map.h index 4b4531b..24177f0 100644 --- a/sys/include/map.h +++ b/sys/include/map.h @@ -21,19 +21,19 @@ * as it is used internally by the resource map routines. */ struct map { - struct mapent *m_map; /* start of the map */ - struct mapent *m_limit; /* address of last slot in map */ - char *m_name; /* name of resource */ + struct mapent *m_map; /* start of the map */ + struct mapent *m_limit; /* address of last slot in map */ + char *m_name; /* name of resource */ /* we use m_name when the map overflows, in warning messages */ }; struct mapent { - size_t m_size; /* size of this segment of the map */ - size_t m_addr; /* resource-space addr of start of segment */ + size_t m_size; /* size of this segment of the map */ + size_t m_addr; /* resource-space addr of start of segment */ }; #ifdef KERNEL -extern struct map swapmap[]; /* space for swap allocation */ +extern struct map swapmap[]; /* space for swap allocation */ /* * Allocate units from the given map. diff --git a/sys/include/mount.h b/sys/include/mount.h index 9841bc8..3b28834 100644 --- a/sys/include/mount.h +++ b/sys/include/mount.h @@ -9,36 +9,36 @@ */ #include -#define MNAMELEN 90 /* length of buffer for returned name */ +#define MNAMELEN 90 /* length of buffer for returned name */ struct statfs { - short f_type; /* type of filesystem (see below) */ - u_short f_flags; /* copy of mount flags */ - short f_bsize; /* fundamental file system block size */ - short f_iosize; /* optimal transfer block size */ - daddr_t f_blocks; /* total data blocks in file system */ - daddr_t f_bfree; /* free blocks in fs */ - daddr_t f_bavail; /* free blocks avail to non-superuser */ - ino_t f_files; /* total file nodes in file system */ - ino_t f_ffree; /* free file nodes in fs */ - long f_fsid[2]; /* file system id */ - long f_spare[5]; /* spare for later */ - char f_mntonname[MNAMELEN]; /* directory on which mounted */ - char f_mntfromname[MNAMELEN];/* mounted filesystem */ + short f_type; /* type of filesystem (see below) */ + u_short f_flags; /* copy of mount flags */ + short f_bsize; /* fundamental file system block size */ + short f_iosize; /* optimal transfer block size */ + daddr_t f_blocks; /* total data blocks in file system */ + daddr_t f_bfree; /* free blocks in fs */ + daddr_t f_bavail; /* free blocks avail to non-superuser */ + ino_t f_files; /* total file nodes in file system */ + ino_t f_ffree; /* free file nodes in fs */ + long f_fsid[2]; /* file system id */ + long f_spare[5]; /* spare for later */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ + char f_mntfromname[MNAMELEN];/* mounted filesystem */ }; /* * File system types. Since only UFS is supported the others are not * specified at this time. */ -#define MOUNT_NONE 0 -#define MOUNT_UFS 1 /* Fast Filesystem */ -#define MOUNT_MAXTYPE 1 +#define MOUNT_NONE 0 +#define MOUNT_UFS 1 /* Fast Filesystem */ +#define MOUNT_MAXTYPE 1 -#define INITMOUNTNAMES { \ - "none", /* 0 MOUNT_NONE */ \ - "ufs", /* 1 MOUNT_UFS */ \ - 0, \ +#define INITMOUNTNAMES { \ + "none", /* 0 MOUNT_NONE */ \ + "ufs", /* 1 MOUNT_UFS */ \ + 0, \ } /* @@ -46,40 +46,40 @@ struct statfs { * One allocated on every mount. * Used to find the super block. */ -struct mount +struct mount { - dev_t m_dev; /* device mounted */ - struct fs m_filsys; /* superblock data */ -#define m_flags m_filsys.fs_flags - struct inode *m_inodp; /* pointer to mounted on inode */ - struct inode *m_qinod; /* QUOTA: pointer to quota file */ - char m_mntfrom [MNAMELEN]; /* /dev/xxxx mounted from */ - char m_mnton [MNAMELEN]; /* directory mounted on - this is the - * full(er) version of fs_fsmnt. */ + dev_t m_dev; /* device mounted */ + struct fs m_filsys; /* superblock data */ +#define m_flags m_filsys.fs_flags + struct inode *m_inodp; /* pointer to mounted on inode */ + struct inode *m_qinod; /* QUOTA: pointer to quota file */ + char m_mntfrom [MNAMELEN]; /* /dev/xxxx mounted from */ + char m_mnton [MNAMELEN]; /* directory mounted on - this is the + * full(er) version of fs_fsmnt. */ }; /* * Mount flags. */ -#define MNT_RDONLY 0x0001 /* read only filesystem */ -#define MNT_SYNCHRONOUS 0x0002 /* file system written synchronously */ -#define MNT_NOEXEC 0x0004 /* can't exec from filesystem */ -#define MNT_NOSUID 0x0008 /* don't honor setuid bits on fs */ -#define MNT_NODEV 0x0010 /* don't interpret special files */ -#define MNT_QUOTA 0x0020 /* quotas are enabled on filesystem */ -#define MNT_ASYNC 0x0040 /* file system written asynchronously */ -#define MNT_NOATIME 0x0080 /* don't update access times */ +#define MNT_RDONLY 0x0001 /* read only filesystem */ +#define MNT_SYNCHRONOUS 0x0002 /* file system written synchronously */ +#define MNT_NOEXEC 0x0004 /* can't exec from filesystem */ +#define MNT_NOSUID 0x0008 /* don't honor setuid bits on fs */ +#define MNT_NODEV 0x0010 /* don't interpret special files */ +#define MNT_QUOTA 0x0020 /* quotas are enabled on filesystem */ +#define MNT_ASYNC 0x0040 /* file system written asynchronously */ +#define MNT_NOATIME 0x0080 /* don't update access times */ /* * Mask of flags that are visible to statfs(). */ -#define MNT_VISFLAGMASK 0x0fff +#define MNT_VISFLAGMASK 0x0fff /* * filesystem control flags. The high 4 bits are used for this. Since NFS * support will never be a problem we can avoid making the flags into a 'long. */ -#define MNT_UPDATE 0x1000 /* not a real mount, just an update */ +#define MNT_UPDATE 0x1000 /* not a real mount, just an update */ /* * Flags for various system call interfaces. @@ -87,12 +87,12 @@ struct mount * These aren't used for anything in the system and are present only * for source code compatibility reasons. */ -#define MNT_WAIT 1 -#define MNT_NOWAIT 2 +#define MNT_WAIT 1 +#define MNT_NOWAIT 2 #ifdef KERNEL -struct mount mount[NMOUNT]; +struct mount mount[NMOUNT]; #else diff --git a/sys/include/msgbuf.h b/sys/include/msgbuf.h index aeabd54..2bea47a 100644 --- a/sys/include/msgbuf.h +++ b/sys/include/msgbuf.h @@ -3,17 +3,17 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#define MSG_MAGIC 0x063061 -#define MSG_BSIZE 2048 +#define MSG_MAGIC 0x063061 +#define MSG_BSIZE 2048 -struct msgbuf { - long msg_magic; - int msg_bufx; - int msg_bufr; - char msg_bufc [MSG_BSIZE]; +struct msgbuf { + long msg_magic; + int msg_bufx; + int msg_bufr; + char msg_bufc [MSG_BSIZE]; }; -#define logMSG 0 /* /dev/klog */ +#define logMSG 0 /* /dev/klog */ #ifdef KERNEL /* diff --git a/sys/include/mtio.h b/sys/include/mtio.h index 3848a24..de7edf7 100644 --- a/sys/include/mtio.h +++ b/sys/include/mtio.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)mtio.h 7.1.2 (2.11BSD) 1998/3/7 + * @(#)mtio.h 7.1.2 (2.11BSD) 1998/3/7 */ /* @@ -11,36 +11,36 @@ */ /* structure for MTIOCTOP - mag tape op command */ -struct mtop { - short mt_op; /* operations defined below */ - daddr_t mt_count; /* how many of them */ +struct mtop { + short mt_op; /* operations defined below */ + daddr_t mt_count; /* how many of them */ }; /* operations */ -#define MTWEOF 0 /* write an end-of-file record */ -#define MTFSF 1 /* forward space file */ -#define MTBSF 2 /* backward space file */ -#define MTFSR 3 /* forward space record */ -#define MTBSR 4 /* backward space record */ -#define MTREW 5 /* rewind */ -#define MTOFFL 6 /* rewind and put the drive offline */ -#define MTNOP 7 /* no operation, sets status only */ -#define MTCACHE 8 /* enable controller cache */ -#define MTNOCACHE 9 /* disable controller cache */ -#define MTFLUSH 10 /* flush cache */ +#define MTWEOF 0 /* write an end-of-file record */ +#define MTFSF 1 /* forward space file */ +#define MTBSF 2 /* backward space file */ +#define MTFSR 3 /* forward space record */ +#define MTBSR 4 /* backward space record */ +#define MTREW 5 /* rewind */ +#define MTOFFL 6 /* rewind and put the drive offline */ +#define MTNOP 7 /* no operation, sets status only */ +#define MTCACHE 8 /* enable controller cache */ +#define MTNOCACHE 9 /* disable controller cache */ +#define MTFLUSH 10 /* flush cache */ /* structure for MTIOCGET - mag tape get status command */ -struct mtget { - short mt_type; /* type of magtape device */ +struct mtget { + short mt_type; /* type of magtape device */ /* the following two registers are grossly device dependent */ - short mt_dsreg; /* ``drive status'' register */ - short mt_erreg; /* ``error'' register */ + short mt_dsreg; /* ``drive status'' register */ + short mt_erreg; /* ``error'' register */ /* end device-dependent registers */ - short mt_resid; /* residual count */ + short mt_resid; /* residual count */ /* the following two are not yet implemented */ - daddr_t mt_fileno; /* file number of current position */ - daddr_t mt_blkno; /* block number of current position */ + daddr_t mt_fileno; /* file number of current position */ + daddr_t mt_blkno; /* block number of current position */ /* end not yet implemented */ }; @@ -48,33 +48,33 @@ struct mtget { * Constants for mt_type byte. These are the same * for other controllers compatible with the types listed. */ -#define MT_ISTS 0x01 /* TS-11 */ -#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */ -#define MT_ISTM 0x03 /* TM11/TE10 Unibus */ -#define MT_ISMT 0x04 /* TM78/TU78 Massbus */ -#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */ -#define MT_ISCPC 0x06 /* SUN */ -#define MT_ISAR 0x07 /* SUN */ -#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */ +#define MT_ISTS 0x01 /* TS-11 */ +#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */ +#define MT_ISTM 0x03 /* TM11/TE10 Unibus */ +#define MT_ISMT 0x04 /* TM78/TU78 Massbus */ +#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */ +#define MT_ISCPC 0x06 /* SUN */ +#define MT_ISAR 0x07 /* SUN */ +#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */ /* * At present only the TMSCP driver reports this information in the * high byte of the 'drive status' word. Other drives will (hopefully) * be updated in the future. */ -#define MTF_BOM 0x01 /* At beginning of media */ -#define MTF_EOM 0x02 /* At the end of media */ -#define MTF_OFFLINE 0x04 /* Drive is offline */ -#define MTF_WRTLCK 0x08 /* Drive is write protected */ -#define MTF_WRITTEN 0x10 /* Tape has been written */ +#define MTF_BOM 0x01 /* At beginning of media */ +#define MTF_EOM 0x02 /* At the end of media */ +#define MTF_OFFLINE 0x04 /* Drive is offline */ +#define MTF_WRTLCK 0x08 /* Drive is write protected */ +#define MTF_WRITTEN 0x10 /* Tape has been written */ /* mag tape io control commands */ -#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ -#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ -#define MTIOCIEOT _IO ('m', 3) /* ignore EOT error */ -#define MTIOCEEOT _IO ('m', 4) /* enable EOT error */ +#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ +#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ +#define MTIOCIEOT _IO ('m', 3) /* ignore EOT error */ +#define MTIOCEEOT _IO ('m', 4) /* enable EOT error */ #ifndef KERNEL -#define DEFTAPE "/dev/rmt8" -#define MT_DEF "/dev/nrmt8" +#define DEFTAPE "/dev/rmt8" +#define MT_DEF "/dev/nrmt8" #endif diff --git a/sys/include/namei.h b/sys/include/namei.h index f5c6228..90428c9 100644 --- a/sys/include/namei.h +++ b/sys/include/namei.h @@ -4,7 +4,7 @@ * specifies the terms and conditions for redistribution. */ #ifndef _NAMEI_ -#define _NAMEI_ +#define _NAMEI_ #ifdef KERNEL #include "uio.h" @@ -18,54 +18,54 @@ * minimize space allocated on the kernel stack. */ struct nameidata { - caddr_t ni_dirp; /* pathname pointer */ - short ni_nameiop; /* see below */ - short ni_error; /* error return if any */ - off_t ni_endoff; /* end of useful stuff in directory */ - struct inode *ni_pdir; /* inode of parent directory of dirp */ - struct inode *ni_ip; /* inode of dirp */ - off_t ni_offset; /* offset in directory */ - u_short ni_count; /* offset of open slot (off_t?) */ - struct direct ni_dent; /* current directory entry */ + caddr_t ni_dirp; /* pathname pointer */ + short ni_nameiop; /* see below */ + short ni_error; /* error return if any */ + off_t ni_endoff; /* end of useful stuff in directory */ + struct inode *ni_pdir; /* inode of parent directory of dirp */ + struct inode *ni_ip; /* inode of dirp */ + off_t ni_offset; /* offset in directory */ + u_short ni_count; /* offset of open slot (off_t?) */ + struct direct ni_dent; /* current directory entry */ }; /* * namei operations and modifiers */ -#define LOOKUP 0 /* perform name lookup only */ -#define CREATE 1 /* setup for file creation */ -#define DELETE 2 /* setup for file deletion */ -#define LOCKPARENT 0x10 /* see the top of namei */ -#define NOCACHE 0x20 /* name must not be left in cache */ -#define FOLLOW 0x40 /* follow symbolic links */ -#define NOFOLLOW 0x0 /* don't follow symbolic links (pseudo) */ +#define LOOKUP 0 /* perform name lookup only */ +#define CREATE 1 /* setup for file creation */ +#define DELETE 2 /* setup for file deletion */ +#define LOCKPARENT 0x10 /* see the top of namei */ +#define NOCACHE 0x20 /* name must not be left in cache */ +#define FOLLOW 0x40 /* follow symbolic links */ +#define NOFOLLOW 0x0 /* don't follow symbolic links (pseudo) */ -#define NDINIT(ndp,op,flags,namep) {\ - (ndp)->ni_nameiop = op | flags; \ - (ndp)->ni_dirp = namep; } +#define NDINIT(ndp,op,flags,namep) {\ + (ndp)->ni_nameiop = op | flags; \ + (ndp)->ni_dirp = namep; } /* * This structure describes the elements in the cache of recent * names looked up by namei. */ -struct namecache { - struct namecache *nc_forw; /* hash chain, MUST BE FIRST */ - struct namecache *nc_back; /* hash chain, MUST BE FIRST */ - struct namecache *nc_nxt; /* LRU chain */ - struct namecache **nc_prev; /* LRU chain */ - struct inode *nc_ip; /* inode the name refers to */ - ino_t nc_ino; /* ino of parent of name */ - dev_t nc_dev; /* dev of parent of name */ - dev_t nc_idev; /* dev of the name ref'd */ - u_short nc_id; /* referenced inode's id */ - char nc_nlen; /* length of name */ -#define NCHNAMLEN 15 /* maximum name segment length we bother with */ - char nc_name[NCHNAMLEN]; /* segment name */ +struct namecache { + struct namecache *nc_forw; /* hash chain, MUST BE FIRST */ + struct namecache *nc_back; /* hash chain, MUST BE FIRST */ + struct namecache *nc_nxt; /* LRU chain */ + struct namecache **nc_prev; /* LRU chain */ + struct inode *nc_ip; /* inode the name refers to */ + ino_t nc_ino; /* ino of parent of name */ + dev_t nc_dev; /* dev of parent of name */ + dev_t nc_idev; /* dev of the name ref'd */ + u_short nc_id; /* referenced inode's id */ + char nc_nlen; /* length of name */ +#define NCHNAMLEN 15 /* maximum name segment length we bother with */ + char nc_name[NCHNAMLEN]; /* segment name */ }; #ifdef KERNEL -extern struct namecache namecache []; -struct nchstats nchstats; /* cache effectiveness statistics */ +extern struct namecache namecache []; +struct nchstats nchstats; /* cache effectiveness statistics */ /* * Name cache initialization. @@ -92,13 +92,13 @@ int dirremove (struct nameidata *ndp); /* * Stats on usefulness of namei caches. */ -struct nchstats { - long ncs_goodhits; /* hits that we can reall use */ - long ncs_badhits; /* hits we must drop */ - long ncs_falsehits; /* hits with id mismatch */ - long ncs_miss; /* misses */ - long ncs_long; /* long names that ignore cache */ - long ncs_pass2; /* names found with passes == 2 */ - long ncs_2passes; /* number of times we attempt it */ +struct nchstats { + long ncs_goodhits; /* hits that we can reall use */ + long ncs_badhits; /* hits we must drop */ + long ncs_falsehits; /* hits with id mismatch */ + long ncs_miss; /* misses */ + long ncs_long; /* long names that ignore cache */ + long ncs_pass2; /* names found with passes == 2 */ + long ncs_2passes; /* number of times we attempt it */ }; #endif diff --git a/sys/include/param.h b/sys/include/param.h index ad05fc5..5d57ebb 100644 --- a/sys/include/param.h +++ b/sys/include/param.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#define BSD 211 /* 2.11 * 100, as cpp doesn't do floats */ +#define BSD 211 /* 2.11 * 100, as cpp doesn't do floats */ #ifndef offsetof #define offsetof(type, member) ((size_t)(&((type *)0)->member)) @@ -18,53 +18,53 @@ * Machine-independent constants */ #ifndef NMOUNT -#define NMOUNT 2 /* number of mountable file systems */ +#define NMOUNT 2 /* number of mountable file systems */ #endif -#define MAXUPRC 20 /* max processes per user */ -#define NOFILE 30 /* max open files per process */ -#define NCARGS 5120 /* # characters in exec arglist */ -#define NGROUPS 16 /* max number groups */ +#define MAXUPRC 20 /* max processes per user */ +#define NOFILE 30 /* max open files per process */ +#define NCARGS 5120 /* # characters in exec arglist */ +#define NGROUPS 16 /* max number groups */ -#define NOGROUP 65535 /* marker for empty group set member */ +#define NOGROUP 65535 /* marker for empty group set member */ /* * Priorities */ -#define PSWP 0 -#define PINOD 10 -#define PRIBIO 20 -#define PRIUBA 24 -#define PZERO 25 -#define PPIPE 26 -#define PSOCK 26 -#define PWAIT 30 -#define PLOCK 35 -#define PPAUSE 40 -#define PUSER 50 +#define PSWP 0 +#define PINOD 10 +#define PRIBIO 20 +#define PRIUBA 24 +#define PZERO 25 +#define PPIPE 26 +#define PSOCK 26 +#define PWAIT 30 +#define PLOCK 35 +#define PPAUSE 40 +#define PUSER 50 -#define NZERO 0 +#define NZERO 0 -#define PRIMASK 0xff -#define PCATCH 0x100 +#define PRIMASK 0xff +#define PCATCH 0x100 /* * Signals */ #include -#define NBPW sizeof(int) /* number of bytes in an integer */ +#define NBPW sizeof(int) /* number of bytes in an integer */ -#ifndef NULL -#define NULL 0 +#ifndef NULL +#define NULL 0 #endif -#define CMASK 026 /* default mask for file creation */ -#define NODEV (dev_t)(-1) +#define CMASK 026 /* default mask for file creation */ +#define NODEV (dev_t)(-1) /* CBLOCK is the size of a clist block, must be power of 2 */ -#define CBLOCK 32 -#define CBSIZE (CBLOCK - sizeof(struct cblock *)) /* data chars/clist */ -#define CROUND (CBLOCK - 1) /* clist rounding */ +#define CBLOCK 32 +#define CBSIZE (CBLOCK - sizeof(struct cblock *)) /* data chars/clist */ +#define CROUND (CBLOCK - 1) /* clist rounding */ #include @@ -73,7 +73,7 @@ * * The file system is made out of blocks of most MAXBSIZE units. */ -#define MAXBSIZE 1024 +#define MAXBSIZE 1024 /* * MAXPATHLEN defines the longest permissable path length @@ -86,29 +86,29 @@ * enough to allow all legitimate uses, but halt infinite loops * reasonably quickly. */ -#define MAXPATHLEN 256 -#define MAXSYMLINKS 8 +#define MAXPATHLEN 256 +#define MAXSYMLINKS 8 /* * Macros for fast min/max. */ -#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) #ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) #endif /* * Macros for counting and rounding. */ #ifndef howmany -# define howmany(x,y) (((x)+((y)-1))/(y)) +# define howmany(x,y) (((x)+((y)-1))/(y)) #endif -#define roundup(x,y) ((((x)+((y)-1))/(y))*(y)) +#define roundup(x,y) ((((x)+((y)-1))/(y))*(y)) /* * Maximum size of hostname recognized and stored in the kernel. */ -#define MAXHOSTNAMELEN 64 +#define MAXHOSTNAMELEN 64 #if defined(KERNEL) && defined(INET) # include "machine/net_mac.h" @@ -117,9 +117,9 @@ /* * MAXMEM is the maximum core per process is allowed. First number is Kb. */ -#define MAXMEM (96*1024) +#define MAXMEM (96*1024) /* * Max length of a user login name. */ -#define MAXLOGNAME 16 +#define MAXLOGNAME 16 diff --git a/sys/include/picga.h b/sys/include/picga.h index dae8da5..c492719 100644 --- a/sys/include/picga.h +++ b/sys/include/picga.h @@ -29,13 +29,13 @@ #define SPI_FGCOLOR 0x86 #define SPI_BGCOLOR 0x87 -#define FONT_SINCLAIR 0x00 -#define FONT_TOPAZ 0x01 +#define FONT_SINCLAIR 0x00 +#define FONT_TOPAZ 0x01 -#define UP 0 -#define DOWN 1 -#define LEFT 2 -#define RIGHT 3 +#define UP 0 +#define DOWN 1 +#define LEFT 2 +#define RIGHT 3 struct coord2 { unsigned short x; @@ -95,6 +95,6 @@ extern int picga_write(dev_t dev, struct uio *uio, int flag); extern int picga_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag); #endif -#define PICGA_CLS _IO('g', 1) +#define PICGA_CLS _IO('g', 1) #endif diff --git a/sys/include/proc.h b/sys/include/proc.h index 4cca294..06467f6 100644 --- a/sys/include/proc.h +++ b/sys/include/proc.h @@ -3,8 +3,8 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#ifndef _SYS_PROC_H_ -#define _SYS_PROC_H_ +#ifndef _SYS_PROC_H_ +#define _SYS_PROC_H_ /* * One structure allocated per active @@ -14,89 +14,89 @@ * Other per process data (user.h) * is swapped with the process. */ -struct proc { - struct proc *p_nxt; /* linked list of allocated proc slots */ - struct proc **p_prev; /* also zombies, and free proc's */ - struct proc *p_pptr; /* pointer to process structure of parent */ - short p_flag; - short p_uid; /* user id, used to direct tty signals */ - short p_pid; /* unique process id */ - short p_ppid; /* process id of parent */ - long p_sig; /* signals pending to this process */ - int p_stat; +struct proc { + struct proc *p_nxt; /* linked list of allocated proc slots */ + struct proc **p_prev; /* also zombies, and free proc's */ + struct proc *p_pptr; /* pointer to process structure of parent */ + short p_flag; + short p_uid; /* user id, used to direct tty signals */ + short p_pid; /* unique process id */ + short p_ppid; /* process id of parent */ + long p_sig; /* signals pending to this process */ + int p_stat; - /* - * Union to overwrite information no longer needed by ZOMBIED - * process with exit information for the parent process. The - * two structures have been carefully set up to use the same - * amount of memory. Must be very careful that any values in - * p_alive are not used for zombies (zombproc). - */ - union { - struct { - char P_pri; /* priority, negative is high */ - char P_cpu; /* cpu usage for scheduling */ - char P_time; /* resident time for scheduling */ - char P_nice; /* nice for cpu usage */ - char P_slptime; /* secs sleeping */ - char P_ptracesig; /* used between parent & traced child */ - struct proc *P_hash; /* hashed based on p_pid */ - long P_sigmask; /* current signal mask */ - long P_sigignore; /* signals being ignored */ - long P_sigcatch; /* signals being caught by user */ - short P_pgrp; /* name of process group leader */ - struct proc *P_link; /* linked list of running processes */ - size_t P_addr; /* address of u. area */ - size_t P_daddr; /* address of data area */ - size_t P_saddr; /* address of stack area */ - size_t P_dsize; /* size of data area (clicks) */ - size_t P_ssize; /* size of stack segment (clicks) */ - caddr_t P_wchan; /* event process is awaiting */ - struct k_itimerval P_realtimer; - } p_alive; - struct { - int P_xstat; /* exit status for wait */ - struct k_rusage P_ru; /* exit information */ - } p_dead; - } p_un; + /* + * Union to overwrite information no longer needed by ZOMBIED + * process with exit information for the parent process. The + * two structures have been carefully set up to use the same + * amount of memory. Must be very careful that any values in + * p_alive are not used for zombies (zombproc). + */ + union { + struct { + char P_pri; /* priority, negative is high */ + char P_cpu; /* cpu usage for scheduling */ + char P_time; /* resident time for scheduling */ + char P_nice; /* nice for cpu usage */ + char P_slptime; /* secs sleeping */ + char P_ptracesig; /* used between parent & traced child */ + struct proc *P_hash; /* hashed based on p_pid */ + long P_sigmask; /* current signal mask */ + long P_sigignore; /* signals being ignored */ + long P_sigcatch; /* signals being caught by user */ + short P_pgrp; /* name of process group leader */ + struct proc *P_link; /* linked list of running processes */ + size_t P_addr; /* address of u. area */ + size_t P_daddr; /* address of data area */ + size_t P_saddr; /* address of stack area */ + size_t P_dsize; /* size of data area (clicks) */ + size_t P_ssize; /* size of stack segment (clicks) */ + caddr_t P_wchan; /* event process is awaiting */ + struct k_itimerval P_realtimer; + } p_alive; + struct { + int P_xstat; /* exit status for wait */ + struct k_rusage P_ru; /* exit information */ + } p_dead; + } p_un; }; -#define p_pri p_un.p_alive.P_pri -#define p_cpu p_un.p_alive.P_cpu -#define p_time p_un.p_alive.P_time -#define p_nice p_un.p_alive.P_nice -#define p_slptime p_un.p_alive.P_slptime -#define p_hash p_un.p_alive.P_hash -#define p_ptracesig p_un.p_alive.P_ptracesig -#define p_sigmask p_un.p_alive.P_sigmask -#define p_sigignore p_un.p_alive.P_sigignore -#define p_sigcatch p_un.p_alive.P_sigcatch -#define p_pgrp p_un.p_alive.P_pgrp -#define p_link p_un.p_alive.P_link -#define p_addr p_un.p_alive.P_addr -#define p_daddr p_un.p_alive.P_daddr -#define p_saddr p_un.p_alive.P_saddr -#define p_dsize p_un.p_alive.P_dsize -#define p_ssize p_un.p_alive.P_ssize -#define p_wchan p_un.p_alive.P_wchan -#define p_realtimer p_un.p_alive.P_realtimer -#define p_clktim p_realtimer.it_value +#define p_pri p_un.p_alive.P_pri +#define p_cpu p_un.p_alive.P_cpu +#define p_time p_un.p_alive.P_time +#define p_nice p_un.p_alive.P_nice +#define p_slptime p_un.p_alive.P_slptime +#define p_hash p_un.p_alive.P_hash +#define p_ptracesig p_un.p_alive.P_ptracesig +#define p_sigmask p_un.p_alive.P_sigmask +#define p_sigignore p_un.p_alive.P_sigignore +#define p_sigcatch p_un.p_alive.P_sigcatch +#define p_pgrp p_un.p_alive.P_pgrp +#define p_link p_un.p_alive.P_link +#define p_addr p_un.p_alive.P_addr +#define p_daddr p_un.p_alive.P_daddr +#define p_saddr p_un.p_alive.P_saddr +#define p_dsize p_un.p_alive.P_dsize +#define p_ssize p_un.p_alive.P_ssize +#define p_wchan p_un.p_alive.P_wchan +#define p_realtimer p_un.p_alive.P_realtimer +#define p_clktim p_realtimer.it_value -#define p_xstat p_un.p_dead.P_xstat -#define p_ru p_un.p_dead.P_ru +#define p_xstat p_un.p_dead.P_xstat +#define p_ru p_un.p_dead.P_ru -#define PIDHSZ 16 -#define PIDHASH(pid) ((pid) & (PIDHSZ - 1)) +#define PIDHSZ 16 +#define PIDHASH(pid) ((pid) & (PIDHSZ - 1)) /* arguments to swapout: */ -#define X_OLDSIZE (-1) /* the old size is the same as current */ -#define X_DONTFREE 0 /* save core image (for parent in newproc) */ -#define X_FREECORE 1 /* free core space after swap */ +#define X_OLDSIZE (-1) /* the old size is the same as current */ +#define X_DONTFREE 0 /* save core image (for parent in newproc) */ +#define X_FREECORE 1 /* free core space after swap */ #ifdef KERNEL -struct proc *pidhash [PIDHSZ]; -extern struct proc proc[]; /* the proc table itself */ -struct proc *freeproc, *zombproc, *allproc, *qs; - /* lists of procs in various states */ +struct proc *pidhash [PIDHSZ]; +extern struct proc proc[]; /* the proc table itself */ +struct proc *freeproc, *zombproc, *allproc, *qs; + /* lists of procs in various states */ extern int nproc; /* @@ -277,31 +277,31 @@ void execsigs(register struct proc *p); #endif /* KERMEL */ /* stat codes */ -#define SSLEEP 1 /* awaiting an event */ -#define SWAIT 2 /* (abandoned state) */ -#define SRUN 3 /* running */ -#define SIDL 4 /* intermediate state in process creation */ -#define SZOMB 5 /* intermediate state in process termination */ -#define SSTOP 6 /* process being traced */ +#define SSLEEP 1 /* awaiting an event */ +#define SWAIT 2 /* (abandoned state) */ +#define SRUN 3 /* running */ +#define SIDL 4 /* intermediate state in process creation */ +#define SZOMB 5 /* intermediate state in process termination */ +#define SSTOP 6 /* process being traced */ /* flag codes */ -#define SLOAD 0x0001 /* in core */ -#define SSYS 0x0002 /* swapper or pager process */ -#define SLOCK 0x0004 /* process being swapped out */ -#define SSWAP 0x0008 /* save area flag */ -#define P_TRACED 0x0010 /* process is being traced */ -#define P_WAITED 0x0020 /* another tracing flag */ -#define P_SINTR 0x0080 /* sleeping interruptibly */ -#define SVFORK 0x0100 /* process resulted from vfork() */ -#define SVFPRNT 0x0200 /* parent in vfork, waiting for child */ -#define SVFDONE 0x0400 /* parent has released child in vfork */ - /* 0x0800 unused */ -#define P_TIMEOUT 0x1000 /* tsleep timeout expired */ -#define P_NOCLDSTOP 0x2000 /* no SIGCHLD signal to parent */ -#define P_SELECT 0x4000 /* selecting; wakeup/waiting danger */ - /* 0x8000 unused */ +#define SLOAD 0x0001 /* in core */ +#define SSYS 0x0002 /* swapper or pager process */ +#define SLOCK 0x0004 /* process being swapped out */ +#define SSWAP 0x0008 /* save area flag */ +#define P_TRACED 0x0010 /* process is being traced */ +#define P_WAITED 0x0020 /* another tracing flag */ +#define P_SINTR 0x0080 /* sleeping interruptibly */ +#define SVFORK 0x0100 /* process resulted from vfork() */ +#define SVFPRNT 0x0200 /* parent in vfork, waiting for child */ +#define SVFDONE 0x0400 /* parent has released child in vfork */ + /* 0x0800 unused */ +#define P_TIMEOUT 0x1000 /* tsleep timeout expired */ +#define P_NOCLDSTOP 0x2000 /* no SIGCHLD signal to parent */ +#define P_SELECT 0x4000 /* selecting; wakeup/waiting danger */ + /* 0x8000 unused */ -#define S_DATA 0 /* specified segment */ -#define S_STACK 1 +#define S_DATA 0 /* specified segment */ +#define S_STACK 1 -#endif /* !_SYS_PROC_H_ */ +#endif /* !_SYS_PROC_H_ */ diff --git a/sys/include/ptrace.h b/sys/include/ptrace.h index 49cd4ac..8ce1ab2 100644 --- a/sys/include/ptrace.h +++ b/sys/include/ptrace.h @@ -7,16 +7,16 @@ #ifndef _PTRACE_ #define _PTRACE_ -#define PT_TRACE_ME 0 /* child declares it's being traced */ -#define PT_READ_I 1 /* read word in child's I space */ -#define PT_READ_D 2 /* read word in child's D space */ -#define PT_READ_U 3 /* read word in child's user structure */ -#define PT_WRITE_I 4 /* write word in child's I space */ -#define PT_WRITE_D 5 /* write word in child's D space */ -#define PT_WRITE_U 6 /* write word in child's user structure */ -#define PT_CONTINUE 7 /* continue the child */ -#define PT_KILL 8 /* kill the child process */ -#define PT_STEP 9 /* single step the child */ +#define PT_TRACE_ME 0 /* child declares it's being traced */ +#define PT_READ_I 1 /* read word in child's I space */ +#define PT_READ_D 2 /* read word in child's D space */ +#define PT_READ_U 3 /* read word in child's user structure */ +#define PT_WRITE_I 4 /* write word in child's I space */ +#define PT_WRITE_D 5 /* write word in child's D space */ +#define PT_WRITE_U 6 /* write word in child's user structure */ +#define PT_CONTINUE 7 /* continue the child */ +#define PT_KILL 8 /* kill the child process */ +#define PT_STEP 9 /* single step the child */ /* * Tracing variables. @@ -27,10 +27,10 @@ * per user. */ struct ipc { - int ip_lock; - int ip_req; - int *ip_addr; - int ip_data; + int ip_lock; + int ip_req; + int *ip_addr; + int ip_data; }; #ifdef KERNEL diff --git a/sys/include/pty.h b/sys/include/pty.h index 5825227..95ed62c 100644 --- a/sys/include/pty.h +++ b/sys/include/pty.h @@ -1,13 +1,13 @@ #ifndef _PTY_H #define _PTY_H -#define PF_RCOLL 0x01 -#define PF_WCOLL 0x02 -#define PF_PKT 0x08 /* packet mode */ -#define PF_STOPPED 0x10 /* user told stopped */ -#define PF_REMOTE 0x20 /* remote and flow controlled input */ -#define PF_NOSTOP 0x40 -#define PF_UCNTL 0x80 /* user control mode */ +#define PF_RCOLL 0x01 +#define PF_WCOLL 0x02 +#define PF_PKT 0x08 /* packet mode */ +#define PF_STOPPED 0x10 /* user told stopped */ +#define PF_REMOTE 0x20 /* remote and flow controlled input */ +#define PF_NOSTOP 0x40 +#define PF_UCNTL 0x80 /* user control mode */ #ifdef KERNEL diff --git a/sys/include/pwm.h b/sys/include/pwm.h index 4c07de5..8fe5f83 100644 --- a/sys/include/pwm.h +++ b/sys/include/pwm.h @@ -4,16 +4,16 @@ #include struct pwm_state { - int mode; - int pwm_duty; + int mode; + int pwm_duty; }; -#define PWM_MAX_DEV 5 +#define PWM_MAX_DEV 5 -#define PWM_MODE_PWM 0x0001 +#define PWM_MODE_PWM 0x0001 -#define PWM_SET_MODE _IOW('i',1,int) -#define PWM_DUTY _IOW('i',2,int) +#define PWM_SET_MODE _IOW('i',1,int) +#define PWM_DUTY _IOW('i',2,int) #ifdef KERNEL #include "conf.h" diff --git a/sys/include/rdisk.h b/sys/include/rdisk.h index 4760979..7e18d10 100644 --- a/sys/include/rdisk.h +++ b/sys/include/rdisk.h @@ -3,70 +3,70 @@ #include "conf.h" -#define RDISK_FS 0xB7 -#define RDISK_SWAP 0xB8 +#define RDISK_FS 0xB7 +#define RDISK_SWAP 0xB8 -#define RD_DEFAULT 0x00000000UL -#define RD_READONLY 0x00000001UL -#define RD_PREPART 0x00000002UL +#define RD_DEFAULT 0x00000000UL +#define RD_READONLY 0x00000001UL +#define RD_PREPART 0x00000002UL -#define S_SILENT 0x8000 +#define S_SILENT 0x8000 -#define RAMDISK_PARTSPEC(n,t,s,l) \ -m->partitions[n].type=t; \ -m->partitions[n].lbastart=s; \ -m->partitions[n].lbalength=l; +#define RAMDISK_PARTSPEC(n, t, s, l) \ + m->partitions[n].type = t; \ + m->partitions[n].lbastart = s; \ + m->partitions[n].lbalength = l; struct diskentry { - void (*pre_init)(int unit); - int (*init)(int unit,int flag); - int (*deinit)(int unit); - int (*open)(int unit, int mode, int flags); - int (*size)(int unit); - int (*read)(int unit, unsigned int offset, char *data, unsigned int bcount); - int (*write)(int unit, unsigned int offset, char *data, unsigned int bcount); - unsigned char unit; - unsigned int settings; + void (*pre_init)(int unit); + int (*init)(int unit,int flag); + int (*deinit)(int unit); + int (*open)(int unit, int mode, int flags); + int (*size)(int unit); + int (*read)(int unit, unsigned int offset, char *data, unsigned int bcount); + int (*write)(int unit, unsigned int offset, char *data, unsigned int bcount); + unsigned char unit; + unsigned int settings; }; struct diskflags { - unsigned char opens; - unsigned int start[4]; - unsigned int len[4]; - unsigned int blocks; + unsigned char opens; + unsigned int start[4]; + unsigned int len[4]; + unsigned int blocks; } __attribute__((packed)); struct chs { - unsigned char head; - struct { - unsigned cylhigh:2; - unsigned sector:6; - } __attribute__((packed)); - unsigned char cyllow; + unsigned char head; + struct { + unsigned cylhigh : 2; + unsigned sector : 6; + } __attribute__((packed)); + unsigned char cyllow; }__attribute__((packed)); struct partition { -#define P_ACTIVE 0x80 - unsigned char status; - struct chs start; - unsigned char type; - struct chs end; - unsigned long lbastart; - unsigned long lbalength; +#define P_ACTIVE 0x80 + unsigned char status; + struct chs start; + unsigned char type; + struct chs end; + unsigned long lbastart; + unsigned long lbalength; }; struct mbr { - unsigned char bootstrap1[218]; - unsigned short pad0000; - unsigned char biosdrive; - unsigned char secs; - unsigned char mins; - unsigned char hours; - unsigned char bootstrap2[216]; - unsigned int sig; - unsigned short pad0001; - struct partition partitions[4]; - unsigned short bootsig; + unsigned char bootstrap1[218]; + unsigned short pad0000; + unsigned char biosdrive; + unsigned char secs; + unsigned char mins; + unsigned char hours; + unsigned char bootstrap2[216]; + unsigned int sig; + unsigned short pad0001; + struct partition partitions[4]; + unsigned short bootsig; }__attribute__((packed)); #ifdef KERNEL @@ -89,9 +89,9 @@ extern const struct devspec rd0devs[]; extern const struct devspec rd1devs[]; extern const struct devspec rd2devs[]; extern const struct devspec rd3devs[]; -#endif +#endif -#define RDGETMEDIASIZE _IOR('r',1,int) -#define RDREINIT _IO('r',2) +#define RDGETMEDIASIZE _IOR('r', 1, int) +#define RDREINIT _IO('r', 2) #endif diff --git a/sys/include/reboot.h b/sys/include/reboot.h index 91b65ea..b15b326 100644 --- a/sys/include/reboot.h +++ b/sys/include/reboot.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)reboot.h 1.2 (2.11BSD GTE) 1996/5/9 + * @(#)reboot.h 1.2 (2.11BSD GTE) 1996/5/9 */ /* @@ -11,21 +11,21 @@ * These are passed to boot program in r4, * and on to init. */ -#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */ +#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */ -#define RB_ASKNAME 0x001 /* ask for file name to reboot from */ -#define RB_SINGLE 0x002 /* reboot to single user only */ -#define RB_NOSYNC 0x004 /* dont sync before reboot */ -#define RB_HALT 0x008 /* don't reboot, just halt */ -#define RB_INITNAME 0x010 /* name given for /etc/init */ -#define RB_DFLTROOT 0x020 /* use compiled-in rootdev */ -#define RB_DUMP 0x040 /* take a dump before rebooting */ -#define RB_NOFSCK 0x080 /* don't perform fsck's on reboot */ -#define RB_POWRFAIL 0x100 /* reboot caused by power failure */ -#define RB_RDONLY 0x200 /* mount root fs read-only */ -#define RB_AUTODEBUG 0x400 /* init runs autoconfig with "-d" (debug) */ -#define RB_POWEROFF 0x800 /* signal PSU to switch off power */ -#define RB_BOOTLOADER 0x1000 /* reboot into the bootloader */ +#define RB_ASKNAME 0x001 /* ask for file name to reboot from */ +#define RB_SINGLE 0x002 /* reboot to single user only */ +#define RB_NOSYNC 0x004 /* dont sync before reboot */ +#define RB_HALT 0x008 /* don't reboot, just halt */ +#define RB_INITNAME 0x010 /* name given for /etc/init */ +#define RB_DFLTROOT 0x020 /* use compiled-in rootdev */ +#define RB_DUMP 0x040 /* take a dump before rebooting */ +#define RB_NOFSCK 0x080 /* don't perform fsck's on reboot */ +#define RB_POWRFAIL 0x100 /* reboot caused by power failure */ +#define RB_RDONLY 0x200 /* mount root fs read-only */ +#define RB_AUTODEBUG 0x400 /* init runs autoconfig with "-d" (debug) */ +#define RB_POWEROFF 0x800 /* signal PSU to switch off power */ +#define RB_BOOTLOADER 0x1000 /* reboot into the bootloader */ -#define RB_PANIC 0 /* reboot due to panic */ -#define RB_BOOT 1 /* reboot due to boot() */ +#define RB_PANIC 0 /* reboot due to panic */ +#define RB_BOOT 1 /* reboot due to boot() */ diff --git a/sys/include/resource.h b/sys/include/resource.h index 9b50aa9..b178692 100644 --- a/sys/include/resource.h +++ b/sys/include/resource.h @@ -3,88 +3,88 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)resource.h 1.3 (2.11BSD GTE) 1997/2/14 + * @(#)resource.h 1.3 (2.11BSD GTE) 1997/2/14 */ -#ifndef _SYS_RESOURCE_H_ -#define _SYS_RESOURCE_H_ +#ifndef _SYS_RESOURCE_H_ +#define _SYS_RESOURCE_H_ /* * Process priority specifications to get/setpriority. */ -#define PRIO_MIN -20 -#define PRIO_MAX 20 +#define PRIO_MIN -20 +#define PRIO_MAX 20 -#define PRIO_PROCESS 0 -#define PRIO_PGRP 1 -#define PRIO_USER 2 +#define PRIO_PROCESS 0 +#define PRIO_PGRP 1 +#define PRIO_USER 2 /* * Resource utilization information. */ -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN -1 +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 -struct rusage { - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ - long ru_maxrss; -#define ru_first ru_ixrss - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data " */ - long ru_isrss; /* integral unshared stack " */ - long ru_minflt; /* page reclaims */ - long ru_majflt; /* page faults */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary " */ -#define ru_last ru_nivcsw +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ + long ru_maxrss; +#define ru_first ru_ixrss + long ru_ixrss; /* integral shared memory size */ + long ru_idrss; /* integral unshared data " */ + long ru_isrss; /* integral unshared stack " */ + long ru_minflt; /* page reclaims */ + long ru_majflt; /* page faults */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary " */ +#define ru_last ru_nivcsw }; -struct k_rusage { /* KERNEL RUSAGE STRUCTURE */ -#define k_ru_first ru_utime - long ru_utime; /* user time used ('hz' ticks) */ - long ru_stime; /* system time used ('hz' ticks) */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary " */ -#define k_ru_last ru_nivcsw +struct k_rusage { /* KERNEL RUSAGE STRUCTURE */ +#define k_ru_first ru_utime + long ru_utime; /* user time used ('hz' ticks) */ + long ru_stime; /* system time used ('hz' ticks) */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary " */ +#define k_ru_last ru_nivcsw }; /* * Resource limits */ -#define RLIMIT_CPU 0 /* cpu time in milliseconds */ -#define RLIMIT_FSIZE 1 /* maximum file size */ -#define RLIMIT_DATA 2 /* data size */ -#define RLIMIT_STACK 3 /* stack size */ -#define RLIMIT_CORE 4 /* core file size */ -#define RLIMIT_RSS 5 /* resident set size */ +#define RLIMIT_CPU 0 /* cpu time in milliseconds */ +#define RLIMIT_FSIZE 1 /* maximum file size */ +#define RLIMIT_DATA 2 /* data size */ +#define RLIMIT_STACK 3 /* stack size */ +#define RLIMIT_CORE 4 /* core file size */ +#define RLIMIT_RSS 5 /* resident set size */ -#define RLIM_NLIMITS 6 /* number of resource limits */ +#define RLIM_NLIMITS 6 /* number of resource limits */ -#define RLIM_INFINITY 0x7fffffff +#define RLIM_INFINITY 0x7fffffff struct rlimit { - long rlim_cur; /* current (soft) limit */ - long rlim_max; /* maximum value for rlim_cur */ + long rlim_cur; /* current (soft) limit */ + long rlim_max; /* maximum value for rlim_cur */ }; /* Load average structure. */ struct loadavg { - short ldavg[3]; - int fscale; + short ldavg[3]; + int fscale; }; #ifdef KERNEL @@ -104,4 +104,4 @@ int getrusage (int who, struct rusage *usage); #endif -#endif /* !_SYS_RESOURCE_H_ */ +#endif /* !_SYS_RESOURCE_H_ */ diff --git a/sys/include/select.h b/sys/include/select.h index 9828fb6..a62cb78 100644 --- a/sys/include/select.h +++ b/sys/include/select.h @@ -1,6 +1,6 @@ /*- * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. + * 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 @@ -12,8 +12,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -30,11 +30,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)select.h 8.2.1 (2.11BSD) 2000/2/28 + * @(#)select.h 8.2.1 (2.11BSD) 2000/2/28 */ #ifndef _SYS_SELECT_H_ -#define _SYS_SELECT_H_ +#define _SYS_SELECT_H_ #include @@ -44,21 +44,21 @@ * FD_SETSIZE may be defined by the user, but the default here * should be >= NOFILE (param.h). */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 32 +#ifndef FD_SETSIZE +#define FD_SETSIZE 32 #endif -typedef long fd_mask; -#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ +typedef long fd_mask; +#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ -typedef struct fd_set { - fd_mask fds_bits[1]; +typedef struct fd_set { + fd_mask fds_bits[1]; } fd_set; -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) +#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) #ifndef KERNEL #ifndef CROSS @@ -68,7 +68,7 @@ void bzero(void *, unsigned long); /* According to POSIX.1-2001 */ struct timeval; int select (int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, struct timeval *timeout); + fd_set *exceptfds, struct timeval *timeout); #endif /* !KERNEL */ diff --git a/sys/include/signal.h b/sys/include/signal.h index 475dd43..fb345a4 100644 --- a/sys/include/signal.h +++ b/sys/include/signal.h @@ -3,104 +3,104 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#ifndef NSIG +#ifndef NSIG #include -#define NSIG 32 +#define NSIG 32 -#define SIGHUP 1 /* hangup */ -#define SIGINT 2 /* interrupt */ -#define SIGQUIT 3 /* quit */ -#define SIGILL 4 /* illegal instruction (not reset when caught) */ -#define SIGTRAP 5 /* trace trap (not reset when caught) */ -#define SIGIOT 6 /* IOT instruction */ -#define SIGABRT SIGIOT /* compatibility */ -#define SIGEMT 7 /* EMT instruction */ -#define SIGFPE 8 /* floating point exception */ -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGBUS 10 /* bus error */ -#define SIGSEGV 11 /* segmentation violation */ -#define SIGSYS 12 /* bad argument to system call */ -#define SIGPIPE 13 /* write on a pipe with no one to read it */ -#define SIGALRM 14 /* alarm clock */ -#define SIGTERM 15 /* software termination signal from kill */ -#define SIGURG 16 /* urgent condition on IO channel */ -#define SIGSTOP 17 /* sendable stop signal not from tty */ -#define SIGTSTP 18 /* stop signal from tty */ -#define SIGCONT 19 /* continue a stopped process */ -#define SIGCHLD 20 /* to parent on child stop or exit */ -#define SIGCLD SIGCHLD /* compatibility */ -#define SIGTTIN 21 /* to readers pgrp upon background tty read */ -#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ -#define SIGIO 23 /* input/output possible signal */ -#define SIGXCPU 24 /* exceeded CPU time limit */ -#define SIGXFSZ 25 /* exceeded file size limit */ -#define SIGVTALRM 26 /* virtual time alarm */ -#define SIGPROF 27 /* profiling time alarm */ -#define SIGWINCH 28 /* window size changes */ -#define SIGUSR1 30 /* user defined signal 1 */ -#define SIGUSR2 31 /* user defined signal 2 */ +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt */ +#define SIGQUIT 3 /* quit */ +#define SIGILL 4 /* illegal instruction (not reset when caught) */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGIOT 6 /* IOT instruction */ +#define SIGABRT SIGIOT /* compatibility */ +#define SIGEMT 7 /* EMT instruction */ +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGBUS 10 /* bus error */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGSYS 12 /* bad argument to system call */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ +#define SIGURG 16 /* urgent condition on IO channel */ +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGCLD SIGCHLD /* compatibility */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ +#define SIGIO 23 /* input/output possible signal */ +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#define SIGWINCH 28 /* window size changes */ +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ -typedef void (*sig_t) (int); /* type of signal function */ +typedef void (*sig_t) (int); /* type of signal function */ -#define SIG_ERR (sig_t) -1 -#define SIG_DFL (sig_t) 0 -#define SIG_IGN (sig_t) 1 +#define SIG_ERR (sig_t) -1 +#define SIG_DFL (sig_t) 0 +#define SIG_IGN (sig_t) 1 typedef unsigned long sigset_t; /* * Signal vector "template" used in sigaction call. */ -struct sigaction { - sig_t sa_handler; /* signal handler */ - sigset_t sa_mask; /* signal mask to apply */ - int sa_flags; /* see signal options below */ +struct sigaction { + sig_t sa_handler; /* signal handler */ + sigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ }; -#define SA_ONSTACK 0x0001 /* take signal on signal stack */ -#define SA_RESTART 0x0002 /* restart system on signal return */ -#define SA_DISABLE 0x0004 /* disable taking signals on alternate stack */ -#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ +#define SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define SA_RESTART 0x0002 /* restart system on signal return */ +#define SA_DISABLE 0x0004 /* disable taking signals on alternate stack */ +#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ /* * Flags for sigprocmask: */ -#define SIG_BLOCK 1 /* block specified signal set */ -#define SIG_UNBLOCK 2 /* unblock specified signal set */ -#define SIG_SETMASK 3 /* set specified signal set */ +#define SIG_BLOCK 1 /* block specified signal set */ +#define SIG_UNBLOCK 2 /* unblock specified signal set */ +#define SIG_SETMASK 3 /* set specified signal set */ /* * Structure used in sigaltstack call. */ -struct sigaltstack { - char *ss_base; /* signal stack base */ - int ss_size; /* signal stack length */ - int ss_flags; /* SA_DISABLE and/or SA_ONSTACK */ +struct sigaltstack { + char *ss_base; /* signal stack base */ + int ss_size; /* signal stack length */ + int ss_flags; /* SA_DISABLE and/or SA_ONSTACK */ }; -#define MINSIGSTKSZ 128 /* minimum allowable stack */ -#define SIGSTKSZ (MINSIGSTKSZ + 384) /* recommended stack size */ +#define MINSIGSTKSZ 128 /* minimum allowable stack */ +#define SIGSTKSZ (MINSIGSTKSZ + 384) /* recommended stack size */ /* * 4.3 compatibility: * Signal vector "template" used in sigvec call. */ -struct sigvec { - sig_t sv_handler; /* signal handler */ - long sv_mask; /* signal mask to apply */ - int sv_flags; /* see signal options below */ +struct sigvec { + sig_t sv_handler; /* signal handler */ + long sv_mask; /* signal mask to apply */ + int sv_flags; /* see signal options below */ }; -#define SV_ONSTACK SA_ONSTACK /* take signal on signal stack */ -#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ -#define sv_onstack sv_flags /* isn't compatibility wonderful! */ +#define SV_ONSTACK SA_ONSTACK /* take signal on signal stack */ +#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ +#define sv_onstack sv_flags /* isn't compatibility wonderful! */ /* * 4.3 compatibility: * Structure used in sigstack call. */ -struct sigstack { - char *ss_sp; /* signal stack pointer */ - int ss_onstack; /* current status */ +struct sigstack { + char *ss_sp; /* signal stack pointer */ + int ss_onstack; /* current status */ }; /* @@ -110,51 +110,51 @@ struct sigstack { * to the handler to allow it to properly restore state if * a non-standard exit is performed. */ -struct sigcontext { - int sc_onstack; /* sigstack state to restore */ - long sc_mask; /* signal mask to restore */ - int sc_r1; /* r1 to restore */ - int sc_r2; /* and other registers */ - int sc_r3; - int sc_r4; - int sc_r5; - int sc_r6; - int sc_r7; - int sc_r8; - int sc_r9; - int sc_r10; - int sc_r11; - int sc_r12; - int sc_r13; - int sc_r14; - int sc_r15; - int sc_r16; - int sc_r17; - int sc_r18; - int sc_r19; - int sc_r20; - int sc_r21; - int sc_r22; - int sc_r23; - int sc_r24; - int sc_r25; - int sc_gp; - int sc_sp; /* sp to restore */ - int sc_fp; - int sc_ra; - int sc_lo; - int sc_hi; - int sc_pc; /* pc to restore */ +struct sigcontext { + int sc_onstack; /* sigstack state to restore */ + long sc_mask; /* signal mask to restore */ + int sc_r1; /* r1 to restore */ + int sc_r2; /* and other registers */ + int sc_r3; + int sc_r4; + int sc_r5; + int sc_r6; + int sc_r7; + int sc_r8; + int sc_r9; + int sc_r10; + int sc_r11; + int sc_r12; + int sc_r13; + int sc_r14; + int sc_r15; + int sc_r16; + int sc_r17; + int sc_r18; + int sc_r19; + int sc_r20; + int sc_r21; + int sc_r22; + int sc_r23; + int sc_r24; + int sc_r25; + int sc_gp; + int sc_sp; /* sp to restore */ + int sc_fp; + int sc_ra; + int sc_lo; + int sc_hi; + int sc_pc; /* pc to restore */ }; /* * Macro for converting signal number to a mask suitable for * sigblock(). */ -#define sigmask(m) (1L << ((m)-1)) -#define sigaddset(set, signo) (*(set) |= 1L << ((signo) - 1), 0) -#define sigdelset(set, signo) (*(set) &= ~(1L << ((signo) - 1)), 0) -#define sigemptyset(set) (*(set) = (sigset_t)0, (int)0) +#define sigmask(m) (1L << ((m)-1)) +#define sigaddset(set, signo) (*(set) |= 1L << ((signo) - 1), 0) +#define sigdelset(set, signo) (*(set) &= ~(1L << ((signo) - 1)), 0) +#define sigemptyset(set) (*(set) = (sigset_t)0, (int)0) #define sigfillset(set) (*(set) = ~(sigset_t)0, (int)0) #define sigismember(set, signo) ((*(set) & (1L << ((signo) - 1))) != 0) @@ -182,8 +182,6 @@ int sigprocmask (int how, const sigset_t *set, sigset_t *oldset); int siginterrupt (int sig, int flag); int sigsuspend (const sigset_t *mask); -#define BADSIG SIG_ERR - #endif /* KERNEL */ #endif /* NSIG */ diff --git a/sys/include/signalvar.h b/sys/include/signalvar.h index 537d600..8be847a 100644 --- a/sys/include/signalvar.h +++ b/sys/include/signalvar.h @@ -1,6 +1,6 @@ /* * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * 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 @@ -12,8 +12,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -30,8 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ -#define _SYS_SIGNALVAR_H_ +#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ +#define _SYS_SIGNALVAR_H_ /* * Kernel signal definitions and data structures, @@ -41,12 +41,12 @@ */ /* signal flags */ -#define SAS_OLDMASK 0x01 /* need to restore mask before pause */ -#define SAS_ALTSTACK 0x02 /* have alternate signal stack */ +#define SAS_OLDMASK 0x01 /* need to restore mask before pause */ +#define SAS_ALTSTACK 0x02 /* have alternate signal stack */ /* additional signal action values, used only temporarily/internally */ -#define SIG_CATCH (sig_t) 2 -#define SIG_HOLD (sig_t) 3 +#define SIG_CATCH (sig_t) 2 +#define SIG_HOLD (sig_t) 3 /* * Determine signal that should be delivered to process p, the current @@ -56,65 +56,64 @@ * This probably should be a routine (assembly) instead of a macro due * to the voluminous code generated by all of the 'long' operations. */ -#define CURSIG(p) \ - (((p)->p_sig == 0 || \ - (((p)->p_flag & P_TRACED) == 0 && \ - ((p)->p_sig & ~(p)->p_sigmask) == 0)) ? \ - 0 : issignal(p)) +#define CURSIG(p) (((p)->p_sig == 0 || \ + (((p)->p_flag & P_TRACED) == 0 && \ + ((p)->p_sig & ~(p)->p_sigmask) == 0)) ? \ + 0 : issignal(p)) /* * Signal properties and actions. * The array below categorizes the signals and their default actions * according to the following properties: */ -#define SA_KILL 0x01 /* terminates process by default */ -#define SA_CORE 0x02 /* ditto and coredumps */ -#define SA_STOP 0x04 /* suspend process */ -#define SA_TTYSTOP 0x08 /* ditto, from tty */ -#define SA_IGNORE 0x10 /* ignore by default */ -#define SA_CONT 0x20 /* continue if suspended */ +#define SA_KILL 0x01 /* terminates process by default */ +#define SA_CORE 0x02 /* ditto and coredumps */ +#define SA_STOP 0x04 /* suspend process */ +#define SA_TTYSTOP 0x08 /* ditto, from tty */ +#define SA_IGNORE 0x10 /* ignore by default */ +#define SA_CONT 0x20 /* continue if suspended */ -#ifdef SIGPROP +#ifdef SIGPROP const char sigprop [NSIG + 1] = { - 0, /* unused */ - SA_KILL, /* SIGHUP */ - SA_KILL, /* SIGINT */ - SA_KILL | SA_CORE, /* SIGQUIT */ - SA_KILL | SA_CORE, /* SIGILL */ - SA_KILL | SA_CORE, /* SIGTRAP */ - SA_KILL | SA_CORE, /* SIGABRT */ - SA_KILL | SA_CORE, /* SIGEMT */ - SA_KILL | SA_CORE, /* SIGFPE */ - SA_KILL, /* SIGKILL */ - SA_KILL | SA_CORE, /* SIGBUS */ - SA_KILL | SA_CORE, /* SIGSEGV */ - SA_KILL | SA_CORE, /* SIGSYS */ - SA_KILL, /* SIGPIPE */ - SA_KILL, /* SIGALRM */ - SA_KILL, /* SIGTERM */ - SA_IGNORE, /* SIGURG */ - SA_STOP, /* SIGSTOP */ - SA_STOP | SA_TTYSTOP, /* SIGTSTP */ - SA_IGNORE | SA_CONT, /* SIGCONT */ - SA_IGNORE, /* SIGCHLD */ - SA_STOP | SA_TTYSTOP, /* SIGTTIN */ - SA_STOP | SA_TTYSTOP, /* SIGTTOU */ - SA_IGNORE, /* SIGIO */ - SA_KILL, /* SIGXCPU */ - SA_KILL, /* SIGXFSZ */ - SA_KILL, /* SIGVTALRM */ - SA_KILL, /* SIGPROF */ - SA_IGNORE, /* SIGWINCH */ - SA_IGNORE, /* SIGINFO */ - SA_KILL, /* SIGUSR1 */ - SA_KILL, /* SIGUSR2 */ + 0, /* unused */ + SA_KILL, /* SIGHUP */ + SA_KILL, /* SIGINT */ + SA_KILL | SA_CORE, /* SIGQUIT */ + SA_KILL | SA_CORE, /* SIGILL */ + SA_KILL | SA_CORE, /* SIGTRAP */ + SA_KILL | SA_CORE, /* SIGABRT */ + SA_KILL | SA_CORE, /* SIGEMT */ + SA_KILL | SA_CORE, /* SIGFPE */ + SA_KILL, /* SIGKILL */ + SA_KILL | SA_CORE, /* SIGBUS */ + SA_KILL | SA_CORE, /* SIGSEGV */ + SA_KILL | SA_CORE, /* SIGSYS */ + SA_KILL, /* SIGPIPE */ + SA_KILL, /* SIGALRM */ + SA_KILL, /* SIGTERM */ + SA_IGNORE, /* SIGURG */ + SA_STOP, /* SIGSTOP */ + SA_STOP | SA_TTYSTOP, /* SIGTSTP */ + SA_IGNORE | SA_CONT, /* SIGCONT */ + SA_IGNORE, /* SIGCHLD */ + SA_STOP | SA_TTYSTOP, /* SIGTTIN */ + SA_STOP | SA_TTYSTOP, /* SIGTTOU */ + SA_IGNORE, /* SIGIO */ + SA_KILL, /* SIGXCPU */ + SA_KILL, /* SIGXFSZ */ + SA_KILL, /* SIGVTALRM */ + SA_KILL, /* SIGPROF */ + SA_IGNORE, /* SIGWINCH */ + SA_IGNORE, /* SIGINFO */ + SA_KILL, /* SIGUSR1 */ + SA_KILL, /* SIGUSR2 */ }; #endif /* SIGPROP */ -#ifdef KERNEL -#define contsigmask (sigmask(SIGCONT)) -#define stopsigmask (sigmask(SIGSTOP) | sigmask(SIGTSTP) | \ - sigmask(SIGTTIN) | sigmask(SIGTTOU)) -#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) +#ifdef KERNEL +#define contsigmask (sigmask(SIGCONT)) +#define stopsigmask (sigmask(SIGSTOP) | sigmask(SIGTSTP) | \ + sigmask(SIGTTIN) | sigmask(SIGTTOU)) +#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) #endif -#endif /* !_SYS_SIGNALVAR_H_ */ +#endif /* !_SYS_SIGNALVAR_H_ */ diff --git a/sys/include/spi.h b/sys/include/spi.h index 1b670b1..8930e70 100644 --- a/sys/include/spi.h +++ b/sys/include/spi.h @@ -7,7 +7,7 @@ /* * Ioctl definitions for SPI driver. */ -#ifndef _SPI_H +#ifndef _SPI_H #define _SPI_H #include @@ -20,17 +20,17 @@ #define SPICTL_IO16(n) _ION('p', 4, n) /* transfer n*16 bits */ #define SPICTL_IO32(n) _ION('p', 5, n) /* transfer n*32 bits */ -#define SPICTL_IO8R(n) _ION('p', 6, n) /* transfer R n*8 bits */ -#define SPICTL_IO16R(n) _ION('p', 7, n) /* transfer R n*16 bits */ -#define SPICTL_IO32R(n) _ION('p', 8, n) /* transfer R n*32 bits */ +#define SPICTL_IO8R(n) _ION('p', 6, n) /* transfer R n*8 bits */ +#define SPICTL_IO16R(n) _ION('p', 7, n) /* transfer R n*16 bits */ +#define SPICTL_IO32R(n) _ION('p', 8, n) /* transfer R n*32 bits */ -#define SPICTL_IO8W(n) _ION('p', 9, n) /* transfer W n*8 bits */ -#define SPICTL_IO16W(n) _ION('p', 10, n) /* transfer W n*16 bits */ -#define SPICTL_IO32W(n) _ION('p', 11, n) /* transfer W n*32 bits */ +#define SPICTL_IO8W(n) _ION('p', 9, n) /* transfer W n*8 bits */ +#define SPICTL_IO16W(n) _ION('p', 10, n) /* transfer W n*16 bits */ +#define SPICTL_IO32W(n) _ION('p', 11, n) /* transfer W n*32 bits */ -#define SPICTL_IO32B(n) _ION('p', 12, n) /* transfer BE n*32 bits */ -#define SPICTL_IO32RB(n) _ION('p', 13, n) /* transfer RBE n*32 bits */ -#define SPICTL_IO32WB(n) _ION('p', 14, n) /* transfer WBE n*32 bits */ +#define SPICTL_IO32B(n) _ION('p', 12, n) /* transfer BE n*32 bits */ +#define SPICTL_IO32RB(n) _ION('p', 13, n) /* transfer RBE n*32 bits */ +#define SPICTL_IO32WB(n) _ION('p', 14, n) /* transfer WBE n*32 bits */ #ifdef KERNEL #include "conf.h" diff --git a/sys/include/spi_bus.h b/sys/include/spi_bus.h index 7c806ec..04cb7e7 100644 --- a/sys/include/spi_bus.h +++ b/sys/include/spi_bus.h @@ -4,30 +4,30 @@ #ifdef KERNEL struct spireg { - volatile unsigned con; /* Control */ + volatile unsigned con; /* Control */ volatile unsigned conclr; volatile unsigned conset; volatile unsigned coninv; - volatile unsigned stat; /* Status */ + volatile unsigned stat; /* Status */ volatile unsigned statclr; volatile unsigned statset; volatile unsigned statinv; - volatile unsigned buf; /* Transmit and receive buffer */ + volatile unsigned buf; /* Transmit and receive buffer */ volatile unsigned unused1; volatile unsigned unused2; volatile unsigned unused3; - volatile unsigned brg; /* Baud rate generator */ + volatile unsigned brg; /* Baud rate generator */ volatile unsigned brgclr; volatile unsigned brgset; volatile unsigned brginv; }; struct spi_dev { - struct spireg *bus; - unsigned int *cs_tris; - unsigned int cs_pin; - unsigned int baud; - unsigned int mode; + struct spireg *bus; + unsigned int *cs_tris; + unsigned int cs_pin; + unsigned int baud; + unsigned int mode; }; extern int spi_open(unsigned int bus, unsigned int *tris, unsigned int pin); diff --git a/sys/include/stat.h b/sys/include/stat.h index 00ceab3..2c39159 100644 --- a/sys/include/stat.h +++ b/sys/include/stat.h @@ -3,70 +3,70 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ -#ifndef _STAT_H_ -#define _STAT_H_ +#ifndef _STAT_H_ +#define _STAT_H_ #include -struct stat +struct stat { - dev_t st_dev; - ino_t st_ino; - u_int st_mode; - int st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - off_t st_size; - time_t st_atime; - time_t st_mtime; - time_t st_ctime; - long st_blksize; - long st_blocks; - u_int st_flags; + dev_t st_dev; + ino_t st_ino; + u_int st_mode; + int st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + off_t st_size; + time_t st_atime; + time_t st_mtime; + time_t st_ctime; + long st_blksize; + long st_blocks; + u_int st_flags; }; -#define S_IFMT 0170000 /* type of file */ -#define S_IFDIR 0040000 /* directory */ -#define S_IFCHR 0020000 /* character special */ -#define S_IFBLK 0060000 /* block special */ -#define S_IFREG 0100000 /* regular */ -#define S_IFLNK 0120000 /* symbolic link */ -#define S_IFSOCK 0140000/* socket */ -#define S_ISUID 0004000 /* set user id on execution */ -#define S_ISGID 0002000 /* set group id on execution */ -#define S_ISVTX 0001000 /* save swapped text even after use */ -#define S_IREAD 0000400 /* read permission, owner */ -#define S_IWRITE 0000200 /* write permission, owner */ -#define S_IEXEC 0000100 /* execute/search permission, owner */ +#define S_IFMT 0170000 /* type of file */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFCHR 0020000 /* character special */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#define S_IREAD 0000400 /* read permission, owner */ +#define S_IWRITE 0000200 /* write permission, owner */ +#define S_IEXEC 0000100 /* execute/search permission, owner */ /* * Definitions of flags in mode that are 4.4 compatible. */ -#define S_IFIFO 0010000 /* named pipe (fifo) - Not used by 2.11BSD */ +#define S_IFIFO 0010000 /* named pipe (fifo) - Not used by 2.11BSD */ -#define S_IRWXU 0000700 /* RWX mask for owner */ -#define S_IRUSR 0000400 /* R for owner */ -#define S_IWUSR 0000200 /* W for owner */ -#define S_IXUSR 0000100 /* X for owner */ +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ -#define S_IRWXG 0000070 /* RWX mask for group */ -#define S_IRGRP 0000040 /* R for group */ -#define S_IWGRP 0000020 /* W for group */ -#define S_IXGRP 0000010 /* X for group */ +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ -#define S_IRWXO 0000007 /* RWX mask for other */ -#define S_IROTH 0000004 /* R for other */ -#define S_IWOTH 0000002 /* W for other */ -#define S_IXOTH 0000001 /* X for other */ +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ -#define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR) /* directory */ -#define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR) /* character special */ -#define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK) /* block special */ -#define S_ISREG(m) ((m & S_IFMT) == S_IFREG) /* regular */ -#define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) /* symbolic link */ -#define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK) /* socket */ +#define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR) /* directory */ +#define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR) /* character special */ +#define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK) /* block special */ +#define S_ISREG(m) ((m & S_IFMT) == S_IFREG) /* regular */ +#define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) /* symbolic link */ +#define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK) /* socket */ /* * Definitions of flags stored in file flags word. Different from 4.4 because @@ -76,24 +76,24 @@ struct stat * * Super-user and owner changeable flags. */ -#define UF_SETTABLE 0x00ff /* mask of owner changeable flags */ -#define UF_NODUMP 0x0001 /* do not dump file */ -#define UF_IMMUTABLE 0x0002 /* file may not be changed */ -#define UF_APPEND 0x0004 /* writes to file may only append */ +#define UF_SETTABLE 0x00ff /* mask of owner changeable flags */ +#define UF_NODUMP 0x0001 /* do not dump file */ +#define UF_IMMUTABLE 0x0002 /* file may not be changed */ +#define UF_APPEND 0x0004 /* writes to file may only append */ /* * Super-user changeable flags. */ -#define SF_SETTABLE 0xff00 /* mask of superuser changeable flags */ -#define SF_ARCHIVED 0x0100 /* file is archived */ -#define SF_IMMUTABLE 0x0200 /* file may not be changed */ -#define SF_APPEND 0x0400 /* writes to file may only append */ +#define SF_SETTABLE 0xff00 /* mask of superuser changeable flags */ +#define SF_ARCHIVED 0x0100 /* file is archived */ +#define SF_IMMUTABLE 0x0200 /* file may not be changed */ +#define SF_APPEND 0x0400 /* writes to file may only append */ #ifdef KERNEL /* * Shorthand abbreviations of above. */ -#define APPEND (UF_APPEND | SF_APPEND) -#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) +#define APPEND (UF_APPEND | SF_APPEND) +#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) #else int chmod (const char *path, mode_t mode); diff --git a/sys/include/sysctl.h b/sys/include/sysctl.h index 53c7228..6356684 100644 --- a/sys/include/sysctl.h +++ b/sys/include/sysctl.h @@ -1,6 +1,6 @@ /* * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Mike Karels at Berkeley Software Design, Inc. @@ -15,8 +15,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -34,7 +34,7 @@ * SUCH DAMAGE. */ #ifndef _SYS_SYSCTL_H_ -#define _SYS_SYSCTL_H_ +#define _SYS_SYSCTL_H_ /* * These are for the eproc, etext, einode, efile and map structures. @@ -58,7 +58,7 @@ * respective subsystem header files. */ -#define CTL_MAXNAME 12 /* largest number of components supported */ +#define CTL_MAXNAME 12 /* largest number of components supported */ /* * Each subsystem defined by sysctl defines a list of variables @@ -68,219 +68,219 @@ * pairs to be used by sysctl(1) in manipulating the subsystem. */ struct ctlname { - char *ctl_name; /* subsystem name */ - int ctl_type; /* type of name */ + char *ctl_name; /* subsystem name */ + int ctl_type; /* type of name */ }; -#define CTLTYPE_NODE 1 /* name is a node */ -#define CTLTYPE_INT 2 /* name describes a 16-bit integer */ -#define CTLTYPE_STRING 3 /* name describes a string */ -#define CTLTYPE_LONG 4 /* name describes a 32-bit number */ -#define CTLTYPE_STRUCT 5 /* name describes a structure */ +#define CTLTYPE_NODE 1 /* name is a node */ +#define CTLTYPE_INT 2 /* name describes a 16-bit integer */ +#define CTLTYPE_STRING 3 /* name describes a string */ +#define CTLTYPE_LONG 4 /* name describes a 32-bit number */ +#define CTLTYPE_STRUCT 5 /* name describes a structure */ /* * Top-level identifiers */ -#define CTL_UNSPEC 0 /* unused */ -#define CTL_KERN 1 /* "high kernel": proc, limits */ -#define CTL_VM 2 /* virtual memory */ -#define CTL_FS 3 /* file system, mount type is next */ -#define CTL_NET 4 /* network, see socket.h */ -#define CTL_DEBUG 5 /* debugging parameters */ -#define CTL_HW 6 /* generic cpu/io */ -#define CTL_MACHDEP 7 /* machine dependent */ -#define CTL_USER 8 /* user-level */ -#define CTL_MAXID 9 /* number of valid top-level ids */ +#define CTL_UNSPEC 0 /* unused */ +#define CTL_KERN 1 /* "high kernel": proc, limits */ +#define CTL_VM 2 /* virtual memory */ +#define CTL_FS 3 /* file system, mount type is next */ +#define CTL_NET 4 /* network, see socket.h */ +#define CTL_DEBUG 5 /* debugging parameters */ +#define CTL_HW 6 /* generic cpu/io */ +#define CTL_MACHDEP 7 /* machine dependent */ +#define CTL_USER 8 /* user-level */ +#define CTL_MAXID 9 /* number of valid top-level ids */ -#ifndef KERNEL +#ifndef KERNEL #define CTL_NAMES { \ - { 0, 0 }, \ - { "kern", CTLTYPE_NODE }, \ - { "vm", CTLTYPE_NODE }, \ - { "fs", CTLTYPE_NODE }, \ - { "net", CTLTYPE_NODE }, \ - { "debug", CTLTYPE_NODE }, \ - { "hw", CTLTYPE_NODE }, \ - { "machdep", CTLTYPE_NODE }, \ - { "user", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { "kern", CTLTYPE_NODE }, \ + { "vm", CTLTYPE_NODE }, \ + { "fs", CTLTYPE_NODE }, \ + { "net", CTLTYPE_NODE }, \ + { "debug", CTLTYPE_NODE }, \ + { "hw", CTLTYPE_NODE }, \ + { "machdep", CTLTYPE_NODE }, \ + { "user", CTLTYPE_NODE }, \ } #endif /* * CTL_KERN identifiers */ -#define KERN_OSTYPE 1 /* string: system version */ -#define KERN_OSRELEASE 2 /* string: system release */ -#define KERN_OSREV 3 /* int: system revision */ -#define KERN_VERSION 4 /* string: compile time info */ -#define KERN_MAXINODES 5 /* int: max inodes */ -#define KERN_MAXPROC 6 /* int: max processes */ -#define KERN_MAXFILES 7 /* int: max open files */ -#define KERN_ARGMAX 8 /* int: max arguments to exec */ -#define KERN_SECURELVL 9 /* int: system security level */ -#define KERN_HOSTNAME 10 /* string: hostname */ -#define KERN_HOSTID 11 /* int: host identifier */ -#define KERN_CLOCKRATE 12 /* struct: struct clockrate */ -#define KERN_INODE 13 /* struct: inode structures */ -#define KERN_PROC 14 /* struct: process entries */ -#define KERN_FILE 15 /* struct: file entries */ -#define KERN_PROF 16 /* node: kernel profiling info */ -#define KERN_POSIX1 17 /* int: POSIX.1 version */ -#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ -#define KERN_JOB_CONTROL 19 /* int: is job control available */ -#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ -#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ -#define KERN_MAXTEXTS 22 /* int: # of text entries */ -#define KERN_TEXT 23 /* struct: text entries */ -#define KERN_ACCTTHRESH 24 /* int: accounting daemon threshold */ -#define KERN_MAXID 25 /* number of valid kern ids */ +#define KERN_OSTYPE 1 /* string: system version */ +#define KERN_OSRELEASE 2 /* string: system release */ +#define KERN_OSREV 3 /* int: system revision */ +#define KERN_VERSION 4 /* string: compile time info */ +#define KERN_MAXINODES 5 /* int: max inodes */ +#define KERN_MAXPROC 6 /* int: max processes */ +#define KERN_MAXFILES 7 /* int: max open files */ +#define KERN_ARGMAX 8 /* int: max arguments to exec */ +#define KERN_SECURELVL 9 /* int: system security level */ +#define KERN_HOSTNAME 10 /* string: hostname */ +#define KERN_HOSTID 11 /* int: host identifier */ +#define KERN_CLOCKRATE 12 /* struct: struct clockrate */ +#define KERN_INODE 13 /* struct: inode structures */ +#define KERN_PROC 14 /* struct: process entries */ +#define KERN_FILE 15 /* struct: file entries */ +#define KERN_PROF 16 /* node: kernel profiling info */ +#define KERN_POSIX1 17 /* int: POSIX.1 version */ +#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ +#define KERN_JOB_CONTROL 19 /* int: is job control available */ +#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ +#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ +#define KERN_MAXTEXTS 22 /* int: # of text entries */ +#define KERN_TEXT 23 /* struct: text entries */ +#define KERN_ACCTTHRESH 24 /* int: accounting daemon threshold */ +#define KERN_MAXID 25 /* number of valid kern ids */ -#ifndef KERNEL +#ifndef KERNEL #define CTL_KERN_NAMES { \ - { 0, 0 }, \ - { "ostype", CTLTYPE_STRING }, \ - { "osrelease", CTLTYPE_STRING }, \ - { "osrevision", CTLTYPE_LONG }, \ - { "version", CTLTYPE_STRING }, \ - { "maxinodes", CTLTYPE_INT }, \ - { "maxproc", CTLTYPE_INT }, \ - { "maxfiles", CTLTYPE_INT }, \ - { "argmax", CTLTYPE_INT }, \ - { "securelevel", CTLTYPE_INT }, \ - { "hostname", CTLTYPE_STRING }, \ - { "hostid", CTLTYPE_LONG }, \ - { "clockrate", CTLTYPE_STRUCT }, \ - { "inode", CTLTYPE_STRUCT }, \ - { "proc", CTLTYPE_STRUCT }, \ - { "file", CTLTYPE_STRUCT }, \ - { "profiling", CTLTYPE_NODE }, \ - { "posix1version", CTLTYPE_INT }, \ - { "ngroups", CTLTYPE_INT }, \ - { "job_control", CTLTYPE_INT }, \ - { "saved_ids", CTLTYPE_INT }, \ - { "boottime", CTLTYPE_STRUCT }, \ - { "maxtexts", CTLTYPE_INT }, \ - { "text", CTLTYPE_STRUCT }, \ - { "acctthresh", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "ostype", CTLTYPE_STRING }, \ + { "osrelease", CTLTYPE_STRING }, \ + { "osrevision", CTLTYPE_LONG }, \ + { "version", CTLTYPE_STRING }, \ + { "maxinodes", CTLTYPE_INT }, \ + { "maxproc", CTLTYPE_INT }, \ + { "maxfiles", CTLTYPE_INT }, \ + { "argmax", CTLTYPE_INT }, \ + { "securelevel", CTLTYPE_INT }, \ + { "hostname", CTLTYPE_STRING }, \ + { "hostid", CTLTYPE_LONG }, \ + { "clockrate", CTLTYPE_STRUCT }, \ + { "inode", CTLTYPE_STRUCT }, \ + { "proc", CTLTYPE_STRUCT }, \ + { "file", CTLTYPE_STRUCT }, \ + { "profiling", CTLTYPE_NODE }, \ + { "posix1version", CTLTYPE_INT }, \ + { "ngroups", CTLTYPE_INT }, \ + { "job_control", CTLTYPE_INT }, \ + { "saved_ids", CTLTYPE_INT }, \ + { "boottime", CTLTYPE_STRUCT }, \ + { "maxtexts", CTLTYPE_INT }, \ + { "text", CTLTYPE_STRUCT }, \ + { "acctthresh", CTLTYPE_INT }, \ } #endif /* * KERN_PROC subtypes */ -#define KERN_PROC_ALL 0 /* everything */ -#define KERN_PROC_PID 1 /* by process id */ -#define KERN_PROC_PGRP 2 /* by process group id */ -#define KERN_PROC_SESSION 3 /* by session of pid - NOT IN 2.11 */ -#define KERN_PROC_TTY 4 /* by controlling tty */ -#define KERN_PROC_UID 5 /* by effective uid */ -#define KERN_PROC_RUID 6 /* by real uid */ +#define KERN_PROC_ALL 0 /* everything */ +#define KERN_PROC_PID 1 /* by process id */ +#define KERN_PROC_PGRP 2 /* by process group id */ +#define KERN_PROC_SESSION 3 /* by session of pid - NOT IN 2.11 */ +#define KERN_PROC_TTY 4 /* by controlling tty */ +#define KERN_PROC_UID 5 /* by effective uid */ +#define KERN_PROC_RUID 6 /* by real uid */ /* * KERN_PROC subtype ops return arrays of augmented proc structures: */ struct kinfo_proc { - struct proc kp_proc; /* proc structure */ - struct eproc { - struct proc *e_paddr; /* address of proc */ - dev_t e_tdev; /* controlling tty dev */ - pid_t e_tpgid; /* tty process group id */ - uid_t e_ruid; /* real uid */ - } kp_eproc; + struct proc kp_proc; /* proc structure */ + struct eproc { + struct proc *e_paddr; /* address of proc */ + dev_t e_tdev; /* controlling tty dev */ + pid_t e_tpgid; /* tty process group id */ + uid_t e_ruid; /* real uid */ + } kp_eproc; }; /* * KERN_INODE returns an array of augmented inode structures: */ -struct kinfo_inode { - struct inode *kp_inodep; /* address of inode */ - struct inode kp_inode; /* inode structure */ +struct kinfo_inode { + struct inode *kp_inodep; /* address of inode */ + struct inode kp_inode; /* inode structure */ }; /* * KERN_FILE returns an array of augmented file structures: */ -struct kinfo_file { - struct file *kp_filep; /* address of file */ - struct file kp_file; /* file structure */ +struct kinfo_file { + struct file *kp_filep; /* address of file */ + struct file kp_file; /* file structure */ }; /* * CTL_HW identifiers */ -#define HW_MACHINE 1 /* string: machine class */ -#define HW_MODEL 2 /* string: specific machine model */ -#define HW_NCPU 3 /* int: number of cpus */ -#define HW_BYTEORDER 4 /* int: machine byte order */ -#define HW_PHYSMEM 5 /* int: total memory */ -#define HW_USERMEM 6 /* int: non-kernel memory */ -#define HW_PAGESIZE 7 /* int: software page size */ -#define HW_DISKNAMES 8 /* strings: disk drive names */ -#define HW_DISKSTATS 9 /* struct: diskstats[] */ -#define HW_MAXID 10 /* number of valid hw ids */ +#define HW_MACHINE 1 /* string: machine class */ +#define HW_MODEL 2 /* string: specific machine model */ +#define HW_NCPU 3 /* int: number of cpus */ +#define HW_BYTEORDER 4 /* int: machine byte order */ +#define HW_PHYSMEM 5 /* int: total memory */ +#define HW_USERMEM 6 /* int: non-kernel memory */ +#define HW_PAGESIZE 7 /* int: software page size */ +#define HW_DISKNAMES 8 /* strings: disk drive names */ +#define HW_DISKSTATS 9 /* struct: diskstats[] */ +#define HW_MAXID 10 /* number of valid hw ids */ -#ifndef KERNEL +#ifndef KERNEL #define CTL_HW_NAMES { \ - { 0, 0 }, \ - { "machine", CTLTYPE_STRING }, \ - { "model", CTLTYPE_STRING }, \ - { "ncpu", CTLTYPE_INT }, \ - { "byteorder", CTLTYPE_INT }, \ - { "physmem", CTLTYPE_LONG }, \ - { "usermem", CTLTYPE_LONG }, \ - { "pagesize", CTLTYPE_INT }, \ - { "disknames", CTLTYPE_STRUCT }, \ - { "diskstats", CTLTYPE_STRUCT }, \ + { 0, 0 }, \ + { "machine", CTLTYPE_STRING }, \ + { "model", CTLTYPE_STRING }, \ + { "ncpu", CTLTYPE_INT }, \ + { "byteorder", CTLTYPE_INT }, \ + { "physmem", CTLTYPE_LONG }, \ + { "usermem", CTLTYPE_LONG }, \ + { "pagesize", CTLTYPE_INT }, \ + { "disknames", CTLTYPE_STRUCT }, \ + { "diskstats", CTLTYPE_STRUCT }, \ } #endif -#ifndef KERNEL +#ifndef KERNEL /* * CTL_USER definitions */ -#define USER_CS_PATH 1 /* string: _CS_PATH */ -#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ -#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ -#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ -#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ -#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ -#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ -#define USER_LINE_MAX 8 /* int: LINE_MAX */ -#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ -#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ -#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ -#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ -#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ -#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ -#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ -#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ -#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ -#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ -#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ -#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ -#define USER_MAXID 21 /* number of valid user ids */ +#define USER_CS_PATH 1 /* string: _CS_PATH */ +#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ +#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ +#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ +#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ +#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ +#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ +#define USER_LINE_MAX 8 /* int: LINE_MAX */ +#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ +#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ +#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ +#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ +#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ +#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ +#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ +#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ +#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ +#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ +#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ +#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ +#define USER_MAXID 21 /* number of valid user ids */ -#define CTL_USER_NAMES { \ - { 0, 0 }, \ - { "cs_path", CTLTYPE_STRING }, \ - { "bc_base_max", CTLTYPE_INT }, \ - { "bc_dim_max", CTLTYPE_INT }, \ - { "bc_scale_max", CTLTYPE_INT }, \ - { "bc_string_max", CTLTYPE_INT }, \ - { "coll_weights_max", CTLTYPE_INT }, \ - { "expr_nest_max", CTLTYPE_INT }, \ - { "line_max", CTLTYPE_INT }, \ - { "re_dup_max", CTLTYPE_INT }, \ - { "posix2_version", CTLTYPE_INT }, \ - { "posix2_c_bind", CTLTYPE_INT }, \ - { "posix2_c_dev", CTLTYPE_INT }, \ - { "posix2_char_term", CTLTYPE_INT }, \ - { "posix2_fort_dev", CTLTYPE_INT }, \ - { "posix2_fort_run", CTLTYPE_INT }, \ - { "posix2_localedef", CTLTYPE_INT }, \ - { "posix2_sw_dev", CTLTYPE_INT }, \ - { "posix2_upe", CTLTYPE_INT }, \ - { "stream_max", CTLTYPE_INT }, \ - { "tzname_max", CTLTYPE_INT }, \ +#define CTL_USER_NAMES { \ + { 0, 0 }, \ + { "cs_path", CTLTYPE_STRING }, \ + { "bc_base_max", CTLTYPE_INT }, \ + { "bc_dim_max", CTLTYPE_INT }, \ + { "bc_scale_max", CTLTYPE_INT }, \ + { "bc_string_max", CTLTYPE_INT }, \ + { "coll_weights_max", CTLTYPE_INT }, \ + { "expr_nest_max", CTLTYPE_INT }, \ + { "line_max", CTLTYPE_INT }, \ + { "re_dup_max", CTLTYPE_INT }, \ + { "posix2_version", CTLTYPE_INT }, \ + { "posix2_c_bind", CTLTYPE_INT }, \ + { "posix2_c_dev", CTLTYPE_INT }, \ + { "posix2_char_term", CTLTYPE_INT }, \ + { "posix2_fort_dev", CTLTYPE_INT }, \ + { "posix2_fort_run", CTLTYPE_INT }, \ + { "posix2_localedef", CTLTYPE_INT }, \ + { "posix2_sw_dev", CTLTYPE_INT }, \ + { "posix2_upe", CTLTYPE_INT }, \ + { "stream_max", CTLTYPE_INT }, \ + { "tzname_max", CTLTYPE_INT }, \ } #endif @@ -290,22 +290,22 @@ struct kinfo_file { * Second level identifier specifies which debug variable. * Third level identifier specifies which stucture component. */ -#define CTL_DEBUG_NAME 0 /* string: variable name */ -#define CTL_DEBUG_VALUE 1 /* int: variable value */ -#define CTL_DEBUG_MAXID 20 +#define CTL_DEBUG_NAME 0 /* string: variable name */ +#define CTL_DEBUG_VALUE 1 /* int: variable value */ +#define CTL_DEBUG_MAXID 20 /* * Locking and stats */ struct sysctl_lock { - int sl_lock; - int sl_want; - int sl_locked; + int sl_lock; + int sl_want; + int sl_locked; }; -#ifdef KERNEL +#ifdef KERNEL -#ifdef DEBUG +#ifdef DEBUG /* * CTL_DEBUG variables. * @@ -319,34 +319,34 @@ struct sysctl_lock { * entered into the array. */ struct ctldebug { - char *debugname; /* name of debugging variable */ - int *debugvar; /* pointer to debugging variable */ + char *debugname; /* name of debugging variable */ + int *debugvar; /* pointer to debugging variable */ }; extern struct ctldebug debug0, debug1, debug2, debug3, debug4; extern struct ctldebug debug5, debug6, debug7, debug8, debug9; extern struct ctldebug debug10, debug11, debug12, debug13, debug14; extern struct ctldebug debug15, debug16, debug17, debug18, debug19; -#endif /* DEBUG */ +#endif /* DEBUG */ struct sysctl_lock memlock; /* * Internal sysctl function calling convention: * - * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen); + * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen); * * The name parameter points at the next component of the name to be * interpreted. The namelen parameter is the number of integers in * the name. */ typedef int (sysctlfn) (int *name, u_int namelen, - void *oldp, size_t *oldlenp, void *newp, size_t newlen); + void *oldp, size_t *oldlenp, void *newp, size_t newlen); /* * Get old / set new parameters for an integer value. */ int sysctl_int (void *oldp, size_t *oldlenp, - void *newp, size_t newlen, int *valp); + void *newp, size_t newlen, int *valp); /* * As above, but read-only. @@ -357,7 +357,7 @@ int sysctl_rdint (void *oldp, size_t *oldlenp, void *newp, int val); * Get old / set new parameters for an long value. */ int sysctl_long (void *oldp, size_t *oldlenp, - void *newp, size_t newlen, long *valp); + void *newp, size_t newlen, long *valp); /* * As above, but read-only. @@ -365,10 +365,10 @@ int sysctl_long (void *oldp, size_t *oldlenp, int sysctl_rdlong (void *oldp, size_t *oldlenp, void *newp, long val); /* - * Get old / set new parameters for a string value. + * Get old / set new parameters for a string value. */ int sysctl_string (void *oldp, size_t *oldlenp, - void *newp, size_t newlen, char *str, int maxlen); + void *newp, size_t newlen, char *str, int maxlen); /* * As above, but read-only. @@ -379,15 +379,15 @@ int sysctl_rdstring (void *oldp, size_t *oldlenp, void *newp, const char *str); * Get old parameters for a structure. */ int sysctl_rdstruct (void *oldp, size_t *oldlenp, - void *newp, void *sp, int len); + void *newp, void *sp, int len); -#else /* !KERNEL */ +#else /* !KERNEL */ int sysctl (int *name, u_int namelen, void *oldp, size_t *oldlenp, - void *newp, size_t newlen); + void *newp, size_t newlen); int __sysctl (int *name, u_int namelen, void *oldp, size_t *oldlenp, - void *newp, size_t newlen); + void *newp, size_t newlen); -#endif /* KERNEL */ -#endif /* !_SYS_SYSCTL_H_ */ +#endif /* KERNEL */ +#endif /* !_SYS_SYSCTL_H_ */ diff --git a/sys/include/syslog.h b/sys/include/syslog.h index 62229e1..8f2c80b 100644 --- a/sys/include/syslog.h +++ b/sys/include/syslog.h @@ -1,6 +1,6 @@ /* * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. + * 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 @@ -12,8 +12,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -30,14 +30,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)syslog.h 8.1.2 (2.11BSD) 1999/06/18 + * @(#)syslog.h 8.1.2 (2.11BSD) 1999/06/18 * $Id: syslog.h,v 1.4 1994/08/21 04:42:00 paul Exp $ */ #ifndef _SYS_SYSLOG_H_ #define _SYS_SYSLOG_H_ -#define _PATH_LOG "/dev/log" +#define _PATH_LOG "/dev/log" /* * priorities/facilities are encoded into a single 16-bit quantity, where the @@ -48,101 +48,101 @@ * * priorities (these are ordered) */ -#define LOG_EMERG 0 /* system is unusable */ -#define LOG_ALERT 1 /* action must be taken immediately */ -#define LOG_CRIT 2 /* critical conditions */ -#define LOG_ERR 3 /* error conditions */ -#define LOG_WARNING 4 /* warning conditions */ -#define LOG_NOTICE 5 /* normal but significant condition */ -#define LOG_INFO 6 /* informational */ -#define LOG_DEBUG 7 /* debug-level messages */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ -#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ - /* extract priority */ -#define LOG_PRI(p) ((p) & LOG_PRIMASK) -#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) #ifdef SYSLOG_NAMES -#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ - /* mark "facility" */ -#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) typedef struct _code { - char *c_name; - int c_val; + char *c_name; + int c_val; } CODE; CODE prioritynames[] = { - "alert", LOG_ALERT, - "crit", LOG_CRIT, - "debug", LOG_DEBUG, - "emerg", LOG_EMERG, - "err", LOG_ERR, - "info", LOG_INFO, - "none", INTERNAL_NOPRI, /* INTERNAL */ - "notice", LOG_NOTICE, - "warning", LOG_WARNING, - NULL, -1, + "alert", LOG_ALERT, + "crit", LOG_CRIT, + "debug", LOG_DEBUG, + "emerg", LOG_EMERG, + "err", LOG_ERR, + "info", LOG_INFO, + "none", INTERNAL_NOPRI, /* INTERNAL */ + "notice", LOG_NOTICE, + "warning", LOG_WARNING, + NULL, -1, }; #endif /* facility codes */ -#define LOG_KERN (0<<3) /* kernel messages */ -#define LOG_USER (1<<3) /* random user-level messages */ -#define LOG_MAIL (2<<3) /* mail system */ -#define LOG_DAEMON (3<<3) /* system daemons */ -#define LOG_AUTH (4<<3) /* security/authorization messages */ -#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ -#define LOG_LPR (6<<3) /* line printer subsystem */ -#define LOG_NEWS (7<<3) /* network news subsystem */ -#define LOG_UUCP (8<<3) /* UUCP subsystem */ -#define LOG_CRON (9<<3) /* clock daemon */ -#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ -#define LOG_FTP (11<<3) /* ftp daemon */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ - /* other codes through 15 reserved for system use */ -#define LOG_LOCAL0 (16<<3) /* reserved for local use */ -#define LOG_LOCAL1 (17<<3) /* reserved for local use */ -#define LOG_LOCAL2 (18<<3) /* reserved for local use */ -#define LOG_LOCAL3 (19<<3) /* reserved for local use */ -#define LOG_LOCAL4 (20<<3) /* reserved for local use */ -#define LOG_LOCAL5 (21<<3) /* reserved for local use */ -#define LOG_LOCAL6 (22<<3) /* reserved for local use */ -#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ -#define LOG_NFACILITIES 24 /* current number of facilities */ -#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ - /* facility of pri */ -#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) #ifdef SYSLOG_NAMES CODE facilitynames[] = { - "auth", LOG_AUTH, - "authpriv", LOG_AUTHPRIV, - "cron", LOG_CRON, - "daemon", LOG_DAEMON, - "ftp", LOG_FTP, - "kern", LOG_KERN, - "lpr", LOG_LPR, - "mail", LOG_MAIL, - "mark", INTERNAL_MARK, /* INTERNAL */ - "news", LOG_NEWS, - "syslog", LOG_SYSLOG, - "user", LOG_USER, - "uucp", LOG_UUCP, - "local0", LOG_LOCAL0, - "local1", LOG_LOCAL1, - "local2", LOG_LOCAL2, - "local3", LOG_LOCAL3, - "local4", LOG_LOCAL4, - "local5", LOG_LOCAL5, - "local6", LOG_LOCAL6, - "local7", LOG_LOCAL7, - NULL, -1, + "auth", LOG_AUTH, + "authpriv", LOG_AUTHPRIV, + "cron", LOG_CRON, + "daemon", LOG_DAEMON, + "ftp", LOG_FTP, + "kern", LOG_KERN, + "lpr", LOG_LPR, + "mail", LOG_MAIL, + "mark", INTERNAL_MARK, /* INTERNAL */ + "news", LOG_NEWS, + "syslog", LOG_SYSLOG, + "user", LOG_USER, + "uucp", LOG_UUCP, + "local0", LOG_LOCAL0, + "local1", LOG_LOCAL1, + "local2", LOG_LOCAL2, + "local3", LOG_LOCAL3, + "local4", LOG_LOCAL4, + "local5", LOG_LOCAL5, + "local6", LOG_LOCAL6, + "local7", LOG_LOCAL7, + NULL, -1, }; #endif #ifdef KERNEL -#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ #else void syslog (int pri, const char *fmt, ...); void openlog (const char *ident, int logstat, int logfac); @@ -152,8 +152,8 @@ void closelog (void); /* * arguments to setlogmask. */ -#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ -#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ /* * Option flags for openlog. @@ -161,11 +161,11 @@ void closelog (void); * LOG_ODELAY no longer does anything. * LOG_NDELAY is the inverse of what it used to be. */ -#define LOG_PID 0x01 /* log the pid with each message */ -#define LOG_CONS 0x02 /* log on the console if errors in sending */ -#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ -#define LOG_NDELAY 0x08 /* don't delay open */ -#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ -#define LOG_PERROR 0x20 /* log to stderr as well */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ #endif diff --git a/sys/include/systm.h b/sys/include/systm.h index 64331a2..8c78453 100644 --- a/sys/include/systm.h +++ b/sys/include/systm.h @@ -9,16 +9,16 @@ * It can only be decreased by process 1 (/sbin/init). * * Security levels are as follows: - * -1 permannently insecure mode - always run system in level 0 mode. - * 0 insecure mode - immutable and append-only flags make be turned off. - * All devices may be read or written subject to permission modes. - * 1 secure mode - immutable and append-only flags may not be changed; - * raw disks of mounted filesystems, /dev/mem, and /dev/kmem are - * read-only. - * 2 highly secure mode - same as (1) plus raw disks are always - * read-only whether mounted or not. This level precludes tampering - * with filesystems by unmounting them, but also inhibits running - * newfs while the system is secured. + * -1 permannently insecure mode - always run system in level 0 mode. + * 0 insecure mode - immutable and append-only flags make be turned off. + * All devices may be read or written subject to permission modes. + * 1 secure mode - immutable and append-only flags may not be changed; + * raw disks of mounted filesystems, /dev/mem, and /dev/kmem are + * read-only. + * 2 highly secure mode - same as (1) plus raw disks are always + * read-only whether mounted or not. This level precludes tampering + * with filesystems by unmounting them, but also inhibits running + * newfs while the system is secured. * * In normal operation, the system runs in level 0 mode while single user * and in level 1 mode while multiuser. If level 2 mode is desired while @@ -32,9 +32,10 @@ * patched by a stalking hacker. */ #include "conf.h" -extern int securelevel; /* system security level */ -extern const char version[]; /* system version */ +extern int securelevel; /* system security level */ + +extern const char version[]; /* system version */ /* * Nblkdev is the number of entries (rows) in the block switch. @@ -52,23 +53,23 @@ extern const int nchrdev; */ extern const int nsysent; -extern int mpid; /* generic for unique process id's */ -extern char runin; /* scheduling flag */ -extern char runout; /* scheduling flag */ -extern int runrun; /* scheduling flag */ -extern char curpri; /* more scheduling */ +extern int mpid; /* generic for unique process id's */ +extern char runin; /* scheduling flag */ +extern char runout; /* scheduling flag */ +extern int runrun; /* scheduling flag */ +extern char curpri; /* more scheduling */ -extern u_int swapstart, nswap; /* start and size of swap space */ -extern int updlock; /* lock for sync */ -extern daddr_t rablock; /* block to be read ahead */ -extern dev_t rootdev; /* device of the root */ -extern dev_t dumpdev; /* device to take dumps on */ -extern long dumplo; /* offset into dumpdev */ -extern dev_t swapdev; /* swapping device */ -extern dev_t pipedev; /* pipe device */ +extern u_int swapstart, nswap; /* start and size of swap space */ +extern int updlock; /* lock for sync */ +extern daddr_t rablock; /* block to be read ahead */ +extern dev_t rootdev; /* device of the root */ +extern dev_t dumpdev; /* device to take dumps on */ +extern long dumplo; /* offset into dumpdev */ +extern dev_t swapdev; /* swapping device */ +extern dev_t pipedev; /* pipe device */ -extern const char icode[]; /* user init code */ -extern const char icodeend[]; /* its end */ +extern const char icode[]; /* user init code */ +extern const char icodeend[]; /* its end */ struct inode; daddr_t bmap (struct inode *ip, daddr_t bn, int rwflg, int flags); @@ -80,26 +81,26 @@ extern void kmemdev(); */ extern const struct sysent { - int sy_narg; /* total number of arguments */ - void (*sy_call) (void); /* handler */ + int sy_narg; /* total number of arguments */ + void (*sy_call) (void); /* handler */ } sysent[]; extern const char *syscallnames[]; -extern int noproc; /* no one is running just now */ -extern char *panicstr; -extern int boothowto; /* reboot flags, from boot */ -extern int selwait; -extern size_t physmem; /* total amount of physical memory */ +extern int noproc; /* no one is running just now */ +extern char *panicstr; +extern int boothowto; /* reboot flags, from boot */ +extern int selwait; +extern size_t physmem; /* total amount of physical memory */ extern dev_t get_cdev_by_name(char *); extern char *cdevname(dev_t dev); void panic (char *msg); void printf (char *fmt, ...); -void uprintf (char *fmt, ...); /* print to the current user's terminal */ +void uprintf (char *fmt, ...); /* print to the current user's terminal */ struct tty; -void tprintf (struct tty *tp, char *fmt, ...); /* print to the specified terminal */ +void tprintf (struct tty *tp, char *fmt, ...); /* print to the specified terminal */ int loginit (void); void log (int level, char *fmt, ...); int logwrt (char *buf, int len, int log); @@ -109,8 +110,8 @@ void cninit (void); void cnidentify (void); void cnputc (char c); int cngetc (void); -int baduaddr (caddr_t addr); /* detect bad user address */ -int badkaddr (caddr_t addr); /* detect bad kernel address */ +int baduaddr (caddr_t addr); /* detect bad user address */ +int badkaddr (caddr_t addr); /* detect bad kernel address */ int strncmp (const char *s1, const char *s2, size_t n); void bzero (void *s, size_t nbytes); @@ -118,14 +119,14 @@ void bcopy (const void *src, void *dest, size_t nbytes); int bcmp (const void *a, const void *b, size_t nbytes); int copystr (caddr_t src, caddr_t dest, u_int maxlen, u_int *copied); size_t strlen (const char *s); -int ffs (u_long i); /* find the index of the lsb set bit */ +int ffs (u_long i); /* find the index of the lsb set bit */ void insque (void *element, void *pred); void remque (void *element); -void startup (void); /* machine-dependent startup code */ -int chrtoblk (dev_t dev); /* convert from character to block device number */ -int isdisk (dev_t dev, int type); /* determine if a device is a disk */ -int iskmemdev (dev_t dev); /* identify /dev/mem and /dev/kmem */ +void startup (void); /* machine-dependent startup code */ +int chrtoblk (dev_t dev); /* convert from character to block device number */ +int isdisk (dev_t dev, int type); /* determine if a device is a disk */ +int iskmemdev (dev_t dev); /* identify /dev/mem and /dev/kmem */ void boot (dev_t dev, int howto); /* @@ -165,69 +166,69 @@ void coutinit (void); /* * Syscalls. */ -void nosys (void); +void nosys (void); /* 1.1 processes and protection */ -void getpid (void); -void getppid (void), fork (void), rexit (void), execv (void), execve (void); -void wait4 (void), getuid (void), getgid (void), getgroups (void), setgroups (void); -void geteuid (void), getegid (void); -void getpgrp (void), setpgrp (void); -void setgid (void), setegid (void), setuid (void), seteuid (void); -void ucall (void); /* 2BSD calls */ +void getpid (void); +void getppid (void), fork (void), rexit (void), execv (void), execve (void); +void wait4 (void), getuid (void), getgid (void), getgroups (void), setgroups (void); +void geteuid (void), getegid (void); +void getpgrp (void), setpgrp (void); +void setgid (void), setegid (void), setuid (void), seteuid (void); +void ucall (void); /* 2BSD calls */ /* 1.2 memory management */ -void brk (void); -void ustore (void); /* 2BSD calls */ -void ufetch (void); /* 2BSD calls */ +void brk (void); +void ustore (void); /* 2BSD calls */ +void ufetch (void); /* 2BSD calls */ /* 1.3 signals */ -void sigstack (void), sigreturn (void); -void sigaction (void), sigprocmask (void), sigpending (void), sigaltstack (void), sigsuspend (void); -void sigwait (void), kill (void), killpg (void); +void sigstack (void), sigreturn (void); +void sigaction (void), sigprocmask (void), sigpending (void), sigaltstack (void), sigsuspend (void); +void sigwait (void), kill (void), killpg (void); /* 1.4 timing and statistics */ -void gettimeofday (void), settimeofday (void); -void getitimer (void), setitimer (void); -void adjtime (void); +void gettimeofday (void), settimeofday (void); +void getitimer (void), setitimer (void); +void adjtime (void); /* 1.5 descriptors */ -void getdtablesize (void), dup (void), dup2 (void), close (void); -void pselect (void), select (void), fcntl (void), flock (void); +void getdtablesize (void), dup (void), dup2 (void), close (void); +void pselect (void), select (void), fcntl (void), flock (void); /* 1.6 resource controls */ -void getpriority (void), setpriority (void), getrusage (void), getrlimit (void), setrlimit (void); +void getpriority (void), setpriority (void), getrusage (void), getrlimit (void), setrlimit (void); /* 1.7 system operation support */ -void umount (void), smount (void); -void sync (void), reboot (void), __sysctl (void); +void umount (void), smount (void); +void sync (void), reboot (void), __sysctl (void); /* 2.1 generic operations */ -void read (void), write (void), readv (void), writev (void), ioctl (void); +void read (void), write (void), readv (void), writev (void), ioctl (void); /* 2.2 file system */ -void chdir (void), fchdir (void), chroot (void); -void mkdir (void), rmdir (void), chflags (void), fchflags (void); -void open (void), mknod (void), unlink (void), stat (void), fstat (void), lstat (void); -void chown (void), fchown (void), chmod (void), fchmod (void), utimes (void); -void link (void), symlink (void), readlink (void), rename (void); -void lseek (void), truncate (void), ftruncate (void), saccess (void), fsync (void); -void statfs (void), fstatfs (void), getfsstat (void); +void chdir (void), fchdir (void), chroot (void); +void mkdir (void), rmdir (void), chflags (void), fchflags (void); +void open (void), mknod (void), unlink (void), stat (void), fstat (void), lstat (void); +void chown (void), fchown (void), chmod (void), fchmod (void), utimes (void); +void link (void), symlink (void), readlink (void), rename (void); +void lseek (void), truncate (void), ftruncate (void), saccess (void), fsync (void); +void statfs (void), fstatfs (void), getfsstat (void); /* 2.3 communications */ -void socket (void), bind (void), listen (void), accept (void), connect (void); -void socketpair (void), sendto (void), send (void), recvfrom (void), recv (void); -void sendmsg (void), recvmsg (void), shutdown (void), setsockopt (void), getsockopt (void); -void getsockname (void), getpeername (void), pipe (void); +void socket (void), bind (void), listen (void), accept (void), connect (void); +void socketpair (void), sendto (void), send (void), recvfrom (void), recv (void); +void sendmsg (void), recvmsg (void), shutdown (void), setsockopt (void), getsockopt (void); +void getsockname (void), getpeername (void), pipe (void); -void umask (void); /* XXX */ +void umask (void); /* XXX */ /* 2.4 processes */ -void ptrace (void); +void ptrace (void); -void profil (void); /* 'cuz sys calls are interruptible */ -void vhangup (void); /* should just do in exit (void) */ -void vfork (void); /* awaiting fork w/ copy on write */ +void profil (void); /* 'cuz sys calls are interruptible */ +void vhangup (void); /* should just do in exit (void) */ +void vfork (void); /* awaiting fork w/ copy on write */ /* * Drivers. diff --git a/sys/include/time.h b/sys/include/time.h index 35d6254..4a6692e 100644 --- a/sys/include/time.h +++ b/sys/include/time.h @@ -4,8 +4,8 @@ * specifies the terms and conditions for redistribution. */ -#ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ #include @@ -14,8 +14,8 @@ * and used in other calls. */ struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ }; /* @@ -24,49 +24,50 @@ struct timeval { * same makes life simpler than changing the names. */ struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ }; struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ }; -#define DST_NONE 0 /* not on dst */ -#define DST_USA 1 /* USA style dst */ -#define DST_AUST 2 /* Australian style dst */ -#define DST_WET 3 /* Western European dst */ -#define DST_MET 4 /* Middle European dst */ -#define DST_EET 5 /* Eastern European dst */ -#define DST_CAN 6 /* Canada */ +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ /* * Operations on timevals. * * NB: timercmp does not work for >= or <=. */ -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) -#define timercmp(tvp, uvp, cmp) \ - ((tvp)->tv_sec cmp (uvp)->tv_sec || \ - (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec) -#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + ((tvp)->tv_sec cmp (uvp)->tv_sec || \ + (tvp)->tv_sec == (uvp)->tv_sec && \ + (tvp)->tv_usec cmp (uvp)->tv_usec) +#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 /* * Names of the interval timers, and structure * defining a timer setting. */ -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 -struct k_itimerval { - long it_interval; /* timer interval */ - long it_value; /* current value */ +struct k_itimerval { + long it_interval; /* timer interval */ + long it_value; /* current value */ }; -struct itimerval { - struct timeval it_interval; /* timer interval */ - struct timeval it_value; /* current value */ +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ }; #ifdef KERNEL @@ -93,7 +94,7 @@ int gettimeofday (struct timeval *tv, struct timezone *tz); int utimes (const char *filename, const struct timeval times[2]); int getitimer (int which, struct itimerval *curr_value); int setitimer (int which, const struct itimerval *new_value, - struct itimerval *old_value); + struct itimerval *old_value); int getpriority (int which, int who); int setpriority (int which, int who, int prio); char *tztab (int zone, int dst); @@ -104,11 +105,11 @@ char *tztab (int zone, int dst); * Getkerninfo clock information structure */ struct clockinfo { - int hz; /* clock frequency */ - int tick; /* micro-seconds per hz tick */ - int stathz; /* statistics clock frequency */ - int profhz; /* profiling clock frequency */ + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ }; extern unsigned int msec(); -#endif /* !_SYS_TIME_H_ */ +#endif /* !_SYS_TIME_H_ */ diff --git a/sys/include/times.h b/sys/include/times.h index 546e7d1..881a1e9 100644 --- a/sys/include/times.h +++ b/sys/include/times.h @@ -3,15 +3,15 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)times.h 7.1 (Berkeley) 6/4/86 + * @(#)times.h 7.1 (Berkeley) 6/4/86 */ /* * Structure returned by times() */ struct tms { - time_t tms_utime; /* user time */ - time_t tms_stime; /* system time */ - time_t tms_cutime; /* user time, children */ - time_t tms_cstime; /* system time, children */ + time_t tms_utime; /* user time */ + time_t tms_stime; /* system time */ + time_t tms_cutime; /* user time, children */ + time_t tms_cstime; /* system time, children */ }; diff --git a/sys/include/trace.h b/sys/include/trace.h deleted file mode 100644 index 87bfa3c..0000000 --- a/sys/include/trace.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1982, 1986 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. - */ - -/* - * File system buffer tracing points; all trace - * - * Slipped into 2.10 in about 15 minutes. Bears only a casual - * relationship to the 4.X code, we just used the same names so - * someone could do it right if they felt like it. Note that - * the #defines aren't even sequentially numbered. - */ -#define TR_BREADHIT 0 /* buffer read found in cache */ -#define TR_BREADMISS 1 /* buffer read not in cache */ -#define TR_BWRITE 2 /* buffer written */ -#define TR_BREADHITRA 3 /* buffer read-ahead found in cache */ -#define TR_BREADMISSRA 4 /* buffer read-ahead not in cache */ -#define TR_BRELSE 5 /* brelse */ -#define TR_SWAPIO 6 /* swap i/o request arrives */ -#define TR_NUM_210 7 /* size of array for 2.10BSD */ - -#define TR_XFODMISS 5 /* exe fod read */ -#define TR_XFODHIT 6 /* exe fod read */ -#define TR_BREALLOC 8 /* expand/contract a buffer */ - -/* - * Memory allocator trace points; all trace the amount of memory involved - */ -#define TR_MALL 10 /* memory allocated */ - -/* - * Paging trace points: all are - */ -#define TR_INTRANS 20 /* page intransit block */ -#define TR_EINTRANS 21 /* page intransit wait done */ -#define TR_FRECLAIM 22 /* reclaim from free list */ -#define TR_RECLAIM 23 /* reclaim from loop */ -#define TR_XSFREC 24 /* reclaim from free list instead of drum */ -#define TR_XIFREC 25 /* reclaim from free list instead of fsys */ -#define TR_WAITMEM 26 /* wait for memory in pagein */ -#define TR_EWAITMEM 27 /* end memory wait in pagein */ -#define TR_ZFOD 28 /* zfod page fault */ -#define TR_EXFOD 29 /* exec fod page fault */ -#define TR_VRFOD 30 /* vread fod page fault */ -#define TR_CACHEFOD 31 /* fod in file system cache */ -#define TR_SWAPIN 32 /* drum page fault */ -#define TR_PGINDONE 33 /* page in done */ - -/* - * System call trace points. - */ -#define TR_VADVISE 40 /* vadvise occurred with */ - -/* - * Miscellaneous - */ -#define TR_STAMP 45 /* user said vtrace(VTR_STAMP, value); */ - -/* - * This defines the size of the trace flags array. - */ -#define TR_NFLAGS 100 /* generous */ - -#define TRCSIZ 4096 - -/* - * Specifications of the vtrace() system call, which takes one argument. - */ -#define VTRACE 64+51 - -#define VTR_DISABLE 0 /* set a trace flag to 0 */ -#define VTR_ENABLE 1 /* set a trace flag to 1 */ -#define VTR_VALUE 2 /* return value of a trace flag */ -#define VTR_UALARM 3 /* set alarm to go off (sig 16) */ - /* in specified number of hz */ -#define VTR_STAMP 4 /* user specified stamp */ - -#if defined(KERNEL) && defined(UCB_METER) -u_long tracebuf[TR_NUM_210]; -#define trace(a) tracebuf[a]++; -#else -#define trace(a) ; -#endif diff --git a/sys/include/tty.h b/sys/include/tty.h index 6753e85..6a3fddc 100644 --- a/sys/include/tty.h +++ b/sys/include/tty.h @@ -24,9 +24,9 @@ * The routines in tty_subr.c manipulate these structures. */ struct clist { - int c_cc; /* character count */ - char *c_cf; /* pointer to first char */ - char *c_cl; /* pointer to last char */ + int c_cc; /* character count */ + char *c_cf; /* pointer to first char */ + char *c_cl; /* pointer to last char */ }; /* @@ -37,74 +37,74 @@ struct clist { * (low, high, timeout). */ struct tty { - union { - struct { - struct clist T_rawq; - struct clist T_canq; - } t_t; -#define t_rawq t_nu.t_t.T_rawq /* raw characters or partial line */ -#define t_canq t_nu.t_t.T_canq /* raw characters or partial line */ - struct { - struct buf *T_bufp; - char *T_cp; - int T_inbuf; - int T_rec; - } t_n; -#define t_bufp t_nu.t_n.T_bufp /* buffer allocated to protocol */ -#define t_cp t_nu.t_n.T_cp /* pointer into the ripped off buffer */ -#define t_inbuf t_nu.t_n.T_inbuf /* number chars in the buffer */ -#define t_rec t_nu.t_n.T_rec /* have a complete record */ - } t_nu; - struct clist t_outq; /* device */ - void (*t_oproc) (struct tty*); - struct proc *t_rsel; /* tty */ - struct proc *t_wsel; - caddr_t T_LINEP; /* ### */ - caddr_t t_addr; /* ??? */ - dev_t t_dev; /* device */ - long t_flags; /* some of both */ - long t_state; /* some of both */ - int t_pgrp; /* tty */ - int t_delct; /* tty */ - int t_col; /* tty */ - int t_ispeed, t_ospeed; /* device */ - int t_rocount, t_rocol; /* tty */ - struct ttychars t_chars; /* tty */ - struct winsize t_winsize; /* window size */ + union { + struct { + struct clist T_rawq; + struct clist T_canq; + } t_t; +#define t_rawq t_nu.t_t.T_rawq /* raw characters or partial line */ +#define t_canq t_nu.t_t.T_canq /* raw characters or partial line */ + struct { + struct buf *T_bufp; + char *T_cp; + int T_inbuf; + int T_rec; + } t_n; +#define t_bufp t_nu.t_n.T_bufp /* buffer allocated to protocol */ +#define t_cp t_nu.t_n.T_cp /* pointer into the ripped off buffer */ +#define t_inbuf t_nu.t_n.T_inbuf /* number chars in the buffer */ +#define t_rec t_nu.t_n.T_rec /* have a complete record */ + } t_nu; + struct clist t_outq; /* device */ + void (*t_oproc) (struct tty*); + struct proc *t_rsel; /* tty */ + struct proc *t_wsel; + caddr_t T_LINEP; /* ### */ + caddr_t t_addr; /* ??? */ + dev_t t_dev; /* device */ + long t_flags; /* some of both */ + long t_state; /* some of both */ + int t_pgrp; /* tty */ + int t_delct; /* tty */ + int t_col; /* tty */ + int t_ispeed, t_ospeed; /* device */ + int t_rocount, t_rocol; /* tty */ + struct ttychars t_chars; /* tty */ + struct winsize t_winsize; /* window size */ /* be careful of tchars & co. */ -#define t_erase t_chars.tc_erase -#define t_kill t_chars.tc_kill -#define t_intrc t_chars.tc_intrc -#define t_quitc t_chars.tc_quitc -#define t_startc t_chars.tc_startc -#define t_stopc t_chars.tc_stopc -#define t_eofc t_chars.tc_eofc -#define t_brkc t_chars.tc_brkc -#define t_suspc t_chars.tc_suspc -#define t_dsuspc t_chars.tc_dsuspc -#define t_rprntc t_chars.tc_rprntc -#define t_flushc t_chars.tc_flushc -#define t_werasc t_chars.tc_werasc -#define t_lnextc t_chars.tc_lnextc +#define t_erase t_chars.tc_erase +#define t_kill t_chars.tc_kill +#define t_intrc t_chars.tc_intrc +#define t_quitc t_chars.tc_quitc +#define t_startc t_chars.tc_startc +#define t_stopc t_chars.tc_stopc +#define t_eofc t_chars.tc_eofc +#define t_brkc t_chars.tc_brkc +#define t_suspc t_chars.tc_suspc +#define t_dsuspc t_chars.tc_dsuspc +#define t_rprntc t_chars.tc_rprntc +#define t_flushc t_chars.tc_flushc +#define t_werasc t_chars.tc_werasc +#define t_lnextc t_chars.tc_lnextc }; -#define TTIPRI 28 -#define TTOPRI 29 +#define TTIPRI 28 +#define TTOPRI 29 /* limits */ -#define NSPEEDS 29 -#define TTMASK 15 -#define OBUFSIZ 100 +#define NSPEEDS 29 +#define TTMASK 15 +#define OBUFSIZ 100 #ifdef KERNEL extern const int tthiwat[NSPEEDS], ttlowat[NSPEEDS]; extern int q_to_b(register struct clist *q, char *cp, int cc); -#define TTHIWAT(tp) tthiwat[(tp)->t_ospeed&TTMASK] -#define TTLOWAT(tp) ttlowat[(tp)->t_ospeed&TTMASK] +#define TTHIWAT(tp) tthiwat[(tp)->t_ospeed&TTMASK] +#define TTLOWAT(tp) ttlowat[(tp)->t_ospeed&TTMASK] -extern int nldisp; /* number of line disciplines */ +extern int nldisp; /* number of line disciplines */ /* * Set t_chars to default values. @@ -219,34 +219,34 @@ void ttywflush (struct tty *tp); #endif /* KERNEL */ /* internal state bits */ -#define TS_TIMEOUT 0x000001L /* delay timeout in progress */ -#define TS_WOPEN 0x000002L /* waiting for open to complete */ -#define TS_ISOPEN 0x000004L /* device is open */ -#define TS_FLUSH 0x000008L /* outq has been flushed during DMA */ -#define TS_CARR_ON 0x000010L /* software copy of carrier-present */ -#define TS_BUSY 0x000020L /* output in progress */ -#define TS_ASLEEP 0x000040L /* wakeup when output done */ -#define TS_XCLUDE 0x000080L /* exclusive-use flag against open */ -#define TS_TTSTOP 0x000100L /* output stopped by ctl-s */ -#define TS_HUPCLS 0x000200L /* hang up upon last close */ -#define TS_TBLOCK 0x000400L /* tandem queue blocked */ -#define TS_RCOLL 0x000800L /* collision in read select */ -#define TS_WCOLL 0x001000L /* collision in write select */ -#define TS_ASYNC 0x004000L /* tty in async i/o mode */ +#define TS_TIMEOUT 0x000001L /* delay timeout in progress */ +#define TS_WOPEN 0x000002L /* waiting for open to complete */ +#define TS_ISOPEN 0x000004L /* device is open */ +#define TS_FLUSH 0x000008L /* outq has been flushed during DMA */ +#define TS_CARR_ON 0x000010L /* software copy of carrier-present */ +#define TS_BUSY 0x000020L /* output in progress */ +#define TS_ASLEEP 0x000040L /* wakeup when output done */ +#define TS_XCLUDE 0x000080L /* exclusive-use flag against open */ +#define TS_TTSTOP 0x000100L /* output stopped by ctl-s */ +#define TS_HUPCLS 0x000200L /* hang up upon last close */ +#define TS_TBLOCK 0x000400L /* tandem queue blocked */ +#define TS_RCOLL 0x000800L /* collision in read select */ +#define TS_WCOLL 0x001000L /* collision in write select */ +#define TS_ASYNC 0x004000L /* tty in async i/o mode */ /* state for intra-line fancy editing work */ -#define TS_ERASE 0x040000L /* within a \.../ for PRTRUB */ -#define TS_LNCH 0x080000L /* next character is literal */ -#define TS_TYPEN 0x100000L /* retyping suspended input (PENDIN) */ -#define TS_CNTTB 0x200000L /* counting tab width; leave FLUSHO alone */ +#define TS_ERASE 0x040000L /* within a \.../ for PRTRUB */ +#define TS_LNCH 0x080000L /* next character is literal */ +#define TS_TYPEN 0x100000L /* retyping suspended input (PENDIN) */ +#define TS_CNTTB 0x200000L /* counting tab width; leave FLUSHO alone */ -#define TS_LOCAL (TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB) +#define TS_LOCAL (TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB) /* define partab character types */ -#define ORDINARY 0 -#define CONTROL 1 -#define BACKSPACE 2 -#define NEWLINE 3 -#define TAB 4 -#define VTAB 5 -#define RETURN 6 +#define ORDINARY 0 +#define CONTROL 1 +#define BACKSPACE 2 +#define NEWLINE 3 +#define TAB 4 +#define VTAB 5 +#define RETURN 6 #endif diff --git a/sys/include/ttychars.h b/sys/include/ttychars.h index c2f09d3..2cd51d3 100644 --- a/sys/include/ttychars.h +++ b/sys/include/ttychars.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)ttychars.h 7.2 (2.11BSD) 1997/4/15 + * @(#)ttychars.h 7.2 (2.11BSD) 1997/4/15 */ /* @@ -11,42 +11,42 @@ * related to terminal handling. */ #ifndef _TTYCHARS_ -#define _TTYCHARS_ +#define _TTYCHARS_ struct ttychars { - char tc_erase; /* erase last character */ - char tc_kill; /* erase entire line */ - char tc_intrc; /* interrupt */ - char tc_quitc; /* quit */ - char tc_startc; /* start output */ - char tc_stopc; /* stop output */ - char tc_eofc; /* end-of-file */ - char tc_brkc; /* input delimiter (like nl) */ - char tc_suspc; /* stop process signal */ - char tc_dsuspc; /* delayed stop process signal */ - char tc_rprntc; /* reprint line */ - char tc_flushc; /* flush output (toggles) */ - char tc_werasc; /* word erase */ - char tc_lnextc; /* literal next character */ + char tc_erase; /* erase last character */ + char tc_kill; /* erase entire line */ + char tc_intrc; /* interrupt */ + char tc_quitc; /* quit */ + char tc_startc; /* start output */ + char tc_stopc; /* stop output */ + char tc_eofc; /* end-of-file */ + char tc_brkc; /* input delimiter (like nl) */ + char tc_suspc; /* stop process signal */ + char tc_dsuspc; /* delayed stop process signal */ + char tc_rprntc; /* reprint line */ + char tc_flushc; /* flush output (toggles) */ + char tc_werasc; /* word erase */ + char tc_lnextc; /* literal next character */ }; -#define CTRL(c) (c & 037) -#define _POSIX_VDISABLE ((unsigned char)'\377') -#define CCEQ(val,c) (c == val ? val != _POSIX_VDISABLE : 0) +#define CTRL(c) (c & 037) +#define _POSIX_VDISABLE ((unsigned char)'\377') +#define CCEQ(val,c) (c == val ? val != _POSIX_VDISABLE : 0) /* default special characters */ -#define CERASE 0177 -#define CKILL CTRL('u') -#define CINTR CTRL('c') -#define CQUIT CTRL('\\') -#define CSTART CTRL('q') -#define CSTOP CTRL('s') -#define CEOF CTRL('d') -#define CEOT CEOF -#define CBRK _POSIX_VDISABLE -#define CSUSP CTRL('z') -#define CDSUSP CTRL('y') -#define CRPRNT CTRL('r') -#define CFLUSH CTRL('o') -#define CWERASE CTRL('w') -#define CLNEXT CTRL('v') +#define CERASE 0177 +#define CKILL CTRL('u') +#define CINTR CTRL('c') +#define CQUIT CTRL('\\') +#define CSTART CTRL('q') +#define CSTOP CTRL('s') +#define CEOF CTRL('d') +#define CEOT CEOF +#define CBRK _POSIX_VDISABLE +#define CSUSP CTRL('z') +#define CDSUSP CTRL('y') +#define CRPRNT CTRL('r') +#define CFLUSH CTRL('o') +#define CWERASE CTRL('w') +#define CLNEXT CTRL('v') #endif /* _TTYCHARS_ */ diff --git a/sys/include/ttydev.h b/sys/include/ttydev.h index 34455ba..acf2e8b 100644 --- a/sys/include/ttydev.h +++ b/sys/include/ttydev.h @@ -3,55 +3,55 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)ttydev.h 7.1 (Berkeley) 6/4/86 + * @(#)ttydev.h 7.1 (Berkeley) 6/4/86 */ /* * Terminal definitions related to underlying hardware. */ #ifndef _TTYDEV_ -#define _TTYDEV_ +#define _TTYDEV_ /* * Speeds */ -#define B0 0 -#define B50 1 -#define B75 2 -#define B150 3 -#define B200 4 -#define B300 5 -#define B600 6 -#define B1200 7 -#define B1800 8 -#define B2400 9 -#define B4800 10 -#define B9600 11 -#define B19200 12 -#define B38400 13 -#define B57600 14 -#define B115200 15 -#define B230400 16 -#define B460800 17 -#define B500000 18 -#define B576000 19 -#define B921600 20 -#define B1000000 21 -#define B1152000 22 -#define B1500000 23 -#define B2000000 24 -#define B2500000 25 -#define B3000000 26 -#define B3500000 27 -#define B4000000 28 +#define B0 0 +#define B50 1 +#define B75 2 +#define B150 3 +#define B200 4 +#define B300 5 +#define B600 6 +#define B1200 7 +#define B1800 8 +#define B2400 9 +#define B4800 10 +#define B9600 11 +#define B19200 12 +#define B38400 13 +#define B57600 14 +#define B115200 15 +#define B230400 16 +#define B460800 17 +#define B500000 18 +#define B576000 19 +#define B921600 20 +#define B1000000 21 +#define B1152000 22 +#define B1500000 23 +#define B2000000 24 +#define B2500000 25 +#define B3000000 26 +#define B3500000 27 +#define B4000000 28 #ifdef KERNEL /* * Modem control commands. */ -#define DMSET 0 -#define DMBIS 1 -#define DMBIC 2 -#define DMGET 3 +#define DMSET 0 +#define DMBIS 1 +#define DMBIC 2 +#define DMGET 3 #endif #endif diff --git a/sys/include/types.h b/sys/include/types.h index 9c34b2e..3060922 100644 --- a/sys/include/types.h +++ b/sys/include/types.h @@ -5,43 +5,43 @@ */ #ifndef _SYS_TYPES_H_ -#define _SYS_TYPES_H_ +#define _SYS_TYPES_H_ /* * Basic system types and major/minor device constructing/busting macros. */ /* major part of a device */ -#define major(x) ((int)(((int)(x)>>8)&0377)) +#define major(x) ((int)(((int)(x)>>8)&0377)) /* minor part of a device */ -#define minor(x) ((int)((x)&0377)) +#define minor(x) ((int)((x)&0377)) /* make a device number */ -#define makedev(x,y) ((dev_t)(((x)<<8) | (y))) +#define makedev(x,y) ((dev_t)(((x)<<8) | (y))) -typedef unsigned char u_char; -typedef unsigned short u_short; -typedef unsigned int u_int; -typedef unsigned long u_long; /* see this! unsigned longs at last! */ -typedef unsigned short ushort; /* sys III compat */ +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; /* see this! unsigned longs at last! */ +typedef unsigned short ushort; /* sys III compat */ #ifdef pdp11 -typedef struct label_t { - int val[7]; /* regs 2-7 and super SP */ +typedef struct label_t { + int val[7]; /* regs 2-7 and super SP */ } label_t; #endif #ifdef __mips__ -typedef struct label_t { - unsigned val[12]; /* regs S0-S8, RA, GP and SP */ +typedef struct label_t { + unsigned val[12]; /* regs S0-S8, RA, GP and SP */ } label_t; #endif -typedef long daddr_t; -typedef char * caddr_t; -typedef u_int ino_t; +typedef long daddr_t; +typedef char * caddr_t; +typedef u_int ino_t; #ifndef _SIZE_T #define _SIZE_T -typedef u_int size_t; +typedef u_int size_t; #endif #ifndef __ssize_t_defined #ifndef _SSIZE_T @@ -52,18 +52,18 @@ typedef int ssize_t; #endif #ifndef _TIME_T #define _TIME_T -typedef long time_t; +typedef long time_t; #endif -typedef int dev_t; -#ifndef _OFF_T -#define _OFF_T -typedef long off_t; +typedef int dev_t; +#ifndef _OFF_T +#define _OFF_T +typedef long off_t; #endif -typedef u_int uid_t; -typedef u_int gid_t; -typedef int pid_t; -typedef u_int mode_t; -typedef int bool_t; /* boolean */ +typedef u_int uid_t; +typedef u_int gid_t; +typedef int pid_t; +typedef u_int mode_t; +typedef int bool_t; /* boolean */ #define _PID_T #define _UID_T #define _GID_T @@ -72,10 +72,10 @@ typedef int bool_t; /* boolean */ #define _TIME_T #define _MODE_T -#define NBBY 8 /* number of bits in a byte */ +#define NBBY 8 /* number of bits in a byte */ #ifndef howmany -#define howmany(x, y) (((x)+((y)-1))/(y)) +#define howmany(x, y) (((x)+((y)-1))/(y)) #endif #include diff --git a/sys/include/uart.h b/sys/include/uart.h index 205f982..47b761c 100644 --- a/sys/include/uart.h +++ b/sys/include/uart.h @@ -10,9 +10,9 @@ #include "conf.h" struct uart_irq { - int er; - int rx; - int tx; + int er; + int rx; + int tx; }; extern const struct uart_irq uirq[NUART]; @@ -21,26 +21,26 @@ extern const struct uart_irq uirq[NUART]; * PIC32 UART registers. */ struct uartreg { - volatile unsigned mode; /* Mode */ - volatile unsigned modeclr; - volatile unsigned modeset; - volatile unsigned modeinv; - volatile unsigned sta; /* Status and control */ - volatile unsigned staclr; - volatile unsigned staset; - volatile unsigned stainv; - volatile unsigned txreg; /* Transmit */ - volatile unsigned unused1; - volatile unsigned unused2; - volatile unsigned unused3; - volatile unsigned rxreg; /* Receive */ - volatile unsigned unused4; - volatile unsigned unused5; - volatile unsigned unused6; - volatile unsigned brg; /* Baud rate */ - volatile unsigned brgclr; - volatile unsigned brgset; - volatile unsigned brginv; + volatile unsigned mode; /* Mode */ + volatile unsigned modeclr; + volatile unsigned modeset; + volatile unsigned modeinv; + volatile unsigned sta; /* Status and control */ + volatile unsigned staclr; + volatile unsigned staset; + volatile unsigned stainv; + volatile unsigned txreg; /* Transmit */ + volatile unsigned unused1; + volatile unsigned unused2; + volatile unsigned unused3; + volatile unsigned rxreg; /* Receive */ + volatile unsigned unused4; + volatile unsigned unused5; + volatile unsigned unused6; + volatile unsigned brg; /* Baud rate */ + volatile unsigned brgclr; + volatile unsigned brgset; + volatile unsigned brginv; }; extern struct tty uartttys[NUART]; diff --git a/sys/include/uio.h b/sys/include/uio.h index 09e79ed..c2d8a8b 100644 --- a/sys/include/uio.h +++ b/sys/include/uio.h @@ -1,6 +1,6 @@ /* * Copyright (c) 1982, 1986, 1993, 1994 - * The Regents of the University of California. All rights reserved. + * 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 @@ -12,8 +12,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -36,7 +36,7 @@ */ #ifndef _SYS_UIO_H_ -#define _SYS_UIO_H_ +#define _SYS_UIO_H_ #include "types.h" @@ -45,18 +45,18 @@ * iov_base should be a void *. */ struct iovec { - char *iov_base; /* Base address. */ - size_t iov_len; /* Length. */ + char *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ }; -enum uio_rw { UIO_READ, UIO_WRITE }; +enum uio_rw { UIO_READ, UIO_WRITE }; struct uio { - struct iovec *uio_iov; - int uio_iovcnt; - off_t uio_offset; - u_int uio_resid; - enum uio_rw uio_rw; + struct iovec *uio_iov; + int uio_iovcnt; + off_t uio_offset; + u_int uio_resid; + enum uio_rw uio_rw; }; #ifdef KERNEL diff --git a/sys/include/user.h b/sys/include/user.h index 0128556..1fcc8c7 100644 --- a/sys/include/user.h +++ b/sys/include/user.h @@ -21,89 +21,89 @@ * 0x80007400; contains the system stack (and possibly network stack) per * user; is cross referenced with the proc structure for the same process. */ -#define MAXCOMLEN MAXNAMLEN /* <= MAXNAMLEN, >= sizeof(ac_comm) */ +#define MAXCOMLEN MAXNAMLEN /* <= MAXNAMLEN, >= sizeof(ac_comm) */ struct user { - struct proc *u_procp; /* pointer to proc structure */ - int *u_frame; /* address of users saved frame */ - char u_comm[MAXCOMLEN + 1]; /* command file name */ - label_t u_qsave; /* for non-local gotos on interrupts */ - label_t u_rsave; /* save info when exchanging stacks */ - label_t u_ssave; /* label variable for swapping */ + struct proc *u_procp; /* pointer to proc structure */ + int *u_frame; /* address of users saved frame */ + char u_comm[MAXCOMLEN + 1]; /* command file name */ + label_t u_qsave; /* for non-local gotos on interrupts */ + label_t u_rsave; /* save info when exchanging stacks */ + label_t u_ssave; /* label variable for swapping */ /* syscall parameters and results */ - int u_arg[6]; /* arguments to current system call */ - int u_rval; /* return value */ - int u_error; /* return error code */ + int u_arg[6]; /* arguments to current system call */ + int u_rval; /* return value */ + int u_error; /* return error code */ /* 1.1 - processes and protection */ - uid_t u_uid; /* effective user id */ - uid_t u_svuid; /* saved user id */ - uid_t u_ruid; /* real user id */ - gid_t u_svgid; /* saved group id */ - gid_t u_rgid; /* real group id */ - gid_t u_groups[NGROUPS]; /* groups, 0 terminated */ + uid_t u_uid; /* effective user id */ + uid_t u_svuid; /* saved user id */ + uid_t u_ruid; /* real user id */ + gid_t u_svgid; /* saved group id */ + gid_t u_rgid; /* real group id */ + gid_t u_groups[NGROUPS]; /* groups, 0 terminated */ /* 1.2 - memory management */ - size_t u_tsize; /* text size (clicks) */ - size_t u_dsize; /* data size (clicks) */ - size_t u_ssize; /* stack size (clicks) */ + size_t u_tsize; /* text size (clicks) */ + size_t u_dsize; /* data size (clicks) */ + size_t u_ssize; /* stack size (clicks) */ /* 1.3 - signal management */ - sig_t u_signal[NSIG]; /* disposition of signals */ - long u_sigmask[NSIG]; /* signals to be blocked */ - long u_sigonstack; /* signals to take on sigstack */ - long u_sigintr; /* signals that interrupt syscalls */ - long u_oldmask; /* saved mask from before sigpause */ - int u_code; /* ``code'' to trap */ - int u_psflags; /* Process Signal flags */ - struct sigaltstack u_sigstk; /* signal stack info */ - u_int u_sigtramp; /* pointer to trampoline code in user space */ + sig_t u_signal[NSIG]; /* disposition of signals */ + long u_sigmask[NSIG]; /* signals to be blocked */ + long u_sigonstack; /* signals to take on sigstack */ + long u_sigintr; /* signals that interrupt syscalls */ + long u_oldmask; /* saved mask from before sigpause */ + int u_code; /* ``code'' to trap */ + int u_psflags; /* Process Signal flags */ + struct sigaltstack u_sigstk; /* signal stack info */ + u_int u_sigtramp; /* pointer to trampoline code in user space */ /* 1.4 - descriptor management */ - struct file *u_ofile[NOFILE]; /* file structures for open files */ - char u_pofile[NOFILE]; /* per-process flags of open files */ - int u_lastfile; /* high-water mark of u_ofile */ -#define UF_EXCLOSE 0x1 /* auto-close on exec */ -#define UF_MAPPED 0x2 /* mapped from device */ - struct inode *u_cdir; /* current directory */ - struct inode *u_rdir; /* root directory of current process */ - struct tty *u_ttyp; /* controlling tty pointer */ - dev_t u_ttyd; /* controlling tty dev */ - int u_cmask; /* mask for file creation */ + struct file *u_ofile[NOFILE]; /* file structures for open files */ + char u_pofile[NOFILE]; /* per-process flags of open files */ + int u_lastfile; /* high-water mark of u_ofile */ +#define UF_EXCLOSE 0x1 /* auto-close on exec */ +#define UF_MAPPED 0x2 /* mapped from device */ + struct inode *u_cdir; /* current directory */ + struct inode *u_rdir; /* root directory of current process */ + struct tty *u_ttyp; /* controlling tty pointer */ + dev_t u_ttyd; /* controlling tty dev */ + int u_cmask; /* mask for file creation */ /* 1.5 - timing and statistics */ - struct k_rusage u_ru; /* stats for this proc */ - struct k_rusage u_cru; /* sum of stats for reaped children */ - struct k_itimerval u_timer[2]; /* profile/virtual timers */ - long u_start; - int u_dupfd; /* XXX - see kern_descrip.c/fdopen */ + struct k_rusage u_ru; /* stats for this proc */ + struct k_rusage u_cru; /* sum of stats for reaped children */ + struct k_itimerval u_timer[2]; /* profile/virtual timers */ + long u_start; + int u_dupfd; /* XXX - see kern_descrip.c/fdopen */ - struct uprof { /* profile arguments */ - unsigned *pr_base; /* buffer base */ - unsigned pr_size; /* buffer size */ - unsigned pr_off; /* pc offset */ - unsigned pr_scale; /* pc scaling */ - } u_prof; + struct uprof { /* profile arguments */ + unsigned *pr_base; /* buffer base */ + unsigned pr_size; /* buffer size */ + unsigned pr_off; /* pc offset */ + unsigned pr_scale; /* pc scaling */ + } u_prof; /* 1.6 - resource controls */ - struct rlimit u_rlimit[RLIM_NLIMITS]; + struct rlimit u_rlimit[RLIM_NLIMITS]; /* namei & co. */ - struct nameicache { /* last successful directory search */ - off_t nc_prevoffset; /* offset at which last entry found */ - ino_t nc_inumber; /* inum of cached directory */ - dev_t nc_dev; /* dev of cached directory */ - } u_ncache; - int u_stack[1]; /* kernel stack per user - * extends from u + USIZE - * backward not to reach here */ + struct nameicache { /* last successful directory search */ + off_t nc_prevoffset; /* offset at which last entry found */ + ino_t nc_inumber; /* inum of cached directory */ + dev_t nc_dev; /* dev of cached directory */ + } u_ncache; + int u_stack[1]; /* kernel stack per user + * extends from u + USIZE + * backward not to reach here */ }; #include #ifdef KERNEL -extern struct user u, u0; +extern struct user u, u0; /* * Increment user profiling counters. diff --git a/sys/include/utsname.h b/sys/include/utsname.h index 947462d..110c82a 100644 --- a/sys/include/utsname.h +++ b/sys/include/utsname.h @@ -1,6 +1,6 @@ /*- * Copyright (c) 1994 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Chuck Karish of Mindcraft, Inc. @@ -15,8 +15,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -33,17 +33,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#ifndef _SYS_UTSNAME_H -#define _SYS_UTSNAME_H +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H struct utsname { - char sysname[128]; /* Name of this OS. */ - char nodename[128]; /* Name of this network node. */ - char release[128]; /* Release level. */ - char version[128]; /* Version level. */ - char machine[128]; /* Hardware type. */ + char sysname[128]; /* Name of this OS. */ + char nodename[128]; /* Name of this network node. */ + char release[128]; /* Release level. */ + char version[128]; /* Version level. */ + char machine[128]; /* Hardware type. */ }; int uname (struct utsname *name); -#endif /* !_SYS_UTSNAME_H */ +#endif /* !_SYS_UTSNAME_H */ diff --git a/sys/include/vmmac.h b/sys/include/vmmac.h index 8151d66..505639c 100644 --- a/sys/include/vmmac.h +++ b/sys/include/vmmac.h @@ -3,9 +3,9 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)vmmac.h 1.1 (2.10 Berkeley) 12/1/86 + * @(#)vmmac.h 1.1 (2.10 Berkeley) 12/1/86 */ /* Average new into old with aging factor time */ -#define ave(smooth, cnt, time) \ - smooth = ((time - 1) * (smooth) + (cnt)) / (time) +#define ave(smooth, cnt, time) \ + smooth = ((time - 1) * (smooth) + (cnt)) / (time) diff --git a/sys/include/vmmeter.h b/sys/include/vmmeter.h index 24d3e6c..b6d21ff 100644 --- a/sys/include/vmmeter.h +++ b/sys/include/vmmeter.h @@ -9,57 +9,57 @@ */ struct vmrate { -#define v_first v_swtch - u_short v_swtch; /* context switches */ - u_short v_trap; /* calls to trap */ - u_short v_syscall; /* calls to syscall() */ - u_short v_intr; /* device interrupts */ - u_short v_soft; /* software interrupts */ - u_short v_fpsim; /* floating point simulator faults */ - u_short v_kbin; /* kbytes swapped in */ - u_short v_kbout; /* kbytes swapped out */ - u_short v_swpin; /* swapins */ - u_short v_swpout; /* swapouts */ -#define v_last v_swpout +#define v_first v_swtch + u_short v_swtch; /* context switches */ + u_short v_trap; /* calls to trap */ + u_short v_syscall; /* calls to syscall() */ + u_short v_intr; /* device interrupts */ + u_short v_soft; /* software interrupts */ + u_short v_fpsim; /* floating point simulator faults */ + u_short v_kbin; /* kbytes swapped in */ + u_short v_kbout; /* kbytes swapped out */ + u_short v_swpin; /* swapins */ + u_short v_swpout; /* swapouts */ +#define v_last v_swpout }; struct vmsum { - long v_swtch; /* context switches */ - long v_trap; /* calls to trap */ - long v_syscall; /* calls to syscall() */ - long v_intr; /* device interrupts */ - long v_soft; /* software interrupts */ - long v_fpsim; /* floating point simulator faults */ - long v_kbin; /* kbytes swapped in */ - long v_kbout; /* kbytes swapped out */ - long v_swpin; /* swapins */ - long v_swpout; /* swapouts */ + long v_swtch; /* context switches */ + long v_trap; /* calls to trap */ + long v_syscall; /* calls to syscall() */ + long v_intr; /* device interrupts */ + long v_soft; /* software interrupts */ + long v_fpsim; /* floating point simulator faults */ + long v_kbin; /* kbytes swapped in */ + long v_kbout; /* kbytes swapped out */ + long v_swpin; /* swapins */ + long v_swpout; /* swapouts */ }; #if defined(KERNEL) && defined(UCB_METER) -struct vmrate cnt, rate; -struct vmsum sum; +struct vmrate cnt, rate; +struct vmsum sum; #endif /* systemwide totals computed every five seconds */ struct vmtotal { - short t_rq; /* length of the run queue */ - short t_dw; /* jobs in ``disk wait'' (neg priority) */ - short t_sl; /* jobs sleeping in core */ - short t_sw; /* swapped out runnable/short block jobs */ - long t_vm; /* total virtual memory, clicks */ - long t_avm; /* active virtual memory, clicks */ - size_t t_rm; /* total real memory, clicks */ - size_t t_arm; /* active real memory, clicks */ - long t_vmtxt; /* virtual memory used by text, clicks */ - long t_avmtxt; /* active virtual memory used by text, clicks */ - size_t t_rmtxt; /* real memory used by text, clicks */ - size_t t_armtxt; /* active real memory used by text, clicks */ - size_t t_free; /* free memory, kb */ + short t_rq; /* length of the run queue */ + short t_dw; /* jobs in ``disk wait'' (neg priority) */ + short t_sl; /* jobs sleeping in core */ + short t_sw; /* swapped out runnable/short block jobs */ + long t_vm; /* total virtual memory, clicks */ + long t_avm; /* active virtual memory, clicks */ + size_t t_rm; /* total real memory, clicks */ + size_t t_arm; /* active real memory, clicks */ + long t_vmtxt; /* virtual memory used by text, clicks */ + long t_avmtxt; /* active virtual memory used by text, clicks */ + size_t t_rmtxt; /* real memory used by text, clicks */ + size_t t_armtxt; /* active real memory used by text, clicks */ + size_t t_free; /* free memory, kb */ }; #ifdef KERNEL -struct vmtotal total; +struct vmtotal total; /* * Count up various things once a second diff --git a/sys/include/vmparam.h b/sys/include/vmparam.h index 684e583..210d420 100644 --- a/sys/include/vmparam.h +++ b/sys/include/vmparam.h @@ -7,16 +7,16 @@ /* * CTL_VM identifiers */ -#define VM_METER 1 /* struct vmmeter */ -#define VM_LOADAVG 2 /* struct loadavg */ -#define VM_SWAPMAP 3 /* struct mapent _swapmap[] */ -#define VM_MAXID 5 /* number of valid vm ids */ +#define VM_METER 1 /* struct vmmeter */ +#define VM_LOADAVG 2 /* struct loadavg */ +#define VM_SWAPMAP 3 /* struct mapent _swapmap[] */ +#define VM_MAXID 5 /* number of valid vm ids */ -#ifndef KERNEL +#ifndef KERNEL #define CTL_VM_NAMES { \ - { 0, 0 }, \ - { "vmmeter", CTLTYPE_STRUCT }, \ - { "loadavg", CTLTYPE_STRUCT }, \ - { "swapmap", CTLTYPE_STRUCT }, \ + { 0, 0 }, \ + { "vmmeter", CTLTYPE_STRUCT }, \ + { "loadavg", CTLTYPE_STRUCT }, \ + { "swapmap", CTLTYPE_STRUCT }, \ } #endif diff --git a/sys/include/vmsystm.h b/sys/include/vmsystm.h index 3312681..6f68a56 100644 --- a/sys/include/vmsystm.h +++ b/sys/include/vmsystm.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)vmsystm.h 7.2.1 (2.11BSD GTE) 1/15/95 + * @(#)vmsystm.h 7.2.1 (2.11BSD GTE) 1/15/95 */ /* @@ -11,25 +11,26 @@ */ #if defined(KERNEL) && defined(UCB_METER) && !defined(SUPERVISOR) -size_t freemem; /* remaining clicks of free memory */ +size_t freemem; /* remaining clicks of free memory */ -u_short avefree; /* moving average of remaining free clicks */ -u_short avefree30; /* 30 sec (avefree is 5 sec) moving average */ +u_short avefree; /* moving average of remaining free clicks */ +u_short avefree30; /* 30 sec (avefree is 5 sec) moving average */ /* writable copies of tunables */ -int maxslp; /* max sleep time before very swappable */ +int maxslp; /* max sleep time before very swappable */ #endif /* * Fork/vfork accounting. */ -struct forkstat +struct forkstat { - long cntfork; - long cntvfork; - long sizfork; - long sizvfork; + long cntfork; + long cntvfork; + long sizfork; + long sizvfork; }; + #if defined(KERNEL) && defined(UCB_METER) && !defined(SUPERVISOR) -struct forkstat forkstat; +struct forkstat forkstat; #endif diff --git a/sys/include/wait.h b/sys/include/wait.h index 587b0b1..0a41c8f 100644 --- a/sys/include/wait.h +++ b/sys/include/wait.h @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)wait.h 7.2.1 (2.11BSD GTE) 1995/06/23 + * @(#)wait.h 7.2.1 (2.11BSD GTE) 1995/06/23 */ /* @@ -20,33 +20,33 @@ * wait and wait3. If w_stopval==WSTOPPED, then the second structure * describes the information returned, else the first. See WUNTRACED below. */ -union wait { - int w_status; /* used in syscall */ - /* - * Terminated process status. - */ - struct { - unsigned w_Termsig :7; /* termination signal */ - unsigned w_Coredump :1; /* core dump indicator */ - unsigned w_Retcode :8; /* exit code if w_termsig==0 */ - } w_T; - /* - * Stopped process status. Returned - * only for traced children unless requested - * with the WUNTRACED option bit. - */ - struct { - unsigned w_Stopval :8; /* == W_STOPPED if stopped */ - unsigned w_Stopsig :8; /* signal that stopped us */ - } w_S; +union wait { + int w_status; /* used in syscall */ + /* + * Terminated process status. + */ + struct { + unsigned w_Termsig :7; /* termination signal */ + unsigned w_Coredump :1; /* core dump indicator */ + unsigned w_Retcode :8; /* exit code if w_termsig==0 */ + } w_T; + /* + * Stopped process status. Returned + * only for traced children unless requested + * with the WUNTRACED option bit. + */ + struct { + unsigned w_Stopval :8; /* == W_STOPPED if stopped */ + unsigned w_Stopsig :8; /* signal that stopped us */ + } w_S; }; -#define w_termsig w_T.w_Termsig -#define w_coredump w_T.w_Coredump -#define w_retcode w_T.w_Retcode -#define w_stopval w_S.w_Stopval -#define w_stopsig w_S.w_Stopsig +#define w_termsig w_T.w_Termsig +#define w_coredump w_T.w_Coredump +#define w_retcode w_T.w_Retcode +#define w_stopval w_S.w_Stopval +#define w_stopsig w_S.w_Stopsig -#define WSTOPPED 0177 /* value of s.stopval if process is stopped */ +#define WSTOPPED 0177 /* value of s.stopval if process is stopped */ /* * Option bits for the second argument of wait3. WNOHANG causes the @@ -57,24 +57,24 @@ union wait { * this option is done, it is as though they were still running... nothing * about them is returned. */ -#define WNOHANG 1 /* dont hang in wait */ -#define WUNTRACED 2 /* tell about stopped, untraced children */ +#define WNOHANG 1 /* dont hang in wait */ +#define WUNTRACED 2 /* tell about stopped, untraced children */ -#define WIFSTOPPED(x) (((union wait*)&(x))->w_stopval == WSTOPPED) -#define WIFSIGNALED(x) (((union wait*)&(x))->w_stopval != WSTOPPED &&\ +#define WIFSTOPPED(x) (((union wait*)&(x))->w_stopval == WSTOPPED) +#define WIFSIGNALED(x) (((union wait*)&(x))->w_stopval != WSTOPPED &&\ (((union wait*)&(x))->w_termsig != 0)) -#define WIFEXITED(x) (((union wait*)&(x))->w_stopval != WSTOPPED &&\ +#define WIFEXITED(x) (((union wait*)&(x))->w_stopval != WSTOPPED &&\ (((union wait*)&(x))->w_termsig == 0)) -#define WEXITSTATUS(x) (((union wait*)&(x))->w_retcode) -#define WTERMSIG(x) (((union wait*)&(x))->w_termsig) -#define WCOREDUMP(x) (((union wait*)&(x))->w_coredump) -#define WSTOPSIG(x) (((union wait*)&(x))->w_stopsig) +#define WEXITSTATUS(x) (((union wait*)&(x))->w_retcode) +#define WTERMSIG(x) (((union wait*)&(x))->w_termsig) +#define WCOREDUMP(x) (((union wait*)&(x))->w_coredump) +#define WSTOPSIG(x) (((union wait*)&(x))->w_stopsig) -#define W_STOPCODE(sig) ((sig << 8) | WSTOPPED) -#define W_EXITCODE(ret,sig) ((ret << 8) | (sig)) +#define W_STOPCODE(sig) ((sig << 8) | WSTOPPED) +#define W_EXITCODE(ret,sig) ((ret << 8) | (sig)) -#define WAIT_ANY (-1) -#define WAIT_MYPGRP 0 +#define WAIT_ANY (-1) +#define WAIT_MYPGRP 0 #ifndef KERNEL #include diff --git a/sys/kernel/exec_aout.c b/sys/kernel/exec_aout.c index 9aa78d1..68aa9d8 100644 --- a/sys/kernel/exec_aout.c +++ b/sys/kernel/exec_aout.c @@ -18,78 +18,78 @@ int exec_aout_check(struct exec_params *epp) { - int error; + int error; - if (epp->hdr_len < sizeof(struct exec)) - return ENOEXEC; - if (!(N_GETMID(epp->hdr.aout) == MID_ZERO && - N_GETFLAG(epp->hdr.aout) == 0)) - return ENOEXEC; + if (epp->hdr_len < sizeof(struct exec)) + return ENOEXEC; + if (!(N_GETMID(epp->hdr.aout) == MID_ZERO && + N_GETFLAG(epp->hdr.aout) == 0)) + return ENOEXEC; - switch (N_GETMAGIC(epp->hdr.aout)) { - case OMAGIC: - epp->hdr.aout.a_data += epp->hdr.aout.a_text; - epp->hdr.aout.a_text = 0; - break; - default: - printf("Bad a.out magic = %0o\n", N_GETMAGIC(epp->hdr.aout)); - return ENOEXEC; - } + switch (N_GETMAGIC(epp->hdr.aout)) { + case OMAGIC: + epp->hdr.aout.a_data += epp->hdr.aout.a_text; + epp->hdr.aout.a_text = 0; + break; + default: + printf("Bad a.out magic = %0o\n", N_GETMAGIC(epp->hdr.aout)); + return ENOEXEC; + } - /* - * Save arglist - */ - exec_save_args(epp); + /* + * Save arglist + */ + exec_save_args(epp); - DEBUG("Exec file header:\n"); - DEBUG("a_midmag = %#x\n", epp->hdr.aout.a_midmag); /* magic number */ - DEBUG("a_text = %d\n", epp->hdr.aout.a_text); /* size of text segment */ - DEBUG("a_data = %d\n", epp->hdr.aout.a_data); /* size of initialized data */ - DEBUG("a_bss = %d\n", epp->hdr.aout.a_bss); /* size of uninitialized data */ - DEBUG("a_reltext = %d\n", epp->hdr.aout.a_reltext); /* size of text relocation info */ - DEBUG("a_reldata = %d\n", epp->hdr.aout.a_reldata); /* size of data relocation info */ - DEBUG("a_syms = %d\n", epp->hdr.aout.a_syms); /* size of symbol table */ - DEBUG("a_entry = %#x\n", epp->hdr.aout.a_entry); /* entry point */ + DEBUG("Exec file header:\n"); + DEBUG("a_midmag = %#x\n", epp->hdr.aout.a_midmag); /* magic number */ + DEBUG("a_text = %d\n", epp->hdr.aout.a_text); /* size of text segment */ + DEBUG("a_data = %d\n", epp->hdr.aout.a_data); /* size of initialized data */ + DEBUG("a_bss = %d\n", epp->hdr.aout.a_bss); /* size of uninitialized data */ + DEBUG("a_reltext = %d\n", epp->hdr.aout.a_reltext); /* size of text relocation info */ + DEBUG("a_reldata = %d\n", epp->hdr.aout.a_reldata); /* size of data relocation info */ + DEBUG("a_syms = %d\n", epp->hdr.aout.a_syms); /* size of symbol table */ + DEBUG("a_entry = %#x\n", epp->hdr.aout.a_entry); /* entry point */ - /* - * Set up memory allocation - */ - epp->text.vaddr = epp->heap.vaddr = NO_ADDR; - epp->text.len = epp->heap.len = 0; + /* + * Set up memory allocation + */ + epp->text.vaddr = epp->heap.vaddr = NO_ADDR; + epp->text.len = epp->heap.len = 0; - epp->data.vaddr = (caddr_t)USER_DATA_START; - epp->data.len = epp->hdr.aout.a_data; - epp->bss.vaddr = epp->data.vaddr + epp->data.len; - epp->bss.len = epp->hdr.aout.a_bss; - epp->heap.vaddr = epp->bss.vaddr + epp->bss.len; - epp->heap.len = 0; - epp->stack.len = SSIZE + roundup(epp->argbc + epp->envbc, NBPW) + (epp->argc + epp->envc+4)*NBPW; - epp->stack.vaddr = (caddr_t)USER_DATA_END - epp->stack.len; + epp->data.vaddr = (caddr_t)USER_DATA_START; + epp->data.len = epp->hdr.aout.a_data; + epp->bss.vaddr = epp->data.vaddr + epp->data.len; + epp->bss.len = epp->hdr.aout.a_bss; + epp->heap.vaddr = epp->bss.vaddr + epp->bss.len; + epp->heap.len = 0; + epp->stack.len = SSIZE + roundup(epp->argbc + epp->envbc, NBPW) + (epp->argc + epp->envc+4)*NBPW; + epp->stack.vaddr = (caddr_t)USER_DATA_END - epp->stack.len; - /* - * Allocate core at this point, committed to the new image. - * TODO: What to do for errors? - */ - exec_estab(epp); + /* + * Allocate core at this point, committed to the new image. + * TODO: What to do for errors? + */ + exec_estab(epp); - /* read in text and data */ - DEBUG("reading a.out image\n"); - error = rdwri (UIO_READ, epp->ip, - (caddr_t)epp->data.vaddr, epp->hdr.aout.a_data, - sizeof(struct exec) + epp->hdr.aout.a_text, IO_UNIT, 0); - if (error) - DEBUG("read image returned error=%d\n", error); - if (error) { - /* - * Error - all is lost, when the old image is possible corrupt - * and we could not load a new. - */ - psignal (u.u_procp, SIGSEGV); - return error; - } + /* read in text and data */ + DEBUG("reading a.out image\n"); + error = rdwri (UIO_READ, epp->ip, + (caddr_t)epp->data.vaddr, epp->hdr.aout.a_data, + sizeof(struct exec) + epp->hdr.aout.a_text, IO_UNIT, 0); + if (error) + DEBUG("read image returned error=%d\n", error); + if (error) { + /* + * Error - all is lost, when the old image is possible corrupt + * and we could not load a new. + */ + psignal (u.u_procp, SIGSEGV); + return error; + } - exec_clear(epp); - exec_setupstack(epp->hdr.aout.a_entry, epp); + exec_clear(epp); + exec_setupstack(epp->hdr.aout.a_entry, epp); - return 0; + return 0; } diff --git a/sys/kernel/exec_conf.c b/sys/kernel/exec_conf.c index a541218..002ca0a 100644 --- a/sys/kernel/exec_conf.c +++ b/sys/kernel/exec_conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec_conf.c,v 1.43 2000/06/09 22:38:57 oki Exp $ */ +/* $NetBSD: exec_conf.c,v 1.43 2000/06/09 22:38:57 oki Exp $ */ /* * Copyright (c) 1993, 1994 Christopher G. Demetriou @@ -46,13 +46,13 @@ int exec_elf_check(struct exec_params *epp); const struct execsw execsw[] = { #ifdef EXEC_AOUT - { exec_aout_check, "a.out" }, /* a.out binaries */ + { exec_aout_check, "a.out" }, /* a.out binaries */ #endif #ifdef EXEC_ELF - { exec_elf_check, "elf" }, /* 32bit ELF bins */ + { exec_elf_check, "elf" }, /* 32bit ELF bins */ #endif #ifdef EXEC_SCRIPT - { exec_script_check, "script" }, /* shell scripts */ + { exec_script_check, "script" }, /* shell scripts */ #endif }; int nexecs = (sizeof(execsw) / sizeof(*execsw)); diff --git a/sys/kernel/exec_elf.c b/sys/kernel/exec_elf.c index 423ebf4..82062b0 100644 --- a/sys/kernel/exec_elf.c +++ b/sys/kernel/exec_elf.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf32.c,v 1.49.2.2 2000/11/03 20:00:38 tv Exp $ */ +/* $NetBSD: exec_elf32.c,v 1.49.2.2 2000/11/03 20:00:38 tv Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. @@ -70,24 +70,20 @@ #include "map.h" #include "user.h" #include "proc.h" -//#include "malloc.h" #include "inode.h" #include "namei.h" -//#include "vnode.h" #include "exec.h" #include "exec_elf.h" #include "fcntl.h" -//#include "syscall.h" #include "signalvar.h" #include "mount.h" #include "stat.h" - extern char sigcode[], esigcode[]; /* round up and down to page boundaries. */ -#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) -#define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) +#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) +#define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) /* * elf_check(): Prepare an Elf binary's exec package @@ -101,107 +97,107 @@ extern char sigcode[], esigcode[]; int exec_elf_check(struct exec_params *epp) { - struct elf_phdr *ph; - int error, i, phsize; + struct elf_phdr *ph; + int error, i, phsize; - const char elfident[] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, - ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ELFOSABI_SYSV, 0}; + const char elfident[] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, + ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ELFOSABI_SYSV, 0}; - /* - * Check that this is an ELF file that we can handle, - * and do some sanity checks on the header - */ - if (epp->hdr_len < sizeof(struct elf_ehdr)) - return ENOEXEC; - for (i = 0; i < sizeof elfident; i++) - if (epp->hdr.elf.e_ident[i] != elfident[i]) - return ENOEXEC; - if (epp->hdr.elf.e_type != ET_EXEC) - return ENOEXEC; - if (epp->hdr.elf.e_machine != EM_MIPS || epp->hdr.elf.e_version != EV_CURRENT) - return ENOEXEC; - if (epp->hdr.elf.e_phentsize != sizeof(struct elf_phdr) || epp->hdr.elf.e_phoff == 0 || epp->hdr.elf.e_phnum == 0) - return ENOEXEC; - if (epp->hdr.elf.e_shnum == 0 || epp->hdr.elf.e_shentsize != sizeof(struct elf_shdr)) - return ENOEXEC; + /* + * Check that this is an ELF file that we can handle, + * and do some sanity checks on the header + */ + if (epp->hdr_len < sizeof(struct elf_ehdr)) + return ENOEXEC; + for (i = 0; i < sizeof elfident; i++) + if (epp->hdr.elf.e_ident[i] != elfident[i]) + return ENOEXEC; + if (epp->hdr.elf.e_type != ET_EXEC) + return ENOEXEC; + if (epp->hdr.elf.e_machine != EM_MIPS || epp->hdr.elf.e_version != EV_CURRENT) + return ENOEXEC; + if (epp->hdr.elf.e_phentsize != sizeof(struct elf_phdr) || epp->hdr.elf.e_phoff == 0 || epp->hdr.elf.e_phnum == 0) + return ENOEXEC; + if (epp->hdr.elf.e_shnum == 0 || epp->hdr.elf.e_shentsize != sizeof(struct elf_shdr)) + return ENOEXEC; - /* - * Read program headers - */ - phsize = epp->hdr.elf.e_phnum * sizeof(struct elf_phdr); - ph = exec_alloc(phsize, NBPW, epp); - if (ph == NULL) { - printf("can't alloc ph[] sz=%d\n", phsize); - return ENOEXEC; - } - if ((error = rdwri(UIO_READ, epp->ip, (caddr_t)ph, phsize, epp->hdr.elf.e_phoff, IO_UNIT, 0)) != 0) - return ENOEXEC; + /* + * Read program headers + */ + phsize = epp->hdr.elf.e_phnum * sizeof(struct elf_phdr); + ph = exec_alloc(phsize, NBPW, epp); + if (ph == NULL) { + printf("can't alloc ph[] sz=%d\n", phsize); + return ENOEXEC; + } + if ((error = rdwri(UIO_READ, epp->ip, (caddr_t)ph, phsize, epp->hdr.elf.e_phoff, IO_UNIT, 0)) != 0) + return ENOEXEC; - epp->text.len = epp->data.len = epp->bss.len = epp->stack.len = epp->heap.len = 0; - epp->text.vaddr = epp->data.vaddr = epp->bss.vaddr = epp->stack.vaddr = epp->heap.vaddr = NO_ADDR; + epp->text.len = epp->data.len = epp->bss.len = epp->stack.len = epp->heap.len = 0; + epp->text.vaddr = epp->data.vaddr = epp->bss.vaddr = epp->stack.vaddr = epp->heap.vaddr = NO_ADDR; - if (epp->hdr.elf.e_phnum == 1 && ph[0].p_type == PT_LOAD && ph[0].p_flags == (PF_R|PF_W|PF_X)) { - /* - * In the simple a.out type link, in elf format, there is only - * one loadable segment that is RWE containing everything - * Here we fix the memory allocation, and we are done. - */ - epp->data.vaddr = (caddr_t)ph[0].p_vaddr; - epp->data.len = ph[0].p_memsz; - epp->heap.vaddr = (caddr_t)ph[0].p_vaddr + ph[0].p_memsz; - epp->heap.len = 0; - epp->stack.len = SSIZE + epp->argbc + epp->envbc + (epp->argc+epp->envc+4)*NBPW; - epp->stack.vaddr = (caddr_t)USER_DATA_END - epp->stack.len; + if (epp->hdr.elf.e_phnum == 1 && ph[0].p_type == PT_LOAD && ph[0].p_flags == (PF_R|PF_W|PF_X)) { + /* + * In the simple a.out type link, in elf format, there is only + * one loadable segment that is RWE containing everything + * Here we fix the memory allocation, and we are done. + */ + epp->data.vaddr = (caddr_t)ph[0].p_vaddr; + epp->data.len = ph[0].p_memsz; + epp->heap.vaddr = (caddr_t)ph[0].p_vaddr + ph[0].p_memsz; + epp->heap.len = 0; + epp->stack.len = SSIZE + epp->argbc + epp->envbc + (epp->argc+epp->envc+4)*NBPW; + epp->stack.vaddr = (caddr_t)USER_DATA_END - epp->stack.len; - /* - * We assume .bss is the different between the memory data - * section size and the file size. - */ - epp->bss.vaddr = epp->data.vaddr + ph[0].p_filesz; - epp->bss.len = ph[0].p_memsz - ph[0].p_filesz; - epp->data.len = epp->bss.vaddr - epp->data.vaddr; - } else { - /* - * At the current moment we don't handle anything else - * The rest of the code is implemented as need arise. - */ - return ENOEXEC; - } + /* + * We assume .bss is the different between the memory data + * section size and the file size. + */ + epp->bss.vaddr = epp->data.vaddr + ph[0].p_filesz; + epp->bss.len = ph[0].p_memsz - ph[0].p_filesz; + epp->data.len = epp->bss.vaddr - epp->data.vaddr; + } else { + /* + * At the current moment we don't handle anything else + * The rest of the code is implemented as need arise. + */ + return ENOEXEC; + } - /* - * Save arglist - */ - exec_save_args(epp); + /* + * Save arglist + */ + exec_save_args(epp); - /* - * Establish memory - */ - if ((error = exec_estab(epp)) != 0) - return error; + /* + * Establish memory + */ + if ((error = exec_estab(epp)) != 0) + return error; - /* - * Now load the program sections into memory - */ - for (i = 0; i < epp->hdr.elf.e_phnum; i++) { - if (ph[i].p_type != PT_LOAD) - continue; - /* - * Sanity check that the load is to our intended address space. - */ - if (!((epp->text.vaddr != NO_ADDR - && ((caddr_t)ph[i].p_vaddr >= epp->text.vaddr - && (caddr_t)ph[i].p_vaddr + ph[i].p_filesz <= epp->text.vaddr + epp->text.len)) - || (epp->data.vaddr != NO_ADDR - && (caddr_t)ph[i].p_vaddr >= epp->data.vaddr - && (caddr_t)ph[i].p_vaddr + ph[i].p_filesz <= epp->data.vaddr + epp->data.len)) - || ph[i].p_filesz >= ph[i].p_memsz || ph[i].p_filesz <= 0) - return ENOEXEC; - - error = rdwri(UIO_READ, epp->ip, (caddr_t)ph[i].p_vaddr, ph[i].p_filesz, ph[i].p_offset, IO_UNIT, 0); - } + /* + * Now load the program sections into memory + */ + for (i = 0; i < epp->hdr.elf.e_phnum; i++) { + if (ph[i].p_type != PT_LOAD) + continue; + /* + * Sanity check that the load is to our intended address space. + */ + if (!((epp->text.vaddr != NO_ADDR + && ((caddr_t)ph[i].p_vaddr >= epp->text.vaddr + && (caddr_t)ph[i].p_vaddr + ph[i].p_filesz <= epp->text.vaddr + epp->text.len)) + || (epp->data.vaddr != NO_ADDR + && (caddr_t)ph[i].p_vaddr >= epp->data.vaddr + && (caddr_t)ph[i].p_vaddr + ph[i].p_filesz <= epp->data.vaddr + epp->data.len)) + || ph[i].p_filesz >= ph[i].p_memsz || ph[i].p_filesz <= 0) + return ENOEXEC; - exec_clear(epp); - exec_setupstack(epp->hdr.elf.e_entry, epp); - - return 0; + error = rdwri(UIO_READ, epp->ip, (caddr_t)ph[i].p_vaddr, ph[i].p_filesz, ph[i].p_offset, IO_UNIT, 0); + } + + exec_clear(epp); + exec_setupstack(epp->hdr.elf.e_entry, epp); + + return 0; } diff --git a/sys/kernel/exec_script.c b/sys/kernel/exec_script.c index 1d59a70..fa04b86 100644 --- a/sys/kernel/exec_script.c +++ b/sys/kernel/exec_script.c @@ -9,88 +9,88 @@ int exec_script_check(struct exec_params *epp) { - char *cp; - struct nameidata nd; - struct nameidata *ndp; - int error; - struct inode *ip = 0; + char *cp; + struct nameidata nd; + struct nameidata *ndp; + int error; + struct inode *ip = 0; - /* - * We come here with the first line of the executable - * script file. - * Check is to see if it starts with the magic marker: #! - */ - if (epp->hdr.sh[0] != '#' || epp->hdr.sh[1] != '!' || epp->sh.interpreted) - return ENOEXEC; - epp->sh.interpreted = 1; + /* + * We come here with the first line of the executable + * script file. + * Check is to see if it starts with the magic marker: #! + */ + if (epp->hdr.sh[0] != '#' || epp->hdr.sh[1] != '!' || epp->sh.interpreted) + return ENOEXEC; + epp->sh.interpreted = 1; - /* - * If setuid/gid scripts were to be disallowed this is where it would - * have to be done. - * u.u_uid = uid; - * u.u_gid = u_groups[0]; - */ + /* + * If setuid/gid scripts were to be disallowed this is where it would + * have to be done. + * u.u_uid = uid; + * u.u_gid = u_groups[0]; + */ - /* - * The first line of the text file - * should be one line on the format: - * #! \n - */ - cp = &epp->hdr.sh[2]; - while (cp < &epp->hdr.sh[MIN(epp->hdr_len, SHSIZE)]) { - if (*cp == '\t') - *cp = ' '; - else if (*cp == '\n') { - *cp = '\0'; - break; - } - cp++; - } - if (cp == &epp->hdr.sh[MIN(epp->hdr_len, SHSIZE)]) - return ENOEXEC; + /* + * The first line of the text file + * should be one line on the format: + * #! \n + */ + cp = &epp->hdr.sh[2]; + while (cp < &epp->hdr.sh[MIN(epp->hdr_len, SHSIZE)]) { + if (*cp == '\t') + *cp = ' '; + else if (*cp == '\n') { + *cp = '\0'; + break; + } + cp++; + } + if (cp == &epp->hdr.sh[MIN(epp->hdr_len, SHSIZE)]) + return ENOEXEC; - /* - * Pick up script interpreter file name - */ - cp = &epp->hdr.sh[2]; - while (*cp == ' ') - cp++; - if (!*cp) - return ENOEXEC; - bzero(&nd, sizeof nd); - ndp = &nd; - ndp->ni_dirp = cp; - while (*cp && *cp != ' ') - cp++; - if (*cp != '\0') { - *cp++ = 0; - while (*cp && *cp == ' ') - cp++; - if (*cp) { - if ((error = copystr(cp, epp->sh.interparg, sizeof epp->sh.interparg, NULL))) - goto done; - } - } + /* + * Pick up script interpreter file name + */ + cp = &epp->hdr.sh[2]; + while (*cp == ' ') + cp++; + if (!*cp) + return ENOEXEC; + bzero(&nd, sizeof nd); + ndp = &nd; + ndp->ni_dirp = cp; + while (*cp && *cp != ' ') + cp++; + if (*cp != '\0') { + *cp++ = 0; + while (*cp && *cp == ' ') + cp++; + if (*cp) { + if ((error = copystr(cp, epp->sh.interparg, sizeof epp->sh.interparg, NULL))) + goto done; + } + } - /* - * the interpreter is the new file to exec - */ - ndp->ni_nameiop = LOOKUP | FOLLOW; - ip = namei (ndp); - if (ip == NULL) - return u.u_error; - if ((error = copystr(ndp->ni_dent.d_name, epp->sh.interpname, sizeof epp->sh.interpname, NULL))) - goto done; + /* + * the interpreter is the new file to exec + */ + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei (ndp); + if (ip == NULL) + return u.u_error; + if ((error = copystr(ndp->ni_dent.d_name, epp->sh.interpname, sizeof epp->sh.interpname, NULL))) + goto done; - /* - * Everything set up, do the recursive exec() - */ - if (epp->ip) - iput(epp->ip); - epp->ip = ip; - error = exec_check(epp); + /* + * Everything set up, do the recursive exec() + */ + if (epp->ip) + iput(epp->ip); + epp->ip = ip; + error = exec_check(epp); done: - if (ip) - iput(ip); - return error; + if (ip) + iput(ip); + return error; } diff --git a/sys/kernel/exec_subr.c b/sys/kernel/exec_subr.c index 4e12abb..3f58560 100644 --- a/sys/kernel/exec_subr.c +++ b/sys/kernel/exec_subr.c @@ -20,38 +20,37 @@ * * var a: * USER_DATA_END: !----------! - * ! +P_ssize ! stack - * p_saddr -> ¡----------! + * ! +P_ssize ! stack + * p_saddr -> ¡----------! * - * !----------! - * ! +P_dsize ! .data + .bss + heap - * P_daddr -> !----------! + * !----------! + * ! +P_dsize ! .data + .bss + heap + * P_daddr -> !----------! * * var b: * * USER_DATA_END: !--------! - * ! +ssize ! stack - * saddr -> ¡--------! - * ! +hsize ! heap - * haddr -> !--------! - * ! +dsize ! .data + .bss - * daddr -> !--------! - * ! +tsize ! .text - * taddr -> !--------! + * ! +ssize ! stack + * saddr -> ¡--------! + * ! +hsize ! heap + * haddr -> !--------! + * ! +dsize ! .data + .bss + * daddr -> !--------! + * ! +tsize ! .text + * taddr -> !--------! * paddr -> +psize * * var c: * !--------! - * ! +tsize ! .text (read only section) - * taddr -> !--------! - * ! +ssize ! stack - * saddr -> ¡--------! - * ! +hsize ! heap - * haddr -> !--------! - * ! +dsize ! .data + .bss - * daddr -> !--------! + * ! +tsize ! .text (read only section) + * taddr -> !--------! + * ! +ssize ! stack + * saddr -> ¡--------! + * ! +hsize ! heap + * haddr -> !--------! + * ! +dsize ! .data + .bss + * daddr -> !--------! * paddr -> +psize - * */ /* @@ -59,91 +58,91 @@ * * The following is a key to top of the stack and the variables used. * - * topp-> [argv] top word for /bin/ps - * <0> - * n - * g - * r - * a - * ... - * <0> - * 0 - * g - * r - * ucp -> a - * [0] - * [envn] - * ... - * envp -> [env0] - * [0] - * [argn] ptr to argn - * ... - * argp -> [arg0] ptr to arg0 - * [] - * [] - * [] - * sp -> [] + * topp-> [argv] top word for /bin/ps + * <0> + * n + * g + * r + * a + * ... + * <0> + * 0 + * g + * r + * ucp -> a + * [0] + * [envn] + * ... + * envp -> [env0] + * [0] + * [argn] ptr to argn + * ... + * argp -> [arg0] ptr to arg0 + * [] + * [] + * [] + * sp -> [] * */ void exec_setupstack(unsigned entryaddr, struct exec_params *epp) { - int nc,i; - u_int len; - char *ucp; - char **argp, **envp, ***topp; + int nc,i; + u_int len; + char *ucp; + char **argp, **envp, ***topp; - DEBUG("exec_setupstack:\n"); + DEBUG("exec_setupstack:\n"); - /* - * Set up top of stack structure as above - * This depends on that kernel and user spaces - * map to the same addresses. - */ - topp = (char ***)(epp->stack.vaddr + epp->stack.len - NBPW); /* Last word of RAM */ - ucp = (char *)((unsigned)topp - roundup(epp->envbc + epp->argbc,NBPW)); /* arg string space */ - envp = (char **)(ucp - (epp->envc+1)*NBPW); /* Make place for envp[...], +1 for the 0 */ - argp = envp - (epp->argc+1)*NBPW; /* Make place for argv[...] */ - u.u_frame [FRAME_SP] = (int)(argp-16); - u.u_frame [FRAME_R4] = epp->argc; /* $a0 := argc */ - u.u_frame [FRAME_R5] = (int)argp; /* $a1 := argp */ - u.u_frame [FRAME_R6] = (int)envp; /* $a2 := env */ - *topp = argp; /* for /bin/ps */ + /* + * Set up top of stack structure as above + * This depends on that kernel and user spaces + * map to the same addresses. + */ + topp = (char ***)(epp->stack.vaddr + epp->stack.len - NBPW); /* Last word of RAM */ + ucp = (char *)((unsigned)topp - roundup(epp->envbc + epp->argbc,NBPW)); /* arg string space */ + envp = (char **)(ucp - (epp->envc+1)*NBPW); /* Make place for envp[...], +1 for the 0 */ + argp = envp - (epp->argc+1)*NBPW; /* Make place for argv[...] */ + u.u_frame [FRAME_SP] = (int)(argp-16); + u.u_frame [FRAME_R4] = epp->argc; /* $a0 := argc */ + u.u_frame [FRAME_R5] = (int)argp; /* $a1 := argp */ + u.u_frame [FRAME_R6] = (int)envp; /* $a2 := env */ + *topp = argp; /* for /bin/ps */ - /* - * copy the arguments into the structure - */ - nc = 0; - for (i = 0; i < epp->argc; i++) { - argp[i] = (caddr_t)ucp; - if (copystr((caddr_t)epp->argp[i], (caddr_t)ucp, (caddr_t)topp-ucp, &len) == 0) { - nc += len; - ucp += len; - } - } - argp[epp->argc] = NULL; + /* + * copy the arguments into the structure + */ + nc = 0; + for (i = 0; i < epp->argc; i++) { + argp[i] = (caddr_t)ucp; + if (copystr((caddr_t)epp->argp[i], (caddr_t)ucp, (caddr_t)topp-ucp, &len) == 0) { + nc += len; + ucp += len; + } + } + argp[epp->argc] = NULL; - for (i = 0; i < epp->envc; i++) { - envp[i] = ucp; - if (copystr((caddr_t)epp->envp[i], (caddr_t)ucp, (caddr_t)topp-ucp, &len) == 0) { - nc += len; - ucp += len; - } - } - envp[epp->envc] = NULL; + for (i = 0; i < epp->envc; i++) { + envp[i] = ucp; + if (copystr((caddr_t)epp->envp[i], (caddr_t)ucp, (caddr_t)topp-ucp, &len) == 0) { + nc += len; + ucp += len; + } + } + envp[epp->envc] = NULL; - ucp = (caddr_t)roundup((unsigned)ucp, NBPW); - if ((caddr_t)ucp != (caddr_t)topp) { - DEBUG("Copying of arg list went wrong, ucp=%#x, topp=%#x\n", ucp, topp); - panic("exec check"); - } + ucp = (caddr_t)roundup((unsigned)ucp, NBPW); + if ((caddr_t)ucp != (caddr_t)topp) { + DEBUG("Copying of arg list went wrong, ucp=%#x, topp=%#x\n", ucp, topp); + panic("exec check"); + } - u.u_frame [FRAME_PC] = entryaddr; - DEBUG("Setting up new PC=%#x\n", entryaddr); + u.u_frame [FRAME_PC] = entryaddr; + DEBUG("Setting up new PC=%#x\n", entryaddr); - /* - * Remember file name for accounting. - */ - (void) copystr(argp[0], u.u_comm, MAXCOMLEN, 0); + /* + * Remember file name for accounting. + */ + (void) copystr(argp[0], u.u_comm, MAXCOMLEN, 0); } /* @@ -157,26 +156,26 @@ void exec_setupstack(unsigned entryaddr, struct exec_params *epp) */ void *exec_alloc(int size, int ru, struct exec_params *epp) { - char *cp; - int i; + char *cp; + int i; - for (i = 0; i < MAXALLOCBUF; i++) - if (MAXBSIZE - (ru<=1?epp->alloc[i].fill:roundup(epp->alloc[i].fill,ru)) >= size) - break; - if (i == MAXALLOCBUF) - return NULL; - if (epp->alloc[i].bp == NULL) { - if ((epp->alloc[i].bp = geteblk()) == NULL) { - DEBUG("exec_alloc: no buf\n"); - return NULL; - } - } - if (ru > 1) - epp->alloc[i].fill = roundup(epp->alloc[i].fill, ru); - cp = epp->alloc[i].bp->b_addr + epp->alloc[i].fill; - epp->alloc[i].fill += size; - bzero (cp, size); - return cp; + for (i = 0; i < MAXALLOCBUF; i++) + if (MAXBSIZE - (ru<=1?epp->alloc[i].fill:roundup(epp->alloc[i].fill,ru)) >= size) + break; + if (i == MAXALLOCBUF) + return NULL; + if (epp->alloc[i].bp == NULL) { + if ((epp->alloc[i].bp = geteblk()) == NULL) { + DEBUG("exec_alloc: no buf\n"); + return NULL; + } + } + if (ru > 1) + epp->alloc[i].fill = roundup(epp->alloc[i].fill, ru); + cp = epp->alloc[i].bp->b_addr + epp->alloc[i].fill; + epp->alloc[i].fill += size; + bzero (cp, size); + return cp; } /* @@ -184,14 +183,14 @@ void *exec_alloc(int size, int ru, struct exec_params *epp) */ void exec_alloc_freeall(struct exec_params *epp) { - int i; - for (i = 0; i < MAXALLOCBUF; i++) { - if (epp->alloc[i].bp) { - brelse(epp->alloc[i].bp); - epp->alloc[i].bp = NULL; - epp->alloc[i].fill = 0; - } - } + int i; + for (i = 0; i < MAXALLOCBUF; i++) { + if (epp->alloc[i].bp) { + brelse(epp->alloc[i].bp); + epp->alloc[i].bp = NULL; + epp->alloc[i].fill = 0; + } + } } /* @@ -201,46 +200,46 @@ void exec_alloc_freeall(struct exec_params *epp) */ int exec_estab(struct exec_params *epp) { - DEBUG("text = %#x..%#x, len=%d\n", epp->text.vaddr, epp->text.vaddr+epp->text.len, epp->text.len); - DEBUG("data = %#x..%#x, len=%d\n", epp->data.vaddr, epp->data.vaddr+epp->data.len, epp->data.len); - DEBUG("bss = %#x..%#x, len=%d\n", epp->bss.vaddr, epp->bss.vaddr+epp->bss.len, epp->bss.len); - DEBUG("heap = %#x..%#x, len=%d\n", epp->heap.vaddr, epp->heap.vaddr+epp->heap.len, epp->heap.len); - DEBUG("stack = %#x..%#x, len=%d\n", epp->stack.vaddr, epp->stack.vaddr+epp->stack.len, epp->stack.len); + DEBUG("text = %#x..%#x, len=%d\n", epp->text.vaddr, epp->text.vaddr+epp->text.len, epp->text.len); + DEBUG("data = %#x..%#x, len=%d\n", epp->data.vaddr, epp->data.vaddr+epp->data.len, epp->data.len); + DEBUG("bss = %#x..%#x, len=%d\n", epp->bss.vaddr, epp->bss.vaddr+epp->bss.len, epp->bss.len); + DEBUG("heap = %#x..%#x, len=%d\n", epp->heap.vaddr, epp->heap.vaddr+epp->heap.len, epp->heap.len); + DEBUG("stack = %#x..%#x, len=%d\n", epp->stack.vaddr, epp->stack.vaddr+epp->stack.len, epp->stack.len); - /* - * Right now we can only handle the simple original a.out - * case, so we double check for that case here. - */ - if (epp->text.vaddr != NO_ADDR || epp->data.vaddr == NO_ADDR - || epp->data.vaddr != (caddr_t)USER_DATA_START || epp->stack.vaddr != (caddr_t)USER_DATA_END - epp->stack.len) - return ENOMEM; + /* + * Right now we can only handle the simple original a.out + * case, so we double check for that case here. + */ + if (epp->text.vaddr != NO_ADDR || epp->data.vaddr == NO_ADDR + || epp->data.vaddr != (caddr_t)USER_DATA_START || epp->stack.vaddr != (caddr_t)USER_DATA_END - epp->stack.len) + return ENOMEM; - /* - * Try out for overflow - */ - if (epp->text.len + epp->data.len + epp->heap.len + epp->stack.len > MAXMEM) - return ENOMEM; + /* + * Try out for overflow + */ + if (epp->text.len + epp->data.len + epp->heap.len + epp->stack.len > MAXMEM) + return ENOMEM; - if (roundup((unsigned)epp->data.vaddr + epp->data.len, NBPW) != roundup((unsigned)epp->bss.vaddr, NBPW)) { - DEBUG(".bss do not follow .data\n"); - return ENOMEM; - } + if (roundup((unsigned)epp->data.vaddr + epp->data.len, NBPW) != roundup((unsigned)epp->bss.vaddr, NBPW)) { + DEBUG(".bss do not follow .data\n"); + return ENOMEM; + } - /* - * Allocate core at this point, committed to the new image. - */ - u.u_prof.pr_scale = 0; - if (u.u_procp->p_flag & SVFORK) - endvfork(); - u.u_procp->p_dsize = epp->data.len + epp->bss.len; - u.u_procp->p_daddr = (size_t)epp->data.vaddr; - u.u_procp->p_ssize = epp->stack.len; - u.u_procp->p_saddr = (size_t)epp->stack.vaddr; + /* + * Allocate core at this point, committed to the new image. + */ + u.u_prof.pr_scale = 0; + if (u.u_procp->p_flag & SVFORK) + endvfork(); + u.u_procp->p_dsize = epp->data.len + epp->bss.len; + u.u_procp->p_daddr = (size_t)epp->data.vaddr; + u.u_procp->p_ssize = epp->stack.len; + u.u_procp->p_saddr = (size_t)epp->stack.vaddr; - DEBUG("core allocation: \n"); - DEBUG("daddr =%#x..%#x\n", u.u_procp->p_daddr, u.u_procp->p_daddr + u.u_procp->p_dsize); - DEBUG("saddr =%#x..%#x\n", u.u_procp->p_saddr, u.u_procp->p_saddr + u.u_procp->p_ssize); - return 0; + DEBUG("core allocation: \n"); + DEBUG("daddr =%#x..%#x\n", u.u_procp->p_daddr, u.u_procp->p_daddr + u.u_procp->p_dsize); + DEBUG("saddr =%#x..%#x\n", u.u_procp->p_saddr, u.u_procp->p_saddr + u.u_procp->p_ssize); + return 0; } @@ -249,177 +248,170 @@ int exec_estab(struct exec_params *epp) */ void exec_save_args(struct exec_params *epp) { - unsigned len; - caddr_t cp; - int argc, i, l; - char **argp, *ap; + unsigned len; + caddr_t cp; + int argc, i, l; + char **argp, *ap; - epp->argc = epp->envc = 0; - epp->argbc = epp->envbc = 0; + epp->argc = epp->envc = 0; + epp->argbc = epp->envbc = 0; - argc = 0; - if ((argp = epp->userargp) != NULL) - while (argp[argc]) - argc++; + argc = 0; + if ((argp = epp->userargp) != NULL) + while (argp[argc]) + argc++; #ifdef EXEC_SCRIPT - if (epp->sh.interpreted) { - argc++; - if (epp->sh.interparg[0]) - argc++; - } + if (epp->sh.interpreted) { + argc++; + if (epp->sh.interparg[0]) + argc++; + } #endif - if (argc != 0) { - if ((epp->argp = (char **)exec_alloc(argc * sizeof(char *), NBPW, epp)) == NULL) - return; - for (;;) { - /* - * For a interpreter script, the arg list is changed to - * #! - * arg[0] - the interpreter executable name (path) - * arg[1] - interpreter arg (optional) - * arg[2 or 1] - script name - * arg[3 or 2...] - script arg[1...] - */ - if (argp) - ap = *argp++; - else - ap = NULL; + if (argc != 0) { + if ((epp->argp = (char **)exec_alloc(argc * sizeof(char *), NBPW, epp)) == NULL) + return; + for (;;) { + /* + * For a interpreter script, the arg list is changed to + * #! + * arg[0] - the interpreter executable name (path) + * arg[1] - interpreter arg (optional) + * arg[2 or 1] - script name + * arg[3 or 2...] - script arg[1...] + */ + if (argp) + ap = *argp++; + else + ap = NULL; #ifdef EXEC_SCRIPT - if (epp->sh.interpreted) { - if (epp->argc == 0) - ap = epp->sh.interpname; - else if (epp->argc == 1 && epp->sh.interparg[0]) { - ap = epp->sh.interparg; - --argp; - } else if ((epp->argc == 1 || (epp->argc == 2 && epp->sh.interparg[0]))) { - ap = epp->userfname; - --argp; - } - } + if (epp->sh.interpreted) { + if (epp->argc == 0) + ap = epp->sh.interpname; + else if (epp->argc == 1 && epp->sh.interparg[0]) { + ap = epp->sh.interparg; + --argp; + } else if ((epp->argc == 1 || (epp->argc == 2 && epp->sh.interparg[0]))) { + ap = epp->userfname; + --argp; + } + } #endif - if (ap == 0) - break; - l = strlen(ap)+1; - if ((cp = exec_alloc(l, 1, epp)) == NULL) - return; - if (copystr(ap, cp, l, &len) != 0) - return; - epp->argp[epp->argc++] = cp; - epp->argbc += len;; - } - } - argc = 0; - if ((argp = epp->userenvp) != NULL) - while (argp[argc]) - argc++; - epp->envc = 0; - epp->envbc = 0; - if (argc != 0) { - if ((epp->envp = (char **)exec_alloc(argc * sizeof(char *), NBPW, epp)) == NULL) - return; - for (;;) { - if (argp) - ap = *argp++; - else - ap = NULL; - if (ap == 0) - break; - l = strlen(ap)+1; - if ((cp = exec_alloc(l, 1, epp)) == NULL) - return; - if (copystr(ap, cp, l, &len) != 0) - return; - epp->envp[epp->envc++] = cp; - epp->envbc += len; - } - } + if (ap == 0) + break; + l = strlen(ap)+1; + if ((cp = exec_alloc(l, 1, epp)) == NULL) + return; + if (copystr(ap, cp, l, &len) != 0) + return; + epp->argp[epp->argc++] = cp; + epp->argbc += len;; + } + } + argc = 0; + if ((argp = epp->userenvp) != NULL) + while (argp[argc]) + argc++; + epp->envc = 0; + epp->envbc = 0; + if (argc != 0) { + if ((epp->envp = (char **)exec_alloc(argc * sizeof(char *), NBPW, epp)) == NULL) + return; + for (;;) { + if (argp) + ap = *argp++; + else + ap = NULL; + if (ap == 0) + break; + l = strlen(ap)+1; + if ((cp = exec_alloc(l, 1, epp)) == NULL) + return; + if (copystr(ap, cp, l, &len) != 0) + return; + epp->envp[epp->envc++] = cp; + epp->envbc += len; + } + } - for (i = 0; i < epp->argc; i++) - DEBUG("arg[%d] = \"%s\"\n", i, epp->argp[i]); + for (i = 0; i < epp->argc; i++) + DEBUG("arg[%d] = \"%s\"\n", i, epp->argp[i]); - for (i = 0; i < epp->envc; i++) - DEBUG("env[%d] = \"%s\"\n", i, epp->envp[i]); - - - /* - * Number of string pool chars needed for this arg list - */ -// return (bc + NBPW-1) & ~(NBPW-1); - return; + for (i = 0; i < epp->envc; i++) + DEBUG("env[%d] = \"%s\"\n", i, epp->envp[i]); } void exec_clear(struct exec_params *epp) { - char *cp; - int cc; + char *cp; + int cc; - /* clear BSS */ - if (epp->bss.len > 0) - bzero((void *)epp->bss.vaddr, epp->bss.len); - if (epp->heap.len > 0) - bzero((void *)epp->heap.vaddr, epp->heap.len); - /* Clear stack */ - bzero((void *)epp->stack.vaddr, epp->stack.len); + /* clear BSS */ + if (epp->bss.len > 0) + bzero((void *)epp->bss.vaddr, epp->bss.len); + if (epp->heap.len > 0) + bzero((void *)epp->heap.vaddr, epp->heap.len); + /* Clear stack */ + bzero((void *)epp->stack.vaddr, epp->stack.len); - /* - * set SUID/SGID protections, if no tracing - */ - if ((u.u_procp->p_flag & P_TRACED) == 0) { - u.u_uid = epp->uid; - u.u_procp->p_uid = epp->uid; - u.u_groups[0] = epp->gid; - } else - psignal (u.u_procp, SIGTRAP); - u.u_svuid = u.u_uid; - u.u_svgid = u.u_groups[0]; + /* + * set SUID/SGID protections, if no tracing + */ + if ((u.u_procp->p_flag & P_TRACED) == 0) { + u.u_uid = epp->uid; + u.u_procp->p_uid = epp->uid; + u.u_groups[0] = epp->gid; + } else + psignal (u.u_procp, SIGTRAP); + u.u_svuid = u.u_uid; + u.u_svgid = u.u_groups[0]; - u.u_tsize = epp->text.len; - u.u_dsize = epp->data.len + epp->bss.len; - u.u_ssize = epp->stack.len; + u.u_tsize = epp->text.len; + u.u_dsize = epp->data.len + epp->bss.len; + u.u_ssize = epp->stack.len; - /* - * Clear registers. - */ - u.u_frame [FRAME_R1] = 0; /* $at */ - u.u_frame [FRAME_R2] = 0; /* $v0 */ - u.u_frame [FRAME_R3] = 0; /* $v1 */ - u.u_frame [FRAME_R7] = 0; /* $a3 */ - u.u_frame [FRAME_R8] = 0; /* $t0 */ - u.u_frame [FRAME_R9] = 0; /* $t1 */ - u.u_frame [FRAME_R10] = 0; /* $t2 */ - u.u_frame [FRAME_R11] = 0; /* $t3 */ - u.u_frame [FRAME_R12] = 0; /* $t4 */ - u.u_frame [FRAME_R13] = 0; /* $t5 */ - u.u_frame [FRAME_R14] = 0; /* $t6 */ - u.u_frame [FRAME_R15] = 0; /* $t7 */ - u.u_frame [FRAME_R16] = 0; /* $s0 */ - u.u_frame [FRAME_R17] = 0; /* $s1 */ - u.u_frame [FRAME_R18] = 0; /* $s2 */ - u.u_frame [FRAME_R19] = 0; /* $s3 */ - u.u_frame [FRAME_R20] = 0; /* $s4 */ - u.u_frame [FRAME_R21] = 0; /* $s5 */ - u.u_frame [FRAME_R22] = 0; /* $s6 */ - u.u_frame [FRAME_R23] = 0; /* $s7 */ - u.u_frame [FRAME_R24] = 0; /* $t8 */ - u.u_frame [FRAME_R25] = 0; /* $t9 */ - u.u_frame [FRAME_FP] = 0; - u.u_frame [FRAME_RA] = 0; - u.u_frame [FRAME_LO] = 0; - u.u_frame [FRAME_HI] = 0; - u.u_frame [FRAME_GP] = 0; + /* + * Clear registers. + */ + u.u_frame [FRAME_R1] = 0; /* $at */ + u.u_frame [FRAME_R2] = 0; /* $v0 */ + u.u_frame [FRAME_R3] = 0; /* $v1 */ + u.u_frame [FRAME_R7] = 0; /* $a3 */ + u.u_frame [FRAME_R8] = 0; /* $t0 */ + u.u_frame [FRAME_R9] = 0; /* $t1 */ + u.u_frame [FRAME_R10] = 0; /* $t2 */ + u.u_frame [FRAME_R11] = 0; /* $t3 */ + u.u_frame [FRAME_R12] = 0; /* $t4 */ + u.u_frame [FRAME_R13] = 0; /* $t5 */ + u.u_frame [FRAME_R14] = 0; /* $t6 */ + u.u_frame [FRAME_R15] = 0; /* $t7 */ + u.u_frame [FRAME_R16] = 0; /* $s0 */ + u.u_frame [FRAME_R17] = 0; /* $s1 */ + u.u_frame [FRAME_R18] = 0; /* $s2 */ + u.u_frame [FRAME_R19] = 0; /* $s3 */ + u.u_frame [FRAME_R20] = 0; /* $s4 */ + u.u_frame [FRAME_R21] = 0; /* $s5 */ + u.u_frame [FRAME_R22] = 0; /* $s6 */ + u.u_frame [FRAME_R23] = 0; /* $s7 */ + u.u_frame [FRAME_R24] = 0; /* $t8 */ + u.u_frame [FRAME_R25] = 0; /* $t9 */ + u.u_frame [FRAME_FP] = 0; + u.u_frame [FRAME_RA] = 0; + u.u_frame [FRAME_LO] = 0; + u.u_frame [FRAME_HI] = 0; + u.u_frame [FRAME_GP] = 0; - execsigs (u.u_procp); + execsigs (u.u_procp); - /* - * Clear (close) files - */ - for (cp = u.u_pofile, cc = 0; cc <= u.u_lastfile; cc++, cp++) { - if (*cp & UF_EXCLOSE) { - (void) closef (u.u_ofile [cc]); - u.u_ofile [cc] = NULL; - *cp = 0; - } - } - while (u.u_lastfile >= 0 && u.u_ofile [u.u_lastfile] == NULL) - u.u_lastfile--; + /* + * Clear (close) files + */ + for (cp = u.u_pofile, cc = 0; cc <= u.u_lastfile; cc++, cp++) { + if (*cp & UF_EXCLOSE) { + (void) closef (u.u_ofile [cc]); + u.u_ofile [cc] = NULL; + *cp = 0; + } + } + while (u.u_lastfile >= 0 && u.u_ofile [u.u_lastfile] == NULL) + u.u_lastfile--; } diff --git a/sys/kernel/init_main.c b/sys/kernel/init_main.c index 436b9d1..593b49c 100644 --- a/sys/kernel/init_main.c +++ b/sys/kernel/init_main.c @@ -23,9 +23,9 @@ #include "stat.h" #include "rdisk.h" -u_int swapstart, nswap; /* start and size of swap space */ -size_t physmem; /* total amount of physical memory */ -int boothowto; /* reboot flags, from boot */ +u_int swapstart, nswap; /* start and size of swap space */ +size_t physmem; /* total amount of physical memory */ +int boothowto; /* reboot flags, from boot */ /* * Initialize hash links for buffers. @@ -33,11 +33,11 @@ int boothowto; /* reboot flags, from boot */ static void bhinit() { - register int i; - register struct bufhd *bp; + register int i; + register struct bufhd *bp; - for (bp = bufhash, i = 0; i < BUFHSZ; i++, bp++) - bp->b_forw = bp->b_back = (struct buf *)bp; + for (bp = bufhash, i = 0; i < BUFHSZ; i++, bp++) + bp->b_forw = bp->b_back = (struct buf *)bp; } /* @@ -47,22 +47,22 @@ bhinit() static void binit() { - register struct buf *bp; - register int i; - caddr_t paddr; + register struct buf *bp; + register int i; + caddr_t paddr; - for (bp = bfreelist; bp < &bfreelist[BQUEUES]; bp++) - bp->b_forw = bp->b_back = bp->av_forw = bp->av_back = bp; - paddr = bufdata; - for (i = 0; i < NBUF; i++, paddr += MAXBSIZE) { - bp = &buf[i]; - bp->b_dev = NODEV; - bp->b_bcount = 0; - bp->b_addr = paddr; - binshash(bp, &bfreelist[BQ_AGE]); - bp->b_flags = B_BUSY|B_INVAL; - brelse(bp); - } + for (bp = bfreelist; bp < &bfreelist[BQUEUES]; bp++) + bp->b_forw = bp->b_back = bp->av_forw = bp->av_back = bp; + paddr = bufdata; + for (i = 0; i < NBUF; i++, paddr += MAXBSIZE) { + bp = &buf[i]; + bp->b_dev = NODEV; + bp->b_bcount = 0; + bp->b_addr = paddr; + binshash(bp, &bfreelist[BQ_AGE]); + bp->b_flags = B_BUSY|B_INVAL; + brelse(bp); + } } /* @@ -72,16 +72,16 @@ binit() static void cinit() { - register int ccp; - register struct cblock *cp; + register int ccp; + register struct cblock *cp; - ccp = (int)cfree; - ccp = (ccp + CROUND) & ~CROUND; - for (cp = (struct cblock *)ccp; cp <= &cfree[NCLIST - 1]; cp++) { - cp->c_next = cfreelist; - cfreelist = cp; - cfreecount += CBSIZE; - } + ccp = (int)cfree; + ccp = (ccp + CROUND) & ~CROUND; + for (cp = (struct cblock *)ccp; cp <= &cfree[NCLIST - 1]; cp++) { + cp->c_next = cfreelist; + cfreelist = cp; + cfreecount += CBSIZE; + } } /* @@ -90,252 +90,252 @@ cinit() * soon as a stack and segmentation * have been established. * Functions: - * clear and free user core - * turn on clock - * hand craft 0th process - * call all initialization routines - * fork - process 0 to schedule - * - process 1 execute bootstrap + * clear and free user core + * turn on clock + * hand craft 0th process + * call all initialization routines + * fork - process 0 to schedule + * - process 1 execute bootstrap */ int main() { - register struct proc *p; - register int i; - register struct fs *fs = NULL; - char inbuf[4]; - char inch; - int s __attribute__((unused)); + register struct proc *p; + register int i; + register struct fs *fs = NULL; + char inbuf[4]; + char inch; + int s __attribute__((unused)); - startup(); - printf ("\n%s", version); - cpuidentify(); - cnidentify(); + startup(); + printf ("\n%s", version); + cpuidentify(); + cnidentify(); - /* - * Set up system process 0 (swapper). - */ - p = &proc[0]; - p->p_addr = (size_t) &u; - p->p_stat = SRUN; - p->p_flag |= SLOAD | SSYS; - p->p_nice = NZERO; + /* + * Set up system process 0 (swapper). + */ + p = &proc[0]; + p->p_addr = (size_t) &u; + p->p_stat = SRUN; + p->p_flag |= SLOAD | SSYS; + p->p_nice = NZERO; - u.u_procp = p; /* init user structure */ - u.u_cmask = CMASK; - u.u_lastfile = -1; - for (i = 1; i < NGROUPS; i++) - u.u_groups[i] = NOGROUP; - for (i = 0; i < sizeof(u.u_rlimit)/sizeof(u.u_rlimit[0]); i++) - u.u_rlimit[i].rlim_cur = u.u_rlimit[i].rlim_max = - RLIM_INFINITY; + u.u_procp = p; /* init user structure */ + u.u_cmask = CMASK; + u.u_lastfile = -1; + for (i = 1; i < NGROUPS; i++) + u.u_groups[i] = NOGROUP; + for (i = 0; i < sizeof(u.u_rlimit)/sizeof(u.u_rlimit[0]); i++) + u.u_rlimit[i].rlim_cur = u.u_rlimit[i].rlim_max = + RLIM_INFINITY; - /* Initialize signal state for process 0 */ - siginit (p); + /* Initialize signal state for process 0 */ + siginit (p); - /* - * Initialize tables, protocols, and set up well-known inodes. - */ + /* + * Initialize tables, protocols, and set up well-known inodes. + */ #ifdef LOG_ENABLED - loginit(); + loginit(); #endif - coutinit(); - cinit(); - pqinit(); - ihinit(); - bhinit(); - binit(); - nchinit(); - clkstart(); - s = spl0(); - rdisk_init(); + coutinit(); + cinit(); + pqinit(); + ihinit(); + bhinit(); + binit(); + nchinit(); + clkstart(); + s = spl0(); + rdisk_init(); - pipedev = rootdev = get_boot_device(); - swapdev = get_swap_device(); + pipedev = rootdev = get_boot_device(); + swapdev = get_swap_device(); - /* Mount a root filesystem. */ - for (;;) { - if(rootdev!=-1) - { - fs = mountfs (rootdev, (boothowto & RB_RDONLY) ? MNT_RDONLY : 0, - (struct inode*) 0); - } - if (fs) - break; - printf ("No root filesystem available!\n"); -// rdisk_list_partitions(RDISK_FS); + /* Mount a root filesystem. */ + for (;;) { + if(rootdev!=-1) + { + fs = mountfs (rootdev, (boothowto & RB_RDONLY) ? MNT_RDONLY : 0, + (struct inode*) 0); + } + if (fs) + break; + printf ("No root filesystem available!\n"); +// rdisk_list_partitions(RDISK_FS); retry: - printf ("Please enter device to boot from (press ? to list): "); - inch=0; - inbuf[0] = inbuf[1] = inbuf[2] = inbuf[3] = 0; - while((inch=cngetc()) != '\r') - { - switch(inch) - { - case '?': - printf("?\n"); - rdisk_list_partitions(RDISK_FS); - printf ("Please enter device to boot from (press ? to list): "); - break; - default: - printf("%c",inch); - inbuf[0] = inbuf[1]; - inbuf[1] = inbuf[2]; - inbuf[2] = inbuf[3]; - inbuf[3] = inch; - break; - } - } - - inch = 0; - if(inbuf[0]=='r' && inbuf[1]=='d') - { - if(inbuf[2]>='0' && inbuf[2] < '0'+rdisk_num_disks()) - { - if(inbuf[3]>='a' && inbuf[3]<='d') - { - rootdev=makedev(inbuf[2]-'0',inbuf[3]-'a'+1); - inch = 1; - } - } - } else if(inbuf[1]=='r' && inbuf[2]=='d') { - if(inbuf[3]>='0' && inbuf[3] < '0'+rdisk_num_disks()) - { - rootdev=makedev(inbuf[3]-'0',0); - inch = 1; - } - } else if(inbuf[3] == 0) { - inch = 1; - } - if(inch==0) - { - printf("\nUnknown device.\n\n"); - goto retry; - } - printf ("\n\n"); + printf ("Please enter device to boot from (press ? to list): "); + inch=0; + inbuf[0] = inbuf[1] = inbuf[2] = inbuf[3] = 0; + while((inch=cngetc()) != '\r') + { + switch(inch) + { + case '?': + printf("?\n"); + rdisk_list_partitions(RDISK_FS); + printf ("Please enter device to boot from (press ? to list): "); + break; + default: + printf("%c",inch); + inbuf[0] = inbuf[1]; + inbuf[1] = inbuf[2]; + inbuf[2] = inbuf[3]; + inbuf[3] = inch; + break; + } } - printf ("phys mem = %u kbytes\n", physmem / 1024); - printf ("user mem = %u kbytes\n", MAXMEM / 1024); - if(minor(rootdev)==0) - { - printf ("root dev = rd%d (%d,%d)\n", - major(rootdev), - major(rootdev), minor(rootdev) - ); - } else { - printf ("root dev = rd%d%c (%d,%d)\n", - major(rootdev), 'a'+minor(rootdev)-1, - major(rootdev), minor(rootdev) - ); - } - printf ("root size = %u kbytes\n", fs->fs_fsize * DEV_BSIZE / 1024); - mount[0].m_inodp = (struct inode*) 1; /* XXX */ - mount_updname (fs, "/", "root", 1, 4); - time.tv_sec = fs->fs_time; - boottime = time; - - /* Find a swap file. */ - swapstart = 1; - while(swapdev == -1) - { - printf("Please enter swap device (press ? to list): "); - inbuf[0] = inbuf[1] = inbuf[2] = inbuf[3] = 0; - while((inch = cngetc())!='\r') - { - switch(inch) - { - case '?': - printf("?\n"); - rdisk_list_partitions(RDISK_SWAP); - printf("Please enter swap device (press ? to list): "); - break; - default: - printf("%c",inch); - inbuf[0] = inbuf[1]; - inbuf[1] = inbuf[2]; - inbuf[2] = inbuf[3]; - inbuf[3] = inch; - break; - } - } - inch = 0; - if(inbuf[0]=='r' && inbuf[1]=='d') - { - if(inbuf[2]>='0' && inbuf[2] < '0'+rdisk_num_disks()) - { - if(inbuf[3]>='a' && inbuf[3]<='d') - { - swapdev=makedev(inbuf[2]-'0',inbuf[3]-'a'+1); - inch = 1; - } - } - } else if(inbuf[1]=='r' && inbuf[2]=='d') { - if(inbuf[3]>='0' && inbuf[3] < '0'+rdisk_num_disks()) - { - swapdev=makedev(inbuf[3]-'0',0); - inch = 1; - } - } - - if(minor(swapdev)!=0) - { - if(partition_type(swapdev)!=RDISK_SWAP) - { - printf("\nNot a swap partition!\n\n"); - swapdev=-1; - } - } - } - nswap = rdsize(swapdev); - - if(minor(swapdev)==0) - { - printf ("swap dev = rd%d (%d,%d)\n", - major(swapdev), - major(swapdev), minor(swapdev) - ); - } else { - printf ("swap dev = rd%d%c (%d,%d)\n", - major(swapdev), 'a'+minor(swapdev)-1, - major(swapdev), minor(swapdev) - ); - } - (*bdevsw[major(swapdev)].d_open)(swapdev, FREAD|FWRITE, S_IFBLK); - printf ("swap size = %u kbytes\n", nswap * DEV_BSIZE / 1024); - if (nswap <= 0) - panic ("zero swap size"); /* don't want to panic, but what ? */ - mfree (swapmap, nswap, swapstart); - - /* Kick off timeout driven events by calling first time. */ - schedcpu (0); - - /* Set up the root file system. */ - rootdir = iget (rootdev, &mount[0].m_filsys, (ino_t) ROOTINO); - iunlock (rootdir); - u.u_cdir = iget (rootdev, &mount[0].m_filsys, (ino_t) ROOTINO); - iunlock (u.u_cdir); - u.u_rdir = NULL; - - /* - * Make init process. - */ - if (newproc (0) == 0) { - /* Parent process with pid 0: swapper. - * No return from sched. */ - sched(); + inch = 0; + if(inbuf[0]=='r' && inbuf[1]=='d') + { + if(inbuf[2]>='0' && inbuf[2] < '0'+rdisk_num_disks()) + { + if(inbuf[3]>='a' && inbuf[3]<='d') + { + rootdev=makedev(inbuf[2]-'0',inbuf[3]-'a'+1); + inch = 1; + } + } + } else if(inbuf[1]=='r' && inbuf[2]=='d') { + if(inbuf[3]>='0' && inbuf[3] < '0'+rdisk_num_disks()) + { + rootdev=makedev(inbuf[3]-'0',0); + inch = 1; + } + } else if(inbuf[3] == 0) { + inch = 1; } - /* Child process with pid 1: init. */ - s = splhigh(); - p = u.u_procp; - p->p_dsize = icodeend - icode; - p->p_daddr = USER_DATA_START; - p->p_ssize = 1024; /* one kbyte of stack */ - p->p_saddr = USER_DATA_END - 1024; - bcopy ((caddr_t) icode, (caddr_t) USER_DATA_START, icodeend - icode); - /* - * return goes to location 0 of user init code - * just copied out. - */ - return 0; + if(inch==0) + { + printf("\nUnknown device.\n\n"); + goto retry; + } + printf ("\n\n"); + } + printf ("phys mem = %u kbytes\n", physmem / 1024); + printf ("user mem = %u kbytes\n", MAXMEM / 1024); + if(minor(rootdev)==0) + { + printf ("root dev = rd%d (%d,%d)\n", + major(rootdev), + major(rootdev), minor(rootdev) + ); + } else { + printf ("root dev = rd%d%c (%d,%d)\n", + major(rootdev), 'a'+minor(rootdev)-1, + major(rootdev), minor(rootdev) + ); + } + + printf ("root size = %u kbytes\n", fs->fs_fsize * DEV_BSIZE / 1024); + mount[0].m_inodp = (struct inode*) 1; /* XXX */ + mount_updname (fs, "/", "root", 1, 4); + time.tv_sec = fs->fs_time; + boottime = time; + + /* Find a swap file. */ + swapstart = 1; + while(swapdev == -1) + { + printf("Please enter swap device (press ? to list): "); + inbuf[0] = inbuf[1] = inbuf[2] = inbuf[3] = 0; + while((inch = cngetc())!='\r') + { + switch(inch) + { + case '?': + printf("?\n"); + rdisk_list_partitions(RDISK_SWAP); + printf("Please enter swap device (press ? to list): "); + break; + default: + printf("%c",inch); + inbuf[0] = inbuf[1]; + inbuf[1] = inbuf[2]; + inbuf[2] = inbuf[3]; + inbuf[3] = inch; + break; + } + } + inch = 0; + if(inbuf[0]=='r' && inbuf[1]=='d') + { + if(inbuf[2]>='0' && inbuf[2] < '0'+rdisk_num_disks()) + { + if(inbuf[3]>='a' && inbuf[3]<='d') + { + swapdev=makedev(inbuf[2]-'0',inbuf[3]-'a'+1); + inch = 1; + } + } + } else if(inbuf[1]=='r' && inbuf[2]=='d') { + if(inbuf[3]>='0' && inbuf[3] < '0'+rdisk_num_disks()) + { + swapdev=makedev(inbuf[3]-'0',0); + inch = 1; + } + } + + if(minor(swapdev)!=0) + { + if(partition_type(swapdev)!=RDISK_SWAP) + { + printf("\nNot a swap partition!\n\n"); + swapdev=-1; + } + } + } + nswap = rdsize(swapdev); + + if(minor(swapdev)==0) + { + printf ("swap dev = rd%d (%d,%d)\n", + major(swapdev), + major(swapdev), minor(swapdev) + ); + } else { + printf ("swap dev = rd%d%c (%d,%d)\n", + major(swapdev), 'a'+minor(swapdev)-1, + major(swapdev), minor(swapdev) + ); + } + (*bdevsw[major(swapdev)].d_open)(swapdev, FREAD|FWRITE, S_IFBLK); + printf ("swap size = %u kbytes\n", nswap * DEV_BSIZE / 1024); + if (nswap <= 0) + panic ("zero swap size"); /* don't want to panic, but what ? */ + mfree (swapmap, nswap, swapstart); + + /* Kick off timeout driven events by calling first time. */ + schedcpu (0); + + /* Set up the root file system. */ + rootdir = iget (rootdev, &mount[0].m_filsys, (ino_t) ROOTINO); + iunlock (rootdir); + u.u_cdir = iget (rootdev, &mount[0].m_filsys, (ino_t) ROOTINO); + iunlock (u.u_cdir); + u.u_rdir = NULL; + + /* + * Make init process. + */ + if (newproc (0) == 0) { + /* Parent process with pid 0: swapper. + * No return from sched. */ + sched(); + } + /* Child process with pid 1: init. */ + s = splhigh(); + p = u.u_procp; + p->p_dsize = icodeend - icode; + p->p_daddr = USER_DATA_START; + p->p_ssize = 1024; /* one kbyte of stack */ + p->p_saddr = USER_DATA_END - 1024; + bcopy ((caddr_t) icode, (caddr_t) USER_DATA_START, icodeend - icode); + /* + * return goes to location 0 of user init code + * just copied out. + */ + return 0; } diff --git a/sys/kernel/init_sysent.c b/sys/kernel/init_sysent.c index 9570403..ce46da4 100644 --- a/sys/kernel/init_sysent.c +++ b/sys/kernel/init_sysent.c @@ -10,11 +10,11 @@ #include "glob.h" #ifdef INET -# define ifnet(narg, name) narg, name -# define errnet(narg, name) narg, name +# define ifnet(narg, name) narg, name +# define errnet(narg, name) narg, name #else -# define ifnet(narg, name) 0, nosys -# define errnet(narg, name) 0, nonet +# define ifnet(narg, name) 0, nosys +# define errnet(narg, name) 0, nonet #endif extern void sc_msec(); @@ -36,176 +36,176 @@ extern void sc_msec(); * are encoded in the lower byte of the trap instruction -- see trap.c. */ const struct sysent sysent[] = { - { 1, nosys }, /* 0 = out-of-range */ - { 1, rexit }, /* 1 = exit */ - { 0, fork }, /* 2 = fork */ - { 3, read }, /* 3 = read */ - { 3, write }, /* 4 = write */ - { 3, open }, /* 5 = open */ - { 1, close }, /* 6 = close */ - { 4, wait4 }, /* 7 = wait4 */ - { 0, nosys }, /* 8 = (old creat) */ - { 2, link }, /* 9 = link */ - { 1, unlink }, /* 10 = unlink */ - { 2, execv }, /* 11 = execv */ - { 1, chdir }, /* 12 = chdir */ - { 1, fchdir }, /* 13 = fchdir */ - { 3, mknod }, /* 14 = mknod */ - { 2, chmod }, /* 15 = chmod */ - { 3, chown }, /* 16 = chown; now 3 args */ - { 2, chflags }, /* 17 = chflags */ - { 2, fchflags }, /* 18 = fchflags */ - { 4, lseek }, /* 19 = lseek */ - { 0, getpid }, /* 20 = getpid */ - { 3, smount }, /* 21 = mount */ - { 1, umount }, /* 22 = umount */ - { 6, __sysctl }, /* 23 = __sysctl */ - { 0, getuid }, /* 24 = getuid */ - { 0, geteuid }, /* 25 = geteuid */ - { 4, ptrace }, /* 26 = ptrace */ - { 0, getppid }, /* 27 = getppid */ - { 2, statfs }, /* 28 = statfs */ - { 2, fstatfs }, /* 29 = fstatfs */ - { 3, getfsstat }, /* 30 = getfsstat */ - { 4, sigaction }, /* 31 = sigaction */ - { 3, sigprocmask }, /* 32 = sigprocmask */ - { 2, saccess }, /* 33 = access */ - { 1, sigpending }, /* 34 = sigpending */ - { 2, sigaltstack }, /* 35 = sigaltstack */ - { 0, sync }, /* 36 = sync */ - { 2, kill }, /* 37 = kill */ - { 2, stat }, /* 38 = stat */ - { 2, nosys }, /* 39 = getlogin */ - { 2, lstat }, /* 40 = lstat */ - { 1, dup }, /* 41 = dup */ - { 0, pipe }, /* 42 = pipe */ - { 1, nosys }, /* 43 = setlogin */ - { 4, profil }, /* 44 = profil */ - { 1, setuid }, /* 45 = setuid */ - { 1, seteuid }, /* 46 = seteuid */ - { 0, getgid }, /* 47 = getgid */ - { 0, getegid }, /* 48 = getegid */ - { 1, setgid }, /* 49 = setgid */ - { 1, setegid }, /* 50 = setegid */ - { 0, kmemdev }, /* 51 = kmemdev */ - { 3, nosys }, /* 52 = (2.9) set phys addr */ - { 1, nosys }, /* 53 = (2.9) lock in core */ - { 4, ioctl }, /* 54 = ioctl */ - { 1, reboot }, /* 55 = reboot */ - { 2, sigwait }, /* 56 = sigwait */ - { 2, symlink }, /* 57 = symlink */ - { 3, readlink }, /* 58 = readlink */ - { 3, execve }, /* 59 = execve */ - { 1, umask }, /* 60 = umask */ - { 1, chroot }, /* 61 = chroot */ - { 2, fstat }, /* 62 = fstat */ - { 0, nosys }, /* 63 = reserved */ - { 0, nosys }, /* 64 = (old getpagesize) */ - { 6, pselect }, /* 65 = pselect */ - { 0, vfork }, /* 66 = vfork */ - { 0, nosys }, /* 67 = unused */ - { 0, nosys }, /* 68 = unused */ - { 1, brk }, /* 69 = brk */ + { 1, nosys }, /* 0 = out-of-range */ + { 1, rexit }, /* 1 = exit */ + { 0, fork }, /* 2 = fork */ + { 3, read }, /* 3 = read */ + { 3, write }, /* 4 = write */ + { 3, open }, /* 5 = open */ + { 1, close }, /* 6 = close */ + { 4, wait4 }, /* 7 = wait4 */ + { 0, nosys }, /* 8 = (old creat) */ + { 2, link }, /* 9 = link */ + { 1, unlink }, /* 10 = unlink */ + { 2, execv }, /* 11 = execv */ + { 1, chdir }, /* 12 = chdir */ + { 1, fchdir }, /* 13 = fchdir */ + { 3, mknod }, /* 14 = mknod */ + { 2, chmod }, /* 15 = chmod */ + { 3, chown }, /* 16 = chown; now 3 args */ + { 2, chflags }, /* 17 = chflags */ + { 2, fchflags }, /* 18 = fchflags */ + { 4, lseek }, /* 19 = lseek */ + { 0, getpid }, /* 20 = getpid */ + { 3, smount }, /* 21 = mount */ + { 1, umount }, /* 22 = umount */ + { 6, __sysctl }, /* 23 = __sysctl */ + { 0, getuid }, /* 24 = getuid */ + { 0, geteuid }, /* 25 = geteuid */ + { 4, ptrace }, /* 26 = ptrace */ + { 0, getppid }, /* 27 = getppid */ + { 2, statfs }, /* 28 = statfs */ + { 2, fstatfs }, /* 29 = fstatfs */ + { 3, getfsstat }, /* 30 = getfsstat */ + { 4, sigaction }, /* 31 = sigaction */ + { 3, sigprocmask }, /* 32 = sigprocmask */ + { 2, saccess }, /* 33 = access */ + { 1, sigpending }, /* 34 = sigpending */ + { 2, sigaltstack }, /* 35 = sigaltstack */ + { 0, sync }, /* 36 = sync */ + { 2, kill }, /* 37 = kill */ + { 2, stat }, /* 38 = stat */ + { 2, nosys }, /* 39 = getlogin */ + { 2, lstat }, /* 40 = lstat */ + { 1, dup }, /* 41 = dup */ + { 0, pipe }, /* 42 = pipe */ + { 1, nosys }, /* 43 = setlogin */ + { 4, profil }, /* 44 = profil */ + { 1, setuid }, /* 45 = setuid */ + { 1, seteuid }, /* 46 = seteuid */ + { 0, getgid }, /* 47 = getgid */ + { 0, getegid }, /* 48 = getegid */ + { 1, setgid }, /* 49 = setgid */ + { 1, setegid }, /* 50 = setegid */ + { 0, kmemdev }, /* 51 = kmemdev */ + { 3, nosys }, /* 52 = (2.9) set phys addr */ + { 1, nosys }, /* 53 = (2.9) lock in core */ + { 4, ioctl }, /* 54 = ioctl */ + { 1, reboot }, /* 55 = reboot */ + { 2, sigwait }, /* 56 = sigwait */ + { 2, symlink }, /* 57 = symlink */ + { 3, readlink }, /* 58 = readlink */ + { 3, execve }, /* 59 = execve */ + { 1, umask }, /* 60 = umask */ + { 1, chroot }, /* 61 = chroot */ + { 2, fstat }, /* 62 = fstat */ + { 0, nosys }, /* 63 = reserved */ + { 0, nosys }, /* 64 = (old getpagesize) */ + { 6, pselect }, /* 65 = pselect */ + { 0, vfork }, /* 66 = vfork */ + { 0, nosys }, /* 67 = unused */ + { 0, nosys }, /* 68 = unused */ + { 1, brk }, /* 69 = brk */ #ifdef GLOB_ENABLED - { 1, rdglob }, /* 70 = read from global */ - { 2, wrglob }, /* 71 = write to global */ + { 1, rdglob }, /* 70 = read from global */ + { 2, wrglob }, /* 71 = write to global */ #else { 1, nosys }, { 2, nosys }, #endif - { 0, sc_msec }, /* 72 = msec */ - { 0, nosys }, /* 73 = unused */ - { 0, nosys }, /* 74 = unused */ - { 0, nosys }, /* 75 = unused */ - { 0, vhangup }, /* 76 = vhangup */ - { 0, nosys }, /* 77 = unused */ - { 0, nosys }, /* 78 = unused */ - { 2, getgroups }, /* 79 = getgroups */ - { 2, setgroups }, /* 80 = setgroups */ - { 1, getpgrp }, /* 81 = getpgrp */ - { 2, setpgrp }, /* 82 = setpgrp */ - { 3, setitimer }, /* 83 = setitimer */ - { 0, nosys }, /* 84 = (old wait,wait3) */ - { 0, nosys }, /* 85 = unused */ - { 2, getitimer }, /* 86 = getitimer */ - { 0, nosys }, /* 87 = (old gethostname) */ - { 0, nosys }, /* 88 = (old sethostname) */ - { 0, getdtablesize }, /* 89 = getdtablesize */ - { 2, dup2 }, /* 90 = dup2 */ - { 0, nosys }, /* 91 = unused */ - { 3, fcntl }, /* 92 = fcntl */ - { 5, select }, /* 93 = select */ - { 0, nosys }, /* 94 = unused */ - { 1, fsync }, /* 95 = fsync */ - { 3, setpriority }, /* 96 = setpriority */ - { errnet(3, socket) }, /* 97 = socket */ - { ifnet(3, connect) }, /* 98 = connect */ - { ifnet(3, accept) }, /* 99 = accept */ - { 2, getpriority }, /* 100 = getpriority */ - { ifnet(4, send) }, /* 101 = send */ - { ifnet(4, recv) }, /* 102 = recv */ - { 1, sigreturn }, /* 103 = sigreturn */ - { ifnet(3, bind) }, /* 104 = bind */ - { ifnet(5, setsockopt) }, /* 105 = setsockopt */ - { ifnet(2, listen) }, /* 106 = listen */ - { 1, sigsuspend }, /* 107 = sigsuspend */ - { 0, nosys }, /* 108 = (old sigvec) */ - { 0, nosys }, /* 109 = (old sigblock) */ - { 0, nosys }, /* 110 = (old sigsetmask) */ - { 0, nosys }, /* 111 = (old sigpause) */ - { 2, sigstack }, /* 112 = sigstack COMPAT-43 */ - { ifnet(3, recvmsg) }, /* 113 = recvmsg */ - { ifnet(3, sendmsg) }, /* 114 = sendmsg */ - { 0, nosys }, /* 115 = unused */ - { 2, gettimeofday }, /* 116 = gettimeofday */ - { 2, getrusage }, /* 117 = getrusage */ - { ifnet(5, getsockopt) }, /* 118 = getsockopt */ - { 0, nosys }, /* 119 = unused */ - { 3, readv }, /* 120 = readv */ - { 3, writev }, /* 121 = writev */ - { 2, settimeofday }, /* 122 = settimeofday */ - { 3, fchown }, /* 123 = fchown */ - { 2, fchmod }, /* 124 = fchmod */ - { ifnet(6, recvfrom) }, /* 125 = recvfrom */ - { 0, nosys }, /* 126 = (old setreuid) */ - { 0, nosys }, /* 127 = (old setregid) */ - { 2, rename }, /* 128 = rename */ - { 3, truncate }, /* 129 = truncate */ - { 3, ftruncate }, /* 130 = ftruncate */ - { 2, flock }, /* 131 = flock */ - { 0, nosys }, /* 132 = nosys */ - { ifnet(6, sendto) }, /* 133 = sendto */ - { ifnet(2, shutdown) }, /* 134 = shutdown */ - { errnet(4, socketpair) }, /* 135 = socketpair */ - { 2, mkdir }, /* 136 = mkdir */ - { 1, rmdir }, /* 137 = rmdir */ - { 2, utimes }, /* 138 = utimes */ - { 0, nosys }, /* 139 = unused */ - { 2, adjtime }, /* 140 = adjtime */ - { ifnet(3, getpeername) }, /* 141 = getpeername */ - { 0, nosys }, /* 142 = (old gethostid) */ - { 0, nosys }, /* 143 = (old sethostid) */ - { 2, getrlimit }, /* 144 = getrlimit */ - { 2, setrlimit }, /* 145 = setrlimit */ - { 2, killpg }, /* 146 = killpg */ - { 0, nosys }, /* 147 = nosys */ - { 2, nosys }, /* 148 = quota */ - { 4, nosys }, /* 149 = qquota */ - { ifnet(3, getsockname) }, /* 150 = getsockname */ - /* - * Syscalls 151-180 inclusive are reserved for vendor-specific - * system calls. (This includes various calls added for compatibity - * with other Unix variants.) - */ + { 0, sc_msec }, /* 72 = msec */ + { 0, nosys }, /* 73 = unused */ + { 0, nosys }, /* 74 = unused */ + { 0, nosys }, /* 75 = unused */ + { 0, vhangup }, /* 76 = vhangup */ + { 0, nosys }, /* 77 = unused */ + { 0, nosys }, /* 78 = unused */ + { 2, getgroups }, /* 79 = getgroups */ + { 2, setgroups }, /* 80 = setgroups */ + { 1, getpgrp }, /* 81 = getpgrp */ + { 2, setpgrp }, /* 82 = setpgrp */ + { 3, setitimer }, /* 83 = setitimer */ + { 0, nosys }, /* 84 = (old wait,wait3) */ + { 0, nosys }, /* 85 = unused */ + { 2, getitimer }, /* 86 = getitimer */ + { 0, nosys }, /* 87 = (old gethostname) */ + { 0, nosys }, /* 88 = (old sethostname) */ + { 0, getdtablesize }, /* 89 = getdtablesize */ + { 2, dup2 }, /* 90 = dup2 */ + { 0, nosys }, /* 91 = unused */ + { 3, fcntl }, /* 92 = fcntl */ + { 5, select }, /* 93 = select */ + { 0, nosys }, /* 94 = unused */ + { 1, fsync }, /* 95 = fsync */ + { 3, setpriority }, /* 96 = setpriority */ + { errnet(3, socket) }, /* 97 = socket */ + { ifnet(3, connect) }, /* 98 = connect */ + { ifnet(3, accept) }, /* 99 = accept */ + { 2, getpriority }, /* 100 = getpriority */ + { ifnet(4, send) }, /* 101 = send */ + { ifnet(4, recv) }, /* 102 = recv */ + { 1, sigreturn }, /* 103 = sigreturn */ + { ifnet(3, bind) }, /* 104 = bind */ + { ifnet(5, setsockopt) }, /* 105 = setsockopt */ + { ifnet(2, listen) }, /* 106 = listen */ + { 1, sigsuspend }, /* 107 = sigsuspend */ + { 0, nosys }, /* 108 = (old sigvec) */ + { 0, nosys }, /* 109 = (old sigblock) */ + { 0, nosys }, /* 110 = (old sigsetmask) */ + { 0, nosys }, /* 111 = (old sigpause) */ + { 2, sigstack }, /* 112 = sigstack COMPAT-43 */ + { ifnet(3, recvmsg) }, /* 113 = recvmsg */ + { ifnet(3, sendmsg) }, /* 114 = sendmsg */ + { 0, nosys }, /* 115 = unused */ + { 2, gettimeofday }, /* 116 = gettimeofday */ + { 2, getrusage }, /* 117 = getrusage */ + { ifnet(5, getsockopt) }, /* 118 = getsockopt */ + { 0, nosys }, /* 119 = unused */ + { 3, readv }, /* 120 = readv */ + { 3, writev }, /* 121 = writev */ + { 2, settimeofday }, /* 122 = settimeofday */ + { 3, fchown }, /* 123 = fchown */ + { 2, fchmod }, /* 124 = fchmod */ + { ifnet(6, recvfrom) }, /* 125 = recvfrom */ + { 0, nosys }, /* 126 = (old setreuid) */ + { 0, nosys }, /* 127 = (old setregid) */ + { 2, rename }, /* 128 = rename */ + { 3, truncate }, /* 129 = truncate */ + { 3, ftruncate }, /* 130 = ftruncate */ + { 2, flock }, /* 131 = flock */ + { 0, nosys }, /* 132 = nosys */ + { ifnet(6, sendto) }, /* 133 = sendto */ + { ifnet(2, shutdown) }, /* 134 = shutdown */ + { errnet(4, socketpair) }, /* 135 = socketpair */ + { 2, mkdir }, /* 136 = mkdir */ + { 1, rmdir }, /* 137 = rmdir */ + { 2, utimes }, /* 138 = utimes */ + { 0, nosys }, /* 139 = unused */ + { 2, adjtime }, /* 140 = adjtime */ + { ifnet(3, getpeername) }, /* 141 = getpeername */ + { 0, nosys }, /* 142 = (old gethostid) */ + { 0, nosys }, /* 143 = (old sethostid) */ + { 2, getrlimit }, /* 144 = getrlimit */ + { 2, setrlimit }, /* 145 = setrlimit */ + { 2, killpg }, /* 146 = killpg */ + { 0, nosys }, /* 147 = nosys */ + { 2, nosys }, /* 148 = quota */ + { 4, nosys }, /* 149 = qquota */ + { ifnet(3, getsockname) }, /* 150 = getsockname */ + /* + * Syscalls 151-180 inclusive are reserved for vendor-specific + * system calls. (This includes various calls added for compatibity + * with other Unix variants.) + */ - /* - * 2BSD special calls - */ - { 0, nosys }, /* 151 = unused */ - { 2, ustore }, /* 152 = ustore */ - { 1, ufetch }, /* 153 = ufetch */ - { 4, ucall }, /* 154 = ucall */ - { 0, nosys }, /* 155 = fperr */ + /* + * 2BSD special calls + */ + { 0, nosys }, /* 151 = unused */ + { 2, ustore }, /* 152 = ustore */ + { 1, ufetch }, /* 153 = ufetch */ + { 4, ucall }, /* 154 = ucall */ + { 0, nosys }, /* 155 = fperr */ }; const int nsysent = sizeof (sysent) / sizeof (sysent[0]); diff --git a/sys/kernel/kern_clock.c b/sys/kernel/kern_clock.c index 87f0de4..1c93cb8 100644 --- a/sys/kernel/kern_clock.c +++ b/sys/kernel/kern_clock.c @@ -11,12 +11,12 @@ #include "kernel.h" #include "systm.h" -int noproc; /* no one is running just now */ +int noproc; /* no one is running just now */ -struct callout *callfree, calltodo; +struct callout *callfree, calltodo; #ifdef UCB_METER -int dk_ndrive = DK_NDRIVE; +int dk_ndrive = DK_NDRIVE; /* * Gather statistics on resource utilization. @@ -29,44 +29,44 @@ int dk_ndrive = DK_NDRIVE; /*ARGSUSED*/ void gatherstats(pc, ps) - caddr_t pc; - int ps; + caddr_t pc; + int ps; { - register int cpstate; + register int cpstate; - /* - * Determine what state the cpu is in. - */ - if (USERMODE(ps)) { - /* - * CPU was in user state. - */ - if (u.u_procp->p_nice > NZERO) - cpstate = CP_NICE; - else - cpstate = CP_USER; - } else { - /* - * CPU was in system state. If profiling kernel - * increment a counter. If no process is running - * then this is a system tick if we were running - * at a non-zero IPL (in a driver). If a process is running, - * then we charge it with system time even if we were - * at a non-zero IPL, since the system often runs - * this way during processing of system calls. - * This is approximate, but the lack of true interval - * timers makes doing anything else difficult. - */ - cpstate = CP_SYS; - if (noproc && BASEPRI(ps)) - cpstate = CP_IDLE; - } - /* - * We maintain statistics shown by user-level statistics - * programs: the amount of time in each cpu state, and - * the amount of time each of DK_NDRIVE ``drives'' is busy. - */ - cp_time[cpstate]++; + /* + * Determine what state the cpu is in. + */ + if (USERMODE(ps)) { + /* + * CPU was in user state. + */ + if (u.u_procp->p_nice > NZERO) + cpstate = CP_NICE; + else + cpstate = CP_USER; + } else { + /* + * CPU was in system state. If profiling kernel + * increment a counter. If no process is running + * then this is a system tick if we were running + * at a non-zero IPL (in a driver). If a process is running, + * then we charge it with system time even if we were + * at a non-zero IPL, since the system often runs + * this way during processing of system calls. + * This is approximate, but the lack of true interval + * timers makes doing anything else difficult. + */ + cpstate = CP_SYS; + if (noproc && BASEPRI(ps)) + cpstate = CP_IDLE; + } + /* + * We maintain statistics shown by user-level statistics + * programs: the amount of time in each cpu state, and + * the amount of time each of DK_NDRIVE ``drives'' is busy. + */ + cp_time[cpstate]++; } #endif /* UCB_METER */ @@ -76,49 +76,49 @@ gatherstats(pc, ps) */ void softclock(pc, ps) - caddr_t pc; - int ps; + caddr_t pc; + int ps; { - for (;;) { - register struct callout *p1; - register caddr_t arg; - register void (*func) (caddr_t); - register int s; + for (;;) { + register struct callout *p1; + register caddr_t arg; + register void (*func) (caddr_t); + register int s; - s = splhigh(); - if ((p1 = calltodo.c_next) == 0 || p1->c_time > 0) { - splx(s); - break; - } - arg = p1->c_arg; - func = p1->c_func; - calltodo.c_next = p1->c_next; - p1->c_next = callfree; - callfree = p1; - splx(s); - (*func) (arg); - } - /* - * If trapped user-mode and profiling, give it - * a profiling tick. - */ - if (USERMODE(ps)) { - register struct proc *p = u.u_procp; + s = splhigh(); + if ((p1 = calltodo.c_next) == 0 || p1->c_time > 0) { + splx(s); + break; + } + arg = p1->c_arg; + func = p1->c_func; + calltodo.c_next = p1->c_next; + p1->c_next = callfree; + callfree = p1; + splx(s); + (*func) (arg); + } + /* + * If trapped user-mode and profiling, give it + * a profiling tick. + */ + if (USERMODE(ps)) { + register struct proc *p = u.u_procp; - if (u.u_prof.pr_scale) - addupc(pc, &u.u_prof, 1); - /* - * Check to see if process has accumulated - * more than 10 minutes of user time. If so - * reduce priority to give others a chance. - */ + if (u.u_prof.pr_scale) + addupc(pc, &u.u_prof, 1); + /* + * Check to see if process has accumulated + * more than 10 minutes of user time. If so + * reduce priority to give others a chance. + */ - if (p->p_uid && p->p_nice == NZERO && - u.u_ru.ru_utime > 10L * 60L * hz) { - p->p_nice = NZERO+4; - (void) setpri(p); - } - } + if (p->p_uid && p->p_nice == NZERO && + u.u_ru.ru_utime > 10L * 60L * hz) { + p->p_nice = NZERO+4; + (void) setpri(p); + } + } } /* @@ -126,124 +126,124 @@ softclock(pc, ps) * We update the events relating to real time. * Also gather statistics. * - * reprime clock - * implement callouts - * maintain user/system times - * maintain date - * profile + * reprime clock + * implement callouts + * maintain user/system times + * maintain date + * profile */ void hardclock(pc, ps) - caddr_t pc; - int ps; + caddr_t pc; + int ps; { - register struct callout *p1; - register struct proc *p; - register int needsoft = 0; + register struct callout *p1; + register struct proc *p; + register int needsoft = 0; - /* - * Update real-time timeout queue. - * At front of queue are some number of events which are ``due''. - * The time to these is <= 0 and if negative represents the - * number of ticks which have passed since it was supposed to happen. - * The rest of the q elements (times > 0) are events yet to happen, - * where the time for each is given as a delta from the previous. - * Decrementing just the first of these serves to decrement the time - * to all events. - */ - p1 = calltodo.c_next; - while (p1) { - if (--p1->c_time > 0) - break; - needsoft = 1; - if (p1->c_time == 0) - break; - p1 = p1->c_next; - } + /* + * Update real-time timeout queue. + * At front of queue are some number of events which are ``due''. + * The time to these is <= 0 and if negative represents the + * number of ticks which have passed since it was supposed to happen. + * The rest of the q elements (times > 0) are events yet to happen, + * where the time for each is given as a delta from the previous. + * Decrementing just the first of these serves to decrement the time + * to all events. + */ + p1 = calltodo.c_next; + while (p1) { + if (--p1->c_time > 0) + break; + needsoft = 1; + if (p1->c_time == 0) + break; + p1 = p1->c_next; + } - /* - * Charge the time out based on the mode the cpu is in. - * Here again we fudge for the lack of proper interval timers - * assuming that the current state has been around at least - * one tick. - */ - if (USERMODE(ps)) { - if (u.u_prof.pr_scale) - needsoft = 1; - /* - * CPU was in user state. Increment - * user time counter, and process process-virtual time - * interval timer. - */ - u.u_ru.ru_utime++; - if (u.u_timer[ITIMER_VIRTUAL - 1].it_value && - !--u.u_timer[ITIMER_VIRTUAL - 1].it_value) { - psignal(u.u_procp, SIGVTALRM); - u.u_timer[ITIMER_VIRTUAL - 1].it_value = - u.u_timer[ITIMER_VIRTUAL - 1].it_interval; - } - } else { - /* - * CPU was in system state. - */ - if (!noproc) - u.u_ru.ru_stime++; - } + /* + * Charge the time out based on the mode the cpu is in. + * Here again we fudge for the lack of proper interval timers + * assuming that the current state has been around at least + * one tick. + */ + if (USERMODE(ps)) { + if (u.u_prof.pr_scale) + needsoft = 1; + /* + * CPU was in user state. Increment + * user time counter, and process process-virtual time + * interval timer. + */ + u.u_ru.ru_utime++; + if (u.u_timer[ITIMER_VIRTUAL - 1].it_value && + !--u.u_timer[ITIMER_VIRTUAL - 1].it_value) { + psignal(u.u_procp, SIGVTALRM); + u.u_timer[ITIMER_VIRTUAL - 1].it_value = + u.u_timer[ITIMER_VIRTUAL - 1].it_interval; + } + } else { + /* + * CPU was in system state. + */ + if (!noproc) + u.u_ru.ru_stime++; + } - /* - * If the cpu is currently scheduled to a process, then - * charge it with resource utilization for a tick, updating - * statistics which run in (user+system) virtual time, - * such as the cpu time limit and profiling timers. - * This assumes that the current process has been running - * the entire last tick. - */ - if (noproc == 0) { - p = u.u_procp; - if (++p->p_cpu == 0) - p->p_cpu--; - if ((u.u_ru.ru_utime+u.u_ru.ru_stime+1) > - u.u_rlimit[RLIMIT_CPU].rlim_cur) { - psignal(p, SIGXCPU); - if (u.u_rlimit[RLIMIT_CPU].rlim_cur < - u.u_rlimit[RLIMIT_CPU].rlim_max) - u.u_rlimit[RLIMIT_CPU].rlim_cur += 5 * hz; - } - if (u.u_timer[ITIMER_PROF - 1].it_value && - !--u.u_timer[ITIMER_PROF - 1].it_value) { - psignal(p, SIGPROF); - u.u_timer[ITIMER_PROF - 1].it_value = - u.u_timer[ITIMER_PROF - 1].it_interval; - } - } + /* + * If the cpu is currently scheduled to a process, then + * charge it with resource utilization for a tick, updating + * statistics which run in (user+system) virtual time, + * such as the cpu time limit and profiling timers. + * This assumes that the current process has been running + * the entire last tick. + */ + if (noproc == 0) { + p = u.u_procp; + if (++p->p_cpu == 0) + p->p_cpu--; + if ((u.u_ru.ru_utime+u.u_ru.ru_stime+1) > + u.u_rlimit[RLIMIT_CPU].rlim_cur) { + psignal(p, SIGXCPU); + if (u.u_rlimit[RLIMIT_CPU].rlim_cur < + u.u_rlimit[RLIMIT_CPU].rlim_max) + u.u_rlimit[RLIMIT_CPU].rlim_cur += 5 * hz; + } + if (u.u_timer[ITIMER_PROF - 1].it_value && + !--u.u_timer[ITIMER_PROF - 1].it_value) { + psignal(p, SIGPROF); + u.u_timer[ITIMER_PROF - 1].it_value = + u.u_timer[ITIMER_PROF - 1].it_interval; + } + } #ifdef UCB_METER - gatherstats (pc, ps); + gatherstats (pc, ps); #endif - /* - * Increment the time-of-day, process callouts at a very - * low cpu priority, so we don't keep the relatively high - * clock interrupt priority any longer than necessary. - */ - if (adjdelta) { - if (adjdelta > 0) { - ++lbolt; - --adjdelta; - } else { - --lbolt; - ++adjdelta; - } - } - if (++lbolt >= hz) { - lbolt -= hz; - ++time.tv_sec; - } + /* + * Increment the time-of-day, process callouts at a very + * low cpu priority, so we don't keep the relatively high + * clock interrupt priority any longer than necessary. + */ + if (adjdelta) { + if (adjdelta > 0) { + ++lbolt; + --adjdelta; + } else { + --lbolt; + ++adjdelta; + } + } + if (++lbolt >= hz) { + lbolt -= hz; + ++time.tv_sec; + } - if (needsoft && BASEPRI(ps)) { /* if ps is high, just return */ -// (void) splsoftclock(); - softclock (pc, ps); - } + if (needsoft && BASEPRI(ps)) { /* if ps is high, just return */ +// (void) splsoftclock(); + softclock (pc, ps); + } } /* @@ -251,30 +251,30 @@ hardclock(pc, ps) */ void timeout (fun, arg, t) - void (*fun) (caddr_t); - caddr_t arg; - register int t; + void (*fun) (caddr_t); + caddr_t arg; + register int t; { - register struct callout *p1, *p2, *pnew; - register int s = splclock(); + register struct callout *p1, *p2, *pnew; + register int s = splclock(); - if (t <= 0) - t = 1; - pnew = callfree; - if (pnew == NULL) - panic("timeout table overflow"); - callfree = pnew->c_next; - pnew->c_arg = arg; - pnew->c_func = fun; - for (p1 = &calltodo; (p2 = p1->c_next) && p2->c_time < t; p1 = p2) - if (p2->c_time > 0) - t -= p2->c_time; - p1->c_next = pnew; - pnew->c_next = p2; - pnew->c_time = t; - if (p2) - p2->c_time -= t; - splx(s); + if (t <= 0) + t = 1; + pnew = callfree; + if (pnew == NULL) + panic("timeout table overflow"); + callfree = pnew->c_next; + pnew->c_arg = arg; + pnew->c_func = fun; + for (p1 = &calltodo; (p2 = p1->c_next) && p2->c_time < t; p1 = p2) + if (p2->c_time > 0) + t -= p2->c_time; + p1->c_next = pnew; + pnew->c_next = p2; + pnew->c_time = t; + if (p2) + p2->c_time -= t; + splx(s); } /* @@ -283,41 +283,41 @@ timeout (fun, arg, t) */ void untimeout (fun, arg) - void (*fun) (caddr_t); - caddr_t arg; + void (*fun) (caddr_t); + caddr_t arg; { - register struct callout *p1, *p2; - register int s; + register struct callout *p1, *p2; + register int s; - s = splclock(); - for (p1 = &calltodo; (p2 = p1->c_next) != 0; p1 = p2) { - if (p2->c_func == fun && p2->c_arg == arg) { - if (p2->c_next && p2->c_time > 0) - p2->c_next->c_time += p2->c_time; - p1->c_next = p2->c_next; - p2->c_next = callfree; - callfree = p2; - break; - } - } - splx(s); + s = splclock(); + for (p1 = &calltodo; (p2 = p1->c_next) != 0; p1 = p2) { + if (p2->c_func == fun && p2->c_arg == arg) { + if (p2->c_next && p2->c_time > 0) + p2->c_next->c_time += p2->c_time; + p1->c_next = p2->c_next; + p2->c_next = callfree; + callfree = p2; + break; + } + } + splx(s); } void profil() { - register struct a { - unsigned *bufbase; - unsigned bufsize; - unsigned pcoffset; - unsigned pcscale; - } *uap = (struct a*) u.u_arg; - register struct uprof *upp = &u.u_prof; + register struct a { + unsigned *bufbase; + unsigned bufsize; + unsigned pcoffset; + unsigned pcscale; + } *uap = (struct a*) u.u_arg; + register struct uprof *upp = &u.u_prof; - upp->pr_base = uap->bufbase; - upp->pr_size = uap->bufsize; - upp->pr_off = uap->pcoffset; - upp->pr_scale = uap->pcscale; + upp->pr_base = uap->bufbase; + upp->pr_size = uap->bufsize; + upp->pr_off = uap->pcoffset; + upp->pr_scale = uap->pcscale; } /* @@ -327,36 +327,36 @@ profil() */ int hzto(tv) - register struct timeval *tv; + register struct timeval *tv; { - register long ticks; - register long sec; - register int s = splhigh(); + register long ticks; + register long sec; + register int s = splhigh(); - /* - * If number of milliseconds will fit in 32 bit arithmetic, - * then compute number of milliseconds to time and scale to - * ticks. Otherwise just compute number of hz in time, rounding - * times greater than representible to maximum value. - * - * Delta times less than 25 days can be computed ``exactly''. - * Maximum value for any timeout in 10ms ticks is 250 days. - */ - sec = tv->tv_sec - time.tv_sec; - if (sec <= 0x7fffffff / 1000 - 1000) - ticks = ((tv->tv_sec - time.tv_sec) * 1000 + - (tv->tv_usec - time.tv_usec) / 1000) / (1000/hz); - else if (sec <= 0x7fffffff / hz) - ticks = sec * hz; - else - ticks = 0x7fffffff; - splx(s); + /* + * If number of milliseconds will fit in 32 bit arithmetic, + * then compute number of milliseconds to time and scale to + * ticks. Otherwise just compute number of hz in time, rounding + * times greater than representible to maximum value. + * + * Delta times less than 25 days can be computed ``exactly''. + * Maximum value for any timeout in 10ms ticks is 250 days. + */ + sec = tv->tv_sec - time.tv_sec; + if (sec <= 0x7fffffff / 1000 - 1000) + ticks = ((tv->tv_sec - time.tv_sec) * 1000 + + (tv->tv_usec - time.tv_usec) / 1000) / (1000/hz); + else if (sec <= 0x7fffffff / hz) + ticks = sec * hz; + else + ticks = 0x7fffffff; + splx(s); #ifdef pdp11 - /* stored in an "int", so 16-bit max */ - if (ticks > 0x7fff) - ticks = 0x7fff; + /* stored in an "int", so 16-bit max */ + if (ticks > 0x7fff) + ticks = 0x7fff; #endif - return ((int)ticks); + return ((int)ticks); } /* @@ -365,9 +365,9 @@ hzto(tv) void coutinit() { - int i; + int i; - callfree = callout; - for (i=1; i u.u_lastfile) - u.u_lastfile = i; - return (i); - } - u.u_error = EMFILE; - return (-1); + for (; i < NOFILE; i++) + if (u.u_ofile[i] == NULL) { + u.u_rval = i; + u.u_pofile[i] = 0; + if (i > u.u_lastfile) + u.u_lastfile = i; + return (i); + } + u.u_error = EMFILE; + return (-1); } /* @@ -54,62 +54,62 @@ ufalloc(i) void getdtablesize() { - u.u_rval = NOFILE; + u.u_rval = NOFILE; } static void dupit(fd, fp, flags) - register int fd; - register struct file *fp; - int flags; + register int fd; + register struct file *fp; + int flags; { - u.u_ofile[fd] = fp; - u.u_pofile[fd] = flags; - fp->f_count++; - if (fd > u.u_lastfile) - u.u_lastfile = fd; + u.u_ofile[fd] = fp; + u.u_pofile[fd] = flags; + fp->f_count++; + if (fd > u.u_lastfile) + u.u_lastfile = fd; } void dup() { - register struct a { - int i; - } *uap = (struct a *) u.u_arg; - register struct file *fp; - register int j; + register struct a { + int i; + } *uap = (struct a *) u.u_arg; + register struct file *fp; + register int j; - if (uap->i &~ 077) { uap->i &= 077; dup2(); return; } /* XXX */ + if (uap->i &~ 077) { uap->i &= 077; dup2(); return; } /* XXX */ - GETF(fp, uap->i); - j = ufalloc(0); - if (j < 0) - return; - dupit(j, fp, u.u_pofile[uap->i] &~ UF_EXCLOSE); + GETF(fp, uap->i); + j = ufalloc(0); + if (j < 0) + return; + dupit(j, fp, u.u_pofile[uap->i] &~ UF_EXCLOSE); } void dup2() { - register struct a { - int i, j; - } *uap = (struct a *) u.u_arg; - register struct file *fp; + register struct a { + int i, j; + } *uap = (struct a *) u.u_arg; + register struct file *fp; - GETF(fp, uap->i); - if (uap->j < 0 || uap->j >= NOFILE) { - u.u_error = EBADF; - return; - } - u.u_rval = uap->j; - if (uap->i == uap->j) - return; - if (u.u_ofile[uap->j]) - /* - * dup2 must succeed even if the close has an error. - */ - (void) closef(u.u_ofile[uap->j]); - dupit(uap->j, fp, u.u_pofile[uap->i] &~ UF_EXCLOSE); + GETF(fp, uap->i); + if (uap->j < 0 || uap->j >= NOFILE) { + u.u_error = EBADF; + return; + } + u.u_rval = uap->j; + if (uap->i == uap->j) + return; + if (u.u_ofile[uap->j]) + /* + * dup2 must succeed even if the close has an error. + */ + (void) closef(u.u_ofile[uap->j]); + dupit(uap->j, fp, u.u_pofile[uap->i] &~ UF_EXCLOSE); } /* @@ -118,75 +118,75 @@ dup2() void fcntl() { - register struct file *fp; - register struct a { - int fdes; - int cmd; - int arg; - } *uap; - register int i; - register char *pop; + register struct file *fp; + register struct a { + int fdes; + int cmd; + int arg; + } *uap; + register int i; + register char *pop; - uap = (struct a *)u.u_arg; - fp = getf(uap->fdes); - if (fp == NULL) - return; - pop = &u.u_pofile[uap->fdes]; - switch(uap->cmd) { - case F_DUPFD: - i = uap->arg; - if (i < 0 || i >= NOFILE) { - u.u_error = EINVAL; - return; - } - if ((i = ufalloc(i)) < 0) - return; - dupit(i, fp, *pop &~ UF_EXCLOSE); - break; + uap = (struct a *)u.u_arg; + fp = getf(uap->fdes); + if (fp == NULL) + return; + pop = &u.u_pofile[uap->fdes]; + switch(uap->cmd) { + case F_DUPFD: + i = uap->arg; + if (i < 0 || i >= NOFILE) { + u.u_error = EINVAL; + return; + } + if ((i = ufalloc(i)) < 0) + return; + dupit(i, fp, *pop &~ UF_EXCLOSE); + break; - case F_GETFD: - u.u_rval = *pop & 1; - break; + case F_GETFD: + u.u_rval = *pop & 1; + break; - case F_SETFD: - *pop = (*pop &~ 1) | (uap->arg & 1); - break; + case F_SETFD: + *pop = (*pop &~ 1) | (uap->arg & 1); + break; - case F_GETFL: - u.u_rval = OFLAGS(fp->f_flag); - break; + case F_GETFL: + u.u_rval = OFLAGS(fp->f_flag); + break; - case F_SETFL: - fp->f_flag &= ~FCNTLFLAGS; - fp->f_flag |= (FFLAGS(uap->arg)) & FCNTLFLAGS; - u.u_error = fset (fp, FNONBLOCK, fp->f_flag & FNONBLOCK); - if (u.u_error) - break; - u.u_error = fset (fp, FASYNC, fp->f_flag & FASYNC); - if (u.u_error) - (void) fset (fp, FNONBLOCK, 0); - break; + case F_SETFL: + fp->f_flag &= ~FCNTLFLAGS; + fp->f_flag |= (FFLAGS(uap->arg)) & FCNTLFLAGS; + u.u_error = fset (fp, FNONBLOCK, fp->f_flag & FNONBLOCK); + if (u.u_error) + break; + u.u_error = fset (fp, FASYNC, fp->f_flag & FASYNC); + if (u.u_error) + (void) fset (fp, FNONBLOCK, 0); + break; - case F_GETOWN: - u.u_error = fgetown (fp, &u.u_rval); - break; + case F_GETOWN: + u.u_error = fgetown (fp, &u.u_rval); + break; - case F_SETOWN: - u.u_error = fsetown (fp, uap->arg); - break; + case F_SETOWN: + u.u_error = fsetown (fp, uap->arg); + break; - default: - u.u_error = EINVAL; - } + default: + u.u_error = EINVAL; + } } int fioctl(fp, cmd, value) - register struct file *fp; - u_int cmd; - caddr_t value; + register struct file *fp; + u_int cmd; + caddr_t value; { - return ((*Fops[fp->f_type]->fo_ioctl)(fp, cmd, value)); + return ((*Fops[fp->f_type]->fo_ioctl)(fp, cmd, value)); } /* @@ -194,15 +194,15 @@ fioctl(fp, cmd, value) */ int fset (fp, bit, value) - register struct file *fp; - int bit, value; + register struct file *fp; + int bit, value; { - if (value) - fp->f_flag |= bit; - else - fp->f_flag &= ~bit; - return (fioctl(fp, (u_int)(bit == FNONBLOCK ? FIONBIO : FIOASYNC), - (caddr_t)&value)); + if (value) + fp->f_flag |= bit; + else + fp->f_flag &= ~bit; + return (fioctl(fp, (u_int)(bit == FNONBLOCK ? FIONBIO : FIOASYNC), + (caddr_t)&value)); } /* @@ -210,20 +210,20 @@ fset (fp, bit, value) */ int fgetown(fp, valuep) - register struct file *fp; - register int *valuep; + register struct file *fp; + register int *valuep; { - register int error; + register int error; #ifdef INET - if (fp->f_type == DTYPE_SOCKET) { - *valuep = mfsd(&fp->f_socket->so_pgrp); - return (0); - } + if (fp->f_type == DTYPE_SOCKET) { + *valuep = mfsd(&fp->f_socket->so_pgrp); + return (0); + } #endif - error = fioctl(fp, (u_int)TIOCGPGRP, (caddr_t)valuep); - *valuep = -*valuep; - return (error); + error = fioctl(fp, (u_int)TIOCGPGRP, (caddr_t)valuep); + *valuep = -*valuep; + return (error); } /* @@ -231,79 +231,79 @@ fgetown(fp, valuep) */ int fsetown(fp, value) - register struct file *fp; - int value; + register struct file *fp; + int value; { #ifdef INET - if (fp->f_type == DTYPE_SOCKET) { - mtsd(&fp->f_socket->so_pgrp, value); - return (0); - } + if (fp->f_type == DTYPE_SOCKET) { + mtsd(&fp->f_socket->so_pgrp, value); + return (0); + } #endif - if (value > 0) { - register struct proc *p = pfind(value); - if (p == 0) - return (ESRCH); - value = p->p_pgrp; - } else - value = -value; - return (fioctl(fp, (u_int)TIOCSPGRP, (caddr_t)&value)); + if (value > 0) { + register struct proc *p = pfind(value); + if (p == 0) + return (ESRCH); + value = p->p_pgrp; + } else + value = -value; + return (fioctl(fp, (u_int)TIOCSPGRP, (caddr_t)&value)); } void close() { - register struct a { - int i; - } *uap = (struct a *)u.u_arg; - register struct file *fp; + register struct a { + int i; + } *uap = (struct a *)u.u_arg; + register struct file *fp; - GETF(fp, uap->i); - u.u_ofile[uap->i] = NULL; - while (u.u_lastfile >= 0 && u.u_ofile[u.u_lastfile] == NULL) - u.u_lastfile--; - u.u_error = closef(fp); - /* WHAT IF u.u_error ? */ + GETF(fp, uap->i); + u.u_ofile[uap->i] = NULL; + while (u.u_lastfile >= 0 && u.u_ofile[u.u_lastfile] == NULL) + u.u_lastfile--; + u.u_error = closef(fp); + /* WHAT IF u.u_error ? */ } void fstat() { - register struct file *fp; - register struct a { - int fdes; - struct stat *sb; - } *uap; - struct stat ub; + register struct file *fp; + register struct a { + int fdes; + struct stat *sb; + } *uap; + struct stat ub; - uap = (struct a *)u.u_arg; - fp = getf(uap->fdes); - if (fp == NULL) - return; - switch (fp->f_type) { + uap = (struct a *)u.u_arg; + fp = getf(uap->fdes); + if (fp == NULL) + return; + switch (fp->f_type) { - case DTYPE_PIPE: - case DTYPE_INODE: - u.u_error = ino_stat((struct inode *)fp->f_data, &ub); - if (fp->f_type == DTYPE_PIPE) - ub.st_size -= fp->f_offset; - break; + case DTYPE_PIPE: + case DTYPE_INODE: + u.u_error = ino_stat((struct inode *)fp->f_data, &ub); + if (fp->f_type == DTYPE_PIPE) + ub.st_size -= fp->f_offset; + break; #ifdef INET - case DTYPE_SOCKET: - u.u_error = SOO_STAT(fp->f_socket, &ub); - break; + case DTYPE_SOCKET: + u.u_error = SOO_STAT(fp->f_socket, &ub); + break; #endif - default: - u.u_error = EINVAL; - break; - } - if (u.u_error == 0) - u.u_error = copyout((caddr_t)&ub, (caddr_t)uap->sb, - sizeof (ub)); + default: + u.u_error = EINVAL; + break; + } + if (u.u_error == 0) + u.u_error = copyout((caddr_t)&ub, (caddr_t)uap->sb, + sizeof (ub)); } -struct file *lastf; +struct file *lastf; /* * Allocate a user file descriptor @@ -314,30 +314,30 @@ struct file *lastf; struct file * falloc() { - register struct file *fp; - register int i; + register struct file *fp; + register int i; - i = ufalloc(0); - if (i < 0) - return (NULL); - if (lastf == 0) - lastf = file; - for (fp = lastf; fp < file+NFILE; fp++) - if (fp->f_count == 0) - goto slot; - for (fp = file; fp < lastf; fp++) - if (fp->f_count == 0) - goto slot; - log(LOG_ERR, "file: table full\n"); - u.u_error = ENFILE; - return (NULL); + i = ufalloc(0); + if (i < 0) + return (NULL); + if (lastf == 0) + lastf = file; + for (fp = lastf; fp < file+NFILE; fp++) + if (fp->f_count == 0) + goto slot; + for (fp = file; fp < lastf; fp++) + if (fp->f_count == 0) + goto slot; + log(LOG_ERR, "file: table full\n"); + u.u_error = ENFILE; + return (NULL); slot: - u.u_ofile[i] = fp; - fp->f_count = 1; - fp->f_data = 0; - fp->f_offset = 0; - lastf = fp + 1; - return (fp); + u.u_ofile[i] = fp; + fp->f_count = 1; + fp->f_data = 0; + fp->f_offset = 0; + lastf = fp + 1; + return (fp); } /* @@ -348,15 +348,15 @@ slot: */ struct file * getf(f) - register int f; + register int f; { - register struct file *fp; + register struct file *fp; - if ((unsigned)f >= NOFILE || (fp = u.u_ofile[f]) == NULL) { - u.u_error = EBADF; - return (NULL); - } - return (fp); + if ((unsigned)f >= NOFILE || (fp = u.u_ofile[f]) == NULL) { + u.u_error = EBADF; + return (NULL); + } + return (fp); } /* @@ -365,23 +365,23 @@ getf(f) */ int closef(fp) - register struct file *fp; + register struct file *fp; { - int error; + int error; - if (fp == NULL) - return(0); - if (fp->f_count > 1) { - fp->f_count--; - return(0); - } + if (fp == NULL) + return(0); + if (fp->f_count > 1) { + fp->f_count--; + return(0); + } - if ((fp->f_flag & (FSHLOCK|FEXLOCK)) && fp->f_type == DTYPE_INODE) - ino_unlock(fp, FSHLOCK|FEXLOCK); + if ((fp->f_flag & (FSHLOCK|FEXLOCK)) && fp->f_type == DTYPE_INODE) + ino_unlock(fp, FSHLOCK|FEXLOCK); - error = (*Fops[fp->f_type]->fo_close)(fp); - fp->f_count = 0; - return(error); + error = (*Fops[fp->f_type]->fo_close)(fp); + fp->f_count = 0; + return(error); } /* @@ -390,34 +390,34 @@ closef(fp) void flock() { - register struct a { - int fd; - int how; - } *uap = (struct a *)u.u_arg; - register struct file *fp; - int error; + register struct a { + int fd; + int how; + } *uap = (struct a *)u.u_arg; + register struct file *fp; + int error; - if ((fp = getf(uap->fd)) == NULL) - return; - if (fp->f_type != DTYPE_INODE) { - u.u_error = EOPNOTSUPP; - return; - } - if (uap->how & LOCK_UN) { - ino_unlock(fp, FSHLOCK | FEXLOCK); - return; - } - if ((uap->how & (LOCK_SH | LOCK_EX)) == 0) - return; /* error? */ - if (uap->how & LOCK_EX) - uap->how &= ~LOCK_SH; - /* avoid work... */ - if ((fp->f_flag & FEXLOCK) && (uap->how & LOCK_EX)) - return; - if ((fp->f_flag & FSHLOCK) && (uap->how & LOCK_SH)) - return; - error = ino_lock(fp, uap->how); - u.u_error = error; + if ((fp = getf(uap->fd)) == NULL) + return; + if (fp->f_type != DTYPE_INODE) { + u.u_error = EOPNOTSUPP; + return; + } + if (uap->how & LOCK_UN) { + ino_unlock(fp, FSHLOCK | FEXLOCK); + return; + } + if ((uap->how & (LOCK_SH | LOCK_EX)) == 0) + return; /* error? */ + if (uap->how & LOCK_EX) + uap->how &= ~LOCK_SH; + /* avoid work... */ + if ((fp->f_flag & FEXLOCK) && (uap->how & LOCK_EX)) + return; + if ((fp->f_flag & FSHLOCK) && (uap->how & LOCK_SH)) + return; + error = ino_lock(fp, uap->how); + u.u_error = error; } /* @@ -431,19 +431,19 @@ flock() /* ARGSUSED */ int fdopen(dev, mode, type) - dev_t dev; - int mode, type; + dev_t dev; + int mode, type; { - /* - * XXX Kludge: set u.u_dupfd to contain the value of the - * the file descriptor being sought for duplication. The error - * return ensures that the vnode for this device will be released - * by vn_open. Open will detect this special error and take the - * actions in dupfdopen below. Other callers of vn_open will - * simply report the error. - */ - u.u_dupfd = minor(dev); - return(ENODEV); + /* + * XXX Kludge: set u.u_dupfd to contain the value of the + * the file descriptor being sought for duplication. The error + * return ensures that the vnode for this device will be released + * by vn_open. Open will detect this special error and take the + * actions in dupfdopen below. Other callers of vn_open will + * simply report the error. + */ + u.u_dupfd = minor(dev); + return(ENODEV); } /* @@ -451,82 +451,82 @@ fdopen(dev, mode, type) */ int dupfdopen (indx, dfd, mode, error) - register int indx, dfd; - int mode; - int error; + register int indx, dfd; + int mode; + int error; { - register struct file *wfp; - struct file *fp; + register struct file *wfp; + struct file *fp; - /* - * If the to-be-dup'd fd number is greater than the allowed number - * of file descriptors, or the fd to be dup'd has already been - * closed, reject. Note, check for new == old is necessary as - * falloc could allocate an already closed to-be-dup'd descriptor - * as the new descriptor. - */ - fp = u.u_ofile[indx]; - if (dfd >= NOFILE || (wfp = u.u_ofile[dfd]) == NULL || fp == wfp) - return(EBADF); + /* + * If the to-be-dup'd fd number is greater than the allowed number + * of file descriptors, or the fd to be dup'd has already been + * closed, reject. Note, check for new == old is necessary as + * falloc could allocate an already closed to-be-dup'd descriptor + * as the new descriptor. + */ + fp = u.u_ofile[indx]; + if (dfd >= NOFILE || (wfp = u.u_ofile[dfd]) == NULL || fp == wfp) + return(EBADF); - /* - * There are two cases of interest here. - * - * For ENODEV simply dup (dfd) to file descriptor - * (indx) and return. - * - * For ENXIO steal away the file structure from (dfd) and - * store it in (indx). (dfd) is effectively closed by - * this operation. - * - * NOTE: ENXIO only comes out of the 'portal fs' code of 4.4 - since - * 2.11BSD does not implement the portal fs the code is ifdef'd out - * and a short message output. - * - * Any other error code is just returned. - */ - switch (error) { - case ENODEV: - /* - * Check that the mode the file is being opened for is a - * subset of the mode of the existing descriptor. - */ - if (((mode & (FREAD|FWRITE)) | wfp->f_flag) != wfp->f_flag) - return(EACCES); - u.u_ofile[indx] = wfp; - u.u_pofile[indx] = u.u_pofile[dfd]; - wfp->f_count++; - if (indx > u.u_lastfile) - u.u_lastfile = indx; - return(0); -#ifdef haveportalfs - case ENXIO: - /* - * Steal away the file pointer from dfd, and stuff it into indx. - */ - fdp->fd_ofiles[indx] = fdp->fd_ofiles[dfd]; - fdp->fd_ofiles[dfd] = NULL; - fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd]; - fdp->fd_ofileflags[dfd] = 0; - /* - * Complete the clean up of the filedesc structure by - * recomputing the various hints. - */ - if (indx > fdp->fd_lastfile) - fdp->fd_lastfile = indx; - else - while (fdp->fd_lastfile > 0 && - fdp->fd_ofiles[fdp->fd_lastfile] == NULL) - fdp->fd_lastfile--; - if (dfd < fdp->fd_freefile) - fdp->fd_freefile = dfd; - return (0); + /* + * There are two cases of interest here. + * + * For ENODEV simply dup (dfd) to file descriptor + * (indx) and return. + * + * For ENXIO steal away the file structure from (dfd) and + * store it in (indx). (dfd) is effectively closed by + * this operation. + * + * NOTE: ENXIO only comes out of the 'portal fs' code of 4.4 - since + * 2.11BSD does not implement the portal fs the code is ifdef'd out + * and a short message output. + * + * Any other error code is just returned. + */ + switch (error) { + case ENODEV: + /* + * Check that the mode the file is being opened for is a + * subset of the mode of the existing descriptor. + */ + if (((mode & (FREAD|FWRITE)) | wfp->f_flag) != wfp->f_flag) + return(EACCES); + u.u_ofile[indx] = wfp; + u.u_pofile[indx] = u.u_pofile[dfd]; + wfp->f_count++; + if (indx > u.u_lastfile) + u.u_lastfile = indx; + return(0); +#ifdef haveportalfs + case ENXIO: + /* + * Steal away the file pointer from dfd, and stuff it into indx. + */ + fdp->fd_ofiles[indx] = fdp->fd_ofiles[dfd]; + fdp->fd_ofiles[dfd] = NULL; + fdp->fd_ofileflags[indx] = fdp->fd_ofileflags[dfd]; + fdp->fd_ofileflags[dfd] = 0; + /* + * Complete the clean up of the filedesc structure by + * recomputing the various hints. + */ + if (indx > fdp->fd_lastfile) + fdp->fd_lastfile = indx; + else + while (fdp->fd_lastfile > 0 && + fdp->fd_ofiles[fdp->fd_lastfile] == NULL) + fdp->fd_lastfile--; + if (dfd < fdp->fd_freefile) + fdp->fd_freefile = dfd; + return (0); #else - log(LOG_NOTICE, "dupfdopen"); - /* FALLTHROUGH */ + log(LOG_NOTICE, "dupfdopen"); + /* FALLTHROUGH */ #endif - default: - return(error); - } - /* NOTREACHED */ + default: + return(error); + } + /* NOTREACHED */ } diff --git a/sys/kernel/kern_exec.c b/sys/kernel/kern_exec.c index 68745b0..18f0162 100644 --- a/sys/kernel/kern_exec.c +++ b/sys/kernel/kern_exec.c @@ -22,9 +22,9 @@ * exec system call, with and without environments. */ struct execa { - char *fname; - char **argp; - char **envp; + char *fname; + char **argp; + char **envp; }; /* @@ -38,119 +38,119 @@ struct execa { */ int exec_check(struct exec_params *epp) { - int error, i, r; + int error, i, r; - DEBUG("Entering exec_check\n"); - if (access (epp->ip, IEXEC)) - return ENOEXEC; - if ((u.u_procp->p_flag & P_TRACED) && access (epp->ip, IREAD)) - return ENOEXEC; - if ((epp->ip->i_mode & IFMT) != IFREG || - (epp->ip->i_mode & (IEXEC | (IEXEC>>3) | (IEXEC>>6))) == 0) - return EACCES; + DEBUG("Entering exec_check\n"); + if (access (epp->ip, IEXEC)) + return ENOEXEC; + if ((u.u_procp->p_flag & P_TRACED) && access (epp->ip, IREAD)) + return ENOEXEC; + if ((epp->ip->i_mode & IFMT) != IFREG || + (epp->ip->i_mode & (IEXEC | (IEXEC>>3) | (IEXEC>>6))) == 0) + return EACCES; - /* - * Read in first few bytes of file for segment sizes, magic number: - * 407 = plain executable - * Also an ASCII line beginning with #! is - * the file name of a ``interpreter'' and arguments may be prepended - * to the argument list if given here. - * - * INTERPRETER NAMES ARE LIMITED IN LENGTH. - * - * ONLY ONE ARGUMENT MAY BE PASSED TO THE INTERPRETER FROM - * THE ASCII LINE. - */ + /* + * Read in first few bytes of file for segment sizes, magic number: + * 407 = plain executable + * Also an ASCII line beginning with #! is + * the file name of a ``interpreter'' and arguments may be prepended + * to the argument list if given here. + * + * INTERPRETER NAMES ARE LIMITED IN LENGTH. + * + * ONLY ONE ARGUMENT MAY BE PASSED TO THE INTERPRETER FROM + * THE ASCII LINE. + */ - /* - * Read the first 'SHSIZE' bytes from the file to execute - */ - DEBUG("Read header %d bytes from %d\n", sizeof(epp->hdr), 0); + /* + * Read the first 'SHSIZE' bytes from the file to execute + */ + DEBUG("Read header %d bytes from %d\n", sizeof(epp->hdr), 0); #ifdef EXEC_SCRIPT - epp->hdr.sh[0] = '\0'; /* for zero length files */ + epp->hdr.sh[0] = '\0'; /* for zero length files */ #endif - error = rdwri (UIO_READ, epp->ip, - (caddr_t) &epp->hdr, sizeof(epp->hdr), - (off_t)0, IO_UNIT, &r); - if (error) - return error; - epp->hdr_len = sizeof(epp->hdr) - r; + error = rdwri (UIO_READ, epp->ip, + (caddr_t) &epp->hdr, sizeof(epp->hdr), + (off_t)0, IO_UNIT, &r); + if (error) + return error; + epp->hdr_len = sizeof(epp->hdr) - r; - /* - * Given the first part of the image - * loop through the exec file handlers to find - * someone who can handle this file format. - */ - error = ENOEXEC; - DEBUG("Trying %d exec formats\n", nexecs); - for (i = 0; i < nexecs && error != 0; i++) { - DEBUG("Trying exec format %d : %s\n", i, execsw[i].es_name); - if (execsw[i].es_check == NULL) - continue; - error = (*execsw[i].es_check)(epp); - if (error == 0) - break; - } - return error; + /* + * Given the first part of the image + * loop through the exec file handlers to find + * someone who can handle this file format. + */ + error = ENOEXEC; + DEBUG("Trying %d exec formats\n", nexecs); + for (i = 0; i < nexecs && error != 0; i++) { + DEBUG("Trying exec format %d : %s\n", i, execsw[i].es_name); + if (execsw[i].es_check == NULL) + continue; + error = (*execsw[i].es_check)(epp); + if (error == 0) + break; + } + return error; } void execv() { - struct execa *arg = (struct execa *)u.u_arg; + struct execa *arg = (struct execa *)u.u_arg; - arg->envp = NULL; - execve(); + arg->envp = NULL; + execve(); } void execve() { - struct execa *uap = (struct execa *)u.u_arg; - int error; - struct inode *ip; - struct nameidata nd; - register struct nameidata *ndp = &nd; - struct exec_params eparam; + struct execa *uap = (struct execa *)u.u_arg; + int error; + struct inode *ip; + struct nameidata nd; + register struct nameidata *ndp = &nd; + struct exec_params eparam; - DEBUG("execve ('%s', ['%s', '%s', ...])\n", uap->fname, uap->argp[0], uap->argp[1]); - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - ip = namei (ndp); - if (ip == NULL) { - DEBUG("execve: file '%s' not found\n", uap->fname); - return; - } - /* - * The exec_param structure is used to - * keep information about the executable during exec's processing - */ - bzero(&eparam, sizeof eparam); - eparam.userfname = uap->fname; - eparam.userargp = uap->argp; - eparam.userenvp = uap->envp; - eparam.uid = u.u_uid; - eparam.gid = u.u_groups[0]; + DEBUG("execve ('%s', ['%s', '%s', ...])\n", uap->fname, uap->argp[0], uap->argp[1]); + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + ip = namei (ndp); + if (ip == NULL) { + DEBUG("execve: file '%s' not found\n", uap->fname); + return; + } + /* + * The exec_param structure is used to + * keep information about the executable during exec's processing + */ + bzero(&eparam, sizeof eparam); + eparam.userfname = uap->fname; + eparam.userargp = uap->argp; + eparam.userenvp = uap->envp; + eparam.uid = u.u_uid; + eparam.gid = u.u_groups[0]; - if (ip->i_fs->fs_flags & MNT_NOEXEC) { - u.u_error = EACCES; - DEBUG("EACCES\n"); - goto done; - } - if ((ip->i_fs->fs_flags & MNT_NOSUID) == 0) { - if (ip->i_mode & ISUID) - eparam.uid = ip->i_uid; - if (ip->i_mode & ISGID) - eparam.gid = ip->i_gid; - } + if (ip->i_fs->fs_flags & MNT_NOEXEC) { + u.u_error = EACCES; + DEBUG("EACCES\n"); + goto done; + } + if ((ip->i_fs->fs_flags & MNT_NOSUID) == 0) { + if (ip->i_mode & ISUID) + eparam.uid = ip->i_uid; + if (ip->i_mode & ISGID) + eparam.gid = ip->i_gid; + } - eparam.ip = ip; - DEBUG("calling exec_check()\n"); - if ((error = exec_check(&eparam))) - u.u_error = error; - DEBUG("back from exec_check()\n"); + eparam.ip = ip; + DEBUG("calling exec_check()\n"); + if ((error = exec_check(&eparam))) + u.u_error = error; + DEBUG("back from exec_check()\n"); done: - exec_alloc_freeall(&eparam); - if (ip) - iput(ip); + exec_alloc_freeall(&eparam); + if (ip) + iput(ip); } diff --git a/sys/kernel/kern_exit.c b/sys/kernel/kern_exit.c index b665add..2dbe097 100644 --- a/sys/kernel/kern_exit.c +++ b/sys/kernel/kern_exit.c @@ -22,21 +22,21 @@ void endvfork() { - register struct proc *rip, *rpp; + register struct proc *rip, *rpp; - rpp = u.u_procp; - rip = rpp->p_pptr; - rpp->p_flag &= ~SVFORK; - rpp->p_flag |= SLOCK; - wakeup ((caddr_t) rpp); - while (! (rpp->p_flag & SVFDONE)) - sleep ((caddr_t) rip, PZERO-1); - /* - * The parent has taken back our data+stack, set our sizes to 0. - */ - u.u_dsize = rpp->p_dsize = 0; - u.u_ssize = rpp->p_ssize = 0; - rpp->p_flag &= ~(SVFDONE | SLOCK); + rpp = u.u_procp; + rip = rpp->p_pptr; + rpp->p_flag &= ~SVFORK; + rpp->p_flag |= SLOCK; + wakeup ((caddr_t) rpp); + while (! (rpp->p_flag & SVFDONE)) + sleep ((caddr_t) rip, PZERO-1); + /* + * The parent has taken back our data+stack, set our sizes to 0. + */ + u.u_dsize = rpp->p_dsize = 0; + u.u_ssize = rpp->p_ssize = 0; + rpp->p_flag &= ~(SVFDONE | SLOCK); } /* @@ -47,95 +47,95 @@ endvfork() */ void exit (rv) - int rv; + int rv; { - register int i; - register struct proc *p; - struct proc **pp; + register int i; + register struct proc *p; + struct proc **pp; - p = u.u_procp; - p->p_flag &= ~P_TRACED; - p->p_sigignore = ~0; - p->p_sig = 0; - /* - * 2.11 doesn't need to do this and it gets overwritten anyway. - * p->p_realtimer.it_value = 0; - */ - for (i = 0; i <= u.u_lastfile; i++) { - register struct file *f; + p = u.u_procp; + p->p_flag &= ~P_TRACED; + p->p_sigignore = ~0; + p->p_sig = 0; + /* + * 2.11 doesn't need to do this and it gets overwritten anyway. + * p->p_realtimer.it_value = 0; + */ + for (i = 0; i <= u.u_lastfile; i++) { + register struct file *f; - f = u.u_ofile[i]; - u.u_ofile[i] = NULL; - u.u_pofile[i] = 0; - (void) closef(f); - } - ilock(u.u_cdir); - iput(u.u_cdir); - if (u.u_rdir) { - ilock(u.u_rdir); - iput(u.u_rdir); - } - u.u_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; + f = u.u_ofile[i]; + u.u_ofile[i] = NULL; + u.u_pofile[i] = 0; + (void) closef(f); + } + ilock(u.u_cdir); + iput(u.u_cdir); + if (u.u_rdir) { + ilock(u.u_rdir); + iput(u.u_rdir); + } + u.u_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; - if (p->p_flag & SVFORK) - endvfork(); + if (p->p_flag & SVFORK) + endvfork(); - if (p->p_pid == 1) - panic("init died"); - if ((*p->p_prev = p->p_nxt) != NULL) /* off allproc queue */ - p->p_nxt->p_prev = p->p_prev; - p->p_nxt = zombproc; /* onto zombproc */ - if (p->p_nxt != NULL) - p->p_nxt->p_prev = &p->p_nxt; - p->p_prev = &zombproc; - zombproc = p; - p->p_stat = SZOMB; + if (p->p_pid == 1) + panic("init died"); + if ((*p->p_prev = p->p_nxt) != NULL) /* off allproc queue */ + p->p_nxt->p_prev = p->p_prev; + p->p_nxt = zombproc; /* onto zombproc */ + if (p->p_nxt != NULL) + p->p_nxt->p_prev = &p->p_nxt; + p->p_prev = &zombproc; + zombproc = p; + p->p_stat = SZOMB; - noproc = 1; - for (pp = &pidhash[PIDHASH(p->p_pid)]; *pp; pp = &(*pp)->p_hash) - if (*pp == p) { - *pp = p->p_hash; - goto done; - } - panic("exit"); + noproc = 1; + for (pp = &pidhash[PIDHASH(p->p_pid)]; *pp; pp = &(*pp)->p_hash) + if (*pp == p) { + *pp = p->p_hash; + goto done; + } + panic("exit"); done: - /* - * Overwrite p_alive substructure of proc - better not be anything - * important left! - */ - p->p_xstat = rv; - p->p_ru = u.u_ru; - ruadd(&p->p_ru, &u.u_cru); - { - register struct proc *q; - int doingzomb = 0; + /* + * Overwrite p_alive substructure of proc - better not be anything + * important left! + */ + p->p_xstat = rv; + p->p_ru = u.u_ru; + ruadd(&p->p_ru, &u.u_cru); + { + register struct proc *q; + int doingzomb = 0; - q = allproc; + q = allproc; again: - for(; q; q = q->p_nxt) - if (q->p_pptr == p) { - q->p_pptr = &proc[1]; - q->p_ppid = 1; - wakeup((caddr_t)&proc[1]); - if (q->p_flag& P_TRACED) { - q->p_flag &= ~P_TRACED; - psignal(q, SIGKILL); - } else if (q->p_stat == SSTOP) { - psignal(q, SIGHUP); - psignal(q, SIGCONT); - } - } - if (!doingzomb) { - doingzomb = 1; - q = zombproc; - goto again; - } - } - psignal(p->p_pptr, SIGCHLD); - wakeup((caddr_t) p->p_pptr); - wakeup((caddr_t) &runin); - swtch(); - /* NOTREACHED */ + for(; q; q = q->p_nxt) + if (q->p_pptr == p) { + q->p_pptr = &proc[1]; + q->p_ppid = 1; + wakeup((caddr_t)&proc[1]); + if (q->p_flag& P_TRACED) { + q->p_flag &= ~P_TRACED; + psignal(q, SIGKILL); + } else if (q->p_stat == SSTOP) { + psignal(q, SIGHUP); + psignal(q, SIGCONT); + } + } + if (!doingzomb) { + doingzomb = 1; + q = zombproc; + goto again; + } + } + psignal(p->p_pptr, SIGCHLD); + wakeup((caddr_t) p->p_pptr); + wakeup((caddr_t) &runin); + swtch(); + /* NOTREACHED */ } /* @@ -144,19 +144,19 @@ again: void rexit() { - register struct a { - int rval; - } *uap = (struct a*) u.u_arg; + register struct a { + int rval; + } *uap = (struct a*) u.u_arg; - exit (W_EXITCODE (uap->rval, 0)); - /* NOTREACHED */ + exit (W_EXITCODE (uap->rval, 0)); + /* NOTREACHED */ } struct args { - int pid; - int *status; - int options; - struct rusage *rusage; + int pid; + int *status; + int options; + struct rusage *rusage; }; /* @@ -167,114 +167,114 @@ struct args { */ static int wait1 (q, uap, retval) - struct proc *q; - register struct args *uap; - int retval[]; + struct proc *q; + register struct args *uap; + int retval[]; { - int nfound, status; - struct rusage ru; /* used for local conversion */ - register struct proc *p; - register int error; + int nfound, status; + struct rusage ru; /* used for local conversion */ + register struct proc *p; + register int error; - if (uap->pid == WAIT_MYPGRP) /* == 0 */ - uap->pid = -q->p_pgrp; + if (uap->pid == WAIT_MYPGRP) /* == 0 */ + uap->pid = -q->p_pgrp; loop: - nfound = 0; - /* - * 4.X has child links in the proc structure, so they consolidate - * these two tests into one loop. We only have the zombie chain - * and the allproc chain, so we check for ZOMBIES first, then for - * children that have changed state. We check for ZOMBIES first - * because they are more common, and, as the list is typically small, - * a faster check. - */ - for (p = zombproc; p; p = p->p_nxt) { - if (p->p_pptr != q) /* are we the parent of this process? */ - continue; - if (uap->pid != WAIT_ANY && - p->p_pid != uap->pid && p->p_pgrp != -uap->pid) - continue; - retval[0] = p->p_pid; - retval[1] = p->p_xstat; - if (uap->status && (error = copyout ((caddr_t) &p->p_xstat, - (caddr_t) uap->status, sizeof (uap->status)))) - return(error); - if (uap->rusage) { - rucvt(&ru, &p->p_ru); - error = copyout ((caddr_t) &ru, (caddr_t) uap->rusage, sizeof (ru)); - if (error) - return(error); - } - ruadd(&u.u_cru, &p->p_ru); - p->p_xstat = 0; - p->p_stat = NULL; - p->p_pid = 0; - p->p_ppid = 0; - if ((*p->p_prev = p->p_nxt) != NULL) /* off zombproc */ - p->p_nxt->p_prev = p->p_prev; - p->p_nxt = freeproc; /* onto freeproc */ - freeproc = p; - p->p_pptr = 0; - p->p_sig = 0; - p->p_sigcatch = 0; - p->p_sigignore = 0; - p->p_sigmask = 0; - p->p_pgrp = 0; - p->p_flag = 0; - p->p_wchan = 0; - return (0); - } - for (p = allproc; p;p = p->p_nxt) { - if (p->p_pptr != q) - continue; - if (uap->pid != WAIT_ANY && - p->p_pid != uap->pid && p->p_pgrp != -uap->pid) - continue; - ++nfound; - if (p->p_stat == SSTOP && ! (p->p_flag & P_WAITED) && - (p->p_flag & P_TRACED || uap->options & WUNTRACED)) { - p->p_flag |= P_WAITED; - retval[0] = p->p_pid; - error = 0; - if (uap->status) { - status = W_STOPCODE(p->p_ptracesig); - error = copyout ((caddr_t) &status, - (caddr_t) uap->status, sizeof (status)); - } - return (error); - } - } - if (nfound == 0) - return (ECHILD); - if (uap->options&WNOHANG) { - retval[0] = 0; - return (0); - } - error = tsleep ((caddr_t) q, PWAIT|PCATCH, 0); - if (error == 0) - goto loop; - return(error); + nfound = 0; + /* + * 4.X has child links in the proc structure, so they consolidate + * these two tests into one loop. We only have the zombie chain + * and the allproc chain, so we check for ZOMBIES first, then for + * children that have changed state. We check for ZOMBIES first + * because they are more common, and, as the list is typically small, + * a faster check. + */ + for (p = zombproc; p; p = p->p_nxt) { + if (p->p_pptr != q) /* are we the parent of this process? */ + continue; + if (uap->pid != WAIT_ANY && + p->p_pid != uap->pid && p->p_pgrp != -uap->pid) + continue; + retval[0] = p->p_pid; + retval[1] = p->p_xstat; + if (uap->status && (error = copyout ((caddr_t) &p->p_xstat, + (caddr_t) uap->status, sizeof (uap->status)))) + return(error); + if (uap->rusage) { + rucvt(&ru, &p->p_ru); + error = copyout ((caddr_t) &ru, (caddr_t) uap->rusage, sizeof (ru)); + if (error) + return(error); + } + ruadd(&u.u_cru, &p->p_ru); + p->p_xstat = 0; + p->p_stat = NULL; + p->p_pid = 0; + p->p_ppid = 0; + if ((*p->p_prev = p->p_nxt) != NULL) /* off zombproc */ + p->p_nxt->p_prev = p->p_prev; + p->p_nxt = freeproc; /* onto freeproc */ + freeproc = p; + p->p_pptr = 0; + p->p_sig = 0; + p->p_sigcatch = 0; + p->p_sigignore = 0; + p->p_sigmask = 0; + p->p_pgrp = 0; + p->p_flag = 0; + p->p_wchan = 0; + return (0); + } + for (p = allproc; p;p = p->p_nxt) { + if (p->p_pptr != q) + continue; + if (uap->pid != WAIT_ANY && + p->p_pid != uap->pid && p->p_pgrp != -uap->pid) + continue; + ++nfound; + if (p->p_stat == SSTOP && ! (p->p_flag & P_WAITED) && + (p->p_flag & P_TRACED || uap->options & WUNTRACED)) { + p->p_flag |= P_WAITED; + retval[0] = p->p_pid; + error = 0; + if (uap->status) { + status = W_STOPCODE(p->p_ptracesig); + error = copyout ((caddr_t) &status, + (caddr_t) uap->status, sizeof (status)); + } + return (error); + } + } + if (nfound == 0) + return (ECHILD); + if (uap->options&WNOHANG) { + retval[0] = 0; + return (0); + } + error = tsleep ((caddr_t) q, PWAIT|PCATCH, 0); + if (error == 0) + goto loop; + return(error); } void wait4() { - int retval[2]; - register struct args *uap = (struct args*) u.u_arg; + int retval[2]; + register struct args *uap = (struct args*) u.u_arg; - retval[0] = 0; - u.u_error = wait1 (u.u_procp, uap, retval); - if (! u.u_error) - u.u_rval = retval[0]; + retval[0] = 0; + u.u_error = wait1 (u.u_procp, uap, retval); + if (! u.u_error) + u.u_rval = retval[0]; } void reboot() { - struct a { - int opt; - }; + struct a { + int opt; + }; - if (suser ()) - boot (rootdev, ((struct a*)u.u_arg)->opt); + if (suser ()) + boot (rootdev, ((struct a*)u.u_arg)->opt); } diff --git a/sys/kernel/kern_fork.c b/sys/kernel/kern_fork.c index 603812a..656df03 100644 --- a/sys/kernel/kern_fork.c +++ b/sys/kernel/kern_fork.c @@ -14,7 +14,7 @@ #include "kernel.h" #include "syslog.h" -int mpid; /* generic for unique process id's */ +int mpid; /* generic for unique process id's */ /* * Create a new process -- the internal version of system call fork. @@ -22,217 +22,217 @@ int mpid; /* generic for unique process id's */ */ int newproc (isvfork) - int isvfork; + int isvfork; { - register struct proc *child, *parent; - register int n; - static int pidchecked = 0; - struct file *fp; + register struct proc *child, *parent; + register int n; + static int pidchecked = 0; + struct file *fp; - /* - * First, just locate a slot for a process - * and copy the useful info from this process into it. - * The panic "cannot happen" because fork has already - * checked for the existence of a slot. - */ - mpid++; + /* + * First, just locate a slot for a process + * and copy the useful info from this process into it. + * The panic "cannot happen" because fork has already + * checked for the existence of a slot. + */ + mpid++; retry: - if (mpid >= 30000) { - mpid = 100; - pidchecked = 0; - } - if (mpid >= pidchecked) { - int doingzomb = 0; + if (mpid >= 30000) { + mpid = 100; + pidchecked = 0; + } + if (mpid >= pidchecked) { + int doingzomb = 0; - pidchecked = 30000; - /* - * Scan the proc table to check whether this pid - * is in use. Remember the lowest pid that's greater - * than mpid, so we can avoid checking for a while. - */ - child = allproc; + pidchecked = 30000; + /* + * Scan the proc table to check whether this pid + * is in use. Remember the lowest pid that's greater + * than mpid, so we can avoid checking for a while. + */ + child = allproc; again: - for (; child != NULL; child = child->p_nxt) { - if (child->p_pid == mpid || child->p_pgrp == mpid) { - mpid++; - if (mpid >= pidchecked) - goto retry; - } - if (child->p_pid > mpid && pidchecked > child->p_pid) - pidchecked = child->p_pid; - if (child->p_pgrp > mpid && pidchecked > child->p_pgrp) - pidchecked = child->p_pgrp; - } - if (!doingzomb) { - doingzomb = 1; - child = zombproc; - goto again; - } - } - child = freeproc; - if (child == NULL) - panic("no procs"); + for (; child != NULL; child = child->p_nxt) { + if (child->p_pid == mpid || child->p_pgrp == mpid) { + mpid++; + if (mpid >= pidchecked) + goto retry; + } + if (child->p_pid > mpid && pidchecked > child->p_pid) + pidchecked = child->p_pid; + if (child->p_pgrp > mpid && pidchecked > child->p_pgrp) + pidchecked = child->p_pgrp; + } + if (!doingzomb) { + doingzomb = 1; + child = zombproc; + goto again; + } + } + child = freeproc; + if (child == NULL) + panic("no procs"); - freeproc = child->p_nxt; /* off freeproc */ + freeproc = child->p_nxt; /* off freeproc */ - /* - * Make a proc table entry for the new process. - */ - parent = u.u_procp; - child->p_stat = SIDL; - child->p_realtimer.it_value = 0; - child->p_flag = SLOAD; - child->p_uid = parent->p_uid; - child->p_pgrp = parent->p_pgrp; - child->p_nice = parent->p_nice; - child->p_pid = mpid; - child->p_ppid = parent->p_pid; - child->p_pptr = parent; - child->p_time = 0; - child->p_cpu = 0; - child->p_sigmask = parent->p_sigmask; - child->p_sigcatch = parent->p_sigcatch; - child->p_sigignore = parent->p_sigignore; - /* take along any pending signals like stops? */ + /* + * Make a proc table entry for the new process. + */ + parent = u.u_procp; + child->p_stat = SIDL; + child->p_realtimer.it_value = 0; + child->p_flag = SLOAD; + child->p_uid = parent->p_uid; + child->p_pgrp = parent->p_pgrp; + child->p_nice = parent->p_nice; + child->p_pid = mpid; + child->p_ppid = parent->p_pid; + child->p_pptr = parent; + child->p_time = 0; + child->p_cpu = 0; + child->p_sigmask = parent->p_sigmask; + child->p_sigcatch = parent->p_sigcatch; + child->p_sigignore = parent->p_sigignore; + /* take along any pending signals like stops? */ #ifdef UCB_METER - if (isvfork) { - forkstat.cntvfork++; - forkstat.sizvfork += (parent->p_dsize + parent->p_ssize) >> 10; - } else { - forkstat.cntfork++; - forkstat.sizfork += (parent->p_dsize + parent->p_ssize) >> 10; - } + if (isvfork) { + forkstat.cntvfork++; + forkstat.sizvfork += (parent->p_dsize + parent->p_ssize) >> 10; + } else { + forkstat.cntfork++; + forkstat.sizfork += (parent->p_dsize + parent->p_ssize) >> 10; + } #endif - child->p_wchan = 0; - child->p_slptime = 0; - { - struct proc **hash = &pidhash [PIDHASH (child->p_pid)]; + child->p_wchan = 0; + child->p_slptime = 0; + { + struct proc **hash = &pidhash [PIDHASH (child->p_pid)]; - child->p_hash = *hash; - *hash = child; - } - /* - * some shuffling here -- in most UNIX kernels, the allproc assign - * is done after grabbing the struct off of the freeproc list. We - * wait so that if the clock interrupts us and vmtotal walks allproc - * the text pointer isn't garbage. - */ - child->p_nxt = allproc; /* onto allproc */ - child->p_nxt->p_prev = &child->p_nxt; /* (allproc is never NULL) */ - child->p_prev = &allproc; - allproc = child; + child->p_hash = *hash; + *hash = child; + } + /* + * some shuffling here -- in most UNIX kernels, the allproc assign + * is done after grabbing the struct off of the freeproc list. We + * wait so that if the clock interrupts us and vmtotal walks allproc + * the text pointer isn't garbage. + */ + child->p_nxt = allproc; /* onto allproc */ + child->p_nxt->p_prev = &child->p_nxt; /* (allproc is never NULL) */ + child->p_prev = &allproc; + allproc = child; - /* - * Increase reference counts on shared objects. - */ - for (n = 0; n <= u.u_lastfile; n++) { - fp = u.u_ofile[n]; - if (fp == NULL) - continue; - fp->f_count++; - } - u.u_cdir->i_count++; - if (u.u_rdir) - u.u_rdir->i_count++; + /* + * Increase reference counts on shared objects. + */ + for (n = 0; n <= u.u_lastfile; n++) { + fp = u.u_ofile[n]; + if (fp == NULL) + continue; + fp->f_count++; + } + u.u_cdir->i_count++; + if (u.u_rdir) + u.u_rdir->i_count++; - /* - * When the longjmp is executed for the new process, - * here's where it will resume. - */ - if (setjmp (&u.u_ssave)) { - return(1); - } + /* + * When the longjmp is executed for the new process, + * here's where it will resume. + */ + if (setjmp (&u.u_ssave)) { + return(1); + } - child->p_dsize = parent->p_dsize; - child->p_ssize = parent->p_ssize; - child->p_daddr = parent->p_daddr; - child->p_saddr = parent->p_saddr; + child->p_dsize = parent->p_dsize; + child->p_ssize = parent->p_ssize; + child->p_daddr = parent->p_daddr; + child->p_saddr = parent->p_saddr; - /* - * Partially simulate the environment of the new process so that - * when it is actually created (by copying) it will look right. - */ - u.u_procp = child; + /* + * Partially simulate the environment of the new process so that + * when it is actually created (by copying) it will look right. + */ + u.u_procp = child; - /* - * Swap out the current process to generate the copy. - */ - parent->p_stat = SIDL; - child->p_addr = parent->p_addr; - child->p_stat = SRUN; - swapout (child, X_DONTFREE, X_OLDSIZE, X_OLDSIZE); - child->p_flag |= SSWAP; - parent->p_stat = SRUN; - u.u_procp = parent; + /* + * Swap out the current process to generate the copy. + */ + parent->p_stat = SIDL; + child->p_addr = parent->p_addr; + child->p_stat = SRUN; + swapout (child, X_DONTFREE, X_OLDSIZE, X_OLDSIZE); + child->p_flag |= SSWAP; + parent->p_stat = SRUN; + u.u_procp = parent; - if (isvfork) { - /* - * Wait for the child to finish with it. - * RetroBSD: to make this work, significant - * changes in scheduler are required. - */ - parent->p_dsize = 0; - parent->p_ssize = 0; - child->p_flag |= SVFORK; - parent->p_flag |= SVFPRNT; - while (child->p_flag & SVFORK) - sleep ((caddr_t)child, PSWP+1); - if ((child->p_flag & SLOAD) == 0) - panic ("newproc vfork"); - u.u_dsize = parent->p_dsize = child->p_dsize; - parent->p_daddr = child->p_daddr; - child->p_dsize = 0; - u.u_ssize = parent->p_ssize = child->p_ssize; - parent->p_saddr = child->p_saddr; - child->p_ssize = 0; - child->p_flag |= SVFDONE; - wakeup ((caddr_t) parent); - parent->p_flag &= ~SVFPRNT; - } - return(0); + if (isvfork) { + /* + * Wait for the child to finish with it. + * RetroBSD: to make this work, significant + * changes in scheduler are required. + */ + parent->p_dsize = 0; + parent->p_ssize = 0; + child->p_flag |= SVFORK; + parent->p_flag |= SVFPRNT; + while (child->p_flag & SVFORK) + sleep ((caddr_t)child, PSWP+1); + if ((child->p_flag & SLOAD) == 0) + panic ("newproc vfork"); + u.u_dsize = parent->p_dsize = child->p_dsize; + parent->p_daddr = child->p_daddr; + child->p_dsize = 0; + u.u_ssize = parent->p_ssize = child->p_ssize; + parent->p_saddr = child->p_saddr; + child->p_ssize = 0; + child->p_flag |= SVFDONE; + wakeup ((caddr_t) parent); + parent->p_flag &= ~SVFPRNT; + } + return(0); } static void fork1 (isvfork) - int isvfork; + int isvfork; { - register int a; - register struct proc *p1, *p2; + register int a; + register struct proc *p1, *p2; - a = 0; - if (u.u_uid != 0) { - for (p1 = allproc; p1; p1 = p1->p_nxt) - if (p1->p_uid == u.u_uid) - a++; - for (p1 = zombproc; p1; p1 = p1->p_nxt) - if (p1->p_uid == u.u_uid) - a++; - } - /* - * Disallow if - * No processes at all; - * not su and too many procs owned; or - * not su and would take last slot. - */ - p2 = freeproc; - if (p2==NULL) - log(LOG_ERR, "proc: table full\n"); + a = 0; + if (u.u_uid != 0) { + for (p1 = allproc; p1; p1 = p1->p_nxt) + if (p1->p_uid == u.u_uid) + a++; + for (p1 = zombproc; p1; p1 = p1->p_nxt) + if (p1->p_uid == u.u_uid) + a++; + } + /* + * Disallow if + * No processes at all; + * not su and too many procs owned; or + * not su and would take last slot. + */ + p2 = freeproc; + if (p2==NULL) + log(LOG_ERR, "proc: table full\n"); - if (p2==NULL || (u.u_uid!=0 && (p2->p_nxt == NULL || a>MAXUPRC))) { - u.u_error = EAGAIN; - return; - } - p1 = u.u_procp; - if (newproc (isvfork)) { - /* Child */ - u.u_rval = 0; - u.u_start = time.tv_sec; - bzero(&u.u_ru, sizeof(u.u_ru)); - bzero(&u.u_cru, sizeof(u.u_cru)); - return; - } - /* Parent */ - u.u_rval = p2->p_pid; + if (p2==NULL || (u.u_uid!=0 && (p2->p_nxt == NULL || a>MAXUPRC))) { + u.u_error = EAGAIN; + return; + } + p1 = u.u_procp; + if (newproc (isvfork)) { + /* Child */ + u.u_rval = 0; + u.u_start = time.tv_sec; + bzero(&u.u_ru, sizeof(u.u_ru)); + bzero(&u.u_cru, sizeof(u.u_cru)); + return; + } + /* Parent */ + u.u_rval = p2->p_pid; } /* @@ -241,7 +241,7 @@ fork1 (isvfork) void fork() { - fork1 (0); + fork1 (0); } /* @@ -250,5 +250,5 @@ fork() void vfork() { - fork1 (1); + fork1 (1); } diff --git a/sys/kernel/kern_glob.c b/sys/kernel/kern_glob.c index 34203d1..71b3e59 100644 --- a/sys/kernel/kern_glob.c +++ b/sys/kernel/kern_glob.c @@ -18,44 +18,44 @@ unsigned char global_segment[GLOBSZ]; void rdglob() { - struct a { - int addr; - } *uap = (struct a *)u.u_arg; + struct a { + int addr; + } *uap = (struct a *)u.u_arg; - // Only root should have access to the shared memory block - if(u.u_uid!=0) - { - u.u_rval = -1; - return; - } + // Only root should have access to the shared memory block + if(u.u_uid!=0) + { + u.u_rval = -1; + return; + } - if(uap->addr>=GLOBSZ) - { - u.u_rval = -1; - return; - } - u.u_rval = global_segment[uap->addr]; + if(uap->addr>=GLOBSZ) + { + u.u_rval = -1; + return; + } + u.u_rval = global_segment[uap->addr]; } void wrglob() { - struct a { - int addr; - unsigned char value; - } *uap = (struct a *)u.u_arg; + struct a { + int addr; + unsigned char value; + } *uap = (struct a *)u.u_arg; - // Only root should have access to the shared memory block - if(u.u_uid!=0) - { - u.u_rval = -1; - return; - } + // Only root should have access to the shared memory block + if(u.u_uid!=0) + { + u.u_rval = -1; + return; + } - if(uap->addr>=GLOBSZ) - { - u.u_rval = -1; - return; - } - u.u_rval = 0; - global_segment[uap->addr] = uap->value; + if(uap->addr>=GLOBSZ) + { + u.u_rval = -1; + return; + } + u.u_rval = 0; + global_segment[uap->addr] = uap->value; } diff --git a/sys/kernel/kern_mman.c b/sys/kernel/kern_mman.c index 839b7f3..4705f05 100644 --- a/sys/kernel/kern_mman.c +++ b/sys/kernel/kern_mman.c @@ -12,27 +12,27 @@ void brk() { - struct a { - int naddr; - }; - register int newsize, d; + struct a { + int naddr; + }; + register int newsize, d; - /* set newsize to new data size */ - newsize = ((struct a*)u.u_arg)->naddr - u.u_procp->p_daddr; - if (newsize < 0) - newsize = 0; - if (u.u_tsize + newsize + u.u_ssize > MAXMEM) { - u.u_error = ENOMEM; - return; - } + /* set newsize to new data size */ + newsize = ((struct a*)u.u_arg)->naddr - u.u_procp->p_daddr; + if (newsize < 0) + newsize = 0; + if (u.u_tsize + newsize + u.u_ssize > MAXMEM) { + u.u_error = ENOMEM; + return; + } - u.u_procp->p_dsize = newsize; + u.u_procp->p_dsize = newsize; - /* set d to (new - old) */ - d = newsize - u.u_dsize; + /* set d to (new - old) */ + d = newsize - u.u_dsize; //printf ("brk: new size %u bytes, incremented by %d\n", newsize, d); - if (d > 0) - bzero ((void*) (u.u_procp->p_daddr + u.u_dsize), d); - u.u_dsize = newsize; - u.u_rval = u.u_procp->p_daddr + u.u_dsize; + if (d > 0) + bzero ((void*) (u.u_procp->p_daddr + u.u_dsize), d); + u.u_dsize = newsize; + u.u_rval = u.u_procp->p_daddr + u.u_dsize; } diff --git a/sys/kernel/kern_proc.c b/sys/kernel/kern_proc.c index 1df38e8..da4d820 100644 --- a/sys/kernel/kern_proc.c +++ b/sys/kernel/kern_proc.c @@ -13,12 +13,12 @@ */ int inferior(p) - register struct proc *p; + register struct proc *p; { - for (; p != u.u_procp; p = p->p_pptr) - if (p->p_ppid == 0) - return (0); - return (1); + for (; p != u.u_procp; p = p->p_pptr) + if (p->p_ppid == 0) + return (0); + return (1); } /* @@ -26,14 +26,14 @@ inferior(p) */ struct proc * pfind (pid) - register int pid; + register int pid; { - register struct proc *p = pidhash [PIDHASH(pid)]; + register struct proc *p = pidhash [PIDHASH(pid)]; - for (; p; p = p->p_hash) - if (p->p_pid == pid) - return (p); - return ((struct proc *)0); + for (; p; p = p->p_hash) + if (p->p_pid == pid) + return (p); + return ((struct proc *)0); } /* @@ -42,24 +42,24 @@ pfind (pid) void pqinit() { - register struct proc *p; + register struct proc *p; - /* - * most procs are initially on freequeue - * nb: we place them there in their "natural" order. - */ + /* + * most procs are initially on freequeue + * nb: we place them there in their "natural" order. + */ - freeproc = NULL; - for (p = proc+NPROC; --p > proc; freeproc = p) - p->p_nxt = freeproc; + freeproc = NULL; + for (p = proc+NPROC; --p > proc; freeproc = p) + p->p_nxt = freeproc; - /* - * but proc[0] is special ... - */ + /* + * but proc[0] is special ... + */ - allproc = p; - p->p_nxt = NULL; - p->p_prev = &allproc; + allproc = p; + p->p_nxt = NULL; + p->p_prev = &allproc; - zombproc = NULL; + zombproc = NULL; } diff --git a/sys/kernel/kern_prot.c b/sys/kernel/kern_prot.c index 0f37df7..7b7306c 100644 --- a/sys/kernel/kern_prot.c +++ b/sys/kernel/kern_prot.c @@ -13,55 +13,55 @@ void getpid() { - u.u_rval = u.u_procp->p_pid; + u.u_rval = u.u_procp->p_pid; } void getppid() { - u.u_rval = u.u_procp->p_ppid; + u.u_rval = u.u_procp->p_ppid; } void getpgrp() { - register struct a { - int pid; - } *uap = (struct a *)u.u_arg; - register struct proc *p; + register struct a { + int pid; + } *uap = (struct a *)u.u_arg; + register struct proc *p; - if (uap->pid == 0) /* silly... */ - uap->pid = u.u_procp->p_pid; - p = pfind(uap->pid); - if (p == 0) { - u.u_error = ESRCH; - return; - } - u.u_rval = p->p_pgrp; + if (uap->pid == 0) /* silly... */ + uap->pid = u.u_procp->p_pid; + p = pfind(uap->pid); + if (p == 0) { + u.u_error = ESRCH; + return; + } + u.u_rval = p->p_pgrp; } void getuid() { - u.u_rval = u.u_ruid; + u.u_rval = u.u_ruid; } void geteuid() { - u.u_rval = u.u_uid; + u.u_rval = u.u_uid; } void getgid() { - u.u_rval = u.u_rgid; + u.u_rval = u.u_rgid; } void getegid() { - u.u_rval = u.u_groups[0]; + u.u_rval = u.u_groups[0]; } /* @@ -71,72 +71,72 @@ getegid() void getgroups() { - register struct a { - u_int gidsetsize; - int *gidset; - } *uap = (struct a *)u.u_arg; - register gid_t *gp; + register struct a { + u_int gidsetsize; + int *gidset; + } *uap = (struct a *)u.u_arg; + register gid_t *gp; - for (gp = &u.u_groups[NGROUPS]; gp > u.u_groups; gp--) - if (gp[-1] != NOGROUP) - break; - if (uap->gidsetsize < gp - u.u_groups) { - u.u_error = EINVAL; - return; - } - uap->gidsetsize = gp - u.u_groups; - u.u_error = copyout((caddr_t)u.u_groups, (caddr_t)uap->gidset, - uap->gidsetsize * sizeof(u.u_groups[0])); - if (u.u_error) - return; - u.u_rval = uap->gidsetsize; + for (gp = &u.u_groups[NGROUPS]; gp > u.u_groups; gp--) + if (gp[-1] != NOGROUP) + break; + if (uap->gidsetsize < gp - u.u_groups) { + u.u_error = EINVAL; + return; + } + uap->gidsetsize = gp - u.u_groups; + u.u_error = copyout((caddr_t)u.u_groups, (caddr_t)uap->gidset, + uap->gidsetsize * sizeof(u.u_groups[0])); + if (u.u_error) + return; + u.u_rval = uap->gidsetsize; } void setpgrp() { - register struct proc *p; - register struct a { - int pid; - int pgrp; - } *uap = (struct a *)u.u_arg; + register struct proc *p; + register struct a { + int pid; + int pgrp; + } *uap = (struct a *)u.u_arg; - if (uap->pid == 0) /* silly... */ - uap->pid = u.u_procp->p_pid; - p = pfind(uap->pid); - if (p == 0) { - u.u_error = ESRCH; - return; - } - /* need better control mechanisms for process groups */ - if (p->p_uid != u.u_uid && u.u_uid && !inferior(p)) { - u.u_error = EPERM; - return; - } - p->p_pgrp = uap->pgrp; + if (uap->pid == 0) /* silly... */ + uap->pid = u.u_procp->p_pid; + p = pfind(uap->pid); + if (p == 0) { + u.u_error = ESRCH; + return; + } + /* need better control mechanisms for process groups */ + if (p->p_uid != u.u_uid && u.u_uid && !inferior(p)) { + u.u_error = EPERM; + return; + } + p->p_pgrp = uap->pgrp; } void setgroups() { - register struct a { - u_int gidsetsize; - int *gidset; - } *uap = (struct a *)u.u_arg; - register gid_t *gp; + register struct a { + u_int gidsetsize; + int *gidset; + } *uap = (struct a *)u.u_arg; + register gid_t *gp; - if (!suser()) - return; - if (uap->gidsetsize > sizeof (u.u_groups) / sizeof (u.u_groups[0])) { - u.u_error = EINVAL; - return; - } - u.u_error = copyin((caddr_t)uap->gidset, (caddr_t)u.u_groups, - uap->gidsetsize * sizeof (u.u_groups[0])); - if (u.u_error) - return; - for (gp = &u.u_groups[uap->gidsetsize]; gp < &u.u_groups[NGROUPS]; gp++) - *gp = NOGROUP; + if (!suser()) + return; + if (uap->gidsetsize > sizeof (u.u_groups) / sizeof (u.u_groups[0])) { + u.u_error = EINVAL; + return; + } + u.u_error = copyin((caddr_t)uap->gidset, (caddr_t)u.u_groups, + uap->gidsetsize * sizeof (u.u_groups[0])); + if (u.u_error) + return; + for (gp = &u.u_groups[uap->gidsetsize]; gp < &u.u_groups[NGROUPS]; gp++) + *gp = NOGROUP; } /* @@ -144,12 +144,12 @@ setgroups() */ int groupmember(gid) - gid_t gid; + gid_t gid; { - register gid_t *gp; + register gid_t *gp; - for (gp = u.u_groups; gp < &u.u_groups[NGROUPS] && *gp != NOGROUP; gp++) - if (*gp == gid) - return (1); - return (0); + for (gp = u.u_groups; gp < &u.u_groups[NGROUPS] && *gp != NOGROUP; gp++) + if (*gp == gid) + return (1); + return (0); } diff --git a/sys/kernel/kern_prot2.c b/sys/kernel/kern_prot2.c index fa4c66f..bbe5287 100644 --- a/sys/kernel/kern_prot2.c +++ b/sys/kernel/kern_prot2.c @@ -1,6 +1,6 @@ /* * Copyright (c) 1982, 1986, 1989, 1990, 1991, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -43,72 +43,72 @@ void setuid() { - struct a { - uid_t uid; - } *uap = (struct a*) u.u_arg; - register uid_t uid; + struct a { + uid_t uid; + } *uap = (struct a*) u.u_arg; + register uid_t uid; - uid = uap->uid; - if (uid != u.u_ruid && ! suser()) - return; - /* - * Everything's okay, do it. - */ - u.u_procp->p_uid = uid; - u.u_uid = uid; - u.u_ruid = uid; - u.u_svuid = uid; - u.u_error = 0; + uid = uap->uid; + if (uid != u.u_ruid && ! suser()) + return; + /* + * Everything's okay, do it. + */ + u.u_procp->p_uid = uid; + u.u_uid = uid; + u.u_ruid = uid; + u.u_svuid = uid; + u.u_error = 0; } void seteuid() { - struct a { - uid_t euid; - } *uap = (struct a *)u.u_arg; - register uid_t euid; + struct a { + uid_t euid; + } *uap = (struct a *)u.u_arg; + register uid_t euid; - euid = uap->euid; - if (euid != u.u_ruid && euid != u.u_svuid && ! suser()) - return; - /* - * Everything's okay, do it. - */ - u.u_uid = euid; - u.u_error = 0; + euid = uap->euid; + if (euid != u.u_ruid && euid != u.u_svuid && ! suser()) + return; + /* + * Everything's okay, do it. + */ + u.u_uid = euid; + u.u_error = 0; } void setgid() { - struct a { - gid_t gid; - } *uap = (struct a *)u.u_arg; - register gid_t gid; + struct a { + gid_t gid; + } *uap = (struct a *)u.u_arg; + register gid_t gid; - gid = uap->gid; - if (gid != u.u_rgid && ! suser()) - return; + gid = uap->gid; + if (gid != u.u_rgid && ! suser()) + return; - u.u_groups[0] = gid; /* effective gid is u_groups[0] */ - u.u_rgid = gid; - u.u_svgid = gid; - u.u_error = 0; + u.u_groups[0] = gid; /* effective gid is u_groups[0] */ + u.u_rgid = gid; + u.u_svgid = gid; + u.u_error = 0; } void setegid() { - struct a { - gid_t egid; - } *uap = (struct a *)u.u_arg; - register gid_t egid; + struct a { + gid_t egid; + } *uap = (struct a *)u.u_arg; + register gid_t egid; - egid = uap->egid; - if (egid != u.u_rgid && egid != u.u_svgid && ! suser()) - return; + egid = uap->egid; + if (egid != u.u_rgid && egid != u.u_svgid && ! suser()) + return; - u.u_groups[0] = egid; - u.u_error = 0; + u.u_groups[0] = egid; + u.u_error = 0; } diff --git a/sys/kernel/kern_resource.c b/sys/kernel/kern_resource.c index 200af6d..707da9c 100644 --- a/sys/kernel/kern_resource.c +++ b/sys/kernel/kern_resource.c @@ -16,214 +16,214 @@ void getpriority() { - register struct a { - int which; - int who; - } *uap = (struct a *)u.u_arg; - register struct proc *p; - register int low = PRIO_MAX + 1; + register struct a { + int which; + int who; + } *uap = (struct a *)u.u_arg; + register struct proc *p; + register int low = PRIO_MAX + 1; - switch (uap->which) { - case PRIO_PROCESS: - if (uap->who == 0) - p = u.u_procp; - else - p = pfind(uap->who); - if (p == 0) - break; - low = p->p_nice; - break; - case PRIO_PGRP: - if (uap->who == 0) - uap->who = u.u_procp->p_pgrp; - for (p = allproc; p != NULL; p = p->p_nxt) { - if (p->p_pgrp == uap->who && - p->p_nice < low) - low = p->p_nice; - } - break; - case PRIO_USER: - if (uap->who == 0) - uap->who = u.u_uid; - for (p = allproc; p != NULL; p = p->p_nxt) { - if (p->p_uid == uap->who && - p->p_nice < low) - low = p->p_nice; - } - break; - default: - u.u_error = EINVAL; - return; - } - if (low == PRIO_MAX + 1) { - u.u_error = ESRCH; - return; - } - u.u_rval = low; + switch (uap->which) { + case PRIO_PROCESS: + if (uap->who == 0) + p = u.u_procp; + else + p = pfind(uap->who); + if (p == 0) + break; + low = p->p_nice; + break; + case PRIO_PGRP: + if (uap->who == 0) + uap->who = u.u_procp->p_pgrp; + for (p = allproc; p != NULL; p = p->p_nxt) { + if (p->p_pgrp == uap->who && + p->p_nice < low) + low = p->p_nice; + } + break; + case PRIO_USER: + if (uap->who == 0) + uap->who = u.u_uid; + for (p = allproc; p != NULL; p = p->p_nxt) { + if (p->p_uid == uap->who && + p->p_nice < low) + low = p->p_nice; + } + break; + default: + u.u_error = EINVAL; + return; + } + if (low == PRIO_MAX + 1) { + u.u_error = ESRCH; + return; + } + u.u_rval = low; } static void donice(p, n) - register struct proc *p; - register int n; + register struct proc *p; + register int n; { - if (u.u_uid && u.u_ruid && - u.u_uid != p->p_uid && u.u_ruid != p->p_uid) { - u.u_error = EPERM; - return; - } - if (n > PRIO_MAX) - n = PRIO_MAX; - if (n < PRIO_MIN) - n = PRIO_MIN; - if (n < p->p_nice && !suser()) { - u.u_error = EACCES; - return; - } - p->p_nice = n; + if (u.u_uid && u.u_ruid && + u.u_uid != p->p_uid && u.u_ruid != p->p_uid) { + u.u_error = EPERM; + return; + } + if (n > PRIO_MAX) + n = PRIO_MAX; + if (n < PRIO_MIN) + n = PRIO_MIN; + if (n < p->p_nice && !suser()) { + u.u_error = EACCES; + return; + } + p->p_nice = n; } void setpriority() { - register struct a { - int which; - int who; - int prio; - } *uap = (struct a *)u.u_arg; - register struct proc *p; - register int found = 0; + register struct a { + int which; + int who; + int prio; + } *uap = (struct a *)u.u_arg; + register struct proc *p; + register int found = 0; - switch (uap->which) { - case PRIO_PROCESS: - if (uap->who == 0) - p = u.u_procp; - else - p = pfind(uap->who); - if (p == 0) - break; - donice(p, uap->prio); - found++; - break; - case PRIO_PGRP: - if (uap->who == 0) - uap->who = u.u_procp->p_pgrp; - for (p = allproc; p != NULL; p = p->p_nxt) - if (p->p_pgrp == uap->who) { - donice(p, uap->prio); - found++; - } - break; - case PRIO_USER: - if (uap->who == 0) - uap->who = u.u_uid; - for (p = allproc; p != NULL; p = p->p_nxt) - if (p->p_uid == uap->who) { - donice(p, uap->prio); - found++; - } - break; - default: - u.u_error = EINVAL; - return; - } - if (found == 0) - u.u_error = ESRCH; + switch (uap->which) { + case PRIO_PROCESS: + if (uap->who == 0) + p = u.u_procp; + else + p = pfind(uap->who); + if (p == 0) + break; + donice(p, uap->prio); + found++; + break; + case PRIO_PGRP: + if (uap->who == 0) + uap->who = u.u_procp->p_pgrp; + for (p = allproc; p != NULL; p = p->p_nxt) + if (p->p_pgrp == uap->who) { + donice(p, uap->prio); + found++; + } + break; + case PRIO_USER: + if (uap->who == 0) + uap->who = u.u_uid; + for (p = allproc; p != NULL; p = p->p_nxt) + if (p->p_uid == uap->who) { + donice(p, uap->prio); + found++; + } + break; + default: + u.u_error = EINVAL; + return; + } + if (found == 0) + u.u_error = ESRCH; } void setrlimit() { - register struct a { - u_int which; - struct rlimit *lim; - } *uap = (struct a *)u.u_arg; - struct rlimit alim; - register struct rlimit *alimp; + register struct a { + u_int which; + struct rlimit *lim; + } *uap = (struct a *)u.u_arg; + struct rlimit alim; + register struct rlimit *alimp; - if (uap->which >= RLIM_NLIMITS) { - u.u_error = EINVAL; - return; - } - alimp = &u.u_rlimit[uap->which]; - u.u_error = copyin((caddr_t)uap->lim, (caddr_t)&alim, - sizeof (struct rlimit)); - if (u.u_error) - return; - if (uap->which == RLIMIT_CPU) { - /* - * 2.11 stores RLIMIT_CPU as ticks to keep from making - * hardclock() do long multiplication/division. - */ - if (alim.rlim_cur >= RLIM_INFINITY / hz) - alim.rlim_cur = RLIM_INFINITY; - else - alim.rlim_cur = alim.rlim_cur * hz; - if (alim.rlim_max >= RLIM_INFINITY / hz) - alim.rlim_max = RLIM_INFINITY; - else - alim.rlim_max = alim.rlim_max * hz; - } - if (alim.rlim_cur > alimp->rlim_max || alim.rlim_max > alimp->rlim_max) - if (!suser()) - return; - *alimp = alim; + if (uap->which >= RLIM_NLIMITS) { + u.u_error = EINVAL; + return; + } + alimp = &u.u_rlimit[uap->which]; + u.u_error = copyin((caddr_t)uap->lim, (caddr_t)&alim, + sizeof (struct rlimit)); + if (u.u_error) + return; + if (uap->which == RLIMIT_CPU) { + /* + * 2.11 stores RLIMIT_CPU as ticks to keep from making + * hardclock() do long multiplication/division. + */ + if (alim.rlim_cur >= RLIM_INFINITY / hz) + alim.rlim_cur = RLIM_INFINITY; + else + alim.rlim_cur = alim.rlim_cur * hz; + if (alim.rlim_max >= RLIM_INFINITY / hz) + alim.rlim_max = RLIM_INFINITY; + else + alim.rlim_max = alim.rlim_max * hz; + } + if (alim.rlim_cur > alimp->rlim_max || alim.rlim_max > alimp->rlim_max) + if (!suser()) + return; + *alimp = alim; } void getrlimit() { - register struct a { - u_int which; - struct rlimit *rlp; - } *uap = (struct a *)u.u_arg; + register struct a { + u_int which; + struct rlimit *rlp; + } *uap = (struct a *)u.u_arg; - if (uap->which >= RLIM_NLIMITS) { - u.u_error = EINVAL; - return; - } - if (uap->which == RLIMIT_CPU) { - struct rlimit alim; + if (uap->which >= RLIM_NLIMITS) { + u.u_error = EINVAL; + return; + } + if (uap->which == RLIMIT_CPU) { + struct rlimit alim; - alim = u.u_rlimit[uap->which]; - if (alim.rlim_cur != RLIM_INFINITY) - alim.rlim_cur = alim.rlim_cur / hz; - if (alim.rlim_max != RLIM_INFINITY) - alim.rlim_max = alim.rlim_max / hz; - u.u_error = copyout((caddr_t)&alim, - (caddr_t)uap->rlp,sizeof (struct rlimit)); - } - else u.u_error = copyout((caddr_t)&u.u_rlimit[uap->which], - (caddr_t)uap->rlp,sizeof (struct rlimit)); + alim = u.u_rlimit[uap->which]; + if (alim.rlim_cur != RLIM_INFINITY) + alim.rlim_cur = alim.rlim_cur / hz; + if (alim.rlim_max != RLIM_INFINITY) + alim.rlim_max = alim.rlim_max / hz; + u.u_error = copyout((caddr_t)&alim, + (caddr_t)uap->rlp,sizeof (struct rlimit)); + } + else u.u_error = copyout((caddr_t)&u.u_rlimit[uap->which], + (caddr_t)uap->rlp,sizeof (struct rlimit)); } void getrusage() { - register struct a { - int who; - struct rusage *rusage; - } *uap = (struct a *)u.u_arg; - register struct k_rusage *rup; - struct rusage ru; + register struct a { + int who; + struct rusage *rusage; + } *uap = (struct a *)u.u_arg; + register struct k_rusage *rup; + struct rusage ru; - switch (uap->who) { + switch (uap->who) { - case RUSAGE_SELF: - rup = &u.u_ru; - break; + case RUSAGE_SELF: + rup = &u.u_ru; + break; - case RUSAGE_CHILDREN: - rup = &u.u_cru; - break; + case RUSAGE_CHILDREN: + rup = &u.u_cru; + break; - default: - u.u_error = EINVAL; - return; - } - rucvt(&ru,rup); - u.u_error = copyout((caddr_t)&ru, (caddr_t)uap->rusage, - sizeof (struct rusage)); + default: + u.u_error = EINVAL; + return; + } + rucvt(&ru,rup); + u.u_error = copyout((caddr_t)&ru, (caddr_t)uap->rusage, + sizeof (struct rusage)); } /* @@ -231,19 +231,19 @@ getrusage() */ void ruadd(ru, ru2) - struct k_rusage *ru, *ru2; + struct k_rusage *ru, *ru2; { - register long *ip, *ip2; - register int i; + register long *ip, *ip2; + register int i; - /* - * since the kernel timeval structures are single longs, - * fold them into the loop. - */ - ip = &ru->k_ru_first; - ip2 = &ru2->k_ru_first; - for (i = &ru->k_ru_last - &ru->k_ru_first; i >= 0; i--) - *ip++ += *ip2++; + /* + * since the kernel timeval structures are single longs, + * fold them into the loop. + */ + ip = &ru->k_ru_first; + ip2 = &ru2->k_ru_first; + for (i = &ru->k_ru_last - &ru->k_ru_first; i >= 0; i--) + *ip++ += *ip2++; } /* @@ -251,20 +251,20 @@ ruadd(ru, ru2) */ void rucvt (rup, krup) - register struct rusage *rup; - register struct k_rusage *krup; + register struct rusage *rup; + register struct k_rusage *krup; { - bzero((caddr_t)rup, sizeof(*rup)); - rup->ru_utime.tv_sec = krup->ru_utime / hz; - rup->ru_utime.tv_usec = (krup->ru_utime % hz) * usechz; - rup->ru_stime.tv_sec = krup->ru_stime / hz; - rup->ru_stime.tv_usec = (krup->ru_stime % hz) * usechz; - rup->ru_nswap = krup->ru_nswap; - rup->ru_inblock = krup->ru_inblock; - rup->ru_oublock = krup->ru_oublock; - rup->ru_msgsnd = krup->ru_msgsnd; - rup->ru_msgrcv = krup->ru_msgrcv; - rup->ru_nsignals = krup->ru_nsignals; - rup->ru_nvcsw = krup->ru_nvcsw; - rup->ru_nivcsw = krup->ru_nivcsw; + bzero((caddr_t)rup, sizeof(*rup)); + rup->ru_utime.tv_sec = krup->ru_utime / hz; + rup->ru_utime.tv_usec = (krup->ru_utime % hz) * usechz; + rup->ru_stime.tv_sec = krup->ru_stime / hz; + rup->ru_stime.tv_usec = (krup->ru_stime % hz) * usechz; + rup->ru_nswap = krup->ru_nswap; + rup->ru_inblock = krup->ru_inblock; + rup->ru_oublock = krup->ru_oublock; + rup->ru_msgsnd = krup->ru_msgsnd; + rup->ru_msgrcv = krup->ru_msgrcv; + rup->ru_nsignals = krup->ru_nsignals; + rup->ru_nvcsw = krup->ru_nvcsw; + rup->ru_nivcsw = krup->ru_nivcsw; } diff --git a/sys/kernel/kern_sig.c b/sys/kernel/kern_sig.c index 34b19a5..0d52cbd 100644 --- a/sys/kernel/kern_sig.c +++ b/sys/kernel/kern_sig.c @@ -29,21 +29,21 @@ */ static int cansignal (q, signum) - register struct proc *q; - int signum; + register struct proc *q; + int signum; { - register struct proc *curp = u.u_procp; - uid_t ruid; + register struct proc *curp = u.u_procp; + uid_t ruid; - fill_from_u(q, &ruid, NULL, NULL); /* XXX */ - if (curp->p_uid == 0 || /* c effective root */ - u.u_ruid == ruid || /* c real = t real */ - curp->p_uid == ruid || /* c effective = t real */ - u.u_ruid == q->p_uid || /* c real = t effective */ - curp->p_uid == q->p_uid || /* c effective = t effective */ - (signum == SIGCONT && inferior(q))) - return(1); - return(0); + fill_from_u(q, &ruid, NULL, NULL); /* XXX */ + if (curp->p_uid == 0 || /* c effective root */ + u.u_ruid == ruid || /* c real = t real */ + curp->p_uid == ruid || /* c effective = t real */ + u.u_ruid == q->p_uid || /* c real = t effective */ + curp->p_uid == q->p_uid || /* c effective = t effective */ + (signum == SIGCONT && inferior(q))) + return(1); + return(0); } /* @@ -52,127 +52,127 @@ cansignal (q, signum) void sigstack() { - register struct a { - struct sigstack *nss; - struct sigstack *oss; - } *uap = (struct a*) u.u_arg; - struct sigstack ss; - register int error = 0; + register struct a { + struct sigstack *nss; + struct sigstack *oss; + } *uap = (struct a*) u.u_arg; + struct sigstack ss; + register int error = 0; - ss.ss_sp = u.u_sigstk.ss_base; - ss.ss_onstack = u.u_sigstk.ss_flags & SA_ONSTACK; - if(uap->oss && (error = copyout ((caddr_t) &ss, - (caddr_t) uap->oss, sizeof (ss)))) - goto out; - if (uap->nss && (error = copyin ((caddr_t) uap->nss, - (caddr_t) &ss, sizeof (ss))) == 0) { - u.u_sigstk.ss_base = ss.ss_sp; - u.u_sigstk.ss_size = 0; - u.u_sigstk.ss_flags |= (ss.ss_onstack & SA_ONSTACK); - u.u_psflags |= SAS_ALTSTACK; - } + ss.ss_sp = u.u_sigstk.ss_base; + ss.ss_onstack = u.u_sigstk.ss_flags & SA_ONSTACK; + if(uap->oss && (error = copyout ((caddr_t) &ss, + (caddr_t) uap->oss, sizeof (ss)))) + goto out; + if (uap->nss && (error = copyin ((caddr_t) uap->nss, + (caddr_t) &ss, sizeof (ss))) == 0) { + u.u_sigstk.ss_base = ss.ss_sp; + u.u_sigstk.ss_size = 0; + u.u_sigstk.ss_flags |= (ss.ss_onstack & SA_ONSTACK); + u.u_psflags |= SAS_ALTSTACK; + } out: - u.u_error = error; + u.u_error = error; } static int killpg1 (signo, pgrp, all) - int signo, pgrp, all; + int signo, pgrp, all; { - register struct proc *p; - int f, error = 0; + register struct proc *p; + int f, error = 0; - if (! all && pgrp == 0) { - /* - * Zero process id means send to my process group. - */ - pgrp = u.u_procp->p_pgrp; - if (pgrp == 0) - return (ESRCH); - } - for (f = 0, p = allproc; p != NULL; p = p->p_nxt) { - if ((p->p_pgrp != pgrp && !all) || p->p_ppid == 0 || - (p->p_flag&SSYS) || (all && p == u.u_procp)) - continue; - if (! cansignal (p, signo)) { - if (!all) - error = EPERM; - continue; - } - f++; - if (signo) - psignal(p, signo); - } - return (error ? error : (f == 0 ? ESRCH : 0)); + if (! all && pgrp == 0) { + /* + * Zero process id means send to my process group. + */ + pgrp = u.u_procp->p_pgrp; + if (pgrp == 0) + return (ESRCH); + } + for (f = 0, p = allproc; p != NULL; p = p->p_nxt) { + if ((p->p_pgrp != pgrp && !all) || p->p_ppid == 0 || + (p->p_flag&SSYS) || (all && p == u.u_procp)) + continue; + if (! cansignal (p, signo)) { + if (!all) + error = EPERM; + continue; + } + f++; + if (signo) + psignal(p, signo); + } + return (error ? error : (f == 0 ? ESRCH : 0)); } void kill() { - register struct a { - int pid; - int signo; - } *uap = (struct a *)u.u_arg; - register struct proc *p; - register int error = 0; + register struct a { + int pid; + int signo; + } *uap = (struct a *)u.u_arg; + register struct proc *p; + register int error = 0; - /* - * BSD4.3 botches the comparison against NSIG - it's a good thing for - * them psignal catches the error - however, since psignal is the - * kernel's internel signal mechanism and *should be getting correct - * parameters from the rest of the kernel, psignal shouldn't *have* - * to check it's parameters for validity. If you feel differently, - * feel free to clutter up the entire inner kernel with parameter - * checks - start with postsig ... - */ - if (uap->signo < 0 || uap->signo >= NSIG) { - error = EINVAL; - goto out; - } - if (uap->pid > 0) { - /* kill single process */ - p = pfind(uap->pid); - if (p == 0) { - error = ESRCH; - goto out; - } - if (! cansignal (p, uap->signo)) - error = EPERM; - else if (uap->signo) - psignal (p, uap->signo); - goto out; - } - switch (uap->pid) { - case -1: /* broadcast signal */ - error = killpg1 (uap->signo, 0, 1); - break; - case 0: /* signal own process group */ - error = killpg1 (uap->signo, 0, 0); - break; - default: /* negative explicit process group */ - error = killpg1 (uap->signo, -uap->pid, 0); - break; - } + /* + * BSD4.3 botches the comparison against NSIG - it's a good thing for + * them psignal catches the error - however, since psignal is the + * kernel's internel signal mechanism and *should be getting correct + * parameters from the rest of the kernel, psignal shouldn't *have* + * to check it's parameters for validity. If you feel differently, + * feel free to clutter up the entire inner kernel with parameter + * checks - start with postsig ... + */ + if (uap->signo < 0 || uap->signo >= NSIG) { + error = EINVAL; + goto out; + } + if (uap->pid > 0) { + /* kill single process */ + p = pfind(uap->pid); + if (p == 0) { + error = ESRCH; + goto out; + } + if (! cansignal (p, uap->signo)) + error = EPERM; + else if (uap->signo) + psignal (p, uap->signo); + goto out; + } + switch (uap->pid) { + case -1: /* broadcast signal */ + error = killpg1 (uap->signo, 0, 1); + break; + case 0: /* signal own process group */ + error = killpg1 (uap->signo, 0, 0); + break; + default: /* negative explicit process group */ + error = killpg1 (uap->signo, -uap->pid, 0); + break; + } out: - u.u_error = error; + u.u_error = error; } void killpg() { - register struct a { - int pgrp; - int signo; - } *uap = (struct a *)u.u_arg; - register int error = 0; + register struct a { + int pgrp; + int signo; + } *uap = (struct a *)u.u_arg; + register int error = 0; - if (uap->signo < 0 || uap->signo >= NSIG) { - error = EINVAL; - goto out; - } - error = killpg1 (uap->signo, uap->pgrp, 0); + if (uap->signo < 0 || uap->signo >= NSIG) { + error = EINVAL; + goto out; + } + error = killpg1 (uap->signo, uap->pgrp, 0); out: - u.u_error = error; + u.u_error = error; } /* @@ -182,11 +182,11 @@ out: */ void stop(p) - register struct proc *p; + register struct proc *p; { - p->p_stat = SSTOP; - p->p_flag &= ~P_WAITED; - wakeup((caddr_t)p->p_pptr); + p->p_stat = SSTOP; + p->p_flag &= ~P_WAITED; + wakeup((caddr_t)p->p_pptr); } /* @@ -196,16 +196,16 @@ stop(p) */ void gsignal (pgrp, sig) - register int pgrp; + register int pgrp; { - register struct proc *p; + register struct proc *p; - if (pgrp == 0) - return; + if (pgrp == 0) + return; - for (p = allproc; p != NULL; p = p->p_nxt) - if (p->p_pgrp == pgrp) - psignal(p, sig); + for (p = allproc; p != NULL; p = p->p_nxt) + if (p->p_pgrp == pgrp) + psignal(p, sig); } /* @@ -214,181 +214,181 @@ gsignal (pgrp, sig) */ void psignal(p, sig) - register struct proc *p; - register int sig; + register struct proc *p; + register int sig; { - register int s; - sig_t action; - int prop; - long mask; + register int s; + sig_t action; + int prop; + long mask; - mask = sigmask(sig); - prop = sigprop[sig]; + mask = sigmask(sig); + prop = sigprop[sig]; - /* - * If proc is traced, always give parent a chance. - */ - if (p->p_flag & P_TRACED) - action = SIG_DFL; - else { - /* - * If the signal is being ignored, - * then we forget about it immediately. - */ - if (p->p_sigignore & mask) - return; - if (p->p_sigmask & mask) - action = SIG_HOLD; - else if (p->p_sigcatch & mask) - action = SIG_CATCH; - else - action = SIG_DFL; - } + /* + * If proc is traced, always give parent a chance. + */ + if (p->p_flag & P_TRACED) + action = SIG_DFL; + else { + /* + * If the signal is being ignored, + * then we forget about it immediately. + */ + if (p->p_sigignore & mask) + return; + if (p->p_sigmask & mask) + action = SIG_HOLD; + else if (p->p_sigcatch & mask) + action = SIG_CATCH; + else + action = SIG_DFL; + } - if (p->p_nice > NZERO && action == SIG_DFL && (prop & SA_KILL) && - (p->p_flag & P_TRACED) == 0) - p->p_nice = NZERO; + if (p->p_nice > NZERO && action == SIG_DFL && (prop & SA_KILL) && + (p->p_flag & P_TRACED) == 0) + p->p_nice = NZERO; - if (prop & SA_CONT) - p->p_sig &= ~stopsigmask; + if (prop & SA_CONT) + p->p_sig &= ~stopsigmask; - if (prop & SA_STOP) { - /* - * If sending a tty stop signal to a member of an orphaned - * process group (i.e. a child of init), discard the signal - * here if the action is default; don't stop the process - * below if sleeping, and don't clear any pending SIGCONT. - */ - if ((prop & SA_TTYSTOP) && (p->p_pptr == &proc[1]) && - action == SIG_DFL) - return; - p->p_sig &= ~contsigmask; - } - p->p_sig |= mask; + if (prop & SA_STOP) { + /* + * If sending a tty stop signal to a member of an orphaned + * process group (i.e. a child of init), discard the signal + * here if the action is default; don't stop the process + * below if sleeping, and don't clear any pending SIGCONT. + */ + if ((prop & SA_TTYSTOP) && (p->p_pptr == &proc[1]) && + action == SIG_DFL) + return; + p->p_sig &= ~contsigmask; + } + p->p_sig |= mask; - /* - * Defer further processing for signals which are held. - */ - if (action == SIG_HOLD && ((prop & SA_CONT) == 0 || p->p_stat != SSTOP)) - return; - s = splhigh(); - switch (p->p_stat) { + /* + * Defer further processing for signals which are held. + */ + if (action == SIG_HOLD && ((prop & SA_CONT) == 0 || p->p_stat != SSTOP)) + return; + s = splhigh(); + switch (p->p_stat) { - case SSLEEP: - /* - * If process is sleeping uninterruptibly we can not - * interrupt the sleep... the signal will be noticed - * when the process returns through trap() or syscall(). - */ - if ((p->p_flag & P_SINTR) == 0) - goto out; - /* - * Process is sleeping and traced... make it runnable - * so it can discover the signal in issignal() and stop - * for the parent. - */ - if (p->p_flag & P_TRACED) - goto run; + case SSLEEP: + /* + * If process is sleeping uninterruptibly we can not + * interrupt the sleep... the signal will be noticed + * when the process returns through trap() or syscall(). + */ + if ((p->p_flag & P_SINTR) == 0) + goto out; + /* + * Process is sleeping and traced... make it runnable + * so it can discover the signal in issignal() and stop + * for the parent. + */ + if (p->p_flag & P_TRACED) + goto run; - /* - * If SIGCONT is default (or ignored) and process is - * asleep, we are finished; the process should not - * be awakened. - */ - if ((prop & SA_CONT) && action == SIG_DFL) { - p->p_sig &= ~mask; - goto out; - } - /* - * When a sleeping process receives a stop - * signal, process immediately if possible. - * All other (caught or default) signals - * cause the process to run. - */ - if (prop & SA_STOP) { - if (action != SIG_DFL) - goto run; - /* - * If a child holding parent blocked, - * stopping could cause deadlock. - */ - if (p->p_flag & SVFORK) - goto out; - p->p_sig &= ~mask; - p->p_ptracesig = sig; - if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0) - psignal(p->p_pptr, SIGCHLD); - stop(p); - goto out; - } else - goto run; - /*NOTREACHED*/ - case SSTOP: - /* - * If traced process is already stopped, - * then no further action is necessary. - */ - if (p->p_flag & P_TRACED) - goto out; - if (sig == SIGKILL) - goto run; - if (prop & SA_CONT) { - /* - * If SIGCONT is default (or ignored), we continue the - * process but don't leave the signal in p_sig, as - * it has no further action. If SIGCONT is held, we - * continue the process and leave the signal in - * p_sig. If the process catches SIGCONT, let it - * handle the signal itself. If it isn't waiting on - * an event, then it goes back to run state. - * Otherwise, process goes back to sleep state. - */ - if (action == SIG_DFL) - p->p_sig &= ~mask; - if (action == SIG_CATCH || p->p_wchan == 0) - goto run; - p->p_stat = SSLEEP; - goto out; - } + /* + * If SIGCONT is default (or ignored) and process is + * asleep, we are finished; the process should not + * be awakened. + */ + if ((prop & SA_CONT) && action == SIG_DFL) { + p->p_sig &= ~mask; + goto out; + } + /* + * When a sleeping process receives a stop + * signal, process immediately if possible. + * All other (caught or default) signals + * cause the process to run. + */ + if (prop & SA_STOP) { + if (action != SIG_DFL) + goto run; + /* + * If a child holding parent blocked, + * stopping could cause deadlock. + */ + if (p->p_flag & SVFORK) + goto out; + p->p_sig &= ~mask; + p->p_ptracesig = sig; + if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0) + psignal(p->p_pptr, SIGCHLD); + stop(p); + goto out; + } else + goto run; + /*NOTREACHED*/ + case SSTOP: + /* + * If traced process is already stopped, + * then no further action is necessary. + */ + if (p->p_flag & P_TRACED) + goto out; + if (sig == SIGKILL) + goto run; + if (prop & SA_CONT) { + /* + * If SIGCONT is default (or ignored), we continue the + * process but don't leave the signal in p_sig, as + * it has no further action. If SIGCONT is held, we + * continue the process and leave the signal in + * p_sig. If the process catches SIGCONT, let it + * handle the signal itself. If it isn't waiting on + * an event, then it goes back to run state. + * Otherwise, process goes back to sleep state. + */ + if (action == SIG_DFL) + p->p_sig &= ~mask; + if (action == SIG_CATCH || p->p_wchan == 0) + goto run; + p->p_stat = SSLEEP; + goto out; + } - if (prop & SA_STOP) { - /* - * Already stopped, don't need to stop again. - * (If we did the shell could get confused.) - */ - p->p_sig &= ~mask; /* take it away */ - goto out; - } + if (prop & SA_STOP) { + /* + * Already stopped, don't need to stop again. + * (If we did the shell could get confused.) + */ + p->p_sig &= ~mask; /* take it away */ + goto out; + } - /* - * If process is sleeping interruptibly, then simulate a - * wakeup so that when it is continued, it will be made - * runnable and can look at the signal. But don't make - * the process runnable, leave it stopped. - */ - if (p->p_wchan && (p->p_flag & P_SINTR)) - unsleep(p); - goto out; - /*NOTREACHED*/ + /* + * If process is sleeping interruptibly, then simulate a + * wakeup so that when it is continued, it will be made + * runnable and can look at the signal. But don't make + * the process runnable, leave it stopped. + */ + if (p->p_wchan && (p->p_flag & P_SINTR)) + unsleep(p); + goto out; + /*NOTREACHED*/ - default: - /* - * SRUN, SIDL, SZOMB do nothing with the signal, - * other than kicking ourselves if we are running. - * It will either never be noticed, or noticed very soon. - */ - goto out; - } - /*NOTREACHED*/ + default: + /* + * SRUN, SIDL, SZOMB do nothing with the signal, + * other than kicking ourselves if we are running. + * It will either never be noticed, or noticed very soon. + */ + goto out; + } + /*NOTREACHED*/ run: - /* - * Raise priority to at least PUSER. - */ - if (p->p_pri > PUSER) - p->p_pri = PUSER; - setrun(p); + /* + * Raise priority to at least PUSER. + */ + if (p->p_pri > PUSER) + p->p_pri = PUSER; + setrun(p); out: - splx(s); + splx(s); } /* @@ -400,148 +400,148 @@ out: * can usually be done without calling issignal by checking the pending * signals masks in CURSIG)/ The normal sequence is: * - * while (signum = CURSIG(u.u_procp)) - * postsig(signum); + * while (signum = CURSIG(u.u_procp)) + * postsig(signum); */ int issignal (p) - register struct proc *p; + register struct proc *p; { - register int sig; - long mask; - int prop; + register int sig; + long mask; + int prop; - for (;;) { - mask = p->p_sig & ~p->p_sigmask; - if (p->p_flag&SVFORK) - mask &= ~stopsigmask; - if (mask == 0) - return(0); /* No signals to send */ - sig = ffs(mask); - mask = sigmask(sig); - prop = sigprop[sig]; - /* - * We should see pending but ignored signals - * only if P_TRACED was on when they were posted. - */ - if ((mask & p->p_sigignore) && ! (p->p_flag & P_TRACED)) { - p->p_sig &= ~mask; - continue; - } - if ((p->p_flag & P_TRACED) && ! (p->p_flag & SVFORK)) { - /* - * If traced, always stop, and stay - * stopped until released by the parent. - * - * Note that we must clear the pending signal - * before we call procxmt since that routine - * might cause a fault, calling sleep and - * leading us back here again with the same signal. - * Then we would be deadlocked because the tracer - * would still be blocked on the ipc struct from - * the initial request. - */ - p->p_sig &= ~mask; - p->p_ptracesig = sig; - psignal(p->p_pptr, SIGCHLD); - do { - stop(p); - swtch(); - } while (! procxmt() && (p->p_flag & P_TRACED)); + for (;;) { + mask = p->p_sig & ~p->p_sigmask; + if (p->p_flag&SVFORK) + mask &= ~stopsigmask; + if (mask == 0) + return(0); /* No signals to send */ + sig = ffs(mask); + mask = sigmask(sig); + prop = sigprop[sig]; + /* + * We should see pending but ignored signals + * only if P_TRACED was on when they were posted. + */ + if ((mask & p->p_sigignore) && ! (p->p_flag & P_TRACED)) { + p->p_sig &= ~mask; + continue; + } + if ((p->p_flag & P_TRACED) && ! (p->p_flag & SVFORK)) { + /* + * If traced, always stop, and stay + * stopped until released by the parent. + * + * Note that we must clear the pending signal + * before we call procxmt since that routine + * might cause a fault, calling sleep and + * leading us back here again with the same signal. + * Then we would be deadlocked because the tracer + * would still be blocked on the ipc struct from + * the initial request. + */ + p->p_sig &= ~mask; + p->p_ptracesig = sig; + psignal(p->p_pptr, SIGCHLD); + do { + stop(p); + swtch(); + } while (! procxmt() && (p->p_flag & P_TRACED)); - /* - * If parent wants us to take the signal, - * then it will leave it in p->p_ptracesig; - * otherwise we just look for signals again. - */ - sig = p->p_ptracesig; - if (sig == 0) - continue; + /* + * If parent wants us to take the signal, + * then it will leave it in p->p_ptracesig; + * otherwise we just look for signals again. + */ + sig = p->p_ptracesig; + if (sig == 0) + continue; - /* - * Put the new signal into p_sig. If the - * signal is being masked, look for other signals. - */ - mask = sigmask(sig); - p->p_sig |= mask; - if (p->p_sigmask & mask) - continue; + /* + * Put the new signal into p_sig. If the + * signal is being masked, look for other signals. + */ + mask = sigmask(sig); + p->p_sig |= mask; + if (p->p_sigmask & mask) + continue; - /* - * If the traced bit got turned off, go back up - * to the top to rescan signals. This ensures - * that p_sig* and u_signal are consistent. - */ - if ((p->p_flag& P_TRACED) == 0) - continue; - prop = sigprop[sig]; - } + /* + * If the traced bit got turned off, go back up + * to the top to rescan signals. This ensures + * that p_sig* and u_signal are consistent. + */ + if ((p->p_flag& P_TRACED) == 0) + continue; + prop = sigprop[sig]; + } - switch ((int)u.u_signal[sig]) { + switch ((int)u.u_signal[sig]) { - case (int)SIG_DFL: - /* - * Don't take default actions on system processes. - */ - if (p->p_pid <= 1) { + case (int)SIG_DFL: + /* + * Don't take default actions on system processes. + */ + if (p->p_pid <= 1) { #ifdef DIAGNOSTIC - /* - * Are you sure you want to ignore SIGSEGV - * in init? XXX - */ - printf("Process (pid %d) got signal %d\n", - p->p_pid, sig); + /* + * Are you sure you want to ignore SIGSEGV + * in init? XXX + */ + printf("Process (pid %d) got signal %d\n", + p->p_pid, sig); #endif - break; - } - /* - * If there is a pending stop signal to process - * with default action, stop here, - * then clear the signal. However, - * if process is member of an orphaned - * process group, ignore tty stop signals. - */ - if (prop & SA_STOP) { - if (p->p_flag & P_TRACED || - (p->p_pptr == &proc[1] && - prop & SA_TTYSTOP)) - break; /* == ignore */ - p->p_ptracesig = sig; - if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0) - psignal(p->p_pptr, SIGCHLD); - stop(p); - swtch(); - break; - } else if (prop & SA_IGNORE) { - /* - * Except for SIGCONT, shouldn't get here. - * Default action is to ignore; drop it. - */ - break; /* == ignore */ - } else - return(sig); - /*NOTREACHED*/ + break; + } + /* + * If there is a pending stop signal to process + * with default action, stop here, + * then clear the signal. However, + * if process is member of an orphaned + * process group, ignore tty stop signals. + */ + if (prop & SA_STOP) { + if (p->p_flag & P_TRACED || + (p->p_pptr == &proc[1] && + prop & SA_TTYSTOP)) + break; /* == ignore */ + p->p_ptracesig = sig; + if ((p->p_pptr->p_flag & P_NOCLDSTOP) == 0) + psignal(p->p_pptr, SIGCHLD); + stop(p); + swtch(); + break; + } else if (prop & SA_IGNORE) { + /* + * Except for SIGCONT, shouldn't get here. + * Default action is to ignore; drop it. + */ + break; /* == ignore */ + } else + return(sig); + /*NOTREACHED*/ - case (int)SIG_IGN: - /* - * Masking above should prevent us - * ever trying to take action on a held - * or ignored signal, unless process is traced. - */ - if ((prop & SA_CONT) == 0 && - (p->p_flag & P_TRACED) == 0) - printf("issig\n"); - break; /* == ignore */ + case (int)SIG_IGN: + /* + * Masking above should prevent us + * ever trying to take action on a held + * or ignored signal, unless process is traced. + */ + if ((prop & SA_CONT) == 0 && + (p->p_flag & P_TRACED) == 0) + printf("issig\n"); + break; /* == ignore */ - default: - /* - * This signal has an action, let postsig process it. - */ - return(sig); - } - p->p_sig &= ~mask; /* take the signal away! */ - } - /* NOTREACHED */ + default: + /* + * This signal has an action, let postsig process it. + */ + return(sig); + } + p->p_sig &= ~mask; /* take the signal away! */ + } + /* NOTREACHED */ } /* @@ -557,60 +557,60 @@ issignal (p) static int core() { - register struct inode *ip; - struct nameidata nd; - register struct nameidata *ndp = &nd; - register char *np; - char *cp, name[MAXCOMLEN + 6]; + register struct inode *ip; + struct nameidata nd; + register struct nameidata *ndp = &nd; + register char *np; + char *cp, name[MAXCOMLEN + 6]; - /* - * Don't dump if not root. - */ - if (! suser()) - return(0); - if (USIZE + u.u_dsize + u.u_ssize >= u.u_rlimit[RLIMIT_CORE].rlim_cur) - return (0); - cp = u.u_comm; - np = name; - while ((*np++ = *cp++)) - ; - cp = ".core"; - np--; - while ((*np++ = *cp++)) - ; - u.u_error = 0; - NDINIT (ndp, CREATE, FOLLOW, name); - ip = namei(ndp); - if (ip == NULL) { - if (u.u_error) - return (0); - ip = maknode (0644, ndp); - if (ip==NULL) - return (0); - } - if (access(ip, IWRITE) || - (ip->i_mode&IFMT) != IFREG || - ip->i_nlink != 1) { - u.u_error = EFAULT; - goto out; - } - itrunc(ip, (u_long)0, 0); - u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) &u, - USIZE, (off_t) 0, IO_UNIT, (int*) 0); - if (u.u_error) - goto out; + /* + * Don't dump if not root. + */ + if (! suser()) + return(0); + if (USIZE + u.u_dsize + u.u_ssize >= u.u_rlimit[RLIMIT_CORE].rlim_cur) + return (0); + cp = u.u_comm; + np = name; + while ((*np++ = *cp++)) + ; + cp = ".core"; + np--; + while ((*np++ = *cp++)) + ; + u.u_error = 0; + NDINIT (ndp, CREATE, FOLLOW, name); + ip = namei(ndp); + if (ip == NULL) { + if (u.u_error) + return (0); + ip = maknode (0644, ndp); + if (ip==NULL) + return (0); + } + if (access(ip, IWRITE) || + (ip->i_mode&IFMT) != IFREG || + ip->i_nlink != 1) { + u.u_error = EFAULT; + goto out; + } + itrunc(ip, (u_long)0, 0); + u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) &u, + USIZE, (off_t) 0, IO_UNIT, (int*) 0); + if (u.u_error) + goto out; - u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) USER_DATA_START, - u.u_dsize, (off_t) USIZE, IO_UNIT, (int*) 0); - if (u.u_error) - goto out; + u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) USER_DATA_START, + u.u_dsize, (off_t) USIZE, IO_UNIT, (int*) 0); + if (u.u_error) + goto out; - u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) USER_DATA_END - u.u_ssize, - u.u_ssize, (off_t) USIZE + u.u_dsize, - IO_UNIT, (int*) 0); + u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) USER_DATA_END - u.u_ssize, + u.u_ssize, (off_t) USIZE + u.u_dsize, + IO_UNIT, (int*) 0); out: - iput(ip); - return (u.u_error == 0); + iput(ip); + return (u.u_error == 0); } /* @@ -619,48 +619,48 @@ out: */ void postsig(sig) - int sig; + int sig; { - register struct proc *p = u.u_procp; - long mask = sigmask(sig), returnmask; - register sig_t action; + register struct proc *p = u.u_procp; + long mask = sigmask(sig), returnmask; + register sig_t action; - p->p_sig &= ~mask; - action = u.u_signal[sig]; + p->p_sig &= ~mask; + action = u.u_signal[sig]; - if (action != SIG_DFL) { + if (action != SIG_DFL) { #ifdef DIAGNOSTIC - if (action == SIG_IGN || (p->p_sigmask & mask)) - panic("postsig action"); + if (action == SIG_IGN || (p->p_sigmask & mask)) + panic("postsig action"); #endif - u.u_error = 0; /* XXX - why? */ - /* - * Set the new mask value and also defer further - * occurences of this signal. - * - * Special case: user has done a sigsuspend. Here the - * current mask is not of interest, but rather the - * mask from before the sigsuspend is what we want restored - * after the signal processing is completed. - */ - (void) splhigh(); - if (u.u_psflags & SAS_OLDMASK) { - returnmask = u.u_oldmask; - u.u_psflags &= ~SAS_OLDMASK; - } else - returnmask = p->p_sigmask; - p->p_sigmask |= u.u_sigmask[sig] | mask; - (void) spl0(); - u.u_ru.ru_nsignals++; - sendsig(action, sig, returnmask); - return; - } - if (sigprop[sig] & SA_CORE) { - u.u_arg[0] = sig; - if (core()) - sig |= 0200; - } - exit(sig); + u.u_error = 0; /* XXX - why? */ + /* + * Set the new mask value and also defer further + * occurences of this signal. + * + * Special case: user has done a sigsuspend. Here the + * current mask is not of interest, but rather the + * mask from before the sigsuspend is what we want restored + * after the signal processing is completed. + */ + (void) splhigh(); + if (u.u_psflags & SAS_OLDMASK) { + returnmask = u.u_oldmask; + u.u_psflags &= ~SAS_OLDMASK; + } else + returnmask = p->p_sigmask; + p->p_sigmask |= u.u_sigmask[sig] | mask; + (void) spl0(); + u.u_ru.ru_nsignals++; + sendsig(action, sig, returnmask); + return; + } + if (sigprop[sig] & SA_CORE) { + u.u_arg[0] = sig; + if (core()) + sig |= 0200; + } + exit(sig); } /* @@ -672,30 +672,30 @@ postsig(sig) void execsigs(register struct proc *p) { - register int nc; - unsigned long mask; + register int nc; + unsigned long mask; - /* - * Reset caught signals. Held signals remain held - * through p_sigmask (unless they were caught, - * and are now ignored by default). - */ - while (p->p_sigcatch) { - nc = ffs(p->p_sigcatch); - mask = sigmask(nc); - p->p_sigcatch &= ~mask; - if (sigprop[nc] & SA_IGNORE) { - if (nc != SIGCONT) - p->p_sigignore |= mask; - p->p_sig &= ~mask; - } - u.u_signal[nc] = SIG_DFL; - } - /* - * Reset stack state to the user stack (disable the alternate stack). - */ - u.u_sigstk.ss_flags = SA_DISABLE; - u.u_sigstk.ss_size = 0; - u.u_sigstk.ss_base = 0; - u.u_psflags = 0; + /* + * Reset caught signals. Held signals remain held + * through p_sigmask (unless they were caught, + * and are now ignored by default). + */ + while (p->p_sigcatch) { + nc = ffs(p->p_sigcatch); + mask = sigmask(nc); + p->p_sigcatch &= ~mask; + if (sigprop[nc] & SA_IGNORE) { + if (nc != SIGCONT) + p->p_sigignore |= mask; + p->p_sig &= ~mask; + } + u.u_signal[nc] = SIG_DFL; + } + /* + * Reset stack state to the user stack (disable the alternate stack). + */ + u.u_sigstk.ss_flags = SA_DISABLE; + u.u_sigstk.ss_size = 0; + u.u_sigstk.ss_base = 0; + u.u_psflags = 0; } diff --git a/sys/kernel/kern_sig2.c b/sys/kernel/kern_sig2.c index a4801f8..334d8ee 100644 --- a/sys/kernel/kern_sig2.c +++ b/sys/kernel/kern_sig2.c @@ -1,6 +1,6 @@ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -43,7 +43,7 @@ * overlay structure. A smaller kern_sig2.c fits more easily into an overlaid * kernel. */ -#define SIGPROP /* include signal properties table */ +#define SIGPROP /* include signal properties table */ #include #include #include @@ -54,109 +54,109 @@ #include #include #include -#include /* for coredump */ +#include /* for coredump */ static void setsigvec(signum, sa) - int signum; - register struct sigaction *sa; + int signum; + register struct sigaction *sa; { - unsigned long bit; - register struct proc *p = u.u_procp; + unsigned long bit; + register struct proc *p = u.u_procp; - bit = sigmask(signum); - /* - * Change setting atomically. - */ - (void) splhigh(); - u.u_signal[signum] = sa->sa_handler; - u.u_sigmask[signum] = sa->sa_mask &~ sigcantmask; - if ((sa->sa_flags & SA_RESTART) == 0) - u.u_sigintr |= bit; - else - u.u_sigintr &= ~bit; - if (sa->sa_flags & SA_ONSTACK) - u.u_sigonstack |= bit; - else - u.u_sigonstack &= ~bit; - if (signum == SIGCHLD) { - if (sa->sa_flags & SA_NOCLDSTOP) - p->p_flag |= P_NOCLDSTOP; - else - p->p_flag &= ~P_NOCLDSTOP; - } - /* - * Set bit in p_sigignore for signals that are set to SIG_IGN, - * and for signals set to SIG_DFL where the default is to ignore. - * However, don't put SIGCONT in p_sigignore, - * as we have to restart the process. - */ - if (sa->sa_handler == SIG_IGN || - (sigprop[signum] & SA_IGNORE && sa->sa_handler == SIG_DFL)) { - p->p_sig &= ~bit; /* never to be seen again */ - if (signum != SIGCONT) - p->p_sigignore |= bit; /* easier in psignal */ - p->p_sigcatch &= ~bit; - } else { - p->p_sigignore &= ~bit; - if (sa->sa_handler == SIG_DFL) - p->p_sigcatch &= ~bit; - else - p->p_sigcatch |= bit; - } - (void) spl0(); + bit = sigmask(signum); + /* + * Change setting atomically. + */ + (void) splhigh(); + u.u_signal[signum] = sa->sa_handler; + u.u_sigmask[signum] = sa->sa_mask &~ sigcantmask; + if ((sa->sa_flags & SA_RESTART) == 0) + u.u_sigintr |= bit; + else + u.u_sigintr &= ~bit; + if (sa->sa_flags & SA_ONSTACK) + u.u_sigonstack |= bit; + else + u.u_sigonstack &= ~bit; + if (signum == SIGCHLD) { + if (sa->sa_flags & SA_NOCLDSTOP) + p->p_flag |= P_NOCLDSTOP; + else + p->p_flag &= ~P_NOCLDSTOP; + } + /* + * Set bit in p_sigignore for signals that are set to SIG_IGN, + * and for signals set to SIG_DFL where the default is to ignore. + * However, don't put SIGCONT in p_sigignore, + * as we have to restart the process. + */ + if (sa->sa_handler == SIG_IGN || + (sigprop[signum] & SA_IGNORE && sa->sa_handler == SIG_DFL)) { + p->p_sig &= ~bit; /* never to be seen again */ + if (signum != SIGCONT) + p->p_sigignore |= bit; /* easier in psignal */ + p->p_sigcatch &= ~bit; + } else { + p->p_sigignore &= ~bit; + if (sa->sa_handler == SIG_DFL) + p->p_sigcatch &= ~bit; + else + p->p_sigcatch |= bit; + } + (void) spl0(); } void sigaction() { - register struct a { - int signum; - struct sigaction *nsa; - struct sigaction *osa; - u_int sigtramp; - } *uap = (struct a *)u.u_arg; - struct sigaction vec; - register struct sigaction *sa; - register int signum; - u_long bit; - int error = 0; + register struct a { + int signum; + struct sigaction *nsa; + struct sigaction *osa; + u_int sigtramp; + } *uap = (struct a *)u.u_arg; + struct sigaction vec; + register struct sigaction *sa; + register int signum; + u_long bit; + int error = 0; - u.u_sigtramp = uap->sigtramp; /* save trampoline address */ + u.u_sigtramp = uap->sigtramp; /* save trampoline address */ - signum = uap->signum; - if (signum <= 0 || signum >= NSIG) { - error = EINVAL; - goto out; - } - if (uap->nsa && (signum == SIGKILL || signum == SIGSTOP)) { - error = EINVAL; - goto out; - } - sa = &vec; - if (uap->osa) { - sa->sa_handler = u.u_signal[signum]; - sa->sa_mask = u.u_sigmask[signum]; - bit = sigmask(signum); - sa->sa_flags = 0; - if ((u.u_sigonstack & bit) != 0) - sa->sa_flags |= SA_ONSTACK; - if ((u.u_sigintr & bit) == 0) - sa->sa_flags |= SA_RESTART; - if (u.u_procp->p_flag & P_NOCLDSTOP) - sa->sa_flags |= SA_NOCLDSTOP; - error = copyout ((caddr_t) sa, (caddr_t) uap->osa, sizeof(vec)); - if (error != 0) - goto out; - } - if (uap->nsa) { - error = copyin ((caddr_t) uap->nsa, (caddr_t) sa, sizeof(vec)); - if (error != 0) - goto out; - setsigvec(signum, sa); - } + signum = uap->signum; + if (signum <= 0 || signum >= NSIG) { + error = EINVAL; + goto out; + } + if (uap->nsa && (signum == SIGKILL || signum == SIGSTOP)) { + error = EINVAL; + goto out; + } + sa = &vec; + if (uap->osa) { + sa->sa_handler = u.u_signal[signum]; + sa->sa_mask = u.u_sigmask[signum]; + bit = sigmask(signum); + sa->sa_flags = 0; + if ((u.u_sigonstack & bit) != 0) + sa->sa_flags |= SA_ONSTACK; + if ((u.u_sigintr & bit) == 0) + sa->sa_flags |= SA_RESTART; + if (u.u_procp->p_flag & P_NOCLDSTOP) + sa->sa_flags |= SA_NOCLDSTOP; + error = copyout ((caddr_t) sa, (caddr_t) uap->osa, sizeof(vec)); + if (error != 0) + goto out; + } + if (uap->nsa) { + error = copyin ((caddr_t) uap->nsa, (caddr_t) sa, sizeof(vec)); + if (error != 0) + goto out; + setsigvec(signum, sa); + } out: - u.u_error = error; + u.u_error = error; } /* @@ -166,17 +166,17 @@ out: */ void fatalsig(signum) - int signum; + int signum; { - unsigned long mask; - register struct proc *p = u.u_procp; + unsigned long mask; + register struct proc *p = u.u_procp; - u.u_signal[signum] = SIG_DFL; - mask = sigmask(signum); - p->p_sigignore &= ~mask; - p->p_sigcatch &= ~mask; - p->p_sigmask &= ~mask; - psignal(p, signum); + u.u_signal[signum] = SIG_DFL; + mask = sigmask(signum); + p->p_sigignore &= ~mask; + p->p_sigcatch &= ~mask; + p->p_sigmask &= ~mask; + psignal(p, signum); } /* @@ -185,13 +185,13 @@ fatalsig(signum) */ void siginit(p) - register struct proc *p; + register struct proc *p; { - register int i; + register int i; - for (i = 0; i < NSIG; i++) - if (sigprop[i] & SA_IGNORE && i != SIGCONT) - p->p_sigignore |= sigmask(i); + for (i = 0; i < NSIG; i++) + if (sigprop[i] & SA_IGNORE && i != SIGCONT) + p->p_sigignore |= sigmask(i); } /* @@ -205,42 +205,42 @@ siginit(p) void sigprocmask() { - register struct a { - int how; - sigset_t *set; - sigset_t *oset; - } *uap = (struct a *)u.u_arg; - int error = 0; - sigset_t oldmask, newmask; - register struct proc *p = u.u_procp; + register struct a { + int how; + sigset_t *set; + sigset_t *oset; + } *uap = (struct a *)u.u_arg; + int error = 0; + sigset_t oldmask, newmask; + register struct proc *p = u.u_procp; - oldmask = p->p_sigmask; - if (! uap->set) /* No new mask, go possibly return old mask */ - goto out; - error = copyin ((caddr_t) uap->set, (caddr_t) &newmask, sizeof (newmask)); - if (error) - goto out; - (void) splhigh(); + oldmask = p->p_sigmask; + if (! uap->set) /* No new mask, go possibly return old mask */ + goto out; + error = copyin ((caddr_t) uap->set, (caddr_t) &newmask, sizeof (newmask)); + if (error) + goto out; + (void) splhigh(); - switch (uap->how) { - case SIG_BLOCK: - p->p_sigmask |= (newmask &~ sigcantmask); - break; - case SIG_UNBLOCK: - p->p_sigmask &= ~newmask; - break; - case SIG_SETMASK: - p->p_sigmask = newmask &~ sigcantmask; - break; - default: - error = EINVAL; - break; - } - (void) spl0(); + switch (uap->how) { + case SIG_BLOCK: + p->p_sigmask |= (newmask &~ sigcantmask); + break; + case SIG_UNBLOCK: + p->p_sigmask &= ~newmask; + break; + case SIG_SETMASK: + p->p_sigmask = newmask &~ sigcantmask; + break; + default: + error = EINVAL; + break; + } + (void) spl0(); out: - if (error == 0 && uap->oset) - error = copyout ((caddr_t) &oldmask, (caddr_t) uap->oset, sizeof (oldmask)); - u.u_error = error; + if (error == 0 && uap->oset) + error = copyout ((caddr_t) &oldmask, (caddr_t) uap->oset, sizeof (oldmask)); + u.u_error = error; } /* @@ -250,18 +250,18 @@ out: void sigpending() { - register struct a { - struct sigset_t *set; - } *uap = (struct a *)u.u_arg; - register int error = 0; - struct proc *p = u.u_procp; + register struct a { + struct sigset_t *set; + } *uap = (struct a *)u.u_arg; + register int error = 0; + struct proc *p = u.u_procp; - if (uap->set) - error = copyout((caddr_t)&p->p_sig, (caddr_t)uap->set, - sizeof (p->p_sig)); - else - error = EINVAL; - u.u_error = error; + if (uap->set) + error = copyout((caddr_t)&p->p_sig, (caddr_t)uap->set, + sizeof (p->p_sig)); + else + error = EINVAL; + u.u_error = error; } /* @@ -271,101 +271,101 @@ sigpending() void sigsuspend() { - register struct a { - struct sigset_t *set; - } *uap = (struct a *)u.u_arg; - sigset_t nmask = 0; - struct proc *p = u.u_procp; - int error; + register struct a { + struct sigset_t *set; + } *uap = (struct a *)u.u_arg; + sigset_t nmask = 0; + struct proc *p = u.u_procp; + int error; - if (uap->set && (error = copyin ((caddr_t) uap->set, (caddr_t) &nmask, sizeof (nmask)))) - nmask = 0; - /* - * When returning from sigsuspend, we want the old mask to be restored - * after the signal handler has finished. Thus, we save it here and set - * a flag to indicate this. - */ - u.u_oldmask = p->p_sigmask; - u.u_psflags |= SAS_OLDMASK; - p->p_sigmask = nmask &~ sigcantmask; - while (tsleep((caddr_t)&u, PPAUSE|PCATCH, 0) == 0) - ; - /* always return EINTR rather than ERESTART */ - u.u_error = EINTR; + if (uap->set && (error = copyin ((caddr_t) uap->set, (caddr_t) &nmask, sizeof (nmask)))) + nmask = 0; + /* + * When returning from sigsuspend, we want the old mask to be restored + * after the signal handler has finished. Thus, we save it here and set + * a flag to indicate this. + */ + u.u_oldmask = p->p_sigmask; + u.u_psflags |= SAS_OLDMASK; + p->p_sigmask = nmask &~ sigcantmask; + while (tsleep((caddr_t)&u, PPAUSE|PCATCH, 0) == 0) + ; + /* always return EINTR rather than ERESTART */ + u.u_error = EINTR; } void sigaltstack() { - register struct a { - struct sigaltstack * nss; - struct sigaltstack * oss; - } *uap = (struct a *)u.u_arg; - struct sigaltstack ss; - int error = 0; + register struct a { + struct sigaltstack * nss; + struct sigaltstack * oss; + } *uap = (struct a *)u.u_arg; + struct sigaltstack ss; + int error = 0; - if ((u.u_psflags & SAS_ALTSTACK) == 0) - u.u_sigstk.ss_flags |= SA_DISABLE; - if (uap->oss && (error = copyout((caddr_t)&u.u_sigstk, - (caddr_t)uap->oss, sizeof (struct sigaltstack)))) - goto out; - if (uap->nss == 0) - goto out; - error = copyin ((caddr_t) uap->nss, (caddr_t) &ss, sizeof(ss)); - if (error != 0) - goto out; - if (ss.ss_flags & SA_DISABLE) { - if (u.u_sigstk.ss_flags & SA_ONSTACK) - { - error = EINVAL; - goto out; - } - u.u_psflags &= ~SAS_ALTSTACK; - u.u_sigstk.ss_flags = ss.ss_flags; - goto out; - } - if (ss.ss_size < MINSIGSTKSZ) - { - error = ENOMEM; - goto out; - } - u.u_psflags |= SAS_ALTSTACK; - u.u_sigstk = ss; + if ((u.u_psflags & SAS_ALTSTACK) == 0) + u.u_sigstk.ss_flags |= SA_DISABLE; + if (uap->oss && (error = copyout((caddr_t)&u.u_sigstk, + (caddr_t)uap->oss, sizeof (struct sigaltstack)))) + goto out; + if (uap->nss == 0) + goto out; + error = copyin ((caddr_t) uap->nss, (caddr_t) &ss, sizeof(ss)); + if (error != 0) + goto out; + if (ss.ss_flags & SA_DISABLE) { + if (u.u_sigstk.ss_flags & SA_ONSTACK) + { + error = EINVAL; + goto out; + } + u.u_psflags &= ~SAS_ALTSTACK; + u.u_sigstk.ss_flags = ss.ss_flags; + goto out; + } + if (ss.ss_size < MINSIGSTKSZ) + { + error = ENOMEM; + goto out; + } + u.u_psflags |= SAS_ALTSTACK; + u.u_sigstk = ss; out: - u.u_error = error; + u.u_error = error; } void sigwait() { - register struct a { - sigset_t *set; - int *sig; - } *uap = (struct a *)u.u_arg; - sigset_t wanted, sigsavail; - register struct proc *p = u.u_procp; - int signo, error; + register struct a { + sigset_t *set; + int *sig; + } *uap = (struct a *)u.u_arg; + sigset_t wanted, sigsavail; + register struct proc *p = u.u_procp; + int signo, error; - if (uap->set == 0 || uap->sig == 0) { - error = EINVAL; - goto out; - } - error = copyin ((caddr_t) uap->set, (caddr_t) &wanted, sizeof (sigset_t)); - if (error) - goto out; + if (uap->set == 0 || uap->sig == 0) { + error = EINVAL; + goto out; + } + error = copyin ((caddr_t) uap->set, (caddr_t) &wanted, sizeof (sigset_t)); + if (error) + goto out; - wanted |= sigcantmask; - while ((sigsavail = (wanted & p->p_sig)) == 0) - tsleep ((caddr_t) &u.u_signal[0], PPAUSE | PCATCH, 0); + wanted |= sigcantmask; + while ((sigsavail = (wanted & p->p_sig)) == 0) + tsleep ((caddr_t) &u.u_signal[0], PPAUSE | PCATCH, 0); - if (sigsavail & sigcantmask) { - error = EINTR; - goto out; - } + if (sigsavail & sigcantmask) { + error = EINTR; + goto out; + } - signo = ffs(sigsavail); - p->p_sig &= ~sigmask(signo); - error = copyout ((caddr_t) &signo, (caddr_t) uap->sig, sizeof (int)); + signo = ffs(sigsavail); + p->p_sig &= ~sigmask(signo); + error = copyout ((caddr_t) &signo, (caddr_t) uap->sig, sizeof (int)); out: - u.u_error = error; + u.u_error = error; } diff --git a/sys/kernel/kern_subr.c b/sys/kernel/kern_subr.c index a818bbb..d1d88e5 100644 --- a/sys/kernel/kern_subr.c +++ b/sys/kernel/kern_subr.c @@ -14,36 +14,36 @@ */ int uiomove (cp, n, uio) - caddr_t cp; - u_int n; - register struct uio *uio; + caddr_t cp; + u_int n; + register struct uio *uio; { - register struct iovec *iov; - int error = 0; - register u_int cnt; + register struct iovec *iov; + int error = 0; + register u_int cnt; - while (n > 0 && uio->uio_resid) { - iov = uio->uio_iov; - cnt = iov->iov_len; - if (cnt == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - continue; - } - if (cnt > n) - cnt = n; - if (uio->uio_rw == UIO_READ) - bcopy ((caddr_t) cp, iov->iov_base, cnt); - else - bcopy (iov->iov_base, (caddr_t) cp, cnt); - iov->iov_base += cnt; - iov->iov_len -= cnt; - uio->uio_resid -= cnt; - uio->uio_offset += cnt; - cp += cnt; - n -= cnt; - } - return (error); + while (n > 0 && uio->uio_resid) { + iov = uio->uio_iov; + cnt = iov->iov_len; + if (cnt == 0) { + uio->uio_iov++; + uio->uio_iovcnt--; + continue; + } + if (cnt > n) + cnt = n; + if (uio->uio_rw == UIO_READ) + bcopy ((caddr_t) cp, iov->iov_base, cnt); + else + bcopy (iov->iov_base, (caddr_t) cp, cnt); + iov->iov_base += cnt; + iov->iov_len -= cnt; + uio->uio_resid -= cnt; + uio->uio_offset += cnt; + cp += cnt; + n -= cnt; + } + return (error); } /* @@ -51,27 +51,27 @@ uiomove (cp, n, uio) */ int ureadc (c, uio) - register int c; - register struct uio *uio; + register int c; + register struct uio *uio; { - register struct iovec *iov; + register struct iovec *iov; again: - if (uio->uio_iovcnt == 0) - panic("ureadc"); - iov = uio->uio_iov; - if (iov->iov_len == 0 || uio->uio_resid == 0) { - uio->uio_iovcnt--; - uio->uio_iov++; - goto again; - } - *iov->iov_base = c; + if (uio->uio_iovcnt == 0) + panic("ureadc"); + iov = uio->uio_iov; + if (iov->iov_len == 0 || uio->uio_resid == 0) { + uio->uio_iovcnt--; + uio->uio_iov++; + goto again; + } + *iov->iov_base = c; - iov->iov_base++; - iov->iov_len--; - uio->uio_resid--; - uio->uio_offset++; - return (0); + iov->iov_base++; + iov->iov_len--; + uio->uio_resid--; + uio->uio_offset++; + return (0); } /* @@ -79,30 +79,30 @@ again: */ int uwritec(uio) - register struct uio *uio; + register struct uio *uio; { - register struct iovec *iov; - register int c; + register struct iovec *iov; + register int c; - if (uio->uio_resid == 0) - return (-1); + if (uio->uio_resid == 0) + return (-1); again: - if (uio->uio_iovcnt <= 0) - panic("uwritec"); - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - if (--uio->uio_iovcnt == 0) - return (-1); - goto again; - } - c = (u_char) *iov->iov_base; + if (uio->uio_iovcnt <= 0) + panic("uwritec"); + iov = uio->uio_iov; + if (iov->iov_len == 0) { + uio->uio_iov++; + if (--uio->uio_iovcnt == 0) + return (-1); + goto again; + } + c = (u_char) *iov->iov_base; - iov->iov_base++; - iov->iov_len--; - uio->uio_resid--; - uio->uio_offset++; - return (c & 0377); + iov->iov_base++; + iov->iov_len--; + uio->uio_resid--; + uio->uio_offset++; + return (c & 0377); } /* @@ -110,17 +110,17 @@ again: */ int uiofmove(cp, n, uio, iov) - caddr_t cp; - register int n; - struct uio *uio; - struct iovec *iov; + caddr_t cp; + register int n; + struct uio *uio; + struct iovec *iov; { - if (uio->uio_rw == UIO_READ) { - /* From kernel to user. */ - bcopy(cp, iov->iov_base, n); - } else { - /* From user to kernel. */ - bcopy(iov->iov_base, cp, n); - } - return(0); + if (uio->uio_rw == UIO_READ) { + /* From kernel to user. */ + bcopy(cp, iov->iov_base, n); + } else { + /* From user to kernel. */ + bcopy(iov->iov_base, cp, n); + } + return(0); } diff --git a/sys/kernel/kern_synch.c b/sys/kernel/kern_synch.c index d1176f5..f8d011f 100644 --- a/sys/kernel/kern_synch.c +++ b/sys/kernel/kern_synch.c @@ -13,15 +13,15 @@ #include "kernel.h" #include "systm.h" -#define SQSIZE 16 /* Must be power of 2 */ +#define SQSIZE 16 /* Must be power of 2 */ -#define HASH(x) (((int)x >> 5) & (SQSIZE - 1)) -#define SCHMAG 8/10 +#define HASH(x) (((int)x >> 5) & (SQSIZE - 1)) +#define SCHMAG 8/10 -struct proc *slpque[SQSIZE]; +struct proc *slpque[SQSIZE]; -int runrun; /* scheduling flag */ -char curpri; /* more scheduling */ +int runrun; /* scheduling flag */ +char curpri; /* more scheduling */ /* * Recompute process priorities, once a second @@ -29,46 +29,46 @@ char curpri; /* more scheduling */ void schedcpu (caddr_t arg) { - register struct proc *p; - register int a; + register struct proc *p; + register int a; - wakeup((caddr_t)&lbolt); - for (p = allproc; p != NULL; p = p->p_nxt) { - if (p->p_time != 127) - p->p_time++; - /* - * this is where 2.11 does its real time alarms. 4.X uses - * timeouts, since it offers better than second resolution. - * Putting it here allows us to continue using use an int - * to store the number of ticks in the callout structure, - * since the kernel never has a timeout of greater than - * around 9 minutes. - */ - if (p->p_realtimer.it_value && !--p->p_realtimer.it_value) { - psignal(p, SIGALRM); - p->p_realtimer.it_value = p->p_realtimer.it_interval; - } - if (p->p_stat == SSLEEP || p->p_stat == SSTOP) - if (p->p_slptime != 127) - p->p_slptime++; - if (p->p_slptime > 1) - continue; - a = (p->p_cpu & 0377) * SCHMAG + p->p_nice; - if (a < 0) - a = 0; - if (a > 255) - a = 255; - p->p_cpu = a; - if (p->p_pri >= PUSER) - setpri(p); - } - vmmeter(); - if (runin != 0) { - runin = 0; - wakeup((caddr_t)&runin); - } - ++runrun; /* swtch at least once a second */ - timeout (schedcpu, (caddr_t) 0, hz); + wakeup((caddr_t)&lbolt); + for (p = allproc; p != NULL; p = p->p_nxt) { + if (p->p_time != 127) + p->p_time++; + /* + * this is where 2.11 does its real time alarms. 4.X uses + * timeouts, since it offers better than second resolution. + * Putting it here allows us to continue using use an int + * to store the number of ticks in the callout structure, + * since the kernel never has a timeout of greater than + * around 9 minutes. + */ + if (p->p_realtimer.it_value && !--p->p_realtimer.it_value) { + psignal(p, SIGALRM); + p->p_realtimer.it_value = p->p_realtimer.it_interval; + } + if (p->p_stat == SSLEEP || p->p_stat == SSTOP) + if (p->p_slptime != 127) + p->p_slptime++; + if (p->p_slptime > 1) + continue; + a = (p->p_cpu & 0377) * SCHMAG + p->p_nice; + if (a < 0) + a = 0; + if (a > 255) + a = 255; + p->p_cpu = a; + if (p->p_pri >= PUSER) + setpri(p); + } + vmmeter(); + if (runin != 0) { + runin = 0; + wakeup((caddr_t)&runin); + } + ++runrun; /* swtch at least once a second */ + timeout (schedcpu, (caddr_t) 0, hz); } /* @@ -76,19 +76,19 @@ schedcpu (caddr_t arg) */ void updatepri(p) - register struct proc *p; + register struct proc *p; { - register int a = p->p_cpu & 0377; + register int a = p->p_cpu & 0377; - p->p_slptime--; /* the first time was done in schedcpu */ - while (a && --p->p_slptime) - a = (SCHMAG * a) /* + p->p_nice */; - if (a < 0) - a = 0; - if (a > 255) - a = 255; - p->p_cpu = a; - (void) setpri(p); + p->p_slptime--; /* the first time was done in schedcpu */ + while (a && --p->p_slptime) + a = (SCHMAG * a) /* + p->p_nice */; + if (a < 0) + a = 0; + if (a > 255) + a = 255; + p->p_cpu = a; + (void) setpri(p); } /* @@ -98,19 +98,19 @@ updatepri(p) */ static void endtsleep (p) - register struct proc *p; + register struct proc *p; { - register int s; + register int s; - s = splhigh(); - if (p->p_wchan) { - if (p->p_stat == SSLEEP) - setrun(p); - else - unsleep(p); - p->p_flag |= P_TIMEOUT; - } - splx(s); + s = splhigh(); + if (p->p_wchan) { + if (p->p_stat == SSLEEP) + setrun(p); + else + unsleep(p); + p->p_flag |= P_TIMEOUT; + } + splx(s); } /* @@ -128,85 +128,85 @@ endtsleep (p) */ int tsleep (ident, priority, timo) - caddr_t ident; - int priority; - u_int timo; + caddr_t ident; + int priority; + u_int timo; { - register struct proc *p = u.u_procp; - register struct proc **qp; - int s; - int sig, catch = priority & PCATCH; + register struct proc *p = u.u_procp; + register struct proc **qp; + int s; + int sig, catch = priority & PCATCH; - s = splhigh(); - if (panicstr) { - /* - * After a panic just give interrupts a chance then just return. Don't - * run any other procs (or panic again below) in case this is the idle - * process and already asleep. The splnet should be spl0 if the network - * was being used but for now avoid network interrupts that might cause - * another panic. - */ - (void) splnet(); - noop(); - splx(s); - return(0); - } -#ifdef DIAGNOSTIC - if (ident == NULL || p->p_stat != SRUN) - panic("tsleep"); + s = splhigh(); + if (panicstr) { + /* + * After a panic just give interrupts a chance then just return. Don't + * run any other procs (or panic again below) in case this is the idle + * process and already asleep. The splnet should be spl0 if the network + * was being used but for now avoid network interrupts that might cause + * another panic. + */ + (void) splnet(); + noop(); + splx(s); + return(0); + } +#ifdef DIAGNOSTIC + if (ident == NULL || p->p_stat != SRUN) + panic("tsleep"); #endif - p->p_wchan = ident; - p->p_slptime = 0; - p->p_pri = priority & PRIMASK; - qp = &slpque[HASH(ident)]; - p->p_link = *qp; - *qp = p; - if (timo) - timeout (endtsleep, (caddr_t)p, timo); - /* - * We put outselves on the sleep queue and start the timeout before calling - * CURSIG as we could stop there and a wakeup or a SIGCONT (or both) could - * occur while we were stopped. A SIGCONT would cause us to be marked SSLEEP - * without resuming us thus we must be ready for sleep when CURSIG is called. - * If the wakeup happens while we're stopped p->p_wchan will be 0 upon - * return from CURSIG. - */ - if (catch) { - p->p_flag |= P_SINTR; - sig = CURSIG(p); - if (sig) { - if (p->p_wchan) - unsleep(p); - p->p_stat = SRUN; - goto resume; - } - if (p->p_wchan == 0) { - catch = 0; - goto resume; - } - } else - sig = 0; + p->p_wchan = ident; + p->p_slptime = 0; + p->p_pri = priority & PRIMASK; + qp = &slpque[HASH(ident)]; + p->p_link = *qp; + *qp = p; + if (timo) + timeout (endtsleep, (caddr_t)p, timo); + /* + * We put outselves on the sleep queue and start the timeout before calling + * CURSIG as we could stop there and a wakeup or a SIGCONT (or both) could + * occur while we were stopped. A SIGCONT would cause us to be marked SSLEEP + * without resuming us thus we must be ready for sleep when CURSIG is called. + * If the wakeup happens while we're stopped p->p_wchan will be 0 upon + * return from CURSIG. + */ + if (catch) { + p->p_flag |= P_SINTR; + sig = CURSIG(p); + if (sig) { + if (p->p_wchan) + unsleep(p); + p->p_stat = SRUN; + goto resume; + } + if (p->p_wchan == 0) { + catch = 0; + goto resume; + } + } else + sig = 0; - p->p_stat = SSLEEP; - if (p != &proc[0]) - wakeup((caddr_t) &runin); - u.u_ru.ru_nvcsw++; - swtch(); + p->p_stat = SSLEEP; + if (p != &proc[0]) + wakeup((caddr_t) &runin); + u.u_ru.ru_nvcsw++; + swtch(); resume: - splx(s); - p->p_flag &= ~P_SINTR; - if (p->p_flag & P_TIMEOUT) { - p->p_flag &= ~P_TIMEOUT; - if (sig == 0) - return(EWOULDBLOCK); - } else if (timo) - untimeout (endtsleep, (caddr_t)p); - if (catch && (sig != 0 || (sig = CURSIG(p)))) { - if (u.u_sigintr & sigmask(sig)) - return(EINTR); - return(ERESTART); - } - return(0); + splx(s); + p->p_flag &= ~P_SINTR; + if (p->p_flag & P_TIMEOUT) { + p->p_flag &= ~P_TIMEOUT; + if (sig == 0) + return(EWOULDBLOCK); + } else if (timo) + untimeout (endtsleep, (caddr_t)p); + if (catch && (sig != 0 || (sig = CURSIG(p)))) { + if (u.u_sigintr & sigmask(sig)) + return(EINTR); + return(ERESTART); + } + return(0); } /* @@ -223,33 +223,33 @@ resume: */ void sleep (chan, pri) - caddr_t chan; - int pri; + caddr_t chan; + int pri; { - register int priority = pri; + register int priority = pri; - if (pri > PZERO) - priority |= PCATCH; + if (pri > PZERO) + priority |= PCATCH; - u.u_error = tsleep (chan, priority, 0); - /* - * sleep does not return anything. If it was a non-interruptible sleep _or_ - * a successful/normal sleep (one for which a wakeup was done) then return. - */ - if ((priority & PCATCH) == 0 || (u.u_error == 0)) - return; - /* - * XXX - compatibility uglyness. - * - * The tsleep() above will leave one of the following in u_error: - * - * 0 - a wakeup was done, this is handled above - * EWOULDBLOCK - since no timeout was passed to tsleep we will not see this - * EINTR - put into u_error for trap.c to find (interrupted syscall) - * ERESTART - system call to be restared - */ - longjmp (u.u_procp->p_addr, &u.u_qsave); - /*NOTREACHED*/ + u.u_error = tsleep (chan, priority, 0); + /* + * sleep does not return anything. If it was a non-interruptible sleep _or_ + * a successful/normal sleep (one for which a wakeup was done) then return. + */ + if ((priority & PCATCH) == 0 || (u.u_error == 0)) + return; + /* + * XXX - compatibility uglyness. + * + * The tsleep() above will leave one of the following in u_error: + * + * 0 - a wakeup was done, this is handled above + * EWOULDBLOCK - since no timeout was passed to tsleep we will not see this + * EINTR - put into u_error for trap.c to find (interrupted syscall) + * ERESTART - system call to be restared + */ + longjmp (u.u_procp->p_addr, &u.u_qsave); + /*NOTREACHED*/ } /* @@ -257,20 +257,20 @@ sleep (chan, pri) */ void unsleep (p) - register struct proc *p; + register struct proc *p; { - register struct proc **hp; - register int s; + register struct proc **hp; + register int s; - s = splhigh(); - if (p->p_wchan) { - hp = &slpque[HASH(p->p_wchan)]; - while (*hp != p) - hp = &(*hp)->p_link; - *hp = p->p_link; - p->p_wchan = 0; - } - splx(s); + s = splhigh(); + if (p->p_wchan) { + hp = &slpque[HASH(p->p_wchan)]; + while (*hp != p) + hp = &(*hp)->p_link; + *hp = p->p_link; + p->p_wchan = 0; + } + splx(s); } /* @@ -278,52 +278,52 @@ unsleep (p) */ void wakeup (chan) - register caddr_t chan; + register caddr_t chan; { - register struct proc *p, **q; - struct proc **qp; - int s; + register struct proc *p, **q; + struct proc **qp; + int s; - /* - * Since we are called at interrupt time, must insure normal - * kernel mapping to access proc. - */ - s = splclock(); - qp = &slpque[HASH(chan)]; + /* + * Since we are called at interrupt time, must insure normal + * kernel mapping to access proc. + */ + s = splclock(); + qp = &slpque[HASH(chan)]; restart: - for (q = qp; (p = *q); ) { - if (p->p_stat != SSLEEP && p->p_stat != SSTOP) - panic("wakeup"); - if (p->p_wchan==chan) { - p->p_wchan = 0; - *q = p->p_link; - if (p->p_stat == SSLEEP) { - /* OPTIMIZED INLINE EXPANSION OF setrun(p) */ - if (p->p_slptime > 1) - updatepri(p); - p->p_slptime = 0; - p->p_stat = SRUN; - if (p->p_flag & SLOAD) - setrq(p); - /* - * Since curpri is a usrpri, - * p->p_pri is always better than curpri. - */ - runrun++; - if (! (p->p_flag & SLOAD)) { - if (runout != 0) { - runout = 0; - wakeup((caddr_t)&runout); - } - } - /* END INLINE EXPANSION */ - goto restart; - } - p->p_slptime = 0; - } else - q = &p->p_link; - } - splx(s); + for (q = qp; (p = *q); ) { + if (p->p_stat != SSLEEP && p->p_stat != SSTOP) + panic("wakeup"); + if (p->p_wchan==chan) { + p->p_wchan = 0; + *q = p->p_link; + if (p->p_stat == SSLEEP) { + /* OPTIMIZED INLINE EXPANSION OF setrun(p) */ + if (p->p_slptime > 1) + updatepri(p); + p->p_slptime = 0; + p->p_stat = SRUN; + if (p->p_flag & SLOAD) + setrq(p); + /* + * Since curpri is a usrpri, + * p->p_pri is always better than curpri. + */ + runrun++; + if (! (p->p_flag & SLOAD)) { + if (runout != 0) { + runout = 0; + wakeup((caddr_t)&runout); + } + } + /* END INLINE EXPANSION */ + goto restart; + } + p->p_slptime = 0; + } else + q = &p->p_link; + } + splx(s); } /* @@ -332,41 +332,41 @@ restart: */ void setrun (p) - register struct proc *p; + register struct proc *p; { - register int s; + register int s; - s = splhigh(); - switch (p->p_stat) { - case 0: - case SWAIT: - case SRUN: - case SZOMB: - default: - panic("setrun"); + s = splhigh(); + switch (p->p_stat) { + case 0: + case SWAIT: + case SRUN: + case SZOMB: + default: + panic("setrun"); - case SSTOP: - case SSLEEP: - unsleep(p); /* e.g. when sending signals */ - break; + case SSTOP: + case SSLEEP: + unsleep(p); /* e.g. when sending signals */ + break; - case SIDL: - break; - } - if (p->p_slptime > 1) - updatepri(p); - p->p_stat = SRUN; - if (p->p_flag & SLOAD) - setrq(p); - splx(s); - if (p->p_pri < curpri) - runrun++; - if (! (p->p_flag & SLOAD)) { - if (runout != 0) { - runout = 0; - wakeup((caddr_t)&runout); - } - } + case SIDL: + break; + } + if (p->p_slptime > 1) + updatepri(p); + p->p_stat = SRUN; + if (p->p_flag & SLOAD) + setrq(p); + splx(s); + if (p->p_pri < curpri) + runrun++; + if (! (p->p_flag & SLOAD)) { + if (runout != 0) { + runout = 0; + wakeup((caddr_t)&runout); + } + } } /* @@ -377,18 +377,18 @@ setrun (p) */ int setpri (pp) - register struct proc *pp; + register struct proc *pp; { - register int p; + register int p; - p = (pp->p_cpu & 0377)/16; - p += PUSER + pp->p_nice; - if (p > 127) - p = 127; - if (p < curpri) - runrun++; - pp->p_pri = p; - return (p); + p = (pp->p_cpu & 0377)/16; + p += PUSER + pp->p_nice; + if (p > 127) + p = 127; + if (p < curpri) + runrun++; + pp->p_pri = p; + return (p); } /* @@ -402,88 +402,88 @@ setpri (pp) void swtch() { - register struct proc *p, *q; - register int n; - struct proc *pp, *pq; - int s; + register struct proc *p, *q; + register int n; + struct proc *pp, *pq; + int s; #ifdef UCB_METER - cnt.v_swtch++; + cnt.v_swtch++; #endif - /* If not the idle process, resume the idle process. */ - if (u.u_procp != &proc[0]) { - if (setjmp (&u.u_rsave)) { - /* Returned from swapper to user process. */ - return; - } - /* Switch from user process to swapper. */ - longjmp (proc[0].p_addr, &u.u_qsave); - } - /* - * The first save returns nonzero when proc 0 is resumed - * by another process (above); then the second is not done - * and the process-search loop is entered. - */ - if (setjmp (&u.u_qsave)) { - /* Returned from user process. */ - goto loop; - } - /* - * The first save returns 0 when swtch is called in proc 0 - * from sched(). The second save returns 0 immediately, so - * in this case too the process-search loop is entered. - * Thus when proc 0 is awakened by being made runnable, it will - * find itself and resume itself at rsave, and return to sched(). - */ - if (setjmp (&u.u_rsave)) { - /* Swapper resumed by itself. */ - return; - } + /* If not the idle process, resume the idle process. */ + if (u.u_procp != &proc[0]) { + if (setjmp (&u.u_rsave)) { + /* Returned from swapper to user process. */ + return; + } + /* Switch from user process to swapper. */ + longjmp (proc[0].p_addr, &u.u_qsave); + } + /* + * The first save returns nonzero when proc 0 is resumed + * by another process (above); then the second is not done + * and the process-search loop is entered. + */ + if (setjmp (&u.u_qsave)) { + /* Returned from user process. */ + goto loop; + } + /* + * The first save returns 0 when swtch is called in proc 0 + * from sched(). The second save returns 0 immediately, so + * in this case too the process-search loop is entered. + * Thus when proc 0 is awakened by being made runnable, it will + * find itself and resume itself at rsave, and return to sched(). + */ + if (setjmp (&u.u_rsave)) { + /* Swapper resumed by itself. */ + return; + } loop: - s = splhigh(); - noproc = 0; - runrun = 0; + s = splhigh(); + noproc = 0; + runrun = 0; #ifdef DIAGNOSTIC - for (p = qs; p; p = p->p_link) - if (p->p_stat != SRUN) - panic ("swtch SRUN"); + for (p = qs; p; p = p->p_link) + if (p->p_stat != SRUN) + panic ("swtch SRUN"); #endif - pp = NULL; - q = NULL; - n = 128; - /* - * search for highest-priority runnable process - */ - pq = 0; - for (p = qs; p; p = p->p_link) { - if (p->p_flag & SLOAD && p->p_pri < n) { - pp = p; - pq = q; - n = p->p_pri; - } - q = p; - } - /* - * if no process is runnable, idle. - */ - p = pp; - if (p == NULL) { - idle(); - goto loop; - } - if (pq) - pq->p_link = p->p_link; - else - qs = p->p_link; - curpri = n; - splx(s); - /* - * the rsave (ssave) contents are interpreted - * in the new address space - */ - n = p->p_flag & SSWAP; - p->p_flag &= ~SSWAP; - longjmp (p->p_addr, n ? &u.u_ssave : &u.u_rsave); + pp = NULL; + q = NULL; + n = 128; + /* + * search for highest-priority runnable process + */ + pq = 0; + for (p = qs; p; p = p->p_link) { + if (p->p_flag & SLOAD && p->p_pri < n) { + pp = p; + pq = q; + n = p->p_pri; + } + q = p; + } + /* + * if no process is runnable, idle. + */ + p = pp; + if (p == NULL) { + idle(); + goto loop; + } + if (pq) + pq->p_link = p->p_link; + else + qs = p->p_link; + curpri = n; + splx(s); + /* + * the rsave (ssave) contents are interpreted + * in the new address space + */ + n = p->p_flag & SSWAP; + p->p_flag &= ~SSWAP; + longjmp (p->p_addr, n ? &u.u_ssave : &u.u_rsave); } /* @@ -491,23 +491,23 @@ loop: */ void setrq (p) - register struct proc *p; + register struct proc *p; { - register int s; + register int s; - s = splhigh(); + s = splhigh(); #ifdef DIAGNOSTIC - { /* see if already on the run queue */ - register struct proc *q; + { /* see if already on the run queue */ + register struct proc *q; - for (q = qs;q != NULL;q = q->p_link) - if (q == p) - panic("setrq"); - } + for (q = qs;q != NULL;q = q->p_link) + if (q == p) + panic("setrq"); + } #endif - p->p_link = qs; - qs = p; - splx(s); + p->p_link = qs; + qs = p; + splx(s); } /* @@ -517,22 +517,22 @@ setrq (p) */ void remrq (p) - register struct proc *p; + register struct proc *p; { - register struct proc *q; - register int s; + register struct proc *q; + register int s; - s = splhigh(); - if (p == qs) - qs = p->p_link; - else { - for (q = qs; q; q = q->p_link) - if (q->p_link == p) { - q->p_link = p->p_link; - goto done; - } - panic("remrq"); - } + s = splhigh(); + if (p == qs) + qs = p->p_link; + else { + for (q = qs; q; q = q->p_link) + if (q->p_link == p) { + q->p_link = p->p_link; + goto done; + } + panic("remrq"); + } done: - splx(s); + splx(s); } diff --git a/sys/kernel/kern_sysctl.c b/sys/kernel/kern_sysctl.c index 5005e6e..a7a28b6 100644 --- a/sys/kernel/kern_sysctl.c +++ b/sys/kernel/kern_sysctl.c @@ -2,7 +2,7 @@ * sysctl system call. * * Copyright (c) 1982, 1986, 1989, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Mike Karels at Berkeley Software Design, Inc. @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -58,18 +58,18 @@ sysctlfn debug_sysctl; #endif sysctlfn vm_sysctl; sysctlfn fs_sysctl; -#ifdef INET +#ifdef INET sysctlfn net_sysctl; #endif sysctlfn cpu_sysctl; struct sysctl_args { - int *name; - u_int namelen; - void *old; - size_t *oldlenp; - void *new; - size_t newlen; + int *name; + u_int namelen; + void *old; + size_t *oldlenp; + void *new; + size_t newlen; }; static int sysctl_clockrate (char *where, size_t *sizep); @@ -80,94 +80,94 @@ static int sysctl_doproc (int *name, u_int namelen, char *where, size_t *sizep); void __sysctl() { - register struct sysctl_args *uap = (struct sysctl_args*) u.u_arg; - int error; - u_int oldlen = 0; - sysctlfn *fn; - int name [CTL_MAXNAME]; + register struct sysctl_args *uap = (struct sysctl_args*) u.u_arg; + int error; + u_int oldlen = 0; + sysctlfn *fn; + int name [CTL_MAXNAME]; - if (uap->new != NULL && ! suser()) - return; - /* - * all top-level sysctl names are non-terminal - */ - if (uap->namelen > CTL_MAXNAME || uap->namelen < 2) { - u.u_error = EINVAL; - return; - } - error = copyin ((caddr_t) uap->name, (caddr_t) &name, uap->namelen * sizeof(int)); - if (error) { - u.u_error = error; - return; - } + if (uap->new != NULL && ! suser()) + return; + /* + * all top-level sysctl names are non-terminal + */ + if (uap->namelen > CTL_MAXNAME || uap->namelen < 2) { + u.u_error = EINVAL; + return; + } + error = copyin ((caddr_t) uap->name, (caddr_t) &name, uap->namelen * sizeof(int)); + if (error) { + u.u_error = error; + return; + } - switch (name[0]) { - case CTL_KERN: - fn = kern_sysctl; - break; - case CTL_HW: - fn = hw_sysctl; - break; - case CTL_VM: - fn = vm_sysctl; - break; -#ifdef INET - case CTL_NET: - fn = net_sysctl; - break; + switch (name[0]) { + case CTL_KERN: + fn = kern_sysctl; + break; + case CTL_HW: + fn = hw_sysctl; + break; + case CTL_VM: + fn = vm_sysctl; + break; +#ifdef INET + case CTL_NET: + fn = net_sysctl; + break; #endif #ifdef notyet - case CTL_FS: - fn = fs_sysctl; - break; + case CTL_FS: + fn = fs_sysctl; + break; #endif - case CTL_MACHDEP: - fn = cpu_sysctl; - break; + case CTL_MACHDEP: + fn = cpu_sysctl; + break; #ifdef DEBUG - case CTL_DEBUG: - fn = debug_sysctl; - break; + case CTL_DEBUG: + fn = debug_sysctl; + break; #endif - default: - u.u_error = EOPNOTSUPP; - return; - } + default: + u.u_error = EOPNOTSUPP; + return; + } - if (uap->oldlenp && (error = copyin ((caddr_t) uap->oldlenp, - (caddr_t) &oldlen, sizeof(oldlen)))) { - u.u_error = error; - return; - } - if (uap->old != NULL) { - while (memlock.sl_lock) { - memlock.sl_want = 1; - sleep((caddr_t)&memlock, PRIBIO+1); - memlock.sl_locked++; - } - memlock.sl_lock = 1; - } - error = (*fn) (name + 1, uap->namelen - 1, uap->old, &oldlen, - uap->new, uap->newlen); - if (uap->old != NULL) { - memlock.sl_lock = 0; - if (memlock.sl_want) { - memlock.sl_want = 0; - wakeup((caddr_t)&memlock); - } - } - if (error) { - u.u_error = error; - return; - } - if (uap->oldlenp) { - error = copyout ((caddr_t) &oldlen, (caddr_t) uap->oldlenp, sizeof(oldlen)); - if (error) { - u.u_error = error; - return; - } - } - u.u_rval = oldlen; + if (uap->oldlenp && (error = copyin ((caddr_t) uap->oldlenp, + (caddr_t) &oldlen, sizeof(oldlen)))) { + u.u_error = error; + return; + } + if (uap->old != NULL) { + while (memlock.sl_lock) { + memlock.sl_want = 1; + sleep((caddr_t)&memlock, PRIBIO+1); + memlock.sl_locked++; + } + memlock.sl_lock = 1; + } + error = (*fn) (name + 1, uap->namelen - 1, uap->old, &oldlen, + uap->new, uap->newlen); + if (uap->old != NULL) { + memlock.sl_lock = 0; + if (memlock.sl_want) { + memlock.sl_want = 0; + wakeup((caddr_t)&memlock); + } + } + if (error) { + u.u_error = error; + return; + } + if (uap->oldlenp) { + error = copyout ((caddr_t) &oldlen, (caddr_t) uap->oldlenp, sizeof(oldlen)); + if (error) { + u.u_error = error; + return; + } + } + u.u_rval = oldlen; } /* @@ -175,87 +175,87 @@ __sysctl() */ int kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; { - int error, level; - u_long longhostid; - char bsd[10]; + int error, level; + u_long longhostid; + char bsd[10]; - /* all sysctl names at this level are terminal */ - if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF)) - return (ENOTDIR); /* overloaded */ + /* all sysctl names at this level are terminal */ + if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF)) + return (ENOTDIR); /* overloaded */ - switch (name[0]) { - case KERN_OSTYPE: - case KERN_OSRELEASE: - /* code is cheaper than D space */ - bsd[0]='2';bsd[1]='.';bsd[2]='1';bsd[3]='1';bsd[4]='B'; - bsd[5]='S';bsd[6]='D';bsd[7]='\0'; - return (sysctl_rdstring(oldp, oldlenp, newp, bsd)); - case KERN_OSREV: - return (sysctl_rdlong(oldp, oldlenp, newp, (long)BSD)); - case KERN_VERSION: - return (sysctl_rdstring(oldp, oldlenp, newp, version)); - case KERN_MAXINODES: - return(sysctl_rdint(oldp, oldlenp, newp, NINODE)); - case KERN_MAXPROC: - return (sysctl_rdint(oldp, oldlenp, newp, NPROC)); - case KERN_MAXFILES: - return (sysctl_rdint(oldp, oldlenp, newp, NFILE)); - case KERN_ARGMAX: - return (sysctl_rdint(oldp, oldlenp, newp, NCARGS)); - case KERN_SECURELVL: - level = securelevel; - if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) || - newp == NULL) - return (error); - if (level < securelevel && u.u_procp->p_pid != 1) - return (EPERM); - securelevel = level; - return (0); - case KERN_HOSTNAME: - error = sysctl_string(oldp, oldlenp, newp, newlen, - hostname, sizeof(hostname)); - if (newp && !error) - hostnamelen = newlen; - return (error); - case KERN_HOSTID: - longhostid = hostid; - error = sysctl_long(oldp, oldlenp, newp, newlen, (long*) &longhostid); - hostid = longhostid; - return (error); - case KERN_CLOCKRATE: - return (sysctl_clockrate(oldp, oldlenp)); - case KERN_BOOTTIME: - return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime, - sizeof(struct timeval))); - case KERN_INODE: - return (sysctl_inode(oldp, oldlenp)); - case KERN_PROC: - return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); - case KERN_FILE: - return (sysctl_file(oldp, oldlenp)); + switch (name[0]) { + case KERN_OSTYPE: + case KERN_OSRELEASE: + /* code is cheaper than D space */ + bsd[0]='2';bsd[1]='.';bsd[2]='1';bsd[3]='1';bsd[4]='B'; + bsd[5]='S';bsd[6]='D';bsd[7]='\0'; + return (sysctl_rdstring(oldp, oldlenp, newp, bsd)); + case KERN_OSREV: + return (sysctl_rdlong(oldp, oldlenp, newp, (long)BSD)); + case KERN_VERSION: + return (sysctl_rdstring(oldp, oldlenp, newp, version)); + case KERN_MAXINODES: + return(sysctl_rdint(oldp, oldlenp, newp, NINODE)); + case KERN_MAXPROC: + return (sysctl_rdint(oldp, oldlenp, newp, NPROC)); + case KERN_MAXFILES: + return (sysctl_rdint(oldp, oldlenp, newp, NFILE)); + case KERN_ARGMAX: + return (sysctl_rdint(oldp, oldlenp, newp, NCARGS)); + case KERN_SECURELVL: + level = securelevel; + if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) || + newp == NULL) + return (error); + if (level < securelevel && u.u_procp->p_pid != 1) + return (EPERM); + securelevel = level; + return (0); + case KERN_HOSTNAME: + error = sysctl_string(oldp, oldlenp, newp, newlen, + hostname, sizeof(hostname)); + if (newp && !error) + hostnamelen = newlen; + return (error); + case KERN_HOSTID: + longhostid = hostid; + error = sysctl_long(oldp, oldlenp, newp, newlen, (long*) &longhostid); + hostid = longhostid; + return (error); + case KERN_CLOCKRATE: + return (sysctl_clockrate(oldp, oldlenp)); + case KERN_BOOTTIME: + return (sysctl_rdstruct(oldp, oldlenp, newp, &boottime, + sizeof(struct timeval))); + case KERN_INODE: + return (sysctl_inode(oldp, oldlenp)); + case KERN_PROC: + return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp)); + case KERN_FILE: + return (sysctl_file(oldp, oldlenp)); #ifdef GPROF - case KERN_PROF: - return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, - newp, newlen)); + case KERN_PROF: + return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); #endif - case KERN_NGROUPS: - return (sysctl_rdint(oldp, oldlenp, newp, NGROUPS)); - case KERN_JOB_CONTROL: - return (sysctl_rdint(oldp, oldlenp, newp, 1)); - case KERN_POSIX1: - case KERN_SAVED_IDS: - return (sysctl_rdint(oldp, oldlenp, newp, 0)); - default: - return (EOPNOTSUPP); - } - /* NOTREACHED */ + case KERN_NGROUPS: + return (sysctl_rdint(oldp, oldlenp, newp, NGROUPS)); + case KERN_JOB_CONTROL: + return (sysctl_rdint(oldp, oldlenp, newp, 1)); + case KERN_POSIX1: + case KERN_SAVED_IDS: + return (sysctl_rdint(oldp, oldlenp, newp, 0)); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ } /* @@ -263,38 +263,38 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen) */ int hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; { - /* all sysctl names at this level are terminal */ - if (namelen != 1) - return (ENOTDIR); /* overloaded */ + /* all sysctl names at this level are terminal */ + if (namelen != 1) + return (ENOTDIR); /* overloaded */ - switch (name[0]) { - case HW_MACHINE: - return (sysctl_rdstring(oldp, oldlenp, newp, "pic32")); - case HW_MODEL: - return (sysctl_rdstring(oldp, oldlenp, newp, "mips")); - case HW_NCPU: - return (sysctl_rdint(oldp, oldlenp, newp, 1)); /* XXX */ - case HW_BYTEORDER: - return (sysctl_rdint(oldp, oldlenp, newp, ENDIAN)); - case HW_PHYSMEM: - return (sysctl_rdlong(oldp, oldlenp, newp, physmem)); + switch (name[0]) { + case HW_MACHINE: + return (sysctl_rdstring(oldp, oldlenp, newp, "pic32")); + case HW_MODEL: + return (sysctl_rdstring(oldp, oldlenp, newp, "mips")); + case HW_NCPU: + return (sysctl_rdint(oldp, oldlenp, newp, 1)); /* XXX */ + case HW_BYTEORDER: + return (sysctl_rdint(oldp, oldlenp, newp, ENDIAN)); + case HW_PHYSMEM: + return (sysctl_rdlong(oldp, oldlenp, newp, physmem)); #ifdef UCB_METER - case HW_USERMEM: - return (sysctl_rdlong(oldp, oldlenp, newp, freemem)); + case HW_USERMEM: + return (sysctl_rdlong(oldp, oldlenp, newp, freemem)); #endif - case HW_PAGESIZE: - return (sysctl_rdint(oldp, oldlenp, newp, DEV_BSIZE)); - default: - return (EOPNOTSUPP); - } - /* NOTREACHED */ + case HW_PAGESIZE: + return (sysctl_rdint(oldp, oldlenp, newp, DEV_BSIZE)); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ } #ifdef DEBUG @@ -306,38 +306,38 @@ struct ctldebug debug5, debug6, debug7, debug8, debug9; struct ctldebug debug10, debug11, debug12, debug13, debug14; struct ctldebug debug15, debug16, debug17, debug18, debug19; static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = { - &debug0, &debug1, &debug2, &debug3, &debug4, - &debug5, &debug6, &debug7, &debug8, &debug9, - &debug10, &debug11, &debug12, &debug13, &debug14, - &debug15, &debug16, &debug17, &debug18, &debug19, + &debug0, &debug1, &debug2, &debug3, &debug4, + &debug5, &debug6, &debug7, &debug8, &debug9, + &debug10, &debug11, &debug12, &debug13, &debug14, + &debug15, &debug16, &debug17, &debug18, &debug19, }; int debug_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; { - struct ctldebug *cdp; + struct ctldebug *cdp; - /* all sysctl names at this level are name and field */ - if (namelen != 2) - return (ENOTDIR); /* overloaded */ - cdp = debugvars[name[0]]; - if (cdp->debugname == 0) - return (EOPNOTSUPP); - switch (name[1]) { - case CTL_DEBUG_NAME: - return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname)); - case CTL_DEBUG_VALUE: - return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar)); - default: - return (EOPNOTSUPP); - } - /* NOTREACHED */ + /* all sysctl names at this level are name and field */ + if (namelen != 2) + return (ENOTDIR); /* overloaded */ + cdp = debugvars[name[0]]; + if (cdp->debugname == 0) + return (EOPNOTSUPP); + switch (name[1]) { + case CTL_DEBUG_NAME: + return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname)); + case CTL_DEBUG_VALUE: + return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar)); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ } #endif /* DEBUG */ @@ -355,45 +355,45 @@ debug_sysctl(name, namelen, oldp, oldlenp, newp, newlen) */ int vm_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; { - struct loadavg averunnable; /* loadavg in resource.h */ + struct loadavg averunnable; /* loadavg in resource.h */ - /* all sysctl names at this level are terminal */ - if (namelen != 1) - return (ENOTDIR); /* overloaded */ + /* all sysctl names at this level are terminal */ + if (namelen != 1) + return (ENOTDIR); /* overloaded */ - switch (name[0]) { - case VM_LOADAVG: - averunnable.fscale = 256; - averunnable.ldavg[0] = avenrun[0]; - averunnable.ldavg[1] = avenrun[1]; - averunnable.ldavg[2] = avenrun[2]; - return (sysctl_rdstruct(oldp, oldlenp, newp, &averunnable, - sizeof(averunnable))); - case VM_METER: -#ifdef notsure - vmtotal(); /* could be expensive to do this every time */ + switch (name[0]) { + case VM_LOADAVG: + averunnable.fscale = 256; + averunnable.ldavg[0] = avenrun[0]; + averunnable.ldavg[1] = avenrun[1]; + averunnable.ldavg[2] = avenrun[2]; + return (sysctl_rdstruct(oldp, oldlenp, newp, &averunnable, + sizeof(averunnable))); + case VM_METER: +#ifdef notsure + vmtotal(); /* could be expensive to do this every time */ #endif - return (sysctl_rdstruct(oldp, oldlenp, newp, &total, - sizeof(total))); - case VM_SWAPMAP: - if (oldp == NULL) { - *oldlenp = (char *)swapmap[0].m_limit - - (char *)swapmap[0].m_map; - return(0); - } - return (sysctl_rdstruct(oldp, oldlenp, newp, swapmap, - (int)swapmap[0].m_limit - (int)swapmap[0].m_map)); - default: - return (EOPNOTSUPP); - } - /* NOTREACHED */ + return (sysctl_rdstruct(oldp, oldlenp, newp, &total, + sizeof(total))); + case VM_SWAPMAP: + if (oldp == NULL) { + *oldlenp = (char *)swapmap[0].m_limit - + (char *)swapmap[0].m_map; + return(0); + } + return (sysctl_rdstruct(oldp, oldlenp, newp, swapmap, + (int)swapmap[0].m_limit - (int)swapmap[0].m_map)); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ } /* @@ -402,24 +402,24 @@ vm_sysctl(name, namelen, oldp, oldlenp, newp, newlen) */ int sysctl_int(oldp, oldlenp, newp, newlen, valp) - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; - int *valp; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + int *valp; { - int error = 0; + int error = 0; - if (oldp && *oldlenp < sizeof(int)) - return (ENOMEM); - if (newp && newlen != sizeof(int)) - return (EINVAL); - *oldlenp = sizeof(int); - if (oldp) - error = copyout ((caddr_t) valp, (caddr_t) oldp, sizeof(int)); - if (error == 0 && newp) - error = copyin ((caddr_t) newp, (caddr_t) valp, sizeof(int)); - return (error); + if (oldp && *oldlenp < sizeof(int)) + return (ENOMEM); + if (newp && newlen != sizeof(int)) + return (EINVAL); + *oldlenp = sizeof(int); + if (oldp) + error = copyout ((caddr_t) valp, (caddr_t) oldp, sizeof(int)); + if (error == 0 && newp) + error = copyin ((caddr_t) newp, (caddr_t) valp, sizeof(int)); + return (error); } /* @@ -427,21 +427,21 @@ sysctl_int(oldp, oldlenp, newp, newlen, valp) */ int sysctl_rdint(oldp, oldlenp, newp, val) - void *oldp; - size_t *oldlenp; - void *newp; - int val; + void *oldp; + size_t *oldlenp; + void *newp; + int val; { - int error = 0; + int error = 0; - if (oldp && *oldlenp < sizeof(int)) - return (ENOMEM); - if (newp) - return (EPERM); - *oldlenp = sizeof(int); - if (oldp) - error = copyout((caddr_t)&val, oldp, sizeof(int)); - return (error); + if (oldp && *oldlenp < sizeof(int)) + return (ENOMEM); + if (newp) + return (EPERM); + *oldlenp = sizeof(int); + if (oldp) + error = copyout((caddr_t)&val, oldp, sizeof(int)); + return (error); } /* @@ -450,24 +450,24 @@ sysctl_rdint(oldp, oldlenp, newp, val) */ int sysctl_long(oldp, oldlenp, newp, newlen, valp) - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; - long *valp; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + long *valp; { - int error = 0; + int error = 0; - if (oldp && *oldlenp < sizeof(long)) - return (ENOMEM); - if (newp && newlen != sizeof(long)) - return (EINVAL); - *oldlenp = sizeof(long); - if (oldp) - error = copyout ((caddr_t) valp, (caddr_t) oldp, sizeof(long)); - if (error == 0 && newp) - error = copyin ((caddr_t) newp, (caddr_t) valp, sizeof(long)); - return (error); + if (oldp && *oldlenp < sizeof(long)) + return (ENOMEM); + if (newp && newlen != sizeof(long)) + return (EINVAL); + *oldlenp = sizeof(long); + if (oldp) + error = copyout ((caddr_t) valp, (caddr_t) oldp, sizeof(long)); + if (error == 0 && newp) + error = copyin ((caddr_t) newp, (caddr_t) valp, sizeof(long)); + return (error); } /* @@ -475,21 +475,21 @@ sysctl_long(oldp, oldlenp, newp, newlen, valp) */ int sysctl_rdlong(oldp, oldlenp, newp, val) - void *oldp; - size_t *oldlenp; - void *newp; - long val; + void *oldp; + size_t *oldlenp; + void *newp; + long val; { - int error = 0; + int error = 0; - if (oldp && *oldlenp < sizeof(long)) - return (ENOMEM); - if (newp) - return (EPERM); - *oldlenp = sizeof(long); - if (oldp) - error = copyout((caddr_t)&val, oldp, sizeof(long)); - return (error); + if (oldp && *oldlenp < sizeof(long)) + return (ENOMEM); + if (newp) + return (EPERM); + *oldlenp = sizeof(long); + if (oldp) + error = copyout((caddr_t)&val, oldp, sizeof(long)); + return (error); } /* @@ -498,29 +498,29 @@ sysctl_rdlong(oldp, oldlenp, newp, val) */ int sysctl_string(oldp, oldlenp, newp, newlen, str, maxlen) - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; - char *str; - int maxlen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + char *str; + int maxlen; { - int len, error = 0; + int len, error = 0; - len = strlen(str) + 1; - if (oldp && *oldlenp < len) - return (ENOMEM); - if (newp && newlen >= maxlen) - return (EINVAL); - if (oldp) { - *oldlenp = len; - error = copyout (str, oldp, len); - } - if (error == 0 && newp) { - error = copyin (newp, str, newlen); - str[newlen] = 0; - } - return (error); + len = strlen(str) + 1; + if (oldp && *oldlenp < len) + return (ENOMEM); + if (newp && newlen >= maxlen) + return (EINVAL); + if (oldp) { + *oldlenp = len; + error = copyout (str, oldp, len); + } + if (error == 0 && newp) { + error = copyin (newp, str, newlen); + str[newlen] = 0; + } + return (error); } /* @@ -528,22 +528,22 @@ sysctl_string(oldp, oldlenp, newp, newlen, str, maxlen) */ int sysctl_rdstring(oldp, oldlenp, newp, str) - void *oldp; - size_t *oldlenp; - void *newp; - const char *str; + void *oldp; + size_t *oldlenp; + void *newp; + const char *str; { - int len, error = 0; + int len, error = 0; - len = strlen(str) + 1; - if (oldp && *oldlenp < len) - return (ENOMEM); - if (newp) - return (EPERM); - *oldlenp = len; - if (oldp) - error = copyout ((caddr_t) str, oldp, len); - return (error); + len = strlen(str) + 1; + if (oldp && *oldlenp < len) + return (ENOMEM); + if (newp) + return (EPERM); + *oldlenp = len; + if (oldp) + error = copyout ((caddr_t) str, oldp, len); + return (error); } /* @@ -552,26 +552,26 @@ sysctl_rdstring(oldp, oldlenp, newp, str) */ int sysctl_struct(oldp, oldlenp, newp, newlen, sp, len) - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; - void *sp; - int len; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; + void *sp; + int len; { - int error = 0; + int error = 0; - if (oldp && *oldlenp < len) - return (ENOMEM); - if (newp && newlen > len) - return (EINVAL); - if (oldp) { - *oldlenp = len; - error = copyout(sp, oldp, len); - } - if (error == 0 && newp) - error = copyin(newp, sp, len); - return (error); + if (oldp && *oldlenp < len) + return (ENOMEM); + if (newp && newlen > len) + return (EINVAL); + if (oldp) { + *oldlenp = len; + error = copyout(sp, oldp, len); + } + if (error == 0 && newp) + error = copyin(newp, sp, len); + return (error); } /* @@ -580,21 +580,21 @@ sysctl_struct(oldp, oldlenp, newp, newlen, sp, len) */ int sysctl_rdstruct(oldp, oldlenp, newp, sp, len) - void *oldp; - size_t *oldlenp; - void *newp, *sp; - int len; + void *oldp; + size_t *oldlenp; + void *newp, *sp; + int len; { - int error = 0; + int error = 0; - if (oldp && *oldlenp < len) - return (ENOMEM); - if (newp) - return (EPERM); - *oldlenp = len; - if (oldp) - error = copyout(sp, oldp, len); - return (error); + if (oldp && *oldlenp < len) + return (ENOMEM); + if (newp) + return (EPERM); + *oldlenp = len; + if (oldp) + error = copyout(sp, oldp, len); + return (error); } /* @@ -602,49 +602,49 @@ sysctl_rdstruct(oldp, oldlenp, newp, sp, len) */ int sysctl_file(where, sizep) - char *where; - size_t *sizep; + char *where; + size_t *sizep; { - int buflen, error; - register struct file *fp; - struct file *fpp; - char *start = where; - register int i; + int buflen, error; + register struct file *fp; + struct file *fpp; + char *start = where; + register int i; - buflen = *sizep; - if (where == NULL) { - for (i = 0, fp = file; fp < file+NFILE; fp++) - if (fp->f_count) i++; + buflen = *sizep; + if (where == NULL) { + for (i = 0, fp = file; fp < file+NFILE; fp++) + if (fp->f_count) i++; -#define FPTRSZ sizeof (struct file *) -#define FILESZ sizeof (struct file) - /* - * overestimate by 5 files - */ - *sizep = (i + 5) * (FILESZ + FPTRSZ); - return (0); - } +#define FPTRSZ sizeof (struct file *) +#define FILESZ sizeof (struct file) + /* + * overestimate by 5 files + */ + *sizep = (i + 5) * (FILESZ + FPTRSZ); + return (0); + } - /* - * array of extended file structures: first the address then the - * file structure. - */ - for (fp = file; fp < file+NFILE; fp++) { - if (fp->f_count == 0) - continue; - if (buflen < (FPTRSZ + FILESZ)) { - *sizep = where - start; - return (ENOMEM); - } - fpp = fp; - if ((error = copyout ((caddr_t) &fpp, (caddr_t) where, FPTRSZ)) || - (error = copyout ((caddr_t) fp, (caddr_t) (where + FPTRSZ), FILESZ))) - return (error); - buflen -= (FPTRSZ + FILESZ); - where += (FPTRSZ + FILESZ); - } - *sizep = where - start; - return (0); + /* + * array of extended file structures: first the address then the + * file structure. + */ + for (fp = file; fp < file+NFILE; fp++) { + if (fp->f_count == 0) + continue; + if (buflen < (FPTRSZ + FILESZ)) { + *sizep = where - start; + return (ENOMEM); + } + fpp = fp; + if ((error = copyout ((caddr_t) &fpp, (caddr_t) where, FPTRSZ)) || + (error = copyout ((caddr_t) fp, (caddr_t) (where + FPTRSZ), FILESZ))) + return (error); + buflen -= (FPTRSZ + FILESZ); + where += (FPTRSZ + FILESZ); + } + *sizep = where - start; + return (0); } /* @@ -653,19 +653,19 @@ sysctl_file(where, sizep) */ int sysctl_clockrate (where, sizep) - char *where; - size_t *sizep; + char *where; + size_t *sizep; { - struct clockinfo clkinfo; + struct clockinfo clkinfo; - /* - * Construct clockinfo structure. - */ - clkinfo.hz = hz; - clkinfo.tick = usechz; - clkinfo.profhz = 0; - clkinfo.stathz = hz; - return(sysctl_rdstruct(where, sizep, NULL, &clkinfo, sizeof (clkinfo))); + /* + * Construct clockinfo structure. + */ + clkinfo.hz = hz; + clkinfo.tick = usechz; + clkinfo.profhz = 0; + clkinfo.stathz = hz; + return(sysctl_rdstruct(where, sizep, NULL, &clkinfo, sizeof (clkinfo))); } /* @@ -675,42 +675,42 @@ sysctl_clockrate (where, sizep) /* ARGSUSED */ int sysctl_inode (where, sizep) - char *where; - size_t *sizep; + char *where; + size_t *sizep; { - register struct inode *ip; - register char *bp = where; - struct inode *ipp; - char *ewhere; - int error, numi; + register struct inode *ip; + register char *bp = where; + struct inode *ipp; + char *ewhere; + int error, numi; - for (numi = 0, ip = inode; ip < inode+NINODE; ip++) - if (ip->i_count) numi++; + for (numi = 0, ip = inode; ip < inode+NINODE; ip++) + if (ip->i_count) numi++; -#define IPTRSZ sizeof (struct inode *) -#define INODESZ sizeof (struct inode) - if (where == NULL) { - *sizep = (numi + 5) * (IPTRSZ + INODESZ); - return (0); - } - ewhere = where + *sizep; +#define IPTRSZ sizeof (struct inode *) +#define INODESZ sizeof (struct inode) + if (where == NULL) { + *sizep = (numi + 5) * (IPTRSZ + INODESZ); + return (0); + } + ewhere = where + *sizep; - for (ip = inode; ip < inode+NINODE; ip++) { - if (ip->i_count == 0) - continue; - if (bp + IPTRSZ + INODESZ > ewhere) { - *sizep = bp - where; - return (ENOMEM); - } - ipp = ip; - if ((error = copyout ((caddr_t)&ipp, bp, IPTRSZ)) || - (error = copyout ((caddr_t)ip, bp + IPTRSZ, INODESZ))) - return (error); - bp += IPTRSZ + INODESZ; - } + for (ip = inode; ip < inode+NINODE; ip++) { + if (ip->i_count == 0) + continue; + if (bp + IPTRSZ + INODESZ > ewhere) { + *sizep = bp - where; + return (ENOMEM); + } + ipp = ip; + if ((error = copyout ((caddr_t)&ipp, bp, IPTRSZ)) || + (error = copyout ((caddr_t)ip, bp + IPTRSZ, INODESZ))) + return (error); + bp += IPTRSZ + INODESZ; + } - *sizep = bp - where; - return (0); + *sizep = bp - where; + return (0); } /* @@ -728,58 +728,58 @@ sysctl_inode (where, sizep) */ void fill_from_u (p, rup, ttp, tdp) - struct proc *p; - uid_t *rup; - struct tty **ttp; - dev_t *tdp; + struct proc *p; + uid_t *rup; + struct tty **ttp; + dev_t *tdp; { - register struct buf *bp; - dev_t ttyd; - uid_t ruid; - struct tty *ttyp; - struct user *up; + register struct buf *bp; + dev_t ttyd; + uid_t ruid; + struct tty *ttyp; + struct user *up; - if (p->p_stat == SZOMB) { - ruid = (uid_t)-2; - ttyp = NULL; - ttyd = NODEV; - goto out; - } - if (p->p_flag & SLOAD) { - ttyd = ((struct user *)p->p_addr)->u_ttyd; - ttyp = ((struct user *)p->p_addr)->u_ttyp; - ruid = ((struct user *)p->p_addr)->u_ruid; - } else { - bp = geteblk(); - bp->b_dev = swapdev; - bp->b_blkno = (daddr_t)p->p_addr; - bp->b_bcount = DEV_BSIZE; /* XXX */ - bp->b_flags = B_READ; + if (p->p_stat == SZOMB) { + ruid = (uid_t)-2; + ttyp = NULL; + ttyd = NODEV; + goto out; + } + if (p->p_flag & SLOAD) { + ttyd = ((struct user *)p->p_addr)->u_ttyd; + ttyp = ((struct user *)p->p_addr)->u_ttyp; + ruid = ((struct user *)p->p_addr)->u_ruid; + } else { + bp = geteblk(); + bp->b_dev = swapdev; + bp->b_blkno = (daddr_t)p->p_addr; + bp->b_bcount = DEV_BSIZE; /* XXX */ + bp->b_flags = B_READ; - (*bdevsw[major(swapdev)].d_strategy)(bp); - biowait(bp); + (*bdevsw[major(swapdev)].d_strategy)(bp); + biowait(bp); - if (u.u_error) { - ttyd = NODEV; - ttyp = NULL; - ruid = (uid_t)-2; - } else { - up = (struct user*) bp->b_addr; - ruid = up->u_ruid; /* u_ruid = offset 164 */ - ttyd = up->u_ttyd; /* u_ttyd = offset 654 */ - ttyp = up->u_ttyp; /* u_ttyp = offset 652 */ - } - bp->b_flags |= B_AGE; - brelse(bp); - u.u_error = 0; /* XXX */ - } + if (u.u_error) { + ttyd = NODEV; + ttyp = NULL; + ruid = (uid_t)-2; + } else { + up = (struct user*) bp->b_addr; + ruid = up->u_ruid; /* u_ruid = offset 164 */ + ttyd = up->u_ttyd; /* u_ttyd = offset 654 */ + ttyp = up->u_ttyp; /* u_ttyp = offset 652 */ + } + bp->b_flags |= B_AGE; + brelse(bp); + u.u_error = 0; /* XXX */ + } out: - if (rup) - *rup = ruid; - if (ttp) - *ttp = ttyp; - if (tdp) - *tdp = ttyd; + if (rup) + *rup = ruid; + if (ttp) + *ttp = ttyp; + if (tdp) + *tdp = ttyd; } /* @@ -790,120 +790,120 @@ out: */ static void fill_eproc(p, ep) - register struct proc *p; - register struct eproc *ep; + register struct proc *p; + register struct eproc *ep; { - struct tty *ttyp; + struct tty *ttyp; - ep->e_paddr = p; - fill_from_u(p, &ep->e_ruid, &ttyp, &ep->e_tdev); - if (ttyp) - ep->e_tpgid = ttyp->t_pgrp; - else - ep->e_tpgid = 0; + ep->e_paddr = p; + fill_from_u(p, &ep->e_ruid, &ttyp, &ep->e_tdev); + if (ttyp) + ep->e_tpgid = ttyp->t_pgrp; + else + ep->e_tpgid = 0; } /* * try over estimating by 5 procs */ -#define KERN_PROCSLOP (5 * sizeof (struct kinfo_proc)) +#define KERN_PROCSLOP (5 * sizeof (struct kinfo_proc)) int sysctl_doproc(name, namelen, where, sizep) - int *name; - u_int namelen; - char *where; - size_t *sizep; + int *name; + u_int namelen; + char *where; + size_t *sizep; { - register struct proc *p; - register struct kinfo_proc *dp = (struct kinfo_proc *)where; - int needed = 0; - int buflen = where != NULL ? *sizep : 0; - int doingzomb; - struct eproc eproc; - int error = 0; - dev_t ttyd; - uid_t ruid; - struct tty *ttyp; + register struct proc *p; + register struct kinfo_proc *dp = (struct kinfo_proc *)where; + int needed = 0; + int buflen = where != NULL ? *sizep : 0; + int doingzomb; + struct eproc eproc; + int error = 0; + dev_t ttyd; + uid_t ruid; + struct tty *ttyp; - if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL)) - return (EINVAL); - p = (struct proc *)allproc; - doingzomb = 0; + if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL)) + return (EINVAL); + p = (struct proc *)allproc; + doingzomb = 0; again: - for (; p != NULL; p = p->p_nxt) { - /* - * Skip embryonic processes. - */ - if (p->p_stat == SIDL) - continue; - /* - * TODO: sysctl_oproc - make more efficient (see notes below). - * do by session. - */ - switch (name[0]) { + for (; p != NULL; p = p->p_nxt) { + /* + * Skip embryonic processes. + */ + if (p->p_stat == SIDL) + continue; + /* + * TODO: sysctl_oproc - make more efficient (see notes below). + * do by session. + */ + switch (name[0]) { - case KERN_PROC_PID: - /* could do this with just a lookup */ - if (p->p_pid != (pid_t)name[1]) - continue; - break; + case KERN_PROC_PID: + /* could do this with just a lookup */ + if (p->p_pid != (pid_t)name[1]) + continue; + break; - case KERN_PROC_PGRP: - /* could do this by traversing pgrp */ - if (p->p_pgrp != (pid_t)name[1]) - continue; - break; + case KERN_PROC_PGRP: + /* could do this by traversing pgrp */ + if (p->p_pgrp != (pid_t)name[1]) + continue; + break; - case KERN_PROC_TTY: - fill_from_u(p, &ruid, &ttyp, &ttyd); - if (!ttyp || ttyd != (dev_t)name[1]) - continue; - break; + case KERN_PROC_TTY: + fill_from_u(p, &ruid, &ttyp, &ttyd); + if (!ttyp || ttyd != (dev_t)name[1]) + continue; + break; - case KERN_PROC_UID: - if (p->p_uid != (uid_t)name[1]) - continue; - break; + case KERN_PROC_UID: + if (p->p_uid != (uid_t)name[1]) + continue; + break; - case KERN_PROC_RUID: - fill_from_u(p, &ruid, &ttyp, &ttyd); - if (ruid != (uid_t)name[1]) - continue; - break; + case KERN_PROC_RUID: + fill_from_u(p, &ruid, &ttyp, &ttyd); + if (ruid != (uid_t)name[1]) + continue; + break; - case KERN_PROC_ALL: - break; - default: - return(EINVAL); - } - if (buflen >= sizeof(struct kinfo_proc)) { - fill_eproc(p, &eproc); - error = copyout ((caddr_t) p, (caddr_t) &dp->kp_proc, - sizeof(struct proc)); - if (error) - return (error); - error = copyout ((caddr_t)&eproc, (caddr_t) &dp->kp_eproc, - sizeof(eproc)); - if (error) - return (error); - dp++; - buflen -= sizeof(struct kinfo_proc); - } - needed += sizeof(struct kinfo_proc); - } - if (doingzomb == 0) { - p = zombproc; - doingzomb++; - goto again; - } - if (where != NULL) { - *sizep = (caddr_t)dp - where; - if (needed > *sizep) - return (ENOMEM); - } else { - needed += KERN_PROCSLOP; - *sizep = needed; - } - return (0); + case KERN_PROC_ALL: + break; + default: + return(EINVAL); + } + if (buflen >= sizeof(struct kinfo_proc)) { + fill_eproc(p, &eproc); + error = copyout ((caddr_t) p, (caddr_t) &dp->kp_proc, + sizeof(struct proc)); + if (error) + return (error); + error = copyout ((caddr_t)&eproc, (caddr_t) &dp->kp_eproc, + sizeof(eproc)); + if (error) + return (error); + dp++; + buflen -= sizeof(struct kinfo_proc); + } + needed += sizeof(struct kinfo_proc); + } + if (doingzomb == 0) { + p = zombproc; + doingzomb++; + goto again; + } + if (where != NULL) { + *sizep = (caddr_t)dp - where; + if (needed > *sizep) + return (ENOMEM); + } else { + needed += KERN_PROCSLOP; + *sizep = needed; + } + return (0); } diff --git a/sys/kernel/kern_time.c b/sys/kernel/kern_time.c index 452c0c4..f585529 100644 --- a/sys/kernel/kern_time.c +++ b/sys/kernel/kern_time.c @@ -11,40 +11,40 @@ static void setthetime (tv) - register struct timeval *tv; + register struct timeval *tv; { - int s; + int s; - if (! suser()) - return; -#ifdef NOTNOW + if (! suser()) + return; +#ifdef NOTNOW /* * If the system is secure, we do not allow the time to be set to an * earlier value. The time may be slowed (using adjtime) but not set back. * * NOTE: Can not do this until ntpd is updated to deal with the coarse (50, 60 - * hz) clocks. Ntpd wants to adjust time system clock a few microseconds - * at a time (which gets rounded to 0 in adjtime below). If that fails - * ntpd uses settimeofday to step the time backwards which obviously - * will fail if the next 'if' is enabled - all that does is fill up the - * logfiles with "can't set time" messages and the time keeps drifting. + * hz) clocks. Ntpd wants to adjust time system clock a few microseconds + * at a time (which gets rounded to 0 in adjtime below). If that fails + * ntpd uses settimeofday to step the time backwards which obviously + * will fail if the next 'if' is enabled - all that does is fill up the + * logfiles with "can't set time" messages and the time keeps drifting. */ - if (securelevel > 0 && timercmp(tv, &time, <)) { - u.u_error = EPERM; /* XXX */ - return; - } + if (securelevel > 0 && timercmp(tv, &time, <)) { + u.u_error = EPERM; /* XXX */ + return; + } #endif /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */ - boottime.tv_sec += tv->tv_sec - time.tv_sec; - s = splhigh(); - time = *tv; - lbolt = time.tv_usec / usechz; - splx(s); -#ifdef notyet - /* - * if you have a time of day board, use it here - */ - resettodr(); + boottime.tv_sec += tv->tv_sec - time.tv_sec; + s = splhigh(); + time = *tv; + lbolt = time.tv_usec / usechz; + splx(s); +#ifdef notyet + /* + * if you have a time of day board, use it here + */ + resettodr(); #endif } @@ -57,185 +57,185 @@ setthetime (tv) void gettimeofday() { - register struct a { - struct timeval *tp; - struct timezone *tzp; - } *uap = (struct a *)u.u_arg; - struct timeval atv; - int s; - register u_int ms; + register struct a { + struct timeval *tp; + struct timezone *tzp; + } *uap = (struct a *)u.u_arg; + struct timeval atv; + int s; + register u_int ms; - if (uap->tp) { - /* - * We don't resolve the milliseconds on every clock tick; it's - * easier to do it here. Long casts are out of paranoia. - */ - s = splhigh(); - atv = time; - ms = lbolt; - splx(s); - atv.tv_usec = (long)ms * usechz; - u.u_error = copyout ((caddr_t) &atv, (caddr_t) uap->tp, - sizeof(atv)); - if (u.u_error) - return; - } - if (uap->tzp) - u.u_error = copyout ((caddr_t) &tz, (caddr_t) uap->tzp, - sizeof (tz)); + if (uap->tp) { + /* + * We don't resolve the milliseconds on every clock tick; it's + * easier to do it here. Long casts are out of paranoia. + */ + s = splhigh(); + atv = time; + ms = lbolt; + splx(s); + atv.tv_usec = (long)ms * usechz; + u.u_error = copyout ((caddr_t) &atv, (caddr_t) uap->tp, + sizeof(atv)); + if (u.u_error) + return; + } + if (uap->tzp) + u.u_error = copyout ((caddr_t) &tz, (caddr_t) uap->tzp, + sizeof (tz)); } void settimeofday() { - register struct a { - struct timeval *tv; - struct timezone *tzp; - } *uap = (struct a *)u.u_arg; - struct timeval atv; - struct timezone atz; + register struct a { + struct timeval *tv; + struct timezone *tzp; + } *uap = (struct a *)u.u_arg; + struct timeval atv; + struct timezone atz; - if (uap->tv) { - u.u_error = copyin((caddr_t)uap->tv, (caddr_t)&atv, - sizeof (struct timeval)); - if (u.u_error) - return; - setthetime(&atv); - if (u.u_error) - return; - } - if (uap->tzp && suser()) { - u.u_error = copyin((caddr_t)uap->tzp, (caddr_t)&atz, - sizeof (atz)); - if (u.u_error == 0) - tz = atz; - } + if (uap->tv) { + u.u_error = copyin((caddr_t)uap->tv, (caddr_t)&atv, + sizeof (struct timeval)); + if (u.u_error) + return; + setthetime(&atv); + if (u.u_error) + return; + } + if (uap->tzp && suser()) { + u.u_error = copyin((caddr_t)uap->tzp, (caddr_t)&atz, + sizeof (atz)); + if (u.u_error == 0) + tz = atz; + } } void adjtime() { - register struct a { - struct timeval *delta; - struct timeval *olddelta; - } *uap = (struct a *)u.u_arg; - struct timeval atv; - register int s; - long adjust; + register struct a { + struct timeval *delta; + struct timeval *olddelta; + } *uap = (struct a *)u.u_arg; + struct timeval atv; + register int s; + long adjust; - if (!suser()) - return; - u.u_error = copyin((caddr_t)uap->delta, (caddr_t)&atv, - sizeof (struct timeval)); - if (u.u_error) - return; - adjust = (atv.tv_sec * hz) + (atv.tv_usec / usechz); - /* if unstoreable values, just set the clock */ - if (adjust > 0x7fff || adjust < 0x8000) { - s = splclock(); - time.tv_sec += atv.tv_sec; - lbolt += atv.tv_usec / usechz; - while (lbolt >= hz) { - lbolt -= hz; - ++time.tv_sec; - } - splx(s); - if (!uap->olddelta) - return; - atv.tv_sec = atv.tv_usec = 0; - } else { - if (!uap->olddelta) { - adjdelta = adjust; - return; - } - atv.tv_sec = adjdelta / hz; - atv.tv_usec = (adjdelta % hz) * usechz; - adjdelta = adjust; - } - u.u_error = copyout ((caddr_t) &atv, (caddr_t) uap->olddelta, - sizeof (struct timeval)); + if (!suser()) + return; + u.u_error = copyin((caddr_t)uap->delta, (caddr_t)&atv, + sizeof (struct timeval)); + if (u.u_error) + return; + adjust = (atv.tv_sec * hz) + (atv.tv_usec / usechz); + /* if unstoreable values, just set the clock */ + if (adjust > 0x7fff || adjust < 0x8000) { + s = splclock(); + time.tv_sec += atv.tv_sec; + lbolt += atv.tv_usec / usechz; + while (lbolt >= hz) { + lbolt -= hz; + ++time.tv_sec; + } + splx(s); + if (!uap->olddelta) + return; + atv.tv_sec = atv.tv_usec = 0; + } else { + if (!uap->olddelta) { + adjdelta = adjust; + return; + } + atv.tv_sec = adjdelta / hz; + atv.tv_usec = (adjdelta % hz) * usechz; + adjdelta = adjust; + } + u.u_error = copyout ((caddr_t) &atv, (caddr_t) uap->olddelta, + sizeof (struct timeval)); } void getitimer() { - register struct a { - u_int which; - struct itimerval *itv; - } *uap = (struct a *)u.u_arg; - struct itimerval aitv; - register int s; + register struct a { + u_int which; + struct itimerval *itv; + } *uap = (struct a *)u.u_arg; + struct itimerval aitv; + register int s; - if (uap->which > ITIMER_PROF) { - u.u_error = EINVAL; - return; - } - aitv.it_interval.tv_usec = 0; - aitv.it_value.tv_usec = 0; - s = splclock(); - if (uap->which == ITIMER_REAL) { - register struct proc *p = u.u_procp; + if (uap->which > ITIMER_PROF) { + u.u_error = EINVAL; + return; + } + aitv.it_interval.tv_usec = 0; + aitv.it_value.tv_usec = 0; + s = splclock(); + if (uap->which == ITIMER_REAL) { + register struct proc *p = u.u_procp; - aitv.it_interval.tv_sec = p->p_realtimer.it_interval; - aitv.it_value.tv_sec = p->p_realtimer.it_value; - } else { - register struct k_itimerval *t = &u.u_timer[uap->which - 1]; + aitv.it_interval.tv_sec = p->p_realtimer.it_interval; + aitv.it_value.tv_sec = p->p_realtimer.it_value; + } else { + register struct k_itimerval *t = &u.u_timer[uap->which - 1]; - aitv.it_interval.tv_sec = t->it_interval / hz; - aitv.it_value.tv_sec = t->it_value / hz; - } - splx(s); - u.u_error = copyout ((caddr_t)&aitv, (caddr_t)uap->itv, - sizeof (struct itimerval)); + aitv.it_interval.tv_sec = t->it_interval / hz; + aitv.it_value.tv_sec = t->it_value / hz; + } + splx(s); + u.u_error = copyout ((caddr_t)&aitv, (caddr_t)uap->itv, + sizeof (struct itimerval)); } void setitimer() { - register struct a { - u_int which; - struct itimerval *itv, *oitv; - } *uap = (struct a *)u.u_arg; - struct itimerval aitv; - register struct itimerval *aitvp; - int s; + register struct a { + u_int which; + struct itimerval *itv, *oitv; + } *uap = (struct a *)u.u_arg; + struct itimerval aitv; + register struct itimerval *aitvp; + int s; - if (uap->which > ITIMER_PROF) { - u.u_error = EINVAL; - return; - } - aitvp = uap->itv; - if (uap->oitv) { - uap->itv = uap->oitv; - getitimer(); - } - if (aitvp == 0) - return; - u.u_error = copyin((caddr_t)aitvp, (caddr_t)&aitv, - sizeof (struct itimerval)); - if (u.u_error) - return; - s = splclock(); - if (uap->which == ITIMER_REAL) { - register struct proc *p = u.u_procp; + if (uap->which > ITIMER_PROF) { + u.u_error = EINVAL; + return; + } + aitvp = uap->itv; + if (uap->oitv) { + uap->itv = uap->oitv; + getitimer(); + } + if (aitvp == 0) + return; + u.u_error = copyin((caddr_t)aitvp, (caddr_t)&aitv, + sizeof (struct itimerval)); + if (u.u_error) + return; + s = splclock(); + if (uap->which == ITIMER_REAL) { + register struct proc *p = u.u_procp; - p->p_realtimer.it_value = aitv.it_value.tv_sec; - if (aitv.it_value.tv_usec) - ++p->p_realtimer.it_value; - p->p_realtimer.it_interval = aitv.it_interval.tv_sec; - if (aitv.it_interval.tv_usec) - ++p->p_realtimer.it_interval; - } else { - register struct k_itimerval *t = &u.u_timer[uap->which - 1]; + p->p_realtimer.it_value = aitv.it_value.tv_sec; + if (aitv.it_value.tv_usec) + ++p->p_realtimer.it_value; + p->p_realtimer.it_interval = aitv.it_interval.tv_sec; + if (aitv.it_interval.tv_usec) + ++p->p_realtimer.it_interval; + } else { + register struct k_itimerval *t = &u.u_timer[uap->which - 1]; - t->it_value = aitv.it_value.tv_sec * hz; - if (aitv.it_value.tv_usec) - t->it_value += hz; - t->it_interval = aitv.it_interval.tv_sec * hz; - if (aitv.it_interval.tv_usec) - t->it_interval += hz; - } - splx(s); + t->it_value = aitv.it_value.tv_sec * hz; + if (aitv.it_value.tv_usec) + t->it_value += hz; + t->it_interval = aitv.it_interval.tv_sec * hz; + if (aitv.it_interval.tv_usec) + t->it_interval += hz; + } + splx(s); } /* @@ -246,14 +246,14 @@ setitimer() */ int itimerfix(tv) - struct timeval *tv; + struct timeval *tv; { - if (tv->tv_sec < 0 || tv->tv_sec > 100000000L || - tv->tv_usec < 0 || tv->tv_usec >= 1000000L) - return (EINVAL); - if (tv->tv_sec == 0 && tv->tv_usec != 0 && tv->tv_usec < (1000/hz)) - tv->tv_usec = 1000/hz; - return (0); + if (tv->tv_sec < 0 || tv->tv_sec > 100000000L || + tv->tv_usec < 0 || tv->tv_usec >= 1000000L) + return (EINVAL); + if (tv->tv_sec == 0 && tv->tv_usec != 0 && tv->tv_usec < (1000/hz)) + tv->tv_usec = 1000/hz; + return (0); } #ifdef NOT_CURRENTLY_IN_USE @@ -268,50 +268,50 @@ itimerfix(tv) * on which it is operating cannot change in value. */ itimerdecr(itp, usec) - register struct itimerval *itp; - int usec; + register struct itimerval *itp; + int usec; { - if (itp->it_value.tv_usec < usec) { - if (itp->it_value.tv_sec == 0) { - /* expired, and already in next interval */ - usec -= itp->it_value.tv_usec; - goto expire; - } - itp->it_value.tv_usec += 1000000L; - itp->it_value.tv_sec--; - } - itp->it_value.tv_usec -= usec; - usec = 0; - if (timerisset(&itp->it_value)) - return (1); - /* expired, exactly at end of interval */ + if (itp->it_value.tv_usec < usec) { + if (itp->it_value.tv_sec == 0) { + /* expired, and already in next interval */ + usec -= itp->it_value.tv_usec; + goto expire; + } + itp->it_value.tv_usec += 1000000L; + itp->it_value.tv_sec--; + } + itp->it_value.tv_usec -= usec; + usec = 0; + if (timerisset(&itp->it_value)) + return (1); + /* expired, exactly at end of interval */ expire: - if (timerisset(&itp->it_interval)) { - itp->it_value = itp->it_interval; - itp->it_value.tv_usec -= usec; - if (itp->it_value.tv_usec < 0) { - itp->it_value.tv_usec += 1000000L; - itp->it_value.tv_sec--; - } - } else - itp->it_value.tv_usec = 0; /* sec is already 0 */ - return (0); + if (timerisset(&itp->it_interval)) { + itp->it_value = itp->it_interval; + itp->it_value.tv_usec -= usec; + if (itp->it_value.tv_usec < 0) { + itp->it_value.tv_usec += 1000000L; + itp->it_value.tv_sec--; + } + } else + itp->it_value.tv_usec = 0; /* sec is already 0 */ + return (0); } #endif /* NOT_CURRENTLY_IN_USE */ static void tvfix(t1) - struct timeval *t1; + struct timeval *t1; { - if (t1->tv_usec < 0) { - t1->tv_sec--; - t1->tv_usec += 1000000L; - } - if (t1->tv_usec >= 1000000L) { - t1->tv_sec++; - t1->tv_usec -= 1000000L; - } + if (t1->tv_usec < 0) { + t1->tv_sec--; + t1->tv_usec += 1000000L; + } + if (t1->tv_usec >= 1000000L) { + t1->tv_sec++; + t1->tv_usec -= 1000000L; + } } /* @@ -323,20 +323,20 @@ tvfix(t1) */ void timevaladd(t1, t2) - struct timeval *t1, *t2; + struct timeval *t1, *t2; { - t1->tv_sec += t2->tv_sec; - t1->tv_usec += t2->tv_usec; - tvfix(t1); + t1->tv_sec += t2->tv_sec; + t1->tv_usec += t2->tv_usec; + tvfix(t1); } #ifdef NOT_CURRENTLY_IN_USE void timevalsub(t1, t2) - struct timeval *t1, *t2; + struct timeval *t1, *t2; { - t1->tv_sec -= t2->tv_sec; - t1->tv_usec -= t2->tv_usec; - tvfix(t1); + t1->tv_sec -= t2->tv_sec; + t1->tv_usec -= t2->tv_usec; + tvfix(t1); } #endif diff --git a/sys/kernel/rdisk.c b/sys/kernel/rdisk.c index 6752eaf..6631c10 100644 --- a/sys/kernel/rdisk.c +++ b/sys/kernel/rdisk.c @@ -66,30 +66,30 @@ const struct devspec rd3devs[] = { { 0, "rd3" }, { 1, "rd3a" }, { 2, "rd3b" }, { const struct diskentry disks[] = { - {sd_preinit, sdinit, sddeinit, sdopen, sdsize, card_read, card_write, 0, RD_DEFAULT}, + {sd_preinit, sdinit, sddeinit, sdopen, sdsize, card_read, card_write, 0, RD_DEFAULT}, #ifdef SD1_PORT - {sd_preinit, sdinit, sddeinit, sdopen, sdsize, card_read, card_write, 1, RD_DEFAULT}, + {sd_preinit, sdinit, sddeinit, sdopen, sdsize, card_read, card_write, 1, RD_DEFAULT}, #endif #ifdef SRAMC_ENABLED - {sramc_init, no_init, no_deinit, sramc_open, sramc_size, sramc_read, sramc_write, 0, RD_PREPART}, + {sramc_init, no_init, no_deinit, sramc_open, sramc_size, sramc_read, sramc_write, 0, RD_PREPART}, #endif #ifdef SDRAMP_ENABLED - {sdramp_preinit, no_init, no_deinit, sdramp_open, sdramp_size, sdramp_read, sdramp_write, 0, RD_PREPART}, + {sdramp_preinit, no_init, no_deinit, sdramp_open, sdramp_size, sdramp_read, sdramp_write, 0, RD_PREPART}, #endif #ifdef FLASH_ENABLED - {flash_init, no_init, no_deinit, flash_open, flash_size, flash_read, flash_write, 0, RD_READONLY}, + {flash_init, no_init, no_deinit, flash_open, flash_size, flash_read, flash_write, 0, RD_READONLY}, #endif #ifdef MRAMS_ENABLED - {mrams_preinit, no_init, no_deinit, no_open, mrams_size, mrams_read, mrams_write, 0, RD_DEFAULT}, + {mrams_preinit, no_init, no_deinit, no_open, mrams_size, mrams_read, mrams_write, 0, RD_DEFAULT}, #endif #ifdef SPIRAMS_ENABLED - {spirams_preinit, no_init, no_deinit, no_open, spirams_size, spirams_read, spirams_write, 0, RD_DEFAULT}, + {spirams_preinit, no_init, no_deinit, no_open, spirams_size, spirams_read, spirams_write, 0, RD_DEFAULT}, #endif }; @@ -105,300 +105,293 @@ struct diskflags dflags[NRDSK]; static inline struct buf *read_mbr(int root) { - if(root>MAXDEV) return NULL; + if (root > MAXDEV) + return NULL; - int rv; - int unit = disks[root].unit; + int rv; + int unit = disks[root].unit; - struct buf *bp = getnewbuf(); + struct buf *bp = getnewbuf(); - DEBUG8("rd%d: read mbr from device %d\n",root,unit); - rv = disks[root].read(unit,0,bp->b_addr,512); - if(rv==0) - { - DEBUG8("rd%d: mbr read FAIL\n",root); - brelse(buf); - return NULL; - } - DEBUG8("rd%d: mbr read OK\n",root); + DEBUG8("rd%d: read mbr from device %d\n",root,unit); + rv = disks[root].read(unit,0,bp->b_addr,512); + if (rv == 0) { + DEBUG8("rd%d: mbr read FAIL\n",root); + brelse(buf); + return NULL; + } + DEBUG8("rd%d: mbr read OK\n",root); - return bp; + return bp; } static inline int init_device(int root,int flag) { - int i; - int e; - if(root>MAXDEV) return ENODEV; + int i, e, unit; + struct buf *bp; + struct mbr *mbr; - struct buf *bp; - struct mbr *mbr; + if (root > MAXDEV) + return ENODEV; + unit = disks[root].unit; - int unit = disks[root].unit; + e = disks[root].init(unit, flag); + if (e != 0) + return e; - e = disks[root].init(unit,flag); + DEBUG8("rd%d: about to read mbr\n",root); + bp = read_mbr(root); + if (! bp) + return ENXIO; + DEBUG8("rd%d: mbr read\n", root); + mbr = (struct mbr *)bp->b_addr; - if(e!=0) - return e; + DEBUG5("rd%d: partition types: %02X %02X %02X %02X\n",root, + mbr->partitions[0].type, + mbr->partitions[1].type, + mbr->partitions[2].type, + mbr->partitions[3].type + ); + DEBUG8("rd%d: partition 1 start: %p length: %p\n",root, + mbr->partitions[0].lbastart, mbr->partitions[0].lbalength + ); + DEBUG8("rd%d: partition 2 start: %p length: %p\n",root, + mbr->partitions[1].lbastart, mbr->partitions[1].lbalength + ); + DEBUG8("rd%d: partition 3 start: %p length: %p\n",root, + mbr->partitions[2].lbastart, mbr->partitions[2].lbalength + ); + DEBUG8("rd%d: partition 4 start: %p length: %p\n",root, + mbr->partitions[3].lbastart, mbr->partitions[3].lbalength + ); - DEBUG8("rd%d: about to read mbr\n",root); - bp = read_mbr(root); - if(!bp) - return ENXIO; - DEBUG8("rd%d: mbr read\n",root); - - mbr = (struct mbr *)bp->b_addr; - - DEBUG5("rd%d: partition types: %02X %02X %02X %02X\n",root, - mbr->partitions[0].type, - mbr->partitions[1].type, - mbr->partitions[2].type, - mbr->partitions[3].type - ); - DEBUG8("rd%d: partition 1 start: %p length: %p\n",root, - mbr->partitions[0].lbastart, mbr->partitions[0].lbalength - ); - DEBUG8("rd%d: partition 2 start: %p length: %p\n",root, - mbr->partitions[1].lbastart, mbr->partitions[1].lbalength - ); - DEBUG8("rd%d: partition 3 start: %p length: %p\n",root, - mbr->partitions[2].lbastart, mbr->partitions[2].lbalength - ); - DEBUG8("rd%d: partition 4 start: %p length: %p\n",root, - mbr->partitions[3].lbastart, mbr->partitions[3].lbalength - ); - - for(i=0; i<4; i++) - { - struct partition part = mbr->partitions[i]; - dflags[root].start[i] = part.lbastart >> 1; - dflags[root].len[i] = part.lbalength >> 1; - } - dflags[root].blocks = disks[root].size(unit); - brelse(bp); - return 0; + for (i=0; i<4; i++) { + struct partition part = mbr->partitions[i]; + dflags[root].start[i] = part.lbastart >> 1; + dflags[root].len[i] = part.lbalength >> 1; + } + dflags[root].blocks = disks[root].size(unit); + brelse(bp); + return 0; } static inline int deinit_device(int root) { - if(root>MAXDEV) return ENODEV; - return disks[root].deinit(disks[root].unit); + if (root > MAXDEV) + return ENODEV; + return disks[root].deinit(disks[root].unit); } static inline int open_device(int root, int flag) { - int e; - if(root>MAXDEV) return ENODEV; + int e; + if (root > MAXDEV) + return ENODEV; - DEBUG3("rd%d: opening\n",root); - if(dflags[root].opens==0) - { - DEBUG3("rd%d: init device\n",root); - e = init_device(root, flag); - if(e!=0) - return e; - } - dflags[root].opens++; + DEBUG3("rd%d: opening\n",root); + if (dflags[root].opens==0) { + DEBUG3("rd%d: init device\n",root); + e = init_device(root, flag); + if (e != 0) + return e; + } + dflags[root].opens++; - DEBUG3("rd%d: opened: %d\n",root,dflags[root].opens); - return 0; + DEBUG3("rd%d: opened: %d\n",root,dflags[root].opens); + return 0; } static inline int close_device(int root) { - if(root>MAXDEV) return ENODEV; - if(dflags[root].opens==0) - return ENXIO; - dflags[root].opens--; - if(dflags[root].opens==0) - { - deinit_device(root); - } - DEBUG3("rd%d: closed: %d\n",root,dflags[root].opens); - return 0; + if (root > MAXDEV) + return ENODEV; + if (dflags[root].opens == 0) + return ENXIO; + dflags[root].opens--; + if (dflags[root].opens == 0) { + deinit_device(root); + } + DEBUG3("rd%d: closed: %d\n",root,dflags[root].opens); + return 0; } int rdopen(dev_t dev, int mode, int flag) { - int e; - int root = major(dev); - if(root>MAXDEV) return ENODEV; + int root = major(dev); + if (root > MAXDEV) + return ENODEV; - int unit = disks[root].unit; + int unit = disks[root].unit; + int e = open_device(root, flag); + if (e != 0) + return e; - e=open_device(root,flag); - if(e!=0) - return e; - e=disks[root].open(unit,mode,flag); - if(e!=0) - return e; - - return 0; + e = disks[root].open(unit, mode, flag); + if (e != 0) + return e; + return 0; } int rdclose(dev_t dev, int mode, int flag) { - int root = major(dev); - if(root>MAXDEV) return ENODEV; - close_device(root); - return 0; + int root = major(dev); + if (root > MAXDEV) + return ENODEV; + close_device(root); + return 0; } daddr_t rdsize(dev_t dev) { - int root = major(dev); - if(root>MAXDEV) return ENODEV; + int root = major(dev); + if (root > MAXDEV) + return ENODEV; - int part = minor(dev); - int unit = disks[root].unit; - unsigned int blocks; + int part = minor(dev); + int unit = disks[root].unit; + unsigned int blocks; - if(part==0) - { - return disks[root].size(unit); - } else { - if(rdopen(dev,0,S_SILENT)!=0) - return 0; - blocks=dflags[root].len[part-1]; - rdclose(dev,0,0); - DEBUG3("rd%d%c: get partition size: %d\n",root,part+'a'-1,blocks); - return blocks; - } + if (part == 0) { + return disks[root].size(unit); + } + + if (rdopen(dev,0,S_SILENT) != 0) + return 0; + blocks = dflags[root].len[part-1]; + rdclose(dev, 0, 0); + DEBUG3("rd%d%c: get partition size: %d\n",root,part+'a'-1,blocks); + return blocks; } void rdstrategy(register struct buf *bp) { - int root = major(bp->b_dev); + int root = major(bp->b_dev); static int mutex = 0; - if(root>MAXDEV) return; + if (root > MAXDEV) + return; mutex++; - if(mutex>1) - { - led_control(LED_SWAP,1); + if (mutex > 1) { + led_control(LED_SWAP, 1); } else { - led_control(LED_DISK,0); + led_control(LED_DISK, 0); } - int part = minor(bp->b_dev); - int unit = disks[root].unit; + int part = minor(bp->b_dev); + int unit = disks[root].unit; - int offset=0; - int s; + int offset=0; + int s; - if(part>0) - offset = dflags[root].start[part-1]; + if (part > 0) + offset = dflags[root].start[part-1]; - offset += (bp->b_blkno); + offset += (bp->b_blkno); if (bp->b_dev == swapdev) { - led_control(LED_SWAP,1); + led_control(LED_SWAP, 1); } else { - led_control(LED_DISK,1); + led_control(LED_DISK, 1); } s = splbio(); #ifdef UCB_METER - if (rddk >= 0) { - dk_busy |= 1 << (rddk + root); - dk_xfer[rddk + root]++; - dk_bytes[rddk + root] += bp->b_bcount; - } + if (rddk >= 0) { + dk_busy |= 1 << (rddk + root); + dk_xfer[rddk + root]++; + dk_bytes[rddk + root] += bp->b_bcount; + } #endif - if (bp->b_flags & B_READ) { - disks[root].read(unit, offset, bp->b_addr, bp->b_bcount); - } else { - if(!(disks[root].settings & RD_READONLY)) - disks[root].write(unit, offset, bp->b_addr, bp->b_bcount); - } - - biodone(bp); - if (bp->b_dev == swapdev) { - led_control(LED_SWAP,0); + if (bp->b_flags & B_READ) { + disks[root].read(unit, offset, bp->b_addr, bp->b_bcount); } else { - led_control(LED_DISK,0); + if (! (disks[root].settings & RD_READONLY)) + disks[root].write(unit, offset, bp->b_addr, bp->b_bcount); } - splx(s); + + biodone(bp); + if (bp->b_dev == swapdev) { + led_control(LED_SWAP, 0); + } else { + led_control(LED_DISK, 0); + } + splx(s); mutex--; } void update_mbr(int unit) { - + //TODO } int rdioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag) { - int *val; + int *val; - val = (int *)addr; + val = (int *)addr; - if(cmd == RDGETMEDIASIZE) - { - *val = rdsize(dev); - } - if(cmd == RDREINIT) - { - bflush(major(dev)); - init_device(major(dev),S_SILENT); + if (cmd == RDGETMEDIASIZE) { + *val = rdsize(dev); + } + if (cmd == RDREINIT) { + bflush(major(dev)); + init_device(major(dev), S_SILENT); - } - return 0; + } + return 0; } void rdisk_init() { - int i; + int i; - //printf("Prepartition Schema: %s\n",prepartition_schema); + //printf("Prepartition Schema: %s\n",prepartition_schema); #ifdef UCB_METER - dk_alloc(&rddk,NRDSK,"rd"); + dk_alloc(&rddk, NRDSK, "rd"); #endif - for(i=0; ib_addr; - for(j=1; j<5; j++) - { - if(mbr->partitions[j-1].type==type) - { - printf(" rd%d%c: %d KB\n",i,'a'+j-1,rdsize(makedev(i,j))); - } - } - brelse(bp); - } + int i,j; + int e; + struct buf *bp; + struct mbr *mbr; + + for (i=0; ib_addr; + for (j=1; j<5; j++) { + if (mbr->partitions[j-1].type == type) { + printf(" rd%d%c: %d KB\n",i,'a'+j-1,rdsize(makedev(i,j))); + } + } + brelse(bp); + } } int rdisk_num_disks() { - return NRDSK; + return NRDSK; } dev_t get_boot_device() @@ -406,42 +399,35 @@ dev_t get_boot_device() // If a root device has been specified, then we can short cut all this and just // use that device. #ifdef ROOT - return ROOT; + return ROOT; #else - dev_t bd = -1; - int i,j,e; - struct buf *bp; - struct mbr *mbr; + dev_t bd = -1; + int i, j, e; + struct buf *bp; + struct mbr *mbr; - for(i=0; ib_addr; + for (i=0; ib_addr; - for(j=0; j<4; j++) - { - if(mbr->partitions[j].type==RDISK_FS) - { - if(mbr->partitions[j].status & P_ACTIVE) - { - brelse(bp); - rdclose(makedev(i,0),0,0); - return makedev(i,j+1); - } - } - } - brelse(bp); - } - rdclose(makedev(i,0),0,0); - } - } - - return bd; + for (j=0; j<4; j++) { + if (mbr->partitions[j].type == RDISK_FS) { + if (mbr->partitions[j].status & P_ACTIVE) { + brelse(bp); + rdclose(makedev(i, 0), 0, 0); + return makedev(i, j+1); + } + } + } + brelse(bp); + } + rdclose(makedev(i, 0), 0, 0); + } + } + return bd; #endif } @@ -450,243 +436,223 @@ dev_t get_swap_device() // If a swap device has been specified, then we can short cut all this and just // use that device. #ifdef SWAP - return SWAP; + return SWAP; #else - dev_t bd = -1; - int i,j,e; - unsigned int max_size = 0; - struct buf *bp; - struct mbr *mbr; + dev_t bd = -1; + int i, j, e; + unsigned int max_size = 0; + struct buf *bp; + struct mbr *mbr; - // First we look for the first active swap device + // First we look for the first active swap device - for(i=0; ib_addr; + for (i=0; ib_addr; - for(j=0; j<4; j++) - { - if(mbr->partitions[j].type==RDISK_SWAP) - { - // If this partition is the biggest so far - // then store it. We'll use this if - // there is no active partition. - if(mbr->partitions[j].lbalength>max_size) - { - max_size = mbr->partitions[j].lbalength; - bd = makedev(i,j+1); - } + for (j=0; j<4; j++) { + if (mbr->partitions[j].type == RDISK_SWAP) { + // If this partition is the biggest so far + // then store it. We'll use this if + // there is no active partition. + if (mbr->partitions[j].lbalength > max_size) { + max_size = mbr->partitions[j].lbalength; + bd = makedev(i, j+1); + } - // If it is active, then use it. - if(mbr->partitions[j].status & P_ACTIVE) - { - brelse(bp); - rdclose(makedev(i,0),0,0); - return makedev(i,j+1); - } - } - } - brelse(bp); - } - rdclose(makedev(i,0),0,0); - } - } + // If it is active, then use it. + if (mbr->partitions[j].status & P_ACTIVE) { + brelse(bp); + rdclose(makedev(i, 0), 0, 0); + return makedev(i, j+1); + } + } + } + brelse(bp); + } + rdclose(makedev(i, 0), 0, 0); + } + } - // There is no active partition, so we'll use the biggest one we found. - return bd; + // There is no active partition, so we'll use the biggest one we found. + return bd; #endif } unsigned char partition_type(dev_t dev) { - struct buf *bp; - struct mbr *mbr; - unsigned char pt; + struct buf *bp; + struct mbr *mbr; + unsigned char pt; - if(minor(dev)<1 || minor(dev)>4) - return 0; - if(rdopen(dev,0,S_SILENT)==0) - { - bp = read_mbr(major(dev)); - rdclose(dev,0,0); - if(!bp) - { - brelse(bp); - return 0; - } - mbr = (struct mbr *)bp->b_addr; - pt = mbr->partitions[minor(dev)-1].type; - brelse(bp); - return pt; - } - return 0; + if (minor(dev)<1 || minor(dev)>4) + return 0; + + if (rdopen(dev,0,S_SILENT) == 0) { + bp = read_mbr(major(dev)); + rdclose(dev, 0, 0); + if (! bp) { + brelse(bp); + return 0; + } + mbr = (struct mbr *)bp->b_addr; + pt = mbr->partitions[minor(dev)-1].type; + brelse(bp); + return pt; + } + return 0; } int atoi(char *s) { - int i = 0; - char *q; - for(q=s; *q; q++) - { - if(*q < '0' || *q > '9') - { - return i; - } - i = i * 10; - i += *q - '0'; - } - return i; + int i = 0; + char *q; + + for (q=s; *q; q++) { + if (*q < '0' || *q > '9') { + return i; + } + i = i * 10; + i += *q - '0'; + } + return i; } int strcmp(char *s1, char *s2) { - char *p1,*p2; - p1 = s1; - p2 = s2; - while(*p1 && *p2) - { - if(*p1 < *p2) return -1; - if(*p1 > *p2) return 1; - p1++; - p2++; - } - if(*p1 < *p2) return -1; - if(*p1 > *p2) return 1; - return 0; + char *p1,*p2; + p1 = s1; + p2 = s2; + + while (*p1 && *p2) { + if (*p1 < *p2) + return -1; + if (*p1 > *p2) + return 1; + p1++; + p2++; + } + if (*p1 < *p2) + return -1; + if (*p1 > *p2) + return 1; + return 0; } /* - -Prepartition format: - -mrams0:fs@1024,swap@2048,fs@1022 sdramp0:... - -*/ - + * Prepartition format: + * mrams0:fs@1024,swap@2048,fs@1022 sdramp0:... + */ struct buf *prepartition_device(char *devname) { #ifndef PARTITION - char *prepartition_schema = ""; + char *prepartition_schema = ""; #else - char *prepartition_schema = (char *)QUOTE(PARTITION); + char *prepartition_schema = (char *)QUOTE(PARTITION); #endif - char *p,*q; - struct buf *bp; - struct mbr *mbr; - int pnum = 0; - int start = 2; - char dev[9]; - char size[9]; - char type[5]; - int pos = 0; + char *p,*q; + struct buf *bp; + struct mbr *mbr; + int pnum = 0; + int start = 2; + char dev[9]; + char size[9]; + char type[5]; + int pos = 0; - p = prepartition_schema+1; - q = p; + p = prepartition_schema+1; + q = p; - printf("PP Schema: %s\n",prepartition_schema); + printf("PP Schema: %s\n",prepartition_schema); - bp = getnewbuf(); - if(!bp) - { - return NULL; - } + bp = getnewbuf(); + if (! bp) { + return NULL; + } - mbr = (struct mbr *)bp->b_addr; + mbr = (struct mbr *)bp->b_addr; - while(*p) - { - while(*q && *q != ' ') - q++; - if(*q == ' ') - { - *q = 0; - q++; - } + while (*p) { + while (*q && *q != ' ') + q++; + if (*q == ' ') { + *q = 0; + q++; + } - pos = 0; - while((*p) && (*p != ':')) - { - dev[pos++] = *p; - dev[pos] = 0; - p++; - } + pos = 0; + while (*p && *p != ':') { + dev[pos++] = *p; + dev[pos] = 0; + p++; + } - if((*p) == ':') - { - p++; - } else { - printf("Device Format Error (%c)\n",*p); - brelse(bp); - return NULL; - } + if (*p == ':') { + p++; + } else { + printf("Device Format Error (%c)\n",*p); + brelse(bp); + return NULL; + } - while((*p) && (*p != ' ')) - { - pos = 0; - while((*p) && (*p != '@')) - { - type[pos++] = *p; - type[pos] = 0; - p++; - } + while (*p && *p != ' ') { + pos = 0; + while (*p && *p != '@') { + type[pos++] = *p; + type[pos] = 0; + p++; + } - if((*p) == '@') - { - p++; - } else { - printf("Type Format Error\n"); - brelse(bp); - return NULL; - } + if (*p == '@') { + p++; + } else { + printf("Type Format Error\n"); + brelse(bp); + return NULL; + } - pos = 0; - while((*p) && (*p != ',') && (*p != ' ') && (*p != ')')) - { - size[pos++] = *p; - size[pos] = 0; - p++; - } + pos = 0; + while (*p && *p != ',' && *p != ' ' && *p != ')') { + size[pos++] = *p; + size[pos] = 0; + p++; + } - printf("Found partition on %s of type %s and size %s\n", - dev,type,size); + printf("Found partition on %s of type %s and size %s\n", + dev,type,size); - if(!strcmp(dev,devname)) - { - if(!strcmp("sw",type)) - mbr->partitions[pnum].type=RDISK_SWAP; - if(!strcmp("sa",type)) - { - mbr->partitions[pnum].type=RDISK_SWAP; - mbr->partitions[pnum].status = 0x80; - } - if(!strcmp("fs",type)) - mbr->partitions[pnum].type=RDISK_FS; + if (strcmp(dev, devname) == 0) { + if (strcmp("sw", type) == 0) + mbr->partitions[pnum].type = RDISK_SWAP; - mbr->partitions[pnum].lbastart = start; - mbr->partitions[pnum].lbalength = atoi(size)<<1; - start += mbr->partitions[pnum].lbalength; - pnum++; - } - p++; - } - } + if (strcmp("sa", type) == 0) { + mbr->partitions[pnum].type = RDISK_SWAP; + mbr->partitions[pnum].status = 0x80; + } + if (strcmp("fs", type) == 0) + mbr->partitions[pnum].type = RDISK_FS; - if(pnum > 0) - { - mbr->bootsig = 0xAA55; - mbr->biosdrive = 0x80; - mbr->sig = 'R'<<24 | 'T'<<16 | 'E'<<8 | 'R'; - return bp; - } + mbr->partitions[pnum].lbastart = start; + mbr->partitions[pnum].lbalength = atoi(size)<<1; + start += mbr->partitions[pnum].lbalength; + pnum++; + } + p++; + } + } - brelse(bp); - return NULL; + if (pnum > 0) { + mbr->bootsig = 0xAA55; + mbr->biosdrive = 0x80; + mbr->sig = 'R'<<24 | 'T'<<16 | 'E'<<8 | 'R'; + return bp; + } + + brelse(bp); + return NULL; } diff --git a/sys/kernel/subr_log.c b/sys/kernel/subr_log.c index d7251d6..a45d936 100644 --- a/sys/kernel/subr_log.c +++ b/sys/kernel/subr_log.c @@ -16,8 +16,8 @@ * error logging daemon. */ -#define NLOG 1 -int nlog = 1; +#define NLOG 1 +int nlog = 1; #include "param.h" #include "user.h" @@ -37,51 +37,51 @@ const struct devspec logdevs[] = { { 0, 0 } }; -#define LOG_RDPRI (PZERO + 1) +#define LOG_RDPRI (PZERO + 1) -#define LOG_OPEN 0x01 -#define LOG_ASYNC 0x04 -#define LOG_RDWAIT 0x08 +#define LOG_OPEN 0x01 +#define LOG_ASYNC 0x04 +#define LOG_RDWAIT 0x08 -struct msgbuf msgbuf[NLOG]; +struct msgbuf msgbuf[NLOG]; static struct logsoftc { - int sc_state; /* see above for possibilities */ - struct proc *sc_selp; /* process waiting on select call */ - int sc_pgid; /* process/group for async I/O */ - int sc_overrun; /* full buffer count */ + int sc_state; /* see above for possibilities */ + struct proc *sc_selp; /* process waiting on select call */ + int sc_pgid; /* process/group for async I/O */ + int sc_overrun; /* full buffer count */ } logsoftc[NLOG]; /*ARGSUSED*/ int logopen(dev, mode, unused) - dev_t dev; - int mode; + dev_t dev; + int mode; { - register int unit = minor(dev); + register int unit = minor(dev); - if (unit >= NLOG) - return(ENODEV); - if (logisopen(unit)) - return(EBUSY); - if (msgbuf[unit].msg_bufc == 0) /* no buffer allocated */ - return(ENOMEM); - logsoftc[unit].sc_state |= LOG_OPEN; - logsoftc[unit].sc_pgid = u.u_procp->p_pid; /* signal process only */ - logsoftc[unit].sc_overrun = 0; - return(0); + if (unit >= NLOG) + return(ENODEV); + if (logisopen(unit)) + return(EBUSY); + if (msgbuf[unit].msg_bufc == 0) /* no buffer allocated */ + return(ENOMEM); + logsoftc[unit].sc_state |= LOG_OPEN; + logsoftc[unit].sc_pgid = u.u_procp->p_pid; /* signal process only */ + logsoftc[unit].sc_overrun = 0; + return(0); } /*ARGSUSED*/ int logclose(dev, flag, unused) - dev_t dev; - int flag; + dev_t dev; + int flag; { - register int unit = minor(dev); + register int unit = minor(dev); - logsoftc[unit].sc_state = 0; - return(0); + logsoftc[unit].sc_state = 0; + return(0); } /* @@ -90,172 +90,172 @@ logclose(dev, flag, unused) */ int logisopen(unit) - int unit; + int unit; { - if (logsoftc[unit].sc_state & LOG_OPEN) - return(1); - return(0); + if (logsoftc[unit].sc_state & LOG_OPEN) + return(1); + return(0); } /*ARGSUSED*/ int logread(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; + dev_t dev; + struct uio *uio; + int flag; { - register int l; - register struct logsoftc *lp; - register struct msgbuf *mp; - int s, error = 0; - char buf [128]; + register int l; + register struct logsoftc *lp; + register struct msgbuf *mp; + int s, error = 0; + char buf [128]; - l = minor(dev); - lp = &logsoftc[l]; - mp = &msgbuf[l]; - s = splhigh(); - while (mp->msg_bufr == mp->msg_bufx) { - if (flag & IO_NDELAY) { - splx(s); - return(EWOULDBLOCK); - } - lp->sc_state |= LOG_RDWAIT; - sleep((caddr_t)mp, LOG_RDPRI); - } - lp->sc_state &= ~LOG_RDWAIT; + l = minor(dev); + lp = &logsoftc[l]; + mp = &msgbuf[l]; + s = splhigh(); + while (mp->msg_bufr == mp->msg_bufx) { + if (flag & IO_NDELAY) { + splx(s); + return(EWOULDBLOCK); + } + lp->sc_state |= LOG_RDWAIT; + sleep((caddr_t)mp, LOG_RDPRI); + } + lp->sc_state &= ~LOG_RDWAIT; - while (uio->uio_resid) { - l = mp->msg_bufx - mp->msg_bufr; - /* - * If the reader and writer are equal then we have caught up and there - * is nothing more to transfer. - */ - if (l == 0) - break; - /* - * If the write pointer is behind the reader then only consider as - * available for now the bytes from the read pointer thru the end of - * the buffer. - */ - if (l < 0) { - l = MSG_BSIZE - mp->msg_bufr; - /* - * If the reader is exactly at the end of the buffer it is - * time to wrap it around to the beginning and recalculate the - * amount of data to transfer. - */ - if (l == 0) { - mp->msg_bufr = 0; - continue; - } - } - l = MIN (l, uio->uio_resid); - l = MIN (l, sizeof buf); - bcopy (&mp->msg_bufc[mp->msg_bufr], buf, l); - error = uiomove (buf, l, uio); - if (error) - break; - mp->msg_bufr += l; - } - splx(s); - return(error); + while (uio->uio_resid) { + l = mp->msg_bufx - mp->msg_bufr; + /* + * If the reader and writer are equal then we have caught up and there + * is nothing more to transfer. + */ + if (l == 0) + break; + /* + * If the write pointer is behind the reader then only consider as + * available for now the bytes from the read pointer thru the end of + * the buffer. + */ + if (l < 0) { + l = MSG_BSIZE - mp->msg_bufr; + /* + * If the reader is exactly at the end of the buffer it is + * time to wrap it around to the beginning and recalculate the + * amount of data to transfer. + */ + if (l == 0) { + mp->msg_bufr = 0; + continue; + } + } + l = MIN (l, uio->uio_resid); + l = MIN (l, sizeof buf); + bcopy (&mp->msg_bufc[mp->msg_bufr], buf, l); + error = uiomove (buf, l, uio); + if (error) + break; + mp->msg_bufr += l; + } + splx(s); + return(error); } /*ARGSUSED*/ int logselect(dev, rw) - dev_t dev; - int rw; + dev_t dev; + int rw; { - register int s = splhigh(); - int unit = minor(dev); + register int s = splhigh(); + int unit = minor(dev); - switch (rw) { - case FREAD: - if (msgbuf[unit].msg_bufr != msgbuf[unit].msg_bufx) { - splx(s); - return(1); - } - logsoftc[unit].sc_selp = u.u_procp; - break; - } - splx(s); - return(0); + switch (rw) { + case FREAD: + if (msgbuf[unit].msg_bufr != msgbuf[unit].msg_bufx) { + splx(s); + return(1); + } + logsoftc[unit].sc_selp = u.u_procp; + break; + } + splx(s); + return(0); } void logwakeup(unit) - int unit; + int unit; { - register struct proc *p; - register struct logsoftc *lp; - register struct msgbuf *mp; + register struct proc *p; + register struct logsoftc *lp; + register struct msgbuf *mp; - if (! logisopen(unit)) - return; - lp = &logsoftc[unit]; - mp = &msgbuf[unit]; - if (lp->sc_selp) { - selwakeup(lp->sc_selp, (long) 0); - lp->sc_selp = 0; - } - if (lp->sc_state & LOG_ASYNC && (mp->msg_bufx != mp->msg_bufr)) { - if (lp->sc_pgid < 0) - gsignal(-lp->sc_pgid, SIGIO); - else if ((p = pfind(lp->sc_pgid))) - psignal(p, SIGIO); - } - if (lp->sc_state & LOG_RDWAIT) { - wakeup((caddr_t)mp); - lp->sc_state &= ~LOG_RDWAIT; - } + if (! logisopen(unit)) + return; + lp = &logsoftc[unit]; + mp = &msgbuf[unit]; + if (lp->sc_selp) { + selwakeup(lp->sc_selp, (long) 0); + lp->sc_selp = 0; + } + if (lp->sc_state & LOG_ASYNC && (mp->msg_bufx != mp->msg_bufr)) { + if (lp->sc_pgid < 0) + gsignal(-lp->sc_pgid, SIGIO); + else if ((p = pfind(lp->sc_pgid))) + psignal(p, SIGIO); + } + if (lp->sc_state & LOG_RDWAIT) { + wakeup((caddr_t)mp); + lp->sc_state &= ~LOG_RDWAIT; + } } /*ARGSUSED*/ int logioctl(dev, com, data, flag) - dev_t dev; - u_int com; - caddr_t data; - int flag; + dev_t dev; + u_int com; + caddr_t data; + int flag; { - long l; - register int s; - int unit; - register struct logsoftc *lp; - register struct msgbuf *mp; + long l; + register int s; + int unit; + register struct logsoftc *lp; + register struct msgbuf *mp; - unit = minor(dev); - lp = &logsoftc[unit]; - mp = &msgbuf[unit]; + unit = minor(dev); + lp = &logsoftc[unit]; + mp = &msgbuf[unit]; - switch (com) { - case FIONREAD: - s = splhigh(); - l = mp->msg_bufx - mp->msg_bufr; - splx(s); - if (l < 0) - l += MSG_BSIZE; - *(off_t *)data = l; - break; - case FIONBIO: - break; - case FIOASYNC: - if (*(int *)data) - lp->sc_state |= LOG_ASYNC; - else - lp->sc_state &= ~LOG_ASYNC; - break; - case TIOCSPGRP: - lp->sc_pgid = *(int *)data; - break; - case TIOCGPGRP: - *(int *)data = lp->sc_pgid; - break; - default: - return(-1); - } - return(0); + switch (com) { + case FIONREAD: + s = splhigh(); + l = mp->msg_bufx - mp->msg_bufr; + splx(s); + if (l < 0) + l += MSG_BSIZE; + *(off_t *)data = l; + break; + case FIONBIO: + break; + case FIOASYNC: + if (*(int *)data) + lp->sc_state |= LOG_ASYNC; + else + lp->sc_state &= ~LOG_ASYNC; + break; + case TIOCSPGRP: + lp->sc_pgid = *(int *)data; + break; + case TIOCGPGRP: + *(int *)data = lp->sc_pgid; + break; + default: + return(-1); + } + return(0); } /* @@ -264,59 +264,59 @@ logioctl(dev, com, data, flag) */ int logwrt (buf, len, log) - char *buf; - int len; - int log; + char *buf; + int len; + int log; { - register struct msgbuf *mp = &msgbuf[log]; - struct logsoftc *lp = &logsoftc[log]; - register int infront; - int s, n, writer, err = 0; + register struct msgbuf *mp = &msgbuf[log]; + struct logsoftc *lp = &logsoftc[log]; + register int infront; + int s, n, writer, err = 0; - if (mp->msg_magic != MSG_MAGIC || (len > MSG_BSIZE)) - return(-1); - /* - * Hate to do this but since this can be called from anywhere in the kernel - * we have to hold off any interrupt service routines so they don't change - * things. This looks like a lot of code but it isn't really. - */ - s = splhigh(); - while (len) { -again: infront = MSG_BSIZE - mp->msg_bufx; - if (infront <= 0) { - mp->msg_bufx = 0; - infront = MSG_BSIZE - mp->msg_bufr; - } - n = mp->msg_bufr - mp->msg_bufx; - if (n < 0) /* bufr < bufx */ - writer = (MSG_BSIZE - mp->msg_bufx) + mp->msg_bufr; - else if (n == 0) - writer = MSG_BSIZE; - else { - writer = n; - infront = n; - } - if (len > writer) { - /* - * won't fit. the total number of bytes to be written is - * greater than the number available. the buffer is full. - * throw away the old data and keep the current data by resetting - * the 'writer' pointer to the current 'reader' position. Bump the - * overrun counter in case anyone wants to look at it for debugging. - */ - lp->sc_overrun++; - mp->msg_bufx = mp->msg_bufr; - goto again; - } - if (infront > len) - infront = len; - bcopy(buf, &mp->msg_bufc[mp->msg_bufx], infront); - mp->msg_bufx += infront; - len -= infront; - buf += infront; - } - splx(s); - return(err); + if (mp->msg_magic != MSG_MAGIC || (len > MSG_BSIZE)) + return(-1); + /* + * Hate to do this but since this can be called from anywhere in the kernel + * we have to hold off any interrupt service routines so they don't change + * things. This looks like a lot of code but it isn't really. + */ + s = splhigh(); + while (len) { +again: infront = MSG_BSIZE - mp->msg_bufx; + if (infront <= 0) { + mp->msg_bufx = 0; + infront = MSG_BSIZE - mp->msg_bufr; + } + n = mp->msg_bufr - mp->msg_bufx; + if (n < 0) /* bufr < bufx */ + writer = (MSG_BSIZE - mp->msg_bufx) + mp->msg_bufr; + else if (n == 0) + writer = MSG_BSIZE; + else { + writer = n; + infront = n; + } + if (len > writer) { + /* + * won't fit. the total number of bytes to be written is + * greater than the number available. the buffer is full. + * throw away the old data and keep the current data by resetting + * the 'writer' pointer to the current 'reader' position. Bump the + * overrun counter in case anyone wants to look at it for debugging. + */ + lp->sc_overrun++; + mp->msg_bufx = mp->msg_bufr; + goto again; + } + if (infront > len) + infront = len; + bcopy(buf, &mp->msg_bufc[mp->msg_bufx], infront); + mp->msg_bufx += infront; + len -= infront; + buf += infront; + } + splx(s); + return(err); } /* @@ -326,11 +326,11 @@ again: infront = MSG_BSIZE - mp->msg_bufx; int loginit() { - register struct msgbuf *mp; + register struct msgbuf *mp; - for (mp = &msgbuf[0]; mp < &msgbuf[NLOG]; mp++) { - mp->msg_magic = MSG_MAGIC; - mp->msg_bufx = mp->msg_bufr = 0; - } - return(0); + for (mp = &msgbuf[0]; mp < &msgbuf[NLOG]; mp++) { + mp->msg_magic = MSG_MAGIC; + mp->msg_bufx = mp->msg_bufr = 0; + } + return(0); } diff --git a/sys/kernel/subr_prf.c b/sys/kernel/subr_prf.c index 7d720c0..c7c3065 100644 --- a/sys/kernel/subr_prf.c +++ b/sys/kernel/subr_prf.c @@ -14,16 +14,16 @@ #include "systm.h" #include "syslog.h" -#define TOCONS 0x1 -#define TOTTY 0x2 -#define TOLOG 0x4 +#define TOCONS 0x1 +#define TOTTY 0x2 +#define TOLOG 0x4 /* * In case console is off, * panicstr contains argument to last * call to panic. */ -char *panicstr; +char *panicstr; /* * Print a character on console or users terminal. @@ -32,38 +32,38 @@ char *panicstr; */ static void putchar (c, flags, tp) - int c, flags; - register struct tty *tp; + int c, flags; + register struct tty *tp; { - if (flags & TOTTY) { - register int s = spltty(); + if (flags & TOTTY) { + register int s = spltty(); - if (tp && (tp->t_state & (TS_CARR_ON | TS_ISOPEN)) == - (TS_CARR_ON | TS_ISOPEN)) { - if (c == '\n') - (void) ttyoutput('\r', tp); - (void) ttyoutput(c, tp); - ttstart(tp); - } - splx(s); - } + if (tp && (tp->t_state & (TS_CARR_ON | TS_ISOPEN)) == + (TS_CARR_ON | TS_ISOPEN)) { + if (c == '\n') + (void) ttyoutput('\r', tp); + (void) ttyoutput(c, tp); + ttstart(tp); + } + splx(s); + } #ifdef LOG_ENABLED - if ((flags & TOLOG) && c != '\0' && c != '\r' && c != 0177) { - char sym = c; - logwrt (&sym, 1, logMSG); - } + if ((flags & TOLOG) && c != '\0' && c != '\r' && c != 0177) { + char sym = c; + logwrt (&sym, 1, logMSG); + } #endif - if ((flags & TOCONS) && c != '\0') - cnputc(c); + if ((flags & TOCONS) && c != '\0') + cnputc(c); } static unsigned mkhex (unsigned ch) { - ch &= 15; - if (ch > 9) - return ch + 'a' - 10; - return ch + '0'; + ch &= 15; + if (ch > 9) + return ch + 'a' - 10; + return ch + '0'; } /* @@ -75,27 +75,27 @@ mkhex (unsigned ch) static char * ksprintn (char *nbuf, unsigned long ul, int base, int width, int *lenp) { - char *p; + char *p; - p = nbuf; - *p = 0; - for (;;) { - *++p = mkhex (ul % base); - ul /= base; - if (--width > 0) - continue; - if (! ul) - break; - } - if (lenp) - *lenp = p - nbuf; - return (p); + p = nbuf; + *p = 0; + for (;;) { + *++p = mkhex (ul % base); + ul /= base; + if (--width > 0) + continue; + if (! ul) + break; + } + if (lenp) + *lenp = p - nbuf; + return (p); } void puts(char *s, int flags, struct tty *ttyp) { while(*s) - putchar(*(s++), flags, ttyp); + putchar(*(s++), flags, ttyp); } /* @@ -107,7 +107,7 @@ void puts(char *s, int flags, struct tty *ttyp) * The format %b is supported to decode error registers. * Its usage is: * - * printf("reg=%b\n", regval, "*"); + * printf("reg=%b\n", regval, "*"); * * where is the output base expressed as a control character, e.g. * \10 gives octal; \20 gives hex. Each arg is a sequence of characters, @@ -115,17 +115,17 @@ void puts(char *s, int flags, struct tty *ttyp) * the next characters (up to a control character, i.e. a character <= 32), * give the name of the register. Thus: * - * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); + * kvprintf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); * * would produce output: * - * reg=3 + * reg=3 * * The format %D -- Hexdump, takes a pointer. Sharp flag - use `:' as * a separator, instead of a space. For example: * - * ("%6D", ptr) -> XX XX XX XX XX XX - * ("%#*D", len, ptr) -> XX:XX:XX:XX ... + * ("%6D", ptr) -> XX XX XX XX XX XX + * ("%#*D", len, ptr) -> XX:XX:XX:XX ... */ #define PUTC(C) putchar(C,flags,ttyp) @@ -134,296 +134,307 @@ void puts(char *s, int flags, struct tty *ttyp) #define HIOFF "\e[0m" static void prf (fmt, ap, flags, ttyp) - register char *fmt; - register u_int *ap; - int flags; - struct tty *ttyp; + register char *fmt; + register u_int *ap; + int flags; + struct tty *ttyp; { -#define va_arg(ap,type) *(type*) (void*) (ap++) +#define va_arg(ap,type) *(type*) (void*) (ap++) - char *q, nbuf [sizeof(long) * 8 + 1]; - const char *s; - int c, padding, base, lflag, ladjust, sharpflag, neg, dot, size; - int n, width, dwidth, uppercase, extrazeros, sign; - unsigned long ul; + char *q, nbuf [sizeof(long) * 8 + 1]; + const char *s; + int c, padding, base, lflag, ladjust, sharpflag, neg, dot, size; + int n, width, dwidth, uppercase, extrazeros, sign; + unsigned long ul; #ifdef KERNEL_HIGHLIGHT - puts(HION,flags,ttyp); + puts(HION, flags, ttyp); #endif - if (! fmt) - fmt = "(null)\n"; + if (! fmt) + fmt = "(null)\n"; - for (;;) { - while ((c = *fmt++) != '%') { - if (! c) { + for (;;) { + while ((c = *fmt++) != '%') { + if (! c) { #ifdef KERNEL_HIGHLIGHT - puts(HIOFF,flags,ttyp); + puts(HIOFF, flags, ttyp); #endif - return; + return; } - PUTC (c); - } - padding = ' '; - width = 0; extrazeros = 0; - lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; - sign = 0; dot = 0; uppercase = 0; dwidth = -1; -reswitch: c = *fmt++; - switch (c) { - case '.': - dot = 1; - padding = ' '; - dwidth = 0; - goto reswitch; + PUTC (c); + } + padding = ' '; + width = 0; extrazeros = 0; + lflag = 0; ladjust = 0; sharpflag = 0; neg = 0; + sign = 0; dot = 0; uppercase = 0; dwidth = -1; +reswitch: + c = *fmt++; + switch (c) { + case '.': + dot = 1; + padding = ' '; + dwidth = 0; + goto reswitch; - case '#': - sharpflag = 1; - goto reswitch; + case '#': + sharpflag = 1; + goto reswitch; - case '+': - sign = -1; - goto reswitch; + case '+': + sign = -1; + goto reswitch; - case '-': - ladjust = 1; - goto reswitch; + case '-': + ladjust = 1; + goto reswitch; - case '%': - PUTC (c); - break; + case '%': + PUTC (c); + break; - case '*': - if (! dot) { - width = va_arg (ap, int); - if (width < 0) { - ladjust = !ladjust; - width = -width; - } - } else { - dwidth = va_arg (ap, int); - } - goto reswitch; + case '*': + if (! dot) { + width = va_arg (ap, int); + if (width < 0) { + ladjust = !ladjust; + width = -width; + } + } else { + dwidth = va_arg (ap, int); + } + goto reswitch; - case '0': - if (! dot) { - padding = '0'; - goto reswitch; - } - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - for (n=0; ; ++fmt) { - n = n * 10 + c - '0'; - c = *fmt; - if (c < '0' || c > '9') - break; - } - if (dot) - dwidth = n; - else - width = n; - goto reswitch; + case '0': + if (! dot) { + padding = '0'; + goto reswitch; + } + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + for (n=0; ; ++fmt) { + n = n * 10 + c - '0'; + c = *fmt; + if (c < '0' || c > '9') + break; + } + if (dot) + dwidth = n; + else + width = n; + goto reswitch; - case 'b': - ul = va_arg (ap, int); - s = va_arg (ap, const char*); - q = ksprintn (nbuf, ul, *s++, -1, 0); - while (*q) - PUTC (*q--); + case 'b': + ul = va_arg (ap, int); + s = va_arg (ap, const char*); + q = ksprintn (nbuf, ul, *s++, -1, 0); + while (*q) + PUTC (*q--); - if (! ul) - break; - size = 0; - while (*s) { - n = *s++; - if ((char) (ul >> (n-1)) & 1) { - PUTC (size ? ',' : '<'); - for (; (n = *s) > ' '; ++s) - PUTC (n); - size = 1; - } else - while (*s > ' ') - ++s; - } - if (size) - PUTC ('>'); - break; + if (! ul) + break; + size = 0; + while (*s) { + n = *s++; + if ((char) (ul >> (n-1)) & 1) { + PUTC (size ? ',' : '<'); + for (; (n = *s) > ' '; ++s) + PUTC (n); + size = 1; + } else { + while (*s > ' ') + ++s; + } + } + if (size) + PUTC ('>'); + break; - case 'c': - if (! ladjust && width > 0) - while (width--) - PUTC (' '); + case 'c': + if (! ladjust && width > 0) { + while (width--) + PUTC (' '); + } - PUTC (va_arg (ap, int)); + PUTC (va_arg (ap, int)); - if (ladjust && width > 0) - while (width--) - PUTC (' '); - break; + if (ladjust && width > 0) { + while (width--) + PUTC (' '); + } + break; - case 'D': - s = va_arg (ap, const char*); - if (! width) - width = 16; - if (sharpflag) - padding = ':'; - while (width--) { - c = *s++; - PUTC (mkhex (c >> 4)); - PUTC (mkhex (c)); - if (width) - PUTC (padding); - } - break; + case 'D': + s = va_arg (ap, const char*); + if (! width) + width = 16; + if (sharpflag) + padding = ':'; + while (width--) { + c = *s++; + PUTC (mkhex (c >> 4)); + PUTC (mkhex (c)); + if (width) + PUTC (padding); + } + break; - case 'd': - ul = lflag ? va_arg (ap, long) : va_arg (ap, int); - if (! sign) sign = 1; - base = 10; - goto number; + case 'd': + ul = lflag ? va_arg (ap, long) : va_arg (ap, int); + if (! sign) sign = 1; + base = 10; + goto number; - case 'l': - lflag = 1; - goto reswitch; + case 'l': + lflag = 1; + goto reswitch; - case 'o': - ul = lflag ? va_arg (ap, unsigned long) : - va_arg (ap, unsigned int); - base = 8; - goto nosign; + case 'o': + ul = lflag ? va_arg (ap, unsigned long) : + va_arg (ap, unsigned int); + base = 8; + goto nosign; - case 'p': - ul = (size_t) va_arg (ap, void*); - if (! ul) { - s = "(nil)"; - goto const_string; - } - base = 16; - sharpflag = (width == 0); - goto nosign; + case 'p': + ul = (size_t) va_arg (ap, void*); + if (! ul) { + s = "(nil)"; + goto const_string; + } + base = 16; + sharpflag = (width == 0); + goto nosign; - case 'n': - ul = lflag ? va_arg (ap, unsigned long) : - sign ? (unsigned long) va_arg (ap, int) : - va_arg (ap, unsigned int); - base = 10; - goto number; + case 'n': + ul = lflag ? va_arg (ap, unsigned long) : + sign ? (unsigned long) va_arg (ap, int) : + va_arg (ap, unsigned int); + base = 10; + goto number; - case 's': - s = va_arg (ap, char*); - if (! s) - s = (const char*) "(null)"; + case 's': + s = va_arg (ap, char*); + if (! s) + s = (const char*) "(null)"; const_string: - if (! dot) - n = strlen (s); - else - for (n=0; n 0) - while (width--) - PUTC (' '); - while (n--) - PUTC (*s++); - if (ladjust && width > 0) - while (width--) - PUTC (' '); - break; + if (! ladjust && width > 0) { + while (width--) + PUTC (' '); + } + while (n--) + PUTC (*s++); + if (ladjust && width > 0) { + while (width--) + PUTC (' '); + } + break; - case 'u': - ul = lflag ? va_arg (ap, unsigned long) : - va_arg (ap, unsigned int); - base = 10; - goto nosign; + case 'u': + ul = lflag ? va_arg (ap, unsigned long) : + va_arg (ap, unsigned int); + base = 10; + goto nosign; - case 'x': - case 'X': - ul = lflag ? va_arg (ap, unsigned long) : - va_arg (ap, unsigned int); - base = 16; - uppercase = (c == 'X'); - goto nosign; - case 'z': - case 'Z': - ul = lflag ? va_arg (ap, unsigned long) : - sign ? (unsigned long) va_arg (ap, int) : - va_arg (ap, unsigned int); - base = 16; - uppercase = (c == 'Z'); - goto number; + case 'x': + case 'X': + ul = lflag ? va_arg (ap, unsigned long) : + va_arg (ap, unsigned int); + base = 16; + uppercase = (c == 'X'); + goto nosign; + case 'z': + case 'Z': + ul = lflag ? va_arg (ap, unsigned long) : + sign ? (unsigned long) va_arg (ap, int) : + va_arg (ap, unsigned int); + base = 16; + uppercase = (c == 'Z'); + goto number; +nosign: + sign = 0; +number: + if (sign && ((long) ul != 0L)) { + if ((long) ul < 0L) { + neg = '-'; + ul = -(long) ul; + } else if (sign < 0) + neg = '+'; + } + if (dwidth >= (int) sizeof(nbuf)) { + extrazeros = dwidth - sizeof(nbuf) + 1; + dwidth = sizeof(nbuf) - 1; + } + s = ksprintn (nbuf, ul, base, dwidth, &size); + if (sharpflag && ul != 0) { + if (base == 8) + size++; + else if (base == 16) + size += 2; + } + if (neg) + size++; -nosign: sign = 0; -number: if (sign && ((long) ul != 0L)) { - if ((long) ul < 0L) { - neg = '-'; - ul = -(long) ul; - } else if (sign < 0) - neg = '+'; - } - if (dwidth >= (int) sizeof(nbuf)) { - extrazeros = dwidth - sizeof(nbuf) + 1; - dwidth = sizeof(nbuf) - 1; - } - s = ksprintn (nbuf, ul, base, dwidth, &size); - if (sharpflag && ul != 0) { - if (base == 8) - size++; - else if (base == 16) - size += 2; - } - if (neg) - size++; + if (! ladjust && width && padding == ' ' && + (width -= size) > 0) { + do { + PUTC (' '); + } while (--width > 0); + } - if (! ladjust && width && padding == ' ' && - (width -= size) > 0) - do { - PUTC (' '); - } while (--width > 0); + if (neg) + PUTC (neg); - if (neg) - PUTC (neg); + if (sharpflag && ul != 0) { + if (base == 8) { + PUTC ('0'); + } else if (base == 16) { + PUTC ('0'); + PUTC (uppercase ? 'X' : 'x'); + } + } - if (sharpflag && ul != 0) { - if (base == 8) { - PUTC ('0'); - } else if (base == 16) { - PUTC ('0'); - PUTC (uppercase ? 'X' : 'x'); - } - } + if (extrazeros) { + do { + PUTC ('0'); + } while (--extrazeros > 0); + } - if (extrazeros) - do { - PUTC ('0'); - } while (--extrazeros > 0); + if (! ladjust && width && (width -= size) > 0) { + do { + PUTC (padding); + } while (--width > 0); + } - if (! ladjust && width && (width -= size) > 0) - do { - PUTC (padding); - } while (--width > 0); + for (; *s; --s) { + if (uppercase && *s>='a' && *s<='z') { + PUTC (*s + 'A' - 'a'); + } else { + PUTC (*s); + } + } - for (; *s; --s) { - if (uppercase && *s>='a' && *s<='z') { - PUTC (*s + 'A' - 'a'); - } else { - PUTC (*s); - } - } - - if (ladjust && width && (width -= size) > 0) - do { - PUTC (' '); - } while (--width > 0); - break; - default: - PUTC ('%'); - if (lflag) - PUTC ('l'); - PUTC (c); - break; - } - } + if (ladjust && width && (width -= size) > 0) { + do { + PUTC (' '); + } while (--width > 0); + } + break; + default: + PUTC ('%'); + if (lflag) + PUTC ('l'); + PUTC (c); + break; + } + } #ifdef KERNEL_HIGHLIGHT puts(HIOFF,flags,ttyp); #endif @@ -431,11 +442,11 @@ number: if (sign && ((long) ul != 0L)) { static void logpri (level) - int level; + int level; { - putchar ('<', TOLOG, (struct tty*) 0); - prf ("%u", &level, TOLOG, (struct tty*) 0); - putchar ('>', TOLOG, (struct tty*) 0); + putchar ('<', TOLOG, (struct tty*) 0); + prf ("%u", &level, TOLOG, (struct tty*) 0); + putchar ('>', TOLOG, (struct tty*) 0); } /* @@ -446,20 +457,20 @@ logpri (level) * * One additional format: %b is supported to decode error registers. * Usage is: - * printf("reg=%b\n", regval, "*"); + * printf("reg=%b\n", regval, "*"); * Where is the output base expressed as a control character, * e.g. \10 gives octal; \20 gives hex. Each arg is a sequence of * characters, the first of which gives the bit number to be inspected * (origin 1), and the next characters (up to a control character, i.e. * a character <= 32), give the name of the register. Thus - * printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); + * printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); * would produce output: - * reg=3 + * reg=3 */ void printf(char *fmt, ...) { - prf(fmt, &fmt + 1, TOCONS | TOLOG, (struct tty *)0); + prf(fmt, &fmt + 1, TOCONS | TOLOG, (struct tty *)0); } /* @@ -488,14 +499,14 @@ void _printf_cdnopsuxX(char *fmt, ...) void uprintf (char *fmt, ...) { - register struct tty *tp; + register struct tty *tp; - tp = u.u_ttyp; - if (tp == NULL) - return; + tp = u.u_ttyp; + if (tp == NULL) + return; - if (ttycheckoutq (tp, 1)) - prf (fmt, &fmt+1, TOTTY, tp); + if (ttycheckoutq (tp, 1)) + prf (fmt, &fmt+1, TOTTY, tp); } /* @@ -507,16 +518,16 @@ uprintf (char *fmt, ...) void tprintf (register struct tty *tp, char *fmt, ...) { - int flags = TOTTY | TOLOG; + int flags = TOTTY | TOLOG; - logpri (LOG_INFO); - if (tp == (struct tty*) NULL) - tp = &cnttys[0]; - if (ttycheckoutq (tp, 0) == 0) - flags = TOLOG; - prf (fmt, &fmt + 1, flags, tp); + logpri (LOG_INFO); + if (tp == (struct tty*) NULL) + tp = &cnttys[0]; + if (ttycheckoutq (tp, 0) == 0) + flags = TOLOG; + prf (fmt, &fmt + 1, flags, tp); #ifdef LOG_ENABLED - logwakeup (logMSG); + logwakeup (logMSG); #endif } @@ -529,17 +540,17 @@ tprintf (register struct tty *tp, char *fmt, ...) void log (int level, char *fmt, ...) { - register int s = splhigh(); + register int s = splhigh(); - logpri(level); - prf(fmt, &fmt + 1, TOLOG, (struct tty *)0); - splx(s); + logpri(level); + prf(fmt, &fmt + 1, TOLOG, (struct tty *)0); + splx(s); #ifdef LOG_ENABLED - if (! logisopen(logMSG)) + if (! logisopen(logMSG)) #endif - prf(fmt, &fmt + 1, TOCONS, (struct tty *)0); + prf(fmt, &fmt + 1, TOCONS, (struct tty *)0); #ifdef LOG_ENABLED - logwakeup(logMSG); + logwakeup(logMSG); #endif } @@ -551,15 +562,15 @@ log (int level, char *fmt, ...) */ void panic(s) - char *s; + char *s; { - int bootopt = RB_HALT | RB_DUMP; + int bootopt = RB_HALT | RB_DUMP; - if (panicstr) { - bootopt |= RB_NOSYNC; - } else { - panicstr = s; - } - printf ("panic: %s\n", s); - boot (rootdev, bootopt); + if (panicstr) { + bootopt |= RB_NOSYNC; + } else { + panicstr = s; + } + printf ("panic: %s\n", s); + boot (rootdev, bootopt); } diff --git a/sys/kernel/subr_rmap.c b/sys/kernel/subr_rmap.c index 01eddc5..56eb615 100644 --- a/sys/kernel/subr_rmap.c +++ b/sys/kernel/subr_rmap.c @@ -43,37 +43,37 @@ */ size_t malloc (mp, size) - struct map *mp; - register size_t size; + struct map *mp; + register size_t size; { - register struct mapent *bp, *ep; - size_t addr; + register struct mapent *bp, *ep; + size_t addr; - if (! size) - panic ("malloc: size = 0"); - /* - * Search for a piece of the resource map which has enough - * free space to accomodate the request. - */ - for (bp = mp->m_map; bp->m_size; ++bp) - if (bp->m_size >= size) { - /* - * Allocate from the map. If we allocated the entire - * piece, move the rest of the map to the left. - */ - addr = bp->m_addr; - bp->m_size -= size; - if (bp->m_size) - bp->m_addr += size; - else for (ep = bp;; ++ep) { - *ep = *++bp; - if (!bp->m_size) - break; - } - return(addr); - } - /* no entries big enough */ - return 0; + if (! size) + panic ("malloc: size = 0"); + /* + * Search for a piece of the resource map which has enough + * free space to accomodate the request. + */ + for (bp = mp->m_map; bp->m_size; ++bp) + if (bp->m_size >= size) { + /* + * Allocate from the map. If we allocated the entire + * piece, move the rest of the map to the left. + */ + addr = bp->m_addr; + bp->m_size -= size; + if (bp->m_size) + bp->m_addr += size; + else for (ep = bp;; ++ep) { + *ep = *++bp; + if (!bp->m_size) + break; + } + return(addr); + } + /* no entries big enough */ + return 0; } /* @@ -82,88 +82,88 @@ malloc (mp, size) */ void mfree (mp, size, addr) - struct map *mp; - size_t size; - register size_t addr; + struct map *mp; + size_t size; + register size_t addr; { - register struct mapent *bp, *ep; - struct mapent *start; + register struct mapent *bp, *ep; + struct mapent *start; - if (! size) - return; - /* the address must not be 0, or the protocol has broken down. */ - if (! addr) - panic ("mfree: addr = 0"); + if (! size) + return; + /* the address must not be 0, or the protocol has broken down. */ + if (! addr) + panic ("mfree: addr = 0"); - /* - * locate the piece of the map which starts after the - * returned space (or the end of the map). - */ - bp = mp->m_map; - /* printf ("mfree (size=%u, addr=%u) m_map = %08x\n", size, addr, bp); */ + /* + * locate the piece of the map which starts after the + * returned space (or the end of the map). + */ + bp = mp->m_map; + /* printf ("mfree (size=%u, addr=%u) m_map = %08x\n", size, addr, bp); */ - while (bp->m_size && bp->m_addr <= addr) { - /*printf ("skip m_map[%d]: m_addr %u <= addr %u\n", bp - mp->m_map, bp->m_addr, addr);*/ - ++bp; - } + while (bp->m_size && bp->m_addr <= addr) { + /*printf ("skip m_map[%d]: m_addr %u <= addr %u\n", bp - mp->m_map, bp->m_addr, addr);*/ + ++bp; + } - /* if there is a piece on the left abutting us, combine with it. */ - ep = bp - 1; - if (bp != mp->m_map && ep->m_addr + ep->m_size >= addr) { + /* if there is a piece on the left abutting us, combine with it. */ + ep = bp - 1; + if (bp != mp->m_map && ep->m_addr + ep->m_size >= addr) { #ifdef DIAGNOSTIC - /* any overlap is an internal error */ - if (ep->m_addr + ep->m_size > addr) - panic("mfree overlap #1"); + /* any overlap is an internal error */ + if (ep->m_addr + ep->m_size > addr) + panic("mfree overlap #1"); #endif - /* add into piece on the left by increasing its size. */ - ep->m_size += size; + /* add into piece on the left by increasing its size. */ + ep->m_size += size; - /* - * if the combined piece abuts the piece on the right now, - * compress it in also, by shifting the remaining pieces - * of the map over. - */ - if (bp->m_size && addr + size >= bp->m_addr) { + /* + * if the combined piece abuts the piece on the right now, + * compress it in also, by shifting the remaining pieces + * of the map over. + */ + if (bp->m_size && addr + size >= bp->m_addr) { #ifdef DIAGNOSTIC - if (addr + size > bp->m_addr) - panic("mfree overlap #2"); + if (addr + size > bp->m_addr) + panic("mfree overlap #2"); #endif - ep->m_size += bp->m_size; - do { - *++ep = *++bp; - } while (bp->m_size); - } - return; - } + ep->m_size += bp->m_size; + do { + *++ep = *++bp; + } while (bp->m_size); + } + return; + } - /* if doesn't abut on the left, check for abutting on the right. */ - if (bp->m_size && addr + size >= bp->m_addr) { + /* if doesn't abut on the left, check for abutting on the right. */ + if (bp->m_size && addr + size >= bp->m_addr) { #ifdef DIAGNOSTIC - if (addr + size > bp->m_addr) - panic("mfree overlap #3"); + if (addr + size > bp->m_addr) + panic("mfree overlap #3"); #endif - bp->m_addr = addr; - bp->m_size += size; - return; - } + bp->m_addr = addr; + bp->m_size += size; + return; + } - /* doesn't abut. Make a new entry and check for map overflow. */ - for (start = bp; bp->m_size; ++bp); - if (++bp > mp->m_limit) - /* - * too many segments; if this happens, the correct fix - * is to make the map bigger; you can't afford to lose - * chunks of the map. If you need to implement recovery, - * use the above "for" loop to find the smallest entry - * and toss it. - */ - printf("%s: overflow, lost %u clicks at 0%o\n", - mp->m_name, size, addr); - else { - for (ep = bp - 1; ep >= start; *bp-- = *ep--); - start->m_addr = addr; - start->m_size = size; - } + /* doesn't abut. Make a new entry and check for map overflow. */ + for (start = bp; bp->m_size; ++bp); + if (++bp > mp->m_limit) + /* + * too many segments; if this happens, the correct fix + * is to make the map bigger; you can't afford to lose + * chunks of the map. If you need to implement recovery, + * use the above "for" loop to find the smallest entry + * and toss it. + */ + printf("%s: overflow, lost %u clicks at 0%o\n", + mp->m_name, size, addr); + else { + for (ep = bp - 1; ep >= start; *bp-- = *ep--); + start->m_addr = addr; + start->m_size = size; + } } /* @@ -175,56 +175,58 @@ mfree (mp, size, addr) */ size_t malloc3 (mp, d_size, s_size, u_size, a) - struct map *mp; - size_t d_size, s_size, u_size; - size_t a[3]; + struct map *mp; + size_t d_size, s_size, u_size; + size_t a[3]; { - register struct mapent *bp, *remap; - register int next; - struct mapent *madd[3]; - size_t sizes[3]; - int found; + register struct mapent *bp, *remap; + register int next; + struct mapent *madd[3]; + size_t sizes[3]; + int found; - sizes[0] = d_size; - sizes[1] = s_size; - sizes[2] = u_size; - /* - * note, this has to work for d_size and s_size of zero, - * since init() comes in that way. - */ - madd[0] = madd[1] = madd[2] = remap = NULL; - for (found = 0, bp = mp->m_map; bp->m_size; ++bp) - for (next = 0; next < 3; ++next) - if (!madd[next] && sizes[next] <= bp->m_size) { - madd[next] = bp; - bp->m_size -= sizes[next]; - if (!bp->m_size && !remap) - remap = bp; - if (++found == 3) - goto resolve; - } + sizes[0] = d_size; + sizes[1] = s_size; + sizes[2] = u_size; + /* + * note, this has to work for d_size and s_size of zero, + * since init() comes in that way. + */ + madd[0] = madd[1] = madd[2] = remap = NULL; + for (found = 0, bp = mp->m_map; bp->m_size; ++bp) + for (next = 0; next < 3; ++next) + if (!madd[next] && sizes[next] <= bp->m_size) { + madd[next] = bp; + bp->m_size -= sizes[next]; + if (!bp->m_size && !remap) + remap = bp; + if (++found == 3) + goto resolve; + } - /* couldn't get it all; restore the old sizes, try again */ - for (next = 0; next < 3; ++next) - if (madd[next]) - madd[next]->m_size += sizes[next]; - return 0; + /* couldn't get it all; restore the old sizes, try again */ + for (next = 0; next < 3; ++next) + if (madd[next]) + madd[next]->m_size += sizes[next]; + return 0; resolve: - /* got it all, update the addresses. */ - for (next = 0; next < 3; ++next) { - bp = madd[next]; - a[next] = bp->m_addr; - bp->m_addr += sizes[next]; - } + /* got it all, update the addresses. */ + for (next = 0; next < 3; ++next) { + bp = madd[next]; + a[next] = bp->m_addr; + bp->m_addr += sizes[next]; + } - /* remove any entries of size 0; addr of 0 terminates */ - if (remap) - for (bp = remap + 1;; ++bp) - if (bp->m_size || !bp->m_addr) { - *remap++ = *bp; - if (!bp->m_addr) - break; - } - return(a[2]); + /* remove any entries of size 0; addr of 0 terminates */ + if (remap) { + for (bp = remap + 1;; ++bp) { + if (bp->m_size || !bp->m_addr) { + *remap++ = *bp; + if (!bp->m_addr) + break; + } + } + } + return(a[2]); } diff --git a/sys/kernel/sys_generic.c b/sys/kernel/sys_generic.c index d273d96..c052fe5 100644 --- a/sys/kernel/sys_generic.c +++ b/sys/kernel/sys_generic.c @@ -15,51 +15,51 @@ #include "kernel.h" #include "systm.h" -int selwait; +int selwait; static void rwuio (uio) - register struct uio *uio; + register struct uio *uio; { - struct a { - int fdes; - }; - register struct file *fp; - register struct iovec *iov; - u_int i, count; - off_t total; + struct a { + int fdes; + }; + register struct file *fp; + register struct iovec *iov; + u_int i, count; + off_t total; - GETF(fp, ((struct a *)u.u_arg)->fdes); - if ((fp->f_flag & (uio->uio_rw == UIO_READ ? FREAD : FWRITE)) == 0) { - u.u_error = EBADF; - return; - } - total = 0; - uio->uio_resid = 0; - for (iov = uio->uio_iov, i = 0; i < uio->uio_iovcnt; i++, iov++) - total += iov->iov_len; + GETF(fp, ((struct a *)u.u_arg)->fdes); + if ((fp->f_flag & (uio->uio_rw == UIO_READ ? FREAD : FWRITE)) == 0) { + u.u_error = EBADF; + return; + } + total = 0; + uio->uio_resid = 0; + for (iov = uio->uio_iov, i = 0; i < uio->uio_iovcnt; i++, iov++) + total += iov->iov_len; - uio->uio_resid = total; - if (uio->uio_resid != total) { /* check wraparound */ - u.u_error = EINVAL; - return; - } - count = uio->uio_resid; - if (setjmp (&u.u_qsave)) { - /* - * The ONLY way we can get here is via the longjump in sleep. Thus signals - * have been checked and u_error set accordingly. If no bytes have been - * transferred then all that needs to be done now is 'return'; the system - * call will either be restarted or reported as interrupted. If bytes have - * been transferred then we need to calculate the number of bytes transferred. - */ - if (uio->uio_resid == count) - return; - u.u_error = 0; - } else - u.u_error = (*Fops[fp->f_type]->fo_rw) (fp, uio); + uio->uio_resid = total; + if (uio->uio_resid != total) { /* check wraparound */ + u.u_error = EINVAL; + return; + } + count = uio->uio_resid; + if (setjmp (&u.u_qsave)) { + /* + * The ONLY way we can get here is via the longjump in sleep. Thus signals + * have been checked and u_error set accordingly. If no bytes have been + * transferred then all that needs to be done now is 'return'; the system + * call will either be restarted or reported as interrupted. If bytes have + * been transferred then we need to calculate the number of bytes transferred. + */ + if (uio->uio_resid == count) + return; + u.u_error = 0; + } else + u.u_error = (*Fops[fp->f_type]->fo_rw) (fp, uio); - u.u_rval = count - uio->uio_resid; + u.u_rval = count - uio->uio_resid; } /* @@ -68,45 +68,45 @@ rwuio (uio) void read() { - register struct a { - int fdes; - char *cbuf; - unsigned count; - } *uap = (struct a *)u.u_arg; - struct uio auio; - struct iovec aiov; + register struct a { + int fdes; + char *cbuf; + unsigned count; + } *uap = (struct a *)u.u_arg; + struct uio auio; + struct iovec aiov; - aiov.iov_base = (caddr_t)uap->cbuf; - aiov.iov_len = uap->count; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_rw = UIO_READ; - rwuio (&auio); + aiov.iov_base = (caddr_t)uap->cbuf; + aiov.iov_len = uap->count; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_rw = UIO_READ; + rwuio (&auio); } void readv() { - register struct a { - int fdes; - struct iovec *iovp; - unsigned iovcnt; - } *uap = (struct a *)u.u_arg; - struct uio auio; - struct iovec aiov[16]; /* XXX */ + register struct a { + int fdes; + struct iovec *iovp; + unsigned iovcnt; + } *uap = (struct a *)u.u_arg; + struct uio auio; + struct iovec aiov[16]; /* XXX */ - if (uap->iovcnt > sizeof(aiov)/sizeof(aiov[0])) { - u.u_error = EINVAL; - return; - } - auio.uio_iov = aiov; - auio.uio_iovcnt = uap->iovcnt; - auio.uio_rw = UIO_READ; - u.u_error = copyin ((caddr_t)uap->iovp, (caddr_t)aiov, - uap->iovcnt * sizeof (struct iovec)); - if (u.u_error) - return; - rwuio (&auio); + if (uap->iovcnt > sizeof(aiov)/sizeof(aiov[0])) { + u.u_error = EINVAL; + return; + } + auio.uio_iov = aiov; + auio.uio_iovcnt = uap->iovcnt; + auio.uio_rw = UIO_READ; + u.u_error = copyin ((caddr_t)uap->iovp, (caddr_t)aiov, + uap->iovcnt * sizeof (struct iovec)); + if (u.u_error) + return; + rwuio (&auio); } /* @@ -115,45 +115,45 @@ readv() void write() { - register struct a { - int fdes; - char *cbuf; - unsigned count; - } *uap = (struct a *)u.u_arg; - struct uio auio; - struct iovec aiov; + register struct a { + int fdes; + char *cbuf; + unsigned count; + } *uap = (struct a *)u.u_arg; + struct uio auio; + struct iovec aiov; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_rw = UIO_WRITE; - aiov.iov_base = uap->cbuf; - aiov.iov_len = uap->count; - rwuio (&auio); + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_rw = UIO_WRITE; + aiov.iov_base = uap->cbuf; + aiov.iov_len = uap->count; + rwuio (&auio); } void writev() { - register struct a { - int fdes; - struct iovec *iovp; - unsigned iovcnt; - } *uap = (struct a *)u.u_arg; - struct uio auio; - struct iovec aiov[16]; /* XXX */ + register struct a { + int fdes; + struct iovec *iovp; + unsigned iovcnt; + } *uap = (struct a *)u.u_arg; + struct uio auio; + struct iovec aiov[16]; /* XXX */ - if (uap->iovcnt > sizeof(aiov)/sizeof(aiov[0])) { - u.u_error = EINVAL; - return; - } - auio.uio_iov = aiov; - auio.uio_iovcnt = uap->iovcnt; - auio.uio_rw = UIO_WRITE; - u.u_error = copyin ((caddr_t)uap->iovp, (caddr_t)aiov, - uap->iovcnt * sizeof (struct iovec)); - if (u.u_error) - return; - rwuio (&auio); + if (uap->iovcnt > sizeof(aiov)/sizeof(aiov[0])) { + u.u_error = EINVAL; + return; + } + auio.uio_iov = aiov; + auio.uio_iovcnt = uap->iovcnt; + auio.uio_rw = UIO_WRITE; + u.u_error = copyin ((caddr_t)uap->iovp, (caddr_t)aiov, + uap->iovcnt * sizeof (struct iovec)); + if (u.u_error) + return; + rwuio (&auio); } /* @@ -162,102 +162,102 @@ writev() void ioctl() { - register struct file *fp; - register struct a { - int fdes; - long cmd; - caddr_t cmarg; - } *uap; - u_int com; + register struct file *fp; + register struct a { + int fdes; + long cmd; + caddr_t cmarg; + } *uap; + u_int com; - uap = (struct a *)u.u_arg; - fp = getf(uap->fdes); - if (! fp) - return; - if (! (fp->f_flag & (FREAD | FWRITE))) { - u.u_error = EBADF; - return; - } - com = (u_int) uap->cmd; - if (com & (IOC_IN | IOC_OUT)) { - /* Check user address. */ - u_int nbytes = (com & ~(IOC_INOUT | IOC_VOID)) >> 16; - if (baduaddr (uap->cmarg) || - baduaddr (uap->cmarg + nbytes - 1)) { - u.u_error = EFAULT; - return; - } - } + uap = (struct a *)u.u_arg; + fp = getf(uap->fdes); + if (! fp) + return; + if (! (fp->f_flag & (FREAD | FWRITE))) { + u.u_error = EBADF; + return; + } + com = (u_int) uap->cmd; + if (com & (IOC_IN | IOC_OUT)) { + /* Check user address. */ + u_int nbytes = (com & ~(IOC_INOUT | IOC_VOID)) >> 16; + if (baduaddr (uap->cmarg) || + baduaddr (uap->cmarg + nbytes - 1)) { + u.u_error = EFAULT; + return; + } + } - switch (com) { - case FIOCLEX: - u.u_pofile[uap->fdes] |= UF_EXCLOSE; - return; - case FIONCLEX: - u.u_pofile[uap->fdes] &= ~UF_EXCLOSE; - return; - case FIONBIO: - u.u_error = fset (fp, FNONBLOCK, *(int*) uap->cmarg); - return; - case FIOASYNC: - u.u_error = fset (fp, FASYNC, *(int*) uap->cmarg); - return; - case FIOSETOWN: - u.u_error = fsetown (fp, *(int*) uap->cmarg); - return; - case FIOGETOWN: - u.u_error = fgetown (fp, (int*) uap->cmarg); - return; - } - u.u_error = (*Fops[fp->f_type]->fo_ioctl) (fp, com, uap->cmarg); + switch (com) { + case FIOCLEX: + u.u_pofile[uap->fdes] |= UF_EXCLOSE; + return; + case FIONCLEX: + u.u_pofile[uap->fdes] &= ~UF_EXCLOSE; + return; + case FIONBIO: + u.u_error = fset (fp, FNONBLOCK, *(int*) uap->cmarg); + return; + case FIOASYNC: + u.u_error = fset (fp, FASYNC, *(int*) uap->cmarg); + return; + case FIOSETOWN: + u.u_error = fsetown (fp, *(int*) uap->cmarg); + return; + case FIOGETOWN: + u.u_error = fgetown (fp, (int*) uap->cmarg); + return; + } + u.u_error = (*Fops[fp->f_type]->fo_ioctl) (fp, com, uap->cmarg); } -int nselcoll; +int nselcoll; struct pselect_args { - int nd; - fd_set *in; - fd_set *ou; - fd_set *ex; - struct timespec *ts; - sigset_t *maskp; + int nd; + fd_set *in; + fd_set *ou; + fd_set *ex; + struct timespec *ts; + sigset_t *maskp; }; int selscan(ibits, obits, nfd, retval) - fd_set *ibits, *obits; - int nfd, *retval; + fd_set *ibits, *obits; + int nfd, *retval; { - register int i, j, flag; - fd_mask bits; - struct file *fp; - int which, n = 0; + register int i, j, flag; + fd_mask bits; + struct file *fp; + int which, n = 0; - for (which = 0; which < 3; which++) { - switch (which) { - case 0: - flag = FREAD; break; - case 1: - flag = FWRITE; break; - case 2: - flag = 0; break; - } - for (i = 0; i < nfd; i += NFDBITS) { - bits = ibits[which].fds_bits[i/NFDBITS]; - while ((j = ffs(bits)) && i + --j < nfd) { - bits &= ~(1L << j); - fp = u.u_ofile[i + j]; - if (fp == NULL) - return(EBADF); - if ((*Fops[fp->f_type]->fo_select) (fp, flag)) { - FD_SET(i + j, &obits[which]); - n++; - } - } - } - } - *retval = n; - return(0); + for (which = 0; which < 3; which++) { + switch (which) { + case 0: + flag = FREAD; break; + case 1: + flag = FWRITE; break; + case 2: + flag = 0; break; + } + for (i = 0; i < nfd; i += NFDBITS) { + bits = ibits[which].fds_bits[i/NFDBITS]; + while ((j = ffs(bits)) && i + --j < nfd) { + bits &= ~(1L << j); + fp = u.u_ofile[i + j]; + if (fp == NULL) + return(EBADF); + if ((*Fops[fp->f_type]->fo_select) (fp, flag)) { + FD_SET(i + j, &obits[which]); + n++; + } + } + } + } + *retval = n; + return(0); } /* @@ -265,127 +265,127 @@ selscan(ibits, obits, nfd, retval) */ static int select1(uap, is_pselect) - register struct pselect_args *uap; - int is_pselect; + register struct pselect_args *uap; + int is_pselect; { - fd_set ibits[3], obits[3]; - struct timeval atv; - sigset_t sigmsk; - unsigned int timo = 0; - register int error, ni; - int ncoll, s; + fd_set ibits[3], obits[3]; + struct timeval atv; + sigset_t sigmsk; + unsigned int timo = 0; + register int error, ni; + int ncoll, s; - bzero((caddr_t)ibits, sizeof(ibits)); - bzero((caddr_t)obits, sizeof(obits)); - if (uap->nd > NOFILE) - uap->nd = NOFILE; /* forgiving, if slightly wrong */ - ni = howmany(uap->nd, NFDBITS); + bzero((caddr_t)ibits, sizeof(ibits)); + bzero((caddr_t)obits, sizeof(obits)); + if (uap->nd > NOFILE) + uap->nd = NOFILE; /* forgiving, if slightly wrong */ + ni = howmany(uap->nd, NFDBITS); -#define getbits(name, x) \ - if (uap->name) { \ - error = copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \ - (unsigned)(ni * sizeof(fd_mask))); \ - if (error) \ - goto done; \ - } - getbits(in, 0); - getbits(ou, 1); - getbits(ex, 2); -#undef getbits +#define getbits(name, x) \ + if (uap->name) { \ + error = copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \ + (unsigned)(ni * sizeof(fd_mask))); \ + if (error) \ + goto done; \ + } + getbits(in, 0); + getbits(ou, 1); + getbits(ex, 2); +#undef getbits - if (uap->maskp) { - error = copyin ((caddr_t) uap->maskp, (caddr_t) &sigmsk, sizeof(sigmsk)); - sigmsk &= ~sigcantmask; - if (error) - goto done; - } - if (uap->ts) { - error = copyin ((caddr_t) uap->ts, (caddr_t) &atv, sizeof (atv)); - if (error) - goto done; - /* - * nanoseconds ('struct timespec') on a PDP-11 are stupid since a 50 or 60 hz - * clock is all we have. Keeping the names and logic made porting easier - * though. - */ - if (is_pselect) { - struct timespec *ts = (struct timespec *)&atv; + if (uap->maskp) { + error = copyin ((caddr_t) uap->maskp, (caddr_t) &sigmsk, sizeof(sigmsk)); + sigmsk &= ~sigcantmask; + if (error) + goto done; + } + if (uap->ts) { + error = copyin ((caddr_t) uap->ts, (caddr_t) &atv, sizeof (atv)); + if (error) + goto done; + /* + * nanoseconds ('struct timespec') on a PDP-11 are stupid since a 50 or 60 hz + * clock is all we have. Keeping the names and logic made porting easier + * though. + */ + if (is_pselect) { + struct timespec *ts = (struct timespec *)&atv; - if (ts->tv_sec == 0 && ts->tv_nsec < 1000) - atv.tv_usec = 1; - else - atv.tv_usec = ts->tv_nsec / 1000; - } - if (itimerfix(&atv)) { - error = EINVAL; - goto done; - } - s = splhigh(); - time.tv_usec = lbolt * usechz; - timevaladd(&atv, &time); - splx(s); - } + if (ts->tv_sec == 0 && ts->tv_nsec < 1000) + atv.tv_usec = 1; + else + atv.tv_usec = ts->tv_nsec / 1000; + } + if (itimerfix(&atv)) { + error = EINVAL; + goto done; + } + s = splhigh(); + time.tv_usec = lbolt * usechz; + timevaladd(&atv, &time); + splx(s); + } retry: - ncoll = nselcoll; - u.u_procp->p_flag |= P_SELECT; - error = selscan(ibits, obits, uap->nd, &u.u_rval); - if (error || u.u_rval) - goto done; - s = splhigh(); - if (uap->ts) { - /* this should be timercmp(&time, &atv, >=) */ - if ((time.tv_sec > atv.tv_sec || (time.tv_sec == atv.tv_sec - && lbolt * usechz >= atv.tv_usec))) { - splx(s); - goto done; - } - timo = hzto(&atv); - if (timo == 0) - timo = 1; - } - if ((u.u_procp->p_flag & P_SELECT) == 0 || nselcoll != ncoll) { - u.u_procp->p_flag &= ~P_SELECT; - splx(s); - goto retry; - } - u.u_procp->p_flag &= ~P_SELECT; - /* - * If doing a pselect() need to set a temporary mask while in tsleep. - * Returning from pselect after catching a signal the old mask has to be - * restored. Save it here and set the appropriate flag. - */ - if (uap->maskp) { - u.u_oldmask = u.u_procp->p_sigmask; - u.u_psflags |= SAS_OLDMASK; - u.u_procp->p_sigmask = sigmsk; - } - error = tsleep ((caddr_t) &selwait, PSOCK | PCATCH, timo); - if (uap->maskp) - u.u_procp->p_sigmask = u.u_oldmask; - splx(s); - if (error == 0) - goto retry; + ncoll = nselcoll; + u.u_procp->p_flag |= P_SELECT; + error = selscan(ibits, obits, uap->nd, &u.u_rval); + if (error || u.u_rval) + goto done; + s = splhigh(); + if (uap->ts) { + /* this should be timercmp(&time, &atv, >=) */ + if ((time.tv_sec > atv.tv_sec || (time.tv_sec == atv.tv_sec + && lbolt * usechz >= atv.tv_usec))) { + splx(s); + goto done; + } + timo = hzto(&atv); + if (timo == 0) + timo = 1; + } + if ((u.u_procp->p_flag & P_SELECT) == 0 || nselcoll != ncoll) { + u.u_procp->p_flag &= ~P_SELECT; + splx(s); + goto retry; + } + u.u_procp->p_flag &= ~P_SELECT; + /* + * If doing a pselect() need to set a temporary mask while in tsleep. + * Returning from pselect after catching a signal the old mask has to be + * restored. Save it here and set the appropriate flag. + */ + if (uap->maskp) { + u.u_oldmask = u.u_procp->p_sigmask; + u.u_psflags |= SAS_OLDMASK; + u.u_procp->p_sigmask = sigmsk; + } + error = tsleep ((caddr_t) &selwait, PSOCK | PCATCH, timo); + if (uap->maskp) + u.u_procp->p_sigmask = u.u_oldmask; + splx(s); + if (error == 0) + goto retry; done: - u.u_procp->p_flag &= ~P_SELECT; - /* select is not restarted after signals... */ - if (error == ERESTART) - error = EINTR; - if (error == EWOULDBLOCK) - error = 0; -#define putbits(name, x) \ - if (uap->name && \ - (error2 = copyout ((caddr_t) &obits[x], (caddr_t) uap->name, ni*sizeof(fd_mask)))) \ - error = error2; + u.u_procp->p_flag &= ~P_SELECT; + /* select is not restarted after signals... */ + if (error == ERESTART) + error = EINTR; + if (error == EWOULDBLOCK) + error = 0; +#define putbits(name, x) \ + if (uap->name && \ + (error2 = copyout ((caddr_t) &obits[x], (caddr_t) uap->name, ni*sizeof(fd_mask)))) \ + error = error2; - if (error == 0) { - int error2; + if (error == 0) { + int error2; - putbits(in, 0); - putbits(ou, 1); - putbits(ex, 2); + putbits(in, 0); + putbits(ou, 1); + putbits(ex, 2); #undef putbits - } - return(error); + } + return(error); } /* @@ -394,19 +394,19 @@ done: void select() { - struct uap { - int nd; - fd_set *in, *ou, *ex; - struct timeval *tv; - } *uap = (struct uap *)u.u_arg; - register struct pselect_args *pselargs = (struct pselect_args *)uap; + struct uap { + int nd; + fd_set *in, *ou, *ex; + struct timeval *tv; + } *uap = (struct uap *)u.u_arg; + register struct pselect_args *pselargs = (struct pselect_args *)uap; - /* - * Fake the 6th parameter of pselect. See the comment below about the - * number of parameters! - */ - pselargs->maskp = 0; - u.u_error = select1 (pselargs, 0); + /* + * Fake the 6th parameter of pselect. See the comment below about the + * number of parameters! + */ + pselargs->maskp = 0; + u.u_error = select1 (pselargs, 0); } /* @@ -418,95 +418,95 @@ select() void pselect() { - register struct pselect_args *uap = (struct pselect_args *)u.u_arg; + register struct pselect_args *uap = (struct pselect_args *)u.u_arg; - u.u_error = select1(uap, 1); + u.u_error = select1(uap, 1); } /*ARGSUSED*/ int seltrue(dev, flag) - dev_t dev; - int flag; + dev_t dev; + int flag; { - return (1); + return (1); } void selwakeup (p, coll) - register struct proc *p; - long coll; + register struct proc *p; + long coll; { - if (coll) { - nselcoll++; - wakeup ((caddr_t)&selwait); - } - if (p) { - register int s = splhigh(); - if (p->p_wchan == (caddr_t)&selwait) { - if (p->p_stat == SSLEEP) - setrun(p); - else - unsleep(p); - } else if (p->p_flag & P_SELECT) - p->p_flag &= ~P_SELECT; - splx(s); - } + if (coll) { + nselcoll++; + wakeup ((caddr_t)&selwait); + } + if (p) { + register int s = splhigh(); + if (p->p_wchan == (caddr_t)&selwait) { + if (p->p_stat == SSLEEP) + setrun(p); + else + unsleep(p); + } else if (p->p_flag & P_SELECT) + p->p_flag &= ~P_SELECT; + splx(s); + } } int sorw(fp, uio) - register struct file *fp; - register struct uio *uio; + register struct file *fp; + register struct uio *uio; { -#ifdef INET - if (uio->uio_rw == UIO_READ) - return(SORECEIVE((struct socket *)fp->f_socket, 0, uio, 0, 0)); - return(SOSEND((struct socket *)fp->f_socket, 0, uio, 0, 0)); +#ifdef INET + if (uio->uio_rw == UIO_READ) + return(SORECEIVE((struct socket *)fp->f_socket, 0, uio, 0, 0)); + return(SOSEND((struct socket *)fp->f_socket, 0, uio, 0, 0)); #else - return (EOPNOTSUPP); + return (EOPNOTSUPP); #endif } int soctl(fp, com, data) - struct file *fp; - u_int com; - char *data; + struct file *fp; + u_int com; + char *data; { -#ifdef INET - return (SOO_IOCTL(fp, com, data)); +#ifdef INET + return (SOO_IOCTL(fp, com, data)); #else - return (EOPNOTSUPP); + return (EOPNOTSUPP); #endif } int sosel(fp, flag) - struct file *fp; - int flag; + struct file *fp; + int flag; { -#ifdef INET - return (SOO_SELECT(fp, flag)); +#ifdef INET + return (SOO_SELECT(fp, flag)); #else - return (EOPNOTSUPP); + return (EOPNOTSUPP); #endif } int socls(fp) - register struct file *fp; + register struct file *fp; { - register int error = 0; + register int error = 0; -#ifdef INET - if (fp->f_data) - error = SOCLOSE((struct socket *)fp->f_data); - fp->f_data = 0; +#ifdef INET + if (fp->f_data) + error = SOCLOSE((struct socket *)fp->f_data); + fp->f_data = 0; #else - error = EOPNOTSUPP; + error = EOPNOTSUPP; #endif - return(error); + return(error); } /* @@ -515,11 +515,11 @@ socls(fp) * networking might not be defined an appropriate error has to be set */ const struct fileops socketops = { - sorw, soctl, sosel, socls + sorw, soctl, sosel, socls }; const struct fileops *const Fops[] = { - NULL, &inodeops, &socketops, &pipeops + NULL, &inodeops, &socketops, &pipeops }; /* @@ -527,9 +527,9 @@ const struct fileops *const Fops[] = { */ void nostrategy (bp) - struct buf *bp; + struct buf *bp; { - /* Empty. */ + /* Empty. */ } #ifndef INET @@ -539,6 +539,6 @@ nostrategy (bp) void nonet() { - u.u_error = EPROTONOSUPPORT; + u.u_error = EPROTONOSUPPORT; } #endif diff --git a/sys/kernel/sys_inode.c b/sys/kernel/sys_inode.c index 6fb9b6a..2ba579a 100644 --- a/sys/kernel/sys_inode.c +++ b/sys/kernel/sys_inode.c @@ -21,381 +21,381 @@ #include "systm.h" #include "syslog.h" -daddr_t rablock; /* block to be read ahead */ +daddr_t rablock; /* block to be read ahead */ int ino_rw(fp, uio) - struct file *fp; - register struct uio *uio; + struct file *fp; + register struct uio *uio; { - register struct inode *ip = (struct inode *)fp->f_data; - u_int count, error; - int ioflag; + register struct inode *ip = (struct inode *)fp->f_data; + u_int count, error; + int ioflag; - if ((ip->i_mode&IFMT) != IFCHR) - ILOCK(ip); - uio->uio_offset = fp->f_offset; - count = uio->uio_resid; - if (uio->uio_rw == UIO_READ) { - error = rwip(ip, uio, fp->f_flag & FNONBLOCK ? IO_NDELAY : 0); - fp->f_offset += (count - uio->uio_resid); - } else { - ioflag = 0; - if ((ip->i_mode&IFMT) == IFREG && (fp->f_flag & FAPPEND)) - ioflag |= IO_APPEND; - if (fp->f_flag & FNONBLOCK) - ioflag |= IO_NDELAY; - if (fp->f_flag & FFSYNC || - (ip->i_fs->fs_flags & MNT_SYNCHRONOUS)) - ioflag |= IO_SYNC; - error = rwip(ip, uio, ioflag); - if (ioflag & IO_APPEND) - fp->f_offset = uio->uio_offset; - else - fp->f_offset += (count - uio->uio_resid); - } - if ((ip->i_mode&IFMT) != IFCHR) - IUNLOCK(ip); - return (error); + if ((ip->i_mode&IFMT) != IFCHR) + ILOCK(ip); + uio->uio_offset = fp->f_offset; + count = uio->uio_resid; + if (uio->uio_rw == UIO_READ) { + error = rwip(ip, uio, fp->f_flag & FNONBLOCK ? IO_NDELAY : 0); + fp->f_offset += (count - uio->uio_resid); + } else { + ioflag = 0; + if ((ip->i_mode&IFMT) == IFREG && (fp->f_flag & FAPPEND)) + ioflag |= IO_APPEND; + if (fp->f_flag & FNONBLOCK) + ioflag |= IO_NDELAY; + if (fp->f_flag & FFSYNC || + (ip->i_fs->fs_flags & MNT_SYNCHRONOUS)) + ioflag |= IO_SYNC; + error = rwip(ip, uio, ioflag); + if (ioflag & IO_APPEND) + fp->f_offset = uio->uio_offset; + else + fp->f_offset += (count - uio->uio_resid); + } + if ((ip->i_mode&IFMT) != IFCHR) + IUNLOCK(ip); + return (error); } int ino_ioctl(fp, com, data) - register struct file *fp; - register u_int com; - caddr_t data; + register struct file *fp; + register u_int com; + caddr_t data; { - register struct inode *ip = ((struct inode *)fp->f_data); - dev_t dev; + register struct inode *ip = ((struct inode *)fp->f_data); + dev_t dev; - switch (ip->i_mode & IFMT) { + switch (ip->i_mode & IFMT) { - case IFREG: - case IFDIR: - if (com == FIONREAD) { - if (fp->f_type==DTYPE_PIPE && !(fp->f_flag&FREAD)) - *(off_t *)data = 0; - else - *(off_t *)data = ip->i_size - fp->f_offset; - return (0); - } - if (com == FIONBIO || com == FIOASYNC) /* XXX */ - return (0); /* XXX */ - /* fall into ... */ + case IFREG: + case IFDIR: + if (com == FIONREAD) { + if (fp->f_type==DTYPE_PIPE && !(fp->f_flag&FREAD)) + *(off_t *)data = 0; + else + *(off_t *)data = ip->i_size - fp->f_offset; + return (0); + } + if (com == FIONBIO || com == FIOASYNC) /* XXX */ + return (0); /* XXX */ + /* fall into ... */ - default: - return (ENOTTY); + default: + return (ENOTTY); - case IFCHR: - dev = ip->i_rdev; - u.u_rval = 0; - if (setjmp(&u.u_qsave)) { - /* - * The ONLY way we can get here is via the longjump in sleep. Signals have - * been checked for and u_error set accordingly. All that remains to do - * is 'return'. - */ - return(u.u_error); - } - return((*cdevsw[major(dev)].d_ioctl)(dev,com,data,fp->f_flag)); - case IFBLK: - dev = ip->i_rdev; - u.u_rval = 0; - if (setjmp(&u.u_qsave)) { - /* - * The ONLY way we can get here is via the longjump in sleep. Signals have - * been checked for and u_error set accordingly. All that remains to do - * is 'return'. - */ - return(u.u_error); - } - return((*bdevsw[major(dev)].d_ioctl)(dev,com,data,fp->f_flag)); - } + case IFCHR: + dev = ip->i_rdev; + u.u_rval = 0; + if (setjmp(&u.u_qsave)) { + /* + * The ONLY way we can get here is via the longjump in sleep. Signals have + * been checked for and u_error set accordingly. All that remains to do + * is 'return'. + */ + return(u.u_error); + } + return((*cdevsw[major(dev)].d_ioctl)(dev,com,data,fp->f_flag)); + case IFBLK: + dev = ip->i_rdev; + u.u_rval = 0; + if (setjmp(&u.u_qsave)) { + /* + * The ONLY way we can get here is via the longjump in sleep. Signals have + * been checked for and u_error set accordingly. All that remains to do + * is 'return'. + */ + return(u.u_error); + } + return((*bdevsw[major(dev)].d_ioctl)(dev,com,data,fp->f_flag)); + } } int ino_select(fp, which) - struct file *fp; - int which; + struct file *fp; + int which; { - register struct inode *ip = (struct inode *)fp->f_data; - register dev_t dev; + register struct inode *ip = (struct inode *)fp->f_data; + register dev_t dev; - switch (ip->i_mode & IFMT) { + switch (ip->i_mode & IFMT) { - default: - return (1); /* XXX */ + default: + return (1); /* XXX */ - case IFCHR: - dev = ip->i_rdev; - return (*cdevsw[major(dev)].d_select)(dev, which); - } + case IFCHR: + dev = ip->i_rdev; + return (*cdevsw[major(dev)].d_select)(dev, which); + } } const struct fileops inodeops = { - ino_rw, ino_ioctl, ino_select, vn_closefile + ino_rw, ino_ioctl, ino_select, vn_closefile }; int rdwri (rw, ip, base, len, offset, ioflg, aresid) - enum uio_rw rw; - struct inode *ip; - caddr_t base; - int len; - off_t offset; - int ioflg; - register int *aresid; + enum uio_rw rw; + struct inode *ip; + caddr_t base; + int len; + off_t offset; + int ioflg; + register int *aresid; { - struct uio auio; - struct iovec aiov; - register int error; + struct uio auio; + struct iovec aiov; + register int error; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - aiov.iov_base = base; - aiov.iov_len = len; - auio.uio_rw = rw; - auio.uio_resid = len; - auio.uio_offset = offset; - error = rwip(ip, &auio, ioflg); - if (aresid) - *aresid = auio.uio_resid; - else - if (auio.uio_resid) - error = EIO; - return (error); + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + aiov.iov_base = base; + aiov.iov_len = len; + auio.uio_rw = rw; + auio.uio_resid = len; + auio.uio_offset = offset; + error = rwip(ip, &auio, ioflg); + if (aresid) + *aresid = auio.uio_resid; + else + if (auio.uio_resid) + error = EIO; + return (error); } int rwip (ip, uio, ioflag) - register struct inode *ip; - register struct uio *uio; - int ioflag; + register struct inode *ip; + register struct uio *uio; + int ioflag; { - dev_t dev = (dev_t)ip->i_rdev; - register struct buf *bp; - off_t osize; - daddr_t lbn, bn; - int n, on, type, resid; - int error = 0; - int flags; + dev_t dev = (dev_t)ip->i_rdev; + register struct buf *bp; + off_t osize; + daddr_t lbn, bn; + int n, on, type, resid; + int error = 0; + int flags; - //if (uio->uio_offset < 0) - //return (EINVAL); - type = ip->i_mode & IFMT; - /* - * The write case below checks that i/o is done synchronously to directories - * and that i/o to append only files takes place at the end of file. - * We do not panic on non-sync directory i/o - the sync bit is forced on. - */ - if (uio->uio_rw == UIO_READ) { - if (! (ip->i_fs->fs_flags & MNT_NOATIME)) - ip->i_flag |= IACC; - } else { - switch (type) { - case IFREG: - if (ioflag & IO_APPEND) - uio->uio_offset = ip->i_size; - if (ip->i_flags & APPEND && uio->uio_offset != ip->i_size) - return(EPERM); - break; - case IFDIR: - if ((ioflag & IO_SYNC) == 0) - ioflag |= IO_SYNC; - break; - case IFLNK: - case IFBLK: - case IFCHR: - break; - default: - return (EFTYPE); - } - } + //if (uio->uio_offset < 0) + //return (EINVAL); + type = ip->i_mode & IFMT; + /* + * The write case below checks that i/o is done synchronously to directories + * and that i/o to append only files takes place at the end of file. + * We do not panic on non-sync directory i/o - the sync bit is forced on. + */ + if (uio->uio_rw == UIO_READ) { + if (! (ip->i_fs->fs_flags & MNT_NOATIME)) + ip->i_flag |= IACC; + } else { + switch (type) { + case IFREG: + if (ioflag & IO_APPEND) + uio->uio_offset = ip->i_size; + if (ip->i_flags & APPEND && uio->uio_offset != ip->i_size) + return(EPERM); + break; + case IFDIR: + if ((ioflag & IO_SYNC) == 0) + ioflag |= IO_SYNC; + break; + case IFLNK: + case IFBLK: + case IFCHR: + break; + default: + return (EFTYPE); + } + } - /* - * The IO_SYNC flag is turned off here if the 'async' mount flag is on. - * Otherwise directory I/O (which is done by the kernel) would still - * synchronous (because the kernel carefully passes IO_SYNC for all directory - * I/O) even if the fs was mounted with "-o async". - * - * A side effect of this is that if the system administrator mounts a filesystem - * 'async' then the O_FSYNC flag to open() is ignored. - * - * This behaviour should probably be selectable via "sysctl fs.async.dirs" and - * "fs.async.ofsync". A project for a rainy day. - */ - if (type == IFREG || (type == IFDIR && (ip->i_fs->fs_flags & MNT_ASYNC))) - ioflag &= ~IO_SYNC; + /* + * The IO_SYNC flag is turned off here if the 'async' mount flag is on. + * Otherwise directory I/O (which is done by the kernel) would still + * synchronous (because the kernel carefully passes IO_SYNC for all directory + * I/O) even if the fs was mounted with "-o async". + * + * A side effect of this is that if the system administrator mounts a filesystem + * 'async' then the O_FSYNC flag to open() is ignored. + * + * This behaviour should probably be selectable via "sysctl fs.async.dirs" and + * "fs.async.ofsync". A project for a rainy day. + */ + if (type == IFREG || (type == IFDIR && (ip->i_fs->fs_flags & MNT_ASYNC))) + ioflag &= ~IO_SYNC; - if (type == IFCHR) { - if (uio->uio_rw == UIO_READ) { - if (! (ip->i_fs->fs_flags & MNT_NOATIME)) - ip->i_flag |= IACC; - error = (*cdevsw[major(dev)].d_read)(dev, uio, ioflag); - } else { - ip->i_flag |= IUPD|ICHG; - error = (*cdevsw[major(dev)].d_write)(dev, uio, ioflag); - } - return (error); - } - if (uio->uio_resid == 0) - return (0); - if (uio->uio_rw == UIO_WRITE && type == IFREG && - uio->uio_offset + uio->uio_resid > - u.u_rlimit[RLIMIT_FSIZE].rlim_cur) { - psignal(u.u_procp, SIGXFSZ); - return (EFBIG); - } - if (type != IFBLK) - dev = ip->i_dev; - resid = uio->uio_resid; - osize = ip->i_size; + if (type == IFCHR) { + if (uio->uio_rw == UIO_READ) { + if (! (ip->i_fs->fs_flags & MNT_NOATIME)) + ip->i_flag |= IACC; + error = (*cdevsw[major(dev)].d_read)(dev, uio, ioflag); + } else { + ip->i_flag |= IUPD|ICHG; + error = (*cdevsw[major(dev)].d_write)(dev, uio, ioflag); + } + return (error); + } + if (uio->uio_resid == 0) + return (0); + if (uio->uio_rw == UIO_WRITE && type == IFREG && + uio->uio_offset + uio->uio_resid > + u.u_rlimit[RLIMIT_FSIZE].rlim_cur) { + psignal(u.u_procp, SIGXFSZ); + return (EFBIG); + } + if (type != IFBLK) + dev = ip->i_dev; + resid = uio->uio_resid; + osize = ip->i_size; - flags = ioflag & IO_SYNC ? B_SYNC : 0; + flags = ioflag & IO_SYNC ? B_SYNC : 0; - do { - lbn = lblkno(uio->uio_offset); - on = blkoff(uio->uio_offset); - n = MIN((u_int)(DEV_BSIZE - on), uio->uio_resid); - if (type != IFBLK) { - if (uio->uio_rw == UIO_READ) { - off_t diff = ip->i_size - uio->uio_offset; - if (diff <= 0) - return (0); - if (diff < n) - n = diff; - bn = bmap(ip, lbn, B_READ, flags); - } else - bn = bmap(ip,lbn,B_WRITE, - n == DEV_BSIZE ? flags : flags|B_CLRBUF); - if (u.u_error || (uio->uio_rw == UIO_WRITE && (long)bn < 0)) - return (u.u_error); - if (uio->uio_rw == UIO_WRITE && uio->uio_offset + n > ip->i_size && - (type == IFDIR || type == IFREG || type == IFLNK)) - ip->i_size = uio->uio_offset + n; - } else { - bn = lbn; - rablock = bn + 1; - } - if (uio->uio_rw == UIO_READ) { - if ((long)bn < 0) { - bp = geteblk(); - bzero (bp->b_addr, MAXBSIZE); - } else if (ip->i_lastr + 1 == lbn) - bp = breada (dev, bn, rablock); - else - bp = bread (dev, bn); - ip->i_lastr = lbn; - } else { - if (n == DEV_BSIZE) - bp = getblk (dev, bn); - else - bp = bread (dev, bn); - /* - * 4.3 didn't do this, but 2.10 did. not sure why. - * something about tape drivers don't clear buffers on end-of-tape - * any longer (clrbuf can't be called from interrupt). - */ - if (bp->b_resid == DEV_BSIZE) { - bp->b_resid = 0; - bzero (bp->b_addr, MAXBSIZE); - } - } - n = MIN(n, DEV_BSIZE - bp->b_resid); - if (bp->b_flags & B_ERROR) { - error = EIO; - brelse(bp); - break; - } - u.u_error = uiomove (bp->b_addr + on, n, uio); - if (uio->uio_rw == UIO_READ) { - if (n + on == DEV_BSIZE || uio->uio_offset == ip->i_size) { - bp->b_flags |= B_AGE; - if (ip->i_flag & IPIPE) - bp->b_flags &= ~B_DELWRI; - } - brelse(bp); - } else { - if (ioflag & IO_SYNC) - bwrite(bp); - /* - * The check below interacts _very_ badly with virtual memory tmp files - * such as those used by 'ld'. These files tend to be small and repeatedly - * rewritten in 1kb chunks. The check below causes the device driver to be - * called (and I/O initiated) constantly. Not sure what to do about this yet - * but this comment is being placed here as a reminder. - */ - else if (n + on == DEV_BSIZE && !(ip->i_flag & IPIPE)) { - bp->b_flags |= B_AGE; - bawrite(bp); - } else - bdwrite(bp); - ip->i_flag |= IUPD|ICHG; - if (u.u_ruid != 0) - ip->i_mode &= ~(ISUID|ISGID); - } - } while (u.u_error == 0 && uio->uio_resid && n != 0); - if (error == 0) /* XXX */ - error = u.u_error; /* XXX */ - if (error && (uio->uio_rw == UIO_WRITE) && (ioflag & IO_UNIT) && - (type != IFBLK)) { - itrunc(ip, osize, ioflag & IO_SYNC); - uio->uio_offset -= (resid - uio->uio_resid); - uio->uio_resid = resid; - /* - * Should back out the change to the quota here but that would be a lot - * of work for little benefit. Besides we've already made the assumption - * that the entire write would succeed and users can't turn on the IO_UNIT - * bit for their writes anyways. - */ - } + do { + lbn = lblkno(uio->uio_offset); + on = blkoff(uio->uio_offset); + n = MIN((u_int)(DEV_BSIZE - on), uio->uio_resid); + if (type != IFBLK) { + if (uio->uio_rw == UIO_READ) { + off_t diff = ip->i_size - uio->uio_offset; + if (diff <= 0) + return (0); + if (diff < n) + n = diff; + bn = bmap(ip, lbn, B_READ, flags); + } else + bn = bmap(ip,lbn,B_WRITE, + n == DEV_BSIZE ? flags : flags|B_CLRBUF); + if (u.u_error || (uio->uio_rw == UIO_WRITE && (long)bn < 0)) + return (u.u_error); + if (uio->uio_rw == UIO_WRITE && uio->uio_offset + n > ip->i_size && + (type == IFDIR || type == IFREG || type == IFLNK)) + ip->i_size = uio->uio_offset + n; + } else { + bn = lbn; + rablock = bn + 1; + } + if (uio->uio_rw == UIO_READ) { + if ((long)bn < 0) { + bp = geteblk(); + bzero (bp->b_addr, MAXBSIZE); + } else if (ip->i_lastr + 1 == lbn) + bp = breada (dev, bn, rablock); + else + bp = bread (dev, bn); + ip->i_lastr = lbn; + } else { + if (n == DEV_BSIZE) + bp = getblk (dev, bn); + else + bp = bread (dev, bn); + /* + * 4.3 didn't do this, but 2.10 did. not sure why. + * something about tape drivers don't clear buffers on end-of-tape + * any longer (clrbuf can't be called from interrupt). + */ + if (bp->b_resid == DEV_BSIZE) { + bp->b_resid = 0; + bzero (bp->b_addr, MAXBSIZE); + } + } + n = MIN(n, DEV_BSIZE - bp->b_resid); + if (bp->b_flags & B_ERROR) { + error = EIO; + brelse(bp); + break; + } + u.u_error = uiomove (bp->b_addr + on, n, uio); + if (uio->uio_rw == UIO_READ) { + if (n + on == DEV_BSIZE || uio->uio_offset == ip->i_size) { + bp->b_flags |= B_AGE; + if (ip->i_flag & IPIPE) + bp->b_flags &= ~B_DELWRI; + } + brelse(bp); + } else { + if (ioflag & IO_SYNC) + bwrite(bp); + /* + * The check below interacts _very_ badly with virtual memory tmp files + * such as those used by 'ld'. These files tend to be small and repeatedly + * rewritten in 1kb chunks. The check below causes the device driver to be + * called (and I/O initiated) constantly. Not sure what to do about this yet + * but this comment is being placed here as a reminder. + */ + else if (n + on == DEV_BSIZE && !(ip->i_flag & IPIPE)) { + bp->b_flags |= B_AGE; + bawrite(bp); + } else + bdwrite(bp); + ip->i_flag |= IUPD|ICHG; + if (u.u_ruid != 0) + ip->i_mode &= ~(ISUID|ISGID); + } + } while (u.u_error == 0 && uio->uio_resid && n != 0); + if (error == 0) /* XXX */ + error = u.u_error; /* XXX */ + if (error && (uio->uio_rw == UIO_WRITE) && (ioflag & IO_UNIT) && + (type != IFBLK)) { + itrunc(ip, osize, ioflag & IO_SYNC); + uio->uio_offset -= (resid - uio->uio_resid); + uio->uio_resid = resid; + /* + * Should back out the change to the quota here but that would be a lot + * of work for little benefit. Besides we've already made the assumption + * that the entire write would succeed and users can't turn on the IO_UNIT + * bit for their writes anyways. + */ + } #ifdef whybother - if (! error && (ioflag & IO_SYNC)) - IUPDAT(ip, &time, &time, 1); + if (! error && (ioflag & IO_SYNC)) + IUPDAT(ip, &time, &time, 1); #endif - return (error); + return (error); } int ino_stat(ip, sb) - register struct inode *ip; - register struct stat *sb; + register struct inode *ip; + register struct stat *sb; { - register struct icommon2 *ic2; + register struct icommon2 *ic2; - ic2 = &ip->i_ic2; + ic2 = &ip->i_ic2; - /* - * inlined ITIMES which takes advantage of the common times pointer. - */ - if (ip->i_flag & (IUPD|IACC|ICHG)) { - ip->i_flag |= IMOD; - if (ip->i_flag & IACC) - ic2->ic_atime = time.tv_sec; - if (ip->i_flag & IUPD) - ic2->ic_mtime = time.tv_sec; - if (ip->i_flag & ICHG) - ic2->ic_ctime = time.tv_sec; - ip->i_flag &= ~(IUPD|IACC|ICHG); - } - sb->st_dev = ip->i_dev; - sb->st_ino = ip->i_number; - sb->st_mode = ip->i_mode; - sb->st_nlink = ip->i_nlink; - sb->st_uid = ip->i_uid; - sb->st_gid = ip->i_gid; - sb->st_rdev = (dev_t)ip->i_rdev; - sb->st_size = ip->i_size; - sb->st_atime = ic2->ic_atime; - sb->st_mtime = ic2->ic_mtime; - sb->st_ctime = ic2->ic_ctime; - sb->st_blksize = MAXBSIZE; - /* - * blocks are too tough to do; it's not worth the effort. - */ - sb->st_blocks = btod (ip->i_size); - sb->st_flags = ip->i_flags; - return (0); + /* + * inlined ITIMES which takes advantage of the common times pointer. + */ + if (ip->i_flag & (IUPD|IACC|ICHG)) { + ip->i_flag |= IMOD; + if (ip->i_flag & IACC) + ic2->ic_atime = time.tv_sec; + if (ip->i_flag & IUPD) + ic2->ic_mtime = time.tv_sec; + if (ip->i_flag & ICHG) + ic2->ic_ctime = time.tv_sec; + ip->i_flag &= ~(IUPD|IACC|ICHG); + } + sb->st_dev = ip->i_dev; + sb->st_ino = ip->i_number; + sb->st_mode = ip->i_mode; + sb->st_nlink = ip->i_nlink; + sb->st_uid = ip->i_uid; + sb->st_gid = ip->i_gid; + sb->st_rdev = (dev_t)ip->i_rdev; + sb->st_size = ip->i_size; + sb->st_atime = ic2->ic_atime; + sb->st_mtime = ic2->ic_mtime; + sb->st_ctime = ic2->ic_ctime; + sb->st_blksize = MAXBSIZE; + /* + * blocks are too tough to do; it's not worth the effort. + */ + sb->st_blocks = btod (ip->i_size); + sb->st_flags = ip->i_flags; + return (0); } /* @@ -406,73 +406,73 @@ ino_stat(ip, sb) */ int closei (ip, flag) - register struct inode *ip; - int flag; + register struct inode *ip; + int flag; { - register struct mount *mp; - register struct file *fp; - int mode, error; - dev_t dev; - int (*cfunc)(); + register struct mount *mp; + register struct file *fp; + int mode, error; + dev_t dev; + int (*cfunc)(); - mode = ip->i_mode & IFMT; - dev = ip->i_rdev; + mode = ip->i_mode & IFMT; + dev = ip->i_rdev; - switch (mode) { - case IFCHR: - cfunc = cdevsw[major(dev)].d_close; - break; - case IFBLK: - /* - * We don't want to really close the device if it is mounted - */ - /* MOUNT TABLE SHOULD HOLD INODE */ - for (mp = mount; mp < &mount[NMOUNT]; mp++) - if (mp->m_inodp != NULL && mp->m_dev == dev) - return(0); - cfunc = bdevsw[major(dev)].d_close; - break; - default: - return(0); - } - /* - * Check that another inode for the same device isn't active. - * This is because the same device can be referenced by two - * different inodes. - */ - for (fp = file; fp < file+NFILE; fp++) { - if (fp->f_type != DTYPE_INODE) - continue; - if (fp->f_count && (ip = (struct inode *)fp->f_data) && - ip->i_rdev == dev && (ip->i_mode&IFMT) == mode) - return(0); - } - if (mode == IFBLK) { - /* - * On last close of a block device (that isn't mounted) - * we must invalidate any in core blocks, so that - * we can, for instance, change floppy disks. - */ - bflush(dev); - binval(dev); - } - /* - * NOTE: none of the device drivers appear to either set u_error OR return - * anything meaningful from their close routines. It's a good thing - * programs don't bother checking the error status on close() calls. - * Apparently the only time "errno" is meaningful after a "close" is - * when the process is interrupted. - */ - if (setjmp (&u.u_qsave)) { - /* - * If device close routine is interrupted, - * must return so closef can clean up. - */ - if ((error = u.u_error) == 0) - error = EINTR; - } else - error = (*cfunc)(dev, flag, mode); - return (error); + switch (mode) { + case IFCHR: + cfunc = cdevsw[major(dev)].d_close; + break; + case IFBLK: + /* + * We don't want to really close the device if it is mounted + */ + /* MOUNT TABLE SHOULD HOLD INODE */ + for (mp = mount; mp < &mount[NMOUNT]; mp++) + if (mp->m_inodp != NULL && mp->m_dev == dev) + return(0); + cfunc = bdevsw[major(dev)].d_close; + break; + default: + return(0); + } + /* + * Check that another inode for the same device isn't active. + * This is because the same device can be referenced by two + * different inodes. + */ + for (fp = file; fp < file+NFILE; fp++) { + if (fp->f_type != DTYPE_INODE) + continue; + if (fp->f_count && (ip = (struct inode *)fp->f_data) && + ip->i_rdev == dev && (ip->i_mode&IFMT) == mode) + return(0); + } + if (mode == IFBLK) { + /* + * On last close of a block device (that isn't mounted) + * we must invalidate any in core blocks, so that + * we can, for instance, change floppy disks. + */ + bflush(dev); + binval(dev); + } + /* + * NOTE: none of the device drivers appear to either set u_error OR return + * anything meaningful from their close routines. It's a good thing + * programs don't bother checking the error status on close() calls. + * Apparently the only time "errno" is meaningful after a "close" is + * when the process is interrupted. + */ + if (setjmp (&u.u_qsave)) { + /* + * If device close routine is interrupted, + * must return so closef can clean up. + */ + if ((error = u.u_error) == 0) + error = EINTR; + } else + error = (*cfunc)(dev, flag, mode); + return (error); } /* @@ -482,75 +482,75 @@ closei (ip, flag) */ int ino_lock(fp, cmd) - register struct file *fp; - int cmd; + register struct file *fp; + int cmd; { - register int priority = PLOCK; - register struct inode *ip = (struct inode *)fp->f_data; - int error; + register int priority = PLOCK; + register struct inode *ip = (struct inode *)fp->f_data; + int error; - if ((cmd & LOCK_EX) == 0) - priority += 4; + if ((cmd & LOCK_EX) == 0) + priority += 4; /* * If there's a exclusive lock currently applied to the file then we've * gotta wait for the lock with everyone else. * * NOTE: We can NOT sleep on i_exlockc because it is on an odd byte boundary - * and the low (oddness) bit is reserved for networking/supervisor mode - * sleep channels. Thus we always sleep on i_shlockc and simply check - * the proper bits to see if the lock we want is granted. This may - * mean an extra wakeup/sleep event is done once in a while but - * everything will work correctly. + * and the low (oddness) bit is reserved for networking/supervisor mode + * sleep channels. Thus we always sleep on i_shlockc and simply check + * the proper bits to see if the lock we want is granted. This may + * mean an extra wakeup/sleep event is done once in a while but + * everything will work correctly. */ again: - while (ip->i_flag & IEXLOCK) { - /* - * If we're holding an exclusive - * lock, then release it. - */ - if (fp->f_flag & FEXLOCK) { - ino_unlock(fp, FEXLOCK); - continue; - } - if (cmd & LOCK_NB) - return (EWOULDBLOCK); - ip->i_flag |= ILWAIT; - error = tsleep((caddr_t)&ip->i_shlockc, priority | PCATCH, 0); - if (error) - return(error); - } - if ((cmd & LOCK_EX) && (ip->i_flag & ISHLOCK)) { - /* - * Must wait for any shared locks to finish - * before we try to apply a exclusive lock. - * - * If we're holding a shared - * lock, then release it. - */ - if (fp->f_flag & FSHLOCK) { - ino_unlock(fp, FSHLOCK); - goto again; - } - if (cmd & LOCK_NB) - return (EWOULDBLOCK); - ip->i_flag |= ILWAIT; - error = tsleep((caddr_t)&ip->i_shlockc, PLOCK | PCATCH, 0); - if (error) - return(error); - goto again; - } - if (cmd & LOCK_EX) { - cmd &= ~LOCK_SH; - ip->i_exlockc++; - ip->i_flag |= IEXLOCK; - fp->f_flag |= FEXLOCK; - } - if ((cmd & LOCK_SH) && (fp->f_flag & FSHLOCK) == 0) { - ip->i_shlockc++; - ip->i_flag |= ISHLOCK; - fp->f_flag |= FSHLOCK; - } - return (0); + while (ip->i_flag & IEXLOCK) { + /* + * If we're holding an exclusive + * lock, then release it. + */ + if (fp->f_flag & FEXLOCK) { + ino_unlock(fp, FEXLOCK); + continue; + } + if (cmd & LOCK_NB) + return (EWOULDBLOCK); + ip->i_flag |= ILWAIT; + error = tsleep((caddr_t)&ip->i_shlockc, priority | PCATCH, 0); + if (error) + return(error); + } + if ((cmd & LOCK_EX) && (ip->i_flag & ISHLOCK)) { + /* + * Must wait for any shared locks to finish + * before we try to apply a exclusive lock. + * + * If we're holding a shared + * lock, then release it. + */ + if (fp->f_flag & FSHLOCK) { + ino_unlock(fp, FSHLOCK); + goto again; + } + if (cmd & LOCK_NB) + return (EWOULDBLOCK); + ip->i_flag |= ILWAIT; + error = tsleep((caddr_t)&ip->i_shlockc, PLOCK | PCATCH, 0); + if (error) + return(error); + goto again; + } + if (cmd & LOCK_EX) { + cmd &= ~LOCK_SH; + ip->i_exlockc++; + ip->i_flag |= IEXLOCK; + fp->f_flag |= FEXLOCK; + } + if ((cmd & LOCK_SH) && (fp->f_flag & FSHLOCK) == 0) { + ip->i_shlockc++; + ip->i_flag |= ISHLOCK; + fp->f_flag |= FSHLOCK; + } + return (0); } /* @@ -558,32 +558,32 @@ again: */ void ino_unlock(fp, kind) - register struct file *fp; - int kind; + register struct file *fp; + int kind; { - register struct inode *ip = (struct inode *)fp->f_data; - register int flags; + register struct inode *ip = (struct inode *)fp->f_data; + register int flags; - kind &= fp->f_flag; - if (ip == NULL || kind == 0) - return; - flags = ip->i_flag; - if (kind & FSHLOCK) { - if (--ip->i_shlockc == 0) { - ip->i_flag &= ~ISHLOCK; - if (flags & ILWAIT) - wakeup((caddr_t)&ip->i_shlockc); - } - fp->f_flag &= ~FSHLOCK; - } - if (kind & FEXLOCK) { - if (--ip->i_exlockc == 0) { - ip->i_flag &= ~(IEXLOCK|ILWAIT); - if (flags & ILWAIT) - wakeup((caddr_t)&ip->i_shlockc); - } - fp->f_flag &= ~FEXLOCK; - } + kind &= fp->f_flag; + if (ip == NULL || kind == 0) + return; + flags = ip->i_flag; + if (kind & FSHLOCK) { + if (--ip->i_shlockc == 0) { + ip->i_flag &= ~ISHLOCK; + if (flags & ILWAIT) + wakeup((caddr_t)&ip->i_shlockc); + } + fp->f_flag &= ~FSHLOCK; + } + if (kind & FEXLOCK) { + if (--ip->i_exlockc == 0) { + ip->i_flag &= ~(IEXLOCK|ILWAIT); + if (flags & ILWAIT) + wakeup((caddr_t)&ip->i_shlockc); + } + fp->f_flag &= ~FEXLOCK; + } } /* @@ -592,92 +592,92 @@ ino_unlock(fp, kind) */ int openi (ip, mode) - register struct inode *ip; + register struct inode *ip; { - register dev_t dev = ip->i_rdev; - register int maj = major(dev); - dev_t bdev; - int error; + register dev_t dev = ip->i_rdev; + register int maj = major(dev); + dev_t bdev; + int error; - switch (ip->i_mode&IFMT) { + switch (ip->i_mode&IFMT) { - case IFCHR: - if (ip->i_fs->fs_flags & MNT_NODEV) - return(ENXIO); - if ((u_int)maj >= nchrdev) - return (ENXIO); - if (mode & FWRITE) { - /* - * When running in very secure mode, do not allow - * opens for writing of any disk character devices. - */ - if (securelevel >= 2 && isdisk(dev, IFCHR)) - return(EPERM); - /* - * When running in secure mode, do not allow opens - * for writing of /dev/mem, /dev/kmem, or character - * devices whose corresponding block devices are - * currently mounted. - */ - if (securelevel >= 1) { - if ((bdev = chrtoblk(dev)) != NODEV && - (error = ufs_mountedon(bdev))) - return(error); - if (iskmemdev(dev)) - return(EPERM); - } - } - return ((*cdevsw[maj].d_open)(dev, mode, S_IFCHR)); + case IFCHR: + if (ip->i_fs->fs_flags & MNT_NODEV) + return(ENXIO); + if ((u_int)maj >= nchrdev) + return (ENXIO); + if (mode & FWRITE) { + /* + * When running in very secure mode, do not allow + * opens for writing of any disk character devices. + */ + if (securelevel >= 2 && isdisk(dev, IFCHR)) + return(EPERM); + /* + * When running in secure mode, do not allow opens + * for writing of /dev/mem, /dev/kmem, or character + * devices whose corresponding block devices are + * currently mounted. + */ + if (securelevel >= 1) { + if ((bdev = chrtoblk(dev)) != NODEV && + (error = ufs_mountedon(bdev))) + return(error); + if (iskmemdev(dev)) + return(EPERM); + } + } + return ((*cdevsw[maj].d_open)(dev, mode, S_IFCHR)); - case IFBLK: - if (ip->i_fs->fs_flags & MNT_NODEV) - return(ENXIO); - if ((u_int)maj >= nblkdev) - return (ENXIO); - /* - * When running in very secure mode, do not allow - * opens for writing of any disk block devices. - */ - if (securelevel >= 2 && (mode & FWRITE) && isdisk(dev, IFBLK)) - return(EPERM); - /* - * Do not allow opens of block devices that are - * currently mounted. - * - * 2.11BSD must relax this restriction to allow 'fsck' to - * open the root filesystem (which is always mounted) during - * a reboot. Once in secure or very secure mode the - * above restriction is fully effective. On the otherhand - * fsck should 1) use the raw device, 2) not do sync calls... - */ - if (securelevel > 0 && (error = ufs_mountedon(dev))) - return(error); - return ((*bdevsw[maj].d_open)(dev, mode, S_IFBLK)); - } - return (0); + case IFBLK: + if (ip->i_fs->fs_flags & MNT_NODEV) + return(ENXIO); + if ((u_int)maj >= nblkdev) + return (ENXIO); + /* + * When running in very secure mode, do not allow + * opens for writing of any disk block devices. + */ + if (securelevel >= 2 && (mode & FWRITE) && isdisk(dev, IFBLK)) + return(EPERM); + /* + * Do not allow opens of block devices that are + * currently mounted. + * + * 2.11BSD must relax this restriction to allow 'fsck' to + * open the root filesystem (which is always mounted) during + * a reboot. Once in secure or very secure mode the + * above restriction is fully effective. On the otherhand + * fsck should 1) use the raw device, 2) not do sync calls... + */ + if (securelevel > 0 && (error = ufs_mountedon(dev))) + return(error); + return ((*bdevsw[maj].d_open)(dev, mode, S_IFBLK)); + } + return (0); } static void forceclose(dev) - register dev_t dev; + register dev_t dev; { - register struct file *fp; - register struct inode *ip; + register struct file *fp; + register struct inode *ip; - for (fp = file; fp < file+NFILE; fp++) { - if (fp->f_count == 0) - continue; - if (fp->f_type != DTYPE_INODE) - continue; - ip = (struct inode *)fp->f_data; - if (ip == 0) - continue; - if ((ip->i_mode & IFMT) != IFCHR) - continue; - if (ip->i_rdev != dev) - continue; - fp->f_flag &= ~(FREAD | FWRITE); - } + for (fp = file; fp < file+NFILE; fp++) { + if (fp->f_count == 0) + continue; + if (fp->f_type != DTYPE_INODE) + continue; + ip = (struct inode *)fp->f_data; + if (ip == 0) + continue; + if ((ip->i_mode & IFMT) != IFCHR) + continue; + if (ip->i_rdev != dev) + continue; + fp->f_flag &= ~(FREAD | FWRITE); + } } /* @@ -688,11 +688,11 @@ forceclose(dev) void vhangup() { - if (! suser()) - return; - if (u.u_ttyp == NULL) - return; - forceclose(u.u_ttyd); - if ((u.u_ttyp->t_state) & TS_ISOPEN) - gsignal(u.u_ttyp->t_pgrp, SIGHUP); + if (! suser()) + return; + if (u.u_ttyp == NULL) + return; + forceclose(u.u_ttyd); + if ((u.u_ttyp->t_state) & TS_ISOPEN) + gsignal(u.u_ttyp->t_pgrp, SIGHUP); } diff --git a/sys/kernel/sys_pipe.c b/sys/kernel/sys_pipe.c index c0a19c1..bf3e5e0 100644 --- a/sys/kernel/sys_pipe.c +++ b/sys/kernel/sys_pipe.c @@ -15,178 +15,178 @@ int readp (fp, uio, flag) - register struct file *fp; - register struct uio *uio; - int flag; + register struct file *fp; + register struct uio *uio; + int flag; { - register struct inode *ip; - int error; + register struct inode *ip; + int error; - ip = (struct inode *)fp->f_data; + ip = (struct inode *)fp->f_data; loop: - /* Very conservative locking. */ - ILOCK(ip); + /* Very conservative locking. */ + ILOCK(ip); - /* If nothing in the pipe, wait (unless FNONBLOCK is set). */ - if (ip->i_size == 0) { - /* - * If there are not both reader and writer active, - * return without satisfying read. - */ - IUNLOCK(ip); - if (ip->i_count != 2) - return (0); - if (fp->f_flag & FNONBLOCK) - return (EWOULDBLOCK); - ip->i_mode |= IREAD; - sleep((caddr_t)ip+4, PPIPE); - goto loop; - } + /* If nothing in the pipe, wait (unless FNONBLOCK is set). */ + if (ip->i_size == 0) { + /* + * If there are not both reader and writer active, + * return without satisfying read. + */ + IUNLOCK(ip); + if (ip->i_count != 2) + return (0); + if (fp->f_flag & FNONBLOCK) + return (EWOULDBLOCK); + ip->i_mode |= IREAD; + sleep((caddr_t)ip+4, PPIPE); + goto loop; + } - uio->uio_offset = fp->f_offset; - error = rwip(ip, uio, flag); - fp->f_offset = uio->uio_offset; + uio->uio_offset = fp->f_offset; + error = rwip(ip, uio, flag); + fp->f_offset = uio->uio_offset; - /* - * If reader has caught up with writer, reset - * offset and size to 0. - */ - if (fp->f_offset == ip->i_size) { - fp->f_offset = 0; - ip->i_size = 0; - if (ip->i_mode & IWRITE) { - ip->i_mode &= ~IWRITE; - wakeup((caddr_t)ip+2); - } - if (ip->i_wsel) { - selwakeup(ip->i_wsel, (long)(ip->i_flag & IWCOLL)); - ip->i_wsel = 0; - ip->i_flag &= ~IWCOLL; - } - } - IUNLOCK(ip); - return (error); + /* + * If reader has caught up with writer, reset + * offset and size to 0. + */ + if (fp->f_offset == ip->i_size) { + fp->f_offset = 0; + ip->i_size = 0; + if (ip->i_mode & IWRITE) { + ip->i_mode &= ~IWRITE; + wakeup((caddr_t)ip+2); + } + if (ip->i_wsel) { + selwakeup(ip->i_wsel, (long)(ip->i_flag & IWCOLL)); + ip->i_wsel = 0; + ip->i_flag &= ~IWCOLL; + } + } + IUNLOCK(ip); + return (error); } int writep (fp, uio, flag) - struct file *fp; - register struct uio *uio; - int flag; + struct file *fp; + register struct uio *uio; + int flag; { - register struct inode *ip; - register int c; - int error = 0; + register struct inode *ip; + register int c; + int error = 0; - ip = (struct inode *)fp->f_data; - c = uio->uio_resid; - ILOCK(ip); - if ((fp->f_flag & FNONBLOCK) && ip->i_size + c >= MAXPIPSIZ) { - error = EWOULDBLOCK; - goto done; - } + ip = (struct inode *)fp->f_data; + c = uio->uio_resid; + ILOCK(ip); + if ((fp->f_flag & FNONBLOCK) && ip->i_size + c >= MAXPIPSIZ) { + error = EWOULDBLOCK; + goto done; + } loop: - /* If all done, return. */ - if (c == 0) { - uio->uio_resid = 0; - goto done; - } + /* If all done, return. */ + if (c == 0) { + uio->uio_resid = 0; + goto done; + } - /* - * If there are not both read and write sides of the pipe active, - * return error and signal too. - */ - if (ip->i_count != 2) { - psignal(u.u_procp, SIGPIPE); - error = EPIPE; -done: IUNLOCK(ip); - return (error); - } + /* + * If there are not both read and write sides of the pipe active, + * return error and signal too. + */ + if (ip->i_count != 2) { + psignal(u.u_procp, SIGPIPE); + error = EPIPE; +done: IUNLOCK(ip); + return (error); + } - /* - * If the pipe is full, wait for reads to deplete - * and truncate it. - */ - if (ip->i_size >= MAXPIPSIZ) { - ip->i_mode |= IWRITE; - IUNLOCK(ip); - sleep((caddr_t)ip+2, PPIPE); - ILOCK(ip); - goto loop; - } + /* + * If the pipe is full, wait for reads to deplete + * and truncate it. + */ + if (ip->i_size >= MAXPIPSIZ) { + ip->i_mode |= IWRITE; + IUNLOCK(ip); + sleep((caddr_t)ip+2, PPIPE); + ILOCK(ip); + goto loop; + } - /* - * Write what is possible and loop back. - * If writing less than MAXPIPSIZ, it always goes. - * One can therefore get a file > MAXPIPSIZ if write - * sizes do not divide MAXPIPSIZ. - */ - uio->uio_offset = ip->i_size; - uio->uio_resid = MIN((u_int)c, (u_int)MAXPIPSIZ); - c -= uio->uio_resid; - error = rwip(ip, uio, flag); - if (ip->i_mode&IREAD) { - ip->i_mode &= ~IREAD; - wakeup((caddr_t)ip+4); - } - if (ip->i_rsel) { - selwakeup(ip->i_rsel, (long)(ip->i_flag & IRCOLL)); - ip->i_rsel = 0; - ip->i_flag &= ~IRCOLL; - } - goto loop; + /* + * Write what is possible and loop back. + * If writing less than MAXPIPSIZ, it always goes. + * One can therefore get a file > MAXPIPSIZ if write + * sizes do not divide MAXPIPSIZ. + */ + uio->uio_offset = ip->i_size; + uio->uio_resid = MIN((u_int)c, (u_int)MAXPIPSIZ); + c -= uio->uio_resid; + error = rwip(ip, uio, flag); + if (ip->i_mode&IREAD) { + ip->i_mode &= ~IREAD; + wakeup((caddr_t)ip+4); + } + if (ip->i_rsel) { + selwakeup(ip->i_rsel, (long)(ip->i_flag & IRCOLL)); + ip->i_rsel = 0; + ip->i_flag &= ~IRCOLL; + } + goto loop; } int pipe_rw (fp, uio, flag) - register struct file *fp; - register struct uio *uio; - int flag; + register struct file *fp; + register struct uio *uio; + int flag; { - if (uio->uio_rw == UIO_READ) - return (readp(fp, uio, flag)); - return (writep(fp, uio, flag)); + if (uio->uio_rw == UIO_READ) + return (readp(fp, uio, flag)); + return (writep(fp, uio, flag)); } int pipe_select (fp, which) - struct file *fp; - int which; + struct file *fp; + int which; { - register struct inode *ip = (struct inode *)fp->f_data; - register struct proc *p; - register int retval = 0; - extern int selwait; + register struct inode *ip = (struct inode *)fp->f_data; + register struct proc *p; + register int retval = 0; + extern int selwait; - ILOCK(ip); - if (ip->i_count != 2) - retval = 1; + ILOCK(ip); + if (ip->i_count != 2) + retval = 1; - else switch (which) { - case FREAD: - if (ip->i_size) { - retval = 1; - break; - } - if ((p = ip->i_rsel) && p->p_wchan == (caddr_t)&selwait) - ip->i_flag |= IRCOLL; - else - ip->i_rsel = u.u_procp; - break; + else switch (which) { + case FREAD: + if (ip->i_size) { + retval = 1; + break; + } + if ((p = ip->i_rsel) && p->p_wchan == (caddr_t)&selwait) + ip->i_flag |= IRCOLL; + else + ip->i_rsel = u.u_procp; + break; - case FWRITE: - if (ip->i_size < MAXPIPSIZ) { - retval = 1; - break; - } - if ((p = ip->i_wsel) && p->p_wchan == (caddr_t)&selwait) - ip->i_flag |= IWCOLL; - else - ip->i_wsel = u.u_procp; - break; - } - IUNLOCK(ip); - return(retval); + case FWRITE: + if (ip->i_size < MAXPIPSIZ) { + retval = 1; + break; + } + if ((p = ip->i_wsel) && p->p_wchan == (caddr_t)&selwait) + ip->i_flag |= IWCOLL; + else + ip->i_wsel = u.u_procp; + break; + } + IUNLOCK(ip); + return(retval); } /* @@ -201,38 +201,38 @@ pipe_select (fp, which) */ int pipe_close(fp) - struct file *fp; + struct file *fp; { - register struct inode *ip = (struct inode *)fp->f_data; + register struct inode *ip = (struct inode *)fp->f_data; - ilock(ip); -#ifdef DIAGNOSTIC - if ((ip->i_flag & IPIPE) == 0) - panic("pipe_close !IPIPE"); + ilock(ip); +#ifdef DIAGNOSTIC + if ((ip->i_flag & IPIPE) == 0) + panic("pipe_close !IPIPE"); #endif - if (ip->i_rsel) { - selwakeup(ip->i_rsel, (long)(ip->i_flag & IRCOLL)); - ip->i_rsel = 0; - ip->i_flag &= ~IRCOLL; - } - if (ip->i_wsel) { - selwakeup(ip->i_wsel, (long)(ip->i_flag & IWCOLL)); - ip->i_wsel = 0; - ip->i_flag &= ~IWCOLL; - } - ip->i_mode &= ~(IREAD|IWRITE); - wakeup((caddr_t)ip+2); - wakeup((caddr_t)ip+4); + if (ip->i_rsel) { + selwakeup(ip->i_rsel, (long)(ip->i_flag & IRCOLL)); + ip->i_rsel = 0; + ip->i_flag &= ~IRCOLL; + } + if (ip->i_wsel) { + selwakeup(ip->i_wsel, (long)(ip->i_flag & IWCOLL)); + ip->i_wsel = 0; + ip->i_flag &= ~IWCOLL; + } + ip->i_mode &= ~(IREAD|IWRITE); + wakeup((caddr_t)ip+2); + wakeup((caddr_t)ip+4); - /* - * And finally decrement the reference count and (likely) release the inode. - */ - iput(ip); - return(0); + /* + * And finally decrement the reference count and (likely) release the inode. + */ + iput(ip); + return(0); } const struct fileops pipeops = { - pipe_rw, ino_ioctl, pipe_select, pipe_close + pipe_rw, ino_ioctl, pipe_select, pipe_close }; /* @@ -243,65 +243,65 @@ const struct fileops pipeops = { void pipe() { - register struct inode *ip; - register struct file *rf, *wf; - static struct mount *mp; - struct inode itmp; - int r; + register struct inode *ip; + register struct file *rf, *wf; + static struct mount *mp; + struct inode itmp; + int r; - /* - * if pipedev not yet found, or not available, get it; if can't - * find it, use rootdev. It would be cleaner to wander around - * and fix it so that this and getfs() only check m_dev OR - * m_inodp, but hopefully the mount table isn't scanned enough - * to make it a problem. Besides, 4.3's is just as bad. Basic - * fantasy is that if m_inodp is set, m_dev *will* be okay. - */ - if (! mp || ! mp->m_inodp || mp->m_dev != pipedev) { - for (mp = &mount[0]; ; ++mp) { - if (mp == &mount[NMOUNT]) { - mp = &mount[0]; /* use root */ - break; - } - if (mp->m_inodp == NULL || mp->m_dev != pipedev) - continue; - break; - } - if (mp->m_filsys.fs_ronly) { - u.u_error = EROFS; - return; - } - } - itmp.i_fs = &mp->m_filsys; - itmp.i_dev = mp->m_dev; - ip = ialloc (&itmp); - if (ip == NULL) - return; - rf = falloc(); - if (rf == NULL) { - iput (ip); - return; - } - r = u.u_rval; - wf = falloc(); - if (wf == NULL) { - rf->f_count = 0; - u.u_ofile[r] = NULL; - iput (ip); - return; - } + /* + * if pipedev not yet found, or not available, get it; if can't + * find it, use rootdev. It would be cleaner to wander around + * and fix it so that this and getfs() only check m_dev OR + * m_inodp, but hopefully the mount table isn't scanned enough + * to make it a problem. Besides, 4.3's is just as bad. Basic + * fantasy is that if m_inodp is set, m_dev *will* be okay. + */ + if (! mp || ! mp->m_inodp || mp->m_dev != pipedev) { + for (mp = &mount[0]; ; ++mp) { + if (mp == &mount[NMOUNT]) { + mp = &mount[0]; /* use root */ + break; + } + if (mp->m_inodp == NULL || mp->m_dev != pipedev) + continue; + break; + } + if (mp->m_filsys.fs_ronly) { + u.u_error = EROFS; + return; + } + } + itmp.i_fs = &mp->m_filsys; + itmp.i_dev = mp->m_dev; + ip = ialloc (&itmp); + if (ip == NULL) + return; + rf = falloc(); + if (rf == NULL) { + iput (ip); + return; + } + r = u.u_rval; + wf = falloc(); + if (wf == NULL) { + rf->f_count = 0; + u.u_ofile[r] = NULL; + iput (ip); + return; + } #ifdef __mips__ - /* Move a secondary return value to register $v1. */ - u.u_frame [FRAME_R3] = u.u_rval; + /* Move a secondary return value to register $v1. */ + u.u_frame [FRAME_R3] = u.u_rval; #else #error "pipe return value for unknown architecture" #endif - u.u_rval = r; - wf->f_flag = FWRITE; - rf->f_flag = FREAD; - rf->f_type = wf->f_type = DTYPE_PIPE; - rf->f_data = wf->f_data = (caddr_t) ip; - ip->i_count = 2; - ip->i_mode = IFREG; - ip->i_flag = IACC | IUPD | ICHG | IPIPE; + u.u_rval = r; + wf->f_flag = FWRITE; + rf->f_flag = FREAD; + rf->f_type = wf->f_type = DTYPE_PIPE; + rf->f_data = wf->f_data = (caddr_t) ip; + ip->i_count = 2; + ip->i_mode = IFREG; + ip->i_flag = IACC | IUPD | ICHG | IPIPE; } diff --git a/sys/kernel/sys_process.c b/sys/kernel/sys_process.c index e029675..1f9ecd8 100644 --- a/sys/kernel/sys_process.c +++ b/sys/kernel/sys_process.c @@ -17,40 +17,40 @@ void ptrace() { - register struct proc *p; - register struct a { - int req; - int pid; - int *addr; - int data; - } *uap; + register struct proc *p; + register struct a { + int req; + int pid; + int *addr; + int data; + } *uap; - uap = (struct a *)u.u_arg; - if (uap->req <= 0) { - u.u_procp->p_flag |= P_TRACED; - return; - } - p = pfind(uap->pid); - if (p == 0 || p->p_stat != SSTOP || p->p_ppid != u.u_procp->p_pid || - !(p->p_flag & P_TRACED)) { - u.u_error = ESRCH; - return; - } - while (ipc.ip_lock) - sleep((caddr_t)&ipc, PZERO); - ipc.ip_lock = p->p_pid; - ipc.ip_data = uap->data; - ipc.ip_addr = uap->addr; - ipc.ip_req = uap->req; - p->p_flag &= ~P_WAITED; - setrun(p); - while (ipc.ip_req > 0) - sleep((caddr_t)&ipc, PZERO); - u.u_rval = ipc.ip_data; - if (ipc.ip_req < 0) - u.u_error = EIO; - ipc.ip_lock = 0; - wakeup((caddr_t)&ipc); + uap = (struct a *)u.u_arg; + if (uap->req <= 0) { + u.u_procp->p_flag |= P_TRACED; + return; + } + p = pfind(uap->pid); + if (p == 0 || p->p_stat != SSTOP || p->p_ppid != u.u_procp->p_pid || + !(p->p_flag & P_TRACED)) { + u.u_error = ESRCH; + return; + } + while (ipc.ip_lock) + sleep((caddr_t)&ipc, PZERO); + ipc.ip_lock = p->p_pid; + ipc.ip_data = uap->data; + ipc.ip_addr = uap->addr; + ipc.ip_req = uap->req; + p->p_flag &= ~P_WAITED; + setrun(p); + while (ipc.ip_req > 0) + sleep((caddr_t)&ipc, PZERO); + u.u_rval = ipc.ip_data; + if (ipc.ip_req < 0) + u.u_error = EIO; + ipc.ip_lock = 0; + wakeup((caddr_t)&ipc); } /* @@ -61,77 +61,77 @@ ptrace() int procxmt() { - register int i, *p; + register int i, *p; - if (ipc.ip_lock != u.u_procp->p_pid) - return(0); - u.u_procp->p_slptime = 0; - i = ipc.ip_req; - ipc.ip_req = 0; - wakeup ((caddr_t)&ipc); - switch (i) { + if (ipc.ip_lock != u.u_procp->p_pid) + return(0); + u.u_procp->p_slptime = 0; + i = ipc.ip_req; + ipc.ip_req = 0; + wakeup ((caddr_t)&ipc); + switch (i) { - /* read user I */ - case PT_READ_I: + /* read user I */ + case PT_READ_I: - /* read user D */ - case PT_READ_D: - if (baduaddr ((caddr_t) ipc.ip_addr)) - goto error; - ipc.ip_data = *(int*) ipc.ip_addr; - break; + /* read user D */ + case PT_READ_D: + if (baduaddr ((caddr_t) ipc.ip_addr)) + goto error; + ipc.ip_data = *(int*) ipc.ip_addr; + break; - /* read u */ - case PT_READ_U: - i = (int) ipc.ip_addr; - if (i < 0 || i >= USIZE) - goto error; - ipc.ip_data = ((unsigned*)&u) [i/sizeof(int)]; - break; + /* read u */ + case PT_READ_U: + i = (int) ipc.ip_addr; + if (i < 0 || i >= USIZE) + goto error; + ipc.ip_data = ((unsigned*)&u) [i/sizeof(int)]; + break; - /* write user I */ - case PT_WRITE_I: - /* write user D */ - case PT_WRITE_D: - if (baduaddr ((caddr_t) ipc.ip_addr)) - goto error; - *(int*) ipc.ip_addr = ipc.ip_data; - break; + /* write user I */ + case PT_WRITE_I: + /* write user D */ + case PT_WRITE_D: + if (baduaddr ((caddr_t) ipc.ip_addr)) + goto error; + *(int*) ipc.ip_addr = ipc.ip_data; + break; - /* write u */ - case PT_WRITE_U: - i = (int)ipc.ip_addr; - p = (int*)&u + i/sizeof(int); - for (i=0; i NSIG) - goto error; - u.u_procp->p_ptracesig = ipc.ip_data; - return(1); + /* set signal and continue */ + /* one version causes a trace-trap */ + case PT_STEP: + /* Use Status.RP bit to indicate a single-step request. */ + u.u_frame [FRAME_STATUS] |= ST_RP; + /* FALL THROUGH TO ... */ + case PT_CONTINUE: + if ((int)ipc.ip_addr != 1) + u.u_frame [FRAME_PC] = (int)ipc.ip_addr; + if (ipc.ip_data > NSIG) + goto error; + u.u_procp->p_ptracesig = ipc.ip_data; + return(1); - /* force exit */ - case PT_KILL: - exit(u.u_procp->p_ptracesig); - /*NOTREACHED*/ + /* force exit */ + case PT_KILL: + exit(u.u_procp->p_ptracesig); + /*NOTREACHED*/ - default: + default: error: - ipc.ip_req = -1; - } - return(0); + ipc.ip_req = -1; + } + return(0); } diff --git a/sys/kernel/syscalls.c b/sys/kernel/syscalls.c index b6ac2b3..25fb06f 100644 --- a/sys/kernel/syscalls.c +++ b/sys/kernel/syscalls.c @@ -9,161 +9,161 @@ */ #ifndef pdp11 const char *const syscallnames[] = { - "indir", /* 0 = indir */ - "exit", /* 1 = exit */ - "fork", /* 2 = fork */ - "read", /* 3 = read */ - "write", /* 4 = write */ - "open", /* 5 = open */ - "close", /* 6 = close */ - "wait4", /* 7 = wait4 */ - "#8", /* 8 = (old creat) */ - "link", /* 9 = link */ - "unlink", /* 10 = unlink */ - "execv", /* 11 = execv */ - "chdir", /* 12 = chdir */ - "fchdir", /* 13 = fchdir */ - "mknod", /* 14 = mknod */ - "chmod", /* 15 = chmod */ - "chown", /* 16 = chown; now 3 args */ - "chflags", /* 17 = chflags */ - "fchflags", /* 18 = fchflags */ - "lseek", /* 19 = lseek */ - "getpid", /* 20 = getpid */ - "mount", /* 21 = mount */ - "umount", /* 22 = umount */ - "__sysctl", /* 23 = __sysctl */ - "getuid", /* 24 = getuid */ - "geteuid", /* 25 = geteuid */ - "ptrace", /* 26 = ptrace */ - "getppid", /* 27 = getppid */ - "statfs", /* 28 = statfs */ - "fstatfs", /* 29 = fstatfs */ - "getfsstat", /* 30 = getfsstat */ - "sigaction", /* 31 = sigaction */ - "sigprocmask", /* 32 = sigprocmask */ - "access", /* 33 = access */ - "sigpending", /* 34 = sigpending */ - "sigaltstack", /* 35 = sigaltstack */ - "sync", /* 36 = sync */ - "kill", /* 37 = kill */ - "stat", /* 38 = stat */ - "getlogin", /* 39 = getlogin */ - "lstat", /* 40 = lstat */ - "dup", /* 41 = dup */ - "pipe", /* 42 = pipe */ - "setlogin", /* 43 = setlogin */ - "profil", /* 44 = profil */ - "setuid", /* 45 = setuid */ - "seteuid", /* 46 = seteuid */ - "getgid", /* 47 = getgid */ - "getegid", /* 48 = getegid */ - "setgid", /* 49 = setgid */ - "setegid", /* 50 = setegid */ - "kmemdev", /* 51 = kmemdev */ - "phys", /* 52 = (2.9) set phys addr */ - "lock", /* 53 = (2.9) lock in core */ - "ioctl", /* 54 = ioctl */ - "reboot", /* 55 = reboot */ - "sigwait", /* 56 = sigwait */ - "symlink", /* 57 = symlink */ - "readlink", /* 58 = readlink */ - "execve", /* 59 = execve */ - "umask", /* 60 = umask */ - "chroot", /* 61 = chroot */ - "fstat", /* 62 = fstat */ - "#63", /* 63 = unused */ - "#64", /* 64 = (old getpagesize) */ - "pselect", /* 65 = pselect */ - "vfork", /* 66 = vfork */ - "#67", /* 67 = unused */ - "#68", /* 68 = unused */ - "brk", /* 69 = brk */ - "rdglob", /* 70 = read from global space */ - "wrglob", /* 71 = write to global space */ - "msec", /* 72 = kticks */ - "#73", /* 73 = unused */ - "#74", /* 74 = unused */ - "#75", /* 75 = unused */ - "vhangup", /* 76 = vhangup */ - "#77", /* 77 = unused */ - "#78", /* 78 = unused */ - "getgroups", /* 79 = getgroups */ - "setgroups", /* 80 = setgroups */ - "getpgrp", /* 81 = getpgrp */ - "setpgrp", /* 82 = setpgrp */ - "setitimer", /* 83 = setitimer */ - "old wait", /* 84 = wait,wait3 COMPAT*/ - "#85", /* 85 = unused */ - "getitimer", /* 86 = getitimer */ - "#87", /* 87 = (old gethostname) */ - "#88", /* 88 = (old sethostname) */ - "getdtablesize", /* 89 = getdtablesize */ - "dup2", /* 90 = dup2 */ - "#91", /* 91 = unused */ - "fcntl", /* 92 = fcntl */ - "select", /* 93 = select */ - "#94", /* 94 = unused */ - "fsync", /* 95 = fsync */ - "setpriority", /* 96 = setpriority */ - "socket", /* 97 = socket */ - "connect", /* 98 = connect */ - "accept", /* 99 = accept */ - "getpriority", /* 100 = getpriority */ - "send", /* 101 = send */ - "recv", /* 102 = recv */ - "sigreturn", /* 103 = sigreturn */ - "bind", /* 104 = bind */ - "setsockopt", /* 105 = setsockopt */ - "listen", /* 106 = listen */ - "sigsuspend", /* 107 = sigsuspend */ - "#108", /* 108 = (old sigvec) */ - "#109", /* 109 = (old sigblock) */ - "#110", /* 110 = (old sigsetmask) */ - "#111", /* 111 = (old sigpause) */ - "sigstack", /* 112 = sigstack COMPAT-43 */ - "recvmsg", /* 113 = recvmsg */ - "sendmsg", /* 114 = sendmsg */ - "#115", /* 115 = unused */ - "gettimeofday", /* 116 = gettimeofday */ - "getrusage", /* 117 = getrusage */ - "getsockopt", /* 118 = getsockopt */ - "#119", /* 119 = unused */ - "readv", /* 120 = readv */ - "writev", /* 121 = writev */ - "settimeofday", /* 122 = settimeofday */ - "fchown", /* 123 = fchown */ - "fchmod", /* 124 = fchmod */ - "recvfrom", /* 125 = recvfrom */ - "#126", /* 126 = (old setreuid) */ - "#127", /* 127 = (old setregid) */ - "rename", /* 128 = rename */ - "truncate", /* 129 = truncate */ - "ftruncate", /* 130 = ftruncate */ - "flock", /* 131 = flock */ - "#132", /* 132 = unused */ - "sendto", /* 133 = sendto */ - "shutdown", /* 134 = shutdown */ - "socketpair", /* 135 = socketpair */ - "mkdir", /* 136 = mkdir */ - "rmdir", /* 137 = rmdir */ - "utimes", /* 138 = utimes */ - "#139", /* 139 = unused */ - "adjtime", /* 140 = adjtime */ - "getpeername", /* 141 = getpeername */ - "#142", /* 142 = (old gethostid) */ - "#143", /* 143 = (old sethostid) */ - "getrlimit", /* 144 = getrlimit */ - "setrlimit", /* 145 = setrlimit */ - "killpg", /* 146 = killpg */ - "#147", /* 147 = unused */ - "setquota", /* 148 = setquota */ - "quota", /* 149 = quota */ - "getsockname", /* 150 = getsockname */ - "#151", /* 151 = unused */ - "ustore", /* 152 = ustore */ - "ufetch", /* 153 = ufetch */ - "ucall", /* 154 = ucall */ - "#155", /* 155 = unused */ + "indir", /* 0 = indir */ + "exit", /* 1 = exit */ + "fork", /* 2 = fork */ + "read", /* 3 = read */ + "write", /* 4 = write */ + "open", /* 5 = open */ + "close", /* 6 = close */ + "wait4", /* 7 = wait4 */ + "#8", /* 8 = (old creat) */ + "link", /* 9 = link */ + "unlink", /* 10 = unlink */ + "execv", /* 11 = execv */ + "chdir", /* 12 = chdir */ + "fchdir", /* 13 = fchdir */ + "mknod", /* 14 = mknod */ + "chmod", /* 15 = chmod */ + "chown", /* 16 = chown; now 3 args */ + "chflags", /* 17 = chflags */ + "fchflags", /* 18 = fchflags */ + "lseek", /* 19 = lseek */ + "getpid", /* 20 = getpid */ + "mount", /* 21 = mount */ + "umount", /* 22 = umount */ + "__sysctl", /* 23 = __sysctl */ + "getuid", /* 24 = getuid */ + "geteuid", /* 25 = geteuid */ + "ptrace", /* 26 = ptrace */ + "getppid", /* 27 = getppid */ + "statfs", /* 28 = statfs */ + "fstatfs", /* 29 = fstatfs */ + "getfsstat", /* 30 = getfsstat */ + "sigaction", /* 31 = sigaction */ + "sigprocmask", /* 32 = sigprocmask */ + "access", /* 33 = access */ + "sigpending", /* 34 = sigpending */ + "sigaltstack", /* 35 = sigaltstack */ + "sync", /* 36 = sync */ + "kill", /* 37 = kill */ + "stat", /* 38 = stat */ + "getlogin", /* 39 = getlogin */ + "lstat", /* 40 = lstat */ + "dup", /* 41 = dup */ + "pipe", /* 42 = pipe */ + "setlogin", /* 43 = setlogin */ + "profil", /* 44 = profil */ + "setuid", /* 45 = setuid */ + "seteuid", /* 46 = seteuid */ + "getgid", /* 47 = getgid */ + "getegid", /* 48 = getegid */ + "setgid", /* 49 = setgid */ + "setegid", /* 50 = setegid */ + "kmemdev", /* 51 = kmemdev */ + "phys", /* 52 = (2.9) set phys addr */ + "lock", /* 53 = (2.9) lock in core */ + "ioctl", /* 54 = ioctl */ + "reboot", /* 55 = reboot */ + "sigwait", /* 56 = sigwait */ + "symlink", /* 57 = symlink */ + "readlink", /* 58 = readlink */ + "execve", /* 59 = execve */ + "umask", /* 60 = umask */ + "chroot", /* 61 = chroot */ + "fstat", /* 62 = fstat */ + "#63", /* 63 = unused */ + "#64", /* 64 = (old getpagesize) */ + "pselect", /* 65 = pselect */ + "vfork", /* 66 = vfork */ + "#67", /* 67 = unused */ + "#68", /* 68 = unused */ + "brk", /* 69 = brk */ + "rdglob", /* 70 = read from global space */ + "wrglob", /* 71 = write to global space */ + "msec", /* 72 = kticks */ + "#73", /* 73 = unused */ + "#74", /* 74 = unused */ + "#75", /* 75 = unused */ + "vhangup", /* 76 = vhangup */ + "#77", /* 77 = unused */ + "#78", /* 78 = unused */ + "getgroups", /* 79 = getgroups */ + "setgroups", /* 80 = setgroups */ + "getpgrp", /* 81 = getpgrp */ + "setpgrp", /* 82 = setpgrp */ + "setitimer", /* 83 = setitimer */ + "old wait", /* 84 = wait,wait3 COMPAT*/ + "#85", /* 85 = unused */ + "getitimer", /* 86 = getitimer */ + "#87", /* 87 = (old gethostname) */ + "#88", /* 88 = (old sethostname) */ + "getdtablesize", /* 89 = getdtablesize */ + "dup2", /* 90 = dup2 */ + "#91", /* 91 = unused */ + "fcntl", /* 92 = fcntl */ + "select", /* 93 = select */ + "#94", /* 94 = unused */ + "fsync", /* 95 = fsync */ + "setpriority", /* 96 = setpriority */ + "socket", /* 97 = socket */ + "connect", /* 98 = connect */ + "accept", /* 99 = accept */ + "getpriority", /* 100 = getpriority */ + "send", /* 101 = send */ + "recv", /* 102 = recv */ + "sigreturn", /* 103 = sigreturn */ + "bind", /* 104 = bind */ + "setsockopt", /* 105 = setsockopt */ + "listen", /* 106 = listen */ + "sigsuspend", /* 107 = sigsuspend */ + "#108", /* 108 = (old sigvec) */ + "#109", /* 109 = (old sigblock) */ + "#110", /* 110 = (old sigsetmask) */ + "#111", /* 111 = (old sigpause) */ + "sigstack", /* 112 = sigstack COMPAT-43 */ + "recvmsg", /* 113 = recvmsg */ + "sendmsg", /* 114 = sendmsg */ + "#115", /* 115 = unused */ + "gettimeofday", /* 116 = gettimeofday */ + "getrusage", /* 117 = getrusage */ + "getsockopt", /* 118 = getsockopt */ + "#119", /* 119 = unused */ + "readv", /* 120 = readv */ + "writev", /* 121 = writev */ + "settimeofday", /* 122 = settimeofday */ + "fchown", /* 123 = fchown */ + "fchmod", /* 124 = fchmod */ + "recvfrom", /* 125 = recvfrom */ + "#126", /* 126 = (old setreuid) */ + "#127", /* 127 = (old setregid) */ + "rename", /* 128 = rename */ + "truncate", /* 129 = truncate */ + "ftruncate", /* 130 = ftruncate */ + "flock", /* 131 = flock */ + "#132", /* 132 = unused */ + "sendto", /* 133 = sendto */ + "shutdown", /* 134 = shutdown */ + "socketpair", /* 135 = socketpair */ + "mkdir", /* 136 = mkdir */ + "rmdir", /* 137 = rmdir */ + "utimes", /* 138 = utimes */ + "#139", /* 139 = unused */ + "adjtime", /* 140 = adjtime */ + "getpeername", /* 141 = getpeername */ + "#142", /* 142 = (old gethostid) */ + "#143", /* 143 = (old sethostid) */ + "getrlimit", /* 144 = getrlimit */ + "setrlimit", /* 145 = setrlimit */ + "killpg", /* 146 = killpg */ + "#147", /* 147 = unused */ + "setquota", /* 148 = setquota */ + "quota", /* 149 = quota */ + "getsockname", /* 150 = getsockname */ + "#151", /* 151 = unused */ + "ustore", /* 152 = ustore */ + "ufetch", /* 153 = ufetch */ + "ucall", /* 154 = ucall */ + "#155", /* 155 = unused */ }; #endif diff --git a/sys/kernel/tty.c b/sys/kernel/tty.c index 299de95..4933a94 100644 --- a/sys/kernel/tty.c +++ b/sys/kernel/tty.c @@ -17,7 +17,7 @@ #include "inode.h" #include "syslog.h" -static int rts = TIOCM_RTS; +static int rts = TIOCM_RTS; /* * These were moved here from tty.h so that they could be easily modified @@ -34,9 +34,9 @@ static int rts = TIOCM_RTS; * but that would require 2 mapping registers and/or a rewrite of the entire * clist handling. */ -int TTYHOG = 255; -int TTYBLOCK = 128; -int TTYUNBLOCK = 64; +int TTYHOG = 255; +int TTYBLOCK = 128; +int TTYUNBLOCK = 64; /* * Table giving parity for characters and indicating @@ -45,71 +45,129 @@ int TTYUNBLOCK = 64; * no special processing on output. */ const char partab[] = { - 0001,0201,0201,0001,0201,0001,0001,0201, - 0202,0004,0003,0201,0005,0206,0201,0001, - 0201,0001,0001,0201,0001,0201,0201,0001, - 0001,0201,0201,0001,0201,0001,0001,0201, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0201, + 0001,0201,0201,0001,0201,0001,0001,0201, + 0202,0004,0003,0201,0005,0206,0201,0001, + 0201,0001,0001,0201,0001,0201,0201,0001, + 0001,0201,0201,0001,0201,0001,0001,0201, + 0200,0000,0000,0200,0000,0200,0200,0000, + 0000,0200,0200,0000,0200,0000,0000,0200, + 0000,0200,0200,0000,0200,0000,0000,0200, + 0200,0000,0000,0200,0000,0200,0200,0000, + 0200,0000,0000,0200,0000,0200,0200,0000, + 0000,0200,0200,0000,0200,0000,0000,0200, + 0000,0200,0200,0000,0200,0000,0000,0200, + 0200,0000,0000,0200,0000,0200,0200,0000, + 0000,0200,0200,0000,0200,0000,0000,0200, + 0200,0000,0000,0200,0000,0200,0200,0000, + 0200,0000,0000,0200,0000,0200,0200,0000, + 0000,0200,0200,0000,0200,0000,0000,0201, - /* - * 7 bit ascii ends with the last character above, - * but we contine through all 256 codes for the sake - * of the tty output routines which use special vax - * instructions which need a 256 character trt table. - */ + /* + * 7 bit ascii ends with the last character above, + * but we contine through all 256 codes for the sake + * of the tty output routines which use special vax + * instructions which need a 256 character trt table. + */ - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007, - 0007,0007,0007,0007,0007,0007,0007,0007 + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007, + 0007,0007,0007,0007,0007,0007,0007,0007 }; -const int tthiwat[NSPEEDS] = - { 100,100,100,100,100,100,100,200,200,400,400,400,650,650,1300,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000,2000 }; +const int tthiwat[NSPEEDS] = { + 100, /* 0 baud */ + 100, /* 50 baud */ + 100, /* 75 baud */ + 100, /* 150 baud */ + 100, /* 200 baud */ + 100, /* 300 baud */ + 100, /* 600 baud */ + 200, /* 1200 baud */ + 200, /* 1800 baud */ + 400, /* 2400 baud */ + 400, /* 4800 baud */ + 400, /* 9600 baud */ + 650, /* 19200 baud */ + 650, /* 38400 baud */ + 1300, /* 57600 baud */ + 2000, /* 115.2 kbaud */ + 2000, /* 230.4 kbaud */ + 2000, /* 460.8 kbaud */ + 2000, /* 500 kbaud */ + 2000, /* 576 kbaud */ + 2000, /* 921.6 kbaud */ + 2000, /* 1000 kbaud */ + 2000, /* 1152 kbaud */ + 2000, /* 1500 kbaud */ + 2000, /* 2000 kbaud */ + 2000, /* 2500 kbaud */ + 2000, /* 3000 kbaud */ + 2000, /* 3500 kbaud */ + 2000, /* 4000 kbaud */ +}; -const int ttlowat[NSPEEDS] = - { 30, 30, 30, 30, 30, 30, 30, 50, 50,120,120,120,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125 }; +const int ttlowat[NSPEEDS] = { + 30, /* 0 baud */ + 30, /* 50 baud */ + 30, /* 75 baud */ + 30, /* 150 baud */ + 30, /* 200 baud */ + 30, /* 300 baud */ + 30, /* 600 baud */ + 50, /* 1200 baud */ + 50, /* 1800 baud */ + 120, /* 2400 baud */ + 120, /* 4800 baud */ + 120, /* 9600 baud */ + 125, /* 19200 baud */ + 125, /* 38400 baud */ + 125, /* 57600 baud */ + 125, /* 115.2 kbaud */ + 125, /* 230.4 kbaud */ + 125, /* 460.8 kbaud */ + 125, /* 500 kbaud */ + 125, /* 576 kbaud */ + 125, /* 921.6 kbaud */ + 125, /* 1000 kbaud */ + 125, /* 1152 kbaud */ + 125, /* 1500 kbaud */ + 125, /* 2000 kbaud */ + 125, /* 2500 kbaud */ + 125, /* 3000 kbaud */ + 125, /* 3500 kbaud */ + 125, /* 4000 kbaud */ +}; -#define SET(t,f) (t) |= (f) -#define CLR(t,f) (t) &= ~(f) -#define ISSET(t,f) ((t) & (f)) +#define SET(t,f) (t) |= (f) +#define CLR(t,f) (t) &= ~(f) +#define ISSET(t,f) ((t) & (f)) /* * Set t_chars to default values. */ void ttychars(tp) - struct tty *tp; + struct tty *tp; { - static const struct ttychars ttydefaults = { - CERASE, CKILL, CINTR, CQUIT, CSTART, CSTOP, CEOF, - CBRK, CSUSP, CDSUSP, CRPRNT, CFLUSH, CWERASE,CLNEXT - }; + static const struct ttychars ttydefaults = { + CERASE, CKILL, CINTR, CQUIT, CSTART, CSTOP, CEOF, + CBRK, CSUSP, CDSUSP, CRPRNT, CFLUSH, CWERASE,CLNEXT + }; - tp->t_chars = ttydefaults; + tp->t_chars = ttydefaults; } /* @@ -119,42 +177,42 @@ ttychars(tp) */ void ttyowake(tp) - register struct tty *tp; + register struct tty *tp; { - if (tp->t_outq.c_cc <= TTLOWAT(tp)) { - if (ISSET(tp->t_state,TS_ASLEEP)) { - CLR(tp->t_state,TS_ASLEEP); - wakeup ((caddr_t)&tp->t_outq); - } - if (tp->t_wsel) { - selwakeup (tp->t_wsel, tp->t_state & TS_WCOLL); - tp->t_wsel = 0; - CLR(tp->t_state,TS_WCOLL); - } - } + if (tp->t_outq.c_cc <= TTLOWAT(tp)) { + if (ISSET(tp->t_state,TS_ASLEEP)) { + CLR(tp->t_state,TS_ASLEEP); + wakeup ((caddr_t)&tp->t_outq); + } + if (tp->t_wsel) { + selwakeup (tp->t_wsel, tp->t_state & TS_WCOLL); + tp->t_wsel = 0; + CLR(tp->t_state,TS_WCOLL); + } + } } static void ttywait(tp) - register struct tty *tp; + register struct tty *tp; { - register int s = spltty(); + register int s = spltty(); - while ((tp->t_outq.c_cc || tp->t_state & TS_BUSY) && - tp->t_state & TS_CARR_ON && tp->t_oproc) { - (*tp->t_oproc)(tp); - /* - * If the output routine drains the queue and the device is no longer busy - * then don't wait for something that's already happened. - */ - if (tp->t_outq.c_cc == 0 && !ISSET(tp->t_state,TS_BUSY)) - break; - tp->t_state |= TS_ASLEEP; - sleep((caddr_t)&tp->t_outq, TTOPRI); - splx(s); /* drop priority, give interrupts a chance */ - s = spltty(); - } - splx(s); + while ((tp->t_outq.c_cc || tp->t_state & TS_BUSY) && + tp->t_state & TS_CARR_ON && tp->t_oproc) { + (*tp->t_oproc)(tp); + /* + * If the output routine drains the queue and the device is no longer busy + * then don't wait for something that's already happened. + */ + if (tp->t_outq.c_cc == 0 && !ISSET(tp->t_state,TS_BUSY)) + break; + tp->t_state |= TS_ASLEEP; + sleep((caddr_t)&tp->t_outq, TTOPRI); + splx(s); /* drop priority, give interrupts a chance */ + s = spltty(); + } + splx(s); } /* @@ -162,61 +220,61 @@ ttywait(tp) */ void ttywflush(tp) - register struct tty *tp; + register struct tty *tp; { - ttywait(tp); - ttyflush(tp, FREAD); + ttywait(tp); + ttyflush(tp, FREAD); } static void ttyunblock (tp) - register struct tty *tp; + register struct tty *tp; { - if (ISSET(tp->t_flags,TANDEM) && - tp->t_startc != _POSIX_VDISABLE && - putc(tp->t_startc, &tp->t_outq) == 0) { - CLR(tp->t_state,TS_TBLOCK); - ttstart(tp); - } - if (ISSET(tp->t_flags, RTSCTS) && - (*cdevsw[major(tp->t_dev)].d_ioctl) (tp->t_dev, TIOCMBIS, - (caddr_t) &rts, 0) == 0) { - CLR(tp->t_state, TS_TBLOCK); - } + if (ISSET(tp->t_flags,TANDEM) && + tp->t_startc != _POSIX_VDISABLE && + putc(tp->t_startc, &tp->t_outq) == 0) { + CLR(tp->t_state,TS_TBLOCK); + ttstart(tp); + } + if (ISSET(tp->t_flags, RTSCTS) && + (*cdevsw[major(tp->t_dev)].d_ioctl) (tp->t_dev, TIOCMBIS, + (caddr_t) &rts, 0) == 0) { + CLR(tp->t_state, TS_TBLOCK); + } } /* * Flush all TTY queues. */ void ttyflush (tp, rw) - register struct tty *tp; + register struct tty *tp; { - register int s; + register int s; - s = spltty(); - if (rw & FREAD) { - while (getc(&tp->t_canq) >= 0) - ; - while (getc(&tp->t_rawq) >= 0) - ; - tp->t_rocount = 0; - tp->t_rocol = 0; - tp->t_state &= ~TS_LOCAL; - ttwakeup (tp); - } - if (rw & FWRITE) { - tp->t_state &= ~TS_TTSTOP; - (*cdevsw[major(tp->t_dev)].d_stop)(tp, rw); - wakeup ((caddr_t)&tp->t_outq); - while (getc(&tp->t_outq) >= 0) - ; - selwakeup (tp->t_wsel, tp->t_state & TS_WCOLL); - CLR(tp->t_state, TS_WCOLL); - tp->t_wsel = 0; - } - if (rw & FREAD && ISSET(tp->t_state,TS_TBLOCK)) - ttyunblock(tp); - splx(s); + s = spltty(); + if (rw & FREAD) { + while (getc(&tp->t_canq) >= 0) + ; + while (getc(&tp->t_rawq) >= 0) + ; + tp->t_rocount = 0; + tp->t_rocol = 0; + tp->t_state &= ~TS_LOCAL; + ttwakeup (tp); + } + if (rw & FWRITE) { + tp->t_state &= ~TS_TTSTOP; + (*cdevsw[major(tp->t_dev)].d_stop)(tp, rw); + wakeup ((caddr_t)&tp->t_outq); + while (getc(&tp->t_outq) >= 0) + ; + selwakeup (tp->t_wsel, tp->t_state & TS_WCOLL); + CLR(tp->t_state, TS_WCOLL); + tp->t_wsel = 0; + } + if (rw & FREAD && ISSET(tp->t_state,TS_TBLOCK)) + ttyunblock(tp); + splx(s); } /* @@ -224,38 +282,38 @@ void ttyflush (tp, rw) */ void ttyblock(tp) - register struct tty *tp; + register struct tty *tp; { - register int total; + register int total; - total = tp->t_rawq.c_cc + tp->t_canq.c_cc; - /* - * Block further input iff: - * Current input > threshold AND input is available to user program - */ - if (total >= TTYBLOCK && - ((tp->t_flags & (RAW|CBREAK)) || (tp->t_canq.c_cc > 0)) && - (tp->t_state & TS_TBLOCK) == 0) { - /* - * TANDEM is the same as IXOFF for all intents and purposes. Since we could - * get called for either software or hardware flow control we need to check - * the IXOFF bit. - */ - if (ISSET(tp->t_flags,TANDEM) && - tp->t_stopc != _POSIX_VDISABLE && - putc(tp->t_stopc, &tp->t_outq) == 0) { - SET(tp->t_state, TS_TBLOCK); - ttstart(tp); - } - /* - * If queue is full, drop RTS to tell modem to stop sending us stuff - */ - if (ISSET(tp->t_flags, RTSCTS) && - (*cdevsw[major(tp->t_dev)].d_ioctl) (tp->t_dev, TIOCMBIC, - (caddr_t) &rts, 0) == 0) { - SET(tp->t_state, TS_TBLOCK); - } - } + total = tp->t_rawq.c_cc + tp->t_canq.c_cc; + /* + * Block further input iff: + * Current input > threshold AND input is available to user program + */ + if (total >= TTYBLOCK && + ((tp->t_flags & (RAW|CBREAK)) || (tp->t_canq.c_cc > 0)) && + (tp->t_state & TS_TBLOCK) == 0) { + /* + * TANDEM is the same as IXOFF for all intents and purposes. Since we could + * get called for either software or hardware flow control we need to check + * the IXOFF bit. + */ + if (ISSET(tp->t_flags,TANDEM) && + tp->t_stopc != _POSIX_VDISABLE && + putc(tp->t_stopc, &tp->t_outq) == 0) { + SET(tp->t_state, TS_TBLOCK); + ttstart(tp); + } + /* + * If queue is full, drop RTS to tell modem to stop sending us stuff + */ + if (ISSET(tp->t_flags, RTSCTS) && + (*cdevsw[major(tp->t_dev)].d_ioctl) (tp->t_dev, TIOCMBIC, + (caddr_t) &rts, 0) == 0) { + SET(tp->t_state, TS_TBLOCK); + } + } } /* @@ -265,10 +323,10 @@ ttyblock(tp) */ void ttrstrt(tp) - register struct tty *tp; + register struct tty *tp; { - tp->t_state &= ~TS_TIMEOUT; - ttstart(tp); + tp->t_state &= ~TS_TIMEOUT; + ttstart(tp); } /* @@ -281,10 +339,10 @@ ttrstrt(tp) */ void ttstart(tp) - register struct tty *tp; + register struct tty *tp; { - if (tp->t_oproc) /* kludge for pty */ - (*tp->t_oproc) (tp); + if (tp->t_oproc) /* kludge for pty */ + (*tp->t_oproc) (tp); } /* @@ -293,33 +351,33 @@ ttstart(tp) */ static void ttypend (tp) - register struct tty *tp; + register struct tty *tp; { - struct clist tq; - register int c; + struct clist tq; + register int c; - tp->t_flags &= ~PENDIN; - tp->t_state |= TS_TYPEN; - tq = tp->t_rawq; - tp->t_rawq.c_cc = 0; - tp->t_rawq.c_cf = tp->t_rawq.c_cl = 0; - while ((c = getc(&tq)) >= 0) - ttyinput(c, tp); - tp->t_state &= ~TS_TYPEN; + tp->t_flags &= ~PENDIN; + tp->t_state |= TS_TYPEN; + tq = tp->t_rawq; + tp->t_rawq.c_cc = 0; + tp->t_rawq.c_cf = tp->t_rawq.c_cl = 0; + while ((c = getc(&tq)) >= 0) + ttyinput(c, tp); + tp->t_state &= ~TS_TYPEN; } static int ttnread (tp) - register struct tty *tp; + register struct tty *tp; { - register int nread = 0; + register int nread = 0; - if (tp->t_flags & PENDIN) - ttypend(tp); - nread = tp->t_canq.c_cc; - if (tp->t_flags & (RAW|CBREAK)) - nread += tp->t_rawq.c_cc; - return (nread); + if (tp->t_flags & PENDIN) + ttypend(tp); + nread = tp->t_canq.c_cc; + if (tp->t_flags & (RAW|CBREAK)) + nread += tp->t_rawq.c_cc; + return (nread); } /* @@ -328,260 +386,260 @@ ttnread (tp) /*ARGSUSED*/ int ttioctl(tp, com, data, flag) - register struct tty *tp; - u_int com; - caddr_t data; - int flag; + register struct tty *tp; + u_int com; + caddr_t data; + int flag; { - int s; - long newflags; + int s; + long newflags; //printf ("ttioctl (com=%08x, data=%08x, flag=%d)\n", com, data, flag); - /* - * If the ioctl involves modification, - * hang if in the background. - */ - switch (com) { + /* + * If the ioctl involves modification, + * hang if in the background. + */ + switch (com) { - case TIOCSETD: - case TIOCSETP: - case TIOCSETN: - case TIOCFLUSH: - case TIOCSETC: - case TIOCSLTC: - case TIOCSPGRP: - case TIOCLBIS: - case TIOCLBIC: - case TIOCLSET: - case TIOCSTI: - case TIOCSWINSZ: - while (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp && - (u.u_procp->p_flag & SVFORK) == 0 && - !(u.u_procp->p_sigignore & sigmask(SIGTTOU)) && - !(u.u_procp->p_sigmask & sigmask(SIGTTOU))) { - gsignal(u.u_procp->p_pgrp, SIGTTOU); - sleep((caddr_t)&lbolt, TTOPRI); - } - break; - } + case TIOCSETD: + case TIOCSETP: + case TIOCSETN: + case TIOCFLUSH: + case TIOCSETC: + case TIOCSLTC: + case TIOCSPGRP: + case TIOCLBIS: + case TIOCLBIC: + case TIOCLSET: + case TIOCSTI: + case TIOCSWINSZ: + while (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp && + (u.u_procp->p_flag & SVFORK) == 0 && + !(u.u_procp->p_sigignore & sigmask(SIGTTOU)) && + !(u.u_procp->p_sigmask & sigmask(SIGTTOU))) { + gsignal(u.u_procp->p_pgrp, SIGTTOU); + sleep((caddr_t)&lbolt, TTOPRI); + } + break; + } - /* - * Process the ioctl. - */ - switch (com) { + /* + * Process the ioctl. + */ + switch (com) { - /* get discipline number */ - case TIOCGETD: - *(int *)data = 0; - break; + /* get discipline number */ + case TIOCGETD: + *(int *)data = 0; + break; - /* set line discipline */ - case TIOCSETD: { - register int t = *(int *)data; - if (t != 0) - return (ENXIO); - break; - } + /* set line discipline */ + case TIOCSETD: { + register int t = *(int *)data; + if (t != 0) + return (ENXIO); + break; + } - /* prevent more opens on channel */ - case TIOCEXCL: - tp->t_state |= TS_XCLUDE; - break; + /* prevent more opens on channel */ + case TIOCEXCL: + tp->t_state |= TS_XCLUDE; + break; - case TIOCNXCL: - tp->t_state &= ~TS_XCLUDE; - break; + case TIOCNXCL: + tp->t_state &= ~TS_XCLUDE; + break; - /* hang up line on last close */ - case TIOCHPCL: - tp->t_state |= TS_HUPCLS; - break; + /* hang up line on last close */ + case TIOCHPCL: + tp->t_state |= TS_HUPCLS; + break; - case TIOCFLUSH: { - register int flags = *(int *)data; + case TIOCFLUSH: { + register int flags = *(int *)data; - if (flags == 0) - flags = FREAD|FWRITE; - else - flags &= FREAD|FWRITE; - ttyflush(tp, flags); - break; - } + if (flags == 0) + flags = FREAD|FWRITE; + else + flags &= FREAD|FWRITE; + ttyflush(tp, flags); + break; + } - /* return number of characters immediately available */ - case FIONREAD: - *(off_t *)data = ttnread(tp); - break; + /* return number of characters immediately available */ + case FIONREAD: + *(off_t *)data = ttnread(tp); + break; - case TIOCOUTQ: - *(int *)data = tp->t_outq.c_cc; - break; + case TIOCOUTQ: + *(int *)data = tp->t_outq.c_cc; + break; - case TIOCSTOP: - s = spltty(); - if ((tp->t_state & TS_TTSTOP) == 0) { - tp->t_state |= TS_TTSTOP; - (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0); - } - splx(s); - break; + case TIOCSTOP: + s = spltty(); + if ((tp->t_state & TS_TTSTOP) == 0) { + tp->t_state |= TS_TTSTOP; + (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0); + } + splx(s); + break; - case TIOCSTART: - s = spltty(); - if ((tp->t_state & TS_TTSTOP) || (tp->t_flags & FLUSHO)) { - tp->t_state &= ~TS_TTSTOP; - tp->t_flags &= ~FLUSHO; - ttstart(tp); - } - splx(s); - break; + case TIOCSTART: + s = spltty(); + if ((tp->t_state & TS_TTSTOP) || (tp->t_flags & FLUSHO)) { + tp->t_state &= ~TS_TTSTOP; + tp->t_flags &= ~FLUSHO; + ttstart(tp); + } + splx(s); + break; - /* - * Simulate typing of a character at the terminal. - */ - case TIOCSTI: - if (u.u_uid && (flag & FREAD) == 0) - return (EPERM); - if (u.u_uid && u.u_ttyp != tp) - return (EACCES); - ttyinput (*(char *)data, tp); - break; + /* + * Simulate typing of a character at the terminal. + */ + case TIOCSTI: + if (u.u_uid && (flag & FREAD) == 0) + return (EPERM); + if (u.u_uid && u.u_ttyp != tp) + return (EACCES); + ttyinput (*(char *)data, tp); + break; - case TIOCSETP: - case TIOCSETN: { - register struct sgttyb *sg = (struct sgttyb *)data; + case TIOCSETP: + case TIOCSETN: { + register struct sgttyb *sg = (struct sgttyb *)data; - tp->t_erase = sg->sg_erase; - tp->t_kill = sg->sg_kill; - tp->t_ispeed = sg->sg_ispeed; - tp->t_ospeed = sg->sg_ospeed; - newflags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffffL); - s = spltty(); - if (tp->t_flags & RAW || newflags & RAW || com == TIOCSETP) { - ttywait(tp); - ttyflush(tp, FREAD); - } else if ((tp->t_flags & CBREAK) != (newflags & CBREAK)) { - if (newflags & CBREAK) { - struct clist tq; + tp->t_erase = sg->sg_erase; + tp->t_kill = sg->sg_kill; + tp->t_ispeed = sg->sg_ispeed; + tp->t_ospeed = sg->sg_ospeed; + newflags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffffL); + s = spltty(); + if (tp->t_flags & RAW || newflags & RAW || com == TIOCSETP) { + ttywait(tp); + ttyflush(tp, FREAD); + } else if ((tp->t_flags & CBREAK) != (newflags & CBREAK)) { + if (newflags & CBREAK) { + struct clist tq; - catq(&tp->t_rawq, &tp->t_canq); - tq = tp->t_rawq; - tp->t_rawq = tp->t_canq; - tp->t_canq = tq; - } else { - tp->t_flags |= PENDIN; - newflags |= PENDIN; - ttwakeup (tp); - } - } - tp->t_flags = newflags; - if (tp->t_flags & RAW) { - tp->t_state &= ~TS_TTSTOP; - ttstart(tp); - } - splx(s); - break; - } + catq(&tp->t_rawq, &tp->t_canq); + tq = tp->t_rawq; + tp->t_rawq = tp->t_canq; + tp->t_canq = tq; + } else { + tp->t_flags |= PENDIN; + newflags |= PENDIN; + ttwakeup (tp); + } + } + tp->t_flags = newflags; + if (tp->t_flags & RAW) { + tp->t_state &= ~TS_TTSTOP; + ttstart(tp); + } + splx(s); + break; + } - /* send current parameters to user */ - case TIOCGETP: { - register struct sgttyb *sg = (struct sgttyb *)data; + /* send current parameters to user */ + case TIOCGETP: { + register struct sgttyb *sg = (struct sgttyb *)data; - sg->sg_ispeed = tp->t_ispeed; - sg->sg_ospeed = tp->t_ospeed; - sg->sg_erase = tp->t_erase; - sg->sg_kill = tp->t_kill; - sg->sg_flags = tp->t_flags; - break; - } + sg->sg_ispeed = tp->t_ispeed; + sg->sg_ospeed = tp->t_ospeed; + sg->sg_erase = tp->t_erase; + sg->sg_kill = tp->t_kill; + sg->sg_flags = tp->t_flags; + break; + } - case FIONBIO: - break; /* XXX remove */ + case FIONBIO: + break; /* XXX remove */ - case FIOASYNC: - if (*(int *)data) - tp->t_state |= TS_ASYNC; - else - tp->t_state &= ~TS_ASYNC; - break; + case FIOASYNC: + if (*(int *)data) + tp->t_state |= TS_ASYNC; + else + tp->t_state &= ~TS_ASYNC; + break; - case TIOCGETC: - bcopy((caddr_t)&tp->t_intrc, data, sizeof (struct tchars)); - break; + case TIOCGETC: + bcopy((caddr_t)&tp->t_intrc, data, sizeof (struct tchars)); + break; - case TIOCSETC: - bcopy(data, (caddr_t)&tp->t_intrc, sizeof (struct tchars)); - break; + case TIOCSETC: + bcopy(data, (caddr_t)&tp->t_intrc, sizeof (struct tchars)); + break; - /* set/get local special characters */ - case TIOCSLTC: - bcopy(data, (caddr_t)&tp->t_suspc, sizeof (struct ltchars)); - break; + /* set/get local special characters */ + case TIOCSLTC: + bcopy(data, (caddr_t)&tp->t_suspc, sizeof (struct ltchars)); + break; - case TIOCGLTC: - bcopy((caddr_t)&tp->t_suspc, data, sizeof (struct ltchars)); - break; + case TIOCGLTC: + bcopy((caddr_t)&tp->t_suspc, data, sizeof (struct ltchars)); + break; - /* - * Modify local mode word. - */ - case TIOCLBIS: - tp->t_flags |= (long)*(u_int *)data << 16; - break; + /* + * Modify local mode word. + */ + case TIOCLBIS: + tp->t_flags |= (long)*(u_int *)data << 16; + break; - case TIOCLBIC: - tp->t_flags &= ~((long)*(u_int *)data << 16); - break; + case TIOCLBIC: + tp->t_flags &= ~((long)*(u_int *)data << 16); + break; - case TIOCLSET: - tp->t_flags &= 0xffffL; - tp->t_flags |= (long)*(u_int *)data << 16; - break; + case TIOCLSET: + tp->t_flags &= 0xffffL; + tp->t_flags |= (long)*(u_int *)data << 16; + break; - case TIOCLGET: - *(int *)data = tp->t_flags >> 16; - break; + case TIOCLGET: + *(int *)data = tp->t_flags >> 16; + break; - /* - * Allow SPGRP only if tty is open for reading. - * Quick check: if we can find a process in the new pgrp, - * this user must own that process. - * SHOULD VERIFY THAT PGRP IS IN USE AND IS THIS USER'S. - */ - case TIOCSPGRP: { - struct proc *p; - short pgrp = *(int *)data; + /* + * Allow SPGRP only if tty is open for reading. + * Quick check: if we can find a process in the new pgrp, + * this user must own that process. + * SHOULD VERIFY THAT PGRP IS IN USE AND IS THIS USER'S. + */ + case TIOCSPGRP: { + struct proc *p; + short pgrp = *(int *)data; - if (u.u_uid && (flag & FREAD) == 0) - return (EPERM); - p = pfind(pgrp); - if (p && p->p_pgrp == pgrp && - p->p_uid != u.u_uid && u.u_uid && !inferior(p)) - return (EPERM); - tp->t_pgrp = pgrp; - break; - } + if (u.u_uid && (flag & FREAD) == 0) + return (EPERM); + p = pfind(pgrp); + if (p && p->p_pgrp == pgrp && + p->p_uid != u.u_uid && u.u_uid && !inferior(p)) + return (EPERM); + tp->t_pgrp = pgrp; + break; + } - case TIOCGPGRP: - *(int *)data = tp->t_pgrp; - break; + case TIOCGPGRP: + *(int *)data = tp->t_pgrp; + break; - case TIOCSWINSZ: - if (bcmp((caddr_t)&tp->t_winsize, data, - sizeof (struct winsize))) { - tp->t_winsize = *(struct winsize *)data; - gsignal(tp->t_pgrp, SIGWINCH); - } - break; + case TIOCSWINSZ: + if (bcmp((caddr_t)&tp->t_winsize, data, + sizeof (struct winsize))) { + tp->t_winsize = *(struct winsize *)data; + gsignal(tp->t_pgrp, SIGWINCH); + } + break; - case TIOCGWINSZ: - *(struct winsize *)data = tp->t_winsize; - break; + case TIOCGWINSZ: + *(struct winsize *)data = tp->t_winsize; + break; - default: - return (-1); - } - return (0); + default: + return (-1); + } + return (0); } /* @@ -589,38 +647,38 @@ ttioctl(tp, com, data, flag) */ int ttyselect (tp, rw) - register struct tty *tp; - int rw; + register struct tty *tp; + int rw; { - int nread; - register int s = spltty(); + int nread; + register int s = spltty(); - switch (rw) { + switch (rw) { - case FREAD: - nread = ttnread(tp); - if ((nread > 0) || ((tp->t_state & TS_CARR_ON) == 0)) - goto win; - if (tp->t_rsel && tp->t_rsel->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_RCOLL; - else - tp->t_rsel = u.u_procp; - break; + case FREAD: + nread = ttnread(tp); + if ((nread > 0) || ((tp->t_state & TS_CARR_ON) == 0)) + goto win; + if (tp->t_rsel && tp->t_rsel->p_wchan == (caddr_t)&selwait) + tp->t_state |= TS_RCOLL; + else + tp->t_rsel = u.u_procp; + break; - case FWRITE: - if (tp->t_outq.c_cc <= TTLOWAT(tp)) - goto win; - if (tp->t_wsel && tp->t_wsel->p_wchan == (caddr_t)&selwait) - tp->t_state |= TS_WCOLL; - else - tp->t_wsel = u.u_procp; - break; - } - splx(s); - return (0); + case FWRITE: + if (tp->t_outq.c_cc <= TTLOWAT(tp)) + goto win; + if (tp->t_wsel && tp->t_wsel->p_wchan == (caddr_t)&selwait) + tp->t_state |= TS_WCOLL; + else + tp->t_wsel = u.u_procp; + break; + } + splx(s); + return (0); win: - splx(s); - return (1); + splx(s); + return (1); } /* @@ -630,26 +688,26 @@ win: */ int ttyopen(dev, tp) - dev_t dev; - register struct tty *tp; + dev_t dev; + register struct tty *tp; { - register struct proc *pp; + register struct proc *pp; - pp = u.u_procp; - tp->t_dev = dev; - if (pp->p_pgrp == 0) { - u.u_ttyp = tp; - u.u_ttyd = dev; - if (tp->t_pgrp == 0) - tp->t_pgrp = pp->p_pid; - pp->p_pgrp = tp->t_pgrp; - } - tp->t_state &= ~TS_WOPEN; - if ((tp->t_state & TS_ISOPEN) == 0) { - tp->t_state |= TS_ISOPEN; - bzero((caddr_t)&tp->t_winsize, sizeof(tp->t_winsize)); - } - return (0); + pp = u.u_procp; + tp->t_dev = dev; + if (pp->p_pgrp == 0) { + u.u_ttyp = tp; + u.u_ttyd = dev; + if (tp->t_pgrp == 0) + tp->t_pgrp = pp->p_pid; + pp->p_pgrp = tp->t_pgrp; + } + tp->t_state &= ~TS_WOPEN; + if ((tp->t_state & TS_ISOPEN) == 0) { + tp->t_state |= TS_ISOPEN; + bzero((caddr_t)&tp->t_winsize, sizeof(tp->t_winsize)); + } + return (0); } /* @@ -657,19 +715,19 @@ ttyopen(dev, tp) */ int ttylclose (tp, flag) - register struct tty *tp; - int flag; + register struct tty *tp; + int flag; { - /* - * 4.4 has IO_NDELAY but I think that is a mistake because the upper level - * 'close' routines all pass 'fp->f_flags' down. This was verified with a - * printf here - the F* flags are received rather than the IO_* flags! - */ - if (flag & FNDELAY) - ttyflush(tp, FREAD|FWRITE); - else - ttywflush(tp); - return (0); + /* + * 4.4 has IO_NDELAY but I think that is a mistake because the upper level + * 'close' routines all pass 'fp->f_flags' down. This was verified with a + * printf here - the F* flags are received rather than the IO_* flags! + */ + if (flag & FNDELAY) + ttyflush(tp, FREAD|FWRITE); + else + ttywflush(tp); + return (0); } /* @@ -677,11 +735,11 @@ ttylclose (tp, flag) */ void ttyclose(tp) - register struct tty *tp; + register struct tty *tp; { - ttyflush(tp, FREAD|FWRITE); - tp->t_pgrp = 0; - tp->t_state = 0; + ttyflush(tp, FREAD|FWRITE); + tp->t_pgrp = 0; + tp->t_state = 0; } /* @@ -691,41 +749,41 @@ ttyclose(tp) */ int ttymodem(tp, flag) - register struct tty *tp; - int flag; + register struct tty *tp; + int flag; { - if ((tp->t_state & TS_WOPEN) == 0 && (tp->t_flags & MDMBUF)) { - /* - * MDMBUF: do flow control according to carrier flag - */ - if (flag) { - tp->t_state &= ~TS_TTSTOP; - ttstart(tp); - } else if ((tp->t_state & TS_TTSTOP) == 0) { - tp->t_state |= TS_TTSTOP; - (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0); - } - } else if (flag == 0) { - /* - * Lost carrier. - */ - tp->t_state &= ~TS_CARR_ON; - if (tp->t_state & TS_ISOPEN) { - if ((tp->t_flags & NOHANG) == 0) { - gsignal(tp->t_pgrp, SIGHUP); - gsignal(tp->t_pgrp, SIGCONT); - ttyflush(tp, FREAD|FWRITE); - return (0); - } - } - } else { - /* - * Carrier now on. - */ - tp->t_state |= TS_CARR_ON; - wakeup ((caddr_t) &tp->t_rawq); - } - return (1); + if ((tp->t_state & TS_WOPEN) == 0 && (tp->t_flags & MDMBUF)) { + /* + * MDMBUF: do flow control according to carrier flag + */ + if (flag) { + tp->t_state &= ~TS_TTSTOP; + ttstart(tp); + } else if ((tp->t_state & TS_TTSTOP) == 0) { + tp->t_state |= TS_TTSTOP; + (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0); + } + } else if (flag == 0) { + /* + * Lost carrier. + */ + tp->t_state &= ~TS_CARR_ON; + if (tp->t_state & TS_ISOPEN) { + if ((tp->t_flags & NOHANG) == 0) { + gsignal(tp->t_pgrp, SIGHUP); + gsignal(tp->t_pgrp, SIGCONT); + ttyflush(tp, FREAD|FWRITE); + return (0); + } + } + } else { + /* + * Carrier now on. + */ + tp->t_state |= TS_CARR_ON; + wakeup ((caddr_t) &tp->t_rawq); + } + return (1); } /* @@ -734,14 +792,14 @@ ttymodem(tp, flag) */ int nullmodem(tp, flag) - register struct tty *tp; - int flag; + register struct tty *tp; + int flag; { - if (flag) - tp->t_state |= TS_CARR_ON; - else - tp->t_state &= ~TS_CARR_ON; - return (flag); + if (flag) + tp->t_state |= TS_CARR_ON; + else + tp->t_state &= ~TS_CARR_ON; + return (flag); } /* @@ -749,13 +807,13 @@ nullmodem(tp, flag) */ static void ttyout (cp, tp) - register char *cp; - register struct tty *tp; + register char *cp; + register struct tty *tp; { - register int c; + register int c; - while ((c = *cp++)) - (void) ttyoutput (c, tp); + while ((c = *cp++)) + (void) ttyoutput (c, tp); } /* @@ -764,13 +822,13 @@ ttyout (cp, tp) */ static void ttyrubo(tp, cnt) - register struct tty *tp; - register int cnt; + register struct tty *tp; + register int cnt; { - register char *rubostring = (tp->t_flags & CRTERA) ? "\b \b" : "\b"; + register char *rubostring = (tp->t_flags & CRTERA) ? "\b \b" : "\b"; - while (--cnt >= 0) - ttyout(rubostring, tp); + while (--cnt >= 0) + ttyout(rubostring, tp); } /* @@ -778,34 +836,34 @@ ttyrubo(tp, cnt) */ static void ttyecho(c, tp) - register int c; - register struct tty *tp; + register int c; + register struct tty *tp; { - register int c7; + register int c7; - if ((tp->t_state & TS_CNTTB) == 0) - tp->t_flags &= ~FLUSHO; - if ((tp->t_flags & ECHO) == 0) - return; - c &= 0377; + if ((tp->t_state & TS_CNTTB) == 0) + tp->t_flags &= ~FLUSHO; + if ((tp->t_flags & ECHO) == 0) + return; + c &= 0377; - if (tp->t_flags & RAW) { - (void) ttyoutput(c, tp); - return; - } - if (c == '\r' && tp->t_flags & CRMOD) - c = '\n'; - c7 = c & 0177; - if (tp->t_flags & CTLECH) { - if ((c7 <= 037 && c != '\t' && c != '\n') || c7 == 0177) { - (void) ttyoutput('^', tp); - if (c7 == 0177) - c7 = '?'; - else - c7 += 'A' - 1; - } - } - (void) ttyoutput(c7, tp); + if (tp->t_flags & RAW) { + (void) ttyoutput(c, tp); + return; + } + if (c == '\r' && tp->t_flags & CRMOD) + c = '\n'; + c7 = c & 0177; + if (tp->t_flags & CTLECH) { + if ((c7 <= 037 && c != '\t' && c != '\n') || c7 == 0177) { + (void) ttyoutput('^', tp); + if (c7 == 0177) + c7 = '?'; + else + c7 += 'A' - 1; + } + } + (void) ttyoutput(c7, tp); } /* @@ -814,23 +872,23 @@ ttyecho(c, tp) */ static void ttyretype(tp) - register struct tty *tp; + register struct tty *tp; { - register char *cp; - int s; + register char *cp; + int s; - if (tp->t_rprntc != _POSIX_VDISABLE) - ttyecho(tp->t_rprntc, tp); - (void) ttyoutput('\n', tp); - s = spltty(); - for (cp = tp->t_canq.c_cf; cp; cp = nextc(&tp->t_canq, cp)) - ttyecho(*cp, tp); - for (cp = tp->t_rawq.c_cf; cp; cp = nextc(&tp->t_rawq, cp)) - ttyecho(*cp, tp); - tp->t_state &= ~TS_ERASE; - splx(s); - tp->t_rocount = tp->t_rawq.c_cc; - tp->t_rocol = 0; + if (tp->t_rprntc != _POSIX_VDISABLE) + ttyecho(tp->t_rprntc, tp); + (void) ttyoutput('\n', tp); + s = spltty(); + for (cp = tp->t_canq.c_cf; cp; cp = nextc(&tp->t_canq, cp)) + ttyecho(*cp, tp); + for (cp = tp->t_rawq.c_cf; cp; cp = nextc(&tp->t_rawq, cp)) + ttyecho(*cp, tp); + tp->t_state &= ~TS_ERASE; + splx(s); + tp->t_rocount = tp->t_rawq.c_cc; + tp->t_rocol = 0; } /* @@ -839,84 +897,84 @@ ttyretype(tp) */ static void ttyrub(c, tp) - register int c; - register struct tty *tp; + register int c; + register struct tty *tp; { - register char *cp; - int savecol; - int s; + register char *cp; + int savecol; + int s; - if ((tp->t_flags & ECHO) == 0) - return; - tp->t_flags &= ~FLUSHO; - c &= 0377; - if (tp->t_flags & CRTBS) { - if (tp->t_rocount == 0) { - /* - * Screwed by ttwrite; retype - */ - ttyretype(tp); - return; - } - /* - * Out of the ENTIRE tty subsystem would believe this is the ONLY place - * that the "9th" bit (quoted chars) is tested? - */ - if (c == ('\t' | 0200) || c == ('\n' | 0200)) - ttyrubo (tp, 2); - else switch (partab [c &= 0177] & 0177) { + if ((tp->t_flags & ECHO) == 0) + return; + tp->t_flags &= ~FLUSHO; + c &= 0377; + if (tp->t_flags & CRTBS) { + if (tp->t_rocount == 0) { + /* + * Screwed by ttwrite; retype + */ + ttyretype(tp); + return; + } + /* + * Out of the ENTIRE tty subsystem would believe this is the ONLY place + * that the "9th" bit (quoted chars) is tested? + */ + if (c == ('\t' | 0200) || c == ('\n' | 0200)) + ttyrubo (tp, 2); + else switch (partab [c &= 0177] & 0177) { - case ORDINARY: - ttyrubo(tp, 1); - break; + case ORDINARY: + ttyrubo(tp, 1); + break; - case VTAB: - case BACKSPACE: - case CONTROL: - case RETURN: - if (tp->t_flags & CTLECH) - ttyrubo(tp, 2); - break; + case VTAB: + case BACKSPACE: + case CONTROL: + case RETURN: + if (tp->t_flags & CTLECH) + ttyrubo(tp, 2); + break; - case TAB: - if (tp->t_rocount < tp->t_rawq.c_cc) { - ttyretype(tp); - return; - } - s = spltty(); - savecol = tp->t_col; - tp->t_state |= TS_CNTTB; - tp->t_flags |= FLUSHO; - tp->t_col = tp->t_rocol; - cp = tp->t_rawq.c_cf; - for (; cp; cp = nextc (&tp->t_rawq, cp)) - ttyecho(*cp, tp); - tp->t_flags &= ~FLUSHO; - tp->t_state &= ~TS_CNTTB; - splx(s); - /* - * savecol will now be length of the tab - */ - savecol -= tp->t_col; - tp->t_col += savecol; - if (savecol > 8) - savecol = 8; /* overflow screw */ - while (--savecol >= 0) - (void) ttyoutput('\b', tp); - break; + case TAB: + if (tp->t_rocount < tp->t_rawq.c_cc) { + ttyretype(tp); + return; + } + s = spltty(); + savecol = tp->t_col; + tp->t_state |= TS_CNTTB; + tp->t_flags |= FLUSHO; + tp->t_col = tp->t_rocol; + cp = tp->t_rawq.c_cf; + for (; cp; cp = nextc (&tp->t_rawq, cp)) + ttyecho(*cp, tp); + tp->t_flags &= ~FLUSHO; + tp->t_state &= ~TS_CNTTB; + splx(s); + /* + * savecol will now be length of the tab + */ + savecol -= tp->t_col; + tp->t_col += savecol; + if (savecol > 8) + savecol = 8; /* overflow screw */ + while (--savecol >= 0) + (void) ttyoutput('\b', tp); + break; - default: - panic("ttyrub"); - } - } else if (tp->t_flags & PRTERA) { - if ((tp->t_state & TS_ERASE) == 0) { - (void) ttyoutput('\\', tp); - tp->t_state |= TS_ERASE; - } - ttyecho(c, tp); - } else - ttyecho(tp->t_erase, tp); - tp->t_rocount--; + default: + panic("ttyrub"); + } + } else if (tp->t_flags & PRTERA) { + if ((tp->t_state & TS_ERASE) == 0) { + (void) ttyoutput('\\', tp); + tp->t_state |= TS_ERASE; + } + ttyecho(c, tp); + } else + ttyecho(tp->t_erase, tp); + tp->t_rocount--; } /* @@ -924,11 +982,11 @@ ttyrub(c, tp) */ int ttbreakc (c, tp) - register int c; - register struct tty *tp; + register int c; + register struct tty *tp; { - return (c == '\n' || CCEQ (tp->t_eofc, c) || CCEQ (tp->t_brkc, c) || - (c == '\r' && (tp->t_flags & CRMOD))); + return (c == '\n' || CCEQ (tp->t_eofc, c) || CCEQ (tp->t_brkc, c) || + (c == '\r' && (tp->t_flags & CRMOD))); } /* @@ -940,245 +998,245 @@ ttbreakc (c, tp) */ void ttyinput (c, tp) - register int c; - register struct tty *tp; + register int c; + register struct tty *tp; { - long t_flags = tp->t_flags; - int i; + long t_flags = tp->t_flags; + int i; - /* - * If input is pending take it first. - */ - if (t_flags & PENDIN) - ttypend(tp); + /* + * If input is pending take it first. + */ + if (t_flags & PENDIN) + ttypend(tp); #ifdef UCB_METER - tk_nin++; + tk_nin++; #endif - c &= 0377; + c &= 0377; - /* - * In tandem mode, check high water mark. - */ - if (t_flags & (TANDEM | RTSCTS)) - ttyblock(tp); + /* + * In tandem mode, check high water mark. + */ + if (t_flags & (TANDEM | RTSCTS)) + ttyblock(tp); - if (t_flags & RAW) { - /* - * Raw mode, just put character - * in input q w/o interpretation. - */ - if (tp->t_rawq.c_cc > TTYHOG) - ttyflush(tp, FREAD | FWRITE); - else { - if (putc(c, &tp->t_rawq) == 0) - ttwakeup (tp); - ttyecho(c, tp); - } - goto endcase; - } - - /* - * Ignore any high bit added during - * previous ttyinput processing. - */ - if ((tp->t_state & TS_TYPEN) == 0 && (t_flags & PASS8) == 0) - c &= 0177; - - /* - * Check for literal nexting very first. This is the _ONLY_ place - * left which ORs in 0200. Handling literal nexting this way is - * what keeps the tty subsystem from being 8 bit clean. The fix is - * horrendous though and is put off for now. And to think that ALL - * of this is made necessary by ttyrubout() - it's the only place that - * actually _checks_ the 0200 bit and only for newline and tab chars - * at that! - * - * If we had 9 bit bytes life would be a lot simpler ;) - * - * The basic idea is to flag the character as "special" and also - * modify it so that the character does not match any of the special - * editing or control characters. We could just as simply jump directly - * to the test for 'cbreak' below. - */ - if (tp->t_state & TS_LNCH) { - c |= 0200; - tp->t_state &= ~TS_LNCH; - } - - /* - * Scan for special characters. This code - * is really just a big case statement with - * non-constant cases. The bottom of the - * case statement is labeled ``endcase'', so goto - * it after a case match, or similar. - */ - if (CCEQ(tp->t_lnextc, c)) { - if (t_flags & ECHO) - ttyout("^\b", tp); - tp->t_state |= TS_LNCH; - goto endcase; - } - if (CCEQ(tp->t_flushc, c)) { - if (t_flags & FLUSHO) - tp->t_flags &= ~FLUSHO; - else { - ttyflush(tp, FWRITE); - ttyecho(c, tp); - if (tp->t_rawq.c_cc + tp->t_canq.c_cc) - ttyretype(tp); - tp->t_flags |= FLUSHO; - } - goto startoutput; - } - if (CCEQ(tp->t_suspc, c)) { - if ((t_flags & NOFLSH) == 0) - ttyflush(tp, FREAD); - ttyecho(c, tp); - gsignal(tp->t_pgrp, SIGTSTP); - goto endcase; + if (t_flags & RAW) { + /* + * Raw mode, just put character + * in input q w/o interpretation. + */ + if (tp->t_rawq.c_cc > TTYHOG) + ttyflush(tp, FREAD | FWRITE); + else { + if (putc(c, &tp->t_rawq) == 0) + ttwakeup (tp); + ttyecho(c, tp); } + goto endcase; + } - /* - * Handle start/stop characters. - */ - if (CCEQ(tp->t_stopc, c)) { - if ((tp->t_state & TS_TTSTOP) == 0) { - tp->t_state |= TS_TTSTOP; - (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0); - return; - } - if (CCEQ(tp->t_startc, c)) - return; - goto endcase; - } - if (CCEQ(tp->t_startc, c)) - goto restartoutput; + /* + * Ignore any high bit added during + * previous ttyinput processing. + */ + if ((tp->t_state & TS_TYPEN) == 0 && (t_flags & PASS8) == 0) + c &= 0177; - /* - * Look for interrupt/quit chars. - */ - if (CCEQ(tp->t_intrc, c) || CCEQ(tp->t_quitc, c)) { - if ((t_flags & NOFLSH) == 0) - ttyflush(tp, FREAD|FWRITE); - ttyecho(c, tp); - gsignal(tp->t_pgrp, CCEQ(tp->t_intrc, c) ? SIGINT : SIGQUIT); - goto endcase; - } + /* + * Check for literal nexting very first. This is the _ONLY_ place + * left which ORs in 0200. Handling literal nexting this way is + * what keeps the tty subsystem from being 8 bit clean. The fix is + * horrendous though and is put off for now. And to think that ALL + * of this is made necessary by ttyrubout() - it's the only place that + * actually _checks_ the 0200 bit and only for newline and tab chars + * at that! + * + * If we had 9 bit bytes life would be a lot simpler ;) + * + * The basic idea is to flag the character as "special" and also + * modify it so that the character does not match any of the special + * editing or control characters. We could just as simply jump directly + * to the test for 'cbreak' below. + */ + if (tp->t_state & TS_LNCH) { + c |= 0200; + tp->t_state &= ~TS_LNCH; + } - /* - * Cbreak mode, don't process line editing - * characters; check high water mark for wakeup. - */ - if (t_flags & CBREAK) { - if (tp->t_rawq.c_cc > TTYHOG) { - if (tp->t_outq.c_cc < TTHIWAT(tp)) - (void) ttyoutput(CTRL('g'), tp); - } else if (putc(c, &tp->t_rawq) == 0) { - ttwakeup (tp); - ttyecho (c, tp); - } - goto endcase; - } - - /* - * From here on down cooked mode character - * processing takes place. - */ - if (CCEQ(tp->t_erase, c) || CCEQ(CTRL('h'), c)) { - if (tp->t_rawq.c_cc) - ttyrub(unputc(&tp->t_rawq), tp); - goto endcase; - } - if (CCEQ(tp->t_kill, c)) { - if (t_flags & CRTKIL && - tp->t_rawq.c_cc == tp->t_rocount) { - while (tp->t_rawq.c_cc) - ttyrub(unputc(&tp->t_rawq), tp); - } else { - ttyecho(c, tp); - ttyecho('\n', tp); - while (getc(&tp->t_rawq) > 0) - ; - tp->t_rocount = 0; - } - tp->t_state &= ~TS_LOCAL; - goto endcase; - } - - /* - * Check word erase/reprint line. - */ - if (CCEQ(tp->t_werasc, c)) { - if (tp->t_rawq.c_cc == 0) - goto endcase; - do { - c = unputc(&tp->t_rawq); - if (c != ' ' && c != '\t') - goto erasenb; - ttyrub(c, tp); - } while (tp->t_rawq.c_cc); - goto endcase; -erasenb: - do { - ttyrub(c, tp); - if (tp->t_rawq.c_cc == 0) - goto endcase; - c = unputc(&tp->t_rawq); - } while (c != ' ' && c != '\t'); - (void) putc(c, &tp->t_rawq); - goto endcase; - } - if (CCEQ(tp->t_rprntc, c)) { + /* + * Scan for special characters. This code + * is really just a big case statement with + * non-constant cases. The bottom of the + * case statement is labeled ``endcase'', so goto + * it after a case match, or similar. + */ + if (CCEQ(tp->t_lnextc, c)) { + if (t_flags & ECHO) + ttyout("^\b", tp); + tp->t_state |= TS_LNCH; + goto endcase; + } + if (CCEQ(tp->t_flushc, c)) { + if (t_flags & FLUSHO) + tp->t_flags &= ~FLUSHO; + else { + ttyflush(tp, FWRITE); + ttyecho(c, tp); + if (tp->t_rawq.c_cc + tp->t_canq.c_cc) ttyretype(tp); - goto endcase; + tp->t_flags |= FLUSHO; } + goto startoutput; + } + if (CCEQ(tp->t_suspc, c)) { + if ((t_flags & NOFLSH) == 0) + ttyflush(tp, FREAD); + ttyecho(c, tp); + gsignal(tp->t_pgrp, SIGTSTP); + goto endcase; + } - /* - * Check for input buffer overflow - */ - if (tp->t_rawq.c_cc+tp->t_canq.c_cc >= TTYHOG) { - (void) ttyoutput(CTRL('g'), tp); - goto endcase; - } + /* + * Handle start/stop characters. + */ + if (CCEQ(tp->t_stopc, c)) { + if ((tp->t_state & TS_TTSTOP) == 0) { + tp->t_state |= TS_TTSTOP; + (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0); + return; + } + if (CCEQ(tp->t_startc, c)) + return; + goto endcase; + } + if (CCEQ(tp->t_startc, c)) + goto restartoutput; - /* - * Put data char in q for user and - * wakeup on seeing a line delimiter. - */ - if (putc(c, &tp->t_rawq) == 0) { - if (ttbreakc (c, tp)) { - tp->t_rocount = 0; - catq(&tp->t_rawq, &tp->t_canq); - ttwakeup (tp); - } else if (tp->t_rocount++ == 0) - tp->t_rocol = tp->t_col; - if (tp->t_state & TS_ERASE) { - tp->t_state &= ~TS_ERASE; - (void) ttyoutput('/', tp); - } - i = tp->t_col; - ttyecho(c, tp); - if (CCEQ(tp->t_eofc, c) && t_flags & ECHO) { - i = MIN(2, tp->t_col - i); - while (i > 0) { - (void) ttyoutput('\b', tp); - i--; - } - } - } + /* + * Look for interrupt/quit chars. + */ + if (CCEQ(tp->t_intrc, c) || CCEQ(tp->t_quitc, c)) { + if ((t_flags & NOFLSH) == 0) + ttyflush(tp, FREAD|FWRITE); + ttyecho(c, tp); + gsignal(tp->t_pgrp, CCEQ(tp->t_intrc, c) ? SIGINT : SIGQUIT); + goto endcase; + } + + /* + * Cbreak mode, don't process line editing + * characters; check high water mark for wakeup. + */ + if (t_flags & CBREAK) { + if (tp->t_rawq.c_cc > TTYHOG) { + if (tp->t_outq.c_cc < TTHIWAT(tp)) + (void) ttyoutput(CTRL('g'), tp); + } else if (putc(c, &tp->t_rawq) == 0) { + ttwakeup (tp); + ttyecho (c, tp); + } + goto endcase; + } + + /* + * From here on down cooked mode character + * processing takes place. + */ + if (CCEQ(tp->t_erase, c) || CCEQ(CTRL('h'), c)) { + if (tp->t_rawq.c_cc) + ttyrub(unputc(&tp->t_rawq), tp); + goto endcase; + } + if (CCEQ(tp->t_kill, c)) { + if (t_flags & CRTKIL && + tp->t_rawq.c_cc == tp->t_rocount) { + while (tp->t_rawq.c_cc) + ttyrub(unputc(&tp->t_rawq), tp); + } else { + ttyecho(c, tp); + ttyecho('\n', tp); + while (getc(&tp->t_rawq) > 0) + ; + tp->t_rocount = 0; + } + tp->t_state &= ~TS_LOCAL; + goto endcase; + } + + /* + * Check word erase/reprint line. + */ + if (CCEQ(tp->t_werasc, c)) { + if (tp->t_rawq.c_cc == 0) + goto endcase; + do { + c = unputc(&tp->t_rawq); + if (c != ' ' && c != '\t') + goto erasenb; + ttyrub(c, tp); + } while (tp->t_rawq.c_cc); + goto endcase; +erasenb: + do { + ttyrub(c, tp); + if (tp->t_rawq.c_cc == 0) + goto endcase; + c = unputc(&tp->t_rawq); + } while (c != ' ' && c != '\t'); + (void) putc(c, &tp->t_rawq); + goto endcase; + } + if (CCEQ(tp->t_rprntc, c)) { + ttyretype(tp); + goto endcase; + } + + /* + * Check for input buffer overflow + */ + if (tp->t_rawq.c_cc+tp->t_canq.c_cc >= TTYHOG) { + (void) ttyoutput(CTRL('g'), tp); + goto endcase; + } + + /* + * Put data char in q for user and + * wakeup on seeing a line delimiter. + */ + if (putc(c, &tp->t_rawq) == 0) { + if (ttbreakc (c, tp)) { + tp->t_rocount = 0; + catq(&tp->t_rawq, &tp->t_canq); + ttwakeup (tp); + } else if (tp->t_rocount++ == 0) + tp->t_rocol = tp->t_col; + if (tp->t_state & TS_ERASE) { + tp->t_state &= ~TS_ERASE; + (void) ttyoutput('/', tp); + } + i = tp->t_col; + ttyecho(c, tp); + if (CCEQ(tp->t_eofc, c) && t_flags & ECHO) { + i = MIN(2, tp->t_col - i); + while (i > 0) { + (void) ttyoutput('\b', tp); + i--; + } + } + } endcase: - /* - * If DEC-style start/stop is enabled don't restart - * output until seeing the start character. - */ - if (t_flags & DECCTQ && tp->t_state & TS_TTSTOP && - tp->t_startc != tp->t_stopc) - return; + /* + * If DEC-style start/stop is enabled don't restart + * output until seeing the start character. + */ + if (t_flags & DECCTQ && tp->t_state & TS_TTSTOP && + tp->t_startc != tp->t_stopc) + return; restartoutput: - tp->t_state &= ~TS_TTSTOP; - tp->t_flags &= ~FLUSHO; + tp->t_state &= ~TS_TTSTOP; + tp->t_flags &= ~FLUSHO; startoutput: - ttstart(tp); + ttstart(tp); } /* @@ -1191,86 +1249,86 @@ startoutput: */ int ttyoutput(c, tp) - register int c; - register struct tty *tp; + register int c; + register struct tty *tp; { - register int col; + register int col; - if (tp->t_flags & (RAW|LITOUT)) { - if (tp->t_flags & FLUSHO) - return (-1); - if (putc(c, &tp->t_outq)) - return(c); + if (tp->t_flags & (RAW|LITOUT)) { + if (tp->t_flags & FLUSHO) + return (-1); + if (putc(c, &tp->t_outq)) + return(c); #ifdef UCB_METER - tk_nout++; + tk_nout++; #endif - return(-1); - } + return(-1); + } - c &= 0177; -#ifdef whybother - /* - * Ignore EOT in normal mode to avoid - * hanging up certain terminals. - */ - if (c == CEOT && (tp->t_flags & CBREAK) == 0) - return(-1); + c &= 0177; +#ifdef whybother + /* + * Ignore EOT in normal mode to avoid + * hanging up certain terminals. + */ + if (c == CEOT && (tp->t_flags & CBREAK) == 0) + return(-1); #endif - /* - * Turn tabs to spaces as required - */ - if (c == '\t' && (tp->t_flags & XTABS)) { - register int s; + /* + * Turn tabs to spaces as required + */ + if (c == '\t' && (tp->t_flags & XTABS)) { + register int s; - c = 8 - (tp->t_col&7); - if ((tp->t_flags & FLUSHO) == 0) { - s = spltty(); /* don't interrupt tabs */ - c -= b_to_q(" ", c, &tp->t_outq); + c = 8 - (tp->t_col&7); + if ((tp->t_flags & FLUSHO) == 0) { + s = spltty(); /* don't interrupt tabs */ + c -= b_to_q(" ", c, &tp->t_outq); #ifdef UCB_METER - tk_nout += c; + tk_nout += c; #endif - splx(s); - } - tp->t_col += c; - return (c ? -1 : '\t'); - } + splx(s); + } + tp->t_col += c; + return (c ? -1 : '\t'); + } #ifdef UCB_METER - tk_nout++; + tk_nout++; #endif - /* - * turn to if desired. - */ - if (c == '\n' && tp->t_flags & CRMOD) { - if (putc('\r', &tp->t_outq)) - return(c); + /* + * turn to if desired. + */ + if (c == '\n' && tp->t_flags & CRMOD) { + if (putc('\r', &tp->t_outq)) + return(c); #ifdef UCB_METER - tk_nout++; + tk_nout++; #endif - } - if ((tp->t_flags & FLUSHO) == 0 && putc(c, &tp->t_outq)) - return (c); + } + if ((tp->t_flags & FLUSHO) == 0 && putc(c, &tp->t_outq)) + return (c); - col = tp->t_col; - switch (partab[c] & 077) { + col = tp->t_col; + switch (partab[c] & 077) { - case ORDINARY: - col++; - case CONTROL: - break; - case BACKSPACE: - if (col) - col--; - break; - case NEWLINE: - case RETURN: - col = 0; - break; - case TAB: - col = (col | 07) + 1; - break; - } - tp->t_col = col; - return(-1); + case ORDINARY: + col++; + case CONTROL: + break; + case BACKSPACE: + if (col) + col--; + break; + case NEWLINE: + case RETURN: + col = 0; + break; + case TAB: + col = (col | 07) + 1; + break; + } + tp->t_col = col; + return(-1); } /* @@ -1279,144 +1337,144 @@ ttyoutput(c, tp) */ int ttread (tp, uio, flag) - register struct tty *tp; - struct uio *uio; + register struct tty *tp; + struct uio *uio; { - register struct clist *qp; - register int c; - long t_flags; - int s, first, error = 0, carrier; + register struct clist *qp; + register int c; + long t_flags; + int s, first, error = 0, carrier; loop: - /* - * Take any pending input first. - */ - s = spltty(); - if (tp->t_flags & PENDIN) - ttypend(tp); - splx(s); + /* + * Take any pending input first. + */ + s = spltty(); + if (tp->t_flags & PENDIN) + ttypend(tp); + splx(s); - /* - * Hang process if it's in the background. - */ - if (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) { - if ((u.u_procp->p_sigignore & sigmask(SIGTTIN)) || - (u.u_procp->p_sigmask & sigmask(SIGTTIN)) || - u.u_procp->p_flag & SVFORK) - return (EIO); - gsignal(u.u_procp->p_pgrp, SIGTTIN); - sleep((caddr_t)&lbolt, TTIPRI); - goto loop; - } - t_flags = tp->t_flags; + /* + * Hang process if it's in the background. + */ + if (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) { + if ((u.u_procp->p_sigignore & sigmask(SIGTTIN)) || + (u.u_procp->p_sigmask & sigmask(SIGTTIN)) || + u.u_procp->p_flag & SVFORK) + return (EIO); + gsignal(u.u_procp->p_pgrp, SIGTTIN); + sleep((caddr_t)&lbolt, TTIPRI); + goto loop; + } + t_flags = tp->t_flags; - /* - * In raw mode take characters directly from the - * raw queue w/o processing. Interlock against - * device interrupts when interrogating rawq. - */ - if (t_flags & RAW) { - s = spltty(); - if (tp->t_rawq.c_cc <= 0) { - carrier = ISSET(tp->t_state, TS_CARR_ON); - if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) { - splx(s); - return(0); /* EOF */ - } - if (flag & IO_NDELAY) { - splx(s); - return(EWOULDBLOCK); - } - sleep((caddr_t)&tp->t_rawq, TTIPRI); - splx(s); - goto loop; - } - splx(s); - while (!error && tp->t_rawq.c_cc && uio->uio_resid) - error = ureadc(getc(&tp->t_rawq), uio); - goto checktandem; - } + /* + * In raw mode take characters directly from the + * raw queue w/o processing. Interlock against + * device interrupts when interrogating rawq. + */ + if (t_flags & RAW) { + s = spltty(); + if (tp->t_rawq.c_cc <= 0) { + carrier = ISSET(tp->t_state, TS_CARR_ON); + if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) { + splx(s); + return(0); /* EOF */ + } + if (flag & IO_NDELAY) { + splx(s); + return(EWOULDBLOCK); + } + sleep((caddr_t)&tp->t_rawq, TTIPRI); + splx(s); + goto loop; + } + splx(s); + while (!error && tp->t_rawq.c_cc && uio->uio_resid) + error = ureadc(getc(&tp->t_rawq), uio); + goto checktandem; + } - /* - * In cbreak mode use the rawq, otherwise - * take characters from the canonicalized q. - */ - qp = t_flags & CBREAK ? &tp->t_rawq : &tp->t_canq; + /* + * In cbreak mode use the rawq, otherwise + * take characters from the canonicalized q. + */ + qp = t_flags & CBREAK ? &tp->t_rawq : &tp->t_canq; - /* - * No input, sleep on rawq awaiting hardware - * receipt and notification. - */ - s = spltty(); - if (qp->c_cc <= 0) { - carrier = ISSET(tp->t_state, TS_CARR_ON); - if (!carrier && ISSET(tp->t_state,TS_ISOPEN)) - { - splx(s); - return(0); /* EOF */ - } - if (flag & IO_NDELAY) - { - splx(s); - return(EWOULDBLOCK); - } - sleep((caddr_t)&tp->t_rawq, TTIPRI); - splx(s); - goto loop; - } - splx(s); + /* + * No input, sleep on rawq awaiting hardware + * receipt and notification. + */ + s = spltty(); + if (qp->c_cc <= 0) { + carrier = ISSET(tp->t_state, TS_CARR_ON); + if (!carrier && ISSET(tp->t_state,TS_ISOPEN)) + { + splx(s); + return(0); /* EOF */ + } + if (flag & IO_NDELAY) + { + splx(s); + return(EWOULDBLOCK); + } + sleep((caddr_t)&tp->t_rawq, TTIPRI); + splx(s); + goto loop; + } + splx(s); - /* - * Input present, perform input mapping - * and processing (we're not in raw mode). - */ - first = 1; - while ((c = getc(qp)) >= 0) { - if (t_flags & CRMOD && c == '\r') - c = '\n'; - /* - * Check for delayed suspend character. - */ - if (CCEQ(tp->t_dsuspc, c)) { - gsignal(tp->t_pgrp, SIGTSTP); - if (first) { - sleep((caddr_t)&lbolt, TTIPRI); - goto loop; - } - break; - } - /* - * Interpret EOF only in cooked mode. - */ - if (CCEQ(tp->t_eofc, c) && (t_flags & CBREAK) == 0) - break; - /* - * Give user character. - */ - error = ureadc(t_flags & PASS8 ? c : c & 0177, uio); - if (error) - break; - if (uio->uio_resid == 0) - break; - /* - * In cooked mode check for a "break character" - * marking the end of a "line of input". - */ - if ((t_flags & CBREAK) == 0 && ttbreakc (c, tp)) - break; - first = 0; - } + /* + * Input present, perform input mapping + * and processing (we're not in raw mode). + */ + first = 1; + while ((c = getc(qp)) >= 0) { + if (t_flags & CRMOD && c == '\r') + c = '\n'; + /* + * Check for delayed suspend character. + */ + if (CCEQ(tp->t_dsuspc, c)) { + gsignal(tp->t_pgrp, SIGTSTP); + if (first) { + sleep((caddr_t)&lbolt, TTIPRI); + goto loop; + } + break; + } + /* + * Interpret EOF only in cooked mode. + */ + if (CCEQ(tp->t_eofc, c) && (t_flags & CBREAK) == 0) + break; + /* + * Give user character. + */ + error = ureadc(t_flags & PASS8 ? c : c & 0177, uio); + if (error) + break; + if (uio->uio_resid == 0) + break; + /* + * In cooked mode check for a "break character" + * marking the end of a "line of input". + */ + if ((t_flags & CBREAK) == 0 && ttbreakc (c, tp)) + break; + first = 0; + } checktandem: - /* - * Look to unblock output now that (presumably) - * the input queue has gone down. - */ - s = spltty(); - if (ISSET(tp->t_state,TS_TBLOCK) && tp->t_rawq.c_cc < TTYUNBLOCK) - ttyunblock(tp); - splx(s); - return(error); + /* + * Look to unblock output now that (presumably) + * the input queue has gone down. + */ + s = spltty(); + if (ISSET(tp->t_state,TS_TBLOCK) && tp->t_rawq.c_cc < TTYUNBLOCK) + ttyunblock(tp); + splx(s); + return(error); } /* @@ -1429,27 +1487,27 @@ checktandem: */ int ttycheckoutq (tp, wait) - register struct tty *tp; - int wait; + register struct tty *tp; + int wait; { - int hiwat, s, oldsig; + int hiwat, s, oldsig; - hiwat = TTHIWAT(tp); - s = spltty(); - oldsig = u.u_procp->p_sig; - if (tp->t_outq.c_cc > hiwat + 200) - while (tp->t_outq.c_cc > hiwat) { - ttstart(tp); - if (wait == 0 || u.u_procp->p_sig != oldsig) { - splx(s); - return(0); - } - timeout (wakeup, (caddr_t)&tp->t_outq, hz); - tp->t_state |= TS_ASLEEP; - sleep ((caddr_t) &tp->t_outq, PZERO - 1); - } - splx(s); - return(1); + hiwat = TTHIWAT(tp); + s = spltty(); + oldsig = u.u_procp->p_sig; + if (tp->t_outq.c_cc > hiwat + 200) + while (tp->t_outq.c_cc > hiwat) { + ttstart(tp); + if (wait == 0 || u.u_procp->p_sig != oldsig) { + splx(s); + return(0); + } + timeout (wakeup, (caddr_t)&tp->t_outq, hz); + tp->t_state |= TS_ASLEEP; + sleep ((caddr_t) &tp->t_outq, PZERO - 1); + } + splx(s); + return(1); } /* @@ -1459,16 +1517,16 @@ ttycheckoutq (tp, wait) */ static int scanc (size, str) - unsigned size; - const char *str; + unsigned size; + const char *str; { - if (size == 0 || str == 0) - return 0; - do { - if (partab [(u_char) *str++] & 077) - return size; - } while (--size > 0); - return 0; + if (size == 0 || str == 0) + return 0; + do { + if (partab [(u_char) *str++] & 077) + return size; + } while (--size > 0); + return 0; } /* @@ -1477,184 +1535,184 @@ scanc (size, str) */ int ttwrite (tp, uio, flag) - register struct tty *tp; - register struct uio *uio; + register struct tty *tp; + register struct uio *uio; { - char *cp; - register int cc, ce; - int i, hiwat, cnt, error, s; - char obuf[OBUFSIZ]; + char *cp; + register int cc, ce; + int i, hiwat, cnt, error, s; + char obuf[OBUFSIZ]; - hiwat = TTHIWAT(tp); - cnt = uio->uio_resid; - error = 0; - cc = 0; - cp = 0; + hiwat = TTHIWAT(tp); + cnt = uio->uio_resid; + error = 0; + cc = 0; + cp = 0; loop: - s = spltty(); - if (! (tp->t_state & TS_CARR_ON)) { - if (tp->t_state & TS_ISOPEN) { - splx(s); - return(EIO); - } else if (flag & IO_NDELAY) { - splx(s); - error = EWOULDBLOCK; - goto out; - } else { - /* Sleep awaiting carrier. */ - sleep((caddr_t)&tp->t_rawq, TTIPRI); - splx(s); - goto loop; - } - } - splx(s); - /* - * Hang the process if it's in the background. - */ - if (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp && - (tp->t_flags & TOSTOP) && (u.u_procp->p_flag & SVFORK)==0 && - ! (u.u_procp->p_sigignore & sigmask(SIGTTOU)) && - ! (u.u_procp->p_sigmask & sigmask(SIGTTOU))) { - gsignal(u.u_procp->p_pgrp, SIGTTOU); - sleep((caddr_t)&lbolt, TTIPRI); - goto loop; - } + s = spltty(); + if (! (tp->t_state & TS_CARR_ON)) { + if (tp->t_state & TS_ISOPEN) { + splx(s); + return(EIO); + } else if (flag & IO_NDELAY) { + splx(s); + error = EWOULDBLOCK; + goto out; + } else { + /* Sleep awaiting carrier. */ + sleep((caddr_t)&tp->t_rawq, TTIPRI); + splx(s); + goto loop; + } + } + splx(s); + /* + * Hang the process if it's in the background. + */ + if (u.u_procp->p_pgrp != tp->t_pgrp && tp == u.u_ttyp && + (tp->t_flags & TOSTOP) && (u.u_procp->p_flag & SVFORK)==0 && + ! (u.u_procp->p_sigignore & sigmask(SIGTTOU)) && + ! (u.u_procp->p_sigmask & sigmask(SIGTTOU))) { + gsignal(u.u_procp->p_pgrp, SIGTTOU); + sleep((caddr_t)&lbolt, TTIPRI); + goto loop; + } - /* - * Process the user's data in at most OBUFSIZ - * chunks. Perform lower case simulation and - * similar hacks. Keep track of high water - * mark, sleep on overflow awaiting device aid - * in acquiring new space. - */ - while (uio->uio_resid || cc > 0) { - if (tp->t_flags & FLUSHO) { - uio->uio_resid = 0; - return(0); - } - if (tp->t_outq.c_cc > hiwat) - goto ovhiwat; - /* - * Grab a hunk of data from the user, unless we have some - * leftover from last time. - */ - if (cc == 0) { - cc = MIN(uio->uio_resid, OBUFSIZ); - cp = obuf; - error = uiomove(cp, cc, uio); - if (error) { - cc = 0; - break; - } - } - /* - * If nothing fancy need be done, grab those characters we - * can handle without any of ttyoutput's processing and - * just transfer them to the output q. For those chars - * which require special processing (as indicated by the - * bits in partab), call ttyoutput. After processing - * a hunk of data, look for FLUSHO so ^O's will take effect - * immediately. - */ - while (cc > 0) { - if (tp->t_flags & (RAW|LITOUT)) - ce = cc; - else { - ce = cc - scanc((unsigned)cc, (caddr_t)cp); - /* - * If ce is zero, then we're processing - * a special character through ttyoutput. - */ - if (ce == 0) { - tp->t_rocount = 0; - if (ttyoutput(*cp, tp) >= 0) { + /* + * Process the user's data in at most OBUFSIZ + * chunks. Perform lower case simulation and + * similar hacks. Keep track of high water + * mark, sleep on overflow awaiting device aid + * in acquiring new space. + */ + while (uio->uio_resid || cc > 0) { + if (tp->t_flags & FLUSHO) { + uio->uio_resid = 0; + return(0); + } + if (tp->t_outq.c_cc > hiwat) + goto ovhiwat; + /* + * Grab a hunk of data from the user, unless we have some + * leftover from last time. + */ + if (cc == 0) { + cc = MIN(uio->uio_resid, OBUFSIZ); + cp = obuf; + error = uiomove(cp, cc, uio); + if (error) { + cc = 0; + break; + } + } + /* + * If nothing fancy need be done, grab those characters we + * can handle without any of ttyoutput's processing and + * just transfer them to the output q. For those chars + * which require special processing (as indicated by the + * bits in partab), call ttyoutput. After processing + * a hunk of data, look for FLUSHO so ^O's will take effect + * immediately. + */ + while (cc > 0) { + if (tp->t_flags & (RAW|LITOUT)) + ce = cc; + else { + ce = cc - scanc((unsigned)cc, (caddr_t)cp); + /* + * If ce is zero, then we're processing + * a special character through ttyoutput. + */ + if (ce == 0) { + tp->t_rocount = 0; + if (ttyoutput(*cp, tp) >= 0) { overflow: /* out of c-lists */ - s = spltty(); - ttstart(tp); - if (flag & IO_NDELAY) { - splx(s); - uio->uio_resid += cc; - return (uio->uio_resid == cnt ? - EWOULDBLOCK : 0); - } - tp->t_state |= TS_ASLEEP; - sleep((caddr_t)&tp->t_outq, TTOPRI); - splx(s); - goto loop; - } - cp++, cc--; - if (tp->t_flags & FLUSHO || - tp->t_outq.c_cc > hiwat) - goto ovhiwat; - continue; - } - } - /* - * A bunch of normal characters have been found, - * transfer them en masse to the output queue and - * continue processing at the top of the loop. - * If there are any further characters in this - * <= OBUFSIZ chunk, the first should be a character - * requiring special handling by ttyoutput. - */ - tp->t_rocount = 0; - i = b_to_q(cp, ce, &tp->t_outq); - ce -= i; - tp->t_col += ce; - cp += ce, cc -= ce; + s = spltty(); + ttstart(tp); + if (flag & IO_NDELAY) { + splx(s); + uio->uio_resid += cc; + return (uio->uio_resid == cnt ? + EWOULDBLOCK : 0); + } + tp->t_state |= TS_ASLEEP; + sleep((caddr_t)&tp->t_outq, TTOPRI); + splx(s); + goto loop; + } + cp++, cc--; + if (tp->t_flags & FLUSHO || + tp->t_outq.c_cc > hiwat) + goto ovhiwat; + continue; + } + } + /* + * A bunch of normal characters have been found, + * transfer them en masse to the output queue and + * continue processing at the top of the loop. + * If there are any further characters in this + * <= OBUFSIZ chunk, the first should be a character + * requiring special handling by ttyoutput. + */ + tp->t_rocount = 0; + i = b_to_q(cp, ce, &tp->t_outq); + ce -= i; + tp->t_col += ce; + cp += ce, cc -= ce; #ifdef UCB_METER - tk_nout += ce; + tk_nout += ce; #endif - if (i > 0) { - /* out of c-lists */ - goto overflow; - } - if (tp->t_flags & FLUSHO || tp->t_outq.c_cc > hiwat) - break; - } /* while (cc > 0) */ - ttstart(tp); - } /* while (uio->uio_resid || cc > 0) */ + if (i > 0) { + /* out of c-lists */ + goto overflow; + } + if (tp->t_flags & FLUSHO || tp->t_outq.c_cc > hiwat) + break; + } /* while (cc > 0) */ + ttstart(tp); + } /* while (uio->uio_resid || cc > 0) */ out: - /* - * If cc is nonzero, we leave the uio structure inconsistent, as the - * offset and iov pointers have moved forward, but it doesn't matter - * (the call will either return short or restart with a new uio). - */ - uio->uio_resid += cc; - return (error); + /* + * If cc is nonzero, we leave the uio structure inconsistent, as the + * offset and iov pointers have moved forward, but it doesn't matter + * (the call will either return short or restart with a new uio). + */ + uio->uio_resid += cc; + return (error); ovhiwat: - s = spltty(); - /* - * This can only occur if FLUSHO is also set in t_flags, - * or if ttstart/oproc is synchronous (or very fast). - */ - if (tp->t_outq.c_cc <= hiwat) { - splx(s); - goto loop; - } - ttstart(tp); - if (flag & IO_NDELAY) { - splx(s); - uio->uio_resid += cc; - return (uio->uio_resid == cnt ? EWOULDBLOCK : 0); - } - tp->t_state |= TS_ASLEEP; - sleep((caddr_t)&tp->t_outq, TTOPRI); - splx(s); - goto loop; + s = spltty(); + /* + * This can only occur if FLUSHO is also set in t_flags, + * or if ttstart/oproc is synchronous (or very fast). + */ + if (tp->t_outq.c_cc <= hiwat) { + splx(s); + goto loop; + } + ttstart(tp); + if (flag & IO_NDELAY) { + splx(s); + uio->uio_resid += cc; + return (uio->uio_resid == cnt ? EWOULDBLOCK : 0); + } + tp->t_state |= TS_ASLEEP; + sleep((caddr_t)&tp->t_outq, TTOPRI); + splx(s); + goto loop; } void ttwakeup (tp) - register struct tty *tp; + register struct tty *tp; { - if (tp->t_rsel) { - selwakeup (tp->t_rsel, tp->t_state & TS_RCOLL); - tp->t_state &= ~TS_RCOLL; - tp->t_rsel = 0; - } - if (tp->t_state & TS_ASYNC) - gsignal (tp->t_pgrp, SIGIO); - wakeup ((caddr_t) &tp->t_rawq); + if (tp->t_rsel) { + selwakeup (tp->t_rsel, tp->t_state & TS_RCOLL); + tp->t_state &= ~TS_RCOLL; + tp->t_rsel = 0; + } + if (tp->t_state & TS_ASYNC) + gsignal (tp->t_pgrp, SIGIO); + wakeup ((caddr_t) &tp->t_rawq); } diff --git a/sys/kernel/tty_pty.c b/sys/kernel/tty_pty.c index 3c6f911..5a08a92 100644 --- a/sys/kernel/tty_pty.c +++ b/sys/kernel/tty_pty.c @@ -33,106 +33,108 @@ const struct devspec ptcdevs[] = { { 0, 0 } }; -extern int TTYHOG; /* see tty.c */ +extern int TTYHOG; /* see tty.c */ -#define BUFSIZ 100 /* Chunk size iomoved to/from user */ +#define BUFSIZ 100 /* Chunk size iomoved to/from user */ /* * pts == /dev/tty[pqrs]? * ptc == /dev/pty[pqrs]? */ -struct tty pt_tty[NPTY]; -struct pt_ioctl { - int pt_flags; - struct proc *pt_selr, *pt_selw; - u_char pt_send; - u_char pt_ucntl; -} pt_ioctl[NPTY]; -int npty = NPTY; /* for pstat -t */ +struct tty pt_tty[NPTY]; -#define PF_RCOLL 0x01 -#define PF_WCOLL 0x02 -#define PF_PKT 0x08 /* packet mode */ -#define PF_STOPPED 0x10 /* user told stopped */ -#define PF_REMOTE 0x20 /* remote and flow controlled input */ -#define PF_NOSTOP 0x40 -#define PF_UCNTL 0x80 /* user control mode */ +struct pt_ioctl { + int pt_flags; + struct proc *pt_selr, *pt_selw; + u_char pt_send; + u_char pt_ucntl; +} pt_ioctl[NPTY]; + +int npty = NPTY; /* for pstat -t */ + +#define PF_RCOLL 0x01 +#define PF_WCOLL 0x02 +#define PF_PKT 0x08 /* packet mode */ +#define PF_STOPPED 0x10 /* user told stopped */ +#define PF_REMOTE 0x20 /* remote and flow controlled input */ +#define PF_NOSTOP 0x40 +#define PF_UCNTL 0x80 /* user control mode */ /*ARGSUSED*/ int ptsopen(dev_t dev, int flag, int mode) { - register struct tty *tp; - int error; + register struct tty *tp; + int error; #ifdef lint - npty = npty; + npty = npty; #endif - if (minor(dev) >= NPTY) - return (ENXIO); - tp = &pt_tty[minor(dev)]; - if ((tp->t_state & TS_ISOPEN) == 0) { - ttychars(tp); /* Set up default chars */ - tp->t_ispeed = tp->t_ospeed = B115200; - tp->t_flags = 0; /* No features (nor raw mode) */ - } else if (tp->t_state&TS_XCLUDE && u.u_uid != 0) - return (EBUSY); - if (tp->t_oproc) /* Ctrlr still around. */ - tp->t_state |= TS_CARR_ON; - while ((tp->t_state & TS_CARR_ON) == 0) { - tp->t_state |= TS_WOPEN; - sleep((caddr_t)&tp->t_rawq, TTIPRI); - } - error = ttyopen(dev, tp); - ptcwakeup (tp, FREAD | FWRITE); - return (error); + if (minor(dev) >= NPTY) + return (ENXIO); + tp = &pt_tty[minor(dev)]; + if ((tp->t_state & TS_ISOPEN) == 0) { + ttychars(tp); /* Set up default chars */ + tp->t_ispeed = tp->t_ospeed = B115200; + tp->t_flags = 0; /* No features (nor raw mode) */ + } else if (tp->t_state&TS_XCLUDE && u.u_uid != 0) + return (EBUSY); + if (tp->t_oproc) /* Ctrlr still around. */ + tp->t_state |= TS_CARR_ON; + while ((tp->t_state & TS_CARR_ON) == 0) { + tp->t_state |= TS_WOPEN; + sleep((caddr_t)&tp->t_rawq, TTIPRI); + } + error = ttyopen(dev, tp); + ptcwakeup (tp, FREAD | FWRITE); + return (error); } int ptsclose(dev_t dev, int flag, int mode) { - register struct tty *tp; + register struct tty *tp; - tp = &pt_tty[minor(dev)]; - ttyclose(tp); - ptcwakeup(tp, FREAD|FWRITE); - return 0; + tp = &pt_tty[minor(dev)]; + ttyclose(tp); + ptcwakeup(tp, FREAD|FWRITE); + return 0; } int ptsread(dev_t dev, register struct uio *uio, int flag) { - register struct tty *tp = &pt_tty[minor(dev)]; - register struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; - int error = 0; + register struct tty *tp = &pt_tty[minor(dev)]; + register struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; + int error = 0; again: - if (pti->pt_flags & PF_REMOTE) { - while (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) { - if ((u.u_procp->p_sigignore & sigmask(SIGTTIN)) || - (u.u_procp->p_sigmask & sigmask(SIGTTIN)) || - u.u_procp->p_flag&SVFORK) - return (EIO); - gsignal(u.u_procp->p_pgrp, SIGTTIN); - sleep((caddr_t)&lbolt, TTIPRI); - } - if (tp->t_canq.c_cc == 0) { - if (flag & IO_NDELAY) - return (EWOULDBLOCK); - sleep((caddr_t)&tp->t_canq, TTIPRI); - goto again; - } - while (tp->t_canq.c_cc > 1 && uio->uio_resid) - if (ureadc(getc(&tp->t_canq), uio) < 0) { - error = EFAULT; - break; - } - if (tp->t_canq.c_cc == 1) - (void) getc(&tp->t_canq); - if (tp->t_canq.c_cc) - return (error); - } else - if (tp->t_oproc) - error = ttread(tp, uio, flag); - ptcwakeup(tp, FWRITE); - return (error); + if (pti->pt_flags & PF_REMOTE) { + while (tp == u.u_ttyp && u.u_procp->p_pgrp != tp->t_pgrp) { + if ((u.u_procp->p_sigignore & sigmask(SIGTTIN)) || + (u.u_procp->p_sigmask & sigmask(SIGTTIN)) || + u.u_procp->p_flag&SVFORK) + return (EIO); + gsignal(u.u_procp->p_pgrp, SIGTTIN); + sleep((caddr_t)&lbolt, TTIPRI); + } + if (tp->t_canq.c_cc == 0) { + if (flag & IO_NDELAY) + return (EWOULDBLOCK); + sleep((caddr_t)&tp->t_canq, TTIPRI); + goto again; + } + while (tp->t_canq.c_cc > 1 && uio->uio_resid) + if (ureadc(getc(&tp->t_canq), uio) < 0) { + error = EFAULT; + break; + } + if (tp->t_canq.c_cc == 1) + (void) getc(&tp->t_canq); + if (tp->t_canq.c_cc) + return (error); + } else + if (tp->t_oproc) + error = ttread(tp, uio, flag); + ptcwakeup(tp, FWRITE); + return (error); } /* @@ -142,12 +144,12 @@ again: */ int ptswrite(dev_t dev, register struct uio *uio, int flag) { - register struct tty *tp; + register struct tty *tp; - tp = &pt_tty[minor(dev)]; - if (tp->t_oproc == 0) - return (EIO); - return ttwrite(tp, uio, flag); + tp = &pt_tty[minor(dev)]; + if (tp->t_oproc == 0) + return (EIO); + return ttwrite(tp, uio, flag); } /* @@ -156,365 +158,365 @@ int ptswrite(dev_t dev, register struct uio *uio, int flag) */ void ptsstart(struct tty *tp) { - register struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; + register struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; - if (tp->t_state & TS_TTSTOP) - return; - if (pti->pt_flags & PF_STOPPED) { - pti->pt_flags &= ~PF_STOPPED; - pti->pt_send = TIOCPKT_START; - } - ptcwakeup(tp, FREAD); + if (tp->t_state & TS_TTSTOP) + return; + if (pti->pt_flags & PF_STOPPED) { + pti->pt_flags &= ~PF_STOPPED; + pti->pt_send = TIOCPKT_START; + } + ptcwakeup(tp, FREAD); } void ptcwakeup(struct tty *tp, int flag) { - struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; + struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; - if (flag & FREAD) { - if (pti->pt_selr) { - selwakeup(pti->pt_selr, (long)(pti->pt_flags & PF_RCOLL)); - pti->pt_selr = 0; - pti->pt_flags &= ~PF_RCOLL; - } - wakeup((caddr_t)&tp->t_outq.c_cf); - } - if (flag & FWRITE) { - if (pti->pt_selw) { - selwakeup(pti->pt_selw, (long)(pti->pt_flags & PF_WCOLL)); - pti->pt_selw = 0; - pti->pt_flags &= ~PF_WCOLL; - } - wakeup((caddr_t)&tp->t_rawq.c_cf); - } + if (flag & FREAD) { + if (pti->pt_selr) { + selwakeup(pti->pt_selr, (long)(pti->pt_flags & PF_RCOLL)); + pti->pt_selr = 0; + pti->pt_flags &= ~PF_RCOLL; + } + wakeup((caddr_t)&tp->t_outq.c_cf); + } + if (flag & FWRITE) { + if (pti->pt_selw) { + selwakeup(pti->pt_selw, (long)(pti->pt_flags & PF_WCOLL)); + pti->pt_selw = 0; + pti->pt_flags &= ~PF_WCOLL; + } + wakeup((caddr_t)&tp->t_rawq.c_cf); + } } /*ARGSUSED*/ int ptcopen(dev_t dev, int flag, int mode) { - register struct tty *tp; - struct pt_ioctl *pti; + register struct tty *tp; + struct pt_ioctl *pti; - if (minor(dev) >= NPTY) - return (ENXIO); - tp = &pt_tty[minor(dev)]; - if (tp->t_oproc) - return (EIO); - tp->t_oproc = ptsstart; - ttymodem(tp, 1); - pti = &pt_ioctl[minor(dev)]; - pti->pt_flags = 0; - pti->pt_send = 0; - pti->pt_ucntl = 0; - return (0); + if (minor(dev) >= NPTY) + return (ENXIO); + tp = &pt_tty[minor(dev)]; + if (tp->t_oproc) + return (EIO); + tp->t_oproc = ptsstart; + ttymodem(tp, 1); + pti = &pt_ioctl[minor(dev)]; + pti->pt_flags = 0; + pti->pt_send = 0; + pti->pt_ucntl = 0; + return (0); } int ptcclose(dev_t dev, int flag, int mode) { - register struct tty *tp; + register struct tty *tp; - tp = &pt_tty[minor(dev)]; - ttymodem(tp, 0); - tp->t_state &= ~TS_CARR_ON; - tp->t_oproc = 0; /* mark closed */ - return 0; + tp = &pt_tty[minor(dev)]; + ttymodem(tp, 0); + tp->t_state &= ~TS_CARR_ON; + tp->t_oproc = 0; /* mark closed */ + return 0; } int ptcread(dev_t dev, register struct uio *uio, int flag) { - register struct tty *tp = &pt_tty[minor(dev)]; - struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; - char buf[BUFSIZ]; - int error = 0, cc; + register struct tty *tp = &pt_tty[minor(dev)]; + struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; + char buf[BUFSIZ]; + int error = 0, cc; - /* - * We want to block until the slave - * is open, and there's something to read; - * but if we lost the slave or we're NBIO, - * then return the appropriate error instead. - */ - for (;;) { - if (tp->t_state&TS_ISOPEN) { - if (pti->pt_flags&PF_PKT && pti->pt_send) { - error = ureadc((int)pti->pt_send, uio); - if (error) - return (error); - pti->pt_send = 0; - return (0); - } - if (pti->pt_flags&PF_UCNTL && pti->pt_ucntl) { - error = ureadc((int)pti->pt_ucntl, uio); - if (error) - return (error); - pti->pt_ucntl = 0; - return (0); - } - if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) - break; - } - if ((tp->t_state&TS_CARR_ON) == 0) - return (0); /* EOF */ - if (flag & IO_NDELAY) - return (EWOULDBLOCK); - sleep((caddr_t)&tp->t_outq.c_cf, TTIPRI); - } - if (pti->pt_flags & (PF_PKT|PF_UCNTL)) - error = ureadc(0, uio); - while (uio->uio_resid && error == 0) { - cc = q_to_b(&tp->t_outq, buf, MIN(uio->uio_resid, BUFSIZ)); - if (cc <= 0) - break; - error = uiomove(buf, cc, uio); - } - if (tp->t_outq.c_cc <= TTLOWAT(tp)) { - if (tp->t_state&TS_ASLEEP) { - tp->t_state &= ~TS_ASLEEP; - wakeup((caddr_t)&tp->t_outq); - } - if (tp->t_wsel) { - selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); - tp->t_wsel = 0; - tp->t_state &= ~TS_WCOLL; - } - } - return (error); + /* + * We want to block until the slave + * is open, and there's something to read; + * but if we lost the slave or we're NBIO, + * then return the appropriate error instead. + */ + for (;;) { + if (tp->t_state&TS_ISOPEN) { + if (pti->pt_flags&PF_PKT && pti->pt_send) { + error = ureadc((int)pti->pt_send, uio); + if (error) + return (error); + pti->pt_send = 0; + return (0); + } + if (pti->pt_flags&PF_UCNTL && pti->pt_ucntl) { + error = ureadc((int)pti->pt_ucntl, uio); + if (error) + return (error); + pti->pt_ucntl = 0; + return (0); + } + if (tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) + break; + } + if ((tp->t_state&TS_CARR_ON) == 0) + return (0); /* EOF */ + if (flag & IO_NDELAY) + return (EWOULDBLOCK); + sleep((caddr_t)&tp->t_outq.c_cf, TTIPRI); + } + if (pti->pt_flags & (PF_PKT|PF_UCNTL)) + error = ureadc(0, uio); + while (uio->uio_resid && error == 0) { + cc = q_to_b(&tp->t_outq, buf, MIN(uio->uio_resid, BUFSIZ)); + if (cc <= 0) + break; + error = uiomove(buf, cc, uio); + } + if (tp->t_outq.c_cc <= TTLOWAT(tp)) { + if (tp->t_state&TS_ASLEEP) { + tp->t_state &= ~TS_ASLEEP; + wakeup((caddr_t)&tp->t_outq); + } + if (tp->t_wsel) { + selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL); + tp->t_wsel = 0; + tp->t_state &= ~TS_WCOLL; + } + } + return (error); } void ptsstop(register struct tty *tp, int flush) { - struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; - int flag; + struct pt_ioctl *pti = &pt_ioctl[minor(tp->t_dev)]; + int flag; - /* note: FLUSHREAD and FLUSHWRITE already ok */ - if (flush == 0) { - flush = TIOCPKT_STOP; - pti->pt_flags |= PF_STOPPED; - } else - pti->pt_flags &= ~PF_STOPPED; - pti->pt_send |= flush; - /* change of perspective */ - flag = 0; - if (flush & FREAD) - flag |= FWRITE; - if (flush & FWRITE) - flag |= FREAD; - ptcwakeup(tp, flag); + /* note: FLUSHREAD and FLUSHWRITE already ok */ + if (flush == 0) { + flush = TIOCPKT_STOP; + pti->pt_flags |= PF_STOPPED; + } else + pti->pt_flags &= ~PF_STOPPED; + pti->pt_send |= flush; + /* change of perspective */ + flag = 0; + if (flush & FREAD) + flag |= FWRITE; + if (flush & FWRITE) + flag |= FREAD; + ptcwakeup(tp, flag); } int ptcselect(dev_t dev, int rw) { - register struct tty *tp = &pt_tty[minor(dev)]; - struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; - struct proc *p; - int s; + register struct tty *tp = &pt_tty[minor(dev)]; + struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; + struct proc *p; + int s; - if ((tp->t_state&TS_CARR_ON) == 0) - return (1); - switch (rw) { + if ((tp->t_state&TS_CARR_ON) == 0) + return (1); + switch (rw) { - case FREAD: - /* - * Need to block timeouts (ttrstart). - */ - s = spltty(); - if ((tp->t_state&TS_ISOPEN) && - tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) { - splx(s); - return (1); - } - splx(s); - /* FALLTHROUGH */ + case FREAD: + /* + * Need to block timeouts (ttrstart). + */ + s = spltty(); + if ((tp->t_state&TS_ISOPEN) && + tp->t_outq.c_cc && (tp->t_state&TS_TTSTOP) == 0) { + splx(s); + return (1); + } + splx(s); + /* FALLTHROUGH */ - case 0: /* exceptional */ - if ((tp->t_state&TS_ISOPEN) && - ((pti->pt_flags&PF_PKT && pti->pt_send) || - (pti->pt_flags&PF_UCNTL && pti->pt_ucntl))) - return (1); - if ((p = pti->pt_selr) && p->p_wchan == (caddr_t)&selwait) - pti->pt_flags |= PF_RCOLL; - else - pti->pt_selr = u.u_procp; - break; + case 0: /* exceptional */ + if ((tp->t_state&TS_ISOPEN) && + ((pti->pt_flags&PF_PKT && pti->pt_send) || + (pti->pt_flags&PF_UCNTL && pti->pt_ucntl))) + return (1); + if ((p = pti->pt_selr) && p->p_wchan == (caddr_t)&selwait) + pti->pt_flags |= PF_RCOLL; + else + pti->pt_selr = u.u_procp; + break; - case FWRITE: - if (tp->t_state&TS_ISOPEN) { - if (pti->pt_flags & PF_REMOTE) { - if (tp->t_canq.c_cc == 0) - return (1); - } else { - if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2) - return (1); - if (tp->t_canq.c_cc == 0 && - (tp->t_flags & (RAW|CBREAK)) == 0) - return (1); - } - } - if ((p = pti->pt_selw) && p->p_wchan == (caddr_t)&selwait) - pti->pt_flags |= PF_WCOLL; - else - pti->pt_selw = u.u_procp; - break; + case FWRITE: + if (tp->t_state&TS_ISOPEN) { + if (pti->pt_flags & PF_REMOTE) { + if (tp->t_canq.c_cc == 0) + return (1); + } else { + if (tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2) + return (1); + if (tp->t_canq.c_cc == 0 && + (tp->t_flags & (RAW|CBREAK)) == 0) + return (1); + } + } + if ((p = pti->pt_selw) && p->p_wchan == (caddr_t)&selwait) + pti->pt_flags |= PF_WCOLL; + else + pti->pt_selw = u.u_procp; + break; - } - return (0); + } + return (0); } int ptcwrite(dev_t dev, register struct uio *uio, int flag) { - register struct tty *tp = &pt_tty[minor(dev)]; - register char *cp = NULL; - register int cc = 0; - char locbuf[BUFSIZ]; - int cnt = 0; - struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; - int error = 0; + register struct tty *tp = &pt_tty[minor(dev)]; + register char *cp = NULL; + register int cc = 0; + char locbuf[BUFSIZ]; + int cnt = 0; + struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; + int error = 0; again: - if ((tp->t_state&TS_ISOPEN) == 0) - goto block; - if (pti->pt_flags & PF_REMOTE) { - if (tp->t_canq.c_cc) - goto block; - while (uio->uio_resid && tp->t_canq.c_cc < TTYHOG - 1) { - if (cc == 0) { - cc = MIN(uio->uio_resid, BUFSIZ); - cc = MIN(cc, TTYHOG - 1 - tp->t_canq.c_cc); - cp = locbuf; - error = uiomove(cp, cc, uio); - if (error) - return (error); - /* check again for safety */ - if ((tp->t_state&TS_ISOPEN) == 0) - return (EIO); - } - if (cc) - (void) b_to_q(cp, cc, &tp->t_canq); - cc = 0; - } - (void) putc(0, &tp->t_canq); - ttwakeup(tp); - wakeup((caddr_t)&tp->t_canq); - return (0); - } - while (uio->uio_resid > 0) { - if (cc == 0) { - cc = MIN(uio->uio_resid, BUFSIZ); - cp = locbuf; - error = uiomove(cp, cc, uio); - if (error) - return (error); - /* check again for safety */ - if ((tp->t_state&TS_ISOPEN) == 0) - return (EIO); - } - while (cc > 0) { - if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && - (tp->t_canq.c_cc > 0 || - tp->t_flags & (RAW|CBREAK))) { - wakeup((caddr_t)&tp->t_rawq); - goto block; - } - ttyinput(*cp++, tp); - cnt++; - cc--; - } - cc = 0; - } - return (0); + if ((tp->t_state&TS_ISOPEN) == 0) + goto block; + if (pti->pt_flags & PF_REMOTE) { + if (tp->t_canq.c_cc) + goto block; + while (uio->uio_resid && tp->t_canq.c_cc < TTYHOG - 1) { + if (cc == 0) { + cc = MIN(uio->uio_resid, BUFSIZ); + cc = MIN(cc, TTYHOG - 1 - tp->t_canq.c_cc); + cp = locbuf; + error = uiomove(cp, cc, uio); + if (error) + return (error); + /* check again for safety */ + if ((tp->t_state&TS_ISOPEN) == 0) + return (EIO); + } + if (cc) + (void) b_to_q(cp, cc, &tp->t_canq); + cc = 0; + } + (void) putc(0, &tp->t_canq); + ttwakeup(tp); + wakeup((caddr_t)&tp->t_canq); + return (0); + } + while (uio->uio_resid > 0) { + if (cc == 0) { + cc = MIN(uio->uio_resid, BUFSIZ); + cp = locbuf; + error = uiomove(cp, cc, uio); + if (error) + return (error); + /* check again for safety */ + if ((tp->t_state&TS_ISOPEN) == 0) + return (EIO); + } + while (cc > 0) { + if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && + (tp->t_canq.c_cc > 0 || + tp->t_flags & (RAW|CBREAK))) { + wakeup((caddr_t)&tp->t_rawq); + goto block; + } + ttyinput(*cp++, tp); + cnt++; + cc--; + } + cc = 0; + } + return (0); block: - /* - * Come here to wait for slave to open, for space - * in outq, or space in rawq. - */ - if ((tp->t_state&TS_CARR_ON) == 0) - return (EIO); - if (flag & IO_NDELAY) { - /* adjust for data copied in but not written */ - uio->uio_resid += cc; - if (cnt == 0) - return (EWOULDBLOCK); - return (0); - } - sleep((caddr_t)&tp->t_rawq.c_cf, TTOPRI); - goto again; + /* + * Come here to wait for slave to open, for space + * in outq, or space in rawq. + */ + if ((tp->t_state&TS_CARR_ON) == 0) + return (EIO); + if (flag & IO_NDELAY) { + /* adjust for data copied in but not written */ + uio->uio_resid += cc; + if (cnt == 0) + return (EWOULDBLOCK); + return (0); + } + sleep((caddr_t)&tp->t_rawq.c_cf, TTOPRI); + goto again; } int ptyioctl(dev_t dev, u_int cmd, caddr_t data, int flag) { - register struct tty *tp = &pt_tty[minor(dev)]; - register struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; - int stop, error; + register struct tty *tp = &pt_tty[minor(dev)]; + register struct pt_ioctl *pti = &pt_ioctl[minor(dev)]; + int stop, error; - /* - * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG. - * ttywflush(tp) will hang if there are characters in the outq. - */ - if (cdevsw[major(dev)].d_open == ptcopen) - switch (cmd) { + /* + * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG. + * ttywflush(tp) will hang if there are characters in the outq. + */ + if (cdevsw[major(dev)].d_open == ptcopen) + switch (cmd) { - case TIOCPKT: - if (*(int *)data) { - if (pti->pt_flags & PF_UCNTL) - return (EINVAL); - pti->pt_flags |= PF_PKT; - } else - pti->pt_flags &= ~PF_PKT; - return (0); + case TIOCPKT: + if (*(int *)data) { + if (pti->pt_flags & PF_UCNTL) + return (EINVAL); + pti->pt_flags |= PF_PKT; + } else + pti->pt_flags &= ~PF_PKT; + return (0); - case TIOCUCNTL: - if (*(int *)data) { - if (pti->pt_flags & PF_PKT) - return (EINVAL); - pti->pt_flags |= PF_UCNTL; - } else - pti->pt_flags &= ~PF_UCNTL; - return (0); + case TIOCUCNTL: + if (*(int *)data) { + if (pti->pt_flags & PF_PKT) + return (EINVAL); + pti->pt_flags |= PF_UCNTL; + } else + pti->pt_flags &= ~PF_UCNTL; + return (0); - case TIOCREMOTE: - if (*(int *)data) - pti->pt_flags |= PF_REMOTE; - else - pti->pt_flags &= ~PF_REMOTE; - ttyflush(tp, FREAD|FWRITE); - return (0); + case TIOCREMOTE: + if (*(int *)data) + pti->pt_flags |= PF_REMOTE; + else + pti->pt_flags &= ~PF_REMOTE; + ttyflush(tp, FREAD|FWRITE); + return (0); - case TIOCSETP: - case TIOCSETN: - case TIOCSETD: - while (getc(&tp->t_outq) >= 0) - ; - break; - } - error = ttioctl (tp, cmd, data, flag); - if (error < 0) { - if (pti->pt_flags & PF_UCNTL && - (cmd & ~0xff) == UIOCCMD(0)) { - if (cmd & 0xff) { - pti->pt_ucntl = (u_char)cmd; - ptcwakeup(tp, FREAD); - } - return (0); - } - error = ENOTTY; - } - stop = (tp->t_flags & RAW) == 0 && - tp->t_stopc == CTRL('s') && tp->t_startc == CTRL('q'); - if (pti->pt_flags & PF_NOSTOP) { - if (stop) { - pti->pt_send &= ~TIOCPKT_NOSTOP; - pti->pt_send |= TIOCPKT_DOSTOP; - pti->pt_flags &= ~PF_NOSTOP; - ptcwakeup(tp, FREAD); - } - } else { - if (!stop) { - pti->pt_send &= ~TIOCPKT_DOSTOP; - pti->pt_send |= TIOCPKT_NOSTOP; - pti->pt_flags |= PF_NOSTOP; - ptcwakeup(tp, FREAD); - } - } - return (error); + case TIOCSETP: + case TIOCSETN: + case TIOCSETD: + while (getc(&tp->t_outq) >= 0) + ; + break; + } + error = ttioctl (tp, cmd, data, flag); + if (error < 0) { + if (pti->pt_flags & PF_UCNTL && + (cmd & ~0xff) == UIOCCMD(0)) { + if (cmd & 0xff) { + pti->pt_ucntl = (u_char)cmd; + ptcwakeup(tp, FREAD); + } + return (0); + } + error = ENOTTY; + } + stop = (tp->t_flags & RAW) == 0 && + tp->t_stopc == CTRL('s') && tp->t_startc == CTRL('q'); + if (pti->pt_flags & PF_NOSTOP) { + if (stop) { + pti->pt_send &= ~TIOCPKT_NOSTOP; + pti->pt_send |= TIOCPKT_DOSTOP; + pti->pt_flags &= ~PF_NOSTOP; + ptcwakeup(tp, FREAD); + } + } else { + if (!stop) { + pti->pt_send &= ~TIOCPKT_DOSTOP; + pti->pt_send |= TIOCPKT_NOSTOP; + pti->pt_flags |= PF_NOSTOP; + ptcwakeup(tp, FREAD); + } + } + return (error); } #endif diff --git a/sys/kernel/tty_subr.c b/sys/kernel/tty_subr.c index 4344544..9d3d4ea 100644 --- a/sys/kernel/tty_subr.c +++ b/sys/kernel/tty_subr.c @@ -9,52 +9,52 @@ #include "tty.h" #include "systm.h" -char cwaiting; +char cwaiting; /* * Character list get/put */ int getc(p) - register struct clist *p; + register struct clist *p; { - register struct cblock *bp; - register int c, s; + register struct cblock *bp; + register int c, s; - s = spltty(); - if (p->c_cc <= 0) { - c = -1; - p->c_cc = 0; - p->c_cf = p->c_cl = NULL; - } else { - c = *p->c_cf++ & 0377; - if (--p->c_cc<=0) { - bp = (struct cblock *)(p->c_cf-1); - bp = (struct cblock *)((int)bp & ~CROUND); - p->c_cf = NULL; - p->c_cl = NULL; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - if (cwaiting) { - wakeup (&cwaiting); - cwaiting = 0; - } - } else if (((int)p->c_cf & CROUND) == 0){ - bp = (struct cblock *)(p->c_cf); - bp--; - p->c_cf = bp->c_next->c_info; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - if (cwaiting) { - wakeup (&cwaiting); - cwaiting = 0; - } - } - } - splx(s); - return (c); + s = spltty(); + if (p->c_cc <= 0) { + c = -1; + p->c_cc = 0; + p->c_cf = p->c_cl = NULL; + } else { + c = *p->c_cf++ & 0377; + if (--p->c_cc<=0) { + bp = (struct cblock *)(p->c_cf-1); + bp = (struct cblock *)((int)bp & ~CROUND); + p->c_cf = NULL; + p->c_cl = NULL; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup (&cwaiting); + cwaiting = 0; + } + } else if (((int)p->c_cf & CROUND) == 0){ + bp = (struct cblock *)(p->c_cf); + bp--; + p->c_cf = bp->c_next->c_info; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup (&cwaiting); + cwaiting = 0; + } + } + } + splx(s); + return (c); } /* @@ -63,62 +63,62 @@ getc(p) */ int q_to_b (q, cp, cc) - register struct clist *q; - char *cp; + register struct clist *q; + char *cp; { - register struct cblock *bp; - register int nc; - int s; - char *acp; + register struct cblock *bp; + register int nc; + int s; + char *acp; - if (cc <= 0) - return (0); - s = spltty(); - if (q->c_cc <= 0) { - q->c_cc = 0; - q->c_cf = q->c_cl = NULL; - splx(s); - return (0); - } - acp = cp; + if (cc <= 0) + return (0); + s = spltty(); + if (q->c_cc <= 0) { + q->c_cc = 0; + q->c_cf = q->c_cl = NULL; + splx(s); + return (0); + } + acp = cp; - while (cc) { - nc = sizeof (struct cblock) - ((int)q->c_cf & CROUND); - nc = MIN(nc, cc); - nc = MIN(nc, q->c_cc); - (void) bcopy(q->c_cf, cp, (unsigned)nc); - q->c_cf += nc; - q->c_cc -= nc; - cc -= nc; - cp += nc; - if (q->c_cc <= 0) { - bp = (struct cblock *)(q->c_cf - 1); - bp = (struct cblock *)((int)bp & ~CROUND); - q->c_cf = q->c_cl = NULL; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - if (cwaiting) { - wakeup (&cwaiting); - cwaiting = 0; - } - break; - } - if (((int)q->c_cf & CROUND) == 0) { - bp = (struct cblock *)(q->c_cf); - bp--; - q->c_cf = bp->c_next->c_info; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - if (cwaiting) { - wakeup (&cwaiting); - cwaiting = 0; - } - } - } - splx(s); - return (cp - acp); + while (cc) { + nc = sizeof (struct cblock) - ((int)q->c_cf & CROUND); + nc = MIN(nc, cc); + nc = MIN(nc, q->c_cc); + (void) bcopy(q->c_cf, cp, (unsigned)nc); + q->c_cf += nc; + q->c_cc -= nc; + cc -= nc; + cp += nc; + if (q->c_cc <= 0) { + bp = (struct cblock *)(q->c_cf - 1); + bp = (struct cblock *)((int)bp & ~CROUND); + q->c_cf = q->c_cl = NULL; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup (&cwaiting); + cwaiting = 0; + } + break; + } + if (((int)q->c_cf & CROUND) == 0) { + bp = (struct cblock *)(q->c_cf); + bp--; + q->c_cf = bp->c_next->c_info; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup (&cwaiting); + cwaiting = 0; + } + } + } + splx(s); + return (cp - acp); } /* @@ -127,38 +127,38 @@ q_to_b (q, cp, cc) * Stop counting if flag&character is non-null. */ int ndqb (q, flag) - register struct clist *q; + register struct clist *q; { - int cc; - int s; + int cc; + int s; - s = spltty(); - if (q->c_cc <= 0) { - cc = -q->c_cc; - goto out; - } - cc = ((int)q->c_cf + CBSIZE) & ~CROUND; - cc -= (int)q->c_cf; - if (q->c_cc < cc) - cc = q->c_cc; - if (flag) { - register char *p, *end; + s = spltty(); + if (q->c_cc <= 0) { + cc = -q->c_cc; + goto out; + } + cc = ((int)q->c_cf + CBSIZE) & ~CROUND; + cc -= (int)q->c_cf; + if (q->c_cc < cc) + cc = q->c_cc; + if (flag) { + register char *p, *end; - p = q->c_cf; - end = p; - end += cc; - while (p < end) { - if (*p & flag) { - cc = (int)p; - cc -= (int)q->c_cf; - break; - } - p++; - } - } + p = q->c_cf; + end = p; + end += cc; + while (p < end) { + if (*p & flag) { + cc = (int)p; + cc -= (int)q->c_cf; + break; + } + p++; + } + } out: - splx(s); - return (cc); + splx(s); + return (cc); } /* @@ -166,56 +166,56 @@ out: */ void ndflush (q, cc) - register struct clist *q; - register int cc; + register struct clist *q; + register int cc; { - register struct cblock *bp; - char *end; - int rem, s; + register struct cblock *bp; + char *end; + int rem, s; - s = spltty(); - if (q->c_cc <= 0) - goto out; - while (cc>0 && q->c_cc) { - bp = (struct cblock *)((int)q->c_cf & ~CROUND); - if ((int)bp == (((int)q->c_cl-1) & ~CROUND)) { - end = q->c_cl; - } else { - end = (char *)((int)bp + sizeof (struct cblock)); - } - rem = end - q->c_cf; - if (cc >= rem) { - cc -= rem; - q->c_cc -= rem; - q->c_cf = bp->c_next->c_info; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - if (cwaiting) { - wakeup (&cwaiting); - cwaiting = 0; - } - } else { - q->c_cc -= cc; - q->c_cf += cc; - if (q->c_cc <= 0) { - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - if (cwaiting) { - wakeup (&cwaiting); - cwaiting = 0; - } - } - break; - } - } - if (q->c_cc <= 0) { - q->c_cf = q->c_cl = NULL; - q->c_cc = 0; - } + s = spltty(); + if (q->c_cc <= 0) + goto out; + while (cc>0 && q->c_cc) { + bp = (struct cblock *)((int)q->c_cf & ~CROUND); + if ((int)bp == (((int)q->c_cl-1) & ~CROUND)) { + end = q->c_cl; + } else { + end = (char *)((int)bp + sizeof (struct cblock)); + } + rem = end - q->c_cf; + if (cc >= rem) { + cc -= rem; + q->c_cc -= rem; + q->c_cf = bp->c_next->c_info; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup (&cwaiting); + cwaiting = 0; + } + } else { + q->c_cc -= cc; + q->c_cf += cc; + if (q->c_cc <= 0) { + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + if (cwaiting) { + wakeup (&cwaiting); + cwaiting = 0; + } + } + break; + } + } + if (q->c_cc <= 0) { + q->c_cf = q->c_cl = NULL; + q->c_cc = 0; + } out: - splx(s); + splx(s); } /* @@ -223,39 +223,39 @@ out: */ int putc (c, p) - register struct clist *p; + register struct clist *p; { - register struct cblock *bp; - register char *cp; - register int s; + register struct cblock *bp; + register char *cp; + register int s; - s = spltty(); - if ((cp = p->c_cl) == NULL || p->c_cc < 0 ) { - if ((bp = cfreelist) == NULL) { - splx(s); - return (-1); - } - cfreelist = bp->c_next; - cfreecount -= CBSIZE; - bp->c_next = NULL; - p->c_cf = cp = bp->c_info; - } else if (((int)cp & CROUND) == 0) { - bp = (struct cblock *)cp - 1; - if ((bp->c_next = cfreelist) == NULL) { - splx(s); - return (-1); - } - bp = bp->c_next; - cfreelist = bp->c_next; - cfreecount -= CBSIZE; - bp->c_next = NULL; - cp = bp->c_info; - } - *cp++ = c; - p->c_cc++; - p->c_cl = cp; - splx(s); - return (0); + s = spltty(); + if ((cp = p->c_cl) == NULL || p->c_cc < 0 ) { + if ((bp = cfreelist) == NULL) { + splx(s); + return (-1); + } + cfreelist = bp->c_next; + cfreecount -= CBSIZE; + bp->c_next = NULL; + p->c_cf = cp = bp->c_info; + } else if (((int)cp & CROUND) == 0) { + bp = (struct cblock *)cp - 1; + if ((bp->c_next = cfreelist) == NULL) { + splx(s); + return (-1); + } + bp = bp->c_next; + cfreelist = bp->c_next; + cfreecount -= CBSIZE; + bp->c_next = NULL; + cp = bp->c_info; + } + *cp++ = c; + p->c_cc++; + p->c_cl = cp; + splx(s); + return (0); } /* @@ -264,50 +264,50 @@ putc (c, p) */ int b_to_q (cp, cc, q) - register char *cp; - struct clist *q; - register int cc; + register char *cp; + struct clist *q; + register int cc; { - register char *cq; - register struct cblock *bp; - register int s, nc; - int acc; + register char *cq; + register struct cblock *bp; + register int s, nc; + int acc; - if (cc <= 0) - return (0); - acc = cc; - s = spltty(); - if ((cq = q->c_cl) == NULL || q->c_cc < 0) { - if ((bp = cfreelist) == NULL) - goto out; - cfreelist = bp->c_next; - cfreecount -= CBSIZE; - bp->c_next = NULL; - q->c_cf = cq = bp->c_info; - } + if (cc <= 0) + return (0); + acc = cc; + s = spltty(); + if ((cq = q->c_cl) == NULL || q->c_cc < 0) { + if ((bp = cfreelist) == NULL) + goto out; + cfreelist = bp->c_next; + cfreecount -= CBSIZE; + bp->c_next = NULL; + q->c_cf = cq = bp->c_info; + } - while (cc) { - if (((int)cq & CROUND) == 0) { - bp = (struct cblock *)cq - 1; - if ((bp->c_next = cfreelist) == NULL) - goto out; - bp = bp->c_next; - cfreelist = bp->c_next; - cfreecount -= CBSIZE; - bp->c_next = NULL; - cq = bp->c_info; - } - nc = MIN(cc, sizeof (struct cblock) - ((int)cq & CROUND)); - (void) bcopy(cp, cq, (unsigned)nc); - cp += nc; - cq += nc; - cc -= nc; - } + while (cc) { + if (((int)cq & CROUND) == 0) { + bp = (struct cblock *)cq - 1; + if ((bp->c_next = cfreelist) == NULL) + goto out; + bp = bp->c_next; + cfreelist = bp->c_next; + cfreecount -= CBSIZE; + bp->c_next = NULL; + cq = bp->c_info; + } + nc = MIN(cc, sizeof (struct cblock) - ((int)cq & CROUND)); + (void) bcopy(cp, cq, (unsigned)nc); + cp += nc; + cq += nc; + cc -= nc; + } out: - q->c_cl = cq; - q->c_cc += acc - cc; - splx(s); - return (cc); + q->c_cl = cq; + q->c_cc += acc - cc; + splx(s); + return (cc); } /* @@ -320,19 +320,19 @@ out: */ char * nextc (p, cp) - register struct clist *p; - register char *cp; + register struct clist *p; + register char *cp; { - register char *rcp; + register char *rcp; - if (p->c_cc && ++cp != p->c_cl) { - if (((int)cp & CROUND) == 0) - rcp = ((struct cblock *)cp)[-1].c_next->c_info; - else - rcp = cp; - } else - rcp = (char *)NULL; - return (rcp); + if (p->c_cc && ++cp != p->c_cl) { + if (((int)cp & CROUND) == 0) + rcp = ((struct cblock *)cp)[-1].c_next->c_info; + else + rcp = cp; + } else + rcp = (char *)NULL; + return (rcp); } /* @@ -340,41 +340,41 @@ nextc (p, cp) */ int unputc (p) - register struct clist *p; + register struct clist *p; { - register struct cblock *bp; - register int c, s; - struct cblock *obp; + register struct cblock *bp; + register int c, s; + struct cblock *obp; - s = spltty(); - if (p->c_cc <= 0) - c = -1; - else { - c = *--p->c_cl; - if (--p->c_cc <= 0) { - bp = (struct cblock *)p->c_cl; - bp = (struct cblock *)((int)bp & ~CROUND); - p->c_cl = p->c_cf = NULL; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - } else if (((int)p->c_cl & CROUND) == sizeof(bp->c_next)) { - p->c_cl = (char *)((int)p->c_cl & ~CROUND); - bp = (struct cblock *)p->c_cf; - bp = (struct cblock *)((int)bp & ~CROUND); - while (bp->c_next != (struct cblock *)p->c_cl) - bp = bp->c_next; - obp = bp; - p->c_cl = (char *)(bp + 1); - bp = bp->c_next; - bp->c_next = cfreelist; - cfreelist = bp; - cfreecount += CBSIZE; - obp->c_next = NULL; - } - } - splx(s); - return (c); + s = spltty(); + if (p->c_cc <= 0) + c = -1; + else { + c = *--p->c_cl; + if (--p->c_cc <= 0) { + bp = (struct cblock *)p->c_cl; + bp = (struct cblock *)((int)bp & ~CROUND); + p->c_cl = p->c_cf = NULL; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + } else if (((int)p->c_cl & CROUND) == sizeof(bp->c_next)) { + p->c_cl = (char *)((int)p->c_cl & ~CROUND); + bp = (struct cblock *)p->c_cf; + bp = (struct cblock *)((int)bp & ~CROUND); + while (bp->c_next != (struct cblock *)p->c_cl) + bp = bp->c_next; + obp = bp; + p->c_cl = (char *)(bp + 1); + bp = bp->c_next; + bp->c_next = cfreelist; + cfreelist = bp; + cfreecount += CBSIZE; + obp->c_next = NULL; + } + } + splx(s); + return (c); } /* @@ -383,24 +383,24 @@ unputc (p) */ void catq (from, to) - register struct clist *from, *to; + register struct clist *from, *to; { - char bbuf [CBSIZE*4]; - register int c; - int s; + char bbuf [CBSIZE*4]; + register int c; + int s; - s = spltty(); - if (to->c_cc == 0) { - *to = *from; - from->c_cc = 0; - from->c_cf = NULL; - from->c_cl = NULL; - splx(s); - return; - } - splx(s); - while (from->c_cc > 0) { - c = q_to_b(from, bbuf, sizeof bbuf); - (void) b_to_q(bbuf, c, to); - } + s = spltty(); + if (to->c_cc == 0) { + *to = *from; + from->c_cc = 0; + from->c_cf = NULL; + from->c_cl = NULL; + splx(s); + return; + } + splx(s); + while (from->c_cc > 0) { + c = q_to_b(from, bbuf, sizeof bbuf); + (void) b_to_q(bbuf, c, to); + } } diff --git a/sys/kernel/tty_tty.c b/sys/kernel/tty_tty.c index 9951ac2..8a63d5d 100644 --- a/sys/kernel/tty_tty.c +++ b/sys/kernel/tty_tty.c @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)tty_tty.c 1.2 (2.11BSD GTE) 11/29/94 + * @(#)tty_tty.c 1.2 (2.11BSD GTE) 11/29/94 */ /* @@ -25,66 +25,66 @@ const struct devspec sydevs[] = { /*ARGSUSED*/ int syopen (dev, flag) - dev_t dev; - int flag; + dev_t dev; + int flag; { - if (u.u_ttyp == NULL) - return (ENXIO); - return((*cdevsw[major(u.u_ttyd)].d_open)(u.u_ttyd, flag, 0)); + if (u.u_ttyp == NULL) + return (ENXIO); + return((*cdevsw[major(u.u_ttyd)].d_open)(u.u_ttyd, flag, 0)); } /*ARGSUSED*/ int syread (dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; + dev_t dev; + struct uio *uio; + int flag; { - if (u.u_ttyp == NULL) - return (ENXIO); - return ((*cdevsw[major(u.u_ttyd)].d_read)(u.u_ttyd, uio, flag)); + if (u.u_ttyp == NULL) + return (ENXIO); + return ((*cdevsw[major(u.u_ttyd)].d_read)(u.u_ttyd, uio, flag)); } /*ARGSUSED*/ int sywrite (dev, uio, flag) - dev_t dev; - struct uio *uio; + dev_t dev; + struct uio *uio; { - if (u.u_ttyp == NULL) - return (ENXIO); - return ((*cdevsw[major(u.u_ttyd)].d_write)(u.u_ttyd, uio, flag)); + if (u.u_ttyp == NULL) + return (ENXIO); + return ((*cdevsw[major(u.u_ttyd)].d_write)(u.u_ttyd, uio, flag)); } /*ARGSUSED*/ int syioctl (dev, cmd, addr, flag) - dev_t dev; - u_int cmd; - caddr_t addr; - int flag; + dev_t dev; + u_int cmd; + caddr_t addr; + int flag; { - if (cmd == TIOCNOTTY) { - u.u_ttyp = 0; - u.u_ttyd = 0; - u.u_procp->p_pgrp = 0; - return (0); - } - if (u.u_ttyp == NULL) - return (ENXIO); - return ((*cdevsw[major(u.u_ttyd)].d_ioctl)(u.u_ttyd, cmd, addr, flag)); + if (cmd == TIOCNOTTY) { + u.u_ttyp = 0; + u.u_ttyd = 0; + u.u_procp->p_pgrp = 0; + return (0); + } + if (u.u_ttyp == NULL) + return (ENXIO); + return ((*cdevsw[major(u.u_ttyd)].d_ioctl)(u.u_ttyd, cmd, addr, flag)); } /*ARGSUSED*/ int syselect (dev, flag) - dev_t dev; - int flag; + dev_t dev; + int flag; { - if (u.u_ttyp == NULL) { - u.u_error = ENXIO; - return (0); - } - return ((*cdevsw[major(u.u_ttyd)].d_select)(u.u_ttyd, flag)); + if (u.u_ttyp == NULL) { + u.u_error = ENXIO; + return (0); + } + return ((*cdevsw[major(u.u_ttyd)].d_select)(u.u_ttyd, flag)); } diff --git a/sys/kernel/ufs_alloc.c b/sys/kernel/ufs_alloc.c index 439d9c3..2d78f67 100644 --- a/sys/kernel/ufs_alloc.c +++ b/sys/kernel/ufs_alloc.c @@ -14,7 +14,7 @@ #include "proc.h" #include "systm.h" -typedef struct fblk *FBLKP; +typedef struct fblk *FBLKP; /* * Allocate a block in the file system. @@ -26,91 +26,91 @@ typedef struct fblk *FBLKP; */ struct buf * balloc(ip, flags) - struct inode *ip; - int flags; + struct inode *ip; + int flags; { - register struct fs *fs; - register struct buf *bp; - int async; - daddr_t bno; + register struct fs *fs; + register struct buf *bp; + int async; + daddr_t bno; - fs = ip->i_fs; - async = fs->fs_flags & MNT_ASYNC; + fs = ip->i_fs; + async = fs->fs_flags & MNT_ASYNC; - while (fs->fs_flock) - sleep((caddr_t)&fs->fs_flock, PINOD); - do { - if (fs->fs_nfree <= 0) - goto nospace; - if (fs->fs_nfree > NICFREE) { - fserr (fs, "bad free count"); - goto nospace; - } - bno = fs->fs_free[--fs->fs_nfree]; - if (bno == 0) - goto nospace; - } while (badblock(fs, bno)); - if (fs->fs_nfree <= 0) { - fs->fs_flock++; - bp = bread(ip->i_dev, bno); - if (((bp->b_flags&B_ERROR) == 0) && (bp->b_resid==0)) { - register struct fblk *fbp; + while (fs->fs_flock) + sleep((caddr_t)&fs->fs_flock, PINOD); + do { + if (fs->fs_nfree <= 0) + goto nospace; + if (fs->fs_nfree > NICFREE) { + fserr (fs, "bad free count"); + goto nospace; + } + bno = fs->fs_free[--fs->fs_nfree]; + if (bno == 0) + goto nospace; + } while (badblock(fs, bno)); + if (fs->fs_nfree <= 0) { + fs->fs_flock++; + bp = bread(ip->i_dev, bno); + if (((bp->b_flags&B_ERROR) == 0) && (bp->b_resid==0)) { + register struct fblk *fbp; - fbp = (FBLKP) bp->b_addr; - *((FBLKP)&fs->fs_nfree) = *fbp; - } - brelse(bp); - /* - * Write the superblock back, synchronously if requested, - * so that the free list pointer won't point at garbage. - * We can still end up with dups in free if we then - * use some of the blocks in this freeblock, then crash - * without a sync. - */ - bp = getblk(ip->i_dev, SUPERB); - fs->fs_fmod = 0; - fs->fs_time = time.tv_sec; - { - register struct fs *fps; + fbp = (FBLKP) bp->b_addr; + *((FBLKP)&fs->fs_nfree) = *fbp; + } + brelse(bp); + /* + * Write the superblock back, synchronously if requested, + * so that the free list pointer won't point at garbage. + * We can still end up with dups in free if we then + * use some of the blocks in this freeblock, then crash + * without a sync. + */ + bp = getblk(ip->i_dev, SUPERB); + fs->fs_fmod = 0; + fs->fs_time = time.tv_sec; + { + register struct fs *fps; - fps = (struct fs*) bp->b_addr; - *fps = *fs; - } - if (!async) - bwrite(bp); - else - bdwrite(bp); - fs->fs_flock = 0; - wakeup((caddr_t)&fs->fs_flock); - if (fs->fs_nfree <=0) - goto nospace; - } - bp = getblk(ip->i_dev, bno); - bp->b_resid = 0; - if (flags & B_CLRBUF) - bzero (bp->b_addr, MAXBSIZE); - fs->fs_fmod = 1; - fs->fs_tfree--; - return(bp); + fps = (struct fs*) bp->b_addr; + *fps = *fs; + } + if (!async) + bwrite(bp); + else + bdwrite(bp); + fs->fs_flock = 0; + wakeup((caddr_t)&fs->fs_flock); + if (fs->fs_nfree <=0) + goto nospace; + } + bp = getblk(ip->i_dev, bno); + bp->b_resid = 0; + if (flags & B_CLRBUF) + bzero (bp->b_addr, MAXBSIZE); + fs->fs_fmod = 1; + fs->fs_tfree--; + return(bp); nospace: - fs->fs_nfree = 0; - fs->fs_tfree = 0; - fserr (fs, "file system full"); - /* - * THIS IS A KLUDGE... - * SHOULD RATHER SEND A SIGNAL AND SUSPEND THE PROCESS IN A - * STATE FROM WHICH THE SYSTEM CALL WILL RESTART - */ - uprintf("\n%s: write failed, file system full\n", fs->fs_fsmnt); - { - register int i; + fs->fs_nfree = 0; + fs->fs_tfree = 0; + fserr (fs, "file system full"); + /* + * THIS IS A KLUDGE... + * SHOULD RATHER SEND A SIGNAL AND SUSPEND THE PROCESS IN A + * STATE FROM WHICH THE SYSTEM CALL WILL RESTART + */ + uprintf("\n%s: write failed, file system full\n", fs->fs_fsmnt); + { + register int i; - for (i = 0; i < 5; i++) - sleep((caddr_t)&lbolt, PRIBIO); - } - u.u_error = ENOSPC; - return(NULL); + for (i = 0; i < 5; i++) + sleep((caddr_t)&lbolt, PRIBIO); + } + u.u_error = ENOSPC; + return(NULL); } /* @@ -123,98 +123,98 @@ nospace: */ struct inode * ialloc (pip) - struct inode *pip; + struct inode *pip; { - register struct fs *fs; - register struct buf *bp; - register struct inode *ip; - int i; - struct dinode *dp; - ino_t ino; - daddr_t adr; - ino_t inobas; - int first; - struct inode *ifind(); - char *emsg = "no inodes free"; + register struct fs *fs; + register struct buf *bp; + register struct inode *ip; + int i; + struct dinode *dp; + ino_t ino; + daddr_t adr; + ino_t inobas; + int first; + struct inode *ifind(); + char *emsg = "no inodes free"; - fs = pip->i_fs; - while (fs->fs_ilock) - sleep((caddr_t)&fs->fs_ilock, PINOD); + fs = pip->i_fs; + while (fs->fs_ilock) + sleep((caddr_t)&fs->fs_ilock, PINOD); loop: - if (fs->fs_ninode > 0) { - ino = fs->fs_inode[--fs->fs_ninode]; - if (ino <= ROOTINO) - goto loop; - ip = iget(pip->i_dev, fs, ino); - if (ip == NULL) - return(NULL); - if (ip->i_mode == 0) { - bzero((caddr_t)ip->i_addr,sizeof(ip->i_addr)); - ip->i_flags = 0; - fs->fs_fmod = 1; - fs->fs_tinode--; - return(ip); - } - /* - * Inode was allocated after all. - * Look some more. - */ - iput(ip); - goto loop; - } - fs->fs_ilock++; - if (fs->fs_nbehind < 4 * NICINOD) { - first = 1; - ino = fs->fs_lasti; + if (fs->fs_ninode > 0) { + ino = fs->fs_inode[--fs->fs_ninode]; + if (ino <= ROOTINO) + goto loop; + ip = iget(pip->i_dev, fs, ino); + if (ip == NULL) + return(NULL); + if (ip->i_mode == 0) { + bzero((caddr_t)ip->i_addr,sizeof(ip->i_addr)); + ip->i_flags = 0; + fs->fs_fmod = 1; + fs->fs_tinode--; + return(ip); + } + /* + * Inode was allocated after all. + * Look some more. + */ + iput(ip); + goto loop; + } + fs->fs_ilock++; + if (fs->fs_nbehind < 4 * NICINOD) { + first = 1; + ino = fs->fs_lasti; #ifdef DIAGNOSTIC - if (itoo(ino)) - panic("ialloc"); + if (itoo(ino)) + panic("ialloc"); #endif - adr = itod(ino); - } else { + adr = itod(ino); + } else { fromtop: - first = 0; - ino = 1; - adr = SUPERB+1; - fs->fs_nbehind = 0; - } - inobas = 0; - for (; adr < fs->fs_isize; adr++) { - inobas = ino; - bp = bread(pip->i_dev, adr); - if ((bp->b_flags & B_ERROR) || bp->b_resid) { - brelse(bp); - ino += INOPB; - continue; - } - dp = (struct dinode*) bp->b_addr; - for (i = 0;i < INOPB;i++) { - if (dp->di_mode != 0) - goto cont; - if (ifind(pip->i_dev, ino)) - goto cont; - fs->fs_inode[fs->fs_ninode++] = ino; - if (fs->fs_ninode >= NICINOD) - break; - cont: - ino++; - dp++; - } - brelse(bp); - if (fs->fs_ninode >= NICINOD) - break; - } - if (fs->fs_ninode < NICINOD && first) - goto fromtop; - fs->fs_lasti = inobas; - fs->fs_ilock = 0; - wakeup((caddr_t)&fs->fs_ilock); - if (fs->fs_ninode > 0) - goto loop; - fserr (fs, emsg); - uprintf("\n%s: %s\n", fs->fs_fsmnt, emsg); - u.u_error = ENOSPC; - return(NULL); + first = 0; + ino = 1; + adr = SUPERB+1; + fs->fs_nbehind = 0; + } + inobas = 0; + for (; adr < fs->fs_isize; adr++) { + inobas = ino; + bp = bread(pip->i_dev, adr); + if ((bp->b_flags & B_ERROR) || bp->b_resid) { + brelse(bp); + ino += INOPB; + continue; + } + dp = (struct dinode*) bp->b_addr; + for (i = 0;i < INOPB;i++) { + if (dp->di_mode != 0) + goto cont; + if (ifind(pip->i_dev, ino)) + goto cont; + fs->fs_inode[fs->fs_ninode++] = ino; + if (fs->fs_ninode >= NICINOD) + break; + cont: + ino++; + dp++; + } + brelse(bp); + if (fs->fs_ninode >= NICINOD) + break; + } + if (fs->fs_ninode < NICINOD && first) + goto fromtop; + fs->fs_lasti = inobas; + fs->fs_ilock = 0; + wakeup((caddr_t)&fs->fs_ilock); + if (fs->fs_ninode > 0) + goto loop; + fserr (fs, emsg); + uprintf("\n%s: %s\n", fs->fs_fsmnt, emsg); + u.u_error = ENOSPC; + return(NULL); } /* @@ -225,40 +225,40 @@ fromtop: */ void free (ip, bno) - struct inode *ip; - daddr_t bno; + struct inode *ip; + daddr_t bno; { - register struct fs *fs; - register struct buf *bp; - struct fblk *fbp; + register struct fs *fs; + register struct buf *bp; + struct fblk *fbp; - fs = ip->i_fs; - if (badblock (fs, bno)) { - printf("bad block %D, ino %d\n", bno, ip->i_number); - return; - } - while (fs->fs_flock) - sleep((caddr_t)&fs->fs_flock, PINOD); - if (fs->fs_nfree <= 0) { - fs->fs_nfree = 1; - fs->fs_free[0] = 0; - } - if (fs->fs_nfree >= NICFREE) { - fs->fs_flock++; - bp = getblk(ip->i_dev, bno); - fbp = (FBLKP) bp->b_addr; - *fbp = *((FBLKP)&fs->fs_nfree); - fs->fs_nfree = 0; - if (fs->fs_flags & MNT_ASYNC) - bdwrite(bp); - else - bwrite(bp); - fs->fs_flock = 0; - wakeup((caddr_t)&fs->fs_flock); - } - fs->fs_free[fs->fs_nfree++] = bno; - fs->fs_tfree++; - fs->fs_fmod = 1; + fs = ip->i_fs; + if (badblock (fs, bno)) { + printf("bad block %D, ino %d\n", bno, ip->i_number); + return; + } + while (fs->fs_flock) + sleep((caddr_t)&fs->fs_flock, PINOD); + if (fs->fs_nfree <= 0) { + fs->fs_nfree = 1; + fs->fs_free[0] = 0; + } + if (fs->fs_nfree >= NICFREE) { + fs->fs_flock++; + bp = getblk(ip->i_dev, bno); + fbp = (FBLKP) bp->b_addr; + *fbp = *((FBLKP)&fs->fs_nfree); + fs->fs_nfree = 0; + if (fs->fs_flags & MNT_ASYNC) + bdwrite(bp); + else + bwrite(bp); + fs->fs_flock = 0; + wakeup((caddr_t)&fs->fs_flock); + } + fs->fs_free[fs->fs_nfree++] = bno; + fs->fs_tfree++; + fs->fs_fmod = 1; } /* @@ -269,34 +269,34 @@ free (ip, bno) */ void ifree (ip, ino) - struct inode *ip; - ino_t ino; + struct inode *ip; + ino_t ino; { - register struct fs *fs; + register struct fs *fs; - fs = ip->i_fs; - fs->fs_tinode++; - if (fs->fs_ilock) - return; - if (fs->fs_ninode >= NICINOD) { - if (fs->fs_lasti > ino) - fs->fs_nbehind++; - return; - } - fs->fs_inode[fs->fs_ninode++] = ino; - fs->fs_fmod = 1; + fs = ip->i_fs; + fs->fs_tinode++; + if (fs->fs_ilock) + return; + if (fs->fs_ninode >= NICINOD) { + if (fs->fs_lasti > ino) + fs->fs_nbehind++; + return; + } + fs->fs_inode[fs->fs_ninode++] = ino; + fs->fs_fmod = 1; } /* * Fserr prints the name of a file system with an error diagnostic. * * The form of the error message is: - * fs: error message + * fs: error message */ void fserr (fp, cp) - struct fs *fp; - char *cp; + struct fs *fp; + char *cp; { - printf ("%s: %s\n", fp->fs_fsmnt, cp); + printf ("%s: %s\n", fp->fs_fsmnt, cp); } diff --git a/sys/kernel/ufs_bio.c b/sys/kernel/ufs_bio.c index 53b54c9..5e4ce91 100644 --- a/sys/kernel/ufs_bio.c +++ b/sys/kernel/ufs_bio.c @@ -11,7 +11,6 @@ #include "dk.h" #include "systm.h" #include "map.h" -#include "trace.h" #include "proc.h" /* @@ -19,23 +18,21 @@ */ struct buf * bread (dev, blkno) - dev_t dev; - daddr_t blkno; + dev_t dev; + daddr_t blkno; { - register struct buf *bp; + register struct buf *bp; - bp = getblk(dev, blkno); - if (bp->b_flags&(B_DONE|B_DELWRI)) { - trace(TR_BREADHIT); - return (bp); - } - bp->b_flags |= B_READ; - bp->b_bcount = DEV_BSIZE; /* XXX? KB */ - (*bdevsw[major(dev)].d_strategy)(bp); - trace(TR_BREADMISS); - u.u_ru.ru_inblock++; /* pay for read */ - biowait(bp); - return(bp); + bp = getblk(dev, blkno); + if (bp->b_flags&(B_DONE|B_DELWRI)) { + return (bp); + } + bp->b_flags |= B_READ; + bp->b_bcount = DEV_BSIZE; /* XXX? KB */ + (*bdevsw[major(dev)].d_strategy)(bp); + u.u_ru.ru_inblock++; /* pay for read */ + biowait(bp); + return(bp); } /* @@ -44,61 +41,55 @@ bread (dev, blkno) */ struct buf * breada(dev, blkno, rablkno) - register dev_t dev; - daddr_t blkno; - daddr_t rablkno; + register dev_t dev; + daddr_t blkno; + daddr_t rablkno; { - register struct buf *bp, *rabp; + register struct buf *bp, *rabp; - bp = NULL; - /* - * If the block isn't in core, then allocate - * a buffer and initiate i/o (getblk checks - * for a cache hit). - */ - if (! incore (dev, blkno)) { - bp = getblk(dev, blkno); - if ((bp->b_flags&(B_DONE|B_DELWRI)) == 0) { - bp->b_flags |= B_READ; - bp->b_bcount = DEV_BSIZE; /* XXX? KB */ - (*bdevsw[major(dev)].d_strategy)(bp); - trace(TR_BREADMISS); - u.u_ru.ru_inblock++; /* pay for read */ - } - else - trace(TR_BREADHIT); - } + bp = NULL; + /* + * If the block isn't in core, then allocate + * a buffer and initiate i/o (getblk checks + * for a cache hit). + */ + if (! incore (dev, blkno)) { + bp = getblk(dev, blkno); + if ((bp->b_flags&(B_DONE|B_DELWRI)) == 0) { + bp->b_flags |= B_READ; + bp->b_bcount = DEV_BSIZE; /* XXX? KB */ + (*bdevsw[major(dev)].d_strategy)(bp); + u.u_ru.ru_inblock++; /* pay for read */ + } + } - /* - * If there's a read-ahead block, start i/o - * on it also (as above). - */ - if (rablkno) { - if (! incore (dev, rablkno)) { - rabp = getblk(dev, rablkno); - if (rabp->b_flags & (B_DONE|B_DELWRI)) { - brelse(rabp); - trace(TR_BREADHITRA); - } else { - rabp->b_flags |= B_READ|B_ASYNC; - rabp->b_bcount = DEV_BSIZE; /* XXX? KB */ - (*bdevsw[major(dev)].d_strategy)(rabp); - trace(TR_BREADMISSRA); - u.u_ru.ru_inblock++; /* pay in advance */ - } - } else - trace(TR_BREADHITRA); - } + /* + * If there's a read-ahead block, start i/o + * on it also (as above). + */ + if (rablkno) { + if (! incore (dev, rablkno)) { + rabp = getblk(dev, rablkno); + if (rabp->b_flags & (B_DONE|B_DELWRI)) { + brelse(rabp); + } else { + rabp->b_flags |= B_READ|B_ASYNC; + rabp->b_bcount = DEV_BSIZE; /* XXX? KB */ + (*bdevsw[major(dev)].d_strategy)(rabp); + u.u_ru.ru_inblock++; /* pay in advance */ + } + } + } - /* - * If block was in core, let bread get it. - * If block wasn't in core, then the read was started - * above, and just wait for it. - */ - if (bp == NULL) - return (bread(dev, blkno)); - biowait(bp); - return (bp); + /* + * If block was in core, let bread get it. + * If block wasn't in core, then the read was started + * above, and just wait for it. + */ + if (bp == NULL) + return (bread(dev, blkno)); + biowait(bp); + return (bp); } /* @@ -107,28 +98,27 @@ breada(dev, blkno, rablkno) */ void bwrite(bp) - register struct buf *bp; + register struct buf *bp; { - register int flag; + register int flag; - flag = bp->b_flags; - bp->b_flags &= ~(B_READ | B_DONE | B_ERROR | B_DELWRI); - if ((flag&B_DELWRI) == 0) - u.u_ru.ru_oublock++; /* noone paid yet */ - trace(TR_BWRITE); - bp->b_bcount = DEV_BSIZE; /* XXX? KB */ - (*bdevsw[major(bp->b_dev)].d_strategy)(bp); + flag = bp->b_flags; + bp->b_flags &= ~(B_READ | B_DONE | B_ERROR | B_DELWRI); + if ((flag&B_DELWRI) == 0) + u.u_ru.ru_oublock++; /* noone paid yet */ + bp->b_bcount = DEV_BSIZE; /* XXX? KB */ + (*bdevsw[major(bp->b_dev)].d_strategy)(bp); - /* - * If the write was synchronous, then await i/o completion. - * If the write was "delayed", then we put the buffer on - * the q of blocks awaiting i/o completion status. - */ - if ((flag&B_ASYNC) == 0) { - biowait(bp); - brelse(bp); - } else if (flag & B_DELWRI) - bp->b_flags |= B_AGE; + /* + * If the write was synchronous, then await i/o completion. + * If the write was "delayed", then we put the buffer on + * the q of blocks awaiting i/o completion status. + */ + if ((flag&B_ASYNC) == 0) { + biowait(bp); + brelse(bp); + } else if (flag & B_DELWRI) + bp->b_flags |= B_AGE; } /* @@ -141,18 +131,18 @@ bwrite(bp) */ void bdwrite (bp) - register struct buf *bp; + register struct buf *bp; { - if ((bp->b_flags&B_DELWRI) == 0) - u.u_ru.ru_oublock++; /* noone paid yet */ - if (bdevsw[major(bp->b_dev)].d_flags & B_TAPE) { - bawrite(bp); - } - else { - bp->b_flags |= B_DELWRI | B_DONE; - brelse(bp); - } + if ((bp->b_flags&B_DELWRI) == 0) + u.u_ru.ru_oublock++; /* noone paid yet */ + if (bdevsw[major(bp->b_dev)].d_flags & B_TAPE) { + bawrite(bp); + } + else { + bp->b_flags |= B_DELWRI | B_DONE; + brelse(bp); + } } /* @@ -160,47 +150,46 @@ bdwrite (bp) */ void brelse (bp) - register struct buf *bp; + register struct buf *bp; { - register struct buf *flist; - register int s; + register struct buf *flist; + register int s; - trace(TR_BRELSE); - /* - * If someone's waiting for the buffer, or - * is waiting for a buffer, wake 'em up. - */ - if (bp->b_flags&B_WANTED) - wakeup((caddr_t)bp); - if (bfreelist[0].b_flags&B_WANTED) { - bfreelist[0].b_flags &= ~B_WANTED; - wakeup((caddr_t)bfreelist); - } - if (bp->b_flags&B_ERROR) { - if (bp->b_flags & B_LOCKED) - bp->b_flags &= ~B_ERROR; /* try again later */ - else - bp->b_dev = NODEV; /* no assoc */ - } - /* - * Stick the buffer back on a free list. - */ - s = splbio(); - if (bp->b_flags & (B_ERROR|B_INVAL)) { - /* block has no info ... put at front of most free list */ - flist = &bfreelist[BQ_AGE]; - binsheadfree(bp, flist); - } else { - if (bp->b_flags & B_LOCKED) - flist = &bfreelist[BQ_LOCKED]; - else if (bp->b_flags & B_AGE) - flist = &bfreelist[BQ_AGE]; - else - flist = &bfreelist[BQ_LRU]; - binstailfree(bp, flist); - } - bp->b_flags &= ~(B_WANTED|B_BUSY|B_ASYNC|B_AGE); - splx(s); + /* + * If someone's waiting for the buffer, or + * is waiting for a buffer, wake 'em up. + */ + if (bp->b_flags&B_WANTED) + wakeup((caddr_t)bp); + if (bfreelist[0].b_flags&B_WANTED) { + bfreelist[0].b_flags &= ~B_WANTED; + wakeup((caddr_t)bfreelist); + } + if (bp->b_flags&B_ERROR) { + if (bp->b_flags & B_LOCKED) + bp->b_flags &= ~B_ERROR; /* try again later */ + else + bp->b_dev = NODEV; /* no assoc */ + } + /* + * Stick the buffer back on a free list. + */ + s = splbio(); + if (bp->b_flags & (B_ERROR|B_INVAL)) { + /* block has no info ... put at front of most free list */ + flist = &bfreelist[BQ_AGE]; + binsheadfree(bp, flist); + } else { + if (bp->b_flags & B_LOCKED) + flist = &bfreelist[BQ_LOCKED]; + else if (bp->b_flags & B_AGE) + flist = &bfreelist[BQ_AGE]; + else + flist = &bfreelist[BQ_LRU]; + binstailfree(bp, flist); + } + bp->b_flags &= ~(B_WANTED|B_BUSY|B_ASYNC|B_AGE); + splx(s); } /* @@ -209,19 +198,19 @@ brelse (bp) */ int incore (dev, blkno) - register dev_t dev; - daddr_t blkno; + register dev_t dev; + daddr_t blkno; { - register struct buf *bp; - register struct buf *dp; + register struct buf *bp; + register struct buf *dp; - dp = BUFHASH(dev, blkno); - blkno = fsbtodb(blkno); - for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) - if (bp->b_blkno == blkno && bp->b_dev == dev && - (bp->b_flags & B_INVAL) == 0) - return (1); - return (0); + dp = BUFHASH(dev, blkno); + blkno = fsbtodb(blkno); + for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) + if (bp->b_blkno == blkno && bp->b_dev == dev && + (bp->b_flags & B_INVAL) == 0) + return (1); + return (0); } /* @@ -232,37 +221,36 @@ incore (dev, blkno) struct buf * getnewbuf() { - register struct buf *bp, *dp; - int s; + register struct buf *bp, *dp; + int s; loop: - s = splbio(); - for (dp = &bfreelist[BQ_AGE]; dp > bfreelist; dp--) - if (dp->av_forw != dp) - break; - if (dp == bfreelist) { /* no free blocks */ - dp->b_flags |= B_WANTED; - sleep((caddr_t)dp, PRIBIO+1); - splx(s); - goto loop; - } - splx(s); - bp = dp->av_forw; - notavail(bp); - if (bp->b_flags & B_DELWRI) { - bawrite(bp); - goto loop; - } - if(bp->b_flags & (B_RAMREMAP|B_PHYS)) { + s = splbio(); + for (dp = &bfreelist[BQ_AGE]; dp > bfreelist; dp--) + if (dp->av_forw != dp) + break; + if (dp == bfreelist) { /* no free blocks */ + dp->b_flags |= B_WANTED; + sleep((caddr_t)dp, PRIBIO+1); + splx(s); + goto loop; + } + splx(s); + bp = dp->av_forw; + notavail(bp); + if (bp->b_flags & B_DELWRI) { + bawrite(bp); + goto loop; + } + if(bp->b_flags & (B_RAMREMAP|B_PHYS)) { #ifdef DIAGNOSTIC - if ((bp < &buf[0]) || (bp >= &buf[NBUF])) - panic("getnewbuf: RAMREMAP bp addr"); + if ((bp < &buf[0]) || (bp >= &buf[NBUF])) + panic("getnewbuf: RAMREMAP bp addr"); #endif - bp->b_addr = bufdata + DEV_BSIZE * (bp - buf); - } - trace(TR_BRELSE); - bp->b_flags = B_BUSY; - return (bp); + bp->b_addr = bufdata + DEV_BSIZE * (bp - buf); + } + bp->b_flags = B_BUSY; + return (bp); } /* @@ -276,48 +264,48 @@ loop: */ struct buf * getblk(dev, blkno) - register dev_t dev; - daddr_t blkno; + register dev_t dev; + daddr_t blkno; { - register struct buf *bp, *dp; - daddr_t dblkno; - int s; + register struct buf *bp, *dp; + daddr_t dblkno; + int s; #ifdef DIAGNOSTIC - if (major(dev) >= nblkdev) - panic("blkdev"); + if (major(dev) >= nblkdev) + panic("blkdev"); #endif - /* - * Search the cache for the block. If we hit, but - * the buffer is in use for i/o, then we wait until - * the i/o has completed. - */ - dp = BUFHASH(dev, blkno); - dblkno = fsbtodb(blkno); + /* + * Search the cache for the block. If we hit, but + * the buffer is in use for i/o, then we wait until + * the i/o has completed. + */ + dp = BUFHASH(dev, blkno); + dblkno = fsbtodb(blkno); loop: - for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) { - if (bp->b_blkno != dblkno || bp->b_dev != dev || - bp->b_flags&B_INVAL) - continue; - s = splbio(); - if (bp->b_flags&B_BUSY) { - bp->b_flags |= B_WANTED; - sleep((caddr_t)bp, PRIBIO+1); - splx(s); - goto loop; - } - splx(s); - notavail(bp); - return (bp); - } - bp = getnewbuf(); - bfree(bp); - bremhash(bp); - binshash(bp, dp); - bp->b_dev = dev; - bp->b_blkno = dblkno; - bp->b_error = 0; - return (bp); + for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) { + if (bp->b_blkno != dblkno || bp->b_dev != dev || + bp->b_flags&B_INVAL) + continue; + s = splbio(); + if (bp->b_flags&B_BUSY) { + bp->b_flags |= B_WANTED; + sleep((caddr_t)bp, PRIBIO+1); + splx(s); + goto loop; + } + splx(s); + notavail(bp); + return (bp); + } + bp = getnewbuf(); + bfree(bp); + bremhash(bp); + binshash(bp, dp); + bp->b_dev = dev; + bp->b_blkno = dblkno; + bp->b_error = 0; + return (bp); } /* @@ -327,17 +315,17 @@ loop: struct buf * geteblk() { - register struct buf *bp, *flist; + register struct buf *bp, *flist; - bp = getnewbuf(); - bp->b_flags |= B_INVAL; - bfree(bp); - bremhash(bp); - flist = &bfreelist[BQ_AGE]; - binshash(bp, flist); - bp->b_dev = (dev_t)NODEV; - bp->b_error = 0; - return (bp); + bp = getnewbuf(); + bp->b_flags |= B_INVAL; + bfree(bp); + bremhash(bp); + flist = &bfreelist[BQ_AGE]; + binshash(bp, flist); + bp->b_dev = (dev_t)NODEV; + bp->b_error = 0; + return (bp); } /* @@ -346,16 +334,16 @@ geteblk() */ void biowait(bp) - register struct buf *bp; + register struct buf *bp; { - register int s; + register int s; - s = splbio(); - while ((bp->b_flags & B_DONE) == 0) - sleep((caddr_t)bp, PRIBIO); - splx(s); - if (! u.u_error) /* XXX */ - u.u_error = geterror(bp); + s = splbio(); + while ((bp->b_flags & B_DONE) == 0) + sleep((caddr_t)bp, PRIBIO); + splx(s); + if (! u.u_error) /* XXX */ + u.u_error = geterror(bp); } /* @@ -364,17 +352,17 @@ biowait(bp) */ void biodone(bp) - register struct buf *bp; + register struct buf *bp; { - if (bp->b_flags & B_DONE) - panic("dup biodone"); - bp->b_flags |= B_DONE; - if (bp->b_flags & B_ASYNC) - brelse(bp); - else { - bp->b_flags &= ~B_WANTED; - wakeup((caddr_t)bp); - } + if (bp->b_flags & B_DONE) + panic("dup biodone"); + bp->b_flags |= B_DONE; + if (bp->b_flags & B_ASYNC) + brelse(bp); + else { + bp->b_flags &= ~B_WANTED; + wakeup((caddr_t)bp); + } } /* @@ -382,35 +370,35 @@ biodone(bp) */ void blkflush (dev, blkno) - register dev_t dev; - daddr_t blkno; + register dev_t dev; + daddr_t blkno; { - register struct buf *ep; - struct buf *dp; - register int s; + register struct buf *ep; + struct buf *dp; + register int s; - dp = BUFHASH(dev, blkno); - blkno = fsbtodb(blkno); + dp = BUFHASH(dev, blkno); + blkno = fsbtodb(blkno); loop: - for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) { - if (ep->b_blkno != blkno || ep->b_dev != dev || - (ep->b_flags&B_INVAL)) - continue; - s = splbio(); - if (ep->b_flags&B_BUSY) { - ep->b_flags |= B_WANTED; - sleep((caddr_t)ep, PRIBIO+1); - splx(s); - goto loop; - } - if (ep->b_flags & B_DELWRI) { - splx(s); - notavail(ep); - bwrite(ep); - goto loop; - } - splx(s); - } + for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) { + if (ep->b_blkno != blkno || ep->b_dev != dev || + (ep->b_flags&B_INVAL)) + continue; + s = splbio(); + if (ep->b_flags&B_BUSY) { + ep->b_flags |= B_WANTED; + sleep((caddr_t)ep, PRIBIO+1); + splx(s); + goto loop; + } + if (ep->b_flags & B_DELWRI) { + splx(s); + notavail(ep); + bwrite(ep); + goto loop; + } + splx(s); + } } /* @@ -419,28 +407,28 @@ loop: */ void bflush(dev) - register dev_t dev; + register dev_t dev; { - register struct buf *bp; - register struct buf *flist; - int s; + register struct buf *bp; + register struct buf *flist; + int s; loop: - s = splbio(); - for (flist = bfreelist; flist < &bfreelist[BQ_EMPTY]; flist++) { - for (bp = flist->av_forw; bp != flist; bp = bp->av_forw) { - if ((bp->b_flags & B_DELWRI) == 0) - continue; - if (dev == bp->b_dev) { - bp->b_flags |= B_ASYNC; - notavail(bp); - bwrite(bp); - splx(s); - goto loop; - } - } - } - splx(s); + s = splbio(); + for (flist = bfreelist; flist < &bfreelist[BQ_EMPTY]; flist++) { + for (bp = flist->av_forw; bp != flist; bp = bp->av_forw) { + if ((bp->b_flags & B_DELWRI) == 0) + continue; + if (dev == bp->b_dev) { + bp->b_flags |= B_ASYNC; + notavail(bp); + bwrite(bp); + splx(s); + goto loop; + } + } + } + splx(s); } /* @@ -449,14 +437,14 @@ loop: */ int geterror (bp) - register struct buf *bp; + register struct buf *bp; { - register int error = 0; + register int error = 0; - if (bp->b_flags&B_ERROR) - if ((error = bp->b_error)==0) - return(EIO); - return (error); + if (bp->b_flags&B_ERROR) + if ((error = bp->b_error)==0) + return(EIO); + return (error); } /* @@ -468,18 +456,18 @@ geterror (bp) * being used for i/o. Eventually, all disc drivers should be forced to * have a close routine, which ought ensure that the queue is empty, then * properly flush the queues. Until that happy day, this suffices for - * correctness. ... kre + * correctness. ... kre */ void binval(dev) - register dev_t dev; + register dev_t dev; { - register struct buf *bp; - register struct bufhd *hp; + register struct buf *bp; + register struct bufhd *hp; #define dp ((struct buf *)hp) - for (hp = bufhash; hp < &bufhash[BUFHSZ]; hp++) - for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) - if (bp->b_dev == dev) - bp->b_flags |= B_INVAL; + for (hp = bufhash; hp < &bufhash[BUFHSZ]; hp++) + for (bp = dp->b_forw; bp != dp; bp = bp->b_forw) + if (bp->b_dev == dev) + bp->b_flags |= B_INVAL; } diff --git a/sys/kernel/ufs_bmap.c b/sys/kernel/ufs_bmap.c index d56d21c..f768f37 100644 --- a/sys/kernel/ufs_bmap.c +++ b/sys/kernel/ufs_bmap.c @@ -24,131 +24,131 @@ */ daddr_t bmap(ip, bn, rwflg, flags) - register struct inode *ip; - daddr_t bn; - int rwflg, flags; + register struct inode *ip; + daddr_t bn; + int rwflg, flags; { - register int i; - register struct buf *bp; - struct buf *nbp; - int j, sh; - daddr_t nb, *bap, ra; - int async = ip->i_fs->fs_flags & MNT_ASYNC; + register int i; + register struct buf *bp; + struct buf *nbp; + int j, sh; + daddr_t nb, *bap, ra; + int async = ip->i_fs->fs_flags & MNT_ASYNC; - if (bn < 0) { - u.u_error = EFBIG; - return((daddr_t)0); - } - ra = rablock = 0; + if (bn < 0) { + u.u_error = EFBIG; + return((daddr_t)0); + } + ra = rablock = 0; - /* - * blocks 0..NADDR-4 are direct blocks - */ - if (bn < NADDR-3) { - i = bn; - nb = ip->i_addr[i]; - if (nb == 0) { - if (rwflg == B_READ || (bp = balloc(ip, flags)) == NULL) - return((daddr_t)-1); - nb = dbtofsb(bp->b_blkno); + /* + * blocks 0..NADDR-4 are direct blocks + */ + if (bn < NADDR-3) { + i = bn; + nb = ip->i_addr[i]; + if (nb == 0) { + if (rwflg == B_READ || (bp = balloc(ip, flags)) == NULL) + return((daddr_t)-1); + nb = dbtofsb(bp->b_blkno); /* * directory blocks are usually the only thing written synchronously at this * point (so they never appear with garbage in them on the disk). This is * overridden if the filesystem was mounted 'async'. */ - if (flags & B_SYNC) - bwrite(bp); - else - bdwrite(bp); - ip->i_addr[i] = nb; - ip->i_flag |= IUPD|ICHG; - } - if (i < NADDR-4) - rablock = ip->i_addr[i+1]; - return(nb); - } + if (flags & B_SYNC) + bwrite(bp); + else + bdwrite(bp); + ip->i_addr[i] = nb; + ip->i_flag |= IUPD|ICHG; + } + if (i < NADDR-4) + rablock = ip->i_addr[i+1]; + return(nb); + } - /* - * addresses NADDR-3, NADDR-2, and NADDR-1 - * have single, double, triple indirect blocks. - * the first step is to determine - * how many levels of indirection. - */ - sh = 0; - nb = 1; - bn -= NADDR-3; - for (j = 3;j > 0;j--) { - sh += NSHIFT; - nb <<= NSHIFT; - if (bn < nb) - break; - bn -= nb; - } - if (j == 0) { - u.u_error = EFBIG; - return((daddr_t)0); - } + /* + * addresses NADDR-3, NADDR-2, and NADDR-1 + * have single, double, triple indirect blocks. + * the first step is to determine + * how many levels of indirection. + */ + sh = 0; + nb = 1; + bn -= NADDR-3; + for (j = 3;j > 0;j--) { + sh += NSHIFT; + nb <<= NSHIFT; + if (bn < nb) + break; + bn -= nb; + } + if (j == 0) { + u.u_error = EFBIG; + return((daddr_t)0); + } - /* - * fetch the first indirect block - */ - nb = ip->i_addr[NADDR-j]; - if (nb == 0) { - if (rwflg == B_READ || (bp = balloc(ip, flags | B_CLRBUF)) == NULL) - return((daddr_t) -1); - nb = dbtofsb(bp->b_blkno); - /* - * Write synchronously if requested so that indirect blocks - * never point at garbage. - */ - if (async) - bdwrite(bp); - else - bwrite(bp); - ip->i_addr[NADDR-j] = nb; - ip->i_flag |= IUPD|ICHG; - } + /* + * fetch the first indirect block + */ + nb = ip->i_addr[NADDR-j]; + if (nb == 0) { + if (rwflg == B_READ || (bp = balloc(ip, flags | B_CLRBUF)) == NULL) + return((daddr_t) -1); + nb = dbtofsb(bp->b_blkno); + /* + * Write synchronously if requested so that indirect blocks + * never point at garbage. + */ + if (async) + bdwrite(bp); + else + bwrite(bp); + ip->i_addr[NADDR-j] = nb; + ip->i_flag |= IUPD|ICHG; + } - /* - * fetch through the indirect blocks - */ - for(;j <= 3;j++) { - bp = bread(ip->i_dev, nb); - if ((bp->b_flags & B_ERROR) || bp->b_resid) { - brelse(bp); - return((daddr_t)0); - } - bap = (daddr_t*) bp->b_addr; - sh -= NSHIFT; - i = (bn>>sh) & NMASK; - nb = bap[i]; - /* - * calculate read-ahead - */ - if (i < NINDIR-1) - ra = bap[i+1]; - if (nb == 0) { - if (rwflg == B_READ || (nbp = balloc(ip, flags | B_CLRBUF)) == NULL) { - brelse(bp); - return((daddr_t) -1); - } - nb = dbtofsb(nbp->b_blkno); + /* + * fetch through the indirect blocks + */ + for(;j <= 3;j++) { + bp = bread(ip->i_dev, nb); + if ((bp->b_flags & B_ERROR) || bp->b_resid) { + brelse(bp); + return((daddr_t)0); + } + bap = (daddr_t*) bp->b_addr; + sh -= NSHIFT; + i = (bn>>sh) & NMASK; + nb = bap[i]; + /* + * calculate read-ahead + */ + if (i < NINDIR-1) + ra = bap[i+1]; + if (nb == 0) { + if (rwflg == B_READ || (nbp = balloc(ip, flags | B_CLRBUF)) == NULL) { + brelse(bp); + return((daddr_t) -1); + } + nb = dbtofsb(nbp->b_blkno); /* * Write synchronously so indirect blocks never point at garbage and blocks * in directories never contain garbage. This check used to be based on the * type of inode, if it was a directory then 'sync' writes were done. See the * comments earlier about filesystems being mounted 'async'. */ - if (!async && (j < 3 || (flags & B_SYNC))) - bwrite(nbp); - else - bdwrite(nbp); - bap = (daddr_t*) bp->b_addr; - bap[i] = nb; - bdwrite(bp); - } else - brelse(bp); - } - rablock = ra; - return(nb); + if (!async && (j < 3 || (flags & B_SYNC))) + bwrite(nbp); + else + bdwrite(nbp); + bap = (daddr_t*) bp->b_addr; + bap[i] = nb; + bdwrite(bp); + } else + brelse(bp); + } + rablock = ra; + return(nb); } diff --git a/sys/kernel/ufs_dsort.c b/sys/kernel/ufs_dsort.c index 3f6b7f9..4e8f9fc 100644 --- a/sys/kernel/ufs_dsort.c +++ b/sys/kernel/ufs_dsort.c @@ -3,7 +3,7 @@ * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. * - * @(#)ufs_dsort.c 1.1 (2.10BSD Berkeley) 12/1/86 + * @(#)ufs_dsort.c 1.1 (2.10BSD Berkeley) 12/1/86 */ /* @@ -17,37 +17,37 @@ void disksort (dp, bp) - register struct buf *dp, *bp; + register struct buf *dp, *bp; { - register struct buf *ap; - struct buf *tp; + register struct buf *ap; + struct buf *tp; - ap = dp->b_actf; - if (ap == NULL) { - dp->b_actf = bp; - dp->b_actl = bp; - bp->av_forw = NULL; - return; - } - tp = NULL; - for (; ap != NULL; ap = ap->av_forw) { - if ((bp->b_flags&B_READ) && (ap->b_flags&B_READ) == 0) { - if (tp == NULL) - tp = ap; - break; - } - if ((bp->b_flags&B_READ) == 0 && (ap->b_flags&B_READ)) - continue; - if (ap->b_cylin <= bp->b_cylin) - if (tp == NULL || ap->b_cylin >= tp->b_cylin) - tp = ap; - } - if (tp == NULL) - tp = dp->b_actl; - bp->av_forw = tp->av_forw; - tp->av_forw = bp; - if (tp == dp->b_actl) - dp->b_actl = bp; + ap = dp->b_actf; + if (ap == NULL) { + dp->b_actf = bp; + dp->b_actl = bp; + bp->av_forw = NULL; + return; + } + tp = NULL; + for (; ap != NULL; ap = ap->av_forw) { + if ((bp->b_flags&B_READ) && (ap->b_flags&B_READ) == 0) { + if (tp == NULL) + tp = ap; + break; + } + if ((bp->b_flags&B_READ) == 0 && (ap->b_flags&B_READ)) + continue; + if (ap->b_cylin <= bp->b_cylin) + if (tp == NULL || ap->b_cylin >= tp->b_cylin) + tp = ap; + } + if (tp == NULL) + tp = dp->b_actl; + bp->av_forw = tp->av_forw; + tp->av_forw = bp; + if (tp == dp->b_actl) + dp->b_actl = bp; } #ifdef UCB_METER @@ -58,27 +58,27 @@ disksort (dp, bp) */ void dk_alloc (dkn, slots, name) - int *dkn; /* pointer to number for iostat */ - int slots; /* number of iostat slots requested */ - char *name; /* name of device */ + int *dkn; /* pointer to number for iostat */ + int slots; /* number of iostat slots requested */ + char *name; /* name of device */ { - int i; - register char **np; - register int *up; + int i; + register char **np; + register int *up; - if (*dkn < 0 && dk_n + slots <= DK_NDRIVE) { - /* - * Allocate and initialize the slots - */ - *dkn = dk_n; - np = &dk_name[dk_n]; - up = &dk_unit[dk_n]; - dk_n += slots; + if (*dkn < 0 && dk_n + slots <= DK_NDRIVE) { + /* + * Allocate and initialize the slots + */ + *dkn = dk_n; + np = &dk_name[dk_n]; + up = &dk_unit[dk_n]; + dk_n += slots; - for (i = 0; i < slots; i++) { - *np++ = name; - *up++ = i; - } - } + for (i = 0; i < slots; i++) { + *np++ = name; + *up++ = i; + } + } } #endif /* UCB_METER */ diff --git a/sys/kernel/ufs_fio.c b/sys/kernel/ufs_fio.c index 556485b..8f7d33b 100644 --- a/sys/kernel/ufs_fio.c +++ b/sys/kernel/ufs_fio.c @@ -27,59 +27,59 @@ */ int access (ip, mode) - register struct inode *ip; - int mode; + register struct inode *ip; + int mode; { - register int m; - register gid_t *gp; + register int m; + register gid_t *gp; - m = mode; - if (m == IWRITE) { - if (ip->i_flags & IMMUTABLE) { - u.u_error = EPERM; - return(1); - } - /* - * Disallow write attempts on read-only - * file systems; unless the file is a block - * or character device resident on the - * file system. - */ - if (ip->i_fs->fs_ronly != 0) { - if ((ip->i_mode & IFMT) != IFCHR && - (ip->i_mode & IFMT) != IFBLK) { - u.u_error = EROFS; - return (1); - } - } - } - /* - * If you're the super-user, - * you always get access. - */ - if (u.u_uid == 0) - return (0); - /* - * Access check is based on only - * one of owner, group, public. - * If not owner, then check group. - * If not a member of the group, then - * check public access. - */ - if (u.u_uid != ip->i_uid) { - m >>= 3; - gp = u.u_groups; - for (; gp < &u.u_groups[NGROUPS] && *gp != NOGROUP; gp++) - if (ip->i_gid == *gp) - goto found; - m >>= 3; + m = mode; + if (m == IWRITE) { + if (ip->i_flags & IMMUTABLE) { + u.u_error = EPERM; + return(1); + } + /* + * Disallow write attempts on read-only + * file systems; unless the file is a block + * or character device resident on the + * file system. + */ + if (ip->i_fs->fs_ronly != 0) { + if ((ip->i_mode & IFMT) != IFCHR && + (ip->i_mode & IFMT) != IFBLK) { + u.u_error = EROFS; + return (1); + } + } + } + /* + * If you're the super-user, + * you always get access. + */ + if (u.u_uid == 0) + return (0); + /* + * Access check is based on only + * one of owner, group, public. + * If not owner, then check group. + * If not a member of the group, then + * check public access. + */ + if (u.u_uid != ip->i_uid) { + m >>= 3; + gp = u.u_groups; + for (; gp < &u.u_groups[NGROUPS] && *gp != NOGROUP; gp++) + if (ip->i_gid == *gp) + goto found; + m >>= 3; found: - ; - } - if ((ip->i_mode&m) != 0) - return (0); - u.u_error = EACCES; - return (1); + ; + } + if ((ip->i_mode&m) != 0) + return (0); + u.u_error = EACCES; + return (1); } /* copied, for supervisory networking, to sys_net.c */ @@ -90,11 +90,11 @@ found: int suser() { - if (u.u_uid == 0) { - return (1); - } - u.u_error = EPERM; - return (0); + if (u.u_uid == 0) { + return (1); + } + u.u_error = EPERM; + return (0); } /* @@ -103,67 +103,67 @@ suser() */ int ufs_setattr (ip, vap) - register struct inode *ip; - register struct vattr *vap; + register struct inode *ip; + register struct vattr *vap; { - int error; - struct timeval atimeval, mtimeval; + int error; + struct timeval atimeval, mtimeval; - if (ip->i_fs->fs_ronly) /* can't change anything on a RO fs */ - return(EROFS); - if (vap->va_flags != VNOVAL) { - if (u.u_uid != ip->i_uid && !suser()) - return(u.u_error); - if (u.u_uid == 0) { - if ((ip->i_flags & - (SF_IMMUTABLE|SF_APPEND)) && securelevel > 0) - return(EPERM); - ip->i_flags = vap->va_flags; - } else { - if (ip->i_flags & (SF_IMMUTABLE|SF_APPEND)) - return(EPERM); - ip->i_flags &= SF_SETTABLE; - ip->i_flags |= (vap->va_flags & UF_SETTABLE); - } - ip->i_flag |= ICHG; - if (vap->va_flags & (IMMUTABLE|APPEND)) - return(0); - } - if (ip->i_flags & (IMMUTABLE|APPEND)) - return(EPERM); - /* - * Go thru the fields (other than 'flags') and update iff not VNOVAL. - */ - if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) { - error = chown1 (ip, vap->va_uid, vap->va_gid); - if (error) - return(error); - } - if (vap->va_size != (off_t)VNOVAL) { - if ((ip->i_mode & IFMT) == IFDIR) - return(EISDIR); - itrunc(ip, vap->va_size, 0); - if (u.u_error) - return(u.u_error); - } - if (vap->va_atime != (time_t)VNOVAL || - vap->va_mtime != (time_t)VNOVAL) { - if (u.u_uid != ip->i_uid && !suser() && - ((vap->va_vaflags & VA_UTIMES_NULL) == 0 || - access(ip, IWRITE))) - return(u.u_error); - if (vap->va_atime != (time_t)VNOVAL && - ! (ip->i_fs->fs_flags & MNT_NOATIME)) - ip->i_flag |= IACC; - if (vap->va_mtime != (time_t)VNOVAL) - ip->i_flag |= (IUPD|ICHG); - atimeval.tv_sec = vap->va_atime; - mtimeval.tv_sec = vap->va_mtime; - iupdat(ip, &atimeval, &mtimeval, 1); - } - if (vap->va_mode != (mode_t)VNOVAL) - return(chmod1(ip, vap->va_mode)); - return(0); + if (ip->i_fs->fs_ronly) /* can't change anything on a RO fs */ + return(EROFS); + if (vap->va_flags != VNOVAL) { + if (u.u_uid != ip->i_uid && !suser()) + return(u.u_error); + if (u.u_uid == 0) { + if ((ip->i_flags & + (SF_IMMUTABLE|SF_APPEND)) && securelevel > 0) + return(EPERM); + ip->i_flags = vap->va_flags; + } else { + if (ip->i_flags & (SF_IMMUTABLE|SF_APPEND)) + return(EPERM); + ip->i_flags &= SF_SETTABLE; + ip->i_flags |= (vap->va_flags & UF_SETTABLE); + } + ip->i_flag |= ICHG; + if (vap->va_flags & (IMMUTABLE|APPEND)) + return(0); + } + if (ip->i_flags & (IMMUTABLE|APPEND)) + return(EPERM); + /* + * Go thru the fields (other than 'flags') and update iff not VNOVAL. + */ + if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) { + error = chown1 (ip, vap->va_uid, vap->va_gid); + if (error) + return(error); + } + if (vap->va_size != (off_t)VNOVAL) { + if ((ip->i_mode & IFMT) == IFDIR) + return(EISDIR); + itrunc(ip, vap->va_size, 0); + if (u.u_error) + return(u.u_error); + } + if (vap->va_atime != (time_t)VNOVAL || + vap->va_mtime != (time_t)VNOVAL) { + if (u.u_uid != ip->i_uid && !suser() && + ((vap->va_vaflags & VA_UTIMES_NULL) == 0 || + access(ip, IWRITE))) + return(u.u_error); + if (vap->va_atime != (time_t)VNOVAL && + ! (ip->i_fs->fs_flags & MNT_NOATIME)) + ip->i_flag |= IACC; + if (vap->va_mtime != (time_t)VNOVAL) + ip->i_flag |= (IUPD|ICHG); + atimeval.tv_sec = vap->va_atime; + mtimeval.tv_sec = vap->va_mtime; + iupdat(ip, &atimeval, &mtimeval, 1); + } + if (vap->va_mode != (mode_t)VNOVAL) + return(chmod1(ip, vap->va_mode)); + return(0); } /* @@ -172,15 +172,15 @@ ufs_setattr (ip, vap) */ int ufs_mountedon (dev) - dev_t dev; + dev_t dev; { - register struct mount *mp; + register struct mount *mp; - for (mp = mount; mp < &mount[NMOUNT]; mp++) { - if (mp->m_inodp == NULL) - continue; - if (mp->m_dev == dev) - return(EBUSY); - } - return(0); + for (mp = mount; mp < &mount[NMOUNT]; mp++) { + if (mp->m_inodp == NULL) + continue; + if (mp->m_dev == dev) + return(EBUSY); + } + return(0); } diff --git a/sys/kernel/ufs_inode.c b/sys/kernel/ufs_inode.c index abc4a5b..31bf5a0 100644 --- a/sys/kernel/ufs_inode.c +++ b/sys/kernel/ufs_inode.c @@ -14,12 +14,12 @@ #include "systm.h" #include "syslog.h" -#define INOHSZ 16 /* must be power of two */ -#define INOHASH(dev,ino) (((dev)+(ino))&(INOHSZ-1)) +#define INOHSZ 16 /* must be power of two */ +#define INOHASH(dev,ino) (((dev)+(ino))&(INOHSZ-1)) -union ihead { /* inode LRU cache, stolen */ - union ihead *ih_head[2]; - struct inode *ih_chain[2]; +union ihead { /* inode LRU cache, stolen */ + union ihead *ih_head[2]; + struct inode *ih_chain[2]; } ihead[INOHSZ]; struct inode *ifreeh, **ifreet; @@ -31,28 +31,28 @@ struct inode *ifreeh, **ifreet; void ihinit() { - register int i; - register struct inode *ip = inode; - register union ihead *ih = ihead; + register int i; + register struct inode *ip = inode; + register union ihead *ih = ihead; - for (i = INOHSZ; --i >= 0; ih++) { - ih->ih_head[0] = ih; - ih->ih_head[1] = ih; - } - ifreeh = ip; - ifreet = &ip->i_freef; - ip->i_freeb = &ifreeh; - ip->i_forw = ip; - ip->i_back = ip; - for (i = NINODE; --i > 0; ) { - ++ip; - ip->i_forw = ip; - ip->i_back = ip; - *ifreet = ip; - ip->i_freeb = ifreet; - ifreet = &ip->i_freef; - } - ip->i_freef = NULL; + for (i = INOHSZ; --i >= 0; ih++) { + ih->ih_head[0] = ih; + ih->ih_head[1] = ih; + } + ifreeh = ip; + ifreet = &ip->i_freef; + ip->i_freeb = &ifreeh; + ip->i_forw = ip; + ip->i_back = ip; + for (i = NINODE; --i > 0; ) { + ++ip; + ip->i_forw = ip; + ip->i_back = ip; + *ifreet = ip; + ip->i_freeb = ifreet; + ifreet = &ip->i_freef; + } + ip->i_freef = NULL; } /* @@ -60,17 +60,17 @@ ihinit() */ struct inode * ifind(dev, ino) - register dev_t dev; - register ino_t ino; + register dev_t dev; + register ino_t ino; { - register struct inode *ip; - union ihead *ih; + register struct inode *ip; + union ihead *ih; - ih = &ihead[INOHASH(dev, ino)]; - for (ip = ih->ih_chain[0]; ip != (struct inode *)ih; ip = ip->i_forw) - if (ino == ip->i_number && dev == ip->i_dev) - return(ip); - return((struct inode *)NULL); + ih = &ihead[INOHASH(dev, ino)]; + for (ip = ih->ih_chain[0]; ip != (struct inode *)ih; ip = ip->i_forw) + if (ino == ip->i_number && dev == ip->i_dev) + return(ip); + return((struct inode *)NULL); } /* @@ -85,130 +85,130 @@ ifind(dev, ino) * inode structure is returned. * * panic: no imt -- if the mounted file - * system is not in the mount table. - * "cannot happen" + * system is not in the mount table. + * "cannot happen" */ struct inode * iget(dev, fs, ino) - dev_t dev; - register struct fs *fs; - ino_t ino; + dev_t dev; + register struct fs *fs; + ino_t ino; { - register struct inode *ip; - union ihead *ih; - struct buf *bp; - struct dinode *dp; + register struct inode *ip; + union ihead *ih; + struct buf *bp; + struct dinode *dp; loop: - ih = &ihead[INOHASH(dev, ino)]; - for (ip = ih->ih_chain[0]; ip != (struct inode *)ih; ip = ip->i_forw) - if (ino == ip->i_number && dev == ip->i_dev) { - /* - * Following is essentially an inline expanded - * copy of igrab(), expanded inline for speed, - * and so that the test for a mounted on inode - * can be deferred until after we are sure that - * the inode isn't busy. - */ - if ((ip->i_flag&ILOCKED) != 0) { - ip->i_flag |= IWANT; - sleep((caddr_t)ip, PINOD); - goto loop; - } - if ((ip->i_flag&IMOUNT) != 0) { - register struct mount *mp; + ih = &ihead[INOHASH(dev, ino)]; + for (ip = ih->ih_chain[0]; ip != (struct inode *)ih; ip = ip->i_forw) + if (ino == ip->i_number && dev == ip->i_dev) { + /* + * Following is essentially an inline expanded + * copy of igrab(), expanded inline for speed, + * and so that the test for a mounted on inode + * can be deferred until after we are sure that + * the inode isn't busy. + */ + if ((ip->i_flag&ILOCKED) != 0) { + ip->i_flag |= IWANT; + sleep((caddr_t)ip, PINOD); + goto loop; + } + if ((ip->i_flag&IMOUNT) != 0) { + register struct mount *mp; - for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) - if(mp->m_inodp == ip) { - dev = mp->m_dev; - fs = &mp->m_filsys; - ino = ROOTINO; - goto loop; - } - panic("no imt"); - } - if (ip->i_count == 0) { /* ino on free list */ - register struct inode *iq; + for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) + if(mp->m_inodp == ip) { + dev = mp->m_dev; + fs = &mp->m_filsys; + ino = ROOTINO; + goto loop; + } + panic("no imt"); + } + if (ip->i_count == 0) { /* ino on free list */ + register struct inode *iq; - iq = ip->i_freef; - if (iq) - iq->i_freeb = ip->i_freeb; - else - ifreet = ip->i_freeb; - *ip->i_freeb = iq; - ip->i_freef = NULL; - ip->i_freeb = NULL; - } - ip->i_count++; - ip->i_flag |= ILOCKED; - return(ip); - } + iq = ip->i_freef; + if (iq) + iq->i_freeb = ip->i_freeb; + else + ifreet = ip->i_freeb; + *ip->i_freeb = iq; + ip->i_freef = NULL; + ip->i_freeb = NULL; + } + ip->i_count++; + ip->i_flag |= ILOCKED; + return(ip); + } - ip = ifreeh; - if (ip == NULL) { - log(LOG_ERR, "inode: table full\n"); - u.u_error = ENFILE; - return(NULL); - } - if (ip->i_count) - panic("free inode isn't"); - { - register struct inode *iq; + ip = ifreeh; + if (ip == NULL) { + log(LOG_ERR, "inode: table full\n"); + u.u_error = ENFILE; + return(NULL); + } + if (ip->i_count) + panic("free inode isn't"); + { + register struct inode *iq; - iq = ip->i_freef; - if (iq) - iq->i_freeb = &ifreeh; - ifreeh = iq; - } - ip->i_freef = NULL; - ip->i_freeb = NULL; - /* - * Now to take inode off the hash chain it was on - * (initially, or after an iflush, it is on a "hash chain" - * consisting entirely of itself, and pointed to by no-one, - * but that doesn't matter), and put it on the chain for - * its new (ino, dev) pair - */ - remque(ip); - insque(ip, ih); - ip->i_dev = dev; - ip->i_fs = fs; - ip->i_number = ino; - cacheinval(ip); - ip->i_flag = ILOCKED; - ip->i_count++; - ip->i_lastr = 0; - bp = bread(dev, itod(ino)); - /* - * Check I/O errors - */ - if ((bp->b_flags&B_ERROR) != 0) { - brelse(bp); - /* - * the inode doesn't contain anything useful, so it would - * be misleading to leave it on its hash chain. - * 'iput' will take care of putting it back on the free list. - */ - remque(ip); - ip->i_forw = ip; - ip->i_back = ip; - /* - * we also loose its inumber, just in case (as iput - * doesn't do that any more) - but as it isn't on its - * hash chain, I doubt if this is really necessary .. kre - * (probably the two methods are interchangable) - */ - ip->i_number = 0; - iput(ip); - return(NULL); - } - dp = (struct dinode*) bp->b_addr; - dp += itoo(ino); - ip->i_ic1 = dp->di_ic1; - ip->i_flags = dp->di_flags; - ip->i_ic2 = dp->di_ic2; - bcopy(dp->di_addr, ip->i_addr, NADDR * sizeof (daddr_t)); - brelse(bp); - return (ip); + iq = ip->i_freef; + if (iq) + iq->i_freeb = &ifreeh; + ifreeh = iq; + } + ip->i_freef = NULL; + ip->i_freeb = NULL; + /* + * Now to take inode off the hash chain it was on + * (initially, or after an iflush, it is on a "hash chain" + * consisting entirely of itself, and pointed to by no-one, + * but that doesn't matter), and put it on the chain for + * its new (ino, dev) pair + */ + remque(ip); + insque(ip, ih); + ip->i_dev = dev; + ip->i_fs = fs; + ip->i_number = ino; + cacheinval(ip); + ip->i_flag = ILOCKED; + ip->i_count++; + ip->i_lastr = 0; + bp = bread(dev, itod(ino)); + /* + * Check I/O errors + */ + if ((bp->b_flags&B_ERROR) != 0) { + brelse(bp); + /* + * the inode doesn't contain anything useful, so it would + * be misleading to leave it on its hash chain. + * 'iput' will take care of putting it back on the free list. + */ + remque(ip); + ip->i_forw = ip; + ip->i_back = ip; + /* + * we also loose its inumber, just in case (as iput + * doesn't do that any more) - but as it isn't on its + * hash chain, I doubt if this is really necessary .. kre + * (probably the two methods are interchangable) + */ + ip->i_number = 0; + iput(ip); + return(NULL); + } + dp = (struct dinode*) bp->b_addr; + dp += itoo(ino); + ip->i_ic1 = dp->di_ic1; + ip->i_flags = dp->di_flags; + ip->i_ic2 = dp->di_ic2; + bcopy(dp->di_addr, ip->i_addr, NADDR * sizeof (daddr_t)); + brelse(bp); + return (ip); } /* @@ -221,26 +221,26 @@ loop: */ void igrab (ip) - register struct inode *ip; + register struct inode *ip; { - while ((ip->i_flag&ILOCKED) != 0) { - ip->i_flag |= IWANT; - sleep((caddr_t)ip, PINOD); - } - if (ip->i_count == 0) { /* ino on free list */ - register struct inode *iq; + while ((ip->i_flag&ILOCKED) != 0) { + ip->i_flag |= IWANT; + sleep((caddr_t)ip, PINOD); + } + if (ip->i_count == 0) { /* ino on free list */ + register struct inode *iq; - iq = ip->i_freef; - if (iq) - iq->i_freeb = ip->i_freeb; - else - ifreet = ip->i_freeb; - *ip->i_freeb = iq; - ip->i_freef = NULL; - ip->i_freeb = NULL; - } - ip->i_count++; - ip->i_flag |= ILOCKED; + iq = ip->i_freef; + if (iq) + iq->i_freeb = ip->i_freeb; + else + ifreet = ip->i_freeb; + *ip->i_freeb = iq; + ip->i_freef = NULL; + ip->i_freeb = NULL; + } + ip->i_count++; + ip->i_flag |= ILOCKED; } /* @@ -252,59 +252,59 @@ igrab (ip) */ void iput (ip) - register struct inode *ip; + register struct inode *ip; { #ifdef notnow - /* - * This code requires a lot of workarounds, you have to change - * lots of places to gratuitously lock just so we can unlock it. - * Not worth it. -- KB - */ - if ((ip->i_flag & ILOCKED) == 0) - panic("iput"); + /* + * This code requires a lot of workarounds, you have to change + * lots of places to gratuitously lock just so we can unlock it. + * Not worth it. -- KB + */ + if ((ip->i_flag & ILOCKED) == 0) + panic("iput"); #endif - IUNLOCK(ip); - irele(ip); + IUNLOCK(ip); + irele(ip); } void irele (ip) - register struct inode *ip; + register struct inode *ip; { - if (ip->i_count == 1) { - ip->i_flag |= ILOCKED; - if (ip->i_nlink <= 0 && ip->i_fs->fs_ronly == 0) { - itrunc (ip, (u_long) 0, 0); - ip->i_mode = 0; - ip->i_rdev = 0; - ip->i_flag |= IUPD|ICHG; - ifree(ip, ip->i_number); - } - IUPDAT(ip, &time, &time, 0); - IUNLOCK(ip); - ip->i_flag = 0; - /* - * Put the inode on the end of the free list. - * Possibly in some cases it would be better to - * put the inode at the head of the free list, - * (eg: where i_mode == 0 || i_number == 0) - * but I will think about that later .. kre - * (i_number is rarely 0 - only after an i/o error in iget, - * where i_mode == 0, the inode will probably be wanted - * again soon for an ialloc, so possibly we should keep it) - */ - if (ifreeh) { - *ifreet = ip; - ip->i_freeb = ifreet; - } else { - ifreeh = ip; - ip->i_freeb = &ifreeh; - } - ip->i_freef = NULL; - ifreet = &ip->i_freef; - } else if (!(ip->i_flag & ILOCKED)) - ITIMES(ip, &time, &time); - ip->i_count--; + if (ip->i_count == 1) { + ip->i_flag |= ILOCKED; + if (ip->i_nlink <= 0 && ip->i_fs->fs_ronly == 0) { + itrunc (ip, (u_long) 0, 0); + ip->i_mode = 0; + ip->i_rdev = 0; + ip->i_flag |= IUPD|ICHG; + ifree(ip, ip->i_number); + } + IUPDAT(ip, &time, &time, 0); + IUNLOCK(ip); + ip->i_flag = 0; + /* + * Put the inode on the end of the free list. + * Possibly in some cases it would be better to + * put the inode at the head of the free list, + * (eg: where i_mode == 0 || i_number == 0) + * but I will think about that later .. kre + * (i_number is rarely 0 - only after an i/o error in iget, + * where i_mode == 0, the inode will probably be wanted + * again soon for an ialloc, so possibly we should keep it) + */ + if (ifreeh) { + *ifreet = ip; + ip->i_freeb = ifreet; + } else { + ifreeh = ip; + ip->i_freeb = &ifreeh; + } + ip->i_freef = NULL; + ifreet = &ip->i_freef; + } else if (!(ip->i_flag & ILOCKED)) + ITIMES(ip, &time, &time); + ip->i_count--; } /* @@ -317,60 +317,60 @@ irele (ip) */ void iupdat (ip, ta, tm, waitfor) - struct inode *ip; - struct timeval *ta, *tm; - int waitfor; + struct inode *ip; + struct timeval *ta, *tm; + int waitfor; { - register struct buf *bp; - register struct dinode *dp; - register struct inode *tip = ip; + register struct buf *bp; + register struct dinode *dp; + register struct inode *tip = ip; - if ((tip->i_flag & (IUPD|IACC|ICHG|IMOD)) == 0) - return; - if (tip->i_fs->fs_ronly) - return; - bp = bread(tip->i_dev, itod(tip->i_number)); - if (bp->b_flags & B_ERROR) { - brelse(bp); - return; - } - if (tip->i_flag&IACC) - tip->i_atime = ta->tv_sec; - if (tip->i_flag&IUPD) - tip->i_mtime = tm->tv_sec; - if (tip->i_flag&ICHG) - tip->i_ctime = time.tv_sec; - tip->i_flag &= ~(IUPD|IACC|ICHG|IMOD); - dp = (struct dinode*) bp->b_addr + itoo (tip->i_number); - dp->di_ic1 = tip->i_ic1; - dp->di_flags = tip->i_flags; - dp->di_ic2 = tip->i_ic2; - bcopy(ip->i_addr, dp->di_addr, NADDR * sizeof (daddr_t)); - if (waitfor && ((ip->i_fs->fs_flags & MNT_ASYNC) == 0)) - bwrite(bp); - else - bdwrite(bp); + if ((tip->i_flag & (IUPD|IACC|ICHG|IMOD)) == 0) + return; + if (tip->i_fs->fs_ronly) + return; + bp = bread(tip->i_dev, itod(tip->i_number)); + if (bp->b_flags & B_ERROR) { + brelse(bp); + return; + } + if (tip->i_flag&IACC) + tip->i_atime = ta->tv_sec; + if (tip->i_flag&IUPD) + tip->i_mtime = tm->tv_sec; + if (tip->i_flag&ICHG) + tip->i_ctime = time.tv_sec; + tip->i_flag &= ~(IUPD|IACC|ICHG|IMOD); + dp = (struct dinode*) bp->b_addr + itoo (tip->i_number); + dp->di_ic1 = tip->i_ic1; + dp->di_flags = tip->i_flags; + dp->di_ic2 = tip->i_ic2; + bcopy(ip->i_addr, dp->di_addr, NADDR * sizeof (daddr_t)); + if (waitfor && ((ip->i_fs->fs_flags & MNT_ASYNC) == 0)) + bwrite(bp); + else + bdwrite(bp); } -#define SINGLE 0 /* index of single indirect block */ -#define DOUBLE 1 /* index of double indirect block */ -#define TRIPLE 2 /* index of triple indirect block */ +#define SINGLE 0 /* index of single indirect block */ +#define DOUBLE 1 /* index of double indirect block */ +#define TRIPLE 2 /* index of triple indirect block */ static void trsingle (ip, bp, last, aflags) - register struct inode *ip; - struct buf *bp; - daddr_t last; - int aflags; + register struct inode *ip; + struct buf *bp; + daddr_t last; + int aflags; { - register const daddr_t *bstart, *bstop; - const daddr_t *blarray = (const daddr_t*) bp->b_addr; + register const daddr_t *bstart, *bstop; + const daddr_t *blarray = (const daddr_t*) bp->b_addr; - bstart = &blarray[NINDIR - 1]; - bstop = &blarray[last]; - for (; bstart > bstop; --bstart) - if (*bstart) - free (ip, *bstart); + bstart = &blarray[NINDIR - 1]; + bstop = &blarray[last]; + for (; bstart > bstop; --bstart) + if (*bstart) + free (ip, *bstart); } /* @@ -385,99 +385,99 @@ trsingle (ip, bp, last, aflags) */ void indirtrunc (ip, bn, lastbn, level, aflags) - struct inode *ip; - daddr_t bn, lastbn; - int level; - int aflags; + struct inode *ip; + daddr_t bn, lastbn; + int level; + int aflags; { - register struct buf *bp; - daddr_t nb, last; - long factor; + register struct buf *bp; + daddr_t nb, last; + long factor; - /* - * Calculate index in current block of last - * block to be kept. -1 indicates the entire - * block so we need not calculate the index. - */ - switch (level) { - default: - case SINGLE: - factor = 1; - break; - case DOUBLE: - factor = NINDIR; - break; - case TRIPLE: - factor = NINDIR * NINDIR; - break; - } - last = lastbn; - if (lastbn > 0) - last = last / factor; - /* - * Get buffer of block pointers, zero those - * entries corresponding to blocks to be free'd, - * and update on disk copy first. - */ - { - register daddr_t *bap; - register struct buf *cpy; + /* + * Calculate index in current block of last + * block to be kept. -1 indicates the entire + * block so we need not calculate the index. + */ + switch (level) { + default: + case SINGLE: + factor = 1; + break; + case DOUBLE: + factor = NINDIR; + break; + case TRIPLE: + factor = NINDIR * NINDIR; + break; + } + last = lastbn; + if (lastbn > 0) + last = last / factor; + /* + * Get buffer of block pointers, zero those + * entries corresponding to blocks to be free'd, + * and update on disk copy first. + */ + { + register daddr_t *bap; + register struct buf *cpy; - bp = bread(ip->i_dev, bn); - if (bp->b_flags&B_ERROR) { - brelse(bp); - return; - } - cpy = geteblk(); - bcopy (bp->b_addr, cpy->b_addr, DEV_BSIZE); - bap = (daddr_t*) bp->b_addr; - bzero((caddr_t)&bap[last + 1], - (u_int)(NINDIR - (last + 1)) * sizeof(daddr_t)); - if (aflags & B_SYNC) - bwrite(bp); - else - bawrite(bp); - bp = cpy; - } + bp = bread(ip->i_dev, bn); + if (bp->b_flags&B_ERROR) { + brelse(bp); + return; + } + cpy = geteblk(); + bcopy (bp->b_addr, cpy->b_addr, DEV_BSIZE); + bap = (daddr_t*) bp->b_addr; + bzero((caddr_t)&bap[last + 1], + (u_int)(NINDIR - (last + 1)) * sizeof(daddr_t)); + if (aflags & B_SYNC) + bwrite(bp); + else + bawrite(bp); + bp = cpy; + } - /* - * Optimized for single indirect blocks, i.e. until a file is - * greater than 4K + 256K you don't have to do a mapin/mapout - * for every entry. The mapin/mapout is required since free() - * may have to map an item in. Have to use another routine - * since it requires 1K of kernel stack to get around the problem - * and that doesn't work well with recursion. - */ - if (level == SINGLE) - trsingle (ip, bp, last, aflags); - else { - register daddr_t *bstart, *bstop; + /* + * Optimized for single indirect blocks, i.e. until a file is + * greater than 4K + 256K you don't have to do a mapin/mapout + * for every entry. The mapin/mapout is required since free() + * may have to map an item in. Have to use another routine + * since it requires 1K of kernel stack to get around the problem + * and that doesn't work well with recursion. + */ + if (level == SINGLE) + trsingle (ip, bp, last, aflags); + else { + register daddr_t *bstart, *bstop; - bstart = (daddr_t*) bp->b_addr; - bstop = &bstart[last]; - bstart += NINDIR - 1; - /* - * Recursively free totally unused blocks. - */ - for (;bstart > bstop;--bstart) { - nb = *bstart; - if (nb) { - indirtrunc(ip,nb,(daddr_t)-1, level-1, aflags); - free(ip, nb); - } - } + bstart = (daddr_t*) bp->b_addr; + bstop = &bstart[last]; + bstart += NINDIR - 1; + /* + * Recursively free totally unused blocks. + */ + for (;bstart > bstop;--bstart) { + nb = *bstart; + if (nb) { + indirtrunc(ip,nb,(daddr_t)-1, level-1, aflags); + free(ip, nb); + } + } - /* - * Recursively free last partial block. - */ - if (lastbn >= 0) { - nb = *bstop; - last = lastbn % factor; - if (nb != 0) - indirtrunc(ip, nb, last, level - 1, aflags); - } - } - brelse(bp); + /* + * Recursively free last partial block. + */ + if (lastbn >= 0) { + nb = *bstop; + last = lastbn % factor; + if (nb != 0) + indirtrunc(ip, nb, last, level - 1, aflags); + } + } + brelse(bp); } /* @@ -490,143 +490,143 @@ indirtrunc (ip, bn, lastbn, level, aflags) */ void itrunc (oip, length, ioflags) - register struct inode *oip; - u_long length; - int ioflags; + register struct inode *oip; + u_long length; + int ioflags; { - daddr_t lastblock; - register int i; - register struct inode *ip; - daddr_t bn, lastiblock[NIADDR]; - struct buf *bp; - int offset, level; - struct inode tip; - int aflags; + daddr_t lastblock; + register int i; + register struct inode *ip; + daddr_t bn, lastiblock[NIADDR]; + struct buf *bp; + int offset, level; + struct inode tip; + int aflags; - aflags = B_CLRBUF; - if (ioflags & IO_SYNC) - aflags |= B_SYNC; + aflags = B_CLRBUF; + if (ioflags & IO_SYNC) + aflags |= B_SYNC; - /* - * special hack for pipes, since size for them isn't the size of - * the file, it's the amount currently waiting for transfer. It's - * unclear that this will work, though, because pipes can (although - * rarely do) get bigger than MAXPIPSIZ. Don't think it worked - * in V7 either, I don't really understand what's going on. - */ - if (oip->i_flag & IPIPE) - oip->i_size = MAXPIPSIZ; - else if (oip->i_size == length) - goto updret; + /* + * special hack for pipes, since size for them isn't the size of + * the file, it's the amount currently waiting for transfer. It's + * unclear that this will work, though, because pipes can (although + * rarely do) get bigger than MAXPIPSIZ. Don't think it worked + * in V7 either, I don't really understand what's going on. + */ + if (oip->i_flag & IPIPE) + oip->i_size = MAXPIPSIZ; + else if (oip->i_size == length) + goto updret; - /* - * Lengthen the size of the file. We must ensure that the - * last byte of the file is allocated. Since the smallest - * value of osize is 0, length will be at least 1. - */ - if (oip->i_size < length) { - bn = bmap(oip, lblkno(length - 1), B_WRITE, aflags); - if (u.u_error || bn < 0) - return; - oip->i_size = length; - goto doquotaupd; - } + /* + * Lengthen the size of the file. We must ensure that the + * last byte of the file is allocated. Since the smallest + * value of osize is 0, length will be at least 1. + */ + if (oip->i_size < length) { + bn = bmap(oip, lblkno(length - 1), B_WRITE, aflags); + if (u.u_error || bn < 0) + return; + oip->i_size = length; + goto doquotaupd; + } - /* - * Calculate index into inode's block list of - * last direct and indirect blocks (if any) - * which we want to keep. Lastblock is -1 when - * the file is truncated to 0. - */ - lastblock = lblkno(length + DEV_BSIZE - 1) - 1; - lastiblock[SINGLE] = lastblock - NDADDR; - lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR; - lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR * NINDIR; - /* - * Update the size of the file. If the file is not being - * truncated to a block boundry, the contents of the - * partial block following the end of the file must be - * zero'ed in case it ever become accessable again because - * of subsequent file growth. - */ - offset = blkoff(length); - if (offset) { - bn = bmap(oip, lblkno(length), B_WRITE, aflags); - if (u.u_error || bn < 0) - return; - bp = bread(oip->i_dev, bn); - if (bp->b_flags & B_ERROR) { - u.u_error = EIO; - brelse(bp); - return; - } - bzero (bp->b_addr + offset, (u_int) (DEV_BSIZE - offset)); - bdwrite(bp); - } - /* - * Update file and block pointers - * on disk before we start freeing blocks. - * If we crash before free'ing blocks below, - * the blocks will be returned to the free list. - * lastiblock values are also normalized to -1 - * for calls to indirtrunc below. - */ - tip = *oip; - oip->i_size = length; - for (level = TRIPLE; level >= SINGLE; level--) - if (lastiblock[level] < 0) { - oip->i_ib[level] = 0; - lastiblock[level] = -1; - } - for (i = NDADDR - 1; i > lastblock; i--) - oip->i_db[i] = 0; + /* + * Calculate index into inode's block list of + * last direct and indirect blocks (if any) + * which we want to keep. Lastblock is -1 when + * the file is truncated to 0. + */ + lastblock = lblkno(length + DEV_BSIZE - 1) - 1; + lastiblock[SINGLE] = lastblock - NDADDR; + lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR; + lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR * NINDIR; + /* + * Update the size of the file. If the file is not being + * truncated to a block boundry, the contents of the + * partial block following the end of the file must be + * zero'ed in case it ever become accessable again because + * of subsequent file growth. + */ + offset = blkoff(length); + if (offset) { + bn = bmap(oip, lblkno(length), B_WRITE, aflags); + if (u.u_error || bn < 0) + return; + bp = bread(oip->i_dev, bn); + if (bp->b_flags & B_ERROR) { + u.u_error = EIO; + brelse(bp); + return; + } + bzero (bp->b_addr + offset, (u_int) (DEV_BSIZE - offset)); + bdwrite(bp); + } + /* + * Update file and block pointers + * on disk before we start freeing blocks. + * If we crash before free'ing blocks below, + * the blocks will be returned to the free list. + * lastiblock values are also normalized to -1 + * for calls to indirtrunc below. + */ + tip = *oip; + oip->i_size = length; + for (level = TRIPLE; level >= SINGLE; level--) + if (lastiblock[level] < 0) { + oip->i_ib[level] = 0; + lastiblock[level] = -1; + } + for (i = NDADDR - 1; i > lastblock; i--) + oip->i_db[i] = 0; - /* - * Indirect blocks first. - */ - ip = &tip; - for (level = TRIPLE; level >= SINGLE; level--) { - bn = ip->i_ib[level]; - if (bn != 0) { - indirtrunc(ip, bn, lastiblock[level], level, aflags); - if (lastiblock[level] < 0) { - ip->i_ib[level] = 0; - free(ip, bn); - } - } - if (lastiblock[level] >= 0) - goto done; - } + /* + * Indirect blocks first. + */ + ip = &tip; + for (level = TRIPLE; level >= SINGLE; level--) { + bn = ip->i_ib[level]; + if (bn != 0) { + indirtrunc(ip, bn, lastiblock[level], level, aflags); + if (lastiblock[level] < 0) { + ip->i_ib[level] = 0; + free(ip, bn); + } + } + if (lastiblock[level] >= 0) + goto done; + } - /* - * All whole direct blocks. - */ - for (i = NDADDR - 1; i > lastblock; i--) { - bn = ip->i_db[i]; - if (bn == 0) - continue; - ip->i_db[i] = 0; - free(ip, bn); - } - if (lastblock < 0) - goto done; + /* + * All whole direct blocks. + */ + for (i = NDADDR - 1; i > lastblock; i--) { + bn = ip->i_db[i]; + if (bn == 0) + continue; + ip->i_db[i] = 0; + free(ip, bn); + } + if (lastblock < 0) + goto done; done: #ifdef DIAGNOSTIC /* BEGIN PARANOIA */ - for (level = SINGLE; level <= TRIPLE; level++) - if (ip->i_ib[level] != oip->i_ib[level]) - panic("itrunc1"); - for (i = 0; i < NDADDR; i++) - if (ip->i_db[i] != oip->i_db[i]) - panic("itrunc2"); + for (level = SINGLE; level <= TRIPLE; level++) + if (ip->i_ib[level] != oip->i_ib[level]) + panic("itrunc1"); + for (i = 0; i < NDADDR; i++) + if (ip->i_db[i] != oip->i_db[i]) + panic("itrunc2"); /* END PARANOIA */ #endif doquotaupd: updret: - oip->i_flag |= ICHG|IUPD; - iupdat(oip, &time, &time, 1); + oip->i_flag |= ICHG|IUPD; + iupdat(oip, &time, &time, 1); } /* @@ -644,34 +644,34 @@ updret: */ int iflush (dev) - dev_t dev; + dev_t dev; { - register struct inode *ip; - register int open = 0; + register struct inode *ip; + register int open = 0; - for (ip = inode; ip < inode+NINODE; ip++) { - if (ip->i_dev == dev) - if (ip->i_count) - return(-1); - else { - remque(ip); - ip->i_forw = ip; - ip->i_back = ip; - /* - * as i_count == 0, the inode was on the free - * list already, just leave it there, it will - * fall off the bottom eventually. We could - * perhaps move it to the head of the free - * list, but as umounts are done so - * infrequently, we would gain very little, - * while making the code bigger. - */ - } - else if (ip->i_count && (ip->i_mode&IFMT)==IFBLK && - ip->i_rdev == dev) - open++; - } - return (open); + for (ip = inode; ip < inode+NINODE; ip++) { + if (ip->i_dev == dev) + if (ip->i_count) + return(-1); + else { + remque(ip); + ip->i_forw = ip; + ip->i_back = ip; + /* + * as i_count == 0, the inode was on the free + * list already, just leave it there, it will + * fall off the bottom eventually. We could + * perhaps move it to the head of the free + * list, but as umounts are done so + * infrequently, we would gain very little, + * while making the code bigger. + */ + } + else if (ip->i_count && (ip->i_mode&IFMT)==IFBLK && + ip->i_rdev == dev) + open++; + } + return (open); } /* @@ -679,9 +679,9 @@ iflush (dev) */ void ilock(ip) - register struct inode *ip; + register struct inode *ip; { - ILOCK(ip); + ILOCK(ip); } /* @@ -689,7 +689,7 @@ ilock(ip) */ void iunlock(ip) - register struct inode *ip; + register struct inode *ip; { - IUNLOCK(ip); + IUNLOCK(ip); } diff --git a/sys/kernel/ufs_mount.c b/sys/kernel/ufs_mount.c index c87cde5..0e2f91b 100644 --- a/sys/kernel/ufs_mount.c +++ b/sys/kernel/ufs_mount.c @@ -24,150 +24,150 @@ */ static int getmdev (pdev, fname) - caddr_t fname; - dev_t *pdev; + caddr_t fname; + dev_t *pdev; { - register dev_t dev; - register struct inode *ip; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register dev_t dev; + register struct inode *ip; + struct nameidata nd; + register struct nameidata *ndp = &nd; - if (!suser()) - return (u.u_error); - NDINIT (ndp, LOOKUP, FOLLOW, fname); - ip = namei(ndp); - if (ip == NULL) { - if (u.u_error == ENOENT) - return (ENODEV); /* needs translation */ - return (u.u_error); - } - if ((ip->i_mode&IFMT) != IFBLK) { - iput(ip); - return (ENOTBLK); - } - dev = (dev_t)ip->i_rdev; - iput(ip); - if (major(dev) >= nblkdev) - return (ENXIO); - *pdev = dev; - return (0); + if (!suser()) + return (u.u_error); + NDINIT (ndp, LOOKUP, FOLLOW, fname); + ip = namei(ndp); + if (ip == NULL) { + if (u.u_error == ENOENT) + return (ENODEV); /* needs translation */ + return (u.u_error); + } + if ((ip->i_mode&IFMT) != IFBLK) { + iput(ip); + return (ENOTBLK); + } + dev = (dev_t)ip->i_rdev; + iput(ip); + if (major(dev) >= nblkdev) + return (ENXIO); + *pdev = dev; + return (0); } void mount_updname (fs, on, from, lenon, lenfrom) - struct fs *fs; - char *on, *from; - int lenon, lenfrom; + struct fs *fs; + char *on, *from; + int lenon, lenfrom; { - struct mount *mp; + struct mount *mp; - bzero (fs->fs_fsmnt, sizeof (fs->fs_fsmnt)); - bcopy (on, fs->fs_fsmnt, sizeof (fs->fs_fsmnt) - 1); - mp = (struct mount*) ((int) fs - offsetof (struct mount, m_filsys)); - bzero (mp->m_mnton, sizeof (mp->m_mnton)); - bzero (mp->m_mntfrom, sizeof (mp->m_mntfrom)); - bcopy (on, mp->m_mnton, lenon); - bcopy (from, mp->m_mntfrom, lenfrom); + bzero (fs->fs_fsmnt, sizeof (fs->fs_fsmnt)); + bcopy (on, fs->fs_fsmnt, sizeof (fs->fs_fsmnt) - 1); + mp = (struct mount*) ((int) fs - offsetof (struct mount, m_filsys)); + bzero (mp->m_mnton, sizeof (mp->m_mnton)); + bzero (mp->m_mntfrom, sizeof (mp->m_mntfrom)); + bcopy (on, mp->m_mnton, lenon); + bcopy (from, mp->m_mntfrom, lenfrom); } void smount() { - register struct a { - char *fspec; - char *freg; - int flags; - } *uap = (struct a *)u.u_arg; - dev_t dev = 0; - register struct inode *ip; - register struct fs *fs; - struct nameidata nd; - struct nameidata *ndp = &nd; - struct mount *mp; - u_int lenon, lenfrom; - int error = 0; - char mnton[MNAMELEN], mntfrom[MNAMELEN]; + register struct a { + char *fspec; + char *freg; + int flags; + } *uap = (struct a *)u.u_arg; + dev_t dev = 0; + register struct inode *ip; + register struct fs *fs; + struct nameidata nd; + struct nameidata *ndp = &nd; + struct mount *mp; + u_int lenon, lenfrom; + int error = 0; + char mnton[MNAMELEN], mntfrom[MNAMELEN]; - u.u_error = getmdev (&dev, uap->fspec); - if (u.u_error) - return; - NDINIT (ndp, LOOKUP, FOLLOW, uap->freg); - if ((ip = namei(ndp)) == NULL) - return; - if ((ip->i_mode&IFMT) != IFDIR) { - error = ENOTDIR; - goto cmnout; - } - copystr (uap->freg, mnton, sizeof (mnton) - 1, &lenon); - copystr (uap->fspec, mntfrom, sizeof (mntfrom) - 1, &lenfrom); + u.u_error = getmdev (&dev, uap->fspec); + if (u.u_error) + return; + NDINIT (ndp, LOOKUP, FOLLOW, uap->freg); + if ((ip = namei(ndp)) == NULL) + return; + if ((ip->i_mode&IFMT) != IFDIR) { + error = ENOTDIR; + goto cmnout; + } + copystr (uap->freg, mnton, sizeof (mnton) - 1, &lenon); + copystr (uap->fspec, mntfrom, sizeof (mntfrom) - 1, &lenfrom); - if (uap->flags & MNT_UPDATE) { - fs = ip->i_fs; - mp = (struct mount *) - ((int)fs - offsetof(struct mount, m_filsys)); - if (ip->i_number != ROOTINO) { - error = EINVAL; /* Not a mount point */ - goto cmnout; - } - /* - * Check that the device passed in is the same one that is in the mount - * table entry for this mount point. - */ - if (dev != mp->m_dev) { - error = EINVAL; /* not right mount point */ - goto cmnout; - } - /* - * This is where the RW to RO transformation would be done. It is, for now, - * too much work to port pages of code to do (besides which most - * programs get very upset at having access yanked out from under them). - */ - if (fs->fs_ronly == 0 && (uap->flags & MNT_RDONLY)) { - error = EPERM; /* ! RW to RO updates */ - goto cmnout; - } - /* - * However, going from RO to RW is easy. Then merge in the new - * flags (async, sync, nodev, etc) passed in from the program. - */ - if (fs->fs_ronly && ((uap->flags & MNT_RDONLY) == 0)) { - fs->fs_ronly = 0; - mp->m_flags &= ~MNT_RDONLY; - } -#define _MF (MNT_NOSUID | MNT_NODEV | MNT_NOEXEC | MNT_ASYNC | MNT_SYNCHRONOUS | MNT_NOATIME) - mp->m_flags &= ~_MF; - mp->m_flags |= (uap->flags & _MF); + if (uap->flags & MNT_UPDATE) { + fs = ip->i_fs; + mp = (struct mount *) + ((int)fs - offsetof(struct mount, m_filsys)); + if (ip->i_number != ROOTINO) { + error = EINVAL; /* Not a mount point */ + goto cmnout; + } + /* + * Check that the device passed in is the same one that is in the mount + * table entry for this mount point. + */ + if (dev != mp->m_dev) { + error = EINVAL; /* not right mount point */ + goto cmnout; + } + /* + * This is where the RW to RO transformation would be done. It is, for now, + * too much work to port pages of code to do (besides which most + * programs get very upset at having access yanked out from under them). + */ + if (fs->fs_ronly == 0 && (uap->flags & MNT_RDONLY)) { + error = EPERM; /* ! RW to RO updates */ + goto cmnout; + } + /* + * However, going from RO to RW is easy. Then merge in the new + * flags (async, sync, nodev, etc) passed in from the program. + */ + if (fs->fs_ronly && ((uap->flags & MNT_RDONLY) == 0)) { + fs->fs_ronly = 0; + mp->m_flags &= ~MNT_RDONLY; + } +#define _MF (MNT_NOSUID | MNT_NODEV | MNT_NOEXEC | MNT_ASYNC | MNT_SYNCHRONOUS | MNT_NOATIME) + mp->m_flags &= ~_MF; + mp->m_flags |= (uap->flags & _MF); #undef _MF - iput(ip); - u.u_error = 0; - goto updname; - } else { - /* - * This is where a new mount (not an update of an existing mount point) is - * done. - * - * The directory being mounted on can have no other references AND can not - * currently be a mount point. Mount points have an inode number of (you - * guessed it) ROOTINO which is 2. - */ - if (ip->i_count != 1 || (ip->i_number == ROOTINO)) { - error = EBUSY; - goto cmnout; - } - fs = mountfs (dev, uap->flags, ip); - if (fs == 0) - return; - } - /* - * Lastly, both for new mounts and updates of existing mounts, update the - * mounted-on and mounted-from fields. - */ + iput(ip); + u.u_error = 0; + goto updname; + } else { + /* + * This is where a new mount (not an update of an existing mount point) is + * done. + * + * The directory being mounted on can have no other references AND can not + * currently be a mount point. Mount points have an inode number of (you + * guessed it) ROOTINO which is 2. + */ + if (ip->i_count != 1 || (ip->i_number == ROOTINO)) { + error = EBUSY; + goto cmnout; + } + fs = mountfs (dev, uap->flags, ip); + if (fs == 0) + return; + } + /* + * Lastly, both for new mounts and updates of existing mounts, update the + * mounted-on and mounted-from fields. + */ updname: - mount_updname(fs, mnton, mntfrom, lenon, lenfrom); - return; + mount_updname(fs, mnton, mntfrom, lenon, lenfrom); + return; cmnout: - iput(ip); - u.u_error = error; + iput(ip); + u.u_error = error; } /* @@ -177,125 +177,125 @@ cmnout: */ struct fs * mountfs (dev, flags, ip) - dev_t dev; - int flags; - struct inode *ip; + dev_t dev; + int flags; + struct inode *ip; { - register struct mount *mp = 0; - struct buf *tp = 0; - register struct fs *fs; - register int error; - int ronly = flags & MNT_RDONLY; - int needclose = 0; + register struct mount *mp = 0; + struct buf *tp = 0; + register struct fs *fs; + register int error; + int ronly = flags & MNT_RDONLY; + int needclose = 0; - error = (*bdevsw[major(dev)].d_open) (dev, - ronly ? FREAD : (FREAD | FWRITE), S_IFBLK); - if (error) - goto out; + error = (*bdevsw[major(dev)].d_open) (dev, + ronly ? FREAD : (FREAD | FWRITE), S_IFBLK); + if (error) + goto out; - needclose = 1; - tp = bread (dev, SUPERB); - if (tp->b_flags & B_ERROR) - goto out; - for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) - if (mp->m_inodp != 0 && dev == mp->m_dev) { - mp = 0; - error = EBUSY; - needclose = 0; - goto out; - } - for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) - if (mp->m_inodp == 0) - goto found; - mp = 0; - error = EMFILE; /* needs translation */ - goto out; + needclose = 1; + tp = bread (dev, SUPERB); + if (tp->b_flags & B_ERROR) + goto out; + for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) + if (mp->m_inodp != 0 && dev == mp->m_dev) { + mp = 0; + error = EBUSY; + needclose = 0; + goto out; + } + for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) + if (mp->m_inodp == 0) + goto found; + mp = 0; + error = EMFILE; /* needs translation */ + goto out; found: - mp->m_inodp = ip; /* reserve slot */ - mp->m_dev = dev; - fs = &mp->m_filsys; - bcopy (tp->b_addr, (caddr_t)fs, sizeof(struct fs)); - brelse (tp); - tp = 0; - if (fs->fs_magic1 != FSMAGIC1 || fs->fs_magic2 != FSMAGIC2) { - error = EINVAL; - goto out; - } - fs->fs_ronly = (ronly != 0); - if (ronly == 0) - fs->fs_fmod = 1; - fs->fs_ilock = 0; - fs->fs_flock = 0; - fs->fs_nbehind = 0; - fs->fs_lasti = 1; - fs->fs_flags = flags; - if (ip) { - ip->i_flag |= IMOUNT; - cacheinval(ip); - IUNLOCK(ip); - } - return (fs); + mp->m_inodp = ip; /* reserve slot */ + mp->m_dev = dev; + fs = &mp->m_filsys; + bcopy (tp->b_addr, (caddr_t)fs, sizeof(struct fs)); + brelse (tp); + tp = 0; + if (fs->fs_magic1 != FSMAGIC1 || fs->fs_magic2 != FSMAGIC2) { + error = EINVAL; + goto out; + } + fs->fs_ronly = (ronly != 0); + if (ronly == 0) + fs->fs_fmod = 1; + fs->fs_ilock = 0; + fs->fs_flock = 0; + fs->fs_nbehind = 0; + fs->fs_lasti = 1; + fs->fs_flags = flags; + if (ip) { + ip->i_flag |= IMOUNT; + cacheinval(ip); + IUNLOCK(ip); + } + return (fs); out: - if (error == 0) - error = EIO; - if (ip) - iput(ip); - if (mp) - mp->m_inodp = 0; - if (tp) - brelse(tp); - if (needclose) { - (*bdevsw[major(dev)].d_close)(dev, - ronly? FREAD : FREAD|FWRITE, S_IFBLK); - binval(dev); - } - u.u_error = error; - return (0); + if (error == 0) + error = EIO; + if (ip) + iput(ip); + if (mp) + mp->m_inodp = 0; + if (tp) + brelse(tp); + if (needclose) { + (*bdevsw[major(dev)].d_close)(dev, + ronly? FREAD : FREAD|FWRITE, S_IFBLK); + binval(dev); + } + u.u_error = error; + return (0); } static int unmount1 (fname) - caddr_t fname; + caddr_t fname; { - dev_t dev = 0; - register struct mount *mp; - register struct inode *ip; - register int error; - int aflag; + dev_t dev = 0; + register struct mount *mp; + register struct inode *ip; + register int error; + int aflag; - error = getmdev(&dev, fname); - if (error) - return (error); - for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) - if (mp->m_inodp != NULL && dev == mp->m_dev) - goto found; - return (EINVAL); + error = getmdev(&dev, fname); + if (error) + return (error); + for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) + if (mp->m_inodp != NULL && dev == mp->m_dev) + goto found; + return (EINVAL); found: - nchinval (dev); /* flush the name cache */ - aflag = mp->m_flags & MNT_ASYNC; - mp->m_flags &= ~MNT_ASYNC; /* Don't want async when unmounting */ - ufs_sync(mp); + nchinval (dev); /* flush the name cache */ + aflag = mp->m_flags & MNT_ASYNC; + mp->m_flags &= ~MNT_ASYNC; /* Don't want async when unmounting */ + ufs_sync(mp); - if (iflush(dev) < 0) { - mp->m_flags |= aflag; - return (EBUSY); - } - ip = mp->m_inodp; - ip->i_flag &= ~IMOUNT; - irele(ip); - mp->m_inodp = 0; - mp->m_dev = 0; - (*bdevsw[major(dev)].d_close)(dev, 0, S_IFBLK); - binval(dev); - return (0); + if (iflush(dev) < 0) { + mp->m_flags |= aflag; + return (EBUSY); + } + ip = mp->m_inodp; + ip->i_flag &= ~IMOUNT; + irele(ip); + mp->m_inodp = 0; + mp->m_dev = 0; + (*bdevsw[major(dev)].d_close)(dev, 0, S_IFBLK); + binval(dev); + return (0); } void umount() { - struct a { - char *fspec; - } *uap = (struct a *)u.u_arg; + struct a { + char *fspec; + } *uap = (struct a *)u.u_arg; - u.u_error = unmount1 (uap->fspec); + u.u_error = unmount1 (uap->fspec); } diff --git a/sys/kernel/ufs_namei.c b/sys/kernel/ufs_namei.c index f881ed5..905a651 100644 --- a/sys/kernel/ufs_namei.c +++ b/sys/kernel/ufs_namei.c @@ -14,36 +14,37 @@ #include "namei.h" #include "proc.h" -int dirchk = 0; +int dirchk = 0; /* * Structures associated with name cacheing. */ -#define NCHHASH 16 /* size of hash table */ +#define NCHHASH 16 /* size of hash table */ -#if ((NCHHASH)&((NCHHASH)-1)) != 0 -#define NHASH(h, i, d) ((unsigned)((h) + (i) + 13 * (int)(d)) % (NCHHASH)) +#if ((NCHHASH)&((NCHHASH)-1)) != 0 +#define NHASH(h, i, d) ((unsigned)((h) + (i) + 13 * (int)(d)) % (NCHHASH)) #else -#define NHASH(h, i, d) ((unsigned)((h) + (i) + 13 * (int)(d)) & ((NCHHASH)-1)) +#define NHASH(h, i, d) ((unsigned)((h) + (i) + 13 * (int)(d)) & ((NCHHASH)-1)) #endif union nchash { - union nchash *nch_head[2]; - struct namecache *nch_chain[2]; + union nchash *nch_head[2]; + struct namecache *nch_chain[2]; } nchash[NCHHASH]; -#define nch_forw nch_chain[0] -#define nch_back nch_chain[1] -struct namecache *nchhead, **nchtail; /* LRU chain pointers */ +#define nch_forw nch_chain[0] +#define nch_back nch_chain[1] + +struct namecache *nchhead, **nchtail; /* LRU chain pointers */ static void dirbad (ip, offset, how) - struct inode *ip; - off_t offset; - char *how; + struct inode *ip; + off_t offset; + char *how; { - printf ("%s: bad dir I=%u off %ld: %s\n", - ip->i_fs->fs_fsmnt, ip->i_number, offset, how); + printf ("%s: bad dir I=%u off %ld: %s\n", + ip->i_fs->fs_fsmnt, ip->i_number, offset, how); } /* @@ -54,56 +55,56 @@ dirbad (ip, offset, how) */ static struct buf * blkatoff(ip, offset, res) - struct inode *ip; - off_t offset; - char **res; + struct inode *ip; + off_t offset; + char **res; { - daddr_t lbn = lblkno(offset); - register struct buf *bp; - daddr_t bn; - char *junk; + daddr_t lbn = lblkno(offset); + register struct buf *bp; + daddr_t bn; + char *junk; - bn = bmap(ip, lbn, B_READ, 0); - if (u.u_error) - return (0); - if (bn == (daddr_t)-1) { - dirbad(ip, offset, "hole in dir"); - return (0); - } - bp = bread(ip->i_dev, bn); - if (bp->b_flags & B_ERROR) { - brelse(bp); - return (0); - } - junk = (caddr_t) bp->b_addr; - if (res) - *res = junk + (u_int)blkoff(offset); - return (bp); + bn = bmap(ip, lbn, B_READ, 0); + if (u.u_error) + return (0); + if (bn == (daddr_t)-1) { + dirbad(ip, offset, "hole in dir"); + return (0); + } + bp = bread(ip->i_dev, bn); + if (bp->b_flags & B_ERROR) { + brelse(bp); + return (0); + } + junk = (caddr_t) bp->b_addr; + if (res) + *res = junk + (u_int)blkoff(offset); + return (bp); } /* * Do consistency checking on a directory entry: - * record length must be multiple of 4 - * entry must fit in rest of its DIRBLKSIZ block - * record must be large enough to contain entry - * name is not longer than MAXNAMLEN - * name must be as long as advertised, and null terminated + * record length must be multiple of 4 + * entry must fit in rest of its DIRBLKSIZ block + * record must be large enough to contain entry + * name is not longer than MAXNAMLEN + * name must be as long as advertised, and null terminated */ static int dirbadentry (ep, entryoffsetinblock) - register struct direct *ep; - int entryoffsetinblock; + register struct direct *ep; + int entryoffsetinblock; { - register int i; + register int i; - if ((ep->d_reclen & 0x3) != 0 || - ep->d_reclen > DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)) || - ep->d_reclen < DIRSIZ(ep) || ep->d_namlen > MAXNAMLEN) - return (1); - for (i = 0; i < ep->d_namlen; i++) - if (ep->d_name[i] == '\0') - return (1); - return (ep->d_name[i]); + if ((ep->d_reclen & 0x3) != 0 || + ep->d_reclen > DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)) || + ep->d_reclen < DIRSIZ(ep) || ep->d_namlen > MAXNAMLEN) + return (1); + for (i = 0; i < ep->d_namlen; i++) + if (ep->d_name[i] == '\0') + return (1); + return (ep->d_name[i]); } /* @@ -145,744 +146,744 @@ dirbadentry (ep, entryoffsetinblock) * * Overall outline of namei: * - * copy in name - * get starting directory + * copy in name + * get starting directory * dirloop: - * check accessibility of directory + * check accessibility of directory * dirloop2: - * copy next component of name to ndp->ni_dent - * handle degenerate case where name is null string - * look for name in cache, if found, then if at end of path - * and deleting or creating, drop it, else to haveino - * search for name in directory, to found or notfound + * copy next component of name to ndp->ni_dent + * handle degenerate case where name is null string + * look for name in cache, if found, then if at end of path + * and deleting or creating, drop it, else to haveino + * search for name in directory, to found or notfound * notfound: - * if creating, return locked directory, leaving info on avail. slots - * else return error + * if creating, return locked directory, leaving info on avail. slots + * else return error * found: - * if at end of path and deleting, return information to allow delete - * if at end of path and rewriting (CREATE and LOCKPARENT), lock target - * inode and return info to allow rewrite - * if .. and on mounted filesys, look in mount table for parent - * if not at end, add name to cache; if at end and neither creating - * nor deleting, add name to cache + * if at end of path and deleting, return information to allow delete + * if at end of path and rewriting (CREATE and LOCKPARENT), lock target + * inode and return info to allow rewrite + * if .. and on mounted filesys, look in mount table for parent + * if not at end, add name to cache; if at end and neither creating + * nor deleting, add name to cache * haveino: - * if symbolic link, massage name in buffer and continue at dirloop - * if more components of name, do next level at dirloop - * return the answer as locked inode + * if symbolic link, massage name in buffer and continue at dirloop + * if more components of name, do next level at dirloop + * return the answer as locked inode * * NOTE: (LOOKUP | LOCKPARENT) currently returns the parent inode, - * but unlocked. + * but unlocked. */ struct inode * namei (ndp) - register struct nameidata *ndp; + register struct nameidata *ndp; { - register char *cp; /* pointer into pathname argument */ + register char *cp; /* pointer into pathname argument */ /* these variables refer to things which must be freed or unlocked */ - struct inode *dp = 0; /* the directory we are searching */ - struct namecache *ncp = 0; /* cache slot for entry */ - struct fs *fs; /* file system that directory is in */ - struct buf *bp = 0; /* a buffer of directory entries */ - struct direct *ep; /* the current directory entry */ - int entryoffsetinblock = 0; /* offset of ep in bp's buffer */ + struct inode *dp = 0; /* the directory we are searching */ + struct namecache *ncp = 0; /* cache slot for entry */ + struct fs *fs; /* file system that directory is in */ + struct buf *bp = 0; /* a buffer of directory entries */ + struct direct *ep; /* the current directory entry */ + int entryoffsetinblock = 0; /* offset of ep in bp's buffer */ /* these variables hold information about the search for a slot */ - enum {NONE, COMPACT, FOUND} slotstatus; - off_t slotoffset = -1; /* offset of area with free space */ - int slotsize = 0; /* size of area at slotoffset */ - int slotfreespace = 0; /* amount of space free in slot */ - int slotneeded = 0; /* size of the entry we're seeking */ + enum {NONE, COMPACT, FOUND} slotstatus; + off_t slotoffset = -1; /* offset of area with free space */ + int slotsize = 0; /* size of area at slotoffset */ + int slotfreespace = 0; /* amount of space free in slot */ + int slotneeded = 0; /* size of the entry we're seeking */ /* */ - int numdirpasses; /* strategy for directory search */ - off_t endsearch; /* offset to end directory search */ - off_t prevoff = 0; /* ndp->ni_offset of previous entry */ - int nlink = 0; /* number of symbolic links taken */ - struct inode *pdp; /* saved dp during symlink work */ - register int i; - int error; - int lockparent; - int docache; /* == 0 do not cache last component */ - int makeentry; /* != 0 if name to be added to cache */ - unsigned hash; /* value of name hash for entry */ - union nchash *nhp = 0; /* cache chain head for entry */ - int isdotdot; /* != 0 if current name is ".." */ - int flag; /* op ie, LOOKUP, CREATE, or DELETE */ - off_t enduseful; /* pointer past last used dir slot */ - char path[MAXPATHLEN]; /* current path */ + int numdirpasses; /* strategy for directory search */ + off_t endsearch; /* offset to end directory search */ + off_t prevoff = 0; /* ndp->ni_offset of previous entry */ + int nlink = 0; /* number of symbolic links taken */ + struct inode *pdp; /* saved dp during symlink work */ + register int i; + int error; + int lockparent; + int docache; /* == 0 do not cache last component */ + int makeentry; /* != 0 if name to be added to cache */ + unsigned hash; /* value of name hash for entry */ + union nchash *nhp = 0; /* cache chain head for entry */ + int isdotdot; /* != 0 if current name is ".." */ + int flag; /* op ie, LOOKUP, CREATE, or DELETE */ + off_t enduseful; /* pointer past last used dir slot */ + char path[MAXPATHLEN]; /* current path */ - lockparent = ndp->ni_nameiop & LOCKPARENT; - docache = (ndp->ni_nameiop & NOCACHE) ^ NOCACHE; - flag = ndp->ni_nameiop &~ (LOCKPARENT|NOCACHE|FOLLOW); - if (flag == DELETE || lockparent) - docache = 0; - /* - * Copy the name into the buffer. - */ - error = copystr (ndp->ni_dirp, path, MAXPATHLEN, (u_int*) 0); - if (error) { - u.u_error = error; - goto retNULL; - } + lockparent = ndp->ni_nameiop & LOCKPARENT; + docache = (ndp->ni_nameiop & NOCACHE) ^ NOCACHE; + flag = ndp->ni_nameiop &~ (LOCKPARENT|NOCACHE|FOLLOW); + if (flag == DELETE || lockparent) + docache = 0; + /* + * Copy the name into the buffer. + */ + error = copystr (ndp->ni_dirp, path, MAXPATHLEN, (u_int*) 0); + if (error) { + u.u_error = error; + goto retNULL; + } - /* - * Get starting directory. - */ - cp = path; - if (*cp == '/') { - while (*cp == '/') - cp++; - if ((dp = u.u_rdir) == NULL) - dp = rootdir; - } else - dp = u.u_cdir; - fs = dp->i_fs; - ILOCK(dp); - dp->i_count++; - ndp->ni_endoff = 0; + /* + * Get starting directory. + */ + cp = path; + if (*cp == '/') { + while (*cp == '/') + cp++; + if ((dp = u.u_rdir) == NULL) + dp = rootdir; + } else + dp = u.u_cdir; + fs = dp->i_fs; + ILOCK(dp); + dp->i_count++; + ndp->ni_endoff = 0; - /* - * We come to dirloop to search a new directory. - * The directory must be locked so that it can be - * iput, and fs must be already set to dp->i_fs. - */ + /* + * We come to dirloop to search a new directory. + * The directory must be locked so that it can be + * iput, and fs must be already set to dp->i_fs. + */ dirloop: - /* - * Check accessibility of directory. - */ - if ((dp->i_mode&IFMT) != IFDIR) { - u.u_error = ENOTDIR; - goto bad; - } - if (access(dp, IEXEC)) - goto bad; + /* + * Check accessibility of directory. + */ + if ((dp->i_mode&IFMT) != IFDIR) { + u.u_error = ENOTDIR; + goto bad; + } + if (access(dp, IEXEC)) + goto bad; dirloop2: - /* - * Copy next component of name to ndp->ni_dent. - */ - hash = 0; - for (i = 0; *cp != 0 && *cp != '/'; cp++) { - if (i >= MAXNAMLEN) { - u.u_error = ENAMETOOLONG; - goto bad; - } - if (*cp & 0200) - if ((*cp&0377) == ('/'|0200) || flag != DELETE) { - u.u_error = EINVAL; - goto bad; - } - ndp->ni_dent.d_name[i++] = *cp; - hash += (unsigned char)*cp * i; - } - ndp->ni_dent.d_namlen = i; - ndp->ni_dent.d_name[i] = '\0'; - isdotdot = (i == 2 && - ndp->ni_dent.d_name[0] == '.' && ndp->ni_dent.d_name[1] == '.'); - makeentry = 1; - if (*cp == '\0' && docache == 0) - makeentry = 0; + /* + * Copy next component of name to ndp->ni_dent. + */ + hash = 0; + for (i = 0; *cp != 0 && *cp != '/'; cp++) { + if (i >= MAXNAMLEN) { + u.u_error = ENAMETOOLONG; + goto bad; + } + if (*cp & 0200) + if ((*cp&0377) == ('/'|0200) || flag != DELETE) { + u.u_error = EINVAL; + goto bad; + } + ndp->ni_dent.d_name[i++] = *cp; + hash += (unsigned char)*cp * i; + } + ndp->ni_dent.d_namlen = i; + ndp->ni_dent.d_name[i] = '\0'; + isdotdot = (i == 2 && + ndp->ni_dent.d_name[0] == '.' && ndp->ni_dent.d_name[1] == '.'); + makeentry = 1; + if (*cp == '\0' && docache == 0) + makeentry = 0; - /* - * Check for degenerate name (e.g. / or "") - * which is a way of talking about a directory, - * e.g. like "/." or ".". - */ - if (ndp->ni_dent.d_name[0] == '\0') { - if (flag != LOOKUP || lockparent) { - u.u_error = EISDIR; - goto bad; - } - goto retDP; - } + /* + * Check for degenerate name (e.g. / or "") + * which is a way of talking about a directory, + * e.g. like "/." or ".". + */ + if (ndp->ni_dent.d_name[0] == '\0') { + if (flag != LOOKUP || lockparent) { + u.u_error = EISDIR; + goto bad; + } + goto retDP; + } - /* - * We now have a segment name to search for, and a directory to search. - * - * Before tediously performing a linear scan of the directory, - * check the name cache to see if the directory/name pair - * we are looking for is known already. We don't do this - * if the segment name is long, simply so the cache can avoid - * holding long names (which would either waste space, or - * add greatly to the complexity). - */ - if (ndp->ni_dent.d_namlen > NCHNAMLEN) { - nchstats.ncs_long++; - makeentry = 0; - } else { - nhp = &nchash[NHASH(hash, dp->i_number, dp->i_dev)]; - for (ncp = nhp->nch_forw; ncp != (struct namecache *)nhp; - ncp = ncp->nc_forw) { - if (ncp->nc_ino == dp->i_number && - ncp->nc_dev == dp->i_dev && - ncp->nc_nlen == ndp->ni_dent.d_namlen && - !bcmp(ncp->nc_name, ndp->ni_dent.d_name, - (unsigned)ncp->nc_nlen)) - break; - } - if (ncp == (struct namecache *)nhp) { - nchstats.ncs_miss++; - ncp = NULL; - } else { - if (ncp->nc_id != ncp->nc_ip->i_id) - nchstats.ncs_falsehits++; - else if (!makeentry) - nchstats.ncs_badhits++; - else { - /* - * move this slot to end of LRU - * chain, if not already there - */ - if (ncp->nc_nxt) { - /* remove from LRU chain */ - *ncp->nc_prev = ncp->nc_nxt; - ncp->nc_nxt->nc_prev = ncp->nc_prev; + /* + * We now have a segment name to search for, and a directory to search. + * + * Before tediously performing a linear scan of the directory, + * check the name cache to see if the directory/name pair + * we are looking for is known already. We don't do this + * if the segment name is long, simply so the cache can avoid + * holding long names (which would either waste space, or + * add greatly to the complexity). + */ + if (ndp->ni_dent.d_namlen > NCHNAMLEN) { + nchstats.ncs_long++; + makeentry = 0; + } else { + nhp = &nchash[NHASH(hash, dp->i_number, dp->i_dev)]; + for (ncp = nhp->nch_forw; ncp != (struct namecache *)nhp; + ncp = ncp->nc_forw) { + if (ncp->nc_ino == dp->i_number && + ncp->nc_dev == dp->i_dev && + ncp->nc_nlen == ndp->ni_dent.d_namlen && + !bcmp(ncp->nc_name, ndp->ni_dent.d_name, + (unsigned)ncp->nc_nlen)) + break; + } + if (ncp == (struct namecache *)nhp) { + nchstats.ncs_miss++; + ncp = NULL; + } else { + if (ncp->nc_id != ncp->nc_ip->i_id) + nchstats.ncs_falsehits++; + else if (!makeentry) + nchstats.ncs_badhits++; + else { + /* + * move this slot to end of LRU + * chain, if not already there + */ + if (ncp->nc_nxt) { + /* remove from LRU chain */ + *ncp->nc_prev = ncp->nc_nxt; + ncp->nc_nxt->nc_prev = ncp->nc_prev; - /* and replace at end of it */ - ncp->nc_nxt = NULL; - ncp->nc_prev = nchtail; - *nchtail = ncp; - nchtail = &ncp->nc_nxt; - } + /* and replace at end of it */ + ncp->nc_nxt = NULL; + ncp->nc_prev = nchtail; + *nchtail = ncp; + nchtail = &ncp->nc_nxt; + } - /* - * Get the next inode in the path. - * See comment above other `IUNLOCK' code for - * an explaination of the locking protocol. - */ - pdp = dp; - if (!isdotdot || dp != u.u_rdir) - dp = ncp->nc_ip; - if (dp == NULL) - panic("namei: null cache ino"); - if (pdp == dp) - dp->i_count++; - else if (isdotdot) { - IUNLOCK(pdp); - igrab(dp); - } else { - igrab(dp); - IUNLOCK(pdp); - } + /* + * Get the next inode in the path. + * See comment above other `IUNLOCK' code for + * an explaination of the locking protocol. + */ + pdp = dp; + if (!isdotdot || dp != u.u_rdir) + dp = ncp->nc_ip; + if (dp == NULL) + panic("namei: null cache ino"); + if (pdp == dp) + dp->i_count++; + else if (isdotdot) { + IUNLOCK(pdp); + igrab(dp); + } else { + igrab(dp); + IUNLOCK(pdp); + } - /* - * Verify that the inode that we got - * did not change while we were waiting - * for it to be locked. - */ - if (ncp->nc_id != ncp->nc_ip->i_id) { - iput(dp); - ILOCK(pdp); - dp = pdp; - nchstats.ncs_falsehits++; - } else { - ndp->ni_dent.d_ino = dp->i_number; - /* ni_dent.d_reclen is garbage ... */ - nchstats.ncs_goodhits++; - goto haveino; - } - } + /* + * Verify that the inode that we got + * did not change while we were waiting + * for it to be locked. + */ + if (ncp->nc_id != ncp->nc_ip->i_id) { + iput(dp); + ILOCK(pdp); + dp = pdp; + nchstats.ncs_falsehits++; + } else { + ndp->ni_dent.d_ino = dp->i_number; + /* ni_dent.d_reclen is garbage ... */ + nchstats.ncs_goodhits++; + goto haveino; + } + } - /* - * Last component and we are renaming or deleting, - * the cache entry is invalid, or otherwise don't - * want cache entry to exist. - */ - /* remove from LRU chain */ - *ncp->nc_prev = ncp->nc_nxt; - if (ncp->nc_nxt) - ncp->nc_nxt->nc_prev = ncp->nc_prev; - else - nchtail = ncp->nc_prev; - remque(ncp); /* remove from hash chain */ - /* insert at head of LRU list (first to grab) */ - ncp->nc_nxt = nchhead; - ncp->nc_prev = &nchhead; - nchhead->nc_prev = &ncp->nc_nxt; - nchhead = ncp; - /* and make a dummy hash chain */ - ncp->nc_forw = ncp; - ncp->nc_back = ncp; - ncp = NULL; - } - } + /* + * Last component and we are renaming or deleting, + * the cache entry is invalid, or otherwise don't + * want cache entry to exist. + */ + /* remove from LRU chain */ + *ncp->nc_prev = ncp->nc_nxt; + if (ncp->nc_nxt) + ncp->nc_nxt->nc_prev = ncp->nc_prev; + else + nchtail = ncp->nc_prev; + remque(ncp); /* remove from hash chain */ + /* insert at head of LRU list (first to grab) */ + ncp->nc_nxt = nchhead; + ncp->nc_prev = &nchhead; + nchhead->nc_prev = &ncp->nc_nxt; + nchhead = ncp; + /* and make a dummy hash chain */ + ncp->nc_forw = ncp; + ncp->nc_back = ncp; + ncp = NULL; + } + } - /* - * Suppress search for slots unless creating - * file and at end of pathname, in which case - * we watch for a place to put the new file in - * case it doesn't already exist. - */ - slotstatus = FOUND; - if (flag == CREATE && *cp == 0) { - slotstatus = NONE; - slotfreespace = 0; - slotneeded = DIRSIZ(&ndp->ni_dent); - } - /* - * If this is the same directory that this process - * previously searched, pick up where we last left off. - * We cache only lookups as these are the most common - * and have the greatest payoff. Caching CREATE has little - * benefit as it usually must search the entire directory - * to determine that the entry does not exist. Caching the - * location of the last DELETE has not reduced profiling time - * and hence has been removed in the interest of simplicity. - */ - if (flag != LOOKUP || dp->i_number != u.u_ncache.nc_inumber || - dp->i_dev != u.u_ncache.nc_dev) { - ndp->ni_offset = 0; - numdirpasses = 1; - } else { - if (u.u_ncache.nc_prevoffset > dp->i_size) - u.u_ncache.nc_prevoffset = 0; - ndp->ni_offset = u.u_ncache.nc_prevoffset; - entryoffsetinblock = blkoff(ndp->ni_offset); - if (entryoffsetinblock != 0) { - bp = blkatoff(dp, ndp->ni_offset, (char **)0); - if (bp == 0) - goto bad; - } - numdirpasses = 2; - nchstats.ncs_2passes++; - } - endsearch = roundup(dp->i_size, DIRBLKSIZ); - enduseful = 0; + /* + * Suppress search for slots unless creating + * file and at end of pathname, in which case + * we watch for a place to put the new file in + * case it doesn't already exist. + */ + slotstatus = FOUND; + if (flag == CREATE && *cp == 0) { + slotstatus = NONE; + slotfreespace = 0; + slotneeded = DIRSIZ(&ndp->ni_dent); + } + /* + * If this is the same directory that this process + * previously searched, pick up where we last left off. + * We cache only lookups as these are the most common + * and have the greatest payoff. Caching CREATE has little + * benefit as it usually must search the entire directory + * to determine that the entry does not exist. Caching the + * location of the last DELETE has not reduced profiling time + * and hence has been removed in the interest of simplicity. + */ + if (flag != LOOKUP || dp->i_number != u.u_ncache.nc_inumber || + dp->i_dev != u.u_ncache.nc_dev) { + ndp->ni_offset = 0; + numdirpasses = 1; + } else { + if (u.u_ncache.nc_prevoffset > dp->i_size) + u.u_ncache.nc_prevoffset = 0; + ndp->ni_offset = u.u_ncache.nc_prevoffset; + entryoffsetinblock = blkoff(ndp->ni_offset); + if (entryoffsetinblock != 0) { + bp = blkatoff(dp, ndp->ni_offset, (char **)0); + if (bp == 0) + goto bad; + } + numdirpasses = 2; + nchstats.ncs_2passes++; + } + endsearch = roundup(dp->i_size, DIRBLKSIZ); + enduseful = 0; searchloop: - while (ndp->ni_offset < endsearch) { - /* - * If offset is on a block boundary, - * read the next directory block. - * Release previous if it exists. - */ - if (blkoff(ndp->ni_offset) == 0) { - if (bp != NULL) { - brelse(bp); - } - bp = blkatoff(dp, ndp->ni_offset, (char **)0); - if (bp == 0) - goto bad; - entryoffsetinblock = 0; - } - /* - * If still looking for a slot, and at a DIRBLKSIZE - * boundary, have to start looking for free space again. - */ - if (slotstatus == NONE && - (entryoffsetinblock&(DIRBLKSIZ-1)) == 0) { - slotoffset = -1; - slotfreespace = 0; - } - /* - * Get pointer to next entry. - * Full validation checks are slow, so we only check - * enough to insure forward progress through the - * directory. Complete checks can be run by patching - * "dirchk" to be true. - */ - ep = (struct direct*) ((caddr_t) bp->b_addr + entryoffsetinblock); - if (ep->d_reclen == 0 || - (dirchk && dirbadentry (ep, entryoffsetinblock))) { - dirbad(dp, ndp->ni_offset, "mangled entry"); - i = DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)); - ndp->ni_offset += i; - entryoffsetinblock += i; - continue; - } + while (ndp->ni_offset < endsearch) { + /* + * If offset is on a block boundary, + * read the next directory block. + * Release previous if it exists. + */ + if (blkoff(ndp->ni_offset) == 0) { + if (bp != NULL) { + brelse(bp); + } + bp = blkatoff(dp, ndp->ni_offset, (char **)0); + if (bp == 0) + goto bad; + entryoffsetinblock = 0; + } + /* + * If still looking for a slot, and at a DIRBLKSIZE + * boundary, have to start looking for free space again. + */ + if (slotstatus == NONE && + (entryoffsetinblock&(DIRBLKSIZ-1)) == 0) { + slotoffset = -1; + slotfreespace = 0; + } + /* + * Get pointer to next entry. + * Full validation checks are slow, so we only check + * enough to insure forward progress through the + * directory. Complete checks can be run by patching + * "dirchk" to be true. + */ + ep = (struct direct*) ((caddr_t) bp->b_addr + entryoffsetinblock); + if (ep->d_reclen == 0 || + (dirchk && dirbadentry (ep, entryoffsetinblock))) { + dirbad(dp, ndp->ni_offset, "mangled entry"); + i = DIRBLKSIZ - (entryoffsetinblock & (DIRBLKSIZ - 1)); + ndp->ni_offset += i; + entryoffsetinblock += i; + continue; + } - /* - * If an appropriate sized slot has not yet been found, - * check to see if one is available. Also accumulate space - * in the current block so that we can determine if - * compaction is viable. - */ - if (slotstatus != FOUND) { - int size = ep->d_reclen; + /* + * If an appropriate sized slot has not yet been found, + * check to see if one is available. Also accumulate space + * in the current block so that we can determine if + * compaction is viable. + */ + if (slotstatus != FOUND) { + int size = ep->d_reclen; - if (ep->d_ino != 0) - size -= DIRSIZ(ep); - if (size > 0) { - if (size >= slotneeded) { - slotstatus = FOUND; - slotoffset = ndp->ni_offset; - slotsize = ep->d_reclen; - } else if (slotstatus == NONE) { - slotfreespace += size; - if (slotoffset == -1) - slotoffset = ndp->ni_offset; - if (slotfreespace >= slotneeded) { - slotstatus = COMPACT; - slotsize = ndp->ni_offset + - ep->d_reclen - slotoffset; - } - } - } - } + if (ep->d_ino != 0) + size -= DIRSIZ(ep); + if (size > 0) { + if (size >= slotneeded) { + slotstatus = FOUND; + slotoffset = ndp->ni_offset; + slotsize = ep->d_reclen; + } else if (slotstatus == NONE) { + slotfreespace += size; + if (slotoffset == -1) + slotoffset = ndp->ni_offset; + if (slotfreespace >= slotneeded) { + slotstatus = COMPACT; + slotsize = ndp->ni_offset + + ep->d_reclen - slotoffset; + } + } + } + } - /* - * Check for a name match. - */ - if (ep->d_ino) { - if (ep->d_namlen == ndp->ni_dent.d_namlen && - !bcmp(ndp->ni_dent.d_name, ep->d_name, - (unsigned)ep->d_namlen)) - goto found; - } - prevoff = ndp->ni_offset; - ndp->ni_offset += ep->d_reclen; - entryoffsetinblock += ep->d_reclen; - if (ep->d_ino) - enduseful = ndp->ni_offset; - } + /* + * Check for a name match. + */ + if (ep->d_ino) { + if (ep->d_namlen == ndp->ni_dent.d_namlen && + !bcmp(ndp->ni_dent.d_name, ep->d_name, + (unsigned)ep->d_namlen)) + goto found; + } + prevoff = ndp->ni_offset; + ndp->ni_offset += ep->d_reclen; + entryoffsetinblock += ep->d_reclen; + if (ep->d_ino) + enduseful = ndp->ni_offset; + } /* notfound: */ - /* - * If we started in the middle of the directory and failed - * to find our target, we must check the beginning as well. - */ - if (numdirpasses == 2) { - numdirpasses--; - ndp->ni_offset = 0; - endsearch = u.u_ncache.nc_prevoffset; - goto searchloop; - } - /* - * If creating, and at end of pathname and current - * directory has not been removed, then can consider - * allowing file to be created. - */ - if (flag == CREATE && *cp == 0 && dp->i_nlink != 0) { - /* - * Access for write is interpreted as allowing - * creation of files in the directory. - */ - if (access(dp, IWRITE)) - goto bad; - /* - * Return an indication of where the new directory - * entry should be put. If we didn't find a slot, - * then set ndp->ni_count to 0 indicating that the new - * slot belongs at the end of the directory. If we found - * a slot, then the new entry can be put in the range - * [ndp->ni_offset .. ndp->ni_offset + ndp->ni_count) - */ - if (slotstatus == NONE) { - ndp->ni_offset = roundup(dp->i_size, DIRBLKSIZ); - ndp->ni_count = 0; - enduseful = ndp->ni_offset; - } else { - ndp->ni_offset = slotoffset; - ndp->ni_count = slotsize; - if (enduseful < slotoffset + slotsize) - enduseful = slotoffset + slotsize; - } - ndp->ni_endoff = roundup(enduseful, DIRBLKSIZ); - dp->i_flag |= IUPD|ICHG; - if (bp) { - brelse(bp); - } - /* - * We return with the directory locked, so that - * the parameters we set up above will still be - * valid if we actually decide to do a direnter(). - * We return NULL to indicate that the entry doesn't - * currently exist, leaving a pointer to the (locked) - * directory inode in ndp->ni_pdir. - */ - ndp->ni_pdir = dp; - goto retNULL; - } - u.u_error = ENOENT; - goto bad; + /* + * If we started in the middle of the directory and failed + * to find our target, we must check the beginning as well. + */ + if (numdirpasses == 2) { + numdirpasses--; + ndp->ni_offset = 0; + endsearch = u.u_ncache.nc_prevoffset; + goto searchloop; + } + /* + * If creating, and at end of pathname and current + * directory has not been removed, then can consider + * allowing file to be created. + */ + if (flag == CREATE && *cp == 0 && dp->i_nlink != 0) { + /* + * Access for write is interpreted as allowing + * creation of files in the directory. + */ + if (access(dp, IWRITE)) + goto bad; + /* + * Return an indication of where the new directory + * entry should be put. If we didn't find a slot, + * then set ndp->ni_count to 0 indicating that the new + * slot belongs at the end of the directory. If we found + * a slot, then the new entry can be put in the range + * [ndp->ni_offset .. ndp->ni_offset + ndp->ni_count) + */ + if (slotstatus == NONE) { + ndp->ni_offset = roundup(dp->i_size, DIRBLKSIZ); + ndp->ni_count = 0; + enduseful = ndp->ni_offset; + } else { + ndp->ni_offset = slotoffset; + ndp->ni_count = slotsize; + if (enduseful < slotoffset + slotsize) + enduseful = slotoffset + slotsize; + } + ndp->ni_endoff = roundup(enduseful, DIRBLKSIZ); + dp->i_flag |= IUPD|ICHG; + if (bp) { + brelse(bp); + } + /* + * We return with the directory locked, so that + * the parameters we set up above will still be + * valid if we actually decide to do a direnter(). + * We return NULL to indicate that the entry doesn't + * currently exist, leaving a pointer to the (locked) + * directory inode in ndp->ni_pdir. + */ + ndp->ni_pdir = dp; + goto retNULL; + } + u.u_error = ENOENT; + goto bad; found: - if (numdirpasses == 2) - nchstats.ncs_pass2++; - /* - * Check that directory length properly reflects presence - * of this entry. - */ - if (entryoffsetinblock + DIRSIZ(ep) > dp->i_size) { - dirbad(dp, ndp->ni_offset, "i_size too small"); - dp->i_size = entryoffsetinblock + DIRSIZ(ep); - dp->i_flag |= IUPD|ICHG; - } + if (numdirpasses == 2) + nchstats.ncs_pass2++; + /* + * Check that directory length properly reflects presence + * of this entry. + */ + if (entryoffsetinblock + DIRSIZ(ep) > dp->i_size) { + dirbad(dp, ndp->ni_offset, "i_size too small"); + dp->i_size = entryoffsetinblock + DIRSIZ(ep); + dp->i_flag |= IUPD|ICHG; + } - /* - * Found component in pathname. - * If the final component of path name, save information - * in the cache as to where the entry was found. - */ - if (*cp == '\0' && flag == LOOKUP) { - u.u_ncache.nc_prevoffset = ndp->ni_offset &~ (DIRBLKSIZ - 1); - u.u_ncache.nc_inumber = dp->i_number; - u.u_ncache.nc_dev = dp->i_dev; - } - /* - * Save directory entry's inode number and reclen in ndp->ni_dent, - * and release directory buffer. - */ - ndp->ni_dent.d_ino = ep->d_ino; - ndp->ni_dent.d_reclen = ep->d_reclen; - brelse(bp); - bp = NULL; + /* + * Found component in pathname. + * If the final component of path name, save information + * in the cache as to where the entry was found. + */ + if (*cp == '\0' && flag == LOOKUP) { + u.u_ncache.nc_prevoffset = ndp->ni_offset &~ (DIRBLKSIZ - 1); + u.u_ncache.nc_inumber = dp->i_number; + u.u_ncache.nc_dev = dp->i_dev; + } + /* + * Save directory entry's inode number and reclen in ndp->ni_dent, + * and release directory buffer. + */ + ndp->ni_dent.d_ino = ep->d_ino; + ndp->ni_dent.d_reclen = ep->d_reclen; + brelse(bp); + bp = NULL; - /* - * If deleting, and at end of pathname, return - * parameters which can be used to remove file. - * If the lockparent flag isn't set, we return only - * the directory (in ndp->ni_pdir), otherwise we go - * on and lock the inode, being careful with ".". - */ - if (flag == DELETE && *cp == 0) { - /* - * Write access to directory required to delete files. - */ - if (access(dp, IWRITE)) - goto bad; - ndp->ni_pdir = dp; /* for dirremove() */ - /* - * Return pointer to current entry in ndp->ni_offset, - * and distance past previous entry (if there - * is a previous entry in this block) in ndp->ni_count. - * Save directory inode pointer in ndp->ni_pdir for dirremove(). - */ - if ((ndp->ni_offset&(DIRBLKSIZ-1)) == 0) - ndp->ni_count = 0; - else - ndp->ni_count = ndp->ni_offset - prevoff; - if (lockparent) { - if (dp->i_number == ndp->ni_dent.d_ino) - dp->i_count++; - else { - dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); - if (dp == NULL) { - iput(ndp->ni_pdir); - goto bad; - } - /* - * If directory is "sticky", then user must own - * the directory, or the file in it, else he - * may not delete it (unless he's root). This - * implements append-only directories. - */ - if ((ndp->ni_pdir->i_mode & ISVTX) && - u.u_uid != 0 && - u.u_uid != ndp->ni_pdir->i_uid && - dp->i_uid != u.u_uid) { - iput(ndp->ni_pdir); - u.u_error = EPERM; - goto bad; - } - } - } - goto retDP; - } + /* + * If deleting, and at end of pathname, return + * parameters which can be used to remove file. + * If the lockparent flag isn't set, we return only + * the directory (in ndp->ni_pdir), otherwise we go + * on and lock the inode, being careful with ".". + */ + if (flag == DELETE && *cp == 0) { + /* + * Write access to directory required to delete files. + */ + if (access(dp, IWRITE)) + goto bad; + ndp->ni_pdir = dp; /* for dirremove() */ + /* + * Return pointer to current entry in ndp->ni_offset, + * and distance past previous entry (if there + * is a previous entry in this block) in ndp->ni_count. + * Save directory inode pointer in ndp->ni_pdir for dirremove(). + */ + if ((ndp->ni_offset&(DIRBLKSIZ-1)) == 0) + ndp->ni_count = 0; + else + ndp->ni_count = ndp->ni_offset - prevoff; + if (lockparent) { + if (dp->i_number == ndp->ni_dent.d_ino) + dp->i_count++; + else { + dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); + if (dp == NULL) { + iput(ndp->ni_pdir); + goto bad; + } + /* + * If directory is "sticky", then user must own + * the directory, or the file in it, else he + * may not delete it (unless he's root). This + * implements append-only directories. + */ + if ((ndp->ni_pdir->i_mode & ISVTX) && + u.u_uid != 0 && + u.u_uid != ndp->ni_pdir->i_uid && + dp->i_uid != u.u_uid) { + iput(ndp->ni_pdir); + u.u_error = EPERM; + goto bad; + } + } + } + goto retDP; + } - /* - * Special handling for ".." allowing chdir out of mounted - * file system: indirect .. in root inode to reevaluate - * in directory file system was mounted on. - */ - if (isdotdot) { - if (dp == u.u_rdir) { - ndp->ni_dent.d_ino = dp->i_number; - makeentry = 0; - } else if (ndp->ni_dent.d_ino == ROOTINO && - dp->i_number == ROOTINO) { - register struct mount *mp; - register dev_t d; + /* + * Special handling for ".." allowing chdir out of mounted + * file system: indirect .. in root inode to reevaluate + * in directory file system was mounted on. + */ + if (isdotdot) { + if (dp == u.u_rdir) { + ndp->ni_dent.d_ino = dp->i_number; + makeentry = 0; + } else if (ndp->ni_dent.d_ino == ROOTINO && + dp->i_number == ROOTINO) { + register struct mount *mp; + register dev_t d; - d = dp->i_dev; - for (mp = &mount[1]; mp < &mount[NMOUNT]; mp++) - if (mp->m_inodp && mp->m_dev == d) { - iput(dp); - dp = mp->m_inodp; - ILOCK(dp); - dp->i_count++; - fs = dp->i_fs; - cp -= 2; /* back over .. */ - goto dirloop2; - } - } - } + d = dp->i_dev; + for (mp = &mount[1]; mp < &mount[NMOUNT]; mp++) + if (mp->m_inodp && mp->m_dev == d) { + iput(dp); + dp = mp->m_inodp; + ILOCK(dp); + dp->i_count++; + fs = dp->i_fs; + cp -= 2; /* back over .. */ + goto dirloop2; + } + } + } - /* - * If rewriting (rename), return the inode and the - * information required to rewrite the present directory - * Must get inode of directory entry to verify it's a - * regular file, or empty directory. - */ - if ((flag == CREATE && lockparent) && *cp == 0) { - if (access(dp, IWRITE)) - goto bad; - ndp->ni_pdir = dp; /* for dirrewrite() */ - /* - * Careful about locking second inode. - * This can only occur if the target is ".". - */ - if (dp->i_number == ndp->ni_dent.d_ino) { - u.u_error = EISDIR; /* XXX */ - goto bad; - } - dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); - if (dp == NULL) { - iput(ndp->ni_pdir); - goto bad; - } - goto retDP; - } + /* + * If rewriting (rename), return the inode and the + * information required to rewrite the present directory + * Must get inode of directory entry to verify it's a + * regular file, or empty directory. + */ + if ((flag == CREATE && lockparent) && *cp == 0) { + if (access(dp, IWRITE)) + goto bad; + ndp->ni_pdir = dp; /* for dirrewrite() */ + /* + * Careful about locking second inode. + * This can only occur if the target is ".". + */ + if (dp->i_number == ndp->ni_dent.d_ino) { + u.u_error = EISDIR; /* XXX */ + goto bad; + } + dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); + if (dp == NULL) { + iput(ndp->ni_pdir); + goto bad; + } + goto retDP; + } - /* - * Check for symbolic link, which may require us to massage the - * name before we continue translation. We do not `iput' the - * directory because we may need it again if the symbolic link - * is relative to the current directory. Instead we save it - * unlocked as "pdp". We must get the target inode before unlocking - * the directory to insure that the inode will not be removed - * before we get it. We prevent deadlock by always fetching - * inodes from the root, moving down the directory tree. Thus - * when following backward pointers ".." we must unlock the - * parent directory before getting the requested directory. - * There is a potential race condition here if both the current - * and parent directories are removed before the `iget' for the - * inode associated with ".." returns. We hope that this occurs - * infrequently since we cannot avoid this race condition without - * implementing a sophisticated deadlock detection algorithm. - * Note also that this simple deadlock detection scheme will not - * work if the file system has any hard links other than ".." - * that point backwards in the directory structure. - */ - pdp = dp; - if (isdotdot) { - IUNLOCK(pdp); /* race to get the inode */ - dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); - if (dp == NULL) - goto bad2; - } else if (dp->i_number == ndp->ni_dent.d_ino) { - dp->i_count++; /* we want ourself, ie "." */ - } else { - dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); - IUNLOCK(pdp); - if (dp == NULL) - goto bad2; - } + /* + * Check for symbolic link, which may require us to massage the + * name before we continue translation. We do not `iput' the + * directory because we may need it again if the symbolic link + * is relative to the current directory. Instead we save it + * unlocked as "pdp". We must get the target inode before unlocking + * the directory to insure that the inode will not be removed + * before we get it. We prevent deadlock by always fetching + * inodes from the root, moving down the directory tree. Thus + * when following backward pointers ".." we must unlock the + * parent directory before getting the requested directory. + * There is a potential race condition here if both the current + * and parent directories are removed before the `iget' for the + * inode associated with ".." returns. We hope that this occurs + * infrequently since we cannot avoid this race condition without + * implementing a sophisticated deadlock detection algorithm. + * Note also that this simple deadlock detection scheme will not + * work if the file system has any hard links other than ".." + * that point backwards in the directory structure. + */ + pdp = dp; + if (isdotdot) { + IUNLOCK(pdp); /* race to get the inode */ + dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); + if (dp == NULL) + goto bad2; + } else if (dp->i_number == ndp->ni_dent.d_ino) { + dp->i_count++; /* we want ourself, ie "." */ + } else { + dp = iget(dp->i_dev, fs, ndp->ni_dent.d_ino); + IUNLOCK(pdp); + if (dp == NULL) + goto bad2; + } - /* - * Insert name into cache if appropriate. - */ - if (makeentry) { - if (ncp != NULL) - panic("namei: duplicating cache"); - /* - * Free the cache slot at head of lru chain. - */ - ncp = nchhead; - if (ncp) { - /* remove from lru chain */ - *ncp->nc_prev = ncp->nc_nxt; - if (ncp->nc_nxt) - ncp->nc_nxt->nc_prev = ncp->nc_prev; - else - nchtail = ncp->nc_prev; - remque(ncp); /* remove from old hash chain */ - /* grab the inode we just found */ - ncp->nc_ip = dp; - /* fill in cache info */ - ncp->nc_ino = pdp->i_number; /* parents inum */ - ncp->nc_dev = pdp->i_dev; /* & device */ - ncp->nc_idev = dp->i_dev; /* our device */ - ncp->nc_id = dp->i_id; /* identifier */ - ncp->nc_nlen = ndp->ni_dent.d_namlen; - bcopy(ndp->ni_dent.d_name, ncp->nc_name, - (unsigned)ncp->nc_nlen); - /* link at end of lru chain */ - ncp->nc_nxt = NULL; - ncp->nc_prev = nchtail; - *nchtail = ncp; - nchtail = &ncp->nc_nxt; - /* and insert on hash chain */ - insque(ncp, nhp); - } - } + /* + * Insert name into cache if appropriate. + */ + if (makeentry) { + if (ncp != NULL) + panic("namei: duplicating cache"); + /* + * Free the cache slot at head of lru chain. + */ + ncp = nchhead; + if (ncp) { + /* remove from lru chain */ + *ncp->nc_prev = ncp->nc_nxt; + if (ncp->nc_nxt) + ncp->nc_nxt->nc_prev = ncp->nc_prev; + else + nchtail = ncp->nc_prev; + remque(ncp); /* remove from old hash chain */ + /* grab the inode we just found */ + ncp->nc_ip = dp; + /* fill in cache info */ + ncp->nc_ino = pdp->i_number; /* parents inum */ + ncp->nc_dev = pdp->i_dev; /* & device */ + ncp->nc_idev = dp->i_dev; /* our device */ + ncp->nc_id = dp->i_id; /* identifier */ + ncp->nc_nlen = ndp->ni_dent.d_namlen; + bcopy(ndp->ni_dent.d_name, ncp->nc_name, + (unsigned)ncp->nc_nlen); + /* link at end of lru chain */ + ncp->nc_nxt = NULL; + ncp->nc_prev = nchtail; + *nchtail = ncp; + nchtail = &ncp->nc_nxt; + /* and insert on hash chain */ + insque(ncp, nhp); + } + } haveino: - fs = dp->i_fs; + fs = dp->i_fs; - /* - * Check for symbolic link - */ - if ((dp->i_mode & IFMT) == IFLNK && - ((ndp->ni_nameiop & FOLLOW) || *cp == '/')) { - u_int pathlen = strlen(cp) + 1; + /* + * Check for symbolic link + */ + if ((dp->i_mode & IFMT) == IFLNK && + ((ndp->ni_nameiop & FOLLOW) || *cp == '/')) { + u_int pathlen = strlen(cp) + 1; - if (dp->i_size + pathlen >= MAXPATHLEN - 1) { - u.u_error = ENAMETOOLONG; - goto bad2; - } - if (++nlink > MAXSYMLINKS) { - u.u_error = ELOOP; - goto bad2; - } + if (dp->i_size + pathlen >= MAXPATHLEN - 1) { + u.u_error = ENAMETOOLONG; + goto bad2; + } + if (++nlink > MAXSYMLINKS) { + u.u_error = ELOOP; + goto bad2; + } - bp = bread(dp->i_dev, bmap(dp, (daddr_t)0, B_READ, 0)); - if (bp->b_flags & B_ERROR) { - brelse(bp); - bp = NULL; - goto bad2; - } - /* - * Shift the rest of path further down the buffer, then - * copy link path into the first part of the buffer. - */ - bcopy(cp, path + (u_int)dp->i_size, pathlen); - bcopy(bp->b_addr, path, (u_int)dp->i_size); - brelse(bp); - bp = NULL; - cp = path; - iput(dp); - if (*cp == '/') { - irele(pdp); - while (*cp == '/') - cp++; - if ((dp = u.u_rdir) == NULL) - dp = rootdir; - ILOCK(dp); - dp->i_count++; - } else { - dp = pdp; - ILOCK(dp); - } - fs = dp->i_fs; - goto dirloop; - } + bp = bread(dp->i_dev, bmap(dp, (daddr_t)0, B_READ, 0)); + if (bp->b_flags & B_ERROR) { + brelse(bp); + bp = NULL; + goto bad2; + } + /* + * Shift the rest of path further down the buffer, then + * copy link path into the first part of the buffer. + */ + bcopy(cp, path + (u_int)dp->i_size, pathlen); + bcopy(bp->b_addr, path, (u_int)dp->i_size); + brelse(bp); + bp = NULL; + cp = path; + iput(dp); + if (*cp == '/') { + irele(pdp); + while (*cp == '/') + cp++; + if ((dp = u.u_rdir) == NULL) + dp = rootdir; + ILOCK(dp); + dp->i_count++; + } else { + dp = pdp; + ILOCK(dp); + } + fs = dp->i_fs; + goto dirloop; + } - /* - * Not a symbolic link. If more pathname, - * continue at next component, else return. - */ - if (*cp == '/') { - while (*cp == '/') - cp++; - irele(pdp); - goto dirloop; - } - if (lockparent) - ndp->ni_pdir = pdp; - else - irele(pdp); + /* + * Not a symbolic link. If more pathname, + * continue at next component, else return. + */ + if (*cp == '/') { + while (*cp == '/') + cp++; + irele(pdp); + goto dirloop; + } + if (lockparent) + ndp->ni_pdir = pdp; + else + irele(pdp); retDP: - ndp->ni_ip = dp; - return (dp); + ndp->ni_ip = dp; + return (dp); bad2: - irele(pdp); + irele(pdp); bad: - if (bp) { - brelse(bp); - } - if (dp) - iput(dp); + if (bp) { + brelse(bp); + } + if (dp) + iput(dp); retNULL: - ndp->ni_ip = NULL; - return (NULL); + ndp->ni_ip = NULL; + return (NULL); } /* @@ -895,110 +896,110 @@ retNULL: */ int direnter(ip, ndp) - struct inode *ip; - register struct nameidata *ndp; + struct inode *ip; + register struct nameidata *ndp; { - register struct direct *ep, *nep; - register struct inode *dp = ndp->ni_pdir; - struct buf *bp; - int loc, spacefree, error = 0; - u_int dsize; - int newentrysize; - char *dirbuf; + register struct direct *ep, *nep; + register struct inode *dp = ndp->ni_pdir; + struct buf *bp; + int loc, spacefree, error = 0; + u_int dsize; + int newentrysize; + char *dirbuf; - ndp->ni_dent.d_ino = ip->i_number; - newentrysize = DIRSIZ(&ndp->ni_dent); - if (ndp->ni_count == 0) { - /* - * If ndp->ni_count is 0, then namei could find no space in the - * directory. In this case ndp->ni_offset will be on a directory - * block boundary and we will write the new entry into a fresh - * block. - */ - if (ndp->ni_offset&(DIRBLKSIZ-1)) - panic("wdir: newblk"); - ndp->ni_dent.d_reclen = DIRBLKSIZ; - error = rdwri (UIO_WRITE, dp, (caddr_t)&ndp->ni_dent, - newentrysize, ndp->ni_offset, - IO_UNIT|IO_SYNC, (int *)0); - dp->i_size = roundup(dp->i_size, DIRBLKSIZ); - iput(dp); - return (error); - } + ndp->ni_dent.d_ino = ip->i_number; + newentrysize = DIRSIZ(&ndp->ni_dent); + if (ndp->ni_count == 0) { + /* + * If ndp->ni_count is 0, then namei could find no space in the + * directory. In this case ndp->ni_offset will be on a directory + * block boundary and we will write the new entry into a fresh + * block. + */ + if (ndp->ni_offset&(DIRBLKSIZ-1)) + panic("wdir: newblk"); + ndp->ni_dent.d_reclen = DIRBLKSIZ; + error = rdwri (UIO_WRITE, dp, (caddr_t)&ndp->ni_dent, + newentrysize, ndp->ni_offset, + IO_UNIT|IO_SYNC, (int *)0); + dp->i_size = roundup(dp->i_size, DIRBLKSIZ); + iput(dp); + return (error); + } - /* - * If ndp->ni_count is non-zero, then namei found space for the new - * entry in the range ndp->ni_offset to ndp->ni_offset + ndp->ni_count. - * in the directory. To use this space, we may have to compact - * the entries located there, by copying them together towards - * the beginning of the block, leaving the free space in - * one usable chunk at the end. - */ + /* + * If ndp->ni_count is non-zero, then namei found space for the new + * entry in the range ndp->ni_offset to ndp->ni_offset + ndp->ni_count. + * in the directory. To use this space, we may have to compact + * the entries located there, by copying them together towards + * the beginning of the block, leaving the free space in + * one usable chunk at the end. + */ - /* - * Increase size of directory if entry eats into new space. - * This should never push the size past a new multiple of - * DIRBLKSIZE. - * - * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN. - */ - if (ndp->ni_offset + ndp->ni_count > dp->i_size) - dp->i_size = ndp->ni_offset + ndp->ni_count; - /* - * Get the block containing the space for the new directory - * entry. Should return error by result instead of u.u_error. - */ - bp = blkatoff(dp, ndp->ni_offset, (char **)&dirbuf); - if (bp == 0) { - iput(dp); - return (u.u_error); - } - /* - * Find space for the new entry. In the simple case, the - * entry at offset base will have the space. If it does - * not, then namei arranged that compacting the region - * ndp->ni_offset to ndp->ni_offset+ndp->ni_count would yield the space. - */ - ep = (struct direct *)dirbuf; - dsize = DIRSIZ(ep); - spacefree = ep->d_reclen - dsize; - for (loc = ep->d_reclen; loc < ndp->ni_count; ) { - nep = (struct direct *)(dirbuf + loc); - if (ep->d_ino) { - /* trim the existing slot */ - ep->d_reclen = dsize; - ep = (struct direct *)((char *)ep + dsize); - } else { - /* overwrite; nothing there; header is ours */ - spacefree += dsize; - } - dsize = DIRSIZ(nep); - spacefree += nep->d_reclen - dsize; - loc += nep->d_reclen; - bcopy((caddr_t)nep, (caddr_t)ep, dsize); - } - /* - * Update the pointer fields in the previous entry (if any), - * copy in the new entry, and write out the block. - */ - if (ep->d_ino == 0) { - if (spacefree + dsize < newentrysize) - panic("wdir: compact1"); - ndp->ni_dent.d_reclen = spacefree + dsize; - } else { - if (spacefree < newentrysize) - panic("wdir: compact2"); - ndp->ni_dent.d_reclen = spacefree; - ep->d_reclen = dsize; - ep = (struct direct *)((char *)ep + dsize); - } - bcopy((caddr_t)&ndp->ni_dent, (caddr_t)ep, (u_int)newentrysize); - bwrite(bp); - dp->i_flag |= IUPD|ICHG; - if (ndp->ni_endoff && ndp->ni_endoff < dp->i_size) - itrunc(dp, (u_long)ndp->ni_endoff, 0); - iput(dp); - return (error); + /* + * Increase size of directory if entry eats into new space. + * This should never push the size past a new multiple of + * DIRBLKSIZE. + * + * N.B. - THIS IS AN ARTIFACT OF 4.2 AND SHOULD NEVER HAPPEN. + */ + if (ndp->ni_offset + ndp->ni_count > dp->i_size) + dp->i_size = ndp->ni_offset + ndp->ni_count; + /* + * Get the block containing the space for the new directory + * entry. Should return error by result instead of u.u_error. + */ + bp = blkatoff(dp, ndp->ni_offset, (char **)&dirbuf); + if (bp == 0) { + iput(dp); + return (u.u_error); + } + /* + * Find space for the new entry. In the simple case, the + * entry at offset base will have the space. If it does + * not, then namei arranged that compacting the region + * ndp->ni_offset to ndp->ni_offset+ndp->ni_count would yield the space. + */ + ep = (struct direct *)dirbuf; + dsize = DIRSIZ(ep); + spacefree = ep->d_reclen - dsize; + for (loc = ep->d_reclen; loc < ndp->ni_count; ) { + nep = (struct direct *)(dirbuf + loc); + if (ep->d_ino) { + /* trim the existing slot */ + ep->d_reclen = dsize; + ep = (struct direct *)((char *)ep + dsize); + } else { + /* overwrite; nothing there; header is ours */ + spacefree += dsize; + } + dsize = DIRSIZ(nep); + spacefree += nep->d_reclen - dsize; + loc += nep->d_reclen; + bcopy((caddr_t)nep, (caddr_t)ep, dsize); + } + /* + * Update the pointer fields in the previous entry (if any), + * copy in the new entry, and write out the block. + */ + if (ep->d_ino == 0) { + if (spacefree + dsize < newentrysize) + panic("wdir: compact1"); + ndp->ni_dent.d_reclen = spacefree + dsize; + } else { + if (spacefree < newentrysize) + panic("wdir: compact2"); + ndp->ni_dent.d_reclen = spacefree; + ep->d_reclen = dsize; + ep = (struct direct *)((char *)ep + dsize); + } + bcopy((caddr_t)&ndp->ni_dent, (caddr_t)ep, (u_int)newentrysize); + bwrite(bp); + dp->i_flag |= IUPD|ICHG; + if (ndp->ni_endoff && ndp->ni_endoff < dp->i_size) + itrunc(dp, (u_long)ndp->ni_endoff, 0); + iput(dp); + return (error); } /* @@ -1015,32 +1016,32 @@ direnter(ip, ndp) */ int dirremove (ndp) - register struct nameidata *ndp; + register struct nameidata *ndp; { - register struct inode *dp = ndp->ni_pdir; - register struct buf *bp; - struct direct *ep; + register struct inode *dp = ndp->ni_pdir; + register struct buf *bp; + struct direct *ep; - if (ndp->ni_count == 0) { - /* - * First entry in block: set d_ino to zero. - */ - ndp->ni_dent.d_ino = 0; - (void) rdwri (UIO_WRITE, dp, (caddr_t) &ndp->ni_dent, - (int) DIRSIZ(&ndp->ni_dent), ndp->ni_offset, - IO_UNIT | IO_SYNC, (int*) 0); - } else { - /* - * Collapse new free space into previous entry. - */ - bp = blkatoff(dp, ndp->ni_offset - ndp->ni_count, (char **)&ep); - if (bp == 0) - return (0); - ep->d_reclen += ndp->ni_dent.d_reclen; - bwrite(bp); - dp->i_flag |= IUPD|ICHG; - } - return (1); + if (ndp->ni_count == 0) { + /* + * First entry in block: set d_ino to zero. + */ + ndp->ni_dent.d_ino = 0; + (void) rdwri (UIO_WRITE, dp, (caddr_t) &ndp->ni_dent, + (int) DIRSIZ(&ndp->ni_dent), ndp->ni_offset, + IO_UNIT | IO_SYNC, (int*) 0); + } else { + /* + * Collapse new free space into previous entry. + */ + bp = blkatoff(dp, ndp->ni_offset - ndp->ni_count, (char **)&ep); + if (bp == 0) + return (0); + ep->d_reclen += ndp->ni_dent.d_reclen; + bwrite(bp); + dp->i_flag |= IUPD|ICHG; + } + return (1); } /* @@ -1050,16 +1051,15 @@ dirremove (ndp) */ void dirrewrite(dp, ip, ndp) - register struct inode *dp; - struct inode *ip; - register struct nameidata *ndp; + register struct inode *dp; + struct inode *ip; + register struct nameidata *ndp; { - - ndp->ni_dent.d_ino = ip->i_number; - u.u_error = rdwri (UIO_WRITE, dp, (caddr_t) &ndp->ni_dent, - (int) DIRSIZ(&ndp->ni_dent), ndp->ni_offset, - IO_UNIT | IO_SYNC, (int*) 0); - iput(dp); + ndp->ni_dent.d_ino = ip->i_number; + u.u_error = rdwri (UIO_WRITE, dp, (caddr_t) &ndp->ni_dent, + (int) DIRSIZ(&ndp->ni_dent), ndp->ni_offset, + IO_UNIT | IO_SYNC, (int*) 0); + iput(dp); } /* @@ -1073,47 +1073,47 @@ dirrewrite(dp, ip, ndp) */ int dirempty (ip, parentino) - register struct inode *ip; - ino_t parentino; + register struct inode *ip; + ino_t parentino; { - register off_t off; - struct dirtemplate dbuf; - register struct direct *dp = (struct direct *)&dbuf; - int error, count; -#define MINDIRSIZ (sizeof (struct dirtemplate) / 2) + register off_t off; + struct dirtemplate dbuf; + register struct direct *dp = (struct direct *)&dbuf; + int error, count; +#define MINDIRSIZ (sizeof (struct dirtemplate) / 2) - for (off = 0; off < ip->i_size; off += dp->d_reclen) { - error = rdwri (UIO_READ, ip, (caddr_t) dp, MINDIRSIZ, - off, IO_UNIT, &count); - /* - * Since we read MINDIRSIZ, residual must - * be 0 unless we're at end of file. - */ - if (error || count != 0) - return (0); - /* avoid infinite loops */ - if (dp->d_reclen == 0) - return (0); - /* skip empty entries */ - if (dp->d_ino == 0) - continue; - /* accept only "." and ".." */ - if (dp->d_namlen > 2) - return (0); - if (dp->d_name[0] != '.') - return (0); - /* - * At this point d_namlen must be 1 or 2. - * 1 implies ".", 2 implies ".." if second - * char is also "." - */ - if (dp->d_namlen == 1) - continue; - if (dp->d_name[1] == '.' && dp->d_ino == parentino) - continue; - return (0); - } - return (1); + for (off = 0; off < ip->i_size; off += dp->d_reclen) { + error = rdwri (UIO_READ, ip, (caddr_t) dp, MINDIRSIZ, + off, IO_UNIT, &count); + /* + * Since we read MINDIRSIZ, residual must + * be 0 unless we're at end of file. + */ + if (error || count != 0) + return (0); + /* avoid infinite loops */ + if (dp->d_reclen == 0) + return (0); + /* skip empty entries */ + if (dp->d_ino == 0) + continue; + /* accept only "." and ".." */ + if (dp->d_namlen > 2) + return (0); + if (dp->d_name[0] != '.') + return (0); + /* + * At this point d_namlen must be 1 or 2. + * 1 implies ".", 2 implies ".." if second + * char is also "." + */ + if (dp->d_namlen == 1) + continue; + if (dp->d_name[1] == '.' && dp->d_ino == parentino) + continue; + return (0); + } + return (1); } /* @@ -1123,56 +1123,56 @@ dirempty (ip, parentino) */ int checkpath (source, target) - struct inode *source, *target; + struct inode *source, *target; { - struct dirtemplate dirbuf; - register struct inode *ip; - register int error = 0; + struct dirtemplate dirbuf; + register struct inode *ip; + register int error = 0; - ip = target; - if (ip->i_number == source->i_number) { - error = EEXIST; - goto out; - } - if (ip->i_number == ROOTINO) - goto out; + ip = target; + if (ip->i_number == source->i_number) { + error = EEXIST; + goto out; + } + if (ip->i_number == ROOTINO) + goto out; - for (;;) { - if ((ip->i_mode&IFMT) != IFDIR) { - error = ENOTDIR; - break; - } - error = rdwri (UIO_READ, ip, (caddr_t) &dirbuf, - sizeof(struct dirtemplate), (off_t) 0, - IO_UNIT, (int*) 0); - if (error != 0) - break; - if (dirbuf.dotdot_namlen != 2 || - dirbuf.dotdot_name[0] != '.' || - dirbuf.dotdot_name[1] != '.') { - error = ENOTDIR; - break; - } - if (dirbuf.dotdot_ino == source->i_number) { - error = EINVAL; - break; - } - if (dirbuf.dotdot_ino == ROOTINO) - break; - iput(ip); - ip = iget(ip->i_dev, ip->i_fs, dirbuf.dotdot_ino); - if (ip == NULL) { - error = u.u_error; - break; - } - } + for (;;) { + if ((ip->i_mode&IFMT) != IFDIR) { + error = ENOTDIR; + break; + } + error = rdwri (UIO_READ, ip, (caddr_t) &dirbuf, + sizeof(struct dirtemplate), (off_t) 0, + IO_UNIT, (int*) 0); + if (error != 0) + break; + if (dirbuf.dotdot_namlen != 2 || + dirbuf.dotdot_name[0] != '.' || + dirbuf.dotdot_name[1] != '.') { + error = ENOTDIR; + break; + } + if (dirbuf.dotdot_ino == source->i_number) { + error = EINVAL; + break; + } + if (dirbuf.dotdot_ino == ROOTINO) + break; + iput(ip); + ip = iget(ip->i_dev, ip->i_fs, dirbuf.dotdot_ino); + if (ip == NULL) { + error = u.u_error; + break; + } + } out: - if (error == ENOTDIR) - printf("checkpath: .. !dir\n"); - if (ip != NULL) - iput(ip); - return (error); + if (error == ENOTDIR) + printf("checkpath: .. !dir\n"); + if (ip != NULL) + iput(ip); + return (error); } /* @@ -1181,24 +1181,24 @@ out: void nchinit() { - register union nchash *nchp; - register struct namecache *ncp; + register union nchash *nchp; + register struct namecache *ncp; - nchhead = 0; - nchtail = &nchhead; - for (ncp = namecache; ncp < &namecache[NNAMECACHE]; ncp++) { - ncp->nc_forw = ncp; /* hash chain */ - ncp->nc_back = ncp; - ncp->nc_nxt = NULL; /* lru chain */ - *nchtail = ncp; - ncp->nc_prev = nchtail; - nchtail = &ncp->nc_nxt; - /* all else is zero already */ - } - for (nchp = nchash; nchp < &nchash[NCHHASH]; nchp++) { - nchp->nch_head[0] = nchp; - nchp->nch_head[1] = nchp; - } + nchhead = 0; + nchtail = &nchhead; + for (ncp = namecache; ncp < &namecache[NNAMECACHE]; ncp++) { + ncp->nc_forw = ncp; /* hash chain */ + ncp->nc_back = ncp; + ncp->nc_nxt = NULL; /* lru chain */ + *nchtail = ncp; + ncp->nc_prev = nchtail; + nchtail = &ncp->nc_nxt; + /* all else is zero already */ + } + for (nchp = nchash; nchp < &nchash[NCHHASH]; nchp++) { + nchp->nch_head[0] = nchp; + nchp->nch_head[1] = nchp; + } } /* @@ -1211,38 +1211,38 @@ nchinit() */ void nchinval (dev) - register dev_t dev; + register dev_t dev; { - register struct namecache *ncp, *nxtcp; + register struct namecache *ncp, *nxtcp; - for (ncp = nchhead; ncp; ncp = nxtcp) { - nxtcp = ncp->nc_nxt; - if (ncp->nc_ip == NULL || - (ncp->nc_idev != dev && ncp->nc_dev != dev)) - continue; - /* free the resources we had */ - ncp->nc_idev = NODEV; - ncp->nc_dev = NODEV; - ncp->nc_id = NULL; - ncp->nc_ino = 0; - ncp->nc_ip = NULL; - remque(ncp); /* remove entry from its hash chain */ - ncp->nc_forw = ncp; /* and make a dummy one */ - ncp->nc_back = ncp; - /* delete this entry from LRU chain */ - *ncp->nc_prev = nxtcp; - if (nxtcp) - nxtcp->nc_prev = ncp->nc_prev; - else - nchtail = ncp->nc_prev; - /* cause rescan of list, it may have altered */ - nxtcp = nchhead; - /* put the now-free entry at head of LRU */ - ncp->nc_nxt = nxtcp; - ncp->nc_prev = &nchhead; - nxtcp->nc_prev = &ncp->nc_nxt; - nchhead = ncp; - } + for (ncp = nchhead; ncp; ncp = nxtcp) { + nxtcp = ncp->nc_nxt; + if (ncp->nc_ip == NULL || + (ncp->nc_idev != dev && ncp->nc_dev != dev)) + continue; + /* free the resources we had */ + ncp->nc_idev = NODEV; + ncp->nc_dev = NODEV; + ncp->nc_id = NULL; + ncp->nc_ino = 0; + ncp->nc_ip = NULL; + remque(ncp); /* remove entry from its hash chain */ + ncp->nc_forw = ncp; /* and make a dummy one */ + ncp->nc_back = ncp; + /* delete this entry from LRU chain */ + *ncp->nc_prev = nxtcp; + if (nxtcp) + nxtcp->nc_prev = ncp->nc_prev; + else + nchtail = ncp->nc_prev; + /* cause rescan of list, it may have altered */ + nxtcp = nchhead; + /* put the now-free entry at head of LRU */ + ncp->nc_nxt = nxtcp; + ncp->nc_prev = &nchhead; + nxtcp->nc_prev = &ncp->nc_nxt; + nchhead = ncp; + } } /* @@ -1251,8 +1251,8 @@ nchinval (dev) void cinvalall() { - register struct namecache *ncp, *encp = &namecache[NNAMECACHE]; + register struct namecache *ncp, *encp = &namecache[NNAMECACHE]; - for (ncp = namecache; ncp < encp; ncp++) - ncp->nc_id = 0; + for (ncp = namecache; ncp < encp; ncp++) + ncp->nc_id = 0; } diff --git a/sys/kernel/ufs_subr.c b/sys/kernel/ufs_subr.c index c9300f6..bf4b889 100644 --- a/sys/kernel/ufs_subr.c +++ b/sys/kernel/ufs_subr.c @@ -13,7 +13,7 @@ #include "kernel.h" #include "systm.h" -int updlock; /* lock for sync */ +int updlock; /* lock for sync */ /* * Go through the mount table looking for filesystems which have been modified. @@ -23,25 +23,25 @@ int updlock; /* lock for sync */ void sync() { - register struct mount *mp; - register struct fs *fs; - int async; + register struct mount *mp; + register struct fs *fs; + int async; - if (updlock) - return; - updlock++; - for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) { - if (mp->m_inodp == NULL || mp->m_dev == NODEV) - continue; - fs = &mp->m_filsys; - if (fs->fs_fmod == 0 || fs->fs_ilock || fs->fs_flock) - continue; - async = mp->m_flags & MNT_ASYNC; - mp->m_flags &= ~MNT_ASYNC; - ufs_sync(mp); - mp->m_flags |= async; - } - updlock = 0; + if (updlock) + return; + updlock++; + for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) { + if (mp->m_inodp == NULL || mp->m_dev == NODEV) + continue; + fs = &mp->m_filsys; + if (fs->fs_fmod == 0 || fs->fs_ilock || fs->fs_flock) + continue; + async = mp->m_flags & MNT_ASYNC; + mp->m_flags &= ~MNT_ASYNC; + ufs_sync(mp); + mp->m_flags |= async; + } + updlock = 0; } /* @@ -49,53 +49,53 @@ sync() * There are two strategies based on the size of the file; * large files are those with more than NBUF/2 blocks. * Large files - * Walk through the buffer pool and push any dirty pages - * associated with the device on which the file resides. + * Walk through the buffer pool and push any dirty pages + * associated with the device on which the file resides. * Small files - * Look up each block in the file to see if it is in the - * buffer pool writing any that are found to disk. - * Note that we make a more stringent check of - * writing out any block in the buffer pool that may - * overlap the inode. This brings the inode up to - * date with recent mods to the cooked device. + * Look up each block in the file to see if it is in the + * buffer pool writing any that are found to disk. + * Note that we make a more stringent check of + * writing out any block in the buffer pool that may + * overlap the inode. This brings the inode up to + * date with recent mods to the cooked device. */ void syncip(ip) - struct inode *ip; + struct inode *ip; { - register struct buf *bp; - register struct buf *lastbufp; - long lbn, lastlbn; - register int s; - daddr_t blkno; + register struct buf *bp; + register struct buf *lastbufp; + long lbn, lastlbn; + register int s; + daddr_t blkno; - lastlbn = howmany(ip->i_size, DEV_BSIZE); - if (lastlbn < NBUF / 2) { - for (lbn = 0; lbn < lastlbn; lbn++) { - blkno = fsbtodb(bmap(ip, lbn, B_READ, 0)); - blkflush(ip->i_dev, blkno); - } - } else { - lastbufp = &buf[NBUF]; - for (bp = buf; bp < lastbufp; bp++) { - if (bp->b_dev != ip->i_dev || - (bp->b_flags & B_DELWRI) == 0) - continue; - s = splbio(); - if (bp->b_flags & B_BUSY) { - bp->b_flags |= B_WANTED; - sleep((caddr_t)bp, PRIBIO+1); - splx(s); - bp--; - continue; - } - splx(s); - notavail(bp); - bwrite(bp); - } - } - ip->i_flag |= ICHG; - iupdat(ip, &time, &time, 1); + lastlbn = howmany(ip->i_size, DEV_BSIZE); + if (lastlbn < NBUF / 2) { + for (lbn = 0; lbn < lastlbn; lbn++) { + blkno = fsbtodb(bmap(ip, lbn, B_READ, 0)); + blkflush(ip->i_dev, blkno); + } + } else { + lastbufp = &buf[NBUF]; + for (bp = buf; bp < lastbufp; bp++) { + if (bp->b_dev != ip->i_dev || + (bp->b_flags & B_DELWRI) == 0) + continue; + s = splbio(); + if (bp->b_flags & B_BUSY) { + bp->b_flags |= B_WANTED; + sleep((caddr_t)bp, PRIBIO+1); + splx(s); + bp--; + continue; + } + splx(s); + notavail(bp); + bwrite(bp); + } + } + ip->i_flag |= ICHG; + iupdat(ip, &time, &time, 1); } /* @@ -103,15 +103,15 @@ syncip(ip) */ int badblock (fp, bn) - register struct fs *fp; - daddr_t bn; + register struct fs *fp; + daddr_t bn; { - if (bn < fp->fs_isize || bn >= fp->fs_fsize) { - printf("bad block %D, ",bn); - fserr(fp, "bad block"); - return (1); - } - return (0); + if (bn < fp->fs_isize || bn >= fp->fs_fsize) { + printf("bad block %D, ",bn); + fserr(fp, "bad block"); + return (1); + } + return (0); } /* @@ -121,25 +121,25 @@ badblock (fp, bn) * consistency check of the super block magic number is performed. * * panic: no fs -- the device is not mounted. - * this "cannot happen" + * this "cannot happen" */ struct fs * getfs(dev) - dev_t dev; + dev_t dev; { - register struct mount *mp; - register struct fs *fs; + register struct mount *mp; + register struct fs *fs; - for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) { - if (mp->m_inodp == NULL || mp->m_dev != dev) - continue; - fs = &mp->m_filsys; - if (fs->fs_nfree > NICFREE || fs->fs_ninode > NICINOD) { - fserr(fs, "bad count"); - fs->fs_nfree = fs->fs_ninode = 0; - } - return(fs); - } - printf("no fs on dev %u/%u\n",major(dev), minor(dev)); - return((struct fs *) NULL); + for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) { + if (mp->m_inodp == NULL || mp->m_dev != dev) + continue; + fs = &mp->m_filsys; + if (fs->fs_nfree > NICFREE || fs->fs_ninode > NICINOD) { + fserr(fs, "bad count"); + fs->fs_nfree = fs->fs_ninode = 0; + } + return(fs); + } + printf("no fs on dev %u/%u\n",major(dev), minor(dev)); + return((struct fs *) NULL); } diff --git a/sys/kernel/ufs_syscalls.c b/sys/kernel/ufs_syscalls.c index 6b4362e..85a425c 100644 --- a/sys/kernel/ufs_syscalls.c +++ b/sys/kernel/ufs_syscalls.c @@ -19,33 +19,33 @@ */ static void chdirec(ipp) - register struct inode **ipp; + register struct inode **ipp; { - register struct inode *ip; - struct a { - char *fname; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct inode *ip; + struct a { + char *fname; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - ip = namei(ndp); - if (ip == NULL) - return; - if ((ip->i_mode&IFMT) != IFDIR) { - u.u_error = ENOTDIR; - goto bad; - } - if (access(ip, IEXEC)) - goto bad; - iunlock(ip); - if (*ipp) - irele(*ipp); - *ipp = ip; - return; + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + ip = namei(ndp); + if (ip == NULL) + return; + if ((ip->i_mode&IFMT) != IFDIR) { + u.u_error = ENOTDIR; + goto bad; + } + if (access(ip, IEXEC)) + goto bad; + iunlock(ip); + if (*ipp) + irele(*ipp); + *ipp = ip; + return; bad: - iput(ip); + iput(ip); } /* @@ -54,35 +54,35 @@ bad: void chdir() { - chdirec (&u.u_cdir); + chdirec (&u.u_cdir); } void fchdir() { - register struct a { - int fd; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; + register struct a { + int fd; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; - ip = getinode (uap->fd); - if (ip == NULL) - return; - ilock(ip); - if ((ip->i_mode & IFMT) != IFDIR) { - u.u_error = ENOTDIR; - goto bad; - } - if (access (ip, IEXEC)) - goto bad; - iunlock(ip); - ip->i_count++; - irele(u.u_cdir); - u.u_cdir = ip; - return; + ip = getinode (uap->fd); + if (ip == NULL) + return; + ilock(ip); + if ((ip->i_mode & IFMT) != IFDIR) { + u.u_error = ENOTDIR; + goto bad; + } + if (access (ip, IEXEC)) + goto bad; + iunlock(ip); + ip->i_count++; + irele(u.u_cdir); + u.u_cdir = ip; + return; bad: - iunlock(ip); - return; + iunlock(ip); + return; } /* @@ -91,8 +91,8 @@ bad: void chroot() { - if (suser()) - chdirec (&u.u_rdir); + if (suser()) + chdirec (&u.u_rdir); } /* @@ -101,78 +101,78 @@ chroot() */ static int copen (mode, cmode, fname) - int mode; - int cmode; - caddr_t fname; + int mode; + int cmode; + caddr_t fname; { - register struct inode *ip; - register struct file *fp; - struct nameidata nd; - register struct nameidata *ndp = &nd; - int indx, type, flags, error; + register struct inode *ip; + register struct file *fp; + struct nameidata nd; + register struct nameidata *ndp = &nd; + int indx, type, flags, error; - if (! fname) - fname = ""; + if (! fname) + fname = ""; //printf ("copen (mode=%#o, cmode=%#o, fname=%#x '%s')\n", mode, cmode, fname, fname); - fp = falloc(); - if (fp == NULL) { + fp = falloc(); + if (fp == NULL) { //printf ("copen: falloc failed, errno=%d\n", u.u_error); - return(u.u_error); /* XXX */ - } - flags = FFLAGS(mode); /* convert from open to kernel flags */ - fp->f_flag = flags & FMASK; - fp->f_type = DTYPE_INODE; - cmode &= 077777 & ~ISVTX; - indx = u.u_rval; - u.u_dupfd = -indx - 1; - NDINIT (ndp, LOOKUP, FOLLOW, fname); + return(u.u_error); /* XXX */ + } + flags = FFLAGS(mode); /* convert from open to kernel flags */ + fp->f_flag = flags & FMASK; + fp->f_type = DTYPE_INODE; + cmode &= 077777 & ~ISVTX; + indx = u.u_rval; + u.u_dupfd = -indx - 1; + NDINIT (ndp, LOOKUP, FOLLOW, fname); - /* - * ENODEV is returned by the 'fdopen()' routine - see the comments in that - * routine for details about the hack being used. - * - * ENXIO only comes out of the 'portal fs' code (which 2.11BSD does not have). - * It probably should have been removed during the port of the 'file descriptor - * driver' since it's a "can not happen" event. - * - * u.u_dupfd is used because there the space in the proc structure is at a - * premium in 2.11 while space in the u structure is relatively free. Also - * there were more unused (pad) fields available in 'u' as compared to 'proc'. - */ - error = vn_open(ndp, flags, cmode); - if (error) { + /* + * ENODEV is returned by the 'fdopen()' routine - see the comments in that + * routine for details about the hack being used. + * + * ENXIO only comes out of the 'portal fs' code (which 2.11BSD does not have). + * It probably should have been removed during the port of the 'file descriptor + * driver' since it's a "can not happen" event. + * + * u.u_dupfd is used because there the space in the proc structure is at a + * premium in 2.11 while space in the u structure is relatively free. Also + * there were more unused (pad) fields available in 'u' as compared to 'proc'. + */ + error = vn_open(ndp, flags, cmode); + if (error) { //printf ("copen: vn_open failed, errno=%d\n", error); - fp->f_count = 0; - if ((error == ENODEV || error == ENXIO) && - u.u_dupfd >= 0 && - (error = dupfdopen(indx,u.u_dupfd,flags,error) == 0)) { - u.u_rval = indx; - return(0); - } - u.u_ofile[indx] = NULL; - return(error); - } - ip = ndp->ni_ip; - u.u_dupfd = 0; + fp->f_count = 0; + if ((error == ENODEV || error == ENXIO) && + u.u_dupfd >= 0 && + (error = dupfdopen(indx,u.u_dupfd,flags,error) == 0)) { + u.u_rval = indx; + return(0); + } + u.u_ofile[indx] = NULL; + return(error); + } + ip = ndp->ni_ip; + u.u_dupfd = 0; - fp->f_data = (caddr_t)ip; + fp->f_data = (caddr_t)ip; - if (flags & (O_EXLOCK | O_SHLOCK)) { - if (flags & O_EXLOCK) - type = LOCK_EX; - else - type = LOCK_SH; - if (flags & FNONBLOCK) - type |= LOCK_NB; - error = ino_lock(fp, type); - if (error) { + if (flags & (O_EXLOCK | O_SHLOCK)) { + if (flags & O_EXLOCK) + type = LOCK_EX; + else + type = LOCK_SH; + if (flags & FNONBLOCK) + type |= LOCK_NB; + error = ino_lock(fp, type); + if (error) { //printf ("copen: ino_lock failed, errno=%d\n", error); - closef(fp); - u.u_ofile[indx] = NULL; - } - } + closef(fp); + u.u_ofile[indx] = NULL; + } + } //printf ("copen returned errno=%d\n", error); - return(error); + return(error); } /* @@ -181,13 +181,13 @@ copen (mode, cmode, fname) void open() { - register struct a { - char *fname; - int mode; - int crtmode; - } *uap = (struct a *) u.u_arg; + register struct a { + char *fname; + int mode; + int crtmode; + } *uap = (struct a *) u.u_arg; - u.u_error = copen (uap->mode, uap->crtmode, uap->fname); + u.u_error = copen (uap->mode, uap->crtmode, uap->fname); } /* @@ -196,45 +196,45 @@ open() void mknod() { - register struct inode *ip; - register struct a { - char *fname; - int fmode; - int dev; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct inode *ip; + register struct a { + char *fname; + int fmode; + int dev; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; - if (! suser()) - return; - NDINIT (ndp, CREATE, NOFOLLOW, uap->fname); - ip = namei(ndp); - if (ip != NULL) { - u.u_error = EEXIST; - goto out; - } - if (u.u_error) - return; - ip = maknode (uap->fmode, ndp); - if (ip == NULL) - return; - switch (ip->i_mode & IFMT) { + if (! suser()) + return; + NDINIT (ndp, CREATE, NOFOLLOW, uap->fname); + ip = namei(ndp); + if (ip != NULL) { + u.u_error = EEXIST; + goto out; + } + if (u.u_error) + return; + ip = maknode (uap->fmode, ndp); + if (ip == NULL) + return; + switch (ip->i_mode & IFMT) { - case IFMT: /* used by badsect to flag bad sectors */ - case IFCHR: - case IFBLK: - if (uap->dev) { - /* - * Want to be able to use this to make badblock - * inodes, so don't truncate the dev number. - */ - ip->i_rdev = uap->dev; - ip->i_dummy = 0; - ip->i_flag |= IACC|IUPD|ICHG; - } - } + case IFMT: /* used by badsect to flag bad sectors */ + case IFCHR: + case IFBLK: + if (uap->dev) { + /* + * Want to be able to use this to make badblock + * inodes, so don't truncate the dev number. + */ + ip->i_rdev = uap->dev; + ip->i_dummy = 0; + ip->i_flag |= IACC|IUPD|ICHG; + } + } out: - iput(ip); + iput(ip); } /* @@ -243,53 +243,53 @@ out: void link() { - register struct inode *ip, *xp; - register struct a { - char *target; - char *linkname; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct inode *ip, *xp; + register struct a { + char *target; + char *linkname; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, LOOKUP, FOLLOW, uap->target); - ip = namei(ndp); /* well, this routine is doomed anyhow */ - if (ip == NULL) - return; - if ((ip->i_mode&IFMT) == IFDIR && !suser()) { - iput(ip); - return; - } - if (ip->i_flags & (IMMUTABLE|APPEND)) { - u.u_error = EPERM; - iput(ip); - return; - } - ip->i_nlink++; - ip->i_flag |= ICHG; - iupdat(ip, &time, &time, 1); - iunlock(ip); - ndp->ni_nameiop = CREATE; - ndp->ni_dirp = (caddr_t)uap->linkname; - xp = namei(ndp); - if (xp != NULL) { - u.u_error = EEXIST; - iput(xp); - goto out; - } - if (u.u_error) - goto out; - if (ndp->ni_pdir->i_dev != ip->i_dev) { - iput(ndp->ni_pdir); - u.u_error = EXDEV; - goto out; - } - u.u_error = direnter(ip, ndp); + NDINIT (ndp, LOOKUP, FOLLOW, uap->target); + ip = namei(ndp); /* well, this routine is doomed anyhow */ + if (ip == NULL) + return; + if ((ip->i_mode&IFMT) == IFDIR && !suser()) { + iput(ip); + return; + } + if (ip->i_flags & (IMMUTABLE|APPEND)) { + u.u_error = EPERM; + iput(ip); + return; + } + ip->i_nlink++; + ip->i_flag |= ICHG; + iupdat(ip, &time, &time, 1); + iunlock(ip); + ndp->ni_nameiop = CREATE; + ndp->ni_dirp = (caddr_t)uap->linkname; + xp = namei(ndp); + if (xp != NULL) { + u.u_error = EEXIST; + iput(xp); + goto out; + } + if (u.u_error) + goto out; + if (ndp->ni_pdir->i_dev != ip->i_dev) { + iput(ndp->ni_pdir); + u.u_error = EXDEV; + goto out; + } + u.u_error = direnter(ip, ndp); out: - if (u.u_error) { - ip->i_nlink--; - ip->i_flag |= ICHG; - } - irele(ip); + if (u.u_error) { + ip->i_nlink--; + ip->i_flag |= ICHG; + } + irele(ip); } /* @@ -298,45 +298,45 @@ out: void symlink() { - register struct a { - char *target; - char *linkname; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - char *tp; - int c, nc; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct a { + char *target; + char *linkname; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + char *tp; + int c, nc; + struct nameidata nd; + register struct nameidata *ndp = &nd; - tp = uap->target; - nc = 0; - for (;;) { - if (baduaddr (tp)) { - u.u_error = EFAULT; - return; - } - c = (u_char) *tp; - if (c == 0) - break; - tp++; - nc++; - } - NDINIT (ndp, CREATE, NOFOLLOW, uap->linkname); - ip = namei(ndp); - if (ip) { - iput(ip); - u.u_error = EEXIST; - return; - } - if (u.u_error) - return; - ip = maknode (IFLNK | 0777, ndp); - if (ip == NULL) - return; - u.u_error = rdwri (UIO_WRITE, ip, uap->target, nc, (off_t) 0, - IO_UNIT, (int*) 0); - /* handle u.u_error != 0 */ - iput(ip); + tp = uap->target; + nc = 0; + for (;;) { + if (baduaddr (tp)) { + u.u_error = EFAULT; + return; + } + c = (u_char) *tp; + if (c == 0) + break; + tp++; + nc++; + } + NDINIT (ndp, CREATE, NOFOLLOW, uap->linkname); + ip = namei(ndp); + if (ip) { + iput(ip); + u.u_error = EEXIST; + return; + } + if (u.u_error) + return; + ip = maknode (IFLNK | 0777, ndp); + if (ip == NULL) + return; + u.u_error = rdwri (UIO_WRITE, ip, uap->target, nc, (off_t) 0, + IO_UNIT, (int*) 0); + /* handle u.u_error != 0 */ + iput(ip); } /* @@ -347,41 +347,41 @@ symlink() void unlink() { - register struct a { - char *fname; - } *uap = (struct a *)u.u_arg; - register struct inode *ip, *dp; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct a { + char *fname; + } *uap = (struct a *)u.u_arg; + register struct inode *ip, *dp; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, DELETE, LOCKPARENT, uap->fname); - ip = namei(ndp); - if (ip == NULL) - return; - dp = ndp->ni_pdir; - if ((ip->i_mode&IFMT) == IFDIR && !suser()) - goto out; - /* - * Don't unlink a mounted file. - */ - if (ip->i_dev != dp->i_dev) { - u.u_error = EBUSY; - goto out; - } - if ((ip->i_flags & (IMMUTABLE|APPEND)) || (dp->i_flags & APPEND)) { - u.u_error = EPERM; - goto out; - } - if (dirremove(ndp)) { - ip->i_nlink--; - ip->i_flag |= ICHG; - } + NDINIT (ndp, DELETE, LOCKPARENT, uap->fname); + ip = namei(ndp); + if (ip == NULL) + return; + dp = ndp->ni_pdir; + if ((ip->i_mode&IFMT) == IFDIR && !suser()) + goto out; + /* + * Don't unlink a mounted file. + */ + if (ip->i_dev != dp->i_dev) { + u.u_error = EBUSY; + goto out; + } + if ((ip->i_flags & (IMMUTABLE|APPEND)) || (dp->i_flags & APPEND)) { + u.u_error = EPERM; + goto out; + } + if (dirremove(ndp)) { + ip->i_nlink--; + ip->i_flag |= ICHG; + } out: - if (dp == ip) - irele(ip); - else - iput(ip); - iput(dp); + if (dp == ip) + irele(ip); + else + iput(ip); + iput(dp); } /* @@ -390,56 +390,56 @@ out: void saccess() { - uid_t t_uid; - gid_t t_gid; - register struct inode *ip; - register struct a { - char *fname; - int fmode; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; + uid_t t_uid; + gid_t t_gid; + register struct inode *ip; + register struct a { + char *fname; + int fmode; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; - t_uid = u.u_uid; - t_gid = u.u_groups[0]; - u.u_uid = u.u_ruid; - u.u_groups[0] = u.u_rgid; - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - ip = namei(ndp); - if (ip != NULL) { - if ((uap->fmode&R_OK) && access(ip, IREAD)) - goto done; - if ((uap->fmode&W_OK) && access(ip, IWRITE)) - goto done; - if ((uap->fmode&X_OK) && access(ip, IEXEC)) - goto done; + t_uid = u.u_uid; + t_gid = u.u_groups[0]; + u.u_uid = u.u_ruid; + u.u_groups[0] = u.u_rgid; + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + ip = namei(ndp); + if (ip != NULL) { + if ((uap->fmode&R_OK) && access(ip, IREAD)) + goto done; + if ((uap->fmode&W_OK) && access(ip, IWRITE)) + goto done; + if ((uap->fmode&X_OK) && access(ip, IEXEC)) + goto done; done: - iput(ip); - } - u.u_uid = t_uid; - u.u_groups[0] = t_gid; + iput(ip); + } + u.u_uid = t_uid; + u.u_groups[0] = t_gid; } static void stat1 (follow) - int follow; + int follow; { - register struct inode *ip; - register struct a { - char *fname; - struct stat *ub; - } *uap = (struct a *)u.u_arg; - struct stat sb; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct inode *ip; + register struct a { + char *fname; + struct stat *ub; + } *uap = (struct a *)u.u_arg; + struct stat sb; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, LOOKUP, follow, uap->fname); - ip = namei(ndp); - if (ip == NULL) - return; - (void) ino_stat(ip, &sb); - iput(ip); - u.u_error = copyout((caddr_t)&sb, (caddr_t)uap->ub, sizeof (sb)); + NDINIT (ndp, LOOKUP, follow, uap->fname); + ip = namei(ndp); + if (ip == NULL) + return; + (void) ino_stat(ip, &sb); + iput(ip); + u.u_error = copyout((caddr_t)&sb, (caddr_t)uap->ub, sizeof (sb)); } /* @@ -448,7 +448,7 @@ stat1 (follow) void stat() { - stat1 (FOLLOW); + stat1 (FOLLOW); } /* @@ -457,7 +457,7 @@ stat() void lstat() { - stat1 (NOFOLLOW); + stat1 (NOFOLLOW); } /* @@ -466,41 +466,41 @@ lstat() void readlink() { - register struct inode *ip; - register struct a { - char *name; - char *buf; - int count; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; - int resid; + register struct inode *ip; + register struct a { + char *name; + char *buf; + int count; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; + int resid; - NDINIT (ndp, LOOKUP, NOFOLLOW, uap->name); - ip = namei(ndp); - if (ip == NULL) - return; - if ((ip->i_mode&IFMT) != IFLNK) { - u.u_error = EINVAL; - goto out; - } - u.u_error = rdwri (UIO_READ, ip, uap->buf, uap->count, (off_t) 0, - IO_UNIT, &resid); + NDINIT (ndp, LOOKUP, NOFOLLOW, uap->name); + ip = namei(ndp); + if (ip == NULL) + return; + if ((ip->i_mode&IFMT) != IFLNK) { + u.u_error = EINVAL; + goto out; + } + u.u_error = rdwri (UIO_READ, ip, uap->buf, uap->count, (off_t) 0, + IO_UNIT, &resid); out: - iput(ip); - u.u_rval = uap->count - resid; + iput(ip); + u.u_rval = uap->count - resid; } static int chflags1 (ip, flags) - register struct inode *ip; - u_short flags; + register struct inode *ip; + u_short flags; { - struct vattr vattr; + struct vattr vattr; - VATTR_NULL(&vattr); - vattr.va_flags = flags; - return(ufs_setattr(ip, &vattr)); + VATTR_NULL(&vattr); + vattr.va_flags = flags; + return(ufs_setattr(ip, &vattr)); } /* @@ -509,19 +509,19 @@ chflags1 (ip, flags) void chflags() { - register struct inode *ip; - register struct a { - char *fname; - u_int flags; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct inode *ip; + register struct a { + char *fname; + u_int flags; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - if ((ip = namei(ndp)) == NULL) - return; - u.u_error = chflags1 (ip, uap->flags); - iput(ip); + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + if ((ip = namei(ndp)) == NULL) + return; + u.u_error = chflags1 (ip, uap->flags); + iput(ip); } /* @@ -530,18 +530,18 @@ chflags() void fchflags() { - register struct a { - int fd; - u_int flags; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; + register struct a { + int fd; + u_int flags; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; - ip = getinode (uap->fd); - if (ip == NULL) - return; - ilock(ip); - u.u_error = chflags1 (ip, uap->flags); - iunlock(ip); + ip = getinode (uap->fd); + if (ip == NULL) + return; + ilock(ip); + u.u_error = chflags1 (ip, uap->flags); + iunlock(ip); } /* @@ -550,23 +550,23 @@ fchflags() void chmod() { - register struct inode *ip; - register struct a { - char *fname; - int fmode; - } *uap = (struct a *)u.u_arg; - struct vattr vattr; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct inode *ip; + register struct a { + char *fname; + int fmode; + } *uap = (struct a *)u.u_arg; + struct vattr vattr; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - ip = namei(ndp); - if (!ip) - return; - VATTR_NULL(&vattr); - vattr.va_mode = uap->fmode & 07777; - u.u_error = ufs_setattr(ip, &vattr); - iput(ip); + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + ip = namei(ndp); + if (!ip) + return; + VATTR_NULL(&vattr); + vattr.va_mode = uap->fmode & 07777; + u.u_error = ufs_setattr(ip, &vattr); + iput(ip); } /* @@ -575,20 +575,20 @@ chmod() void fchmod() { - register struct a { - int fd; - int fmode; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - struct vattr vattr; + register struct a { + int fd; + int fmode; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + struct vattr vattr; - if ((ip = getinode(uap->fd)) == NULL) - return; - ilock(ip); - VATTR_NULL(&vattr); - vattr.va_mode = uap->fmode & 07777; - u.u_error = ufs_setattr(ip, &vattr); - iunlock(ip); + if ((ip = getinode(uap->fd)) == NULL) + return; + ilock(ip); + VATTR_NULL(&vattr); + vattr.va_mode = uap->fmode & 07777; + u.u_error = ufs_setattr(ip, &vattr); + iunlock(ip); } /* @@ -597,22 +597,21 @@ fchmod() */ int chmod1(ip, mode) - register struct inode *ip; - register int mode; + register struct inode *ip; + register int mode; { - - if (u.u_uid != ip->i_uid && !suser()) - return(u.u_error); - if (u.u_uid) { - if ((ip->i_mode & IFMT) != IFDIR && (mode & ISVTX)) - return(EFTYPE); - if (!groupmember(ip->i_gid) && (mode & ISGID)) - return(EPERM); - } - ip->i_mode &= ~07777; /* why? */ - ip->i_mode |= mode&07777; - ip->i_flag |= ICHG; - return (0); + if (u.u_uid != ip->i_uid && !suser()) + return(u.u_error); + if (u.u_uid) { + if ((ip->i_mode & IFMT) != IFDIR && (mode & ISVTX)) + return(EFTYPE); + if (!groupmember(ip->i_gid) && (mode & ISGID)) + return(EPERM); + } + ip->i_mode &= ~07777; /* why? */ + ip->i_mode |= mode&07777; + ip->i_flag |= ICHG; + return (0); } /* @@ -621,25 +620,25 @@ chmod1(ip, mode) void chown() { - register struct inode *ip; - register struct a { - char *fname; - int uid; - int gid; - } *uap = (struct a *)u.u_arg; - struct nameidata nd; - register struct nameidata *ndp = &nd; - struct vattr vattr; + register struct inode *ip; + register struct a { + char *fname; + int uid; + int gid; + } *uap = (struct a *)u.u_arg; + struct nameidata nd; + register struct nameidata *ndp = &nd; + struct vattr vattr; - NDINIT (ndp, LOOKUP, NOFOLLOW, uap->fname); - ip = namei(ndp); - if (ip == NULL) - return; - VATTR_NULL(&vattr); - vattr.va_uid = uap->uid; - vattr.va_gid = uap->gid; - u.u_error = ufs_setattr(ip, &vattr); - iput(ip); + NDINIT (ndp, LOOKUP, NOFOLLOW, uap->fname); + ip = namei(ndp); + if (ip == NULL) + return; + VATTR_NULL(&vattr); + vattr.va_uid = uap->uid; + vattr.va_gid = uap->gid; + u.u_error = ufs_setattr(ip, &vattr); + iput(ip); } /* @@ -648,22 +647,22 @@ chown() void fchown() { - register struct a { - int fd; - int uid; - int gid; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - struct vattr vattr; + register struct a { + int fd; + int uid; + int gid; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + struct vattr vattr; - if ((ip = getinode(uap->fd)) == NULL) - return; - ilock(ip); - VATTR_NULL(&vattr); - vattr.va_uid = uap->uid; - vattr.va_gid = uap->gid; - u.u_error = ufs_setattr(ip, &vattr); - iunlock(ip); + if ((ip = getinode(uap->fd)) == NULL) + return; + ilock(ip); + VATTR_NULL(&vattr); + vattr.va_uid = uap->uid; + vattr.va_gid = uap->gid; + u.u_error = ufs_setattr(ip, &vattr); + iunlock(ip); } /* @@ -672,34 +671,34 @@ fchown() */ int chown1 (ip, uid, gid) - register struct inode *ip; - register int uid, gid; + register struct inode *ip; + register int uid, gid; { - int ouid, ogid; + int ouid, ogid; - if (uid == -1) - uid = ip->i_uid; - if (gid == -1) - gid = ip->i_gid; - /* - * If we don't own the file, are trying to change the owner - * of the file, or are not a member of the target group, - * the caller must be superuser or the call fails. - */ - if ((u.u_uid != ip->i_uid || uid != ip->i_uid || - !groupmember((gid_t)gid)) && !suser()) - return (u.u_error); - ouid = ip->i_uid; - ogid = ip->i_gid; - ip->i_uid = uid; - ip->i_gid = gid; - if (ouid != uid || ogid != gid) - ip->i_flag |= ICHG; - if (ouid != uid && u.u_uid != 0) - ip->i_mode &= ~ISUID; - if (ogid != gid && u.u_uid != 0) - ip->i_mode &= ~ISGID; - return (0); + if (uid == -1) + uid = ip->i_uid; + if (gid == -1) + gid = ip->i_gid; + /* + * If we don't own the file, are trying to change the owner + * of the file, or are not a member of the target group, + * the caller must be superuser or the call fails. + */ + if ((u.u_uid != ip->i_uid || uid != ip->i_uid || + !groupmember((gid_t)gid)) && !suser()) + return (u.u_error); + ouid = ip->i_uid; + ogid = ip->i_gid; + ip->i_uid = uid; + ip->i_gid = gid; + if (ouid != uid || ogid != gid) + ip->i_flag |= ICHG; + if (ouid != uid && u.u_uid != 0) + ip->i_mode &= ~ISUID; + if (ogid != gid && u.u_uid != 0) + ip->i_mode &= ~ISGID; + return (0); } /* @@ -708,26 +707,26 @@ chown1 (ip, uid, gid) void truncate() { - register struct a { - char *fname; - off_t length; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - struct nameidata nd; - register struct nameidata *ndp = &nd; - struct vattr vattr; + register struct a { + char *fname; + off_t length; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + struct nameidata nd; + register struct nameidata *ndp = &nd; + struct vattr vattr; - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - ip = namei(ndp); - if (ip == NULL) - return; - if (access(ip, IWRITE)) - goto bad; - VATTR_NULL(&vattr); - vattr.va_size = uap->length; - u.u_error = ufs_setattr(ip, &vattr); + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + ip = namei(ndp); + if (ip == NULL) + return; + if (access(ip, IWRITE)) + goto bad; + VATTR_NULL(&vattr); + vattr.va_size = uap->length; + u.u_error = ufs_setattr(ip, &vattr); bad: - iput(ip); + iput(ip); } /* @@ -736,35 +735,35 @@ bad: void ftruncate() { - register struct a { - int fd; - off_t length; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - register struct file *fp; - struct vattr vattr; + register struct a { + int fd; + off_t length; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + register struct file *fp; + struct vattr vattr; - if ((fp = getf(uap->fd)) == NULL) - return; - if (!(fp->f_flag&FWRITE) || (fp->f_type != DTYPE_INODE)) { - u.u_error = EINVAL; - return; - } - ip = (struct inode *)fp->f_data; - ilock(ip); - VATTR_NULL(&vattr); - vattr.va_size = uap->length; - u.u_error = ufs_setattr(ip, &vattr); - iunlock(ip); + if ((fp = getf(uap->fd)) == NULL) + return; + if (!(fp->f_flag&FWRITE) || (fp->f_type != DTYPE_INODE)) { + u.u_error = EINVAL; + return; + } + ip = (struct inode *)fp->f_data; + ilock(ip); + VATTR_NULL(&vattr); + vattr.va_size = uap->length; + u.u_error = ufs_setattr(ip, &vattr); + iunlock(ip); } /* * Rename system call. - * rename("foo", "bar"); + * rename("foo", "bar"); * is essentially - * unlink("bar"); - * link("foo", "bar"); - * unlink("foo"); + * unlink("bar"); + * link("foo", "bar"); + * unlink("foo"); * but ``atomically''. Can't do full commit without saving state in the * inode on disk which isn't feasible at this time. Best we can do is * always guarantee the target exists. @@ -788,295 +787,295 @@ ftruncate() void rename() { - struct a { - char *from; - char *to; - } *uap = (struct a *)u.u_arg; - register struct inode *ip, *xp, *dp; - struct dirtemplate dirbuf; - int doingdirectory = 0, oldparent = 0, newparent = 0; - struct nameidata nd; - register struct nameidata *ndp = &nd; - int error = 0; + struct a { + char *from; + char *to; + } *uap = (struct a *)u.u_arg; + register struct inode *ip, *xp, *dp; + struct dirtemplate dirbuf; + int doingdirectory = 0, oldparent = 0, newparent = 0; + struct nameidata nd; + register struct nameidata *ndp = &nd; + int error = 0; - NDINIT (ndp, DELETE, LOCKPARENT, uap->from); - ip = namei(ndp); - if (ip == NULL) - return; - dp = ndp->ni_pdir; - /* - * 'from' file can not be renamed if it is immutable/appendonly or if its - * parent directory is append only. - */ - if ((ip->i_flags & (IMMUTABLE|APPEND)) || (dp->i_flags & APPEND)) { - iput(dp); - if (dp == ip) - irele(ip); - else - iput(ip); - u.u_error = EPERM; - return; - } + NDINIT (ndp, DELETE, LOCKPARENT, uap->from); + ip = namei(ndp); + if (ip == NULL) + return; + dp = ndp->ni_pdir; + /* + * 'from' file can not be renamed if it is immutable/appendonly or if its + * parent directory is append only. + */ + if ((ip->i_flags & (IMMUTABLE|APPEND)) || (dp->i_flags & APPEND)) { + iput(dp); + if (dp == ip) + irele(ip); + else + iput(ip); + u.u_error = EPERM; + return; + } - if ((ip->i_mode&IFMT) == IFDIR) { - register struct direct *d; + if ((ip->i_mode&IFMT) == IFDIR) { + register struct direct *d; - d = &ndp->ni_dent; - /* - * Avoid ".", "..", and aliases of "." for obvious reasons. - */ - if ((d->d_namlen == 1 && d->d_name[0] == '.') || - (d->d_namlen == 2 && bcmp(d->d_name, "..", 2) == 0) || - (dp == ip) || (ip->i_flag & IRENAME)) { - iput(dp); - if (dp == ip) - irele(ip); - else - iput(ip); - u.u_error = EINVAL; - return; - } - ip->i_flag |= IRENAME; - oldparent = dp->i_number; - doingdirectory++; - } - iput(dp); + d = &ndp->ni_dent; + /* + * Avoid ".", "..", and aliases of "." for obvious reasons. + */ + if ((d->d_namlen == 1 && d->d_name[0] == '.') || + (d->d_namlen == 2 && bcmp(d->d_name, "..", 2) == 0) || + (dp == ip) || (ip->i_flag & IRENAME)) { + iput(dp); + if (dp == ip) + irele(ip); + else + iput(ip); + u.u_error = EINVAL; + return; + } + ip->i_flag |= IRENAME; + oldparent = dp->i_number; + doingdirectory++; + } + iput(dp); - /* - * 1) Bump link count while we're moving stuff - * around. If we crash somewhere before - * completing our work, the link count - * may be wrong, but correctable. - */ - ip->i_nlink++; - ip->i_flag |= ICHG; - iupdat(ip, &time, &time, 1); - iunlock(ip); + /* + * 1) Bump link count while we're moving stuff + * around. If we crash somewhere before + * completing our work, the link count + * may be wrong, but correctable. + */ + ip->i_nlink++; + ip->i_flag |= ICHG; + iupdat(ip, &time, &time, 1); + iunlock(ip); - /* - * When the target exists, both the directory - * and target inodes are returned locked. - */ - ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; - ndp->ni_dirp = (caddr_t)uap->to; - xp = namei(ndp); - if (u.u_error) { - error = u.u_error; - goto out; - } - dp = ndp->ni_pdir; - /* - * rename can not be done if 'to' file exists and is immutable/appendonly - * or if the directory is append only (this is because an existing 'to' - * has to be deleted first and that is illegal in an appendonly directory). - */ - if (xp && ((xp->i_flags & (IMMUTABLE|APPEND)) || (dp->i_flags & APPEND))) { - error = EPERM; - goto bad; - } + /* + * When the target exists, both the directory + * and target inodes are returned locked. + */ + ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; + ndp->ni_dirp = (caddr_t)uap->to; + xp = namei(ndp); + if (u.u_error) { + error = u.u_error; + goto out; + } + dp = ndp->ni_pdir; + /* + * rename can not be done if 'to' file exists and is immutable/appendonly + * or if the directory is append only (this is because an existing 'to' + * has to be deleted first and that is illegal in an appendonly directory). + */ + if (xp && ((xp->i_flags & (IMMUTABLE|APPEND)) || (dp->i_flags & APPEND))) { + error = EPERM; + goto bad; + } - /* - * If ".." must be changed (ie the directory gets a new - * parent) then the source directory must not be in the - * directory heirarchy above the target, as this would - * orphan everything below the source directory. Also - * the user must have write permission in the source so - * as to be able to change "..". We must repeat the call - * to namei, as the parent directory is unlocked by the - * call to checkpath(). - */ - if (oldparent != dp->i_number) - newparent = dp->i_number; - if (doingdirectory && newparent) { - if (access(ip, IWRITE)) - goto bad; - do { - dp = ndp->ni_pdir; - if (xp != NULL) - iput(xp); - u.u_error = checkpath(ip, dp); - if (u.u_error) - goto out; - xp = namei(ndp); - if (u.u_error) { - error = u.u_error; - goto out; - } - } while (dp != ndp->ni_pdir); - } - /* - * 2) If target doesn't exist, link the target - * to the source and unlink the source. - * Otherwise, rewrite the target directory - * entry to reference the source inode and - * expunge the original entry's existence. - */ - if (xp == NULL) { - if (dp->i_dev != ip->i_dev) { - error = EXDEV; - goto bad; - } - /* - * Account for ".." in new directory. - * When source and destination have the same - * parent we don't fool with the link count. - */ - if (doingdirectory && newparent) { - dp->i_nlink++; - dp->i_flag |= ICHG; - iupdat(dp, &time, &time, 1); - } - error = direnter(ip, ndp); - if (error) - goto out; - } else { - if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev) { - error = EXDEV; - goto bad; - } - /* - * Short circuit rename(foo, foo). - */ - if (xp->i_number == ip->i_number) - goto bad; - /* - * If the parent directory is "sticky", then the user must - * own the parent directory, or the destination of the rename, - * otherwise the destination may not be changed (except by - * root). This implements append-only directories. - */ - if ((dp->i_mode & ISVTX) && u.u_uid != 0 && - u.u_uid != dp->i_uid && xp->i_uid != u.u_uid) { - error = EPERM; - goto bad; - } - /* - * Target must be empty if a directory - * and have no links to it. - * Also, insure source and target are - * compatible (both directories, or both - * not directories). - */ - if ((xp->i_mode&IFMT) == IFDIR) { - if (!dirempty(xp, dp->i_number) || xp->i_nlink > 2) { - error = ENOTEMPTY; - goto bad; - } - if (!doingdirectory) { - error = ENOTDIR; - goto bad; - } - cacheinval(dp); - } else if (doingdirectory) { - error = EISDIR; - goto bad; - } - dirrewrite(dp, ip, ndp); - if (u.u_error) { - error = u.u_error; - goto bad1; - } - /* - * Adjust the link count of the target to - * reflect the dirrewrite above. If this is - * a directory it is empty and there are - * no links to it, so we can squash the inode and - * any space associated with it. We disallowed - * renaming over top of a directory with links to - * it above, as the remaining link would point to - * a directory without "." or ".." entries. - */ - xp->i_nlink--; - if (doingdirectory) { - if (--xp->i_nlink != 0) - panic("rename: lnk dir"); - itrunc(xp, (u_long)0, 0); /* IO_SYNC? */ - } - xp->i_flag |= ICHG; - iput(xp); - xp = NULL; - } + /* + * If ".." must be changed (ie the directory gets a new + * parent) then the source directory must not be in the + * directory heirarchy above the target, as this would + * orphan everything below the source directory. Also + * the user must have write permission in the source so + * as to be able to change "..". We must repeat the call + * to namei, as the parent directory is unlocked by the + * call to checkpath(). + */ + if (oldparent != dp->i_number) + newparent = dp->i_number; + if (doingdirectory && newparent) { + if (access(ip, IWRITE)) + goto bad; + do { + dp = ndp->ni_pdir; + if (xp != NULL) + iput(xp); + u.u_error = checkpath(ip, dp); + if (u.u_error) + goto out; + xp = namei(ndp); + if (u.u_error) { + error = u.u_error; + goto out; + } + } while (dp != ndp->ni_pdir); + } + /* + * 2) If target doesn't exist, link the target + * to the source and unlink the source. + * Otherwise, rewrite the target directory + * entry to reference the source inode and + * expunge the original entry's existence. + */ + if (xp == NULL) { + if (dp->i_dev != ip->i_dev) { + error = EXDEV; + goto bad; + } + /* + * Account for ".." in new directory. + * When source and destination have the same + * parent we don't fool with the link count. + */ + if (doingdirectory && newparent) { + dp->i_nlink++; + dp->i_flag |= ICHG; + iupdat(dp, &time, &time, 1); + } + error = direnter(ip, ndp); + if (error) + goto out; + } else { + if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev) { + error = EXDEV; + goto bad; + } + /* + * Short circuit rename(foo, foo). + */ + if (xp->i_number == ip->i_number) + goto bad; + /* + * If the parent directory is "sticky", then the user must + * own the parent directory, or the destination of the rename, + * otherwise the destination may not be changed (except by + * root). This implements append-only directories. + */ + if ((dp->i_mode & ISVTX) && u.u_uid != 0 && + u.u_uid != dp->i_uid && xp->i_uid != u.u_uid) { + error = EPERM; + goto bad; + } + /* + * Target must be empty if a directory + * and have no links to it. + * Also, insure source and target are + * compatible (both directories, or both + * not directories). + */ + if ((xp->i_mode&IFMT) == IFDIR) { + if (!dirempty(xp, dp->i_number) || xp->i_nlink > 2) { + error = ENOTEMPTY; + goto bad; + } + if (!doingdirectory) { + error = ENOTDIR; + goto bad; + } + cacheinval(dp); + } else if (doingdirectory) { + error = EISDIR; + goto bad; + } + dirrewrite(dp, ip, ndp); + if (u.u_error) { + error = u.u_error; + goto bad1; + } + /* + * Adjust the link count of the target to + * reflect the dirrewrite above. If this is + * a directory it is empty and there are + * no links to it, so we can squash the inode and + * any space associated with it. We disallowed + * renaming over top of a directory with links to + * it above, as the remaining link would point to + * a directory without "." or ".." entries. + */ + xp->i_nlink--; + if (doingdirectory) { + if (--xp->i_nlink != 0) + panic("rename: lnk dir"); + itrunc(xp, (u_long)0, 0); /* IO_SYNC? */ + } + xp->i_flag |= ICHG; + iput(xp); + xp = NULL; + } - /* - * 3) Unlink the source. - */ - NDINIT (ndp, DELETE, LOCKPARENT, uap->from); - xp = namei(ndp); - if (xp != NULL) - dp = ndp->ni_pdir; - else - dp = NULL; - /* - * Insure that the directory entry still exists and has not - * changed while the new name has been entered. If the source is - * a file then the entry may have been unlinked or renamed. In - * either case there is no further work to be done. If the source - * is a directory then it cannot have been rmdir'ed; its link - * count of three would cause a rmdir to fail with ENOTEMPTY. - * The IRENAME flag insures that it cannot be moved by another - * rename. - */ - if (xp != ip) { - if (doingdirectory) - panic("rename: lost dir entry"); - } else { - /* - * If the source is a directory with a - * new parent, the link count of the old - * parent directory must be decremented - * and ".." set to point to the new parent. - */ - if (doingdirectory && newparent) { - dp->i_nlink--; - dp->i_flag |= ICHG; - error = rdwri (UIO_READ, xp, (caddr_t) &dirbuf, - sizeof(struct dirtemplate), (off_t) 0, - IO_UNIT, (int*) 0); + /* + * 3) Unlink the source. + */ + NDINIT (ndp, DELETE, LOCKPARENT, uap->from); + xp = namei(ndp); + if (xp != NULL) + dp = ndp->ni_pdir; + else + dp = NULL; + /* + * Insure that the directory entry still exists and has not + * changed while the new name has been entered. If the source is + * a file then the entry may have been unlinked or renamed. In + * either case there is no further work to be done. If the source + * is a directory then it cannot have been rmdir'ed; its link + * count of three would cause a rmdir to fail with ENOTEMPTY. + * The IRENAME flag insures that it cannot be moved by another + * rename. + */ + if (xp != ip) { + if (doingdirectory) + panic("rename: lost dir entry"); + } else { + /* + * If the source is a directory with a + * new parent, the link count of the old + * parent directory must be decremented + * and ".." set to point to the new parent. + */ + if (doingdirectory && newparent) { + dp->i_nlink--; + dp->i_flag |= ICHG; + error = rdwri (UIO_READ, xp, (caddr_t) &dirbuf, + sizeof(struct dirtemplate), (off_t) 0, + IO_UNIT, (int*) 0); - if (error == 0) { - if (dirbuf.dotdot_namlen != 2 || - dirbuf.dotdot_name[0] != '.' || - dirbuf.dotdot_name[1] != '.') { - printf("rename: mangled dir\n"); - } else { - dirbuf.dotdot_ino = newparent; - (void) rdwri (UIO_WRITE, xp, - (caddr_t) &dirbuf, - sizeof(struct dirtemplate), - (off_t) 0, - IO_UNIT | IO_SYNC, (int*) 0); - cacheinval(dp); - } - } - } - if (dirremove(ndp)) { - xp->i_nlink--; - xp->i_flag |= ICHG; - } - xp->i_flag &= ~IRENAME; - if (error == 0) /* XXX conservative */ - error = u.u_error; - } - if (dp) - iput(dp); - if (xp) - iput(xp); - irele(ip); - if (error) - u.u_error = error; - return; + if (error == 0) { + if (dirbuf.dotdot_namlen != 2 || + dirbuf.dotdot_name[0] != '.' || + dirbuf.dotdot_name[1] != '.') { + printf("rename: mangled dir\n"); + } else { + dirbuf.dotdot_ino = newparent; + (void) rdwri (UIO_WRITE, xp, + (caddr_t) &dirbuf, + sizeof(struct dirtemplate), + (off_t) 0, + IO_UNIT | IO_SYNC, (int*) 0); + cacheinval(dp); + } + } + } + if (dirremove(ndp)) { + xp->i_nlink--; + xp->i_flag |= ICHG; + } + xp->i_flag &= ~IRENAME; + if (error == 0) /* XXX conservative */ + error = u.u_error; + } + if (dp) + iput(dp); + if (xp) + iput(xp); + irele(ip); + if (error) + u.u_error = error; + return; bad: - iput(dp); + iput(dp); bad1: - if (xp) - iput(xp); + if (xp) + iput(xp); out: - ip->i_nlink--; - ip->i_flag |= ICHG; - irele(ip); - if (error) - u.u_error = error; + ip->i_nlink--; + ip->i_flag |= ICHG; + irele(ip); + if (error) + u.u_error = error; } /* @@ -1084,51 +1083,51 @@ out: */ struct inode * maknode (mode, ndp) - int mode; - register struct nameidata *ndp; + int mode; + register struct nameidata *ndp; { - register struct inode *ip; - register struct inode *pdir = ndp->ni_pdir; + register struct inode *ip; + register struct inode *pdir = ndp->ni_pdir; - ip = ialloc(pdir); - if (ip == NULL) { - iput(pdir); - return (NULL); - } - ip->i_flag |= IACC|IUPD|ICHG; - if ((mode & IFMT) == 0) - mode |= IFREG; - ip->i_mode = mode & ~u.u_cmask; - ip->i_nlink = 1; - ip->i_uid = u.u_uid; - ip->i_gid = pdir->i_gid; - if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) - ip->i_mode &= ~ISGID; - /* - * Make sure inode goes to disk before directory entry. - */ - iupdat(ip, &time, &time, 1); - u.u_error = direnter(ip, ndp); - if (u.u_error) { - /* - * Write error occurred trying to update directory - * so must deallocate the inode. - */ - ip->i_nlink = 0; - ip->i_flag |= ICHG; - iput(ip); - return (NULL); - } - ndp->ni_ip = ip; - return (ip); + ip = ialloc(pdir); + if (ip == NULL) { + iput(pdir); + return (NULL); + } + ip->i_flag |= IACC|IUPD|ICHG; + if ((mode & IFMT) == 0) + mode |= IFREG; + ip->i_mode = mode & ~u.u_cmask; + ip->i_nlink = 1; + ip->i_uid = u.u_uid; + ip->i_gid = pdir->i_gid; + if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) + ip->i_mode &= ~ISGID; + /* + * Make sure inode goes to disk before directory entry. + */ + iupdat(ip, &time, &time, 1); + u.u_error = direnter(ip, ndp); + if (u.u_error) { + /* + * Write error occurred trying to update directory + * so must deallocate the inode. + */ + ip->i_nlink = 0; + ip->i_flag |= ICHG; + iput(ip); + return (NULL); + } + ndp->ni_ip = ip; + return (ip); } /* * A virgin directory (no blushing please). */ const struct dirtemplate mastertemplate = { - 0, 12, 1, ".", - 0, DIRBLKSIZ - 12, 2, "..", + 0, 12, 1, ".", + 0, DIRBLKSIZ - 12, 2, "..", }; /* @@ -1137,99 +1136,99 @@ const struct dirtemplate mastertemplate = { void mkdir() { - register struct a { - char *name; - int dmode; - } *uap = (struct a *)u.u_arg; - register struct inode *ip, *dp; - struct dirtemplate dirtemplate; - struct nameidata nd; - register struct nameidata *ndp = &nd; + register struct a { + char *name; + int dmode; + } *uap = (struct a *)u.u_arg; + register struct inode *ip, *dp; + struct dirtemplate dirtemplate; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, CREATE, NOFOLLOW, uap->name); - ip = namei(ndp); - if (u.u_error) - return; - if (ip != NULL) { - iput(ip); - u.u_error = EEXIST; - return; - } - dp = ndp->ni_pdir; - uap->dmode &= 0777; - uap->dmode |= IFDIR; - /* - * Must simulate part of maknode here - * in order to acquire the inode, but - * not have it entered in the parent - * directory. The entry is made later - * after writing "." and ".." entries out. - */ - ip = ialloc(dp); - if (ip == NULL) { - iput(dp); - return; - } - ip->i_flag |= IACC|IUPD|ICHG; - ip->i_mode = uap->dmode & ~u.u_cmask; - ip->i_nlink = 2; - ip->i_uid = u.u_uid; - ip->i_gid = dp->i_gid; - iupdat(ip, &time, &time, 1); + NDINIT (ndp, CREATE, NOFOLLOW, uap->name); + ip = namei(ndp); + if (u.u_error) + return; + if (ip != NULL) { + iput(ip); + u.u_error = EEXIST; + return; + } + dp = ndp->ni_pdir; + uap->dmode &= 0777; + uap->dmode |= IFDIR; + /* + * Must simulate part of maknode here + * in order to acquire the inode, but + * not have it entered in the parent + * directory. The entry is made later + * after writing "." and ".." entries out. + */ + ip = ialloc(dp); + if (ip == NULL) { + iput(dp); + return; + } + ip->i_flag |= IACC|IUPD|ICHG; + ip->i_mode = uap->dmode & ~u.u_cmask; + ip->i_nlink = 2; + ip->i_uid = u.u_uid; + ip->i_gid = dp->i_gid; + iupdat(ip, &time, &time, 1); - /* - * Bump link count in parent directory - * to reflect work done below. Should - * be done before reference is created - * so reparation is possible if we crash. - */ - dp->i_nlink++; - dp->i_flag |= ICHG; - iupdat(dp, &time, &time, 1); + /* + * Bump link count in parent directory + * to reflect work done below. Should + * be done before reference is created + * so reparation is possible if we crash. + */ + dp->i_nlink++; + dp->i_flag |= ICHG; + iupdat(dp, &time, &time, 1); - /* - * Initialize directory with "." - * and ".." from static template. - */ - dirtemplate = mastertemplate; - dirtemplate.dot_ino = ip->i_number; - dirtemplate.dotdot_ino = dp->i_number; - u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) &dirtemplate, - sizeof (dirtemplate), (off_t) 0, IO_UNIT | IO_SYNC, (int*) 0); - if (u.u_error) { - dp->i_nlink--; - dp->i_flag |= ICHG; - goto bad; - } - ip->i_size = DIRBLKSIZ; - /* - * Directory all set up, now - * install the entry for it in - * the parent directory. - */ - u.u_error = direnter(ip, ndp); - dp = NULL; - if (u.u_error) { - NDINIT (ndp, LOOKUP, NOCACHE, uap->name); - dp = namei(ndp); - if (dp) { - dp->i_nlink--; - dp->i_flag |= ICHG; - } - } + /* + * Initialize directory with "." + * and ".." from static template. + */ + dirtemplate = mastertemplate; + dirtemplate.dot_ino = ip->i_number; + dirtemplate.dotdot_ino = dp->i_number; + u.u_error = rdwri (UIO_WRITE, ip, (caddr_t) &dirtemplate, + sizeof (dirtemplate), (off_t) 0, IO_UNIT | IO_SYNC, (int*) 0); + if (u.u_error) { + dp->i_nlink--; + dp->i_flag |= ICHG; + goto bad; + } + ip->i_size = DIRBLKSIZ; + /* + * Directory all set up, now + * install the entry for it in + * the parent directory. + */ + u.u_error = direnter(ip, ndp); + dp = NULL; + if (u.u_error) { + NDINIT (ndp, LOOKUP, NOCACHE, uap->name); + dp = namei(ndp); + if (dp) { + dp->i_nlink--; + dp->i_flag |= ICHG; + } + } bad: - /* - * No need to do an explicit itrunc here, - * irele will do this for us because we set - * the link count to 0. - */ - if (u.u_error) { - ip->i_nlink = 0; - ip->i_flag |= ICHG; - } - if (dp) - iput(dp); - iput(ip); + /* + * No need to do an explicit itrunc here, + * irele will do this for us because we set + * the link count to 0. + */ + if (u.u_error) { + ip->i_nlink = 0; + ip->i_flag |= ICHG; + } + if (dp) + iput(dp); + iput(ip); } /* @@ -1238,83 +1237,83 @@ bad: void rmdir() { - struct a { - char *name; - } *uap = (struct a *)u.u_arg; - register struct inode *ip, *dp; - struct nameidata nd; - register struct nameidata *ndp = &nd; + struct a { + char *name; + } *uap = (struct a *)u.u_arg; + register struct inode *ip, *dp; + struct nameidata nd; + register struct nameidata *ndp = &nd; - NDINIT (ndp, DELETE, LOCKPARENT, uap->name); - ip = namei(ndp); - if (ip == NULL) - return; - dp = ndp->ni_pdir; - /* - * No rmdir "." please. - */ - if (dp == ip) { - irele(dp); - iput(ip); - u.u_error = EINVAL; - return; - } - if ((ip->i_mode&IFMT) != IFDIR) { - u.u_error = ENOTDIR; - goto out; - } - /* - * Don't remove a mounted on directory. - */ - if (ip->i_dev != dp->i_dev) { - u.u_error = EBUSY; - goto out; - } - /* - * Verify the directory is empty (and valid). - * (Rmdir ".." won't be valid since - * ".." will contain a reference to - * the current directory and thus be - * non-empty.) - */ - if (ip->i_nlink != 2 || !dirempty(ip, dp->i_number)) { - u.u_error = ENOTEMPTY; - goto out; - } - if ((dp->i_flags & APPEND) || (ip->i_flags & (IMMUTABLE|APPEND))) { - u.u_error = EPERM; - goto out; - } - /* - * Delete reference to directory before purging - * inode. If we crash in between, the directory - * will be reattached to lost+found, - */ - if (dirremove(ndp) == 0) - goto out; - dp->i_nlink--; - dp->i_flag |= ICHG; - cacheinval(dp); - iput(dp); - dp = NULL; - /* - * Truncate inode. The only stuff left - * in the directory is "." and "..". The - * "." reference is inconsequential since - * we're quashing it. The ".." reference - * has already been adjusted above. We've - * removed the "." reference and the reference - * in the parent directory, but there may be - * other hard links so decrement by 2 and - * worry about them later. - */ - ip->i_nlink -= 2; - itrunc(ip, (u_long)0, 0); /* IO_SYNC? */ - cacheinval(ip); + NDINIT (ndp, DELETE, LOCKPARENT, uap->name); + ip = namei(ndp); + if (ip == NULL) + return; + dp = ndp->ni_pdir; + /* + * No rmdir "." please. + */ + if (dp == ip) { + irele(dp); + iput(ip); + u.u_error = EINVAL; + return; + } + if ((ip->i_mode&IFMT) != IFDIR) { + u.u_error = ENOTDIR; + goto out; + } + /* + * Don't remove a mounted on directory. + */ + if (ip->i_dev != dp->i_dev) { + u.u_error = EBUSY; + goto out; + } + /* + * Verify the directory is empty (and valid). + * (Rmdir ".." won't be valid since + * ".." will contain a reference to + * the current directory and thus be + * non-empty.) + */ + if (ip->i_nlink != 2 || !dirempty(ip, dp->i_number)) { + u.u_error = ENOTEMPTY; + goto out; + } + if ((dp->i_flags & APPEND) || (ip->i_flags & (IMMUTABLE|APPEND))) { + u.u_error = EPERM; + goto out; + } + /* + * Delete reference to directory before purging + * inode. If we crash in between, the directory + * will be reattached to lost+found, + */ + if (dirremove(ndp) == 0) + goto out; + dp->i_nlink--; + dp->i_flag |= ICHG; + cacheinval(dp); + iput(dp); + dp = NULL; + /* + * Truncate inode. The only stuff left + * in the directory is "." and "..". The + * "." reference is inconsequential since + * we're quashing it. The ".." reference + * has already been adjusted above. We've + * removed the "." reference and the reference + * in the parent directory, but there may be + * other hard links so decrement by 2 and + * worry about them later. + */ + ip->i_nlink -= 2; + itrunc(ip, (u_long)0, 0); /* IO_SYNC? */ + cacheinval(ip); out: - if (dp) - iput(dp); - iput(ip); + if (dp) + iput(dp); + iput(ip); } /* @@ -1322,17 +1321,17 @@ out: */ struct inode * getinode(fdes) - int fdes; + int fdes; { - register struct file *fp; + register struct file *fp; - if ((unsigned)fdes >= NOFILE || (fp = u.u_ofile[fdes]) == NULL) { - u.u_error = EBADF; - return ((struct inode *)0); - } - if (fp->f_type != DTYPE_INODE) { - u.u_error = EINVAL; - return ((struct inode *)0); - } - return((struct inode *)fp->f_data); + if ((unsigned)fdes >= NOFILE || (fp = u.u_ofile[fdes]) == NULL) { + u.u_error = EBADF; + return ((struct inode *)0); + } + if (fp->f_type != DTYPE_INODE) { + u.u_error = EINVAL; + return ((struct inode *)0); + } + return((struct inode *)fp->f_data); } diff --git a/sys/kernel/ufs_syscalls2.c b/sys/kernel/ufs_syscalls2.c index 6124cfb..f3dfed2 100644 --- a/sys/kernel/ufs_syscalls2.c +++ b/sys/kernel/ufs_syscalls2.c @@ -16,99 +16,99 @@ static int statfs1 (mp, sbp) - struct mount *mp; - struct statfs *sbp; + struct mount *mp; + struct statfs *sbp; { - struct statfs sfs; - register struct statfs *sfsp; - struct fs *fs = &mp->m_filsys; + struct statfs sfs; + register struct statfs *sfsp; + struct fs *fs = &mp->m_filsys; - sfsp = &sfs; - sfsp->f_type = MOUNT_UFS; - sfsp->f_bsize = MAXBSIZE; - sfsp->f_iosize = MAXBSIZE; - sfsp->f_blocks = fs->fs_fsize - fs->fs_isize; - sfsp->f_bfree = fs->fs_tfree; - sfsp->f_bavail = fs->fs_tfree; - sfsp->f_files = (fs->fs_isize - 1) * INOPB; - sfsp->f_ffree = fs->fs_tinode; + sfsp = &sfs; + sfsp->f_type = MOUNT_UFS; + sfsp->f_bsize = MAXBSIZE; + sfsp->f_iosize = MAXBSIZE; + sfsp->f_blocks = fs->fs_fsize - fs->fs_isize; + sfsp->f_bfree = fs->fs_tfree; + sfsp->f_bavail = fs->fs_tfree; + sfsp->f_files = (fs->fs_isize - 1) * INOPB; + sfsp->f_ffree = fs->fs_tinode; - bcopy (mp->m_mnton, sfsp->f_mntonname, MNAMELEN); - bcopy (mp->m_mntfrom, sfsp->f_mntfromname, MNAMELEN); - sfsp->f_flags = mp->m_flags & MNT_VISFLAGMASK; - return copyout ((caddr_t) sfsp, (caddr_t) sbp, sizeof (struct statfs)); + bcopy (mp->m_mnton, sfsp->f_mntonname, MNAMELEN); + bcopy (mp->m_mntfrom, sfsp->f_mntfromname, MNAMELEN); + sfsp->f_flags = mp->m_flags & MNT_VISFLAGMASK; + return copyout ((caddr_t) sfsp, (caddr_t) sbp, sizeof (struct statfs)); } void statfs() { - register struct a { - char *path; - struct statfs *buf; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - struct nameidata nd; - register struct nameidata *ndp = &nd; - struct mount *mp; + register struct a { + char *path; + struct statfs *buf; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + struct nameidata nd; + register struct nameidata *ndp = &nd; + struct mount *mp; - NDINIT (ndp, LOOKUP, FOLLOW, uap->path); - ip = namei(ndp); - if (! ip) - return; - mp = (struct mount *)((int)ip->i_fs - offsetof(struct mount, m_filsys)); - iput(ip); - u.u_error = statfs1 (mp, uap->buf); + NDINIT (ndp, LOOKUP, FOLLOW, uap->path); + ip = namei(ndp); + if (! ip) + return; + mp = (struct mount *)((int)ip->i_fs - offsetof(struct mount, m_filsys)); + iput(ip); + u.u_error = statfs1 (mp, uap->buf); } void fstatfs() { - register struct a { - int fd; - struct statfs *buf; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - struct mount *mp; + register struct a { + int fd; + struct statfs *buf; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + struct mount *mp; - ip = getinode(uap->fd); - if (! ip) - return; - mp = (struct mount *)((int)ip->i_fs - offsetof(struct mount, m_filsys)); - u.u_error = statfs1 (mp, uap->buf); + ip = getinode(uap->fd); + if (! ip) + return; + mp = (struct mount *)((int)ip->i_fs - offsetof(struct mount, m_filsys)); + u.u_error = statfs1 (mp, uap->buf); } void getfsstat() { - register struct a { - struct statfs *buf; - int bufsize; - u_int flags; - } *uap = (struct a *)u.u_arg; - register struct mount *mp; - caddr_t sfsp; - int count, maxcount, error; + register struct a { + struct statfs *buf; + int bufsize; + u_int flags; + } *uap = (struct a *)u.u_arg; + register struct mount *mp; + caddr_t sfsp; + int count, maxcount, error; - maxcount = uap->bufsize / sizeof (struct statfs); - sfsp = (caddr_t)uap->buf; - count = 0; - for (mp = mount; mp < &mount[NMOUNT]; mp++) { - if (mp->m_inodp == NULL) - continue; - if (count < maxcount) { - error = statfs1 (mp, sfsp); - if (error) { - u.u_error = error; - return; - } - sfsp += sizeof (struct statfs); - } - count++; - } - if (sfsp && count > maxcount) - u.u_rval = maxcount; - else - u.u_rval = count; + maxcount = uap->bufsize / sizeof (struct statfs); + sfsp = (caddr_t)uap->buf; + count = 0; + for (mp = mount; mp < &mount[NMOUNT]; mp++) { + if (mp->m_inodp == NULL) + continue; + if (count < maxcount) { + error = statfs1 (mp, sfsp); + if (error) { + u.u_error = error; + return; + } + sfsp += sizeof (struct statfs); + } + count++; + } + if (sfsp && count > maxcount) + u.u_rval = maxcount; + else + u.u_rval = count; } /* @@ -118,28 +118,28 @@ getfsstat() */ static void syncinodes(fs) - struct fs *fs; + struct fs *fs; { - register struct inode *ip; + register struct inode *ip; - /* - * Write back each (modified) inode. - */ - for (ip = inode; ip < inode+NINODE; ip++) { - /* - * Attempt to reduce the overhead by short circuiting the scan if the - * inode is not for the filesystem being processed. - */ - if (ip->i_fs != fs) - continue; - if ((ip->i_flag & ILOCKED) != 0 || ip->i_count == 0 || - (ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0) - continue; - ip->i_flag |= ILOCKED; - ip->i_count++; - iupdat(ip, &time, &time, 0); - iput(ip); - } + /* + * Write back each (modified) inode. + */ + for (ip = inode; ip < inode+NINODE; ip++) { + /* + * Attempt to reduce the overhead by short circuiting the scan if the + * inode is not for the filesystem being processed. + */ + if (ip->i_fs != fs) + continue; + if ((ip->i_flag & ILOCKED) != 0 || ip->i_count == 0 || + (ip->i_flag & (IMOD|IACC|IUPD|ICHG)) == 0) + continue; + ip->i_flag |= ILOCKED; + ip->i_count++; + iupdat(ip, &time, &time, 0); + iput(ip); + } } /* @@ -149,33 +149,33 @@ syncinodes(fs) */ int ufs_sync(mp) - register struct mount *mp; + register struct mount *mp; { - register struct fs *fs; - struct buf *bp; - int error = 0; + register struct fs *fs; + struct buf *bp; + int error = 0; - fs = &mp->m_filsys; - if (fs->fs_fmod && (mp->m_flags & MNT_RDONLY)) { - printf("fs = %s\n", fs->fs_fsmnt); - panic("sync: rofs"); - } - syncinodes(fs); /* sync the inodes for this filesystem */ - bflush(mp->m_dev); /* flush dirty data blocks */ - /* - * And lastly the superblock, if the filesystem was modified. - * Write back modified superblocks. Consistency check that the superblock - * of each file system is still in the buffer cache. - */ - if (fs->fs_fmod) { - bp = getblk(mp->m_dev, SUPERB); - fs->fs_fmod = 0; - fs->fs_time = time.tv_sec; - bcopy(fs, bp->b_addr, sizeof (struct fs)); - bwrite(bp); - error = geterror(bp); - } - return(error); + fs = &mp->m_filsys; + if (fs->fs_fmod && (mp->m_flags & MNT_RDONLY)) { + printf("fs = %s\n", fs->fs_fsmnt); + panic("sync: rofs"); + } + syncinodes(fs); /* sync the inodes for this filesystem */ + bflush(mp->m_dev); /* flush dirty data blocks */ + /* + * And lastly the superblock, if the filesystem was modified. + * Write back modified superblocks. Consistency check that the superblock + * of each file system is still in the buffer cache. + */ + if (fs->fs_fmod) { + bp = getblk(mp->m_dev, SUPERB); + fs->fs_fmod = 0; + fs->fs_time = time.tv_sec; + bcopy(fs, bp->b_addr, sizeof (struct fs)); + bwrite(bp); + error = geterror(bp); + } + return(error); } /* @@ -184,12 +184,12 @@ ufs_sync(mp) void umask() { - register struct a { - int mask; - } *uap = (struct a *)u.u_arg; + register struct a { + int mask; + } *uap = (struct a *)u.u_arg; - u.u_rval = u.u_cmask; - u.u_cmask = uap->mask & 07777; + u.u_rval = u.u_cmask; + u.u_cmask = uap->mask & 07777; } /* @@ -198,35 +198,35 @@ umask() void lseek() { - register struct file *fp; - register struct a { - int fd; - off_t off; - int sbase; - } *uap = (struct a *)u.u_arg; + register struct file *fp; + register struct a { + int fd; + off_t off; + int sbase; + } *uap = (struct a *)u.u_arg; - if ((fp = getf(uap->fd)) == NULL) - return; - if (fp->f_type != DTYPE_INODE) { - u.u_error = ESPIPE; - return; - } - switch (uap->sbase) { + if ((fp = getf(uap->fd)) == NULL) + return; + if (fp->f_type != DTYPE_INODE) { + u.u_error = ESPIPE; + return; + } + switch (uap->sbase) { - case L_INCR: - fp->f_offset += uap->off; - break; - case L_XTND: - fp->f_offset = uap->off + ((struct inode *)fp->f_data)->i_size; - break; - case L_SET: - fp->f_offset = uap->off; - break; - default: - u.u_error = EINVAL; - return; - } - u.u_rval = fp->f_offset; + case L_INCR: + fp->f_offset += uap->off; + break; + case L_XTND: + fp->f_offset = uap->off + ((struct inode *)fp->f_data)->i_size; + break; + case L_SET: + fp->f_offset = uap->off; + break; + default: + u.u_error = EINVAL; + return; + } + u.u_rval = fp->f_offset; } /* @@ -235,45 +235,45 @@ lseek() void fsync() { - register struct a { - int fd; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; + register struct a { + int fd; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; - if ((ip = getinode(uap->fd)) == NULL) - return; - ilock(ip); - syncip(ip); - iunlock(ip); + if ((ip = getinode(uap->fd)) == NULL) + return; + ilock(ip); + syncip(ip); + iunlock(ip); } void utimes() { - register struct a { - char *fname; - struct timeval *tptr; - } *uap = (struct a *)u.u_arg; - register struct inode *ip; - struct nameidata nd; - register struct nameidata *ndp = &nd; - struct timeval tv[2]; - struct vattr vattr; + register struct a { + char *fname; + struct timeval *tptr; + } *uap = (struct a *)u.u_arg; + register struct inode *ip; + struct nameidata nd; + register struct nameidata *ndp = &nd; + struct timeval tv[2]; + struct vattr vattr; - VATTR_NULL(&vattr); - if (uap->tptr == NULL) { - tv[0].tv_sec = tv[1].tv_sec = time.tv_sec; - vattr.va_vaflags |= VA_UTIMES_NULL; - } else { - u.u_error = copyin ((caddr_t)uap->tptr,(caddr_t)tv,sizeof(tv)); - if (u.u_error) - return; - } - NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); - if ((ip = namei(ndp)) == NULL) - return; - vattr.va_atime = tv[0].tv_sec; - vattr.va_mtime = tv[1].tv_sec; - u.u_error = ufs_setattr(ip, &vattr); - iput(ip); + VATTR_NULL(&vattr); + if (uap->tptr == NULL) { + tv[0].tv_sec = tv[1].tv_sec = time.tv_sec; + vattr.va_vaflags |= VA_UTIMES_NULL; + } else { + u.u_error = copyin ((caddr_t)uap->tptr,(caddr_t)tv,sizeof(tv)); + if (u.u_error) + return; + } + NDINIT (ndp, LOOKUP, FOLLOW, uap->fname); + if ((ip = namei(ndp)) == NULL) + return; + vattr.va_atime = tv[0].tv_sec; + vattr.va_mtime = tv[1].tv_sec; + u.u_error = ufs_setattr(ip, &vattr); + iput(ip); } diff --git a/sys/kernel/vfs_vnops.c b/sys/kernel/vfs_vnops.c index 8ddd0a9..98ecd3e 100644 --- a/sys/kernel/vfs_vnops.c +++ b/sys/kernel/vfs_vnops.c @@ -1,6 +1,6 @@ /* * Copyright (c) 1982, 1986, 1989, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -63,103 +63,103 @@ */ int vn_open (ndp, fmode, cmode) - register struct nameidata *ndp; - int fmode, cmode; + register struct nameidata *ndp; + int fmode, cmode; { - register struct inode *ip; - register int error; + register struct inode *ip; + register int error; - if (fmode & O_CREAT) { - if ((fmode & O_EXCL) == 0) - ndp->ni_nameiop |= (CREATE|FOLLOW); - else - ndp->ni_nameiop = CREATE; - ip = namei(ndp); - if (ip == NULL) { - if (u.u_error) { - goto retuerr; - } - ip = maknode(cmode, ndp); - if (ip == NULL) { - goto retuerr; - } - fmode &= ~O_TRUNC; - } else { - if (fmode & O_EXCL) { - error = EEXIST; - goto bad; - } - fmode &= ~O_CREAT; - } - } else { - ndp->ni_nameiop = LOOKUP | FOLLOW; - ip = namei(ndp); - if (ip == NULL) { - goto retuerr; - } - } - if ((ip->i_mode & IFMT) == IFSOCK) { - error = EOPNOTSUPP; - goto bad; - } - if ((ip->i_flags & APPEND) && (fmode&(FWRITE|O_APPEND)) == FWRITE) { - error = EPERM; - goto bad; - } - if ((fmode & O_CREAT) == 0) { - if (fmode & FREAD) { - if (access(ip, IREAD)) { - error = u.u_error; /* XXX */ - goto bad; - } - } - if (fmode & (FWRITE | O_TRUNC)) { - if ((ip->i_mode & IFMT) == IFDIR) { - error = EISDIR; - goto bad; - } - if (access(ip, IWRITE)) { - error = u.u_error; - goto bad; - } - } - } - if (fmode & O_TRUNC) - itrunc(ip, (off_t)0, fmode & O_FSYNC ? IO_SYNC : 0); - /* - * 4.4 returns the vnode locked from vn_open which means that each caller - * has to go and unlock it. - * - * 2.11 returns the inode unlocked (for now). - */ - iunlock(ip); /* because namei returns a locked inode */ - if (setjmp(&u.u_qsave)) { - error = EINTR; /* opens are not restarted after signals */ - goto lbad; - } - error = openi (ip, fmode); - if (error) { - goto lbad; + if (fmode & O_CREAT) { + if ((fmode & O_EXCL) == 0) + ndp->ni_nameiop |= (CREATE|FOLLOW); + else + ndp->ni_nameiop = CREATE; + ip = namei(ndp); + if (ip == NULL) { + if (u.u_error) { + goto retuerr; + } + ip = maknode(cmode, ndp); + if (ip == NULL) { + goto retuerr; + } + fmode &= ~O_TRUNC; + } else { + if (fmode & O_EXCL) { + error = EEXIST; + goto bad; + } + fmode &= ~O_CREAT; } - return(0); + } else { + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei(ndp); + if (ip == NULL) { + goto retuerr; + } + } + if ((ip->i_mode & IFMT) == IFSOCK) { + error = EOPNOTSUPP; + goto bad; + } + if ((ip->i_flags & APPEND) && (fmode&(FWRITE|O_APPEND)) == FWRITE) { + error = EPERM; + goto bad; + } + if ((fmode & O_CREAT) == 0) { + if (fmode & FREAD) { + if (access(ip, IREAD)) { + error = u.u_error; /* XXX */ + goto bad; + } + } + if (fmode & (FWRITE | O_TRUNC)) { + if ((ip->i_mode & IFMT) == IFDIR) { + error = EISDIR; + goto bad; + } + if (access(ip, IWRITE)) { + error = u.u_error; + goto bad; + } + } + } + if (fmode & O_TRUNC) + itrunc(ip, (off_t)0, fmode & O_FSYNC ? IO_SYNC : 0); + /* + * 4.4 returns the vnode locked from vn_open which means that each caller + * has to go and unlock it. + * + * 2.11 returns the inode unlocked (for now). + */ + iunlock(ip); /* because namei returns a locked inode */ + if (setjmp(&u.u_qsave)) { + error = EINTR; /* opens are not restarted after signals */ + goto lbad; + } + error = openi (ip, fmode); + if (error) { + goto lbad; + } + return(0); - /* - * Gratuitous lock but it does (correctly) implement the earlier behaviour of - * copen (it also avoids a panic in iput). - */ + /* + * Gratuitous lock but it does (correctly) implement the earlier behaviour of + * copen (it also avoids a panic in iput). + */ lbad: - ilock(ip); + ilock(ip); bad: - /* - * Do NOT do an 'ilock' here - this tag is to be used only when the inode is - * locked (i.e. from namei). - */ - iput(ip); - return(error); + /* + * Do NOT do an 'ilock' here - this tag is to be used only when the inode is + * locked (i.e. from namei). + */ + iput(ip); + return(error); retuerr: - return(u.u_error); /* XXX - Bletch */ + return(u.u_error); /* XXX - Bletch */ } /* @@ -174,14 +174,14 @@ retuerr: */ int vn_close(ip, flags) - register struct inode *ip; - int flags; + register struct inode *ip; + int flags; { - register int error; + register int error; - error = closei(ip, flags); - irele(ip); /* assumes inode is unlocked */ - return(error); + error = closei(ip, flags); + irele(ip); /* assumes inode is unlocked */ + return(error); } /* @@ -197,16 +197,16 @@ vn_close(ip, flags) */ int vn_closefile(fp) - register struct file *fp; + register struct file *fp; { - register struct inode *ip = (struct inode *)fp->f_data; + register struct inode *ip = (struct inode *)fp->f_data; - /* - * Need to clear the inode pointer in the file structure so that the - * inode is not seen during the scan for aliases of character or block - * devices in closei(). - */ - fp->f_data = (caddr_t)0; /* XXX */ - irele(ip); - return (closei(ip, fp->f_flag)); + /* + * Need to clear the inode pointer in the file structure so that the + * inode is not seen during the scan for aliases of character or block + * devices in closei(). + */ + fp->f_data = (caddr_t)0; /* XXX */ + irele(ip); + return (closei(ip, fp->f_flag)); } diff --git a/sys/kernel/vm_sched.c b/sys/kernel/vm_sched.c index 8a92e76..8a9cb88 100644 --- a/sys/kernel/vm_sched.c +++ b/sys/kernel/vm_sched.c @@ -11,19 +11,19 @@ #include "systm.h" #include "debug.h" -#define MINFINITY -32767 /* minus infinity */ +#define MINFINITY -32767 /* minus infinity */ -int maxslp = MAXSLP; -char runin; /* scheduling flag */ -char runout; /* scheduling flag */ +int maxslp = MAXSLP; +char runin; /* scheduling flag */ +char runout; /* scheduling flag */ /* * The main loop of the scheduling (swapping) process. * The basic idea is: - * see if anyone wants to be swapped in - * swap out processes until there is room - * swap him in - * repeat + * see if anyone wants to be swapped in + * swap out processes until there is room + * swap him in + * repeat * The runout flag is set whenever someone is swapped out. Sched sleeps on * it awaiting work. Sched sleeps on runin whenever it cannot find enough * core (by swapping out or otherwise) to fit the selected swapped process. @@ -33,92 +33,91 @@ char runout; /* scheduling flag */ void sched() { - register struct proc *rp; - struct proc *swapped_out = 0, *in_core = 0; - register int out_time, rptime; - int s __attribute__((unused)); + register struct proc *rp; + struct proc *swapped_out = 0, *in_core = 0; + register int out_time, rptime; - for (;;) { - /* Perform swap-out/swap-in action. */ - s=spl0(); - if (in_core) - swapout (in_core, X_FREECORE, X_OLDSIZE, X_OLDSIZE); - if (swapped_out) - swapin (swapped_out); - s=splhigh(); - in_core = 0; - swapped_out = 0; + for (;;) { + /* Perform swap-out/swap-in action. */ + spl0(); + if (in_core) + swapout (in_core, X_FREECORE, X_OLDSIZE, X_OLDSIZE); + if (swapped_out) + swapin (swapped_out); + splhigh(); + in_core = 0; + swapped_out = 0; - /* Find user to swap in; of users ready, - * select one out longest. */ - out_time = -20000; - for (rp = allproc; rp; rp = rp->p_nxt) { - if (rp->p_stat != SRUN || (rp->p_flag & SLOAD)) - continue; - rptime = rp->p_time - rp->p_nice * 8; + /* Find user to swap in; of users ready, + * select one out longest. */ + out_time = -20000; + for (rp = allproc; rp; rp = rp->p_nxt) { + if (rp->p_stat != SRUN || (rp->p_flag & SLOAD)) + continue; + rptime = rp->p_time - rp->p_nice * 8; - /* - * Always bring in parents ending a vfork, - * to avoid deadlock - */ - if (rptime > out_time || (rp->p_flag & SVFPRNT)) { - swapped_out = rp; - out_time = rptime; - if (rp->p_flag & SVFPRNT) - break; - } - } + /* + * Always bring in parents ending a vfork, + * to avoid deadlock + */ + if (rptime > out_time || (rp->p_flag & SVFPRNT)) { + swapped_out = rp; + out_time = rptime; + if (rp->p_flag & SVFPRNT) + break; + } + } - /* If there is no one there, wait. */ - if (! swapped_out) { - ++runout; + /* If there is no one there, wait. */ + if (! swapped_out) { + ++runout; //SETVAL(0); - sleep ((caddr_t) &runout, PSWP); - continue; - } + sleep ((caddr_t) &runout, PSWP); + continue; + } //SETVAL(swapped_out->p_pid); - /* - * Look around for somebody to swap out. - * There may be only one non-system loaded process. - */ - for (rp = allproc; rp != NULL; rp = rp->p_nxt) { - if (rp->p_stat != SZOMB && - (rp->p_flag & (SSYS | SLOAD)) == SLOAD) { - in_core = rp; - break; - } - } - if (! in_core) { - /* In-core memory is empty. */ - continue; - } + /* + * Look around for somebody to swap out. + * There may be only one non-system loaded process. + */ + for (rp = allproc; rp != NULL; rp = rp->p_nxt) { + if (rp->p_stat != SZOMB && + (rp->p_flag & (SSYS | SLOAD)) == SLOAD) { + in_core = rp; + break; + } + } + if (! in_core) { + /* In-core memory is empty. */ + continue; + } - /* - * Swap found user out if sleeping interruptibly, or if he has spent at - * least 1 second in core and the swapped-out process has spent at - * least 2 seconds out. Otherwise wait a bit and try again. - */ - if (! (in_core->p_flag & SLOCK) && - (in_core->p_stat == SSTOP || - (in_core->p_stat == SSLEEP && (in_core->p_flag & P_SINTR)) || - ((in_core->p_stat == SRUN || in_core->p_stat == SSLEEP) && - out_time >= 2 && - in_core->p_time + in_core->p_nice >= 1))) - { - /* Swap out in-core process. */ - in_core->p_flag &= ~SLOAD; - if (in_core->p_stat == SRUN) - remrq (in_core); - } else { - /* Nothing to swap in/out. */ - in_core = 0; - swapped_out = 0; - ++runin; - sleep ((caddr_t) &runin, PSWP); - } - } + /* + * Swap found user out if sleeping interruptibly, or if he has spent at + * least 1 second in core and the swapped-out process has spent at + * least 2 seconds out. Otherwise wait a bit and try again. + */ + if (! (in_core->p_flag & SLOCK) && + (in_core->p_stat == SSTOP || + (in_core->p_stat == SSLEEP && (in_core->p_flag & P_SINTR)) || + ((in_core->p_stat == SRUN || in_core->p_stat == SSLEEP) && + out_time >= 2 && + in_core->p_time + in_core->p_nice >= 1))) + { + /* Swap out in-core process. */ + in_core->p_flag &= ~SLOAD; + if (in_core->p_stat == SRUN) + remrq (in_core); + } else { + /* Nothing to swap in/out. */ + in_core = 0; + swapped_out = 0; + ++runin; + sleep ((caddr_t) &runin, PSWP); + } + } } /* @@ -128,33 +127,33 @@ void vmmeter() { #ifdef UCB_METER - register u_short *cp, *rp; - register long *sp; + register u_short *cp, *rp; + register long *sp; - ave(avefree, freemem, 5); - ave(avefree30, freemem, 30); - cp = &cnt.v_first; - rp = &rate.v_first; - sp = &sum.v_first; - while (cp <= &cnt.v_last) { - ave(*rp, *cp, 5); - *sp += *cp; - *cp = 0; - rp++, cp++, sp++; - } + ave(avefree, freemem, 5); + ave(avefree30, freemem, 30); + cp = &cnt.v_first; + rp = &rate.v_first; + sp = &sum.v_first; + while (cp <= &cnt.v_last) { + ave(*rp, *cp, 5); + *sp += *cp; + *cp = 0; + rp++, cp++, sp++; + } #endif - if (time.tv_sec % 5 == 0) { - vmtotal(); + if (time.tv_sec % 5 == 0) { + vmtotal(); #ifdef UCB_METER - rate.v_swpin = cnt.v_swpin; - sum.v_swpin += cnt.v_swpin; - cnt.v_swpin = 0; - rate.v_swpout = cnt.v_swpout; - sum.v_swpout += cnt.v_swpout; - cnt.v_swpout = 0; + rate.v_swpin = cnt.v_swpin; + sum.v_swpin += cnt.v_swpin; + cnt.v_swpin = 0; + rate.v_swpout = cnt.v_swpout; + sum.v_swpout += cnt.v_swpout; + cnt.v_swpout = 0; #endif - } + } } /* @@ -169,94 +168,94 @@ vmmeter() */ static void loadav (avg, n) - register short *avg; - register int n; + register short *avg; + register int n; { - register int i; - static const long cexp[3] = { - 0353, /* 256 * exp(-1/12) */ - 0373, /* 256 * exp(-1/60) */ - 0376, /* 256 * exp(-1/180) */ - }; + register int i; + static const long cexp[3] = { + 0353, /* 256 * exp(-1/12) */ + 0373, /* 256 * exp(-1/60) */ + 0376, /* 256 * exp(-1/180) */ + }; - for (i = 0; i < 3; i++) - avg[i] = (cexp[i] * (avg[i]-(n<<8)) + (((long)n)<<16)) >> 8; + for (i = 0; i < 3; i++) + avg[i] = (cexp[i] * (avg[i]-(n<<8)) + (((long)n)<<16)) >> 8; } void vmtotal() { - register struct proc *p; - register int nrun = 0; + register struct proc *p; + register int nrun = 0; #ifdef UCB_METER - total.t_vmtxt = 0; - total.t_avmtxt = 0; - total.t_rmtxt = 0; - total.t_armtxt = 0; - total.t_vm = 0; - total.t_avm = 0; - total.t_rm = 0; - total.t_arm = 0; - total.t_rq = 0; - total.t_dw = 0; - total.t_sl = 0; - total.t_sw = 0; + total.t_vmtxt = 0; + total.t_avmtxt = 0; + total.t_rmtxt = 0; + total.t_armtxt = 0; + total.t_vm = 0; + total.t_avm = 0; + total.t_rm = 0; + total.t_arm = 0; + total.t_rq = 0; + total.t_dw = 0; + total.t_sl = 0; + total.t_sw = 0; #endif - for (p = allproc; p != NULL; p = p->p_nxt) { - if (p->p_flag & SSYS) - continue; - if (p->p_stat) { + for (p = allproc; p != NULL; p = p->p_nxt) { + if (p->p_flag & SSYS) + continue; + if (p->p_stat) { #ifdef UCB_METER - if (p->p_stat != SZOMB) { - total.t_vm += p->p_dsize + p->p_ssize + USIZE; - if (p->p_flag & SLOAD) - total.t_rm += p->p_dsize + p->p_ssize - + USIZE; - } + if (p->p_stat != SZOMB) { + total.t_vm += p->p_dsize + p->p_ssize + USIZE; + if (p->p_flag & SLOAD) + total.t_rm += p->p_dsize + p->p_ssize + + USIZE; + } #endif - switch (p->p_stat) { + switch (p->p_stat) { - case SSLEEP: - case SSTOP: - if (!(p->p_flag & P_SINTR) && p->p_stat == SSLEEP) - nrun++; + case SSLEEP: + case SSTOP: + if (!(p->p_flag & P_SINTR) && p->p_stat == SSLEEP) + nrun++; #ifdef UCB_METER - if (p->p_flag & SLOAD) { - if (!(p->p_flag & P_SINTR)) - total.t_dw++; - else if (p->p_slptime < maxslp) - total.t_sl++; - } else if (p->p_slptime < maxslp) - total.t_sw++; - if (p->p_slptime < maxslp) - goto active; + if (p->p_flag & SLOAD) { + if (!(p->p_flag & P_SINTR)) + total.t_dw++; + else if (p->p_slptime < maxslp) + total.t_sl++; + } else if (p->p_slptime < maxslp) + total.t_sw++; + if (p->p_slptime < maxslp) + goto active; #endif - break; + break; - case SRUN: - case SIDL: - nrun++; + case SRUN: + case SIDL: + nrun++; #ifdef UCB_METER - if (p->p_flag & SLOAD) - total.t_rq++; - else - total.t_sw++; + if (p->p_flag & SLOAD) + total.t_rq++; + else + total.t_sw++; active: - total.t_avm += p->p_dsize + p->p_ssize + USIZE; - if (p->p_flag & SLOAD) - total.t_arm += p->p_dsize + p->p_ssize - + USIZE; + total.t_avm += p->p_dsize + p->p_ssize + USIZE; + if (p->p_flag & SLOAD) + total.t_arm += p->p_dsize + p->p_ssize + + USIZE; #endif - break; - } - } - } + break; + } + } + } #ifdef UCB_METER - total.t_vm += total.t_vmtxt; - total.t_avm += total.t_avmtxt; - total.t_rm += total.t_rmtxt; - total.t_arm += total.t_armtxt; - total.t_free = avefree; + total.t_vm += total.t_vmtxt; + total.t_avm += total.t_avmtxt; + total.t_rm += total.t_rmtxt; + total.t_arm += total.t_armtxt; + total.t_free = avefree; #endif - loadav (avenrun, nrun); + loadav (avenrun, nrun); } diff --git a/sys/kernel/vm_swap.c b/sys/kernel/vm_swap.c index 3402e99..d89f5ae 100644 --- a/sys/kernel/vm_swap.c +++ b/sys/kernel/vm_swap.c @@ -20,32 +20,32 @@ */ void swapin (p) - register struct proc *p; + register struct proc *p; { - size_t daddr = USER_DATA_START; - size_t saddr = USER_DATA_END - p->p_ssize; - size_t uaddr = (size_t) &u0; + size_t daddr = USER_DATA_START; + size_t saddr = USER_DATA_END - p->p_ssize; + size_t uaddr = (size_t) &u0; - if (p->p_dsize) { - swap (p->p_daddr, daddr, p->p_dsize, B_READ); - mfree (swapmap, btod (p->p_dsize), p->p_daddr); - } - if (p->p_ssize) { - swap (p->p_saddr, saddr, p->p_ssize, B_READ); - mfree (swapmap, btod (p->p_ssize), p->p_saddr); - } - swap (p->p_addr, uaddr, USIZE, B_READ); - mfree (swapmap, btod (USIZE), p->p_addr); + if (p->p_dsize) { + swap (p->p_daddr, daddr, p->p_dsize, B_READ); + mfree (swapmap, btod (p->p_dsize), p->p_daddr); + } + if (p->p_ssize) { + swap (p->p_saddr, saddr, p->p_ssize, B_READ); + mfree (swapmap, btod (p->p_ssize), p->p_saddr); + } + swap (p->p_addr, uaddr, USIZE, B_READ); + mfree (swapmap, btod (USIZE), p->p_addr); - p->p_daddr = daddr; - p->p_saddr = saddr; - p->p_addr = uaddr; - if (p->p_stat == SRUN) - setrq (p); - p->p_flag |= SLOAD; - p->p_time = 0; + p->p_daddr = daddr; + p->p_saddr = saddr; + p->p_addr = uaddr; + if (p->p_stat == SRUN) + setrq (p); + p->p_flag |= SLOAD; + p->p_time = 0; #ifdef UCB_METER - cnt.v_swpin++; + cnt.v_swpin++; #endif } @@ -61,55 +61,55 @@ swapin (p) */ void swapout (p, freecore, odata, ostack) - register struct proc *p; - int freecore; - register u_int odata, ostack; + register struct proc *p; + int freecore; + register u_int odata, ostack; { - size_t a[3]; + size_t a[3]; - if (odata == (u_int) X_OLDSIZE) - odata = p->p_dsize; - if (ostack == (u_int) X_OLDSIZE) - ostack = p->p_ssize; - if (malloc3 (swapmap, btod (p->p_dsize), btod (p->p_ssize), - btod (USIZE), a) == NULL) - panic ("out of swap space"); - p->p_flag |= SLOCK; - if (odata) { - swap (a[0], p->p_daddr, odata, B_WRITE); - } - if (ostack) { - swap (a[1], p->p_saddr, ostack, B_WRITE); - } - /* - * Increment u_ru.ru_nswap for process being tossed out of core. - * We can be called to swap out a process other than the current - * process, so we have to map in the victim's u structure briefly. - * Note, savekdsa6 *must* be a static, because we remove the stack - * in the next instruction. The splclock is to prevent the clock - * from coming in and doing accounting for the wrong process, plus - * we don't want to come through here twice. Why are we doing - * this, anyway? - */ - { - int s; + if (odata == (u_int) X_OLDSIZE) + odata = p->p_dsize; + if (ostack == (u_int) X_OLDSIZE) + ostack = p->p_ssize; + if (malloc3 (swapmap, btod (p->p_dsize), btod (p->p_ssize), + btod (USIZE), a) == NULL) + panic ("out of swap space"); + p->p_flag |= SLOCK; + if (odata) { + swap (a[0], p->p_daddr, odata, B_WRITE); + } + if (ostack) { + swap (a[1], p->p_saddr, ostack, B_WRITE); + } + /* + * Increment u_ru.ru_nswap for process being tossed out of core. + * We can be called to swap out a process other than the current + * process, so we have to map in the victim's u structure briefly. + * Note, savekdsa6 *must* be a static, because we remove the stack + * in the next instruction. The splclock is to prevent the clock + * from coming in and doing accounting for the wrong process, plus + * we don't want to come through here twice. Why are we doing + * this, anyway? + */ + { + int s; - s = splclock(); - u.u_ru.ru_nswap++; - splx (s); - } - swap (a[2], p->p_addr, USIZE, B_WRITE); - p->p_daddr = a[0]; - p->p_saddr = a[1]; - p->p_addr = a[2]; - p->p_flag &= ~(SLOAD|SLOCK); - p->p_time = 0; + s = splclock(); + u.u_ru.ru_nswap++; + splx (s); + } + swap (a[2], p->p_addr, USIZE, B_WRITE); + p->p_daddr = a[0]; + p->p_saddr = a[1]; + p->p_addr = a[2]; + p->p_flag &= ~(SLOAD|SLOCK); + p->p_time = 0; #ifdef UCB_METER - cnt.v_swpout++; + cnt.v_swpout++; #endif - if (runout) { - runout = 0; - wakeup ((caddr_t)&runout); - } + if (runout) { + runout = 0; + wakeup ((caddr_t)&runout); + } } diff --git a/sys/kernel/vm_swp.c b/sys/kernel/vm_swp.c index f19f6d3..4af7dd3 100644 --- a/sys/kernel/vm_swp.c +++ b/sys/kernel/vm_swp.c @@ -10,7 +10,6 @@ #include "conf.h" #include "systm.h" #include "vm.h" -#include "trace.h" #include "uio.h" /* @@ -18,52 +17,51 @@ */ void swap (blkno, coreaddr, count, rdflg) - size_t blkno, coreaddr; - register int count; - int rdflg; + size_t blkno, coreaddr; + register int count; + int rdflg; { - register struct buf *bp; - int s; + register struct buf *bp; + int s; //printf ("swap (%u, %08x, %d, %s)\n", blkno, coreaddr, count, rdflg ? "R" : "W"); #ifdef UCB_METER - if (rdflg) { - cnt.v_kbin += (count + 1023) / 1024; - } else { - cnt.v_kbout += (count + 1023) / 1024; - } + if (rdflg) { + cnt.v_kbin += (count + 1023) / 1024; + } else { + cnt.v_kbout += (count + 1023) / 1024; + } #endif - bp = geteblk(); /* allocate a buffer header */ + bp = geteblk(); /* allocate a buffer header */ - while (count) { - bp->b_flags = B_BUSY | B_PHYS | B_INVAL | rdflg; - bp->b_dev = swapdev; - bp->b_bcount = count; - bp->b_blkno = blkno; - bp->b_addr = (caddr_t) coreaddr; - trace (TR_SWAPIO); - (*bdevsw[major(swapdev)].d_strategy) (bp); - s = splbio(); - while ((bp->b_flags & B_DONE) == 0) - sleep ((caddr_t)bp, PSWP); - splx (s); - if ((bp->b_flags & B_ERROR) || bp->b_resid) - panic ("hard err: swap"); - count -= count; - coreaddr += count; - blkno += btod (count); - } - brelse(bp); + while (count) { + bp->b_flags = B_BUSY | B_PHYS | B_INVAL | rdflg; + bp->b_dev = swapdev; + bp->b_bcount = count; + bp->b_blkno = blkno; + bp->b_addr = (caddr_t) coreaddr; + (*bdevsw[major(swapdev)].d_strategy) (bp); + s = splbio(); + while ((bp->b_flags & B_DONE) == 0) + sleep ((caddr_t)bp, PSWP); + splx (s); + if ((bp->b_flags & B_ERROR) || bp->b_resid) + panic ("hard err: swap"); + count -= count; + coreaddr += count; + blkno += btod (count); + } + brelse(bp); } /* * Raw I/O. The arguments are - * The strategy routine for the device - * A buffer, which may be a special buffer header - * owned exclusively by the device for this purpose or - * NULL if one is to be allocated. - * The device number - * Read/write flag + * The strategy routine for the device + * A buffer, which may be a special buffer header + * owned exclusively by the device for this purpose or + * NULL if one is to be allocated. + * The device number + * Read/write flag * Essentially all the work is computing physical addresses and * validating them. * @@ -91,87 +89,87 @@ swap (blkno, coreaddr, count, rdflg) */ int physio(strat, bp, dev, rw, uio) - void (*strat) (struct buf*); - register struct buf *bp; - dev_t dev; - int rw; - register struct uio *uio; + void (*strat) (struct buf*); + register struct buf *bp; + dev_t dev; + int rw; + register struct uio *uio; { - int error = 0, s, c, allocbuf = 0; - register struct iovec *iov; + int error = 0, s, c, allocbuf = 0; + register struct iovec *iov; - if (! bp) { - allocbuf++; - bp = geteblk(); - } - u.u_procp->p_flag |= SLOCK; - for ( ; uio->uio_iovcnt; uio->uio_iov++, uio->uio_iovcnt--) { - iov = uio->uio_iov; - if (iov->iov_base >= iov->iov_base + iov->iov_len) { - error = EFAULT; - break; - } - /* - * Check that transfer is either entirely in the - * data or in the stack: that is, either - * the end is in the data or the start is in the stack - * (remember wraparound was already checked). - */ - if (baduaddr (iov->iov_base) || - baduaddr (iov->iov_base + iov->iov_len - 1)) { - error = EFAULT; - break; - } - if (! allocbuf) { - s = splbio(); - while (bp->b_flags & B_BUSY) { - bp->b_flags |= B_WANTED; - sleep((caddr_t)bp, PRIBIO+1); - } - splx(s); - } - bp->b_error = 0; - while (iov->iov_len) { - bp->b_flags = B_BUSY | B_PHYS | B_INVAL | rw; - bp->b_dev = dev; - bp->b_addr = iov->iov_base; - bp->b_blkno = (unsigned) uio->uio_offset >> DEV_BSHIFT; - bp->b_bcount = iov->iov_len; - c = bp->b_bcount; - (*strat)(bp); - s = splbio(); - while ((bp->b_flags & B_DONE) == 0) - sleep((caddr_t)bp, PRIBIO); - if (bp->b_flags & B_WANTED) /* rare */ - wakeup((caddr_t)bp); - splx(s); - c -= bp->b_resid; - iov->iov_base += c; - iov->iov_len -= c; - uio->uio_resid -= c; - uio->uio_offset += c; - /* temp kludge for tape drives */ - if (bp->b_resid || (bp->b_flags & B_ERROR)) - break; - } - bp->b_flags &= ~(B_BUSY | B_WANTED); - error = geterror(bp); - /* temp kludge for tape drives */ - if (bp->b_resid || error) - break; - } - if (allocbuf) - brelse(bp); - u.u_procp->p_flag &= ~SLOCK; - return(error); + if (! bp) { + allocbuf++; + bp = geteblk(); + } + u.u_procp->p_flag |= SLOCK; + for ( ; uio->uio_iovcnt; uio->uio_iov++, uio->uio_iovcnt--) { + iov = uio->uio_iov; + if (iov->iov_base >= iov->iov_base + iov->iov_len) { + error = EFAULT; + break; + } + /* + * Check that transfer is either entirely in the + * data or in the stack: that is, either + * the end is in the data or the start is in the stack + * (remember wraparound was already checked). + */ + if (baduaddr (iov->iov_base) || + baduaddr (iov->iov_base + iov->iov_len - 1)) { + error = EFAULT; + break; + } + if (! allocbuf) { + s = splbio(); + while (bp->b_flags & B_BUSY) { + bp->b_flags |= B_WANTED; + sleep((caddr_t)bp, PRIBIO+1); + } + splx(s); + } + bp->b_error = 0; + while (iov->iov_len) { + bp->b_flags = B_BUSY | B_PHYS | B_INVAL | rw; + bp->b_dev = dev; + bp->b_addr = iov->iov_base; + bp->b_blkno = (unsigned) uio->uio_offset >> DEV_BSHIFT; + bp->b_bcount = iov->iov_len; + c = bp->b_bcount; + (*strat)(bp); + s = splbio(); + while ((bp->b_flags & B_DONE) == 0) + sleep((caddr_t)bp, PRIBIO); + if (bp->b_flags & B_WANTED) /* rare */ + wakeup((caddr_t)bp); + splx(s); + c -= bp->b_resid; + iov->iov_base += c; + iov->iov_len -= c; + uio->uio_resid -= c; + uio->uio_offset += c; + /* temp kludge for tape drives */ + if (bp->b_resid || (bp->b_flags & B_ERROR)) + break; + } + bp->b_flags &= ~(B_BUSY | B_WANTED); + error = geterror(bp); + /* temp kludge for tape drives */ + if (bp->b_resid || error) + break; + } + if (allocbuf) + brelse(bp); + u.u_procp->p_flag &= ~SLOCK; + return(error); } int rawrw (dev, uio, flag) - dev_t dev; - register struct uio *uio; - int flag; + dev_t dev; + register struct uio *uio; + int flag; { - return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL, dev, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE, uio)); + return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL, dev, + uio->uio_rw == UIO_READ ? B_READ : B_WRITE, uio)); } diff --git a/sys/pic32/clock.c b/sys/pic32/clock.c index c86e858..8f46aff 100644 --- a/sys/pic32/clock.c +++ b/sys/pic32/clock.c @@ -12,10 +12,10 @@ void clkstart() { - unsigned count = mips_read_c0_register (C0_COUNT, 0); + unsigned count = mips_read_c0_register (C0_COUNT, 0); - mips_write_c0_register (C0_COMPARE, 0, - count + (CPU_KHZ * 1000 / HZ + 1) / 2); + mips_write_c0_register (C0_COMPARE, 0, + count + (CPU_KHZ * 1000 / HZ + 1) / 2); - IECSET(0) = 1 << PIC32_IRQ_CT; + IECSET(0) = 1 << PIC32_IRQ_CT; } diff --git a/sys/pic32/cpu.h b/sys/pic32/cpu.h index e81d045..4916213 100644 --- a/sys/pic32/cpu.h +++ b/sys/pic32/cpu.h @@ -7,9 +7,9 @@ /* * CTL_MACHDEP definitions. */ -#define CPU_CONSDEV 1 /* dev_t: console terminal device */ -#define CPU_ERRMSG 2 /* get error message by errno */ -#define CPU_NLIST 3 /* get name address */ +#define CPU_CONSDEV 1 /* dev_t: console terminal device */ +#define CPU_ERRMSG 2 /* get error message by errno */ +#define CPU_NLIST 3 /* get name address */ #define CPU_TIMO_CMD 4 #define CPU_TIMO_SEND_OP 5 #define CPU_TIMO_SEND_CSD 6 @@ -19,22 +19,22 @@ #define CPU_TIMO_WAIT_WDONE 10 #define CPU_TIMO_WAIT_WSTOP 11 #define CPU_TIMO_WAIT_WIDLE 12 -#define CPU_MAXID 13 /* number of valid machdep ids */ +#define CPU_MAXID 13 /* number of valid machdep ids */ -#ifndef KERNEL +#ifndef KERNEL #define CTL_MACHDEP_NAMES { \ - { 0, 0 }, \ - { "console_device", CTLTYPE_STRUCT }, \ - { 0, 0 }, \ - { 0, 0 }, \ - { "sd_timeout_cmd", CTLTYPE_INT }, \ - { "sd_timeout_send_op", CTLTYPE_INT }, \ - { "sd_timeout_send_csd", CTLTYPE_INT }, \ - { "sd_timeout_read", CTLTYPE_INT }, \ - { "sd_timeout_wait_cmd", CTLTYPE_INT }, \ - { "sd_timeout_wait_wdata", CTLTYPE_INT }, \ - { "sd_timeout_wait_wdone", CTLTYPE_INT }, \ - { "sd_timeout_wait_wstop", CTLTYPE_INT }, \ - { "sd_timeout_wait_widle", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "sd_timeout_cmd", CTLTYPE_INT }, \ + { "sd_timeout_send_op", CTLTYPE_INT }, \ + { "sd_timeout_send_csd", CTLTYPE_INT }, \ + { "sd_timeout_read", CTLTYPE_INT }, \ + { "sd_timeout_wait_cmd", CTLTYPE_INT }, \ + { "sd_timeout_wait_wdata", CTLTYPE_INT }, \ + { "sd_timeout_wait_wdone", CTLTYPE_INT }, \ + { "sd_timeout_wait_wstop", CTLTYPE_INT }, \ + { "sd_timeout_wait_widle", CTLTYPE_INT }, \ } #endif diff --git a/sys/pic32/elf_machdep.h b/sys/pic32/elf_machdep.h index f02aa75..d3183d5 100644 --- a/sys/pic32/elf_machdep.h +++ b/sys/pic32/elf_machdep.h @@ -1,83 +1,83 @@ -/* $NetBSD: elf_machdep.h,v 1.7 2000/04/02 15:35:50 minoura Exp $ */ +/* $NetBSD: elf_machdep.h,v 1.7 2000/04/02 15:35:50 minoura Exp $ */ -#define ELF_MACHDEP_ID_CASES \ - case EM_MIPS: \ - break; +#define ELF_MACHDEP_ID_CASES \ + case EM_MIPS: \ + break; -#define ARCH_ELFSIZE 32 /* MD native binary size */ +#define ARCH_ELFSIZE 32 /* MD native binary size */ /* mips relocs. */ -#define R_MIPS_NONE 0 -#define R_MIPS_16 1 -#define R_MIPS_32 2 -#define R_MIPS_REL32 3 -#define R_MIPS_REL R_MIPS_REL32 -#define R_MIPS_26 4 -#define R_MIPS_HI16 5 /* high 16 bits of symbol value */ -#define R_MIPS_LO16 6 /* low 16 bits of symbol value */ -#define R_MIPS_GPREL16 7 /* GP-relative reference */ -#define R_MIPS_LITERAL 8 /* Reference to literal section */ -#define R_MIPS_GOT16 9 /* Reference to global offset table */ -#define R_MIPS_GOT R_MIPS_GOT16 -#define R_MIPS_PC16 10 /* 16 bit PC relative reference */ -#define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */ -#define R_MIPS_CALL R_MIPS_CALL16 -#define R_MIPS_GPREL32 12 +#define R_MIPS_NONE 0 +#define R_MIPS_16 1 +#define R_MIPS_32 2 +#define R_MIPS_REL32 3 +#define R_MIPS_REL R_MIPS_REL32 +#define R_MIPS_26 4 +#define R_MIPS_HI16 5 /* high 16 bits of symbol value */ +#define R_MIPS_LO16 6 /* low 16 bits of symbol value */ +#define R_MIPS_GPREL16 7 /* GP-relative reference */ +#define R_MIPS_LITERAL 8 /* Reference to literal section */ +#define R_MIPS_GOT16 9 /* Reference to global offset table */ +#define R_MIPS_GOT R_MIPS_GOT16 +#define R_MIPS_PC16 10 /* 16 bit PC relative reference */ +#define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */ +#define R_MIPS_CALL R_MIPS_CALL16 +#define R_MIPS_GPREL32 12 /* 13, 14, 15 are not defined at this point. */ -#define R_MIPS_UNUSED1 13 -#define R_MIPS_UNUSED2 14 -#define R_MIPS_UNUSED3 15 +#define R_MIPS_UNUSED1 13 +#define R_MIPS_UNUSED2 14 +#define R_MIPS_UNUSED3 15 /* * The remaining relocs are apparently part of the 64-bit Irix ELF ABI. */ -#define R_MIPS_SHIFT5 16 -#define R_MIPS_SHIFT6 17 +#define R_MIPS_SHIFT5 16 +#define R_MIPS_SHIFT6 17 -#define R_MIPS_64 18 -#define R_MIPS_GOT_DISP 19 -#define R_MIPS_GOT_PAGE 20 -#define R_MIPS_GOT_OFST 21 -#define R_MIPS_GOT_HI16 22 -#define R_MIPS_GOT_LO16 23 -#define R_MIPS_SUB 24 -#define R_MIPS_INSERT_A 25 -#define R_MIPS_INSERT_B 26 -#define R_MIPS_DELETE 27 -#define R_MIPS_HIGHER 28 -#define R_MIPS_HIGHEST 29 -#define R_MIPS_CALL_HI16 30 -#define R_MIPS_CALL_LO16 31 -#define R_MIPS_SCN_DISP 32 -#define R_MIPS_REL16 33 -#define R_MIPS_ADD_IMMEDIATE 34 -#define R_MIPS_PJUMP 35 -#define R_MIPS_RELGOT 36 +#define R_MIPS_64 18 +#define R_MIPS_GOT_DISP 19 +#define R_MIPS_GOT_PAGE 20 +#define R_MIPS_GOT_OFST 21 +#define R_MIPS_GOT_HI16 22 +#define R_MIPS_GOT_LO16 23 +#define R_MIPS_SUB 24 +#define R_MIPS_INSERT_A 25 +#define R_MIPS_INSERT_B 26 +#define R_MIPS_DELETE 27 +#define R_MIPS_HIGHER 28 +#define R_MIPS_HIGHEST 29 +#define R_MIPS_CALL_HI16 30 +#define R_MIPS_CALL_LO16 31 +#define R_MIPS_SCN_DISP 32 +#define R_MIPS_REL16 33 +#define R_MIPS_ADD_IMMEDIATE 34 +#define R_MIPS_PJUMP 35 +#define R_MIPS_RELGOT 36 -#define R_MIPS_max 37 -#define R_TYPE(name) __CONCAT(R_MIPS_,name) +#define R_MIPS_max 37 +#define R_TYPE(name) __CONCAT(R_MIPS_,name) /* mips dynamic tags */ -#define DT_MIPS_RLD_VERSION 0x70000001 -#define DT_MIPS_TIME_STAMP 0x70000002 -#define DT_MIPS_ICHECKSUM 0x70000003 -#define DT_MIPS_IVERSION 0x70000004 -#define DT_MIPS_FLAGS 0x70000005 -#define DT_MIPS_BASE_ADDRESS 0x70000006 -#define DT_MIPS_CONFLICT 0x70000008 -#define DT_MIPS_LIBLIST 0x70000009 -#define DT_MIPS_CONFLICTNO 0x7000000b -#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */ -#define DT_MIPS_LIBLISTNO 0x70000010 -#define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */ -#define DT_MIPS_UNREFEXTNO 0x70000012 -#define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */ -#define DT_MIPS_HIPAGENO 0x70000014 -#define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */ +#define DT_MIPS_RLD_VERSION 0x70000001 +#define DT_MIPS_TIME_STAMP 0x70000002 +#define DT_MIPS_ICHECKSUM 0x70000003 +#define DT_MIPS_IVERSION 0x70000004 +#define DT_MIPS_FLAGS 0x70000005 +#define DT_MIPS_BASE_ADDRESS 0x70000006 +#define DT_MIPS_CONFLICT 0x70000008 +#define DT_MIPS_LIBLIST 0x70000009 +#define DT_MIPS_CONFLICTNO 0x7000000b +#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */ +#define DT_MIPS_LIBLISTNO 0x70000010 +#define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */ +#define DT_MIPS_UNREFEXTNO 0x70000012 +#define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */ +#define DT_MIPS_HIPAGENO 0x70000014 +#define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */ /* * Tell the kernel ELF exec code not to try relocating the interpreter diff --git a/sys/pic32/glcd.c b/sys/pic32/glcd.c index 57007ca..a27d6dc 100644 --- a/sys/pic32/glcd.c +++ b/sys/pic32/glcd.c @@ -49,106 +49,106 @@ unsigned char screen_y = 0; const unsigned char font[] = { 0x00, 0x00, 0x00, 0x00, 0x00,// (space) - 0x00, 0x00, 0x5F, 0x00, 0x00,// ! - 0x00, 0x07, 0x00, 0x07, 0x00,// " - 0x14, 0x7F, 0x14, 0x7F, 0x14,// # - 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ - 0x23, 0x13, 0x08, 0x64, 0x62,// % - 0x36, 0x49, 0x55, 0x22, 0x50,// & - 0x00, 0x05, 0x03, 0x00, 0x00,// ' - 0x00, 0x1C, 0x22, 0x41, 0x00,// ( - 0x00, 0x41, 0x22, 0x1C, 0x00,// ) - 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * - 0x08, 0x08, 0x3E, 0x08, 0x08,// + - 0x00, 0x50, 0x30, 0x00, 0x00,// , - 0x08, 0x08, 0x08, 0x08, 0x08,// - - 0x00, 0x60, 0x60, 0x00, 0x00,// . - 0x20, 0x10, 0x08, 0x04, 0x02,// / - 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 - 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 - 0x42, 0x61, 0x51, 0x49, 0x46,// 2 - 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 - 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 - 0x27, 0x45, 0x45, 0x45, 0x39,// 5 - 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 - 0x01, 0x71, 0x09, 0x05, 0x03,// 7 - 0x36, 0x49, 0x49, 0x49, 0x36,// 8 - 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 - 0x00, 0x36, 0x36, 0x00, 0x00,// : - 0x00, 0x56, 0x36, 0x00, 0x00,// ; - 0x00, 0x08, 0x14, 0x22, 0x41,// < - 0x14, 0x14, 0x14, 0x14, 0x14,// = - 0x41, 0x22, 0x14, 0x08, 0x00,// > - 0x02, 0x01, 0x51, 0x09, 0x06,// ? - 0x32, 0x49, 0x79, 0x41, 0x3E,// @ - 0x7E, 0x11, 0x11, 0x11, 0x7E,// A - 0x7F, 0x49, 0x49, 0x49, 0x36,// B - 0x3E, 0x41, 0x41, 0x41, 0x22,// C - 0x7F, 0x41, 0x41, 0x22, 0x1C,// D - 0x7F, 0x49, 0x49, 0x49, 0x41,// E - 0x7F, 0x09, 0x09, 0x01, 0x01,// F - 0x3E, 0x41, 0x41, 0x51, 0x32,// G - 0x7F, 0x08, 0x08, 0x08, 0x7F,// H - 0x00, 0x41, 0x7F, 0x41, 0x00,// I - 0x20, 0x40, 0x41, 0x3F, 0x01,// J - 0x7F, 0x08, 0x14, 0x22, 0x41,// K - 0x7F, 0x40, 0x40, 0x40, 0x40,// L - 0x7F, 0x02, 0x04, 0x02, 0x7F,// M - 0x7F, 0x04, 0x08, 0x10, 0x7F,// N - 0x3E, 0x41, 0x41, 0x41, 0x3E,// O - 0x7F, 0x09, 0x09, 0x09, 0x06,// P - 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q - 0x7F, 0x09, 0x19, 0x29, 0x46,// R - 0x46, 0x49, 0x49, 0x49, 0x31,// S - 0x01, 0x01, 0x7F, 0x01, 0x01,// T - 0x3F, 0x40, 0x40, 0x40, 0x3F,// U - 0x1F, 0x20, 0x40, 0x20, 0x1F,// V - 0x7F, 0x20, 0x18, 0x20, 0x7F,// W - 0x63, 0x14, 0x08, 0x14, 0x63,// X - 0x03, 0x04, 0x78, 0x04, 0x03,// Y - 0x61, 0x51, 0x49, 0x45, 0x43,// Z - 0x00, 0x00, 0x7F, 0x41, 0x41,// [ - 0x02, 0x04, 0x08, 0x10, 0x20,// "\" - 0x41, 0x41, 0x7F, 0x00, 0x00,// ] - 0x04, 0x02, 0x01, 0x02, 0x04,// ^ - 0x40, 0x40, 0x40, 0x40, 0x40,// _ - 0x00, 0x01, 0x02, 0x04, 0x00,// ` - 0x20, 0x54, 0x54, 0x54, 0x78,// a - 0x7F, 0x48, 0x44, 0x44, 0x38,// b - 0x38, 0x44, 0x44, 0x44, 0x20,// c - 0x38, 0x44, 0x44, 0x48, 0x7F,// d - 0x38, 0x54, 0x54, 0x54, 0x18,// e - 0x08, 0x7E, 0x09, 0x01, 0x02,// f - 0x08, 0x14, 0x54, 0x54, 0x3C,// g - 0x7F, 0x08, 0x04, 0x04, 0x78,// h - 0x00, 0x44, 0x7D, 0x40, 0x00,// i - 0x20, 0x40, 0x44, 0x3D, 0x00,// j - 0x00, 0x7F, 0x10, 0x28, 0x44,// k - 0x00, 0x41, 0x7F, 0x40, 0x00,// l - 0x7C, 0x04, 0x18, 0x04, 0x78,// m - 0x7C, 0x08, 0x04, 0x04, 0x78,// n - 0x38, 0x44, 0x44, 0x44, 0x38,// o - 0x7C, 0x14, 0x14, 0x14, 0x08,// p - 0x08, 0x14, 0x14, 0x18, 0x7C,// q - 0x7C, 0x08, 0x04, 0x04, 0x08,// r - 0x48, 0x54, 0x54, 0x54, 0x20,// s - 0x04, 0x3F, 0x44, 0x40, 0x20,// t - 0x3C, 0x40, 0x40, 0x20, 0x7C,// u - 0x1C, 0x20, 0x40, 0x20, 0x1C,// v - 0x3C, 0x40, 0x30, 0x40, 0x3C,// w - 0x44, 0x28, 0x10, 0x28, 0x44,// x - 0x0C, 0x50, 0x50, 0x50, 0x3C,// y - 0x44, 0x64, 0x54, 0x4C, 0x44,// z - 0x00, 0x08, 0x36, 0x41, 0x00,// { - 0x00, 0x00, 0x7F, 0x00, 0x00,// | - 0x00, 0x41, 0x36, 0x08, 0x00,// } - 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> - 0x08, 0x1C, 0x2A, 0x08, 0x08 // <- + 0x00, 0x00, 0x5F, 0x00, 0x00,// ! + 0x00, 0x07, 0x00, 0x07, 0x00,// " + 0x14, 0x7F, 0x14, 0x7F, 0x14,// # + 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ + 0x23, 0x13, 0x08, 0x64, 0x62,// % + 0x36, 0x49, 0x55, 0x22, 0x50,// & + 0x00, 0x05, 0x03, 0x00, 0x00,// ' + 0x00, 0x1C, 0x22, 0x41, 0x00,// ( + 0x00, 0x41, 0x22, 0x1C, 0x00,// ) + 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * + 0x08, 0x08, 0x3E, 0x08, 0x08,// + + 0x00, 0x50, 0x30, 0x00, 0x00,// , + 0x08, 0x08, 0x08, 0x08, 0x08,// - + 0x00, 0x60, 0x60, 0x00, 0x00,// . + 0x20, 0x10, 0x08, 0x04, 0x02,// / + 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 + 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 + 0x42, 0x61, 0x51, 0x49, 0x46,// 2 + 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 + 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 + 0x27, 0x45, 0x45, 0x45, 0x39,// 5 + 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 + 0x01, 0x71, 0x09, 0x05, 0x03,// 7 + 0x36, 0x49, 0x49, 0x49, 0x36,// 8 + 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 + 0x00, 0x36, 0x36, 0x00, 0x00,// : + 0x00, 0x56, 0x36, 0x00, 0x00,// ; + 0x00, 0x08, 0x14, 0x22, 0x41,// < + 0x14, 0x14, 0x14, 0x14, 0x14,// = + 0x41, 0x22, 0x14, 0x08, 0x00,// > + 0x02, 0x01, 0x51, 0x09, 0x06,// ? + 0x32, 0x49, 0x79, 0x41, 0x3E,// @ + 0x7E, 0x11, 0x11, 0x11, 0x7E,// A + 0x7F, 0x49, 0x49, 0x49, 0x36,// B + 0x3E, 0x41, 0x41, 0x41, 0x22,// C + 0x7F, 0x41, 0x41, 0x22, 0x1C,// D + 0x7F, 0x49, 0x49, 0x49, 0x41,// E + 0x7F, 0x09, 0x09, 0x01, 0x01,// F + 0x3E, 0x41, 0x41, 0x51, 0x32,// G + 0x7F, 0x08, 0x08, 0x08, 0x7F,// H + 0x00, 0x41, 0x7F, 0x41, 0x00,// I + 0x20, 0x40, 0x41, 0x3F, 0x01,// J + 0x7F, 0x08, 0x14, 0x22, 0x41,// K + 0x7F, 0x40, 0x40, 0x40, 0x40,// L + 0x7F, 0x02, 0x04, 0x02, 0x7F,// M + 0x7F, 0x04, 0x08, 0x10, 0x7F,// N + 0x3E, 0x41, 0x41, 0x41, 0x3E,// O + 0x7F, 0x09, 0x09, 0x09, 0x06,// P + 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q + 0x7F, 0x09, 0x19, 0x29, 0x46,// R + 0x46, 0x49, 0x49, 0x49, 0x31,// S + 0x01, 0x01, 0x7F, 0x01, 0x01,// T + 0x3F, 0x40, 0x40, 0x40, 0x3F,// U + 0x1F, 0x20, 0x40, 0x20, 0x1F,// V + 0x7F, 0x20, 0x18, 0x20, 0x7F,// W + 0x63, 0x14, 0x08, 0x14, 0x63,// X + 0x03, 0x04, 0x78, 0x04, 0x03,// Y + 0x61, 0x51, 0x49, 0x45, 0x43,// Z + 0x00, 0x00, 0x7F, 0x41, 0x41,// [ + 0x02, 0x04, 0x08, 0x10, 0x20,// "\" + 0x41, 0x41, 0x7F, 0x00, 0x00,// ] + 0x04, 0x02, 0x01, 0x02, 0x04,// ^ + 0x40, 0x40, 0x40, 0x40, 0x40,// _ + 0x00, 0x01, 0x02, 0x04, 0x00,// ` + 0x20, 0x54, 0x54, 0x54, 0x78,// a + 0x7F, 0x48, 0x44, 0x44, 0x38,// b + 0x38, 0x44, 0x44, 0x44, 0x20,// c + 0x38, 0x44, 0x44, 0x48, 0x7F,// d + 0x38, 0x54, 0x54, 0x54, 0x18,// e + 0x08, 0x7E, 0x09, 0x01, 0x02,// f + 0x08, 0x14, 0x54, 0x54, 0x3C,// g + 0x7F, 0x08, 0x04, 0x04, 0x78,// h + 0x00, 0x44, 0x7D, 0x40, 0x00,// i + 0x20, 0x40, 0x44, 0x3D, 0x00,// j + 0x00, 0x7F, 0x10, 0x28, 0x44,// k + 0x00, 0x41, 0x7F, 0x40, 0x00,// l + 0x7C, 0x04, 0x18, 0x04, 0x78,// m + 0x7C, 0x08, 0x04, 0x04, 0x78,// n + 0x38, 0x44, 0x44, 0x44, 0x38,// o + 0x7C, 0x14, 0x14, 0x14, 0x08,// p + 0x08, 0x14, 0x14, 0x18, 0x7C,// q + 0x7C, 0x08, 0x04, 0x04, 0x08,// r + 0x48, 0x54, 0x54, 0x54, 0x20,// s + 0x04, 0x3F, 0x44, 0x40, 0x20,// t + 0x3C, 0x40, 0x40, 0x20, 0x7C,// u + 0x1C, 0x20, 0x40, 0x20, 0x1C,// v + 0x3C, 0x40, 0x30, 0x40, 0x3C,// w + 0x44, 0x28, 0x10, 0x28, 0x44,// x + 0x0C, 0x50, 0x50, 0x50, 0x3C,// y + 0x44, 0x64, 0x54, 0x4C, 0x44,// z + 0x00, 0x08, 0x36, 0x41, 0x00,// { + 0x00, 0x00, 0x7F, 0x00, 0x00,// | + 0x00, 0x41, 0x36, 0x08, 0x00,// } + 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> + 0x08, 0x1C, 0x2A, 0x08, 0x08 // <- }; /* * Devices: - * /dev/glcd + * /dev/glcd * * Write to the device outputs to GLCD memory as data. Use ioctl() to send * comands: @@ -190,42 +190,42 @@ void glcd_write_value(int chip, unsigned char data) if(chip==1) _BS(LAT_CS2, PIN_CS2); - if(data & 0b00000001) + if(data & 0b00000001) _BS(LAT_DB0, PIN_DB0); else _BC(LAT_DB0, PIN_DB0); - if(data & 0b00000010) + if(data & 0b00000010) _BS(LAT_DB1, PIN_DB1); else _BC(LAT_DB1, PIN_DB1); - if(data & 0b00000100) + if(data & 0b00000100) _BS(LAT_DB2, PIN_DB2); else _BC(LAT_DB2, PIN_DB2); - if(data & 0b00001000) + if(data & 0b00001000) _BS(LAT_DB3, PIN_DB3); else _BC(LAT_DB3, PIN_DB3); - if(data & 0b00010000) + if(data & 0b00010000) _BS(LAT_DB4, PIN_DB4); else _BC(LAT_DB4, PIN_DB4); - if(data & 0b00100000) + if(data & 0b00100000) _BS(LAT_DB5, PIN_DB5); else _BC(LAT_DB5, PIN_DB5); - if(data & 0b01000000) + if(data & 0b01000000) _BS(LAT_DB6, PIN_DB6); else _BC(LAT_DB6, PIN_DB6); - if(data & 0b10000000) + if(data & 0b10000000) _BS(LAT_DB7, PIN_DB7); else _BC(LAT_DB7, PIN_DB7); @@ -340,102 +340,95 @@ void glcd_load_page() int glcd_open (dev, flag, mode) - dev_t dev; + dev_t dev; { - int unit = minor(dev); + int unit = minor(dev); - if (unit >= 2) - return ENXIO; - if (u.u_uid != 0) - return EPERM; + if (unit >= 2) + return ENXIO; + if (u.u_uid != 0) + return EPERM; - glcd_init(); - mode = MODE_TEXT; - DEBUG("glcd%d: Openend\n",unit); - //screen_x = 0; - //screen_y = 0; - return 0; + glcd_init(); + mode = MODE_TEXT; + DEBUG("glcd%d: Openend\n",unit); + //screen_x = 0; + //screen_y = 0; + return 0; } int glcd_close (dev_t dev, int flag, int mode) { - return 0; + return 0; } int glcd_read (dev_t dev, struct uio *uio, int flag) { - // TODO - return ENODEV; + // TODO + return ENODEV; } void glcd_scrollUp(void) { - unsigned char x,y; - for(y=0; y<9; y++) - { - for(x=0; x<128; x++) - { - screen[y][x] = screen[y][x]>>1; - if(y<8) - screen[y][x] |= (screen[y+1][x]<<7); - } + unsigned char x, y; + + for (y=0; y<9; y++) { + for (x=0; x<128; x++) { + screen[y][x] = screen[y][x]>>1; + if (y < 8) + screen[y][x] |= (screen[y+1][x]<<7); } + } } void glcd_putc(char c) { unsigned int cpos; - if(c=='\r') - { + + if (c=='\r') { screen_x = 0; return; } - if(c=='\n') - { + if (c=='\n') { screen_y++; - screen_x=0; - if(screen_y>7) - { + screen_x = 0; + if (screen_y>7) { screen_y--; - for(cpos=0; cpos<8; cpos++) + for (cpos=0; cpos<8; cpos++) glcd_scrollUp(); } return; } - if(c==0x08) - { - if(screen_x>0) - { - screen_x-=6; + if (c == 0x08) { + if (screen_x > 0) { + screen_x -= 6; } else { - if(screen_y>0) - { + if (screen_y > 0) { screen_x = 127-7; screen_y--; } } return; } - if(c==0x07) - { + + if (c == 0x07) { return; } - if(c==0x0C) - { + + if (c == 0x0C) { glcd_cls(); glcd_update(); return; } - if(screen_x > 127-6) - { - screen_x=0; + + if (screen_x > 127-6) { + screen_x = 0; screen_y++; - if(screen_y>7) - { + if (screen_y > 7) { screen_y--; - for(cpos=0; cpos<8; cpos++) + for (cpos=0; cpos<8; cpos++) glcd_scrollUp(); } } @@ -450,108 +443,103 @@ void glcd_putc(char c) void glcd_setPixel(int x, int y) { - unsigned char row; - unsigned char pixel; - unsigned char mask; + unsigned char row; + unsigned char pixel; + unsigned char mask; - if(x>127) - return; - if(y>63) - return; - if(x<0) - return; - if(y<0) - return; + if (x > 127) + return; + if (y > 63) + return; + if (x < 0) + return; + if (y < 0) + return; - row = y>>3; - pixel = y & 0x07; + row = y>>3; + pixel = y & 0x07; - mask = 1 << pixel; + mask = 1 << pixel; - screen[row][x] |= mask; + screen[row][x] |= mask; } void glcd_clearPixel(int x, int y) { - unsigned char row; - unsigned char pixel; - unsigned char mask; + unsigned char row; + unsigned char pixel; + unsigned char mask; - if(x>127) - return; - if(y>63) - return; - if(x<0) - return; - if(y<0) - return; + if (x > 127) + return; + if (y > 63) + return; + if (x < 0) + return; + if (y < 0) + return; - row = y>>3; - pixel = y & 0x07; + row = y>>3; + pixel = y & 0x07; - mask = 1 << pixel; + mask = 1 << pixel; - screen[row][x] &= ~mask; + screen[row][x] &= ~mask; } void glcd_drawLine(int x, int y, int x2, int y2, unsigned char ink) { - int w, h; - int dx1=0, dy1=0, dx2=0, dy2=0; - int longest, shortest; - int numerator; - int i; + int w, h; + int dx1=0, dy1=0, dx2=0, dy2=0; + int longest, shortest; + int numerator; + int i; - w = x2 - x; - h = y2 - y; + w = x2 - x; + h = y2 - y; - if(w<0) - { - dx1 = -1; - dx2 = -1; - } - else if(w>0) - { - dx1 = 1; - dx2 = 1; - } - - if(h<0) - dy1 = -1; - else if(h>0) - dy1 = 1; - - longest = abs(w); - shortest = abs(h); - if(!(longest>shortest)) - { - longest = abs(h); - shortest = abs(w); - if(h<0) - dy2 = -1; - else if(h>0) - dy2 = 1; - dx2=0; - } - - numerator = longest >> 1; - for(i=0; i<=longest; i++) - { - if(ink==1) - glcd_setPixel(x,y); - else - glcd_clearPixel(x,y); - numerator += shortest; - if(!(numerator 0) { + dx1 = 1; + dx2 = 1; + } + + if (h < 0) + dy1 = -1; + else if (h > 0) + dy1 = 1; + + longest = abs(w); + shortest = abs(h); + if (! (longest>shortest)) { + longest = abs(h); + shortest = abs(w); + if (h < 0) + dy2 = -1; + else if (h > 0) + dy2 = 1; + dx2 = 0; + } + + numerator = longest >> 1; + for (i=0; i<=longest; i++) { + if (ink == 1) + glcd_setPixel(x, y); + else + glcd_clearPixel(x, y); + + numerator += shortest; + if (! (numerator < longest)) { + numerator -= longest; + x += dx1; + y += dy1; + } else { + x += dx2; + y += dy2; } + } } void glcd_set_pixel(struct glcd_command *c) @@ -580,17 +568,17 @@ void glcd_draw_box(struct glcd_command *c) void glcd_draw_filled_box(struct glcd_command *c) { unsigned char y; - int y1,y2; - if(c->y1 > c->y2) - { - y1 = c->y2; + int y1, y2; + + if (c->y1 > c->y2) { + y1 = c->y2; y2 = c->y1; } else { y1 = c->y1; y2 = c->y2; } - for(y=y1; y<=y2; y++) - { + + for (y=y1; y<=y2; y++) { glcd_drawLine(c->x1, y, c->x2, y, c->ink); } } @@ -608,76 +596,72 @@ int glcd_write (dev_t dev, struct uio *uio, int flag) iov = uio->uio_iov; - switch(mode) - { - case MODE_LOAD: - for(i=0; iiov_len; i++) - { - screen[screen_y][screen_x] = *(iov->iov_base+i); - screen_x++; - if(screen_x==128) - { - screen_y++; - if(screen_y==8) - { - mode=MODE_TEXT; - glcd_update(); - } + switch (mode) { + case MODE_LOAD: + for (i=0; iiov_len; i++) { + screen[screen_y][screen_x] = *(iov->iov_base+i); + screen_x++; + if (screen_x == 128) { + screen_y++; + if (screen_y == 8) { + mode = MODE_TEXT; + glcd_update(); } } - break; - case MODE_TEXT: - for(i=0; iiov_len; i++) - { - glcd_putc(*(iov->iov_base+i)); - } - glcd_update(); - break; + } + break; + case MODE_TEXT: + for (i=0; iiov_len; i++) { + glcd_putc(*(iov->iov_base+i)); + } + glcd_update(); + break; } return 0; } int glcd_ioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag) { - if(cmd == GLCD_RESET) { - glcd_reset(); - } + switch (cmd) { + case GLCD_RESET: + glcd_reset(); + break; - if(cmd == GLCD_UPDATE) { - glcd_update(); - } + case GLCD_UPDATE: + glcd_update(); + break; - if(cmd == GLCD_CLS) { - glcd_cls(); - } + case GLCD_CLS: + glcd_cls(); + break; - if (cmd == GLCD_LOAD_PAGE) { - glcd_load_page(); - } + case GLCD_LOAD_PAGE: + glcd_load_page(); + break; - if (cmd == GLCD_SET_PIXEL) { - glcd_set_pixel((struct glcd_command *)addr); - } + case GLCD_SET_PIXEL: + glcd_set_pixel((struct glcd_command *)addr); + break; - if (cmd == GLCD_CLEAR_PIXEL) { - glcd_clear_pixel((struct glcd_command *)addr); - } + case GLCD_CLEAR_PIXEL: + glcd_clear_pixel((struct glcd_command *)addr); + break; - if (cmd == GLCD_LINE) { - glcd_draw_line((struct glcd_command *)addr); - } + case GLCD_LINE: + glcd_draw_line((struct glcd_command *)addr); + break; - if (cmd == GLCD_BOX) { - glcd_draw_box((struct glcd_command *)addr); - } + case GLCD_BOX: + glcd_draw_box((struct glcd_command *)addr); + break; - if (cmd == GLCD_FILLED_BOX) { - glcd_draw_filled_box((struct glcd_command *)addr); - } + case GLCD_FILLED_BOX: + glcd_draw_filled_box((struct glcd_command *)addr); + break; - if (cmd == GLCD_GOTO_XY) { - glcd_goto_xy((struct glcd_command *)addr); - } - - return 0; + case GLCD_GOTO_XY: + glcd_goto_xy((struct glcd_command *)addr); + break; + } + return 0; } diff --git a/sys/pic32/gpio.c b/sys/pic32/gpio.c index 40abd95..a6d474a 100644 --- a/sys/pic32/gpio.c +++ b/sys/pic32/gpio.c @@ -89,18 +89,18 @@ const struct devspec gpiodevs[] = { * Here are masks of real pins. */ #define MASK(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ - (a<<15 | b<<14 | c<<13 | d<<12 | e<<11 | f<<10 | g<<9 | h<<8 | \ - i<<7 | j<<6 | k<<5 | l<<4 | m<<3 | n<<2 | o<<1 | p) + (a<<15 | b<<14 | c<<13 | d<<12 | e<<11 | f<<10 | g<<9 | h<<8 | \ + i<<7 | j<<6 | k<<5 | l<<4 | m<<3 | n<<2 | o<<1 | p) static const u_int gpio_pins_mx7 [NGPIO] = { /* Missing pins: */ - MASK (1,1,0,0,0,1,1,0,1,1,1,1,1,1,1,1), /* A8, A11-A13 */ - MASK (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), - MASK (1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0), /* C0, C5-C11 */ - MASK (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), - MASK (0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1), /* E10-E15 */ - MASK (0,0,1,1,0,0,0,1,0,0,1,1,1,1,1,1), /* F6-F7, F9-F11, F14-F15 */ - MASK (1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1), /* G2-G5, G10-G11 */ + MASK (1,1,0,0,0,1,1,0,1,1,1,1,1,1,1,1), /* A8, A11-A13 */ + MASK (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), + MASK (1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0), /* C0, C5-C11 */ + MASK (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), + MASK (0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1), /* E10-E15 */ + MASK (0,0,1,1,0,0,0,1,0,0,1,1,1,1,1,1), /* F6-F7, F9-F11, F14-F15 */ + MASK (1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1), /* G2-G5, G10-G11 */ }; /* @@ -119,22 +119,22 @@ u_int gpio_confmask [NGPIO]; * PIC32 port i/o registers. */ struct gpioreg { - volatile unsigned tris; /* Mask of inputs */ - volatile unsigned trisclr; - volatile unsigned trisset; - volatile unsigned trisinv; - volatile unsigned port; /* Read inputs, write outputs */ - volatile unsigned portclr; - volatile unsigned portset; - volatile unsigned portinv; - volatile unsigned lat; /* Read/write outputs */ - volatile unsigned latclr; - volatile unsigned latset; - volatile unsigned latinv; - volatile unsigned odc; /* Open drain configuration */ - volatile unsigned odcclr; - volatile unsigned odcset; - volatile unsigned odcinv; + volatile unsigned tris; /* Mask of inputs */ + volatile unsigned trisclr; + volatile unsigned trisset; + volatile unsigned trisinv; + volatile unsigned port; /* Read inputs, write outputs */ + volatile unsigned portclr; + volatile unsigned portset; + volatile unsigned portinv; + volatile unsigned lat; /* Read/write outputs */ + volatile unsigned latclr; + volatile unsigned latset; + volatile unsigned latinv; + volatile unsigned odc; /* Open drain configuration */ + volatile unsigned odcclr; + volatile unsigned odcset; + volatile unsigned odcinv; }; /* @@ -143,15 +143,15 @@ struct gpioreg { */ static u_int filter_out (mask, portnum, portaddr, pin) - register u_int mask; - u_int portnum; - volatile unsigned *portaddr; + register u_int mask; + u_int portnum; + volatile unsigned *portaddr; { - register struct gpioreg *reg = portnum + (struct gpioreg*) &TRISA; + register struct gpioreg *reg = portnum + (struct gpioreg*) &TRISA; - if ((unsigned) reg == (unsigned) portaddr) - mask &= ~(1 << pin); - return mask; + if ((unsigned) reg == (unsigned) portaddr) + mask &= ~(1 << pin); + return mask; } /* @@ -160,251 +160,251 @@ filter_out (mask, portnum, portaddr, pin) */ static u_int gpio_filter (mask, portnum) - u_int mask; - u_int portnum; + u_int mask; + u_int portnum; { - mask &= gpio_pins_mx7 [portnum]; + mask &= gpio_pins_mx7 [portnum]; #ifdef LED_SWAP_PORT - mask = filter_out (mask, portnum, &LED_SWAP_PORT, LED_SWAP_PIN); + mask = filter_out (mask, portnum, &LED_SWAP_PORT, LED_SWAP_PIN); #endif #ifdef LED_DISK_PORT - mask = filter_out (mask, portnum, &LED_DISK_PORT, LED_DISK_PIN); + mask = filter_out (mask, portnum, &LED_DISK_PORT, LED_DISK_PIN); #endif #ifdef LED_KERNEL_PORT - mask = filter_out (mask, portnum, &LED_KERNEL_PORT, LED_KERNEL_PIN); + mask = filter_out (mask, portnum, &LED_KERNEL_PORT, LED_KERNEL_PIN); #endif #ifdef LED_TTY_PORT - mask = filter_out (mask, portnum, &LED_TTY_PORT, LED_TTY_PIN); + mask = filter_out (mask, portnum, &LED_TTY_PORT, LED_TTY_PIN); #endif #ifdef SD0_CS_PORT - mask = filter_out (mask, portnum, &SD0_CS_PORT, SD0_CS_PIN); + mask = filter_out (mask, portnum, &SD0_CS_PORT, SD0_CS_PIN); #endif #ifdef SD1_CS_PORT - mask = filter_out (mask, portnum, &SD1_CS_PORT, SD1_CS_PIN); + mask = filter_out (mask, portnum, &SD1_CS_PORT, SD1_CS_PIN); #endif #ifdef SD0_ENA_PORT - mask = filter_out (mask, portnum, &SD0_ENA_PORT, SD0_ENA_PIN); + mask = filter_out (mask, portnum, &SD0_ENA_PORT, SD0_ENA_PIN); #endif #ifdef SD1_ENA_PORT - mask = filter_out (mask, portnum, &SD1_ENA_PORT, SD1_ENA_PIN); + mask = filter_out (mask, portnum, &SD1_ENA_PORT, SD1_ENA_PIN); #endif #ifdef UART1_ENA_PORT - mask = filter_out (mask, portnum, &UART1_ENA_PORT, UART1_ENA_PIN); + mask = filter_out (mask, portnum, &UART1_ENA_PORT, UART1_ENA_PIN); #endif #ifdef UART2_ENA_PORT - mask = filter_out (mask, portnum, &UART2_ENA_PORT, UART2_ENA_PIN); + mask = filter_out (mask, portnum, &UART2_ENA_PORT, UART2_ENA_PIN); #endif #ifdef UART3_ENA_PORT - mask = filter_out (mask, portnum, &UART3_ENA_PORT, UART3_ENA_PIN); + mask = filter_out (mask, portnum, &UART3_ENA_PORT, UART3_ENA_PIN); #endif #ifdef UART4_ENA_PORT - mask = filter_out (mask, portnum, &UART4_ENA_PORT, UART4_ENA_PIN); + mask = filter_out (mask, portnum, &UART4_ENA_PORT, UART4_ENA_PIN); #endif #ifdef UART5_ENA_PORT - mask = filter_out (mask, portnum, &UART5_ENA_PORT, UART5_ENA_PIN); + mask = filter_out (mask, portnum, &UART5_ENA_PORT, UART5_ENA_PIN); #endif #ifdef UART6_ENA_PORT - mask = filter_out (mask, portnum, &UART6_ENA_PORT, UART6_ENA_PIN); + mask = filter_out (mask, portnum, &UART6_ENA_PORT, UART6_ENA_PIN); #endif #ifdef SW_DATA_PORT - mask = filter_out (mask, portnum, &SW_DATA_PORT, SW_DATA_PIN); + mask = filter_out (mask, portnum, &SW_DATA_PORT, SW_DATA_PIN); #endif #ifdef SW_LDA_PORT - mask = filter_out (mask, portnum, &SW_LDA_PORT, SW_LDA_PIN); + mask = filter_out (mask, portnum, &SW_LDA_PORT, SW_LDA_PIN); #endif #ifdef SW_RD_PORT - mask = filter_out (mask, portnum, &SW_RD_PORT, SW_RD_PIN); + mask = filter_out (mask, portnum, &SW_RD_PORT, SW_RD_PIN); #endif #ifdef SW_WR_PORT - mask = filter_out (mask, portnum, &SW_WR_PORT, SW_WR_PIN); + mask = filter_out (mask, portnum, &SW_WR_PORT, SW_WR_PIN); #endif #ifdef POWER_ENABLED #ifdef POWER_SWITCH_PORT - mask = filter_out (mask, portnum, &POWER_SWITCH_PORT, POWER_SWITCH_PIN); + mask = filter_out (mask, portnum, &POWER_SWITCH_PORT, POWER_SWITCH_PIN); #endif #ifdef POWER_LED_PORT - mask = filter_out (mask, portnum, &POWER_LED_PORT, POWER_LED_PIN); + mask = filter_out (mask, portnum, &POWER_LED_PORT, POWER_LED_PIN); #endif #ifdef POWER_CONTROL_PORT - mask = filter_out (mask, portnum, &POWER_CONTROL_PORT, POWER_CONTROL_PIN); + mask = filter_out (mask, portnum, &POWER_CONTROL_PORT, POWER_CONTROL_PIN); #endif #endif - return mask; + return mask; } static void gpio_print (dev, buf) - dev_t dev; - char *buf; + dev_t dev; + char *buf; { - u_int unit = minor(dev) & MINOR_UNIT; - register struct gpioreg *reg = unit + (struct gpioreg*) &TRISA; - register u_int mask, conf, tris; - register char c; + u_int unit = minor(dev) & MINOR_UNIT; + register struct gpioreg *reg = unit + (struct gpioreg*) &TRISA; + register u_int mask, conf, tris; + register char c; - conf = gpio_confmask[unit]; - tris = reg->tris; - if (minor(dev) & MINOR_CONF) { - /* /dev/confX device: port configuration mask */ - u_int odc = reg->odc; - for (mask=1<<(NPINS-1); mask; mask>>=1) { - if (! (conf & mask)) - c = '-'; - else if (tris & mask) - c = 'i'; - else - c = (odc & mask) ? 'd' : 'o'; - *buf++ = c; - } - } else { - /* /dev/portX device: port value mask */ - u_int lat = reg->lat; - u_int port = reg->port; - for (mask=1<<(NPINS-1); mask; mask>>=1) { - if (! (conf & mask)) - c = '-'; - else if (tris & mask) - c = (port & mask) ? '1' : '0'; - else - c = (lat & mask) ? '1' : '0'; - *buf++ = c; - } + conf = gpio_confmask[unit]; + tris = reg->tris; + if (minor(dev) & MINOR_CONF) { + /* /dev/confX device: port configuration mask */ + u_int odc = reg->odc; + for (mask=1<<(NPINS-1); mask; mask>>=1) { + if (! (conf & mask)) + c = '-'; + else if (tris & mask) + c = 'i'; + else + c = (odc & mask) ? 'd' : 'o'; + *buf++ = c; } - *buf++ = '\n'; - *buf = 0; + } else { + /* /dev/portX device: port value mask */ + u_int lat = reg->lat; + u_int port = reg->port; + for (mask=1<<(NPINS-1); mask; mask>>=1) { + if (! (conf & mask)) + c = '-'; + else if (tris & mask) + c = (port & mask) ? '1' : '0'; + else + c = (lat & mask) ? '1' : '0'; + *buf++ = c; + } + } + *buf++ = '\n'; + *buf = 0; } static void gpio_parse (dev, buf) - dev_t dev; - char *buf; + dev_t dev; + char *buf; { - u_int unit = minor(dev) & MINOR_UNIT; - register struct gpioreg *reg = unit + (struct gpioreg*) &TRISA; - register u_int mask; - register char c; + u_int unit = minor(dev) & MINOR_UNIT; + register struct gpioreg *reg = unit + (struct gpioreg*) &TRISA; + register u_int mask; + register char c; - if (minor(dev) & MINOR_CONF) { - /* /dev/confX device: port configuration mask */ - for (mask=1<<(NPINS-1); mask; mask>>=1) { - c = *buf++; - if (c <= ' ' || c > '~') - break; + if (minor(dev) & MINOR_CONF) { + /* /dev/confX device: port configuration mask */ + for (mask=1<<(NPINS-1); mask; mask>>=1) { + c = *buf++; + if (c <= ' ' || c > '~') + break; - if (c == 'x' || c == 'X') { - gpio_confmask[unit] &= ~mask; - reg->trisset = mask; - } else if (c == 'i' || c == 'I') { - gpio_confmask[unit] |= mask; - reg->trisset = mask; - } else if (c == 'o' || c == 'O') { - gpio_confmask[unit] |= mask; - reg->odcclr = mask; - reg->trisclr = mask; - } else if (c == 'd' || c == 'D') { - gpio_confmask[unit] |= mask; - reg->odcset = mask; - reg->trisclr = mask; - } - } - } else { - /* /dev/portX device: port value mask */ - u_int conf = gpio_confmask[unit]; - u_int tris = reg->tris; - for (mask=1<<(NPINS-1); mask; mask>>=1) { - c = *buf++; - if (c <= ' ' || c > '~') - break; - - if (! (conf & mask) || (tris & mask)) - continue; - - if (c == '0') - reg->latclr = mask; - else - reg->latset = mask; - } + if (c == 'x' || c == 'X') { + gpio_confmask[unit] &= ~mask; + reg->trisset = mask; + } else if (c == 'i' || c == 'I') { + gpio_confmask[unit] |= mask; + reg->trisset = mask; + } else if (c == 'o' || c == 'O') { + gpio_confmask[unit] |= mask; + reg->odcclr = mask; + reg->trisclr = mask; + } else if (c == 'd' || c == 'D') { + gpio_confmask[unit] |= mask; + reg->odcset = mask; + reg->trisclr = mask; + } } + } else { + /* /dev/portX device: port value mask */ + u_int conf = gpio_confmask[unit]; + u_int tris = reg->tris; + for (mask=1<<(NPINS-1); mask; mask>>=1) { + c = *buf++; + if (c <= ' ' || c > '~') + break; + + if (! (conf & mask) || (tris & mask)) + continue; + + if (c == '0') + reg->latclr = mask; + else + reg->latset = mask; + } + } } int gpioopen (dev, flag, mode) - dev_t dev; + dev_t dev; { - register u_int unit = minor(dev) & MINOR_UNIT; + register u_int unit = minor(dev) & MINOR_UNIT; - if (unit >= NGPIO) - return ENXIO; - if (u.u_uid != 0) - return EPERM; - return 0; + if (unit >= NGPIO) + return ENXIO; + if (u.u_uid != 0) + return EPERM; + return 0; } int gpioclose (dev, flag, mode) - dev_t dev; + dev_t dev; { - return 0; + return 0; } int gpioread (dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; + dev_t dev; + struct uio *uio; + int flag; { - register struct iovec *iov; - register u_int cnt = NPINS + 1; - char buf [20]; + register struct iovec *iov; + register u_int cnt = NPINS + 1; + char buf [20]; - /* I/o size should be large enough. */ - iov = uio->uio_iov; - if (iov->iov_len < cnt) - return EIO; + /* I/o size should be large enough. */ + iov = uio->uio_iov; + if (iov->iov_len < cnt) + return EIO; - /* Read only cnt bytes. */ - if (uio->uio_offset >= cnt) - return 0; - cnt -= uio->uio_offset; + /* Read only cnt bytes. */ + if (uio->uio_offset >= cnt) + return 0; + cnt -= uio->uio_offset; - /* Print port status to buffer. */ - gpio_print (dev, buf); - //PRINTDBG ("gpioread -> %s", buf); + /* Print port status to buffer. */ + gpio_print (dev, buf); + //PRINTDBG ("gpioread -> %s", buf); - bcopy (buf + uio->uio_offset, iov->iov_base, cnt); - iov->iov_base += cnt; - iov->iov_len -= cnt; - uio->uio_resid -= cnt; - uio->uio_offset += cnt; - return 0; + bcopy (buf + uio->uio_offset, iov->iov_base, cnt); + iov->iov_base += cnt; + iov->iov_len -= cnt; + uio->uio_resid -= cnt; + uio->uio_offset += cnt; + return 0; } int gpiowrite (dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; + dev_t dev; + struct uio *uio; + int flag; { - register struct iovec *iov = uio->uio_iov; - register u_int cnt = NPINS; - char buf [20]; + register struct iovec *iov = uio->uio_iov; + register u_int cnt = NPINS; + char buf [20]; - /* I/o size should be large enough. */ - if (iov->iov_len < cnt) - return EIO; + /* I/o size should be large enough. */ + if (iov->iov_len < cnt) + return EIO; - bcopy (iov->iov_base, buf, cnt); - iov->iov_base += cnt; - iov->iov_len -= cnt; - uio->uio_resid -= cnt; - uio->uio_offset += cnt; + bcopy (iov->iov_base, buf, cnt); + iov->iov_base += cnt; + iov->iov_len -= cnt; + uio->uio_resid -= cnt; + uio->uio_offset += cnt; - PRINTDBG ("gpiowrite ('%s')\n", buf); - gpio_parse (dev, buf); - return 0; + PRINTDBG ("gpiowrite ('%s')\n", buf); + gpio_parse (dev, buf); + return 0; } /* @@ -413,108 +413,108 @@ gpiowrite (dev, uio, flag) */ static void gpio_lol (msec, data) - u_int msec; - const short *data; + u_int msec; + const short *data; { - /* Number of control pins for LoL Shield. */ - #define LOL_NPINS 12 + /* Number of control pins for LoL Shield. */ + #define LOL_NPINS 12 - /* Number of rows on LoL Shield. */ - #define LOL_NROW 9 + /* Number of rows on LoL Shield. */ + #define LOL_NROW 9 - /* Number of columns on LoL Shield. */ - #define LOL_NCOL 14 + /* Number of columns on LoL Shield. */ + #define LOL_NCOL 14 - /* Sequence of pins to set high during refresh cycle. */ - static const unsigned high [LOL_NPINS] = { - 1 << 10, /* PB10 - labeled D13 on board (connect to A5) */ - 1 << 9, /* PB9 - D12 (connect to A4) */ - 1 << 7, /* PB7 - D11 (connect to A3) */ - 1 << 6, /* PB6 - D10 (connect to A2) */ - 1 << 4, /* PB4 - D9 (connect to A1) */ - 1 << 11, /* PB11 - D8 */ - 0x10000 << 7, /* PE7 - D7 */ - 0x10000 << 6, /* PE6 - D6 */ - 0x10000 << 5, /* PE5 - D5 */ - 0x10000 << 4, /* PE4 - D4 */ - 0x10000 << 3, /* PE3 - D3 */ - 0x10000 << 2, /* PE2 - D2 */ - }; + /* Sequence of pins to set high during refresh cycle. */ + static const unsigned high [LOL_NPINS] = { + 1 << 10, /* PB10 - labeled D13 on board (connect to A5) */ + 1 << 9, /* PB9 - D12 (connect to A4) */ + 1 << 7, /* PB7 - D11 (connect to A3) */ + 1 << 6, /* PB6 - D10 (connect to A2) */ + 1 << 4, /* PB4 - D9 (connect to A1) */ + 1 << 11, /* PB11 - D8 */ + 0x10000 << 7, /* PE7 - D7 */ + 0x10000 << 6, /* PE6 - D6 */ + 0x10000 << 5, /* PE5 - D5 */ + 0x10000 << 4, /* PE4 - D4 */ + 0x10000 << 3, /* PE3 - D3 */ + 0x10000 << 2, /* PE2 - D2 */ + }; - /* Remap pixels to pin indexes. */ - static const unsigned char lol_map [LOL_NROW*LOL_NCOL*2] = - { - 0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1,0,9,9,0,0,10,10,0,0,11,11,0, - 1,8,1,7,1,6,1,5,1,4,1,3,1,2,1,0,1,9,9,1,1,10,10,1,1,11,11,1, - 2,8,2,7,2,6,2,5,2,4,2,3,2,1,2,0,2,9,9,2,2,10,10,2,2,11,11,2, - 3,8,3,7,3,6,3,5,3,4,3,2,3,1,3,0,3,9,9,3,3,10,10,3,3,11,11,3, - 4,8,4,7,4,6,4,5,4,3,4,2,4,1,4,0,4,9,9,4,4,10,10,4,4,11,11,4, - 5,8,5,7,5,6,5,4,5,3,5,2,5,1,5,0,5,9,9,5,5,10,10,5,5,11,11,5, - 6,8,6,7,6,5,6,4,6,3,6,2,6,1,6,0,6,9,9,6,6,10,10,6,6,11,11,6, - 7,8,7,6,7,5,7,4,7,3,7,2,7,1,7,0,7,9,9,7,7,10,10,7,7,11,11,7, - 8,7,8,6,8,5,8,4,8,3,8,2,8,1,8,0,8,9,9,8,8,10,10,8,8,11,11,8, - }; + /* Remap pixels to pin indexes. */ + static const unsigned char lol_map [LOL_NROW*LOL_NCOL*2] = + { + 0,8,0,7,0,6,0,5,0,4,0,3,0,2,0,1,0,9,9,0,0,10,10,0,0,11,11,0, + 1,8,1,7,1,6,1,5,1,4,1,3,1,2,1,0,1,9,9,1,1,10,10,1,1,11,11,1, + 2,8,2,7,2,6,2,5,2,4,2,3,2,1,2,0,2,9,9,2,2,10,10,2,2,11,11,2, + 3,8,3,7,3,6,3,5,3,4,3,2,3,1,3,0,3,9,9,3,3,10,10,3,3,11,11,3, + 4,8,4,7,4,6,4,5,4,3,4,2,4,1,4,0,4,9,9,4,4,10,10,4,4,11,11,4, + 5,8,5,7,5,6,5,4,5,3,5,2,5,1,5,0,5,9,9,5,5,10,10,5,5,11,11,5, + 6,8,6,7,6,5,6,4,6,3,6,2,6,1,6,0,6,9,9,6,6,10,10,6,6,11,11,6, + 7,8,7,6,7,5,7,4,7,3,7,2,7,1,7,0,7,9,9,7,7,10,10,7,7,11,11,7, + 8,7,8,6,8,5,8,4,8,3,8,2,8,1,8,0,8,9,9,8,8,10,10,8,8,11,11,8, + }; - unsigned row, mask, bmask, emask; - const unsigned char *map; - unsigned low [LOL_NPINS]; + unsigned row, mask, bmask, emask; + const unsigned char *map; + unsigned low [LOL_NPINS]; - /* Clear pin masks. */ - for (row = 0; row < LOL_NPINS; row++) - low [row] = 0; + /* Clear pin masks. */ + for (row = 0; row < LOL_NPINS; row++) + low [row] = 0; - /* Convert image to array of pin masks. */ - for (row = 0; row < LOL_NROW; row++) { - mask = *data++ & ((1 << LOL_NCOL) - 1); - map = &lol_map [row * LOL_NCOL * 2]; - while (mask != 0) { - if (mask & 1) { - low [map[0]] |= high [map[1]]; - } - map += 2; - mask >>= 1; - } + /* Convert image to array of pin masks. */ + for (row = 0; row < LOL_NROW; row++) { + mask = *data++ & ((1 << LOL_NCOL) - 1); + map = &lol_map [row * LOL_NCOL * 2]; + while (mask != 0) { + if (mask & 1) { + low [map[0]] |= high [map[1]]; + } + map += 2; + mask >>= 1; } - bmask = high[0] | high[1] | high[2] | high[3] | high[4] | high[5]; - emask = (high[6] | high[7] | high[8] | high[9] | high[10] | - high[11]) >> 16; + } + bmask = high[0] | high[1] | high[2] | high[3] | high[4] | high[5]; + emask = (high[6] | high[7] | high[8] | high[9] | high[10] | + high[11]) >> 16; - /* Display the image. */ - if (msec < 1) - msec = 20; - while (msec-- > 0) { - for (row = 0; row < LOL_NPINS; row++) { - /* Set all pins to tristate. */ - TRISBSET = bmask; - TRISESET = emask; + /* Display the image. */ + if (msec < 1) + msec = 20; + while (msec-- > 0) { + for (row = 0; row < LOL_NPINS; row++) { + /* Set all pins to tristate. */ + TRISBSET = bmask; + TRISESET = emask; - /* Set one pin to high. */ - mask = high [row]; - if (row < 6) { - TRISBCLR = mask; - LATBSET = mask; - } else { - mask >>= 16; - TRISECLR = mask; - LATESET = mask; - } + /* Set one pin to high. */ + mask = high [row]; + if (row < 6) { + TRISBCLR = mask; + LATBSET = mask; + } else { + mask >>= 16; + TRISECLR = mask; + LATESET = mask; + } - /* Set other pins to low. */ - mask = low [row]; - TRISBCLR = mask; - LATBCLR = mask; - mask >>= 16; - TRISECLR = mask; - LATECLR = mask; + /* Set other pins to low. */ + mask = low [row]; + TRISBCLR = mask; + LATBCLR = mask; + mask >>= 16; + TRISECLR = mask; + LATECLR = mask; - /* Pause to make it visible. */ - udelay (1000 / LOL_NPINS); - } + /* Pause to make it visible. */ + udelay (1000 / LOL_NPINS); } + } - /* Turn display off. */ - TRISBSET = bmask; - TRISESET = emask; + /* Turn display off. */ + TRISBSET = bmask; + TRISESET = emask; } /* @@ -533,96 +533,96 @@ gpio_lol (msec, data) */ int gpioioctl (dev, cmd, addr, flag) - dev_t dev; - register u_int cmd; - caddr_t addr; + dev_t dev; + register u_int cmd; + caddr_t addr; { - register u_int unit, mask, value; - register struct gpioreg *reg; + register u_int unit, mask, value; + register struct gpioreg *reg; - PRINTDBG ("gpioioctl (cmd=%08x, addr=%08x, flag=%d)\n", cmd, addr, flag); - unit = cmd & 0xff; - cmd &= ~0xff; - if (cmd == GPIO_LOL) { - /* display 9x14 image on a lol shield */ - if (baduaddr (addr) || baduaddr (addr + LOL_NROW*2 - 1)) - return EFAULT; - gpio_lol (unit, (const short*) addr); - return 0; - } + PRINTDBG ("gpioioctl (cmd=%08x, addr=%08x, flag=%d)\n", cmd, addr, flag); + unit = cmd & 0xff; + cmd &= ~0xff; + if (cmd == GPIO_LOL) { + /* display 9x14 image on a lol shield */ + if (baduaddr (addr) || baduaddr (addr + LOL_NROW*2 - 1)) + return EFAULT; + gpio_lol (unit, (const short*) addr); + return 0; + } - if ((cmd & (IOC_INOUT | IOC_VOID)) != IOC_VOID || - ((cmd >> 8) & 0xff) != 'g') - return EINVAL; - if (unit >= NGPIO) - return ENXIO; + if ((cmd & (IOC_INOUT | IOC_VOID)) != IOC_VOID || + ((cmd >> 8) & 0xff) != 'g') + return EINVAL; + if (unit >= NGPIO) + return ENXIO; - reg = unit + (struct gpioreg*) &TRISA; - mask = (u_int) addr & 0xffff; - if (cmd & GPIO_COMMAND & (GPIO_CONFIN | GPIO_CONFOUT | GPIO_CONFOD)) - mask = gpio_filter (mask, unit); - else - mask &= gpio_confmask[unit]; + reg = unit + (struct gpioreg*) &TRISA; + mask = (u_int) addr & 0xffff; + if (cmd & GPIO_COMMAND & (GPIO_CONFIN | GPIO_CONFOUT | GPIO_CONFOD)) + mask = gpio_filter (mask, unit); + else + mask &= gpio_confmask[unit]; - if (cmd & GPIO_COMMAND & GPIO_CONFIN) { - /* configure as input */ - PRINTDBG ("TRIS%cSET %p := %04x\n", unit+'A', ®->trisset, mask); - reg->trisset = mask; - gpio_confmask[unit] |= mask; + if (cmd & GPIO_COMMAND & GPIO_CONFIN) { + /* configure as input */ + PRINTDBG ("TRIS%cSET %p := %04x\n", unit+'A', ®->trisset, mask); + reg->trisset = mask; + gpio_confmask[unit] |= mask; - /* skip output-only bits */ - gpio_confmask[unit] ^= mask & ~reg->tris; + /* skip output-only bits */ + gpio_confmask[unit] ^= mask & ~reg->tris; + } + if (cmd & GPIO_COMMAND & (GPIO_CONFOUT | GPIO_CONFOD)) { + if (cmd & GPIO_COMMAND & GPIO_CONFOUT) { + /* configure as output */ + PRINTDBG ("ODC%cCLR %p := %04x\n", unit+'A', ®->odcclr, mask); + reg->odcclr = mask; + } else { + /* configure as open drain */ + PRINTDBG ("ODC%cSET %p := %04x\n", unit+'A', ®->odcset, mask); + reg->odcset = mask; } - if (cmd & GPIO_COMMAND & (GPIO_CONFOUT | GPIO_CONFOD)) { - if (cmd & GPIO_COMMAND & GPIO_CONFOUT) { - /* configure as output */ - PRINTDBG ("ODC%cCLR %p := %04x\n", unit+'A', ®->odcclr, mask); - reg->odcclr = mask; - } else { - /* configure as open drain */ - PRINTDBG ("ODC%cSET %p := %04x\n", unit+'A', ®->odcset, mask); - reg->odcset = mask; - } - PRINTDBG ("TRIS%cCLR %p := %04x\n", unit+'A', ®->trisclr, mask); - reg->trisclr = mask; - gpio_confmask[unit] |= mask; + PRINTDBG ("TRIS%cCLR %p := %04x\n", unit+'A', ®->trisclr, mask); + reg->trisclr = mask; + gpio_confmask[unit] |= mask; - /* skip input-only bits */ - gpio_confmask[unit] ^= mask & reg->tris; - } - if (cmd & GPIO_COMMAND & GPIO_DECONF) { - /* deconfigure */ - gpio_confmask[unit] &= ~mask; - } - if (cmd & GPIO_COMMAND & GPIO_STORE) { - /* store all outputs */ - value = reg->lat; - PRINTDBG ("LAT%c %p -> %04x\n", unit+'A', ®->lat, value); - value &= ~gpio_confmask[unit]; - value |= mask; - PRINTDBG ("LAT%c %p := %04x\n", unit+'A', ®->lat, value); - reg->lat = value; - } - if (cmd & GPIO_COMMAND & GPIO_SET) { - /* set to 1 by mask */ - PRINTDBG ("LAT%cSET %p := %04x\n", unit+'A', ®->latset, mask); - reg->latset = mask; - } - if (cmd & GPIO_COMMAND & GPIO_CLEAR) { - /* set to 0 by mask */ - PRINTDBG ("LAT%cCLR %p := %04x\n", unit+'A', ®->latclr, mask); - reg->latclr = mask; - } - if (cmd & GPIO_COMMAND & GPIO_INVERT) { - /* invert by mask */ - PRINTDBG ("LAT%cINV %p := %04x\n", unit+'A', ®->latinv, mask); - reg->latinv = mask; - } - if (cmd & GPIO_COMMAND & GPIO_POLL) { - /* send current pin values to user */ - value = reg->port; - PRINTDBG ("PORT%c %p -> %04x\n", unit+'A', ®->port, value); - u.u_rval = value; - } - return 0; + /* skip input-only bits */ + gpio_confmask[unit] ^= mask & reg->tris; + } + if (cmd & GPIO_COMMAND & GPIO_DECONF) { + /* deconfigure */ + gpio_confmask[unit] &= ~mask; + } + if (cmd & GPIO_COMMAND & GPIO_STORE) { + /* store all outputs */ + value = reg->lat; + PRINTDBG ("LAT%c %p -> %04x\n", unit+'A', ®->lat, value); + value &= ~gpio_confmask[unit]; + value |= mask; + PRINTDBG ("LAT%c %p := %04x\n", unit+'A', ®->lat, value); + reg->lat = value; + } + if (cmd & GPIO_COMMAND & GPIO_SET) { + /* set to 1 by mask */ + PRINTDBG ("LAT%cSET %p := %04x\n", unit+'A', ®->latset, mask); + reg->latset = mask; + } + if (cmd & GPIO_COMMAND & GPIO_CLEAR) { + /* set to 0 by mask */ + PRINTDBG ("LAT%cCLR %p := %04x\n", unit+'A', ®->latclr, mask); + reg->latclr = mask; + } + if (cmd & GPIO_COMMAND & GPIO_INVERT) { + /* invert by mask */ + PRINTDBG ("LAT%cINV %p := %04x\n", unit+'A', ®->latinv, mask); + reg->latinv = mask; + } + if (cmd & GPIO_COMMAND & GPIO_POLL) { + /* send current pin values to user */ + value = reg->port; + PRINTDBG ("PORT%c %p -> %04x\n", unit+'A', ®->port, value); + u.u_rval = value; + } + return 0; } diff --git a/sys/pic32/hx8357.c b/sys/pic32/hx8357.c index 5934a33..f827ff1 100644 --- a/sys/pic32/hx8357.c +++ b/sys/pic32/hx8357.c @@ -21,7 +21,6 @@ * arising out of or in connection with the use or performance of * this software. */ - #include "param.h" #include "conf.h" #include "user.h" @@ -44,7 +43,6 @@ typedef struct { unsigned char bitsPerPixel; } FontHeader; - struct tty hx8357_ttys[1]; typedef struct { @@ -102,19 +100,22 @@ const struct devspec hx8357devs[] = { { 0, 0 } }; -void inline static writeCommand(unsigned short c) { +void inline static writeCommand(unsigned short c) +{ while (PMMODE & PIC32_PMMODE_BUSY); PMADDR = 0x0000; PMDIN = c; } -void inline static writeData(unsigned short c) { +void inline static writeData(unsigned short c) +{ while (PMMODE & PIC32_PMMODE_BUSY); PMADDR = 0x0001; PMDIN = c; } -void initDisplay() { +void initDisplay() +{ PMCONCLR = PIC32_PMCON_ON; asm volatile("nop"); @@ -125,7 +126,6 @@ void initDisplay() { PMADDR = 0; PMCONSET = PIC32_PMCON_ON; - writeCommand(HX8357_EXIT_SLEEP_MODE); //Sleep Out udelay(150000); writeCommand(HX8357_ENABLE_EXTENSION_COMMAND); @@ -232,7 +232,8 @@ void initDisplay() { } } -void inline static setAddrWindow(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1) { +void inline static setAddrWindow(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1) +{ writeCommand(HX8357_SET_COLUMN_ADDRESS); // Column addr set writeData((x0) >> 8); writeData(x0); // XSTART @@ -248,7 +249,8 @@ void inline static setAddrWindow(unsigned short x0, unsigned short y0, unsigned writeCommand(HX8357_WRITE_MEMORY_START); //Write SRAM Data } -void inline static setPixel(int x, int y, unsigned short color) { +void inline static setPixel(int x, int y, unsigned short color) +{ if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; setAddrWindow(x,y,x+1,y+1); @@ -276,36 +278,36 @@ void inline static setRotation(unsigned char m) { writeCommand(HX8357_SET_ADDRESS_MODE); rotation = m % 4; // can't be higher than 3 - switch (rotation) - { - case 0: - //PORTRAIT - writeData(0x0000); - _width = 320; - _height = 480; - break; - case 1: - //LANDSCAPE - writeData(0x0060); - _width = 480; - _height = 320; - break; - case 2: - //UPSIDE DOWN PORTRAIT - writeData(0x00C0); - _width = 320; - _height = 480; - break; - case 3: - //UPSIDE DOWN LANDSCAPE - writeData(0x00A0); - _width = 480; - _height = 320; - break; + switch (rotation) { + case 0: + //PORTRAIT + writeData(0x0000); + _width = 320; + _height = 480; + break; + case 1: + //LANDSCAPE + writeData(0x0060); + _width = 480; + _height = 320; + break; + case 2: + //UPSIDE DOWN PORTRAIT + writeData(0x00C0); + _width = 320; + _height = 480; + break; + case 3: + //UPSIDE DOWN LANDSCAPE + writeData(0x00A0); + _width = 480; + _height = 320; + break; } } -unsigned short inline static mix(unsigned short a, unsigned short b, unsigned char pct) { +unsigned short inline static mix(unsigned short a, unsigned short b, unsigned char pct) +{ Color565 col_a; Color565 col_b; Color565 col_out; @@ -322,8 +324,8 @@ unsigned short inline static mix(unsigned short a, unsigned short b, unsigned ch } -unsigned char drawChar(int x, int y, unsigned char c, unsigned short color, unsigned short bg) { - +unsigned char drawChar(int x, int y, unsigned char c, unsigned short color, unsigned short bg) +{ if (font == NULL) { return 0; } @@ -373,17 +375,20 @@ unsigned char drawChar(int x, int y, unsigned char c, unsigned short color, unsi return charwidth; } -void updateLine(int l) { - if (l < 0) return; - if (l > 39) return; +void updateLine(int l) +{ + if (l < 0 || l > 39) + return; int c; for (c = 0; c < 80; c++) { - drawChar(c * _font_width, l * _font_height, frame[l][c] & 0x7F, frame[l][c] & 0x80 ? texthicolor : textcolor, textbgcolor); + drawChar(c * _font_width, l * _font_height, frame[l][c] & 0x7F, + frame[l][c] & 0x80 ? texthicolor : textcolor, textbgcolor); } } -void scrollUp() { +void scrollUp() +{ int l, c; for (l = 0; l < 39; l++) { for (c = 0; c < 80; c++) { @@ -404,208 +409,206 @@ int edVal[4]; int bold = 0; -void printChar(unsigned char c) { +void printChar(unsigned char c) +{ switch (c) { - case '\n': - cursor_y ++; - if (cursor_y > 39) { - scrollUp(); - cursor_y = 39; + case '\n': + cursor_y ++; + if (cursor_y > 39) { + scrollUp(); + cursor_y = 39; + } + break; + case '\r': + cursor_x = 0; + break; + case 8: + cursor_x--; + if (cursor_x < 0) { + cursor_x = 79; + cursor_y--; + if (cursor_y < 0) { + cursor_y = 0; } - break; - case '\r': + } + break; + default: + frame[cursor_y][cursor_x] = c | (bold ? 0x80 : 0x00); + cursor_x++; + if (cursor_x == 80) { cursor_x = 0; - break; - case 8: - cursor_x--; - if (cursor_x < 0) { - cursor_x = 79; - cursor_y--; - if (cursor_y < 0) { - cursor_y = 0; - } + cursor_y++; + if (cursor_y == 40) { + cursor_y = 39; + scrollUp(); } - break; - default: - frame[cursor_y][cursor_x] = c | (bold ? 0x80 : 0x00); - cursor_x++; - if (cursor_x == 80) { - cursor_x = 0; - cursor_y++; - if (cursor_y == 40) { - cursor_y = 39; - scrollUp(); - } - } - updateLine(cursor_y); - + } + updateLine(cursor_y); } } int extended = 0; -void writeChar(unsigned char c) { - +void writeChar(unsigned char c) +{ int i, j; updateLine(cursor_y); if (inEscape == 1) { - switch (c) { - case 27: - inEscape = 0; - printChar('^'); - printChar('['); - break; - case '[': - extended = 1; - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - edVal[edValPos%4] *= 10; - edVal[edValPos%4] += c - '0'; - break; - case ';': - edValPos++; - edVal[edValPos%4] = 0; - break; - case 'J': - if (extended == 1) { - if (edVal[0] == 0) { - for (i = cursor_y; i < 40; i++) { - for (j = 0; j < 80; j++) { - frame[i][j] = ' '; - } - updateLine(i); + case 27: + inEscape = 0; + printChar('^'); + printChar('['); + break; + case '[': + extended = 1; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + edVal[edValPos%4] *= 10; + edVal[edValPos%4] += c - '0'; + break; + case ';': + edValPos++; + edVal[edValPos%4] = 0; + break; + case 'J': + if (extended == 1) { + if (edVal[0] == 0) { + for (i = cursor_y; i < 40; i++) { + for (j = 0; j < 80; j++) { + frame[i][j] = ' '; } - } else if (edVal[0] == 1) { - for (i = 0; i < cursor_y; i++) { - for (j = 0; j < 80; j++) { - frame[i][j] = ' '; - } - updateLine(i); - } - } else if (edVal[0] == 2) { - for (i = 0; i < 40; i++) { - for (j = 0; j < 80; j++) { - frame[i][j] = ' '; - } - updateLine(i); - } - } - } - inEscape = 0; - break; - case 'H': - if (extended == 1) { - if (edVal[0] == 0) { - edVal[0] = 1; + updateLine(i); } - if (edVal[1] == 0) { - edVal[1] = 1; + } else if (edVal[0] == 1) { + for (i = 0; i < cursor_y; i++) { + for (j = 0; j < 80; j++) { + frame[i][j] = ' '; + } + updateLine(i); } - cursor_x = (edVal[1] - 1) % 80; - cursor_y = (edVal[0] - 1) % 40; - } - inEscape = 0; - break; - case 'm': - if (extended == 1) { - if (edVal[0] == 0) { - bold = 0; - } else if (edVal[0] == 1) { - bold = 1; + } else if (edVal[0] == 2) { + for (i = 0; i < 40; i++) { + for (j = 0; j < 80; j++) { + frame[i][j] = ' '; + } + updateLine(i); } } - inEscape = 0; - break; + } + inEscape = 0; + break; + case 'H': + if (extended == 1) { + if (edVal[0] == 0) { + edVal[0] = 1; + } + if (edVal[1] == 0) { + edVal[1] = 1; + } + cursor_x = (edVal[1] - 1) % 80; + cursor_y = (edVal[0] - 1) % 40; + } + inEscape = 0; + break; + case 'm': + if (extended == 1) { + if (edVal[0] == 0) { + bold = 0; + } else if (edVal[0] == 1) { + bold = 1; + } + } + inEscape = 0; + break; - case 'A': - if (extended == 0) { - cursor_y--; - if (cursor_y > 0) { - cursor_y = 39; - } + case 'A': + if (extended == 0) { + cursor_y--; + if (cursor_y > 0) { + cursor_y = 39; } - inEscape = 0; - break; + } + inEscape = 0; + break; - case 'B': - if (extended == 0) { + case 'B': + if (extended == 0) { + cursor_y++; + if (cursor_y == 40) { + cursor_y = 0; + } + } + inEscape = 0; + break; + + case 'C': + if (extended == 0) { + cursor_x++; + if (cursor_x == 80) { + cursor_x = 0; cursor_y++; if (cursor_y == 40) { cursor_y = 0; } } - inEscape = 0; - break; + } + inEscape = 0; + break; - case 'C': - if (extended == 0) { - cursor_x++; - if (cursor_x == 80) { - cursor_x = 0; - cursor_y++; - if (cursor_y == 40) { - cursor_y = 0; - } + case 'D': + if (extended == 0) { + cursor_x--; + if (cursor_x < 0) { + cursor_x = 79; + cursor_y--; + if (cursor_y < 0) { + cursor_y = 39; } } - inEscape = 0; - break; + } + inEscape = 0; + break; - case 'D': - if (extended == 0) { - cursor_x--; - if (cursor_x < 0) { - cursor_x = 79; - cursor_y--; - if (cursor_y < 0) { - cursor_y = 39; - } + case 'K': + if (extended == 1) { + if (edVal[0] == 0) { + for (i = cursor_x; i < 80; i++) { + frame[cursor_y][i] = ' '; } - } - inEscape = 0; - break; - - case 'K': - if (extended == 1) { - if (edVal[0] == 0) { - for (i = cursor_x; i < 80; i++) { - frame[cursor_y][i] = ' '; - } - } else if (edVal[1] == 1) { - for (i = 0; i < cursor_x; i++) { - frame[cursor_y][i] = ' '; - } - } else { - for (i = 0; i < 80; i++) { - frame[cursor_y][i] = ' '; - } + } else if (edVal[1] == 1) { + for (i = 0; i < cursor_x; i++) { + frame[cursor_y][i] = ' '; } - updateLine(cursor_y); - } - inEscape = 0; - break; - - default: - if (extended) { - printf("Unhandled extended escape code %c\n", c); } else { - printf("Unhandled escape code %c\n", c); + for (i = 0; i < 80; i++) { + frame[cursor_y][i] = ' '; + } } - inEscape = 0; - break; - } + updateLine(cursor_y); + } + inEscape = 0; + break; + default: + if (extended) { + printf("Unhandled extended escape code %c\n", c); + } else { + printf("Unhandled escape code %c\n", c); + } + inEscape = 0; + break; + } } else { if (c == 27) { inEscape = 1; @@ -616,14 +619,19 @@ void writeChar(unsigned char c) { printChar(c); } } - drawChar(cursor_x * _font_width, cursor_y * _font_height, frame[cursor_y][cursor_x] & 0x7F, 0x0000, bold ? texthicolor : textcolor); -// for (i = 0; i < _font_width; i++) { -// setPixel(cursor_x * _font_width + i, (cursor_y + 1) * _font_height - 1, 0xFFFF); -// } - + drawChar(cursor_x * _font_width, cursor_y * _font_height, + frame[cursor_y][cursor_x] & 0x7F, 0x0000, + bold ? texthicolor : textcolor); +#if 0 + for (i = 0; i < _font_width; i++) { + setPixel(cursor_x * _font_width + i, + (cursor_y + 1) * _font_height - 1, 0xFFFF); + } +#endif } -void hx8357_start(struct tty *tp) { +void hx8357_start(struct tty *tp) +{ register int s; s = spltty(); @@ -641,7 +649,8 @@ void hx8357_start(struct tty *tp) { splx (s); } -void hx8357_init() { +void hx8357_init() +{ initDisplay(); setRotation(1); int i,j; @@ -655,7 +664,8 @@ void hx8357_init() { int ttyIsOpen = 0; -int hx8357_open(dev_t dev, int flag, int mode) { +int hx8357_open(dev_t dev, int flag, int mode) +{ int unit = minor(dev); if (unit == 0) { @@ -675,7 +685,8 @@ int hx8357_open(dev_t dev, int flag, int mode) { return ENODEV; } -int hx8357_close(dev_t dev, int flag, int mode) { +int hx8357_close(dev_t dev, int flag, int mode) +{ int unit = minor(dev); if (unit == 0) { @@ -691,7 +702,8 @@ int hx8357_close(dev_t dev, int flag, int mode) { return ENODEV; } -int hx8357_read(dev_t dev, struct uio *uio, int flag) { +int hx8357_read(dev_t dev, struct uio *uio, int flag) +{ int unit = minor(dev); if (unit == 0) { @@ -705,7 +717,8 @@ int hx8357_read(dev_t dev, struct uio *uio, int flag) { return ENODEV; } -int hx8357_write(dev_t dev, struct uio *uio, int flag) { +int hx8357_write(dev_t dev, struct uio *uio, int flag) +{ int unit = minor(dev); if (unit == 0) { @@ -728,11 +741,12 @@ int hx8357_write(dev_t dev, struct uio *uio, int flag) { uio->uio_offset ++; } return 0; - } + } return ENODEV; } -int hx8357_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag) { +int hx8357_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag) +{ int unit = minor(dev); if (unit == 0) { @@ -752,15 +766,18 @@ int hx8357_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag) { } -void hx8357_putc(dev_t dev, char c) { +void hx8357_putc(dev_t dev, char c) +{ writeChar(c); } -char hx8357_getc(dev_t dev) { +char hx8357_getc(dev_t dev) +{ return 0; } -int hx8357_select (dev_t dev, int rw) { +int hx8357_select (dev_t dev, int rw) +{ int unit = minor(dev); if (unit == 0) { struct tty *tp = &hx8357_ttys[unit]; @@ -771,4 +788,3 @@ int hx8357_select (dev_t dev, int rw) { } return ENODEV; } - diff --git a/sys/pic32/io.h b/sys/pic32/io.h index 491d994..f3df65a 100644 --- a/sys/pic32/io.h +++ b/sys/pic32/io.h @@ -31,41 +31,41 @@ /* * Offsets of register values in saved context. */ -#define FRAME_R1 0 -#define FRAME_R2 1 -#define FRAME_R3 2 -#define FRAME_R4 3 -#define FRAME_R5 4 -#define FRAME_R6 5 -#define FRAME_R7 6 -#define FRAME_R8 7 -#define FRAME_R9 8 -#define FRAME_R10 9 -#define FRAME_R11 10 -#define FRAME_R12 11 -#define FRAME_R13 12 -#define FRAME_R14 13 -#define FRAME_R15 14 -#define FRAME_R16 15 -#define FRAME_R17 16 -#define FRAME_R18 17 -#define FRAME_R19 18 -#define FRAME_R20 19 -#define FRAME_R21 20 -#define FRAME_R22 21 -#define FRAME_R23 22 -#define FRAME_R24 23 -#define FRAME_R25 24 -#define FRAME_GP 25 -#define FRAME_SP 26 -#define FRAME_FP 27 -#define FRAME_RA 28 -#define FRAME_LO 29 -#define FRAME_HI 30 -#define FRAME_STATUS 31 -#define FRAME_PC 32 +#define FRAME_R1 0 +#define FRAME_R2 1 +#define FRAME_R3 2 +#define FRAME_R4 3 +#define FRAME_R5 4 +#define FRAME_R6 5 +#define FRAME_R7 6 +#define FRAME_R8 7 +#define FRAME_R9 8 +#define FRAME_R10 9 +#define FRAME_R11 10 +#define FRAME_R12 11 +#define FRAME_R13 12 +#define FRAME_R14 13 +#define FRAME_R15 14 +#define FRAME_R16 15 +#define FRAME_R17 16 +#define FRAME_R18 17 +#define FRAME_R19 18 +#define FRAME_R20 19 +#define FRAME_R21 20 +#define FRAME_R22 21 +#define FRAME_R23 22 +#define FRAME_R24 23 +#define FRAME_R25 24 +#define FRAME_GP 25 +#define FRAME_SP 26 +#define FRAME_FP 27 +#define FRAME_RA 28 +#define FRAME_LO 29 +#define FRAME_HI 30 +#define FRAME_STATUS 31 +#define FRAME_PC 32 -#define FRAME_WORDS 33 +#define FRAME_WORDS 33 #ifndef __ASSEMBLER__ @@ -97,9 +97,9 @@ unsigned ucall (int priority, void *address, int arg1, int arg2); static void inline __attribute__ ((always_inline)) mips_set_stack_pointer (void *x) { - asm volatile ( - "move $sp, %0" - : : "r" (x) : "sp"); + asm volatile ( + "move $sp, %0" + : : "r" (x) : "sp"); } /* @@ -108,34 +108,34 @@ mips_set_stack_pointer (void *x) static inline __attribute__ ((always_inline)) void *mips_get_stack_pointer () { - void *x; + void *x; - asm volatile ( - "move %0, $sp" - : "=r" (x)); - return x; + asm volatile ( + "move %0, $sp" + : "=r" (x)); + return x; } /* * Read C0 coprocessor register. */ -#define mips_read_c0_register(reg,sel) \ - ({ int __value; \ - asm volatile ( \ - "mfc0 %0, $%1, %2" \ - : "=r" (__value) : "K" (reg), "K" (sel)); \ - __value; \ -}) +#define mips_read_c0_register(reg,sel) \ + ({ int __value; \ + asm volatile ( \ + "mfc0 %0, $%1, %2" \ + : "=r" (__value) : "K" (reg), "K" (sel)); \ + __value; \ + }) /* * Write C0 coprocessor register. */ -#define mips_write_c0_register(reg, sel, value) \ -do { \ - asm volatile ( \ - "mtc0 %z0, $%1, %2 \n ehb" \ - : : "r" ((unsigned int) (value)), "K" (reg), "K" (sel));\ -} while (0) +#define mips_write_c0_register(reg, sel, value) \ + do { \ + asm volatile ( \ + "mtc0 %z0, $%1, %2 \n ehb" \ + : : "r" ((unsigned int) (value)), "K" (reg), "K" (sel)); \ + } while (0) /* * Disable the hardware interrupts, @@ -144,9 +144,9 @@ do { \ static int inline __attribute__ ((always_inline)) mips_intr_disable () { - int status; - asm volatile ("di %0" : "=r" (status)); - return status; + int status; + asm volatile ("di %0" : "=r" (status)); + return status; } /* @@ -155,8 +155,8 @@ mips_intr_disable () static void inline __attribute__ ((always_inline)) mips_intr_restore (int x) { - /* C0_STATUS */ - mips_write_c0_register (12, 0, x); + /* C0_STATUS */ + mips_write_c0_register (12, 0, x); } /* @@ -165,7 +165,7 @@ mips_intr_restore (int x) static void inline __attribute__ ((always_inline)) mips_ehb() { - asm volatile ("ehb"); + asm volatile ("ehb"); } /* @@ -174,9 +174,9 @@ mips_ehb() static int inline __attribute__ ((always_inline)) mips_intr_enable () { - int status; - asm volatile ("ei %0" : "=r" (status)); - return status; + int status; + asm volatile ("ei %0" : "=r" (status)); + return status; } /* @@ -185,11 +185,11 @@ mips_intr_enable () static int inline __attribute__ ((always_inline)) mips_clz (unsigned x) { - int n; + int n; - asm volatile ("clz %0, %1" - : "=r" (n) : "r" (x)); - return n; + asm volatile ("clz %0, %1" + : "=r" (n) : "r" (x)); + return n; } /* @@ -198,12 +198,12 @@ mips_clz (unsigned x) static unsigned inline __attribute__ ((always_inline)) mips_bswap (unsigned x) { - int n; + int n; - asm volatile ( - "wsbh %0, %1 \n" - "rotr %0, 16" - : "=r" (n) : "r" (x)); - return n; + asm volatile ( + "wsbh %0, %1 \n" + "rotr %0, 16" + : "=r" (n) : "r" (x)); + return n; } #endif /* __ASSEMBLER__ */ diff --git a/sys/pic32/limits.h b/sys/pic32/limits.h index 6198023..9173354 100644 --- a/sys/pic32/limits.h +++ b/sys/pic32/limits.h @@ -1,6 +1,6 @@ /* * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. + * 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 @@ -12,8 +12,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -#define CHAR_BIT 8 /* number of bits in a char */ +#define CHAR_BIT 8 /* number of bits in a char */ /* * According to ANSI (section 2.2.4.2), the values below must be usable by @@ -43,24 +43,24 @@ * These numbers work for pcc as well. The UINT_MAX and ULONG_MAX values * are written as hex so that GCC will be quiet about large integer constants. */ -#define SCHAR_MAX 127 /* min value for a signed char */ -#define SCHAR_MIN (-128) /* max value for a signed char */ +#define SCHAR_MAX 127 /* min value for a signed char */ +#define SCHAR_MIN (-128) /* max value for a signed char */ -#define UCHAR_MAX 255 /* max value for an unsigned char */ -#define CHAR_MAX 127 /* max value for a char */ -#define CHAR_MIN (-128) /* min value for a char */ +#define UCHAR_MAX 255 /* max value for an unsigned char */ +#define CHAR_MAX 127 /* max value for a char */ +#define CHAR_MIN (-128) /* min value for a char */ -#define USHRT_MAX 65535 /* max value for an unsigned short */ -#define SHRT_MAX 32767 /* max value for a short */ -#define SHRT_MIN (-32768) /* min value for a short */ +#define USHRT_MAX 65535 /* max value for an unsigned short */ +#define SHRT_MAX 32767 /* max value for a short */ +#define SHRT_MIN (-32768) /* min value for a short */ -#define UINT_MAX 0xffffffff /* max value for an unsigned int */ -#define INT_MAX 2147483647 /* max value for an int */ -#define INT_MIN (-2147483647-1) /* min value for an int */ +#define UINT_MAX 0xffffffff /* max value for an unsigned int */ +#define INT_MAX 2147483647 /* max value for an int */ +#define INT_MIN (-2147483647-1) /* min value for an int */ -#define ULONG_MAX 0xffffffff /* max value for an unsigned long */ -#define LONG_MAX 2147483647L /* max value for a long */ -#define LONG_MIN (-2147483647L-1L) /* min value for a long */ +#define ULONG_MAX 0xffffffff /* max value for an unsigned long */ +#define LONG_MAX 2147483647L /* max value for a long */ +#define LONG_MIN (-2147483647L-1L) /* min value for a long */ #define SSIZE_MAX INT_MAX /* max value for a ssize_t */ -#define SIZE_T_MAX UINT_MAX /* max value for a size_t */ +#define SIZE_T_MAX UINT_MAX /* max value for a size_t */ diff --git a/sys/pic32/machparam.h b/sys/pic32/machparam.h index 6a4b3ca..c2eb51b 100644 --- a/sys/pic32/machparam.h +++ b/sys/pic32/machparam.h @@ -11,10 +11,10 @@ * Definitions for byte order, * according to byte significance from low address to high. */ -#define LITTLE 1234 /* least-significant byte first (vax) */ -#define BIG 4321 /* most-significant byte first */ -#define PDP 3412 /* LSB first in word, MSW first in long (pdp) */ -#define ENDIAN LITTLE /* byte order on pic32 */ +#define LITTLE 1234 /* least-significant byte first (vax) */ +#define BIG 4321 /* most-significant byte first */ +#define PDP 3412 /* LSB first in word, MSW first in long (pdp) */ +#define ENDIAN LITTLE /* byte order on pic32 */ /* * The time for a process to be blocked before being very swappable. @@ -25,47 +25,47 @@ * It is related to human patience and other factors which don't really * change over time. */ -#define MAXSLP 20 +#define MAXSLP 20 /* * Clock ticks per second. The HZ value must be an integer factor of 1000. */ #ifndef HZ -#define HZ 200 +#define HZ 200 #endif /* * System parameter formulae. */ #ifndef NBUF -#define NBUF 10 /* number of i/o buffers */ +#define NBUF 10 /* number of i/o buffers */ #endif -#define MAXUSERS 1 /* number of user logins */ +#define MAXUSERS 1 /* number of user logins */ #ifndef NPROC -#define NPROC 10 /* number of processes */ +#define NPROC 10 /* number of processes */ #endif #ifndef NINODE -#define NINODE 24 +#define NINODE 24 #endif #ifndef NFILE -#define NFILE 24 +#define NFILE 24 #endif -#define NNAMECACHE (NINODE * 11/10) -#define NCALL (16 + 2 * MAXUSERS) -#define NCLIST 32 /* number or CBSIZE blocks */ +#define NNAMECACHE (NINODE * 11/10) +#define NCALL (16 + 2 * MAXUSERS) +#define NCLIST 32 /* number or CBSIZE blocks */ #ifndef SMAPSIZ -#define SMAPSIZ NPROC /* size of swap allocation map */ +#define SMAPSIZ NPROC /* size of swap allocation map */ #endif /* * Disk blocks. */ -#define DEV_BSIZE 1024 /* the same as MAXBSIZE */ -#define DEV_BSHIFT 10 /* log2(DEV_BSIZE) */ -#define DEV_BMASK (DEV_BSIZE-1) +#define DEV_BSIZE 1024 /* the same as MAXBSIZE */ +#define DEV_BSHIFT 10 /* log2(DEV_BSIZE) */ +#define DEV_BMASK (DEV_BSIZE-1) /* Bytes to disk blocks */ -#define btod(x) (((x) + DEV_BSIZE-1) >> DEV_BSHIFT) +#define btod(x) (((x) + DEV_BSIZE-1) >> DEV_BSHIFT) /* * On PIC32, there are total 512 kbytes of flash and 128 kbytes of RAM. @@ -74,33 +74,33 @@ #define FLASH_SIZE (512*1024) #define DATA_SIZE (128*1024) -#define KERNEL_FLASH_SIZE (192*1024) +#define KERNEL_FLASH_SIZE (192*1024) #ifdef KERNEL_EXECUTABLE_RAM extern void _keram_start(), _keram_end(); #define KERAM_SIZE ((unsigned)((char*)&_keram_end-(char*)&_keram_start)) -#define KERNEL_DATA_SIZE (32*1024-KERAM_SIZE) +#define KERNEL_DATA_SIZE (32*1024-KERAM_SIZE) #else -#define KERNEL_DATA_SIZE (32*1024) +#define KERNEL_DATA_SIZE (32*1024) #endif -#define KERNEL_FLASH_START 0x9d000000 -#define USER_FLASH_START (KERNEL_FLASH_START + KERNEL_FLASH_SIZE) -#define USER_FLASH_END (KERNEL_FLASH_START + FLASH_SIZE) +#define KERNEL_FLASH_START 0x9d000000 +#define USER_FLASH_START (KERNEL_FLASH_START + KERNEL_FLASH_SIZE) +#define USER_FLASH_END (KERNEL_FLASH_START + FLASH_SIZE) -#define KERNEL_DATA_START 0x80000000 -#define KERNEL_DATA_END (KERNEL_DATA_START + KERNEL_DATA_SIZE) +#define KERNEL_DATA_START 0x80000000 +#define KERNEL_DATA_END (KERNEL_DATA_START + KERNEL_DATA_SIZE) #ifdef KERNEL_EXECUTABLE_RAM -#define USER_DATA_START (0x7f000000 + KERNEL_DATA_SIZE+KERAM_SIZE) +#define USER_DATA_START (0x7f000000 + KERNEL_DATA_SIZE+KERAM_SIZE) #else -#define USER_DATA_START (0x7f000000 + KERNEL_DATA_SIZE) +#define USER_DATA_START (0x7f000000 + KERNEL_DATA_SIZE) #endif -#define USER_DATA_END (0x7f000000 + DATA_SIZE) +#define USER_DATA_END (0x7f000000 + DATA_SIZE) -#define stacktop(siz) (USER_DATA_END) -#define stackbas(siz) (USER_DATA_END-(siz)) +#define stacktop(siz) (USER_DATA_END) +#define stackbas(siz) (USER_DATA_END-(siz)) /* * User area: a user structure, followed by the kernel @@ -113,8 +113,8 @@ extern void _keram_start(), _keram_end(); * applications having to be recompiled for networking versus non-networking * systems. */ -#define USIZE 3072 -#define SSIZE 2048 /* initial stack size (bytes) */ +#define USIZE 3072 +#define SSIZE 2048 /* initial stack size (bytes) */ #ifdef KERNEL #include "machine/io.h" @@ -122,38 +122,38 @@ extern void _keram_start(), _keram_end(); /* * Macros to decode processor status word. */ -#define USERMODE(ps) (((ps) & ST_UM) != 0) -#define BASEPRI(ps) (CA_RIPL(ps) == 0) +#define USERMODE(ps) (((ps) & ST_UM) != 0) +#define BASEPRI(ps) (CA_RIPL(ps) == 0) -#define splbio() mips_intr_disable () -#define spltty() mips_intr_disable () -#define splclock() mips_intr_disable () -#define splhigh() mips_intr_disable () -#define splnet() mips_intr_enable () -#define splsoftclock() mips_intr_enable () -#define spl0() mips_intr_enable () -#define splx(s) mips_intr_restore (s) +#define splbio() mips_intr_disable() +#define spltty() mips_intr_disable() +#define splclock() mips_intr_disable() +#define splhigh() mips_intr_disable() +#define splnet() mips_intr_enable() +#define splsoftclock() mips_intr_enable() +#define spl0() mips_intr_enable() +#define splx(s) mips_intr_restore(s) -#define noop() asm volatile ("nop") +#define noop() asm volatile("nop") /* * Wait for something to happen. */ -void idle (void); +void idle(void); /* * Microsecond delay routine. */ -void udelay (unsigned usec); +void udelay(unsigned usec); /* * Setup system timer for `hz' timer interrupts per second. */ -void clkstart (void); +void clkstart(void); /* * Control LEDs, installed on the board. - */ + */ #define LED_MISC4 0x80 #define LED_MISC3 0x40 #define LED_MISC2 0x20 @@ -163,7 +163,7 @@ void clkstart (void); #define LED_DISK 0x02 #define LED_KERNEL 0x01 -void led_control (int mask, int on); +void led_control(int mask, int on); /* * Port i/o access, relative to TRIS base. diff --git a/sys/pic32/mem.c b/sys/pic32/mem.c index f0bc531..e8e9301 100644 --- a/sys/pic32/mem.c +++ b/sys/pic32/mem.c @@ -27,59 +27,59 @@ void kmemdev() */ int mmrw (dev, uio, flag) - dev_t dev; - register struct uio *uio; - int flag; + dev_t dev; + register struct uio *uio; + int flag; { - register struct iovec *iov; - int error = 0; - register u_int c; - caddr_t addr; + register struct iovec *iov; + int error = 0; + register u_int c; + caddr_t addr; - //printf ("mmrw (dev=%u, len=%u, flag=%d)\n", dev, uio->uio_iov->iov_len, flag); - while (uio->uio_resid && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - case 0: /* minor device 0 is physical memory (/dev/mem) */ - case 1: /* minor device 1 is kernel memory (/dev/kmem) */ - addr = (caddr_t) uio->uio_offset; - if ((badkaddr (addr) && baduaddr (addr)) || - (badkaddr (addr + iov->iov_len - 1) && - baduaddr (addr + iov->iov_len - 1))) { - error = EFAULT; - break; - } - error = uiomove(addr, iov->iov_len, uio); - break; - case 2: /* minor device 2 is EOF/RATHOLE (/dev/null) */ - if (uio->uio_rw == UIO_READ) - return(0); - c = iov->iov_len; - iov->iov_base += c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - break; - case 3: /* minor device 3 is ZERO (/dev/zero) */ - if (uio->uio_rw == UIO_WRITE) - return(EIO); - c = iov->iov_len; - bzero (iov->iov_base, c); - iov->iov_base += c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - break; - default: - return(EINVAL); - } - } - return(error); + //printf ("mmrw (dev=%u, len=%u, flag=%d)\n", dev, uio->uio_iov->iov_len, flag); + while (uio->uio_resid && error == 0) { + iov = uio->uio_iov; + if (iov->iov_len == 0) { + uio->uio_iov++; + uio->uio_iovcnt--; + if (uio->uio_iovcnt < 0) + panic("mmrw"); + continue; + } + switch (minor(dev)) { + case 0: /* minor device 0 is physical memory (/dev/mem) */ + case 1: /* minor device 1 is kernel memory (/dev/kmem) */ + addr = (caddr_t) uio->uio_offset; + if ((badkaddr (addr) && baduaddr (addr)) || + (badkaddr (addr + iov->iov_len - 1) && + baduaddr (addr + iov->iov_len - 1))) { + error = EFAULT; + break; + } + error = uiomove(addr, iov->iov_len, uio); + break; + case 2: /* minor device 2 is EOF/RATHOLE (/dev/null) */ + if (uio->uio_rw == UIO_READ) + return(0); + c = iov->iov_len; + iov->iov_base += c; + iov->iov_len -= c; + uio->uio_offset += c; + uio->uio_resid -= c; + break; + case 3: /* minor device 3 is ZERO (/dev/zero) */ + if (uio->uio_rw == UIO_WRITE) + return(EIO); + c = iov->iov_len; + bzero (iov->iov_base, c); + iov->iov_base += c; + iov->iov_len -= c; + uio->uio_offset += c; + uio->uio_resid -= c; + break; + default: + return(EINVAL); + } + } + return(error); } diff --git a/sys/pic32/pic32mx.h b/sys/pic32/pic32mx.h index 32fe44d..d5b1950 100644 --- a/sys/pic32/pic32mx.h +++ b/sys/pic32/pic32mx.h @@ -27,66 +27,66 @@ /*-------------------------------------- * Coprocessor 0 registers. */ -#define C0_HWRENA 7 /* Enable RDHWR in non-privileged mode */ -#define C0_BADVADDR 8 /* Virtual address of last exception */ -#define C0_COUNT 9 /* Processor cycle count */ -#define C0_COMPARE 11 /* Timer interrupt control */ -#define C0_STATUS 12 /* Processor status and control */ -#define C0_INTCTL 12 /* Select 1: interrupt control */ -#define C0_SRSCTL 12 /* Select 2: GPR shadow set control */ -#define C0_SRSMAP 12 /* Select 3: vector to shadow set mapping */ -#define C0_CAUSE 13 /* Cause of last exception */ -#define C0_EPC 14 /* Program counter at last exception */ -#define C0_PRID 15 /* Processor identification (read only) */ -#define C0_EBASE 15 /* Select 1: exception base address */ -#define C0_CONFIG 16 /* Configuration */ -#define C0_CONFIG1 16 /* Select 1: configuration 1 */ -#define C0_CONFIG2 16 /* Select 2: configuration 2 */ -#define C0_CONFIG3 16 /* Select 3: configuration 3 */ -#define C0_DEBUG 23 /* Debug control and status */ -#define C0_DEPC 24 /* Program counter at last debug exception */ -#define C0_ERROREPC 30 /* Program counter at last error */ -#define C0_DESAVE 31 /* Debug handler scratchpad register */ +#define C0_HWRENA 7 /* Enable RDHWR in non-privileged mode */ +#define C0_BADVADDR 8 /* Virtual address of last exception */ +#define C0_COUNT 9 /* Processor cycle count */ +#define C0_COMPARE 11 /* Timer interrupt control */ +#define C0_STATUS 12 /* Processor status and control */ +#define C0_INTCTL 12 /* Select 1: interrupt control */ +#define C0_SRSCTL 12 /* Select 2: GPR shadow set control */ +#define C0_SRSMAP 12 /* Select 3: vector to shadow set mapping */ +#define C0_CAUSE 13 /* Cause of last exception */ +#define C0_EPC 14 /* Program counter at last exception */ +#define C0_PRID 15 /* Processor identification (read only) */ +#define C0_EBASE 15 /* Select 1: exception base address */ +#define C0_CONFIG 16 /* Configuration */ +#define C0_CONFIG1 16 /* Select 1: configuration 1 */ +#define C0_CONFIG2 16 /* Select 2: configuration 2 */ +#define C0_CONFIG3 16 /* Select 3: configuration 3 */ +#define C0_DEBUG 23 /* Debug control and status */ +#define C0_DEPC 24 /* Program counter at last debug exception */ +#define C0_ERROREPC 30 /* Program counter at last error */ +#define C0_DESAVE 31 /* Debug handler scratchpad register */ /* * Status register. */ -#define ST_CU0 0x10000000 /* Access to coprocessor 0 allowed (in user mode) */ -#define ST_RP 0x08000000 /* Enable reduced power mode */ -#define ST_RE 0x02000000 /* Reverse endianness (in user mode) */ -#define ST_BEV 0x00400000 /* Exception vectors: bootstrap */ -#define ST_SR 0x00100000 /* Soft reset */ -#define ST_NMI 0x00080000 /* NMI reset */ -#define ST_IPL(x) ((x) << 10) /* Current interrupt priority level */ -#define ST_UM 0x00000010 /* User mode */ -#define ST_ERL 0x00000004 /* Error level */ -#define ST_EXL 0x00000002 /* Exception level */ -#define ST_IE 0x00000001 /* Interrupt enable */ +#define ST_CU0 0x10000000 /* Access to coprocessor 0 allowed (in user mode) */ +#define ST_RP 0x08000000 /* Enable reduced power mode */ +#define ST_RE 0x02000000 /* Reverse endianness (in user mode) */ +#define ST_BEV 0x00400000 /* Exception vectors: bootstrap */ +#define ST_SR 0x00100000 /* Soft reset */ +#define ST_NMI 0x00080000 /* NMI reset */ +#define ST_IPL(x) ((x) << 10) /* Current interrupt priority level */ +#define ST_UM 0x00000010 /* User mode */ +#define ST_ERL 0x00000004 /* Error level */ +#define ST_EXL 0x00000002 /* Exception level */ +#define ST_IE 0x00000001 /* Interrupt enable */ /* * Сause register. */ -#define CA_BD 0x80000000 /* Exception occured in delay slot */ -#define CA_TI 0x40000000 /* Timer interrupt is pending */ -#define CA_CE 0x30000000 /* Coprocessor exception */ -#define CA_DC 0x08000000 /* Disable COUNT register */ -#define CA_IV 0x00800000 /* Use special interrupt vector 0x200 */ -#define CA_RIPL(r) ((r)>>10 & 63) /* Requested interrupt priority level */ -#define CA_IP1 0x00020000 /* Request software interrupt 1 */ -#define CA_IP0 0x00010000 /* Request software interrupt 0 */ -#define CA_EXC_CODE 0x0000007c /* Exception code */ +#define CA_BD 0x80000000 /* Exception occured in delay slot */ +#define CA_TI 0x40000000 /* Timer interrupt is pending */ +#define CA_CE 0x30000000 /* Coprocessor exception */ +#define CA_DC 0x08000000 /* Disable COUNT register */ +#define CA_IV 0x00800000 /* Use special interrupt vector 0x200 */ +#define CA_RIPL(r) ((r)>>10 & 63) /* Requested interrupt priority level */ +#define CA_IP1 0x00020000 /* Request software interrupt 1 */ +#define CA_IP0 0x00010000 /* Request software interrupt 0 */ +#define CA_EXC_CODE 0x0000007c /* Exception code */ -#define CA_Int 0 /* Interrupt */ -#define CA_AdEL (4 << 2) /* Address error, load or instruction fetch */ -#define CA_AdES (5 << 2) /* Address error, store */ -#define CA_IBE (6 << 2) /* Bus error, instruction fetch */ -#define CA_DBE (7 << 2) /* Bus error, load or store */ -#define CA_Sys (8 << 2) /* Syscall */ -#define CA_Bp (9 << 2) /* Breakpoint */ -#define CA_RI (10 << 2) /* Reserved instruction */ -#define CA_CPU (11 << 2) /* Coprocessor unusable */ -#define CA_Ov (12 << 2) /* Arithmetic overflow */ -#define CA_Tr (13 << 2) /* Trap */ +#define CA_Int 0 /* Interrupt */ +#define CA_AdEL (4 << 2) /* Address error, load or instruction fetch */ +#define CA_AdES (5 << 2) /* Address error, store */ +#define CA_IBE (6 << 2) /* Bus error, instruction fetch */ +#define CA_DBE (7 << 2) /* Bus error, load or store */ +#define CA_Sys (8 << 2) /* Syscall */ +#define CA_Bp (9 << 2) /* Breakpoint */ +#define CA_RI (10 << 2) /* Reserved instruction */ +#define CA_CPU (11 << 2) /* Coprocessor unusable */ +#define CA_Ov (12 << 2) /* Arithmetic overflow */ +#define CA_Tr (13 << 2) /* Trap */ #define DB_DBD (1 << 31) /* Debug exception in a branch delay slot */ #define DB_DM (1 << 30) /* Debug mode */ @@ -113,737 +113,737 @@ * Peripheral registers. */ #ifdef __ASSEMBLER__ -#define PIC32_R(a) (0xBF800000 + (a)) +#define PIC32_R(a) (0xBF800000 + (a)) #else -#define PIC32_R(a) *(volatile unsigned*)(0xBF800000 + (a)) +#define PIC32_R(a) *(volatile unsigned*)(0xBF800000 + (a)) #endif /*-------------------------------------- * UART registers. */ -#define U1MODE PIC32_R (0x6000) /* Mode */ -#define U1MODECLR PIC32_R (0x6004) -#define U1MODESET PIC32_R (0x6008) -#define U1MODEINV PIC32_R (0x600C) -#define U1STA PIC32_R (0x6010) /* Status and control */ -#define U1STACLR PIC32_R (0x6014) -#define U1STASET PIC32_R (0x6018) -#define U1STAINV PIC32_R (0x601C) -#define U1TXREG PIC32_R (0x6020) /* Transmit */ -#define U1RXREG PIC32_R (0x6030) /* Receive */ -#define U1BRG PIC32_R (0x6040) /* Baud rate */ -#define U1BRGCLR PIC32_R (0x6044) -#define U1BRGSET PIC32_R (0x6048) -#define U1BRGINV PIC32_R (0x604C) +#define U1MODE PIC32_R (0x6000) /* Mode */ +#define U1MODECLR PIC32_R (0x6004) +#define U1MODESET PIC32_R (0x6008) +#define U1MODEINV PIC32_R (0x600C) +#define U1STA PIC32_R (0x6010) /* Status and control */ +#define U1STACLR PIC32_R (0x6014) +#define U1STASET PIC32_R (0x6018) +#define U1STAINV PIC32_R (0x601C) +#define U1TXREG PIC32_R (0x6020) /* Transmit */ +#define U1RXREG PIC32_R (0x6030) /* Receive */ +#define U1BRG PIC32_R (0x6040) /* Baud rate */ +#define U1BRGCLR PIC32_R (0x6044) +#define U1BRGSET PIC32_R (0x6048) +#define U1BRGINV PIC32_R (0x604C) #ifdef PIC32MX4 -#define U2MODE PIC32_R (0x6200) /* Mode */ -#define U2MODECLR PIC32_R (0x6204) -#define U2MODESET PIC32_R (0x6208) -#define U2MODEINV PIC32_R (0x620C) -#define U2STA PIC32_R (0x6210) /* Status and control */ -#define U2STACLR PIC32_R (0x6214) -#define U2STASET PIC32_R (0x6218) -#define U2STAINV PIC32_R (0x621C) -#define U2TXREG PIC32_R (0x6220) /* Transmit */ -#define U2RXREG PIC32_R (0x6230) /* Receive */ -#define U2BRG PIC32_R (0x6240) /* Baud rate */ -#define U2BRGCLR PIC32_R (0x6244) -#define U2BRGSET PIC32_R (0x6248) -#define U2BRGINV PIC32_R (0x624C) +#define U2MODE PIC32_R (0x6200) /* Mode */ +#define U2MODECLR PIC32_R (0x6204) +#define U2MODESET PIC32_R (0x6208) +#define U2MODEINV PIC32_R (0x620C) +#define U2STA PIC32_R (0x6210) /* Status and control */ +#define U2STACLR PIC32_R (0x6214) +#define U2STASET PIC32_R (0x6218) +#define U2STAINV PIC32_R (0x621C) +#define U2TXREG PIC32_R (0x6220) /* Transmit */ +#define U2RXREG PIC32_R (0x6230) /* Receive */ +#define U2BRG PIC32_R (0x6240) /* Baud rate */ +#define U2BRGCLR PIC32_R (0x6244) +#define U2BRGSET PIC32_R (0x6248) +#define U2BRGINV PIC32_R (0x624C) #endif #ifdef PIC32MX7 -#define U4MODE PIC32_R (0x6200) /* Mode */ -#define U4MODECLR PIC32_R (0x6204) -#define U4MODESET PIC32_R (0x6208) -#define U4MODEINV PIC32_R (0x620C) -#define U4STA PIC32_R (0x6210) /* Status and control */ -#define U4STACLR PIC32_R (0x6214) -#define U4STASET PIC32_R (0x6218) -#define U4STAINV PIC32_R (0x621C) -#define U4TXREG PIC32_R (0x6220) /* Transmit */ -#define U4RXREG PIC32_R (0x6230) /* Receive */ -#define U4BRG PIC32_R (0x6240) /* Baud rate */ -#define U4BRGCLR PIC32_R (0x6244) -#define U4BRGSET PIC32_R (0x6248) -#define U4BRGINV PIC32_R (0x624C) +#define U4MODE PIC32_R (0x6200) /* Mode */ +#define U4MODECLR PIC32_R (0x6204) +#define U4MODESET PIC32_R (0x6208) +#define U4MODEINV PIC32_R (0x620C) +#define U4STA PIC32_R (0x6210) /* Status and control */ +#define U4STACLR PIC32_R (0x6214) +#define U4STASET PIC32_R (0x6218) +#define U4STAINV PIC32_R (0x621C) +#define U4TXREG PIC32_R (0x6220) /* Transmit */ +#define U4RXREG PIC32_R (0x6230) /* Receive */ +#define U4BRG PIC32_R (0x6240) /* Baud rate */ +#define U4BRGCLR PIC32_R (0x6244) +#define U4BRGSET PIC32_R (0x6248) +#define U4BRGINV PIC32_R (0x624C) -#define U3MODE PIC32_R (0x6400) /* Mode */ -#define U3MODECLR PIC32_R (0x6404) -#define U3MODESET PIC32_R (0x6408) -#define U3MODEINV PIC32_R (0x640C) -#define U3STA PIC32_R (0x6410) /* Status and control */ -#define U3STACLR PIC32_R (0x6414) -#define U3STASET PIC32_R (0x6418) -#define U3STAINV PIC32_R (0x641C) -#define U3TXREG PIC32_R (0x6420) /* Transmit */ -#define U3RXREG PIC32_R (0x6430) /* Receive */ -#define U3BRG PIC32_R (0x6440) /* Baud rate */ -#define U3BRGCLR PIC32_R (0x6444) -#define U3BRGSET PIC32_R (0x6448) -#define U3BRGINV PIC32_R (0x644C) +#define U3MODE PIC32_R (0x6400) /* Mode */ +#define U3MODECLR PIC32_R (0x6404) +#define U3MODESET PIC32_R (0x6408) +#define U3MODEINV PIC32_R (0x640C) +#define U3STA PIC32_R (0x6410) /* Status and control */ +#define U3STACLR PIC32_R (0x6414) +#define U3STASET PIC32_R (0x6418) +#define U3STAINV PIC32_R (0x641C) +#define U3TXREG PIC32_R (0x6420) /* Transmit */ +#define U3RXREG PIC32_R (0x6430) /* Receive */ +#define U3BRG PIC32_R (0x6440) /* Baud rate */ +#define U3BRGCLR PIC32_R (0x6444) +#define U3BRGSET PIC32_R (0x6448) +#define U3BRGINV PIC32_R (0x644C) -#define U6MODE PIC32_R (0x6600) /* Mode */ -#define U6MODECLR PIC32_R (0x6604) -#define U6MODESET PIC32_R (0x6608) -#define U6MODEINV PIC32_R (0x660C) -#define U6STA PIC32_R (0x6610) /* Status and control */ -#define U6STACLR PIC32_R (0x6614) -#define U6STASET PIC32_R (0x6618) -#define U6STAINV PIC32_R (0x661C) -#define U6TXREG PIC32_R (0x6620) /* Transmit */ -#define U6RXREG PIC32_R (0x6630) /* Receive */ -#define U6BRG PIC32_R (0x6640) /* Baud rate */ -#define U6BRGCLR PIC32_R (0x6644) -#define U6BRGSET PIC32_R (0x6648) -#define U6BRGINV PIC32_R (0x664C) +#define U6MODE PIC32_R (0x6600) /* Mode */ +#define U6MODECLR PIC32_R (0x6604) +#define U6MODESET PIC32_R (0x6608) +#define U6MODEINV PIC32_R (0x660C) +#define U6STA PIC32_R (0x6610) /* Status and control */ +#define U6STACLR PIC32_R (0x6614) +#define U6STASET PIC32_R (0x6618) +#define U6STAINV PIC32_R (0x661C) +#define U6TXREG PIC32_R (0x6620) /* Transmit */ +#define U6RXREG PIC32_R (0x6630) /* Receive */ +#define U6BRG PIC32_R (0x6640) /* Baud rate */ +#define U6BRGCLR PIC32_R (0x6644) +#define U6BRGSET PIC32_R (0x6648) +#define U6BRGINV PIC32_R (0x664C) -#define U2MODE PIC32_R (0x6800) /* Mode */ -#define U2MODECLR PIC32_R (0x6804) -#define U2MODESET PIC32_R (0x6808) -#define U2MODEINV PIC32_R (0x680C) -#define U2STA PIC32_R (0x6810) /* Status and control */ -#define U2STACLR PIC32_R (0x6814) -#define U2STASET PIC32_R (0x6818) -#define U2STAINV PIC32_R (0x681C) -#define U2TXREG PIC32_R (0x6820) /* Transmit */ -#define U2RXREG PIC32_R (0x6830) /* Receive */ -#define U2BRG PIC32_R (0x6840) /* Baud rate */ -#define U2BRGCLR PIC32_R (0x6844) -#define U2BRGSET PIC32_R (0x6848) -#define U2BRGINV PIC32_R (0x684C) +#define U2MODE PIC32_R (0x6800) /* Mode */ +#define U2MODECLR PIC32_R (0x6804) +#define U2MODESET PIC32_R (0x6808) +#define U2MODEINV PIC32_R (0x680C) +#define U2STA PIC32_R (0x6810) /* Status and control */ +#define U2STACLR PIC32_R (0x6814) +#define U2STASET PIC32_R (0x6818) +#define U2STAINV PIC32_R (0x681C) +#define U2TXREG PIC32_R (0x6820) /* Transmit */ +#define U2RXREG PIC32_R (0x6830) /* Receive */ +#define U2BRG PIC32_R (0x6840) /* Baud rate */ +#define U2BRGCLR PIC32_R (0x6844) +#define U2BRGSET PIC32_R (0x6848) +#define U2BRGINV PIC32_R (0x684C) -#define U5MODE PIC32_R (0x6A00) /* Mode */ -#define U5MODECLR PIC32_R (0x6A04) -#define U5MODESET PIC32_R (0x6A08) -#define U5MODEINV PIC32_R (0x6A0C) -#define U5STA PIC32_R (0x6A10) /* Status and control */ -#define U5STACLR PIC32_R (0x6A14) -#define U5STASET PIC32_R (0x6A18) -#define U5STAINV PIC32_R (0x6A1C) -#define U5TXREG PIC32_R (0x6A20) /* Transmit */ -#define U5RXREG PIC32_R (0x6A30) /* Receive */ -#define U5BRG PIC32_R (0x6A40) /* Baud rate */ -#define U5BRGCLR PIC32_R (0x6A44) -#define U5BRGSET PIC32_R (0x6A48) -#define U5BRGINV PIC32_R (0x6A4C) +#define U5MODE PIC32_R (0x6A00) /* Mode */ +#define U5MODECLR PIC32_R (0x6A04) +#define U5MODESET PIC32_R (0x6A08) +#define U5MODEINV PIC32_R (0x6A0C) +#define U5STA PIC32_R (0x6A10) /* Status and control */ +#define U5STACLR PIC32_R (0x6A14) +#define U5STASET PIC32_R (0x6A18) +#define U5STAINV PIC32_R (0x6A1C) +#define U5TXREG PIC32_R (0x6A20) /* Transmit */ +#define U5RXREG PIC32_R (0x6A30) /* Receive */ +#define U5BRG PIC32_R (0x6A40) /* Baud rate */ +#define U5BRGCLR PIC32_R (0x6A44) +#define U5BRGSET PIC32_R (0x6A48) +#define U5BRGINV PIC32_R (0x6A4C) #endif /* * UART Mode register. */ -#define PIC32_UMODE_STSEL 0x0001 /* 2 Stop bits */ -#define PIC32_UMODE_PDSEL 0x0006 /* Bitmask: */ -#define PIC32_UMODE_PDSEL_8NPAR 0x0000 /* 8-bit data, no parity */ -#define PIC32_UMODE_PDSEL_8EVEN 0x0002 /* 8-bit data, even parity */ -#define PIC32_UMODE_PDSEL_8ODD 0x0004 /* 8-bit data, odd parity */ -#define PIC32_UMODE_PDSEL_9NPAR 0x0006 /* 9-bit data, no parity */ -#define PIC32_UMODE_BRGH 0x0008 /* High Baud Rate Enable */ -#define PIC32_UMODE_RXINV 0x0010 /* Receive Polarity Inversion */ -#define PIC32_UMODE_ABAUD 0x0020 /* Auto-Baud Enable */ -#define PIC32_UMODE_LPBACK 0x0040 /* UARTx Loopback Mode */ -#define PIC32_UMODE_WAKE 0x0080 /* Wake-up on start bit during Sleep Mode */ -#define PIC32_UMODE_UEN 0x0300 /* Bitmask: */ -#define PIC32_UMODE_UEN_RTS 0x0100 /* Using UxRTS pin */ -#define PIC32_UMODE_UEN_RTSCTS 0x0200 /* Using UxCTS and UxRTS pins */ -#define PIC32_UMODE_UEN_BCLK 0x0300 /* Using UxBCLK pin */ -#define PIC32_UMODE_RTSMD 0x0800 /* UxRTS Pin Simplex mode */ -#define PIC32_UMODE_IREN 0x1000 /* IrDA Encoder and Decoder Enable bit */ -#define PIC32_UMODE_SIDL 0x2000 /* Stop in Idle Mode */ -#define PIC32_UMODE_FRZ 0x4000 /* Freeze in Debug Exception Mode */ -#define PIC32_UMODE_ON 0x8000 /* UART Enable */ +#define PIC32_UMODE_STSEL 0x0001 /* 2 Stop bits */ +#define PIC32_UMODE_PDSEL 0x0006 /* Bitmask: */ +#define PIC32_UMODE_PDSEL_8NPAR 0x0000 /* 8-bit data, no parity */ +#define PIC32_UMODE_PDSEL_8EVEN 0x0002 /* 8-bit data, even parity */ +#define PIC32_UMODE_PDSEL_8ODD 0x0004 /* 8-bit data, odd parity */ +#define PIC32_UMODE_PDSEL_9NPAR 0x0006 /* 9-bit data, no parity */ +#define PIC32_UMODE_BRGH 0x0008 /* High Baud Rate Enable */ +#define PIC32_UMODE_RXINV 0x0010 /* Receive Polarity Inversion */ +#define PIC32_UMODE_ABAUD 0x0020 /* Auto-Baud Enable */ +#define PIC32_UMODE_LPBACK 0x0040 /* UARTx Loopback Mode */ +#define PIC32_UMODE_WAKE 0x0080 /* Wake-up on start bit during Sleep Mode */ +#define PIC32_UMODE_UEN 0x0300 /* Bitmask: */ +#define PIC32_UMODE_UEN_RTS 0x0100 /* Using UxRTS pin */ +#define PIC32_UMODE_UEN_RTSCTS 0x0200 /* Using UxCTS and UxRTS pins */ +#define PIC32_UMODE_UEN_BCLK 0x0300 /* Using UxBCLK pin */ +#define PIC32_UMODE_RTSMD 0x0800 /* UxRTS Pin Simplex mode */ +#define PIC32_UMODE_IREN 0x1000 /* IrDA Encoder and Decoder Enable bit */ +#define PIC32_UMODE_SIDL 0x2000 /* Stop in Idle Mode */ +#define PIC32_UMODE_FRZ 0x4000 /* Freeze in Debug Exception Mode */ +#define PIC32_UMODE_ON 0x8000 /* UART Enable */ /* * UART Control and status register. */ -#define PIC32_USTA_URXDA 0x00000001 /* Receive Data Available (read-only) */ -#define PIC32_USTA_OERR 0x00000002 /* Receive Buffer Overrun */ -#define PIC32_USTA_FERR 0x00000004 /* Framing error detected (read-only) */ -#define PIC32_USTA_PERR 0x00000008 /* Parity error detected (read-only) */ -#define PIC32_USTA_RIDLE 0x00000010 /* Receiver is idle (read-only) */ -#define PIC32_USTA_ADDEN 0x00000020 /* Address Detect mode */ -#define PIC32_USTA_URXISEL 0x000000C0 /* Bitmask: receive interrupt is set when... */ -#define PIC32_USTA_URXISEL_NEMP 0x00000000 /* ...receive buffer is not empty */ -#define PIC32_USTA_URXISEL_HALF 0x00000040 /* ...receive buffer becomes 1/2 full */ -#define PIC32_USTA_URXISEL_3_4 0x00000080 /* ...receive buffer becomes 3/4 full */ -#define PIC32_USTA_TRMT 0x00000100 /* Transmit shift register is empty (read-only) */ -#define PIC32_USTA_UTXBF 0x00000200 /* Transmit buffer is full (read-only) */ -#define PIC32_USTA_UTXEN 0x00000400 /* Transmit Enable */ -#define PIC32_USTA_UTXBRK 0x00000800 /* Transmit Break */ -#define PIC32_USTA_URXEN 0x00001000 /* Receiver Enable */ -#define PIC32_USTA_UTXINV 0x00002000 /* Transmit Polarity Inversion */ -#define PIC32_USTA_UTXISEL 0x0000C000 /* Bitmask: TX interrupt is generated when... */ -#define PIC32_USTA_UTXISEL_1 0x00000000 /* ...the transmit buffer contains at least one empty space */ -#define PIC32_USTA_UTXISEL_ALL 0x00004000 /* ...all characters have been transmitted */ -#define PIC32_USTA_UTXISEL_EMP 0x00008000 /* ...the transmit buffer becomes empty */ -#define PIC32_USTA_ADDR 0x00FF0000 /* Automatic Address Mask */ -#define PIC32_USTA_ADM_EN 0x01000000 /* Automatic Address Detect */ +#define PIC32_USTA_URXDA 0x00000001 /* Receive Data Available (read-only) */ +#define PIC32_USTA_OERR 0x00000002 /* Receive Buffer Overrun */ +#define PIC32_USTA_FERR 0x00000004 /* Framing error detected (read-only) */ +#define PIC32_USTA_PERR 0x00000008 /* Parity error detected (read-only) */ +#define PIC32_USTA_RIDLE 0x00000010 /* Receiver is idle (read-only) */ +#define PIC32_USTA_ADDEN 0x00000020 /* Address Detect mode */ +#define PIC32_USTA_URXISEL 0x000000C0 /* Bitmask: receive interrupt is set when... */ +#define PIC32_USTA_URXISEL_NEMP 0x00000000 /* ...receive buffer is not empty */ +#define PIC32_USTA_URXISEL_HALF 0x00000040 /* ...receive buffer becomes 1/2 full */ +#define PIC32_USTA_URXISEL_3_4 0x00000080 /* ...receive buffer becomes 3/4 full */ +#define PIC32_USTA_TRMT 0x00000100 /* Transmit shift register is empty (read-only) */ +#define PIC32_USTA_UTXBF 0x00000200 /* Transmit buffer is full (read-only) */ +#define PIC32_USTA_UTXEN 0x00000400 /* Transmit Enable */ +#define PIC32_USTA_UTXBRK 0x00000800 /* Transmit Break */ +#define PIC32_USTA_URXEN 0x00001000 /* Receiver Enable */ +#define PIC32_USTA_UTXINV 0x00002000 /* Transmit Polarity Inversion */ +#define PIC32_USTA_UTXISEL 0x0000C000 /* Bitmask: TX interrupt is generated when... */ +#define PIC32_USTA_UTXISEL_1 0x00000000 /* ...the transmit buffer contains at least one empty space */ +#define PIC32_USTA_UTXISEL_ALL 0x00004000 /* ...all characters have been transmitted */ +#define PIC32_USTA_UTXISEL_EMP 0x00008000 /* ...the transmit buffer becomes empty */ +#define PIC32_USTA_ADDR 0x00FF0000 /* Automatic Address Mask */ +#define PIC32_USTA_ADM_EN 0x01000000 /* Automatic Address Detect */ /* * Compute the 16-bit baud rate divisor, given * the bus frequency and baud rate. * Round to the nearest integer. */ -#define PIC32_BRG_BAUD(fr,bd) ((((fr)/8 + (bd)) / (bd) / 2) - 1) +#define PIC32_BRG_BAUD(fr,bd) ((((fr)/8 + (bd)) / (bd) / 2) - 1) /*-------------------------------------- * Port A-G registers. */ -#define TRISA PIC32_R (0x86000) /* Port A: mask of inputs */ -#define TRISACLR PIC32_R (0x86004) -#define TRISASET PIC32_R (0x86008) -#define TRISAINV PIC32_R (0x8600C) -#define PORTA PIC32_R (0x86010) /* Port A: read inputs, write outputs */ -#define PORTACLR PIC32_R (0x86014) -#define PORTASET PIC32_R (0x86018) -#define PORTAINV PIC32_R (0x8601C) -#define LATA PIC32_R (0x86020) /* Port A: read/write outputs */ -#define LATACLR PIC32_R (0x86024) -#define LATASET PIC32_R (0x86028) -#define LATAINV PIC32_R (0x8602C) -#define ODCA PIC32_R (0x86030) /* Port A: open drain configuration */ -#define ODCACLR PIC32_R (0x86034) -#define ODCASET PIC32_R (0x86038) -#define ODCAINV PIC32_R (0x8603C) +#define TRISA PIC32_R (0x86000) /* Port A: mask of inputs */ +#define TRISACLR PIC32_R (0x86004) +#define TRISASET PIC32_R (0x86008) +#define TRISAINV PIC32_R (0x8600C) +#define PORTA PIC32_R (0x86010) /* Port A: read inputs, write outputs */ +#define PORTACLR PIC32_R (0x86014) +#define PORTASET PIC32_R (0x86018) +#define PORTAINV PIC32_R (0x8601C) +#define LATA PIC32_R (0x86020) /* Port A: read/write outputs */ +#define LATACLR PIC32_R (0x86024) +#define LATASET PIC32_R (0x86028) +#define LATAINV PIC32_R (0x8602C) +#define ODCA PIC32_R (0x86030) /* Port A: open drain configuration */ +#define ODCACLR PIC32_R (0x86034) +#define ODCASET PIC32_R (0x86038) +#define ODCAINV PIC32_R (0x8603C) -#define TRISB PIC32_R (0x86040) /* Port B: mask of inputs */ -#define TRISBCLR PIC32_R (0x86044) -#define TRISBSET PIC32_R (0x86048) -#define TRISBINV PIC32_R (0x8604C) -#define PORTB PIC32_R (0x86050) /* Port B: read inputs, write outputs */ -#define PORTBCLR PIC32_R (0x86054) -#define PORTBSET PIC32_R (0x86058) -#define PORTBINV PIC32_R (0x8605C) -#define LATB PIC32_R (0x86060) /* Port B: read/write outputs */ -#define LATBCLR PIC32_R (0x86064) -#define LATBSET PIC32_R (0x86068) -#define LATBINV PIC32_R (0x8606C) -#define ODCB PIC32_R (0x86070) /* Port B: open drain configuration */ -#define ODCBCLR PIC32_R (0x86074) -#define ODCBSET PIC32_R (0x86078) -#define ODCBINV PIC32_R (0x8607C) +#define TRISB PIC32_R (0x86040) /* Port B: mask of inputs */ +#define TRISBCLR PIC32_R (0x86044) +#define TRISBSET PIC32_R (0x86048) +#define TRISBINV PIC32_R (0x8604C) +#define PORTB PIC32_R (0x86050) /* Port B: read inputs, write outputs */ +#define PORTBCLR PIC32_R (0x86054) +#define PORTBSET PIC32_R (0x86058) +#define PORTBINV PIC32_R (0x8605C) +#define LATB PIC32_R (0x86060) /* Port B: read/write outputs */ +#define LATBCLR PIC32_R (0x86064) +#define LATBSET PIC32_R (0x86068) +#define LATBINV PIC32_R (0x8606C) +#define ODCB PIC32_R (0x86070) /* Port B: open drain configuration */ +#define ODCBCLR PIC32_R (0x86074) +#define ODCBSET PIC32_R (0x86078) +#define ODCBINV PIC32_R (0x8607C) -#define TRISC PIC32_R (0x86080) /* Port C: mask of inputs */ -#define TRISCCLR PIC32_R (0x86084) -#define TRISCSET PIC32_R (0x86088) -#define TRISCINV PIC32_R (0x8608C) -#define PORTC PIC32_R (0x86090) /* Port C: read inputs, write outputs */ -#define PORTCCLR PIC32_R (0x86094) -#define PORTCSET PIC32_R (0x86098) -#define PORTCINV PIC32_R (0x8609C) -#define LATC PIC32_R (0x860A0) /* Port C: read/write outputs */ -#define LATCCLR PIC32_R (0x860A4) -#define LATCSET PIC32_R (0x860A8) -#define LATCINV PIC32_R (0x860AC) -#define ODCC PIC32_R (0x860B0) /* Port C: open drain configuration */ -#define ODCCCLR PIC32_R (0x860B4) -#define ODCCSET PIC32_R (0x860B8) -#define ODCCINV PIC32_R (0x860BC) +#define TRISC PIC32_R (0x86080) /* Port C: mask of inputs */ +#define TRISCCLR PIC32_R (0x86084) +#define TRISCSET PIC32_R (0x86088) +#define TRISCINV PIC32_R (0x8608C) +#define PORTC PIC32_R (0x86090) /* Port C: read inputs, write outputs */ +#define PORTCCLR PIC32_R (0x86094) +#define PORTCSET PIC32_R (0x86098) +#define PORTCINV PIC32_R (0x8609C) +#define LATC PIC32_R (0x860A0) /* Port C: read/write outputs */ +#define LATCCLR PIC32_R (0x860A4) +#define LATCSET PIC32_R (0x860A8) +#define LATCINV PIC32_R (0x860AC) +#define ODCC PIC32_R (0x860B0) /* Port C: open drain configuration */ +#define ODCCCLR PIC32_R (0x860B4) +#define ODCCSET PIC32_R (0x860B8) +#define ODCCINV PIC32_R (0x860BC) -#define TRISD PIC32_R (0x860C0) /* Port D: mask of inputs */ -#define TRISDCLR PIC32_R (0x860C4) -#define TRISDSET PIC32_R (0x860C8) -#define TRISDINV PIC32_R (0x860CC) -#define PORTD PIC32_R (0x860D0) /* Port D: read inputs, write outputs */ -#define PORTDCLR PIC32_R (0x860D4) -#define PORTDSET PIC32_R (0x860D8) -#define PORTDINV PIC32_R (0x860DC) -#define LATD PIC32_R (0x860E0) /* Port D: read/write outputs */ -#define LATDCLR PIC32_R (0x860E4) -#define LATDSET PIC32_R (0x860E8) -#define LATDINV PIC32_R (0x860EC) -#define ODCD PIC32_R (0x860F0) /* Port D: open drain configuration */ -#define ODCDCLR PIC32_R (0x860F4) -#define ODCDSET PIC32_R (0x860F8) -#define ODCDINV PIC32_R (0x860FC) +#define TRISD PIC32_R (0x860C0) /* Port D: mask of inputs */ +#define TRISDCLR PIC32_R (0x860C4) +#define TRISDSET PIC32_R (0x860C8) +#define TRISDINV PIC32_R (0x860CC) +#define PORTD PIC32_R (0x860D0) /* Port D: read inputs, write outputs */ +#define PORTDCLR PIC32_R (0x860D4) +#define PORTDSET PIC32_R (0x860D8) +#define PORTDINV PIC32_R (0x860DC) +#define LATD PIC32_R (0x860E0) /* Port D: read/write outputs */ +#define LATDCLR PIC32_R (0x860E4) +#define LATDSET PIC32_R (0x860E8) +#define LATDINV PIC32_R (0x860EC) +#define ODCD PIC32_R (0x860F0) /* Port D: open drain configuration */ +#define ODCDCLR PIC32_R (0x860F4) +#define ODCDSET PIC32_R (0x860F8) +#define ODCDINV PIC32_R (0x860FC) -#define TRISE PIC32_R (0x86100) /* Port E: mask of inputs */ -#define TRISECLR PIC32_R (0x86104) -#define TRISESET PIC32_R (0x86108) -#define TRISEINV PIC32_R (0x8610C) -#define PORTE PIC32_R (0x86110) /* Port E: read inputs, write outputs */ -#define PORTECLR PIC32_R (0x86114) -#define PORTESET PIC32_R (0x86118) -#define PORTEINV PIC32_R (0x8611C) -#define LATE PIC32_R (0x86120) /* Port E: read/write outputs */ -#define LATECLR PIC32_R (0x86124) -#define LATESET PIC32_R (0x86128) -#define LATEINV PIC32_R (0x8612C) -#define ODCE PIC32_R (0x86130) /* Port E: open drain configuration */ -#define ODCECLR PIC32_R (0x86134) -#define ODCESET PIC32_R (0x86138) -#define ODCEINV PIC32_R (0x8613C) +#define TRISE PIC32_R (0x86100) /* Port E: mask of inputs */ +#define TRISECLR PIC32_R (0x86104) +#define TRISESET PIC32_R (0x86108) +#define TRISEINV PIC32_R (0x8610C) +#define PORTE PIC32_R (0x86110) /* Port E: read inputs, write outputs */ +#define PORTECLR PIC32_R (0x86114) +#define PORTESET PIC32_R (0x86118) +#define PORTEINV PIC32_R (0x8611C) +#define LATE PIC32_R (0x86120) /* Port E: read/write outputs */ +#define LATECLR PIC32_R (0x86124) +#define LATESET PIC32_R (0x86128) +#define LATEINV PIC32_R (0x8612C) +#define ODCE PIC32_R (0x86130) /* Port E: open drain configuration */ +#define ODCECLR PIC32_R (0x86134) +#define ODCESET PIC32_R (0x86138) +#define ODCEINV PIC32_R (0x8613C) -#define TRISF PIC32_R (0x86140) /* Port F: mask of inputs */ -#define TRISFCLR PIC32_R (0x86144) -#define TRISFSET PIC32_R (0x86148) -#define TRISFINV PIC32_R (0x8614C) -#define PORTF PIC32_R (0x86150) /* Port F: read inputs, write outputs */ -#define PORTFCLR PIC32_R (0x86154) -#define PORTFSET PIC32_R (0x86158) -#define PORTFINV PIC32_R (0x8615C) -#define LATF PIC32_R (0x86160) /* Port F: read/write outputs */ -#define LATFCLR PIC32_R (0x86164) -#define LATFSET PIC32_R (0x86168) -#define LATFINV PIC32_R (0x8616C) -#define ODCF PIC32_R (0x86170) /* Port F: open drain configuration */ -#define ODCFCLR PIC32_R (0x86174) -#define ODCFSET PIC32_R (0x86178) -#define ODCFINV PIC32_R (0x8617C) +#define TRISF PIC32_R (0x86140) /* Port F: mask of inputs */ +#define TRISFCLR PIC32_R (0x86144) +#define TRISFSET PIC32_R (0x86148) +#define TRISFINV PIC32_R (0x8614C) +#define PORTF PIC32_R (0x86150) /* Port F: read inputs, write outputs */ +#define PORTFCLR PIC32_R (0x86154) +#define PORTFSET PIC32_R (0x86158) +#define PORTFINV PIC32_R (0x8615C) +#define LATF PIC32_R (0x86160) /* Port F: read/write outputs */ +#define LATFCLR PIC32_R (0x86164) +#define LATFSET PIC32_R (0x86168) +#define LATFINV PIC32_R (0x8616C) +#define ODCF PIC32_R (0x86170) /* Port F: open drain configuration */ +#define ODCFCLR PIC32_R (0x86174) +#define ODCFSET PIC32_R (0x86178) +#define ODCFINV PIC32_R (0x8617C) -#define TRISG PIC32_R (0x86180) /* Port G: mask of inputs */ -#define TRISGCLR PIC32_R (0x86184) -#define TRISGSET PIC32_R (0x86188) -#define TRISGINV PIC32_R (0x8618C) -#define PORTG PIC32_R (0x86190) /* Port G: read inputs, write outputs */ -#define PORTGCLR PIC32_R (0x86194) -#define PORTGSET PIC32_R (0x86198) -#define PORTGINV PIC32_R (0x8619C) -#define LATG PIC32_R (0x861A0) /* Port G: read/write outputs */ -#define LATGCLR PIC32_R (0x861A4) -#define LATGSET PIC32_R (0x861A8) -#define LATGINV PIC32_R (0x861AC) -#define ODCG PIC32_R (0x861B0) /* Port G: open drain configuration */ -#define ODCGCLR PIC32_R (0x861B4) -#define ODCGSET PIC32_R (0x861B8) -#define ODCGINV PIC32_R (0x861BC) +#define TRISG PIC32_R (0x86180) /* Port G: mask of inputs */ +#define TRISGCLR PIC32_R (0x86184) +#define TRISGSET PIC32_R (0x86188) +#define TRISGINV PIC32_R (0x8618C) +#define PORTG PIC32_R (0x86190) /* Port G: read inputs, write outputs */ +#define PORTGCLR PIC32_R (0x86194) +#define PORTGSET PIC32_R (0x86198) +#define PORTGINV PIC32_R (0x8619C) +#define LATG PIC32_R (0x861A0) /* Port G: read/write outputs */ +#define LATGCLR PIC32_R (0x861A4) +#define LATGSET PIC32_R (0x861A8) +#define LATGINV PIC32_R (0x861AC) +#define ODCG PIC32_R (0x861B0) /* Port G: open drain configuration */ +#define ODCGCLR PIC32_R (0x861B4) +#define ODCGSET PIC32_R (0x861B8) +#define ODCGINV PIC32_R (0x861BC) -#define CNCON PIC32_R (0x861C0) /* Interrupt-on-change control */ -#define CNCONCLR PIC32_R (0x861C4) -#define CNCONSET PIC32_R (0x861C8) -#define CNCONINV PIC32_R (0x861CC) -#define CNEN PIC32_R (0x861D0) /* Input change interrupt enable */ -#define CNENCLR PIC32_R (0x861D4) -#define CNENSET PIC32_R (0x861D8) -#define CNENINV PIC32_R (0x861DC) -#define CNPUE PIC32_R (0x861E0) /* Input pin pull-up enable */ -#define CNPUECLR PIC32_R (0x861E4) -#define CNPUESET PIC32_R (0x861E8) -#define CNPUEINV PIC32_R (0x861EC) +#define CNCON PIC32_R (0x861C0) /* Interrupt-on-change control */ +#define CNCONCLR PIC32_R (0x861C4) +#define CNCONSET PIC32_R (0x861C8) +#define CNCONINV PIC32_R (0x861CC) +#define CNEN PIC32_R (0x861D0) /* Input change interrupt enable */ +#define CNENCLR PIC32_R (0x861D4) +#define CNENSET PIC32_R (0x861D8) +#define CNENINV PIC32_R (0x861DC) +#define CNPUE PIC32_R (0x861E0) /* Input pin pull-up enable */ +#define CNPUECLR PIC32_R (0x861E4) +#define CNPUESET PIC32_R (0x861E8) +#define CNPUEINV PIC32_R (0x861EC) /*-------------------------------------- * A/D Converter registers. */ -#define AD1CON1 PIC32_R (0x9000) /* Control register 1 */ -#define AD1CON1CLR PIC32_R (0x9004) -#define AD1CON1SET PIC32_R (0x9008) -#define AD1CON1INV PIC32_R (0x900C) -#define AD1CON2 PIC32_R (0x9010) /* Control register 2 */ -#define AD1CON2CLR PIC32_R (0x9014) -#define AD1CON2SET PIC32_R (0x9018) -#define AD1CON2INV PIC32_R (0x901C) -#define AD1CON3 PIC32_R (0x9020) /* Control register 3 */ -#define AD1CON3CLR PIC32_R (0x9024) -#define AD1CON3SET PIC32_R (0x9028) -#define AD1CON3INV PIC32_R (0x902C) -#define AD1CHS PIC32_R (0x9040) /* Channel select */ -#define AD1CHSCLR PIC32_R (0x9044) -#define AD1CHSSET PIC32_R (0x9048) -#define AD1CHSINV PIC32_R (0x904C) -#define AD1CSSL PIC32_R (0x9050) /* Input scan selection */ -#define AD1CSSLCLR PIC32_R (0x9054) -#define AD1CSSLSET PIC32_R (0x9058) -#define AD1CSSLINV PIC32_R (0x905C) -#define AD1PCFG PIC32_R (0x9060) /* Port configuration */ -#define AD1PCFGCLR PIC32_R (0x9064) -#define AD1PCFGSET PIC32_R (0x9068) -#define AD1PCFGINV PIC32_R (0x906C) -#define ADC1BUF0 PIC32_R (0x9070) /* Result words */ -#define ADC1BUF1 PIC32_R (0x9080) -#define ADC1BUF2 PIC32_R (0x9090) -#define ADC1BUF3 PIC32_R (0x90A0) -#define ADC1BUF4 PIC32_R (0x90B0) -#define ADC1BUF5 PIC32_R (0x90C0) -#define ADC1BUF6 PIC32_R (0x90D0) -#define ADC1BUF7 PIC32_R (0x90E0) -#define ADC1BUF8 PIC32_R (0x90F0) -#define ADC1BUF9 PIC32_R (0x9100) -#define ADC1BUFA PIC32_R (0x9110) -#define ADC1BUFB PIC32_R (0x9120) -#define ADC1BUFC PIC32_R (0x9130) -#define ADC1BUFD PIC32_R (0x9140) -#define ADC1BUFE PIC32_R (0x9150) -#define ADC1BUFF PIC32_R (0x9160) +#define AD1CON1 PIC32_R (0x9000) /* Control register 1 */ +#define AD1CON1CLR PIC32_R (0x9004) +#define AD1CON1SET PIC32_R (0x9008) +#define AD1CON1INV PIC32_R (0x900C) +#define AD1CON2 PIC32_R (0x9010) /* Control register 2 */ +#define AD1CON2CLR PIC32_R (0x9014) +#define AD1CON2SET PIC32_R (0x9018) +#define AD1CON2INV PIC32_R (0x901C) +#define AD1CON3 PIC32_R (0x9020) /* Control register 3 */ +#define AD1CON3CLR PIC32_R (0x9024) +#define AD1CON3SET PIC32_R (0x9028) +#define AD1CON3INV PIC32_R (0x902C) +#define AD1CHS PIC32_R (0x9040) /* Channel select */ +#define AD1CHSCLR PIC32_R (0x9044) +#define AD1CHSSET PIC32_R (0x9048) +#define AD1CHSINV PIC32_R (0x904C) +#define AD1CSSL PIC32_R (0x9050) /* Input scan selection */ +#define AD1CSSLCLR PIC32_R (0x9054) +#define AD1CSSLSET PIC32_R (0x9058) +#define AD1CSSLINV PIC32_R (0x905C) +#define AD1PCFG PIC32_R (0x9060) /* Port configuration */ +#define AD1PCFGCLR PIC32_R (0x9064) +#define AD1PCFGSET PIC32_R (0x9068) +#define AD1PCFGINV PIC32_R (0x906C) +#define ADC1BUF0 PIC32_R (0x9070) /* Result words */ +#define ADC1BUF1 PIC32_R (0x9080) +#define ADC1BUF2 PIC32_R (0x9090) +#define ADC1BUF3 PIC32_R (0x90A0) +#define ADC1BUF4 PIC32_R (0x90B0) +#define ADC1BUF5 PIC32_R (0x90C0) +#define ADC1BUF6 PIC32_R (0x90D0) +#define ADC1BUF7 PIC32_R (0x90E0) +#define ADC1BUF8 PIC32_R (0x90F0) +#define ADC1BUF9 PIC32_R (0x9100) +#define ADC1BUFA PIC32_R (0x9110) +#define ADC1BUFB PIC32_R (0x9120) +#define ADC1BUFC PIC32_R (0x9130) +#define ADC1BUFD PIC32_R (0x9140) +#define ADC1BUFE PIC32_R (0x9150) +#define ADC1BUFF PIC32_R (0x9160) /*-------------------------------------- * Parallel master port registers. */ -#define PMCON PIC32_R (0x7000) /* Control */ -#define PMCONCLR PIC32_R (0x7004) -#define PMCONSET PIC32_R (0x7008) -#define PMCONINV PIC32_R (0x700C) -#define PMMODE PIC32_R (0x7010) /* Mode */ -#define PMMODECLR PIC32_R (0x7014) -#define PMMODESET PIC32_R (0x7018) -#define PMMODEINV PIC32_R (0x701C) -#define PMADDR PIC32_R (0x7020) /* Address */ -#define PMADDRCLR PIC32_R (0x7024) -#define PMADDRSET PIC32_R (0x7028) -#define PMADDRINV PIC32_R (0x702C) -#define PMDOUT PIC32_R (0x7030) /* Data output */ -#define PMDOUTCLR PIC32_R (0x7034) -#define PMDOUTSET PIC32_R (0x7038) -#define PMDOUTINV PIC32_R (0x703C) -#define PMDIN PIC32_R (0x7040) /* Data input */ -#define PMDINCLR PIC32_R (0x7044) -#define PMDINSET PIC32_R (0x7048) -#define PMDININV PIC32_R (0x704C) -#define PMAEN PIC32_R (0x7050) /* Pin enable */ -#define PMAENCLR PIC32_R (0x7054) -#define PMAENSET PIC32_R (0x7058) -#define PMAENINV PIC32_R (0x705C) -#define PMSTAT PIC32_R (0x7060) /* Status (slave only) */ -#define PMSTATCLR PIC32_R (0x7064) -#define PMSTATSET PIC32_R (0x7068) -#define PMSTATINV PIC32_R (0x706C) +#define PMCON PIC32_R (0x7000) /* Control */ +#define PMCONCLR PIC32_R (0x7004) +#define PMCONSET PIC32_R (0x7008) +#define PMCONINV PIC32_R (0x700C) +#define PMMODE PIC32_R (0x7010) /* Mode */ +#define PMMODECLR PIC32_R (0x7014) +#define PMMODESET PIC32_R (0x7018) +#define PMMODEINV PIC32_R (0x701C) +#define PMADDR PIC32_R (0x7020) /* Address */ +#define PMADDRCLR PIC32_R (0x7024) +#define PMADDRSET PIC32_R (0x7028) +#define PMADDRINV PIC32_R (0x702C) +#define PMDOUT PIC32_R (0x7030) /* Data output */ +#define PMDOUTCLR PIC32_R (0x7034) +#define PMDOUTSET PIC32_R (0x7038) +#define PMDOUTINV PIC32_R (0x703C) +#define PMDIN PIC32_R (0x7040) /* Data input */ +#define PMDINCLR PIC32_R (0x7044) +#define PMDINSET PIC32_R (0x7048) +#define PMDININV PIC32_R (0x704C) +#define PMAEN PIC32_R (0x7050) /* Pin enable */ +#define PMAENCLR PIC32_R (0x7054) +#define PMAENSET PIC32_R (0x7058) +#define PMAENINV PIC32_R (0x705C) +#define PMSTAT PIC32_R (0x7060) /* Status (slave only) */ +#define PMSTATCLR PIC32_R (0x7064) +#define PMSTATSET PIC32_R (0x7068) +#define PMSTATINV PIC32_R (0x706C) /* * PMP Control register. */ -#define PIC32_PMCON_RDSP 0x0001 /* Read strobe polarity active-high */ -#define PIC32_PMCON_WRSP 0x0002 /* Write strobe polarity active-high */ -#define PIC32_PMCON_CS1P 0x0008 /* Chip select 0 polarity active-high */ -#define PIC32_PMCON_CS2P 0x0010 /* Chip select 1 polarity active-high */ -#define PIC32_PMCON_ALP 0x0020 /* Address latch polarity active-high */ -#define PIC32_PMCON_CSF 0x00C0 /* Chip select function bitmask: */ -#define PIC32_PMCON_CSF_NONE 0x0000 /* PMCS2 and PMCS1 as A[15:14] */ -#define PIC32_PMCON_CSF_CS2 0x0040 /* PMCS2 as chip select */ -#define PIC32_PMCON_CSF_CS21 0x0080 /* PMCS2 and PMCS1 as chip select */ -#define PIC32_PMCON_PTRDEN 0x0100 /* Read/write strobe port enable */ -#define PIC32_PMCON_PTWREN 0x0200 /* Write enable strobe port enable */ -#define PIC32_PMCON_PMPTTL 0x0400 /* TTL input buffer select */ -#define PIC32_PMCON_ADRMUX 0x1800 /* Address/data mux selection bitmask: */ -#define PIC32_PMCON_ADRMUX_NONE 0x0000 /* Address and data separate */ -#define PIC32_PMCON_ADRMUX_AD 0x0800 /* Lower address on PMD[7:0], high on PMA[15:8] */ -#define PIC32_PMCON_ADRMUX_D8 0x1000 /* All address on PMD[7:0] */ -#define PIC32_PMCON_ADRMUX_D16 0x1800 /* All address on PMD[15:0] */ -#define PIC32_PMCON_SIDL 0x2000 /* Stop in idle */ -#define PIC32_PMCON_FRZ 0x4000 /* Freeze in debug exception */ -#define PIC32_PMCON_ON 0x8000 /* Parallel master port enable */ +#define PIC32_PMCON_RDSP 0x0001 /* Read strobe polarity active-high */ +#define PIC32_PMCON_WRSP 0x0002 /* Write strobe polarity active-high */ +#define PIC32_PMCON_CS1P 0x0008 /* Chip select 0 polarity active-high */ +#define PIC32_PMCON_CS2P 0x0010 /* Chip select 1 polarity active-high */ +#define PIC32_PMCON_ALP 0x0020 /* Address latch polarity active-high */ +#define PIC32_PMCON_CSF 0x00C0 /* Chip select function bitmask: */ +#define PIC32_PMCON_CSF_NONE 0x0000 /* PMCS2 and PMCS1 as A[15:14] */ +#define PIC32_PMCON_CSF_CS2 0x0040 /* PMCS2 as chip select */ +#define PIC32_PMCON_CSF_CS21 0x0080 /* PMCS2 and PMCS1 as chip select */ +#define PIC32_PMCON_PTRDEN 0x0100 /* Read/write strobe port enable */ +#define PIC32_PMCON_PTWREN 0x0200 /* Write enable strobe port enable */ +#define PIC32_PMCON_PMPTTL 0x0400 /* TTL input buffer select */ +#define PIC32_PMCON_ADRMUX 0x1800 /* Address/data mux selection bitmask: */ +#define PIC32_PMCON_ADRMUX_NONE 0x0000 /* Address and data separate */ +#define PIC32_PMCON_ADRMUX_AD 0x0800 /* Lower address on PMD[7:0], high on PMA[15:8] */ +#define PIC32_PMCON_ADRMUX_D8 0x1000 /* All address on PMD[7:0] */ +#define PIC32_PMCON_ADRMUX_D16 0x1800 /* All address on PMD[15:0] */ +#define PIC32_PMCON_SIDL 0x2000 /* Stop in idle */ +#define PIC32_PMCON_FRZ 0x4000 /* Freeze in debug exception */ +#define PIC32_PMCON_ON 0x8000 /* Parallel master port enable */ /* * PMP Mode register. */ -#define PIC32_PMMODE_WAITE(x) ((x)<<0) /* Wait states: data hold after RW strobe */ -#define PIC32_PMMODE_WAITM(x) ((x)<<2) /* Wait states: data RW strobe */ -#define PIC32_PMMODE_WAITB(x) ((x)<<6) /* Wait states: data setup to RW strobe */ -#define PIC32_PMMODE_MODE 0x0300 /* Mode select bitmask: */ -#define PIC32_PMMODE_MODE_SLAVE 0x0000 /* Legacy slave */ -#define PIC32_PMMODE_MODE_SLENH 0x0100 /* Enhanced slave */ -#define PIC32_PMMODE_MODE_MAST2 0x0200 /* Master mode 2 */ -#define PIC32_PMMODE_MODE_MAST1 0x0300 /* Master mode 1 */ -#define PIC32_PMMODE_MODE16 0x0400 /* 16-bit mode */ -#define PIC32_PMMODE_INCM 0x1800 /* Address increment mode bitmask: */ -#define PIC32_PMMODE_INCM_NONE 0x0000 /* No increment/decrement */ -#define PIC32_PMMODE_INCM_INC 0x0800 /* Increment address */ -#define PIC32_PMMODE_INCM_DEC 0x1000 /* Decrement address */ -#define PIC32_PMMODE_INCM_SLAVE 0x1800 /* Slave auto-increment */ -#define PIC32_PMMODE_IRQM 0x6000 /* Interrupt request bitmask: */ -#define PIC32_PMMODE_IRQM_DIS 0x0000 /* No interrupt generated */ -#define PIC32_PMMODE_IRQM_END 0x2000 /* Interrupt at end of read/write cycle */ -#define PIC32_PMMODE_IRQM_A3 0x4000 /* Interrupt on address 3 */ -#define PIC32_PMMODE_BUSY 0x8000 /* Port is busy */ +#define PIC32_PMMODE_WAITE(x) ((x)<<0) /* Wait states: data hold after RW strobe */ +#define PIC32_PMMODE_WAITM(x) ((x)<<2) /* Wait states: data RW strobe */ +#define PIC32_PMMODE_WAITB(x) ((x)<<6) /* Wait states: data setup to RW strobe */ +#define PIC32_PMMODE_MODE 0x0300 /* Mode select bitmask: */ +#define PIC32_PMMODE_MODE_SLAVE 0x0000 /* Legacy slave */ +#define PIC32_PMMODE_MODE_SLENH 0x0100 /* Enhanced slave */ +#define PIC32_PMMODE_MODE_MAST2 0x0200 /* Master mode 2 */ +#define PIC32_PMMODE_MODE_MAST1 0x0300 /* Master mode 1 */ +#define PIC32_PMMODE_MODE16 0x0400 /* 16-bit mode */ +#define PIC32_PMMODE_INCM 0x1800 /* Address increment mode bitmask: */ +#define PIC32_PMMODE_INCM_NONE 0x0000 /* No increment/decrement */ +#define PIC32_PMMODE_INCM_INC 0x0800 /* Increment address */ +#define PIC32_PMMODE_INCM_DEC 0x1000 /* Decrement address */ +#define PIC32_PMMODE_INCM_SLAVE 0x1800 /* Slave auto-increment */ +#define PIC32_PMMODE_IRQM 0x6000 /* Interrupt request bitmask: */ +#define PIC32_PMMODE_IRQM_DIS 0x0000 /* No interrupt generated */ +#define PIC32_PMMODE_IRQM_END 0x2000 /* Interrupt at end of read/write cycle */ +#define PIC32_PMMODE_IRQM_A3 0x4000 /* Interrupt on address 3 */ +#define PIC32_PMMODE_BUSY 0x8000 /* Port is busy */ /* * PMP Address register. */ -#define PIC32_PMADDR_PADDR 0x3FFF /* Destination address */ -#define PIC32_PMADDR_CS1 0x4000 /* Chip select 1 is active */ -#define PIC32_PMADDR_CS2 0x8000 /* Chip select 2 is active */ +#define PIC32_PMADDR_PADDR 0x3FFF /* Destination address */ +#define PIC32_PMADDR_CS1 0x4000 /* Chip select 1 is active */ +#define PIC32_PMADDR_CS2 0x8000 /* Chip select 2 is active */ /* * PMP status register (slave only). */ -#define PIC32_PMSTAT_OB0E 0x0001 /* Output buffer 0 empty */ -#define PIC32_PMSTAT_OB1E 0x0002 /* Output buffer 1 empty */ -#define PIC32_PMSTAT_OB2E 0x0004 /* Output buffer 2 empty */ -#define PIC32_PMSTAT_OB3E 0x0008 /* Output buffer 3 empty */ -#define PIC32_PMSTAT_OBUF 0x0040 /* Output buffer underflow */ -#define PIC32_PMSTAT_OBE 0x0080 /* Output buffer empty */ -#define PIC32_PMSTAT_IB0F 0x0100 /* Input buffer 0 full */ -#define PIC32_PMSTAT_IB1F 0x0200 /* Input buffer 1 full */ -#define PIC32_PMSTAT_IB2F 0x0400 /* Input buffer 2 full */ -#define PIC32_PMSTAT_IB3F 0x0800 /* Input buffer 3 full */ -#define PIC32_PMSTAT_IBOV 0x4000 /* Input buffer overflow */ -#define PIC32_PMSTAT_IBF 0x8000 /* Input buffer full */ +#define PIC32_PMSTAT_OB0E 0x0001 /* Output buffer 0 empty */ +#define PIC32_PMSTAT_OB1E 0x0002 /* Output buffer 1 empty */ +#define PIC32_PMSTAT_OB2E 0x0004 /* Output buffer 2 empty */ +#define PIC32_PMSTAT_OB3E 0x0008 /* Output buffer 3 empty */ +#define PIC32_PMSTAT_OBUF 0x0040 /* Output buffer underflow */ +#define PIC32_PMSTAT_OBE 0x0080 /* Output buffer empty */ +#define PIC32_PMSTAT_IB0F 0x0100 /* Input buffer 0 full */ +#define PIC32_PMSTAT_IB1F 0x0200 /* Input buffer 1 full */ +#define PIC32_PMSTAT_IB2F 0x0400 /* Input buffer 2 full */ +#define PIC32_PMSTAT_IB3F 0x0800 /* Input buffer 3 full */ +#define PIC32_PMSTAT_IBOV 0x4000 /* Input buffer overflow */ +#define PIC32_PMSTAT_IBF 0x8000 /* Input buffer full */ /*-------------------------------------- * USB registers. */ -#define U1OTGIR PIC32_R (0x85040) /* OTG interrupt flags */ -#define U1OTGIE PIC32_R (0x85050) /* OTG interrupt enable */ -#define U1OTGSTAT PIC32_R (0x85060) /* Comparator and pin status */ -#define U1OTGCON PIC32_R (0x85070) /* Resistor and pin control */ -#define U1PWRC PIC32_R (0x85080) /* Power control */ -#define U1IR PIC32_R (0x85200) /* Pending interrupt */ -#define U1IE PIC32_R (0x85210) /* Interrupt enable */ -#define U1EIR PIC32_R (0x85220) /* Pending error interrupt */ -#define U1EIE PIC32_R (0x85230) /* Error interrupt enable */ -#define U1STAT PIC32_R (0x85240) /* Status FIFO */ -#define U1CON PIC32_R (0x85250) /* Control */ -#define U1ADDR PIC32_R (0x85260) /* Address */ -#define U1BDTP1 PIC32_R (0x85270) /* Buffer descriptor table pointer 1 */ -#define U1FRML PIC32_R (0x85280) /* Frame counter low */ -#define U1FRMH PIC32_R (0x85290) /* Frame counter high */ -#define U1TOK PIC32_R (0x852A0) /* Host control */ -#define U1SOF PIC32_R (0x852B0) /* SOF counter */ -#define U1BDTP2 PIC32_R (0x852C0) /* Buffer descriptor table pointer 2 */ -#define U1BDTP3 PIC32_R (0x852D0) /* Buffer descriptor table pointer 3 */ -#define U1CNFG1 PIC32_R (0x852E0) /* Debug and idle */ -#define U1EP(n) PIC32_R (0x85300 + (n << 4)) /* Endpoint control */ +#define U1OTGIR PIC32_R (0x85040) /* OTG interrupt flags */ +#define U1OTGIE PIC32_R (0x85050) /* OTG interrupt enable */ +#define U1OTGSTAT PIC32_R (0x85060) /* Comparator and pin status */ +#define U1OTGCON PIC32_R (0x85070) /* Resistor and pin control */ +#define U1PWRC PIC32_R (0x85080) /* Power control */ +#define U1IR PIC32_R (0x85200) /* Pending interrupt */ +#define U1IE PIC32_R (0x85210) /* Interrupt enable */ +#define U1EIR PIC32_R (0x85220) /* Pending error interrupt */ +#define U1EIE PIC32_R (0x85230) /* Error interrupt enable */ +#define U1STAT PIC32_R (0x85240) /* Status FIFO */ +#define U1CON PIC32_R (0x85250) /* Control */ +#define U1ADDR PIC32_R (0x85260) /* Address */ +#define U1BDTP1 PIC32_R (0x85270) /* Buffer descriptor table pointer 1 */ +#define U1FRML PIC32_R (0x85280) /* Frame counter low */ +#define U1FRMH PIC32_R (0x85290) /* Frame counter high */ +#define U1TOK PIC32_R (0x852A0) /* Host control */ +#define U1SOF PIC32_R (0x852B0) /* SOF counter */ +#define U1BDTP2 PIC32_R (0x852C0) /* Buffer descriptor table pointer 2 */ +#define U1BDTP3 PIC32_R (0x852D0) /* Buffer descriptor table pointer 3 */ +#define U1CNFG1 PIC32_R (0x852E0) /* Debug and idle */ +#define U1EP(n) PIC32_R (0x85300 + (n << 4)) /* Endpoint control */ /* * USB Control register. */ -#define PIC32_U1CON_USBEN 0x0001 /* USB module enable (device mode) */ -#define PIC32_U1CON_SOFEN 0x0001 /* SOF sent every 1 ms (host mode) */ -#define PIC32_U1CON_PPBRST 0x0002 /* Ping-pong buffers reset */ -#define PIC32_U1CON_RESUME 0x0004 /* Resume signaling enable */ -#define PIC32_U1CON_HOSTEN 0x0008 /* Host mode enable */ -#define PIC32_U1CON_USBRST 0x0010 /* USB reset */ -#define PIC32_U1CON_PKTDIS 0x0020 /* Packet transfer disable */ -#define PIC32_U1CON_TOKBUSY 0x0020 /* Token busy indicator */ -#define PIC32_U1CON_SE0 0x0040 /* Single ended zero detected */ -#define PIC32_U1CON_JSTATE 0x0080 /* Live differential receiver JSTATE flag */ +#define PIC32_U1CON_USBEN 0x0001 /* USB module enable (device mode) */ +#define PIC32_U1CON_SOFEN 0x0001 /* SOF sent every 1 ms (host mode) */ +#define PIC32_U1CON_PPBRST 0x0002 /* Ping-pong buffers reset */ +#define PIC32_U1CON_RESUME 0x0004 /* Resume signaling enable */ +#define PIC32_U1CON_HOSTEN 0x0008 /* Host mode enable */ +#define PIC32_U1CON_USBRST 0x0010 /* USB reset */ +#define PIC32_U1CON_PKTDIS 0x0020 /* Packet transfer disable */ +#define PIC32_U1CON_TOKBUSY 0x0020 /* Token busy indicator */ +#define PIC32_U1CON_SE0 0x0040 /* Single ended zero detected */ +#define PIC32_U1CON_JSTATE 0x0080 /* Live differential receiver JSTATE flag */ /* * USB Power control register. */ -#define PIC32_U1PWRC_USBPWR 0x0001 /* USB operation enable */ -#define PIC32_U1PWRC_USUSPEND 0x0002 /* USB suspend mode */ -#define PIC32_U1PWRC_USLPGRD 0x0010 /* USB sleep entry guard */ -#define PIC32_U1PWRC_UACTPND 0x0080 /* UAB activity pending */ +#define PIC32_U1PWRC_USBPWR 0x0001 /* USB operation enable */ +#define PIC32_U1PWRC_USUSPEND 0x0002 /* USB suspend mode */ +#define PIC32_U1PWRC_USLPGRD 0x0010 /* USB sleep entry guard */ +#define PIC32_U1PWRC_UACTPND 0x0080 /* UAB activity pending */ /* * USB Pending interrupt register. * USB Interrupt enable register. */ -#define PIC32_U1I_DETACH 0x0001 /* Detach (host mode) */ -#define PIC32_U1I_URST 0x0001 /* USB reset (device mode) */ -#define PIC32_U1I_UERR 0x0002 /* USB error condition */ -#define PIC32_U1I_SOF 0x0004 /* SOF token */ -#define PIC32_U1I_TRN 0x0008 /* Token processing complete */ -#define PIC32_U1I_IDLE 0x0010 /* Idle detect */ -#define PIC32_U1I_RESUME 0x0020 /* Resume */ -#define PIC32_U1I_ATTACH 0x0040 /* Peripheral attach */ -#define PIC32_U1I_STALL 0x0080 /* STALL handshake */ +#define PIC32_U1I_DETACH 0x0001 /* Detach (host mode) */ +#define PIC32_U1I_URST 0x0001 /* USB reset (device mode) */ +#define PIC32_U1I_UERR 0x0002 /* USB error condition */ +#define PIC32_U1I_SOF 0x0004 /* SOF token */ +#define PIC32_U1I_TRN 0x0008 /* Token processing complete */ +#define PIC32_U1I_IDLE 0x0010 /* Idle detect */ +#define PIC32_U1I_RESUME 0x0020 /* Resume */ +#define PIC32_U1I_ATTACH 0x0040 /* Peripheral attach */ +#define PIC32_U1I_STALL 0x0080 /* STALL handshake */ /* * USB OTG interrupt flags register. * USB OTG interrupt enable register. */ -#define PIC32_U1OTGI_VBUSVD 0x0001 /* A-device Vbus change */ -#define PIC32_U1OTGI_SESEND 0x0004 /* B-device Vbus change */ -#define PIC32_U1OTGI_SESVD 0x0008 /* Session valid change */ -#define PIC32_U1OTGI_ACTV 0x0010 /* Bus activity indicator */ -#define PIC32_U1OTGI_LSTATE 0x0020 /* Line state stable */ -#define PIC32_U1OTGI_T1MSEC 0x0040 /* 1 millisecond timer expired */ -#define PIC32_U1OTGI_ID 0x0080 /* ID state change */ +#define PIC32_U1OTGI_VBUSVD 0x0001 /* A-device Vbus change */ +#define PIC32_U1OTGI_SESEND 0x0004 /* B-device Vbus change */ +#define PIC32_U1OTGI_SESVD 0x0008 /* Session valid change */ +#define PIC32_U1OTGI_ACTV 0x0010 /* Bus activity indicator */ +#define PIC32_U1OTGI_LSTATE 0x0020 /* Line state stable */ +#define PIC32_U1OTGI_T1MSEC 0x0040 /* 1 millisecond timer expired */ +#define PIC32_U1OTGI_ID 0x0080 /* ID state change */ -#define PIC32_U1OTGSTAT_VBUSVD 0x0001 /* */ -#define PIC32_U1OTGSTAT_SESEND 0x0004 /* */ -#define PIC32_U1OTGSTAT_SESVD 0x0008 /* */ -#define PIC32_U1OTGSTAT_LSTATE 0x0020 /* */ -#define PIC32_U1OTGSTAT_ID 0x0080 /* */ +#define PIC32_U1OTGSTAT_VBUSVD 0x0001 /* */ +#define PIC32_U1OTGSTAT_SESEND 0x0004 /* */ +#define PIC32_U1OTGSTAT_SESVD 0x0008 /* */ +#define PIC32_U1OTGSTAT_LSTATE 0x0020 /* */ +#define PIC32_U1OTGSTAT_ID 0x0080 /* */ -#define PIC32_U1OTGCON_VBUSDIS 0x0001 /* */ -#define PIC32_U1OTGCON_VBUSCHG 0x0002 /* */ -#define PIC32_U1OTGCON_OTGEN 0x0004 /* */ -#define PIC32_U1OTGCON_VBUSON 0x0008 /* */ -#define PIC32_U1OTGCON_DMPULDWN 0x0010 /* */ -#define PIC32_U1OTGCON_DPPULDWN 0x0020 /* */ -#define PIC32_U1OTGCON_DMPULUP 0x0040 /* */ -#define PIC32_U1OTGCON_DPPULUP 0x0080 /* */ +#define PIC32_U1OTGCON_VBUSDIS 0x0001 /* */ +#define PIC32_U1OTGCON_VBUSCHG 0x0002 /* */ +#define PIC32_U1OTGCON_OTGEN 0x0004 /* */ +#define PIC32_U1OTGCON_VBUSON 0x0008 /* */ +#define PIC32_U1OTGCON_DMPULDWN 0x0010 /* */ +#define PIC32_U1OTGCON_DPPULDWN 0x0020 /* */ +#define PIC32_U1OTGCON_DMPULUP 0x0040 /* */ +#define PIC32_U1OTGCON_DPPULUP 0x0080 /* */ -#define PIC32_U1EI_PID 0x0001 /* */ -#define PIC32_U1EI_CRC5 0x0002 /* */ -#define PIC32_U1EI_EOF 0x0002 /* */ -#define PIC32_U1EI_CRC16 0x0004 /* */ -#define PIC32_U1EI_DFN8 0x0008 /* */ -#define PIC32_U1EI_BTO 0x0010 /* */ -#define PIC32_U1EI_DMA 0x0020 /* */ -#define PIC32_U1EI_BMX 0x0040 /* */ -#define PIC32_U1EI_BTS 0x0080 /* */ +#define PIC32_U1EI_PID 0x0001 /* */ +#define PIC32_U1EI_CRC5 0x0002 /* */ +#define PIC32_U1EI_EOF 0x0002 /* */ +#define PIC32_U1EI_CRC16 0x0004 /* */ +#define PIC32_U1EI_DFN8 0x0008 /* */ +#define PIC32_U1EI_BTO 0x0010 /* */ +#define PIC32_U1EI_DMA 0x0020 /* */ +#define PIC32_U1EI_BMX 0x0040 /* */ +#define PIC32_U1EI_BTS 0x0080 /* */ -#define PIC32_U1STAT_PPBI 0x0004 /* */ -#define PIC32_U1STAT_DIR 0x0008 /* */ -#define PIC32_U1STAT_ENDPT(x) (((x) >> 4) & 0xF) /* */ +#define PIC32_U1STAT_PPBI 0x0004 /* */ +#define PIC32_U1STAT_DIR 0x0008 /* */ +#define PIC32_U1STAT_ENDPT(x) (((x) >> 4) & 0xF) /* */ -#define PIC32_U1ADDR_DEVADDR 0x007F /* */ -#define PIC32_U1ADDR_USBADDR0 0x0001 /* */ -#define PIC32_U1ADDR_DEVADDR1 0x0002 /* */ -#define PIC32_U1ADDR_DEVADDR2 0x0004 /* */ -#define PIC32_U1ADDR_DEVADDR3 0x0008 /* */ -#define PIC32_U1ADDR_DEVADDR4 0x0010 /* */ -#define PIC32_U1ADDR_DEVADDR5 0x0020 /* */ -#define PIC32_U1ADDR_DEVADDR6 0x0040 /* */ -#define PIC32_U1ADDR_LSPDEN 0x0080 /* */ +#define PIC32_U1ADDR_DEVADDR 0x007F /* */ +#define PIC32_U1ADDR_USBADDR0 0x0001 /* */ +#define PIC32_U1ADDR_DEVADDR1 0x0002 /* */ +#define PIC32_U1ADDR_DEVADDR2 0x0004 /* */ +#define PIC32_U1ADDR_DEVADDR3 0x0008 /* */ +#define PIC32_U1ADDR_DEVADDR4 0x0010 /* */ +#define PIC32_U1ADDR_DEVADDR5 0x0020 /* */ +#define PIC32_U1ADDR_DEVADDR6 0x0040 /* */ +#define PIC32_U1ADDR_LSPDEN 0x0080 /* */ -#define PIC32_U1FRML_FRM0 0x0001 /* */ -#define PIC32_U1FRML_FRM1 0x0002 /* */ -#define PIC32_U1FRML_FRM2 0x0004 /* */ -#define PIC32_U1FRML_FRM3 0x0008 /* */ -#define PIC32_U1FRML_FRM4 0x0010 /* */ -#define PIC32_U1FRML_FRM5 0x0020 /* */ -#define PIC32_U1FRML_FRM6 0x0040 /* */ -#define PIC32_U1FRML_FRM7 0x0080 /* */ +#define PIC32_U1FRML_FRM0 0x0001 /* */ +#define PIC32_U1FRML_FRM1 0x0002 /* */ +#define PIC32_U1FRML_FRM2 0x0004 /* */ +#define PIC32_U1FRML_FRM3 0x0008 /* */ +#define PIC32_U1FRML_FRM4 0x0010 /* */ +#define PIC32_U1FRML_FRM5 0x0020 /* */ +#define PIC32_U1FRML_FRM6 0x0040 /* */ +#define PIC32_U1FRML_FRM7 0x0080 /* */ -#define PIC32_U1FRMH_FRM8 0x0001 /* */ -#define PIC32_U1FRMH_FRM9 0x0002 /* */ -#define PIC32_U1FRMH_FRM10 0x0004 /* */ +#define PIC32_U1FRMH_FRM8 0x0001 /* */ +#define PIC32_U1FRMH_FRM9 0x0002 /* */ +#define PIC32_U1FRMH_FRM10 0x0004 /* */ -#define PIC32_U1TOK_EP0 0x0001 /* */ -#define PIC32_U1TOK_EP 0x000F /* */ -#define PIC32_U1TOK_EP1 0x0002 /* */ -#define PIC32_U1TOK_EP2 0x0004 /* */ -#define PIC32_U1TOK_EP3 0x0008 /* */ -#define PIC32_U1TOK_PID0 0x0010 /* */ -#define PIC32_U1TOK_PID 0x00F0 /* */ -#define PIC32_U1TOK_PID1 0x0020 /* */ -#define PIC32_U1TOK_PID2 0x0040 /* */ -#define PIC32_U1TOK_PID3 0x0080 /* */ +#define PIC32_U1TOK_EP0 0x0001 /* */ +#define PIC32_U1TOK_EP 0x000F /* */ +#define PIC32_U1TOK_EP1 0x0002 /* */ +#define PIC32_U1TOK_EP2 0x0004 /* */ +#define PIC32_U1TOK_EP3 0x0008 /* */ +#define PIC32_U1TOK_PID0 0x0010 /* */ +#define PIC32_U1TOK_PID 0x00F0 /* */ +#define PIC32_U1TOK_PID1 0x0020 /* */ +#define PIC32_U1TOK_PID2 0x0040 /* */ +#define PIC32_U1TOK_PID3 0x0080 /* */ -#define PIC32_U1CNFG1_USBSIDL 0x0010 /* */ -#define PIC32_U1CNFG1_USBFRZ 0x0020 /* */ -#define PIC32_U1CNFG1_UOEMON 0x0040 /* */ -#define PIC32_U1CNFG1_UTEYE 0x0080 /* */ +#define PIC32_U1CNFG1_USBSIDL 0x0010 /* */ +#define PIC32_U1CNFG1_USBFRZ 0x0020 /* */ +#define PIC32_U1CNFG1_UOEMON 0x0040 /* */ +#define PIC32_U1CNFG1_UTEYE 0x0080 /* */ -#define PIC32_U1EP_EPHSHK 0x0001 /* */ -#define PIC32_U1EP_EPSTALL 0x0002 /* */ -#define PIC32_U1EP_EPTXEN 0x0004 /* */ -#define PIC32_U1EP_EPRXEN 0x0008 /* */ -#define PIC32_U1EP_EPCONDIS 0x0010 /* */ -#define PIC32_U1EP_RETRYDIS 0x0040 /* */ -#define PIC32_U1EP_LSPD 0x0080 /* */ +#define PIC32_U1EP_EPHSHK 0x0001 /* */ +#define PIC32_U1EP_EPSTALL 0x0002 /* */ +#define PIC32_U1EP_EPTXEN 0x0004 /* */ +#define PIC32_U1EP_EPRXEN 0x0008 /* */ +#define PIC32_U1EP_EPCONDIS 0x0010 /* */ +#define PIC32_U1EP_RETRYDIS 0x0040 /* */ +#define PIC32_U1EP_LSPD 0x0080 /* */ /* DB status field values */ -#define PIC32_DB_BSTALL (1 << 2) -#define PIC32_DB_DTS (1 << 3) -#define PIC32_DB_NINC (1 << 4) -#define PIC32_DB_KEEP (1 << 5) -#define PIC32_DB_DATA1 (1 << 6) -#define PIC32_DB_UOWN (1 << 7) -#define PIC32_DB_GET_PID(x) (((x) >> 2) & 0xF) -#define PIC32_DB_SET_PID(x) (((x) & 0xF) << 2) -#define PIC32_DB_GET_COUNT(x) (((x) >> 16) & 0x3FF) -#define PIC32_DB_SET_COUNT(x) (((x) & 0x3FF) << 16) +#define PIC32_DB_BSTALL (1 << 2) +#define PIC32_DB_DTS (1 << 3) +#define PIC32_DB_NINC (1 << 4) +#define PIC32_DB_KEEP (1 << 5) +#define PIC32_DB_DATA1 (1 << 6) +#define PIC32_DB_UOWN (1 << 7) +#define PIC32_DB_GET_PID(x) (((x) >> 2) & 0xF) +#define PIC32_DB_SET_PID(x) (((x) & 0xF) << 2) +#define PIC32_DB_GET_COUNT(x) (((x) >> 16) & 0x3FF) +#define PIC32_DB_SET_COUNT(x) (((x) & 0x3FF) << 16) /*-------------------------------------- * SPI registers. */ #ifdef PIC32MX4 -#define SPI1CON PIC32_R (0x5800) /* Control */ -#define SPI1CONCLR PIC32_R (0x5804) -#define SPI1CONSET PIC32_R (0x5808) -#define SPI1CONINV PIC32_R (0x580C) -#define SPI1STAT PIC32_R (0x5810) /* Status */ -#define SPI1STATCLR PIC32_R (0x5814) -#define SPI1STATSET PIC32_R (0x5818) -#define SPI1STATINV PIC32_R (0x581C) -#define SPI1BUF PIC32_R (0x5820) /* Transmit and receive buffer */ -#define SPI1BRG PIC32_R (0x5830) /* Baud rate generator */ -#define SPI1BRGCLR PIC32_R (0x5834) -#define SPI1BRGSET PIC32_R (0x5838) -#define SPI1BRGINV PIC32_R (0x583C) +#define SPI1CON PIC32_R (0x5800) /* Control */ +#define SPI1CONCLR PIC32_R (0x5804) +#define SPI1CONSET PIC32_R (0x5808) +#define SPI1CONINV PIC32_R (0x580C) +#define SPI1STAT PIC32_R (0x5810) /* Status */ +#define SPI1STATCLR PIC32_R (0x5814) +#define SPI1STATSET PIC32_R (0x5818) +#define SPI1STATINV PIC32_R (0x581C) +#define SPI1BUF PIC32_R (0x5820) /* Transmit and receive buffer */ +#define SPI1BRG PIC32_R (0x5830) /* Baud rate generator */ +#define SPI1BRGCLR PIC32_R (0x5834) +#define SPI1BRGSET PIC32_R (0x5838) +#define SPI1BRGINV PIC32_R (0x583C) #endif #ifdef PIC32MX7 -#define SPI3CON PIC32_R (0x5800) /* Control */ -#define SPI3CONCLR PIC32_R (0x5804) -#define SPI3CONSET PIC32_R (0x5808) -#define SPI3CONINV PIC32_R (0x580C) -#define SPI3STAT PIC32_R (0x5810) /* Status */ -#define SPI3STATCLR PIC32_R (0x5814) -#define SPI3STATSET PIC32_R (0x5818) -#define SPI3STATINV PIC32_R (0x581C) -#define SPI3BUF PIC32_R (0x5820) /* Transmit and receive buffer */ -#define SPI3BRG PIC32_R (0x5830) /* Baud rate generator */ -#define SPI3BRGCLR PIC32_R (0x5834) -#define SPI3BRGSET PIC32_R (0x5838) -#define SPI3BRGINV PIC32_R (0x583C) +#define SPI3CON PIC32_R (0x5800) /* Control */ +#define SPI3CONCLR PIC32_R (0x5804) +#define SPI3CONSET PIC32_R (0x5808) +#define SPI3CONINV PIC32_R (0x580C) +#define SPI3STAT PIC32_R (0x5810) /* Status */ +#define SPI3STATCLR PIC32_R (0x5814) +#define SPI3STATSET PIC32_R (0x5818) +#define SPI3STATINV PIC32_R (0x581C) +#define SPI3BUF PIC32_R (0x5820) /* Transmit and receive buffer */ +#define SPI3BRG PIC32_R (0x5830) /* Baud rate generator */ +#define SPI3BRGCLR PIC32_R (0x5834) +#define SPI3BRGSET PIC32_R (0x5838) +#define SPI3BRGINV PIC32_R (0x583C) -#define SPI4CON PIC32_R (0x5C00) /* Control */ -#define SPI4CONCLR PIC32_R (0x5C04) -#define SPI4CONSET PIC32_R (0x5C08) -#define SPI4CONINV PIC32_R (0x5C0C) -#define SPI4STAT PIC32_R (0x5C10) /* Status */ -#define SPI4STATCLR PIC32_R (0x5C14) -#define SPI4STATSET PIC32_R (0x5C18) -#define SPI4STATINV PIC32_R (0x5C1C) -#define SPI4BUF PIC32_R (0x5C20) /* Transmit and receive buffer */ -#define SPI4BRG PIC32_R (0x5C30) /* Baud rate generator */ -#define SPI4BRGCLR PIC32_R (0x5C34) -#define SPI4BRGSET PIC32_R (0x5C38) -#define SPI4BRGINV PIC32_R (0x5C3C) +#define SPI4CON PIC32_R (0x5C00) /* Control */ +#define SPI4CONCLR PIC32_R (0x5C04) +#define SPI4CONSET PIC32_R (0x5C08) +#define SPI4CONINV PIC32_R (0x5C0C) +#define SPI4STAT PIC32_R (0x5C10) /* Status */ +#define SPI4STATCLR PIC32_R (0x5C14) +#define SPI4STATSET PIC32_R (0x5C18) +#define SPI4STATINV PIC32_R (0x5C1C) +#define SPI4BUF PIC32_R (0x5C20) /* Transmit and receive buffer */ +#define SPI4BRG PIC32_R (0x5C30) /* Baud rate generator */ +#define SPI4BRGCLR PIC32_R (0x5C34) +#define SPI4BRGSET PIC32_R (0x5C38) +#define SPI4BRGINV PIC32_R (0x5C3C) -#define SPI1CON PIC32_R (0x5E00) /* Control */ -#define SPI1CONCLR PIC32_R (0x5E04) -#define SPI1CONSET PIC32_R (0x5E08) -#define SPI1CONINV PIC32_R (0x5E0C) -#define SPI1STAT PIC32_R (0x5E10) /* Status */ -#define SPI1STATCLR PIC32_R (0x5E14) -#define SPI1STATSET PIC32_R (0x5E18) -#define SPI1STATINV PIC32_R (0x5E1C) -#define SPI1BUF PIC32_R (0x5E20) /* Transmit and receive buffer */ -#define SPI1BRG PIC32_R (0x5E30) /* Baud rate generator */ -#define SPI1BRGCLR PIC32_R (0x5E34) -#define SPI1BRGSET PIC32_R (0x5E38) -#define SPI1BRGINV PIC32_R (0x5E3C) +#define SPI1CON PIC32_R (0x5E00) /* Control */ +#define SPI1CONCLR PIC32_R (0x5E04) +#define SPI1CONSET PIC32_R (0x5E08) +#define SPI1CONINV PIC32_R (0x5E0C) +#define SPI1STAT PIC32_R (0x5E10) /* Status */ +#define SPI1STATCLR PIC32_R (0x5E14) +#define SPI1STATSET PIC32_R (0x5E18) +#define SPI1STATINV PIC32_R (0x5E1C) +#define SPI1BUF PIC32_R (0x5E20) /* Transmit and receive buffer */ +#define SPI1BRG PIC32_R (0x5E30) /* Baud rate generator */ +#define SPI1BRGCLR PIC32_R (0x5E34) +#define SPI1BRGSET PIC32_R (0x5E38) +#define SPI1BRGINV PIC32_R (0x5E3C) #endif -#define SPI2CON PIC32_R (0x5A00) /* Control */ -#define SPI2CONCLR PIC32_R (0x5A04) -#define SPI2CONSET PIC32_R (0x5A08) -#define SPI2CONINV PIC32_R (0x5A0C) -#define SPI2STAT PIC32_R (0x5A10) /* Status */ -#define SPI2STATCLR PIC32_R (0x5A14) -#define SPI2STATSET PIC32_R (0x5A18) -#define SPI2STATINV PIC32_R (0x5A1C) -#define SPI2BUF PIC32_R (0x5A20) /* Transmit and receive buffer */ -#define SPI2BRG PIC32_R (0x5A30) /* Baud rate generator */ -#define SPI2BRGCLR PIC32_R (0x5A34) -#define SPI2BRGSET PIC32_R (0x5A38) -#define SPI2BRGINV PIC32_R (0x5A3C) +#define SPI2CON PIC32_R (0x5A00) /* Control */ +#define SPI2CONCLR PIC32_R (0x5A04) +#define SPI2CONSET PIC32_R (0x5A08) +#define SPI2CONINV PIC32_R (0x5A0C) +#define SPI2STAT PIC32_R (0x5A10) /* Status */ +#define SPI2STATCLR PIC32_R (0x5A14) +#define SPI2STATSET PIC32_R (0x5A18) +#define SPI2STATINV PIC32_R (0x5A1C) +#define SPI2BUF PIC32_R (0x5A20) /* Transmit and receive buffer */ +#define SPI2BRG PIC32_R (0x5A30) /* Baud rate generator */ +#define SPI2BRGCLR PIC32_R (0x5A34) +#define SPI2BRGSET PIC32_R (0x5A38) +#define SPI2BRGINV PIC32_R (0x5A3C) /* * SPI Control register. */ -#define PIC32_SPICON_MSTEN 0x00000020 /* Master mode */ -#define PIC32_SPICON_CKP 0x00000040 /* Idle clock is high level */ -#define PIC32_SPICON_SSEN 0x00000080 /* Slave mode: SSx pin enable */ -#define PIC32_SPICON_CKE 0x00000100 /* Output data changes on - * transition from active clock - * state to Idle clock state */ -#define PIC32_SPICON_SMP 0x00000200 /* Master mode: input data sampled - * at end of data output time. */ -#define PIC32_SPICON_MODE16 0x00000400 /* 16-bit data width */ -#define PIC32_SPICON_MODE32 0x00000800 /* 32-bit data width */ -#define PIC32_SPICON_DISSDO 0x00001000 /* SDOx pin is not used */ -#define PIC32_SPICON_SIDL 0x00002000 /* Stop in Idle mode */ -#define PIC32_SPICON_FRZ 0x00004000 /* Freeze in Debug mode */ -#define PIC32_SPICON_ON 0x00008000 /* SPI Peripheral is enabled */ -#define PIC32_SPICON_ENHBUF 0x00010000 /* Enhanced buffer enable */ -#define PIC32_SPICON_SPIFE 0x00020000 /* Frame synchronization pulse - * coincides with the first bit clock */ -#define PIC32_SPICON_FRMPOL 0x20000000 /* Frame pulse is active-high */ -#define PIC32_SPICON_FRMSYNC 0x40000000 /* Frame sync pulse input (Slave mode) */ -#define PIC32_SPICON_FRMEN 0x80000000 /* Framed SPI support */ +#define PIC32_SPICON_MSTEN 0x00000020 /* Master mode */ +#define PIC32_SPICON_CKP 0x00000040 /* Idle clock is high level */ +#define PIC32_SPICON_SSEN 0x00000080 /* Slave mode: SSx pin enable */ +#define PIC32_SPICON_CKE 0x00000100 /* Output data changes on + * transition from active clock + * state to Idle clock state */ +#define PIC32_SPICON_SMP 0x00000200 /* Master mode: input data sampled + * at end of data output time. */ +#define PIC32_SPICON_MODE16 0x00000400 /* 16-bit data width */ +#define PIC32_SPICON_MODE32 0x00000800 /* 32-bit data width */ +#define PIC32_SPICON_DISSDO 0x00001000 /* SDOx pin is not used */ +#define PIC32_SPICON_SIDL 0x00002000 /* Stop in Idle mode */ +#define PIC32_SPICON_FRZ 0x00004000 /* Freeze in Debug mode */ +#define PIC32_SPICON_ON 0x00008000 /* SPI Peripheral is enabled */ +#define PIC32_SPICON_ENHBUF 0x00010000 /* Enhanced buffer enable */ +#define PIC32_SPICON_SPIFE 0x00020000 /* Frame synchronization pulse + * coincides with the first bit clock */ +#define PIC32_SPICON_FRMPOL 0x20000000 /* Frame pulse is active-high */ +#define PIC32_SPICON_FRMSYNC 0x40000000 /* Frame sync pulse input (Slave mode) */ +#define PIC32_SPICON_FRMEN 0x80000000 /* Framed SPI support */ /* * SPI Status register. */ -#define PIC32_SPISTAT_SPIRBF 0x00000001 /* Receive buffer is full */ -#define PIC32_SPISTAT_SPITBF 0x00000002 /* Transmit buffer is full */ -#define PIC32_SPISTAT_SPITBE 0x00000008 /* Transmit buffer is empty */ +#define PIC32_SPISTAT_SPIRBF 0x00000001 /* Receive buffer is full */ +#define PIC32_SPISTAT_SPITBF 0x00000002 /* Transmit buffer is full */ +#define PIC32_SPISTAT_SPITBE 0x00000008 /* Transmit buffer is empty */ #define PIC32_SPISTAT_SPIRBE 0x00000020 /* Receive buffer is empty */ -#define PIC32_SPISTAT_SPIROV 0x00000040 /* Receive overflow flag */ -#define PIC32_SPISTAT_SPIBUSY 0x00000800 /* SPI is busy */ +#define PIC32_SPISTAT_SPIROV 0x00000040 /* Receive overflow flag */ +#define PIC32_SPISTAT_SPIBUSY 0x00000800 /* SPI is busy */ /*-------------------------------------- * DMA controller registers. */ #define DMACON PIC32_R (0x83000) /* DMA Control */ -#define DMACONCLR PIC32_R (0x83004) -#define DMACONSET PIC32_R (0x83008) -#define DMACONINV PIC32_R (0x8300C) +#define DMACONCLR PIC32_R (0x83004) +#define DMACONSET PIC32_R (0x83008) +#define DMACONINV PIC32_R (0x8300C) #define DMASTAT PIC32_R (0x83010) /* DMA Status */ #define DMAADDR PIC32_R (0x83020) /* DMA Address */ // TODO: other DMA registers. @@ -908,18 +908,18 @@ * Prefetch cache controller registers. */ #define CHECON PIC32_R (0x84000) /* Prefetch cache control */ -#define CHECONCLR PIC32_R (0x84004) -#define CHECONSET PIC32_R (0x84008) -#define CHECONINV PIC32_R (0x8400C) +#define CHECONCLR PIC32_R (0x84004) +#define CHECONSET PIC32_R (0x84008) +#define CHECONINV PIC32_R (0x8400C) // TODO: other prefetech registers /*-------------------------------------- * Bus matrix control registers. */ #define BMXCON PIC32_R (0x82000) /* Memory configuration */ -#define BMXCONCLR PIC32_R (0x82004) -#define BMXCONSET PIC32_R (0x82008) -#define BMXCONINV PIC32_R (0x8200C) +#define BMXCONCLR PIC32_R (0x82004) +#define BMXCONSET PIC32_R (0x82008) +#define BMXCONINV PIC32_R (0x8200C) #define BMXDKPBA PIC32_R (0x82010) /* Data RAM kernel program base address */ #define BMXDUDBA PIC32_R (0x82020) /* Data RAM user data base address */ #define BMXDUPBA PIC32_R (0x82030) /* Data RAM user program base address */ @@ -959,30 +959,30 @@ /* * Timer2 registers */ -#define T2CON PIC32_R (0x0800) -#define T2CONSET PIC32_R (0x0808) -#define TMR2 PIC32_R (0x0810) -#define PR2 PIC32_R (0x0820) +#define T2CON PIC32_R (0x0800) +#define T2CONSET PIC32_R (0x0808) +#define TMR2 PIC32_R (0x0810) +#define PR2 PIC32_R (0x0820) /* * Output compare registers */ -#define OC1CON PIC32_R (0x3000) -#define OC1R PIC32_R (0x3010) -#define OC1RS PIC32_R (0x3020) -#define OC4CON PIC32_R (0x3600) -#define OC4R PIC32_R (0x3610) -#define OC4RS PIC32_R (0x3620) +#define OC1CON PIC32_R (0x3000) +#define OC1R PIC32_R (0x3010) +#define OC1RS PIC32_R (0x3020) +#define OC4CON PIC32_R (0x3600) +#define OC4R PIC32_R (0x3610) +#define OC4RS PIC32_R (0x3620) #define BLRKEY *(volatile unsigned*)(0x80000000) /*-------------------------------------- * Configuration registers. */ -#define DEVCFG0 *(volatile unsigned*)0x9fc02ffc -#define DEVCFG1 *(volatile unsigned*)0x9fc02ff8 -#define DEVCFG2 *(volatile unsigned*)0x9fc02ff4 -#define DEVCFG3 *(volatile unsigned*)0x9fc02ff0 +#define DEVCFG0 *(volatile unsigned*)0x9fc02ffc +#define DEVCFG1 *(volatile unsigned*)0x9fc02ff8 +#define DEVCFG2 *(volatile unsigned*)0x9fc02ff4 +#define DEVCFG3 *(volatile unsigned*)0x9fc02ff0 #define PIC32_DEVCFG(cfg0, cfg1, cfg2, cfg3) \ asm (".section .config"); \ @@ -1123,59 +1123,59 @@ /*-------------------------------------- * Interrupt controller registers. */ -#define INTCON PIC32_R (0x81000) /* Interrupt Control */ -#define INTCONCLR PIC32_R (0x81004) -#define INTCONSET PIC32_R (0x81008) -#define INTCONINV PIC32_R (0x8100C) -#define INTSTAT PIC32_R (0x81010) /* Interrupt Status */ -#define IPTMR PIC32_R (0x81020) /* Temporal Proximity Timer */ -#define IPTMRCLR PIC32_R (0x81024) -#define IPTMRSET PIC32_R (0x81028) -#define IPTMRINV PIC32_R (0x8102C) -#define IFS(n) PIC32_R (0x81030+((n)<<4)) /* IFS(0..2) - Interrupt Flag Status */ -#define IFSCLR(n) PIC32_R (0x81034+((n)<<4)) -#define IFSSET(n) PIC32_R (0x81038+((n)<<4)) -#define IFSINV(n) PIC32_R (0x8103C+((n)<<4)) -#define IEC(n) PIC32_R (0x81060+((n)<<4)) /* IEC(0..2) - Interrupt Enable Control */ -#define IECCLR(n) PIC32_R (0x81064+((n)<<4)) -#define IECSET(n) PIC32_R (0x81068+((n)<<4)) -#define IECINV(n) PIC32_R (0x8106C+((n)<<4)) -#define IPC(n) PIC32_R (0x81090+((n)<<4)) /* IPC(0..12) - Interrupt Priority Control */ -#define IPCCLR(n) PIC32_R (0x81094+((n)<<4)) -#define IPCSET(n) PIC32_R (0x81098+((n)<<4)) -#define IPCINV(n) PIC32_R (0x8109C+((n)<<4)) +#define INTCON PIC32_R (0x81000) /* Interrupt Control */ +#define INTCONCLR PIC32_R (0x81004) +#define INTCONSET PIC32_R (0x81008) +#define INTCONINV PIC32_R (0x8100C) +#define INTSTAT PIC32_R (0x81010) /* Interrupt Status */ +#define IPTMR PIC32_R (0x81020) /* Temporal Proximity Timer */ +#define IPTMRCLR PIC32_R (0x81024) +#define IPTMRSET PIC32_R (0x81028) +#define IPTMRINV PIC32_R (0x8102C) +#define IFS(n) PIC32_R (0x81030+((n)<<4)) /* IFS(0..2) - Interrupt Flag Status */ +#define IFSCLR(n) PIC32_R (0x81034+((n)<<4)) +#define IFSSET(n) PIC32_R (0x81038+((n)<<4)) +#define IFSINV(n) PIC32_R (0x8103C+((n)<<4)) +#define IEC(n) PIC32_R (0x81060+((n)<<4)) /* IEC(0..2) - Interrupt Enable Control */ +#define IECCLR(n) PIC32_R (0x81064+((n)<<4)) +#define IECSET(n) PIC32_R (0x81068+((n)<<4)) +#define IECINV(n) PIC32_R (0x8106C+((n)<<4)) +#define IPC(n) PIC32_R (0x81090+((n)<<4)) /* IPC(0..12) - Interrupt Priority Control */ +#define IPCCLR(n) PIC32_R (0x81094+((n)<<4)) +#define IPCSET(n) PIC32_R (0x81098+((n)<<4)) +#define IPCINV(n) PIC32_R (0x8109C+((n)<<4)) /* * Interrupt Control register. */ -#define PIC32_INTCON_INT0EP 0x0001 /* External interrupt 0 polarity rising edge */ -#define PIC32_INTCON_INT1EP 0x0002 /* External interrupt 1 polarity rising edge */ -#define PIC32_INTCON_INT2EP 0x0004 /* External interrupt 2 polarity rising edge */ -#define PIC32_INTCON_INT3EP 0x0008 /* External interrupt 3 polarity rising edge */ -#define PIC32_INTCON_INT4EP 0x0010 /* External interrupt 4 polarity rising edge */ -#define PIC32_INTCON_TPC(x) ((x)<<8) /* Temporal proximity group priority */ -#define PIC32_INTCON_MVEC 0x1000 /* Multi-vectored mode */ -#define PIC32_INTCON_FRZ 0x4000 /* Freeze in debug mode */ -#define PIC32_INTCON_SS0 0x8000 /* Single vector has a shadow register set */ +#define PIC32_INTCON_INT0EP 0x0001 /* External interrupt 0 polarity rising edge */ +#define PIC32_INTCON_INT1EP 0x0002 /* External interrupt 1 polarity rising edge */ +#define PIC32_INTCON_INT2EP 0x0004 /* External interrupt 2 polarity rising edge */ +#define PIC32_INTCON_INT3EP 0x0008 /* External interrupt 3 polarity rising edge */ +#define PIC32_INTCON_INT4EP 0x0010 /* External interrupt 4 polarity rising edge */ +#define PIC32_INTCON_TPC(x) ((x)<<8) /* Temporal proximity group priority */ +#define PIC32_INTCON_MVEC 0x1000 /* Multi-vectored mode */ +#define PIC32_INTCON_FRZ 0x4000 /* Freeze in debug mode */ +#define PIC32_INTCON_SS0 0x8000 /* Single vector has a shadow register set */ /* * Interrupt Status register. */ -#define PIC32_INTSTAT_VEC(s) ((s) & 0xFF) /* Interrupt vector */ -#define PIC32_INTSTAT_SRIPL(s) ((s) >> 8 & 7) /* Requested priority level */ +#define PIC32_INTSTAT_VEC(s) ((s) & 0xFF) /* Interrupt vector */ +#define PIC32_INTSTAT_SRIPL(s) ((s) >> 8 & 7) /* Requested priority level */ #define PIC32_INTSTAT_SRIPL_MASK 0x0700 /* * Interrupt Prority Control register. */ -#define PIC32_IPC_IS0(x) (x) /* Interrupt 0 subpriority */ -#define PIC32_IPC_IP0(x) ((x)<<2) /* Interrupt 0 priority */ -#define PIC32_IPC_IS1(x) ((x)<<8) /* Interrupt 1 subpriority */ -#define PIC32_IPC_IP1(x) ((x)<<10) /* Interrupt 1 priority */ -#define PIC32_IPC_IS2(x) ((x)<<16) /* Interrupt 2 subpriority */ -#define PIC32_IPC_IP2(x) ((x)<<18) /* Interrupt 2 priority */ -#define PIC32_IPC_IS3(x) ((x)<<24) /* Interrupt 3 subpriority */ -#define PIC32_IPC_IP3(x) ((x)<<26) /* Interrupt 3 priority */ +#define PIC32_IPC_IS0(x) (x) /* Interrupt 0 subpriority */ +#define PIC32_IPC_IP0(x) ((x)<<2) /* Interrupt 0 priority */ +#define PIC32_IPC_IS1(x) ((x)<<8) /* Interrupt 1 subpriority */ +#define PIC32_IPC_IP1(x) ((x)<<10) /* Interrupt 1 priority */ +#define PIC32_IPC_IS2(x) ((x)<<16) /* Interrupt 2 subpriority */ +#define PIC32_IPC_IP2(x) ((x)<<18) /* Interrupt 2 priority */ +#define PIC32_IPC_IS3(x) ((x)<<24) /* Interrupt 3 subpriority */ +#define PIC32_IPC_IP3(x) ((x)<<26) /* Interrupt 3 priority */ /* * IRQ numbers for PIC32MX3xx/4xx/5xx/6xx/7xx diff --git a/sys/pic32/power_control.c b/sys/pic32/power_control.c index d956e31..2a379c5 100644 --- a/sys/pic32/power_control.c +++ b/sys/pic32/power_control.c @@ -18,12 +18,10 @@ void power_off() void power_switch_check() { - if(PORT_VAL(POWER_SWITCH_PORT) & (1<0) - { + if (PORT_VAL(POWER_SWITCH_PORT) & (1< 0) { LAT_SET(POWER_LED_PORT) = 1<- 1:1 prescale - _BC(T2CON,4); - _BC(T2CON,3); // 16 bit timer - _BC(T2CON,1); // Internal clock source - PR2 = 0xFFFF; - switch(unit) - { - case 0: - _BS(OC1CON,15); // ON - _BC(OC1CON,5); // 16 bit - _BC(OC1CON,3); // TMR2 - _BS(OC1CON,2); // - _BS(OC1CON,1); // >- PWM Mode, no fault pin - _BC(OC1CON,0); // - state[0].mode = PWM_MODE_PWM; - break; - case 1: - _BS(OC2CON,15); // ON - _BC(OC2CON,5); // 16 bit - _BC(OC2CON,3); // TMR2 - _BS(OC2CON,2); // - _BS(OC2CON,1); // >- PWM Mode, no fault pin - _BC(OC2CON,0); // - state[1].mode = PWM_MODE_PWM; - break; - case 2: - _BS(OC3CON,15); // ON - _BC(OC3CON,5); // 16 bit - _BC(OC3CON,3); // TMR2 - _BS(OC3CON,2); // - _BS(OC3CON,1); // >- PWM Mode, no fault pin - _BC(OC3CON,0); // - state[2].mode = PWM_MODE_PWM; - break; - case 3: - _BS(OC4CON,15); // ON - _BC(OC4CON,5); // 16 bit - _BC(OC4CON,3); // TMR2 - _BS(OC4CON,2); // - _BS(OC4CON,1); // >- PWM Mode, no fault pin - _BC(OC4CON,0); // - state[3].mode = PWM_MODE_PWM; - break; - case 4: - _BS(OC5CON,15); // ON - _BC(OC5CON,5); // 16 bit - _BC(OC5CON,3); // TMR2 - _BS(OC5CON,2); // - _BS(OC5CON,1); // >- PWM Mode, no fault pin - _BC(OC5CON,0); // - state[4].mode = PWM_MODE_PWM; - break; - default: - return EINVAL; - } - DEBUG("pwm%d: Mode set to PWM\n",unit); + switch (mode) { + case PWM_MODE_PWM: + _BS(T2CON,15); // ON + _BC(T2CON,6); + _BC(T2CON,5); // >- 1:1 prescale + _BC(T2CON,4); + _BC(T2CON,3); // 16 bit timer + _BC(T2CON,1); // Internal clock source + PR2 = 0xFFFF; + switch (unit) { + case 0: + _BS(OC1CON,15); // ON + _BC(OC1CON,5); // 16 bit + _BC(OC1CON,3); // TMR2 + _BS(OC1CON,2); // + _BS(OC1CON,1); // >- PWM Mode, no fault pin + _BC(OC1CON,0); // + state[0].mode = PWM_MODE_PWM; + break; + case 1: + _BS(OC2CON,15); // ON + _BC(OC2CON,5); // 16 bit + _BC(OC2CON,3); // TMR2 + _BS(OC2CON,2); // + _BS(OC2CON,1); // >- PWM Mode, no fault pin + _BC(OC2CON,0); // + state[1].mode = PWM_MODE_PWM; + break; + case 2: + _BS(OC3CON,15); // ON + _BC(OC3CON,5); // 16 bit + _BC(OC3CON,3); // TMR2 + _BS(OC3CON,2); // + _BS(OC3CON,1); // >- PWM Mode, no fault pin + _BC(OC3CON,0); // + state[2].mode = PWM_MODE_PWM; + break; + case 3: + _BS(OC4CON,15); // ON + _BC(OC4CON,5); // 16 bit + _BC(OC4CON,3); // TMR2 + _BS(OC4CON,2); // + _BS(OC4CON,1); // >- PWM Mode, no fault pin + _BC(OC4CON,0); // + state[3].mode = PWM_MODE_PWM; + break; + case 4: + _BS(OC5CON,15); // ON + _BC(OC5CON,5); // 16 bit + _BC(OC5CON,3); // TMR2 + _BS(OC5CON,2); // + _BS(OC5CON,1); // >- PWM Mode, no fault pin + _BC(OC5CON,0); // + state[4].mode = PWM_MODE_PWM; break; default: return EINVAL; + } + DEBUG("pwm%d: Mode set to PWM\n",unit); + break; + default: + return EINVAL; } return 0; } int pwm_duty(int unit, unsigned int duty) { - if(state[unit].mode!=PWM_MODE_PWM) + if (state[unit].mode != PWM_MODE_PWM) return EINVAL; - switch(unit) - { - case 0: - OC1RS = duty; - break; - case 1: - OC2RS = duty; - break; - case 2: - OC3RS = duty; - break; - case 3: - OC4RS = duty; - break; - case 4: - OC5RS = duty; - break; - default: - return EINVAL; + switch (unit) { + case 0: + OC1RS = duty; + break; + case 1: + OC2RS = duty; + break; + case 2: + OC3RS = duty; + break; + case 3: + OC4RS = duty; + break; + case 4: + OC5RS = duty; + break; + default: + return EINVAL; } DEBUG("pwm%d: Duty set to %d\n",unit,duty); return 0; @@ -150,33 +147,33 @@ int pwm_duty(int unit, unsigned int duty) int pwm_open (dev, flag, mode) - dev_t dev; + dev_t dev; { - int unit = minor(dev); + int unit = minor(dev); - if (unit >= PWM_MAX_DEV) - return ENXIO; - if (u.u_uid != 0) - return EPERM; - DEBUG("pwm%d: Opened\n",unit); - return 0; + if (unit >= PWM_MAX_DEV) + return ENXIO; + if (u.u_uid != 0) + return EPERM; + DEBUG("pwm%d: Opened\n",unit); + return 0; } int pwm_close (dev, flag, mode) - dev_t dev; + dev_t dev; { - return 0; + return 0; } int pwm_read (dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; + dev_t dev; + struct uio *uio; + int flag; { - // TODO - return ENODEV; + // TODO + return ENODEV; } int pwm_write (dev_t dev, struct uio *uio, int flag) @@ -186,26 +183,25 @@ int pwm_write (dev_t dev, struct uio *uio, int flag) int pwm_ioctl (dev, cmd, addr, flag) - dev_t dev; - register u_int cmd; - caddr_t addr; + dev_t dev; + register u_int cmd; + caddr_t addr; { - int unit; - int *val; - val = (int *)addr; + int unit; + int *val; + val = (int *)addr; - unit = minor(dev); + unit = minor(dev); - if(unit >= PWM_MAX_DEV) - return ENODEV; + if (unit >= PWM_MAX_DEV) + return ENODEV; - if (cmd == PWM_SET_MODE) { - return pwm_set_mode(unit, *val); - } + if (cmd == PWM_SET_MODE) { + return pwm_set_mode(unit, *val); + } - if (cmd == PWM_DUTY) { - return pwm_duty(unit, (unsigned int) *val); - } - - return 0; + if (cmd == PWM_DUTY) { + return pwm_duty(unit, (unsigned int) *val); + } + return 0; } diff --git a/sys/pic32/rd_flash.c b/sys/pic32/rd_flash.c index 5045866..51ec7fa 100644 --- a/sys/pic32/rd_flash.c +++ b/sys/pic32/rd_flash.c @@ -14,43 +14,43 @@ extern unsigned char flash_data_end[] asm("_binary_flash_img_end"); */ daddr_t flash_size(int unit) { - size_t fsize = (size_t)((void *)flash_data_size)>>10; + size_t fsize = (size_t)((void *)flash_data_size)>>10; - DEBUG3("flash%d: %u kbytes\n", unit, fsize); - return fsize; + DEBUG3("flash%d: %u kbytes\n", unit, fsize); + return fsize; } int flash_open (int unit, int flag, int mode) { - if (unit > 0) - return ENXIO; - return 0; + if (unit > 0) + return ENXIO; + return 0; } int flash_read(int unit, unsigned int offset, char *buf, unsigned int bcount) { - unsigned int i; - if(unit>0) - return ENXIO; + unsigned int i; + if(unit>0) + return ENXIO; - offset = offset<<10; - if(!buf) - return 0; + offset = offset<<10; + if(!buf) + return 0; - for(i=0; i 0) - { + while (bcount > 0) { pass++; toread = bcount; - if(toread > MRBSIZE) + if (toread > MRBSIZE) toread = MRBSIZE; chip = offset / MRAMS_CHIPSIZE; address = (offset<<10) - (chip * (MRAMS_CHIPSIZE*1024)); - - if(chip>=MRAMS_CHIPS) - { + if (chip >= MRAMS_CHIPS) { printf("!!!EIO\n"); return EIO; } @@ -137,7 +131,7 @@ int mrams_read(int unit, unsigned int offset, char *data, unsigned int bcount) offset += (toread>>MRBLOG2); data += toread; } - return 1; + return 1; } unsigned int mr_write_block(unsigned int chip, unsigned int address, unsigned int length, char *data) @@ -145,32 +139,31 @@ unsigned int mr_write_block(unsigned int chip, unsigned int address, unsigned in register unsigned int cs = 0; char blank __attribute__((unused)); - switch(chip) - { - case 0: - #ifdef MRAMS_LED0_PORT - TRIS_CLR(MRAMS_LED0_PORT) = 1<>8); spi_transfer(fd[chip], address); -/* - if((length & 0x03) == 0) +#if 0 + if ((length & 3) == 0) spi_bulk_write_32(fd[chip],length,data); - else if((length & 0x01) == 0) + else if ((length & 1) == 0) spi_bulk_write_16(fd[chip],length,data); - else -*/ - spi_bulk_write(fd[chip],length,(unsigned char *)data); + else +#endif + spi_bulk_write(fd[chip],length,(unsigned char *)data); spi_deselect(fd[chip]); - switch(chip) - { - case 0: - #ifdef MRAMS_LED0_PORT - LAT_CLR(MRAMS_LED0_PORT) = 1< 0) - { + while (bcount > 0) { pass++; towrite = bcount; - if(towrite > MRBSIZE) + if (towrite > MRBSIZE) towrite = MRBSIZE; chip = offset / MRAMS_CHIPSIZE; address = (offset<<10) - (chip * (MRAMS_CHIPSIZE*MRBSIZE)); - - if(chip>=MRAMS_CHIPS) - { + if (chip >= MRAMS_CHIPS) { printf("!!!EIO\n"); return EIO; } - + mr_write_block(chip, address, towrite, data); bcount -= towrite; offset += (towrite>>MRBLOG2); @@ -250,16 +239,16 @@ int mrams_write (int unit, unsigned int offset, char *data, unsigned bcount) void mrams_preinit (int unit) { - struct buf *bp; + struct buf *bp; - if (unit >= 1) - return; + if (unit >= 1) + return; - /* Initialize hardware. */ + /* Initialize hardware. */ - fd[0] = spi_open(MRAMS_PORT,(unsigned int *)&MRAMS_CS0_PORT,MRAMS_CS0_PIN); - if(fd[0]==-1) return; + if (fd[0] == -1) + return; spi_brg(fd[0],MRAMS_MHZ * 1000); spi_set(fd[0],PIC32_SPICON_CKE); @@ -295,13 +284,12 @@ void mrams_preinit (int unit) spi_deselect(fd[3]); #endif - printf("mrams0: port %s, size %dKB, speed %d Mbit/sec\n", - spi_name(MRAMS_PORT),MRAMS_CHIPS * MRAMS_CHIPSIZE, - spi_get_brg(fd[0]) / 1000); - bp = prepartition_device("mrams0"); - if(bp) - { - mrams_write (0, 0, bp->b_addr, 512); - brelse(bp); - } + printf("mrams0: port %s, size %dKB, speed %d Mbit/sec\n", + spi_name(MRAMS_PORT),MRAMS_CHIPS * MRAMS_CHIPSIZE, + spi_get_brg(fd[0]) / 1000); + bp = prepartition_device("mrams0"); + if (bp) { + mrams_write (0, 0, bp->b_addr, 512); + brelse(bp); + } } diff --git a/sys/pic32/rd_sdramp.c b/sys/pic32/rd_sdramp.c index 1746202..8640dbc 100644 --- a/sys/pic32/rd_sdramp.c +++ b/sys/pic32/rd_sdramp.c @@ -25,47 +25,46 @@ int sw_dkn = -1; /* Statistics slot number */ /* * physical specs of SDRAM chip */ -#define RAM_COLS 512 +#define RAM_COLS 512 #if SDR_ADDRESS_LINES == 13 -#define RAM_ROWS (4096*2) +#define RAM_ROWS (4096*2) #elif SDR_ADDRESS_LINES == 12 -#define RAM_ROWS 4096 +#define RAM_ROWS 4096 #elif SDR_ADDRESS_LINES == 11 -#define RAM_ROWS 2048 +#define RAM_ROWS 2048 #else #error Invalid Configuration - SDR_ADDRESS_LINES #endif -#define RAM_BANKS 4 - +#define RAM_BANKS 4 /* * RAM_BURST_COUNT MUST be match the number of bytes * read/written by each call to sdram_read/sdram_write - */ -#define RAM_BURST_COUNT 8 + */ +#define RAM_BURST_COUNT 8 /* * CHUNK_SIZE number of bytes in each "chunk" */ -#define CHUNK_SIZE 32 +#define CHUNK_SIZE 32 -#define RAM_BURST_GROUP_COUNT 4 +#define RAM_BURST_GROUP_COUNT 4 + +#define BLOCKS_PER_ROW (RAM_COLS / CHUNK_SIZE) -#define BLOCKS_PER_ROW ( RAM_COLS / CHUNK_SIZE ) - static char swaptemp[CHUNK_SIZE]; /* * Used to specify partition table for ramdisk from Makefile */ -#define RAMDISK_PARTSPEC(n,t,s,l) \ -m->partitions[n].type=t; \ -m->partitions[n].lbastart=s; \ -m->partitions[n].lbalength=l; +#define RAMDISK_PARTSPEC(n,t,s,l) \ + m->partitions[n].type = t; \ + m->partitions[n].lbastart = s; \ + m->partitions[n].lbalength = l; -//void build_ramdisk_mbr( struct mbr* m ); +//void build_ramdisk_mbr(struct mbr* m); // FIXME - FOLLOWING shared with gpio.c - needs to be made common @@ -73,286 +72,277 @@ m->partitions[n].lbalength=l; * PIC32 port i/o registers. */ struct gpioreg { - volatile unsigned tris; /* Mask of inputs */ - volatile unsigned trisclr; - volatile unsigned trisset; - volatile unsigned trisinv; - volatile unsigned port; /* Read inputs, write outputs */ - volatile unsigned portclr; - volatile unsigned portset; - volatile unsigned portinv; - volatile unsigned lat; /* Read/write outputs */ - volatile unsigned latclr; - volatile unsigned latset; - volatile unsigned latinv; - volatile unsigned odc; /* Open drain configuration */ - volatile unsigned odcclr; - volatile unsigned odcset; - volatile unsigned odcinv; + volatile unsigned tris; /* Mask of inputs */ + volatile unsigned trisclr; + volatile unsigned trisset; + volatile unsigned trisinv; + volatile unsigned port; /* Read inputs, write outputs */ + volatile unsigned portclr; + volatile unsigned portset; + volatile unsigned portinv; + volatile unsigned lat; /* Read/write outputs */ + volatile unsigned latclr; + volatile unsigned latset; + volatile unsigned latinv; + volatile unsigned odc; /* Open drain configuration */ + volatile unsigned odcclr; + volatile unsigned odcset; + volatile unsigned odcinv; }; struct ocreg { - volatile unsigned con; /* ? */ - volatile unsigned conclr; - volatile unsigned conset; - volatile unsigned coninv; - volatile unsigned r; /* ? */ - volatile unsigned rclr; - volatile unsigned rset; - volatile unsigned rinv; - volatile unsigned rs; /* ? */ - volatile unsigned rsclr; - volatile unsigned rsset; - volatile unsigned rsinv; + volatile unsigned con; /* ? */ + volatile unsigned conclr; + volatile unsigned conset; + volatile unsigned coninv; + volatile unsigned r; /* ? */ + volatile unsigned rclr; + volatile unsigned rset; + volatile unsigned rinv; + volatile unsigned rs; /* ? */ + volatile unsigned rsclr; + volatile unsigned rsset; + volatile unsigned rsinv; }; static void sdram_bank_c(unsigned bank) { - // In order to keep unnecessary noise from occuring on the - // address lines, don't use the hardware set/clear functions. - // Rather, read the latch value, change it, and write it back. + // In order to keep unnecessary noise from occuring on the + // address lines, don't use the hardware set/clear functions. + // Rather, read the latch value, change it, and write it back. - struct gpioreg * bankport = (struct gpioreg *)&SDR_BANK_PORT; - unsigned v = bankport->lat; - v &= ~(BANK_BITMASK << SDR_BANK_0_BIT); - v |= (bank & BANK_BITMASK) << SDR_BANK_0_BIT; - bankport->lat = v; + struct gpioreg * bankport = (struct gpioreg *)&SDR_BANK_PORT; + unsigned v = bankport->lat; + v &= ~(BANK_BITMASK << SDR_BANK_0_BIT); + v |= (bank & BANK_BITMASK) << SDR_BANK_0_BIT; + bankport->lat = v; } -static void sdram_upperlowerbyte( unsigned bit ) +static void sdram_upperlowerbyte(unsigned bit) { - struct gpioreg * dqm_port = (struct gpioreg *)&SDR_DQM_PORT; + struct gpioreg * dqm_port = (struct gpioreg *)&SDR_DQM_PORT; #ifdef SDR_DQM_UDQM_BIT - if( bit == 0 ) - { - dqm_port->latset = (1<latclr = (1<latset = (1<latclr = (1<latset = (1<latclr = (1<latset = (1<latclr = (1<latset = (1<latclr = (1<latset = (1<latclr = (1<latclr = (1<latclr = (1<latclr = (1<<13)|(1<<8); -address_lb_port->trisclr = (1<<13)|(1<<8); + // make f13 a ground pin? + address_lb_port->latclr = (1<<13) | (1<<8); + address_lb_port->trisclr = (1<<13) | (1<<8); - address_lb_port->trisclr = ADDRESS_LB_MASK; - address_port->trisclr = ADDRESS_MASK; - - /* AD1PCFGSET = 0xFFFF; */ - bank_port->trisclr = BANK_ALL_MASK; + address_lb_port->trisclr = ADDRESS_LB_MASK; + address_port->trisclr = ADDRESS_MASK; + + /* AD1PCFGSET = 0xFFFF; */ + bank_port->trisclr = BANK_ALL_MASK; #ifdef SDR_DQM_UDQM_BIT - dqm_port->latset = (1<latset = (1<latclr = (1<trisclr = SDR_DQM_MASK; + dqm_port->latclr = (1<trisclr = SDR_DQM_MASK; - /* All address lines low */ - address_lb_port->latclr = ADDRESS_LB_MASK; - address_port->latclr = ADDRESS_MASK; - - bank_port->latclr = BANK_ALL_MASK; + /* All address lines low */ + address_lb_port->latclr = ADDRESS_LB_MASK; + address_port->latclr = ADDRESS_MASK; - /* Initialize data lines */ - data_port->trisset = 0xff; + bank_port->latclr = BANK_ALL_MASK; - /* Initialize SDRAM control lines */ - control_port->trisclr = CONTROL_ALL_MASK; + /* Initialize data lines */ + data_port->trisset = 0xff; - /* Command Inhibit */ - control_port->latset = CONTROL_ALL_MASK; + /* Initialize SDRAM control lines */ + control_port->trisclr = CONTROL_ALL_MASK; - /* Initialize CKE line */ - cke_port->trisclr = (1<latset = CONTROL_ALL_MASK; - /* CKE low */ - cke_port->latclr = (1<trisclr = (1<latclr = (1<latset = (1<trisclr = (1<latset = (1<trisclr = (1<con = 0; - ocr_reg->rs = 1; - ocr_reg->r = 3; - ocr_reg->con = 0x8005; + /* Initialize Timer2 */ + T2CON = 0; + TMR2 = 0; + PR2 = 3; + T2CONSET = 0x8000; - /* Clock output starts here */ + /* Initialize OC device */ + ocr_reg->con = 0; + ocr_reg->rs = 1; + ocr_reg->r = 3; + ocr_reg->con = 0x8005; - /* SD-RAM initialization delay */ - unsigned cc_start, cc_now; - asm volatile("mfc0 %0, $9" : "=r" (cc_start)); - do - { - asm volatile("mfc0 %0, $9" : "=r" (cc_now)); - } while( cc_now - cc_start < 500 ); + /* Clock output starts here */ - /* CKE high */ - cke_port->latset = (1<latset = (1<lat = (address_lb_port->lat & ~ADDRESS_LB_MASK) | ((addr & 0x7) << SDR_ADDRESS_LB_A0_BIT); - address_port->lat = (address_port->lat & ~ADDRESS_MASK) - | ((addr & (ADDRESS_MASK<<(3-SDR_ADDRESS_A3_BIT))) >> (3-SDR_ADDRESS_A3_BIT)); + struct gpioreg * address_lb_port = (struct gpioreg *)&SDR_ADDRESS_LB_PORT; + struct gpioreg * address_port = (struct gpioreg *)&SDR_ADDRESS_PORT; + address_lb_port->lat = (address_lb_port->lat & ~ADDRESS_LB_MASK) | ((addr & 0x7) << SDR_ADDRESS_LB_A0_BIT); + address_port->lat = (address_port->lat & ~ADDRESS_MASK) + | ((addr & (ADDRESS_MASK<<(3-SDR_ADDRESS_A3_BIT))) >> (3-SDR_ADDRESS_A3_BIT)); } -static void sdram_active_c( unsigned row_address ) +static void sdram_active_c(unsigned row_address) { - sdram_output_addr( row_address ); - sdram_active(); + sdram_output_addr(row_address); + sdram_active(); } static void sdram_write_c(uint16_t coladdr, uint64_t val) { - sdram_output_addr( coladdr ); - sdram_write( val ); + sdram_output_addr(coladdr); + sdram_write(val); } static uint64_t sdram_read_c(uint16_t coladdr) { - sdram_output_addr( coladdr ); - return sdram_read(); + sdram_output_addr(coladdr); + return sdram_read(); } -static void -read_chunk_from_sdram( uint64_t* dest, unsigned int blockNumber ) +static void +read_chunk_from_sdram(uint64_t* dest, unsigned int blockNumber) { - int startColumn = ( ( blockNumber & ( BLOCKS_PER_ROW - 1 ) ) * CHUNK_SIZE ); // / RAM_BURST_COUNT; - int rowAndBank = blockNumber / BLOCKS_PER_ROW; - int row = rowAndBank & ( RAM_ROWS - 1 ); - int bank = rowAndBank / RAM_ROWS; - int sbank = bank / 4; - bank = bank & 0b011; - int col = startColumn; + int startColumn = (blockNumber & (BLOCKS_PER_ROW - 1)) * CHUNK_SIZE; // / RAM_BURST_COUNT; + int rowAndBank = blockNumber / BLOCKS_PER_ROW; + int row = rowAndBank & (RAM_ROWS - 1); + int bank = rowAndBank / RAM_ROWS; + int sbank = bank / 4; + bank = bank & 0b011; + int col = startColumn; - sdram_upperlowerbyte( sbank ); + sdram_upperlowerbyte(sbank); - while( col < startColumn + CHUNK_SIZE/*/RAM_BURST_COUNT*/ ) { - int x = mips_intr_disable(); - sdram_wake(); - sdram_bank_c(bank); - sdram_active_c(row); - int i; - for( i = 0; i < RAM_BURST_GROUP_COUNT; i++ ) { - *dest++ = sdram_read_c( col ); - col += RAM_BURST_COUNT; - } - sdram_precharge(); - sdram_precharge_all(); - sdram_sleep(); + while (col < startColumn + CHUNK_SIZE/*/RAM_BURST_COUNT*/) { + int x = mips_intr_disable(); + sdram_wake(); + sdram_bank_c(bank); + sdram_active_c(row); + int i; + for (i = 0; i < RAM_BURST_GROUP_COUNT; i++) { + *dest++ = sdram_read_c(col); + col += RAM_BURST_COUNT; + } + sdram_precharge(); + sdram_precharge_all(); + sdram_sleep(); - mips_intr_restore (x); + mips_intr_restore (x); - asm volatile ("nop"); - } + asm volatile ("nop"); + } } -static void -write_chunk_to_sdram( uint64_t* src, unsigned int blockNumber ) +static void +write_chunk_to_sdram(uint64_t* src, unsigned int blockNumber) { - int startColumn = ( ( blockNumber & ( BLOCKS_PER_ROW - 1 ) ) * CHUNK_SIZE ); /// RAM_BURST_COUNT; - int rowAndBank = blockNumber / BLOCKS_PER_ROW; - int row = rowAndBank & ( RAM_ROWS - 1 ); - int bank = rowAndBank / RAM_ROWS; - int sbank = bank / 4; - bank = bank & 0b011; - - sdram_upperlowerbyte( sbank ); + int startColumn = (blockNumber & (BLOCKS_PER_ROW - 1)) * CHUNK_SIZE; /// RAM_BURST_COUNT; + int rowAndBank = blockNumber / BLOCKS_PER_ROW; + int row = rowAndBank & (RAM_ROWS - 1); + int bank = rowAndBank / RAM_ROWS; + int sbank = bank / 4; + bank = bank & 0b011; - int col = startColumn; - while( col < startColumn + CHUNK_SIZE /*/RAM_BURST_COUNT*/ ) { - int x = mips_intr_disable(); + sdram_upperlowerbyte(sbank); - sdram_wake(); - sdram_bank_c(bank); - sdram_active_c(row); - int i; - for( i = 0; i < RAM_BURST_GROUP_COUNT; i++ ) { - sdram_write_c( col, *src++ ); - col += RAM_BURST_COUNT; - } - sdram_precharge(); - sdram_precharge_all(); - sdram_sleep(); + int col = startColumn; + while (col < startColumn + CHUNK_SIZE /*/RAM_BURST_COUNT*/) { + int x = mips_intr_disable(); - mips_intr_restore (x); - - asm volatile ("nop"); - } + sdram_wake(); + sdram_bank_c(bank); + sdram_active_c(row); + int i; + for (i = 0; i < RAM_BURST_GROUP_COUNT; i++) { + sdram_write_c(col, *src++); + col += RAM_BURST_COUNT; + } + sdram_precharge(); + sdram_precharge_all(); + sdram_sleep(); + + mips_intr_restore (x); + + asm volatile ("nop"); + } } - /* * Read a block of data. */ int sdramp_read(int unit, unsigned blockno, char* data, unsigned nbytes) { - blockno = blockno * (DEV_BSIZE/CHUNK_SIZE); + blockno = blockno * (DEV_BSIZE/CHUNK_SIZE); - while( nbytes >= CHUNK_SIZE ) { - read_chunk_from_sdram( (uint64_t*) swaptemp, blockno ); - bcopy( swaptemp, data, CHUNK_SIZE ); - data += CHUNK_SIZE; - blockno += 1; - nbytes -= CHUNK_SIZE; - } + while (nbytes >= CHUNK_SIZE) { + read_chunk_from_sdram((uint64_t*) swaptemp, blockno); + bcopy(swaptemp, data, CHUNK_SIZE); + data += CHUNK_SIZE; + blockno += 1; + nbytes -= CHUNK_SIZE; + } - if( nbytes ) { - read_chunk_from_sdram( (uint64_t*) swaptemp, blockno ); - bcopy( swaptemp, data, nbytes ); - } - - return 1; + if (nbytes) { + read_chunk_from_sdram((uint64_t*) swaptemp, blockno); + bcopy(swaptemp, data, nbytes); + } + return 1; } /* @@ -361,53 +351,51 @@ sdramp_read(int unit, unsigned blockno, char* data, unsigned nbytes) int sdramp_write (int unit, unsigned blockno, char *data, unsigned nbytes) { - blockno = blockno * (DEV_BSIZE/CHUNK_SIZE); + blockno = blockno * (DEV_BSIZE/CHUNK_SIZE); - while( nbytes >= CHUNK_SIZE ) { - bcopy( data, swaptemp, CHUNK_SIZE ); + while (nbytes >= CHUNK_SIZE) { + bcopy(data, swaptemp, CHUNK_SIZE); int x = mips_intr_disable(); - write_chunk_to_sdram( (uint64_t*) swaptemp, blockno ); + write_chunk_to_sdram((uint64_t*) swaptemp, blockno); mips_intr_restore(x); - data += CHUNK_SIZE; - blockno += 1; - nbytes -= CHUNK_SIZE; - } - if( nbytes ) { - read_chunk_from_sdram( (uint64_t*) swaptemp, blockno ); - bcopy( data, swaptemp, nbytes ); + data += CHUNK_SIZE; + blockno += 1; + nbytes -= CHUNK_SIZE; + } + if (nbytes) { + read_chunk_from_sdram((uint64_t*) swaptemp, blockno); + bcopy(data, swaptemp, nbytes); int x = mips_intr_disable(); - write_chunk_to_sdram( (uint64_t*) swaptemp, blockno ); + write_chunk_to_sdram((uint64_t*) swaptemp, blockno); mips_intr_restore(x); - } - return 1; + } + return 1; } void sdramp_preinit (int unit) { - printf("sdramp_preinit\n"); - - int x = mips_intr_disable(); - struct buf *bp; - sdram_init_c(); - mips_intr_restore(x); + printf("sdramp_preinit\n"); - bp = prepartition_device("sdramp0"/*,sdramp_size(0)*/); - if(bp) - { - sdramp_write (0, 0, bp->b_addr, 512); - brelse(bp); - } + int x = mips_intr_disable(); + struct buf *bp; + sdram_init_c(); + mips_intr_restore(x); + bp = prepartition_device("sdramp0"/*,sdramp_size(0)*/); + if (bp) { + sdramp_write (0, 0, bp->b_addr, 512); + brelse(bp); + } } int sdramp_open(int unit, int flag, int mode) { - return 0; + return 0; } int sdramp_size(int unit) { - return (1<= 11 -#define SDR_ADDRESS_A10_BIT 8 +#define SDR_ADDRESS_A10_BIT 8 #endif #if SDR_ADDRESS_LINES >= 12 -#define SDR_ADDRESS_A11_BIT 9 +#define SDR_ADDRESS_A11_BIT 9 #endif #if SDR_ADDRESS_LINES >= 13 -#define SDR_ADDRESS_A12_BIT 10 +#define SDR_ADDRESS_A12_BIT 10 #endif /***** END WARNING *****/ @@ -107,7 +107,7 @@ * logic analyzer for debugging purposes. */ -#define SDR_DATA_PORT TRISE +#define SDR_DATA_PORT TRISE /* * Output Compare @@ -119,9 +119,9 @@ * OC4CON - RD3 */ -#define SDR_OCR OC1CON +#define SDR_OCR OC1CON -/* +/* * Additional sdram connections * * Power and ground as appropriate. @@ -153,19 +153,19 @@ #define SDR_ADDRESS_A12_BITMASK 0 #endif -#define ADDRESS_LB_MASK \ - ((1< 0) - { + while (bcount > 0) { pass++; toread = bcount; - if(toread > MRBSIZE) + if (toread > MRBSIZE) toread = MRBSIZE; chip = offset / SPIRAMS_CHIPSIZE; address = (offset<<10) - (chip * (SPIRAMS_CHIPSIZE*1024)); - - if(chip>=SPIRAMS_CHIPS) - { + if (chip >= SPIRAMS_CHIPS) { printf("!!!EIO\n"); return EIO; } @@ -209,7 +203,7 @@ int spirams_read(int unit, unsigned int offset, char *data, unsigned int bcount) offset += (toread>>MRBLOG2); data += toread; } - return 1; + return 1; } unsigned int spir_write_block(unsigned int chip, unsigned int address, unsigned int length, char *data) @@ -217,32 +211,31 @@ unsigned int spir_write_block(unsigned int chip, unsigned int address, unsigned register unsigned int cs = 0; char blank __attribute__((unused)); - switch(chip) - { - case 0: - #ifdef SPIRAMS_LED0_PORT - TRIS_CLR(SPIRAMS_LED0_PORT) = 1<>8); spi_transfer(fd[chip], address); -/* - if((length & 0x03) == 0) +#if 0 + if ((length & 3) == 0) spi_bulk_write_32(fd[chip],length,data); - else if((length & 0x01) == 0) + else if ((length & 1) == 0) spi_bulk_write_16(fd[chip],length,data); - else -*/ - spi_bulk_write(fd[chip],length,(unsigned char *)data); + else +#endif + spi_bulk_write(fd[chip], length, (unsigned char *)data); spi_deselect(fd[chip]); - switch(chip) - { - case 0: - #ifdef SPIRAMS_LED0_PORT - LAT_CLR(SPIRAMS_LED0_PORT) = 1< 0) - { + while (bcount > 0) { pass++; towrite = bcount; - if(towrite > MRBSIZE) + if (towrite > MRBSIZE) towrite = MRBSIZE; chip = offset / SPIRAMS_CHIPSIZE; address = (offset<<10) - (chip * (SPIRAMS_CHIPSIZE*MRBSIZE)); - if(chip>=SPIRAMS_CHIPS) - { + if (chip >= SPIRAMS_CHIPS) { printf("!!!EIO\n"); return EIO; } - + spir_write_block(chip, address, towrite, data); bcount -= towrite; offset += (towrite>>MRBLOG2); @@ -321,16 +311,16 @@ int spirams_write (int unit, unsigned int offset, char *data, unsigned bcount) void spirams_preinit (int unit) { - struct buf *bp; + struct buf *bp; - if (unit >= 1) - return; + if (unit >= 1) + return; - /* Initialize hardware. */ + /* Initialize hardware. */ - fd[0] = spi_open(SPIRAMS_PORT,(unsigned int *)&SPIRAMS_CS0_PORT,SPIRAMS_CS0_PIN); - if(fd[0]==-1) return; + if (fd[0] == -1) + return; spi_brg(fd[0],SPIRAMS_MHZ * 1000); spi_set(fd[0],PIC32_SPICON_CKE); @@ -426,13 +416,12 @@ void spirams_preinit (int unit) spi_set(fd[15],PIC32_SPICON_CKE); #endif - printf("spirams0: port %d %s, size %dKB, speed %d Mbit/sec\n", - SPIRAMS_PORT, spi_name(fd[0]),SPIRAMS_CHIPS * SPIRAMS_CHIPSIZE, - spi_get_brg(fd[0]) / 1000); - bp = prepartition_device("spirams0"); - if(bp) - { - spirams_write (0, 0, bp->b_addr, 512); - brelse(bp); - } + printf("spirams0: port %d %s, size %dKB, speed %d Mbit/sec\n", + SPIRAMS_PORT, spi_name(fd[0]),SPIRAMS_CHIPS * SPIRAMS_CHIPSIZE, + spi_get_brg(fd[0]) / 1000); + bp = prepartition_device("spirams0"); + if (bp) { + spirams_write (0, 0, bp->b_addr, 512); + brelse(bp); + } } diff --git a/sys/pic32/rd_sramc.c b/sys/pic32/rd_sramc.c index 0cc90b7..08cadd5 100644 --- a/sys/pic32/rd_sramc.c +++ b/sys/pic32/rd_sramc.c @@ -12,11 +12,9 @@ * PMWR - write a byte data[7:0] to memory, increment address, PMWR * PMA0 - HIGH - write Address from data<3:0> in 6 steps: high nibble ... low nibble * - LOW - write/read Data - * + * * Signals PMRD, PMWR are active LOW and idle HIGH * Signal PMA0 is LOW when accessing RAM Data, and HIGH when accessing RAM Addresses - * - * */ #include "param.h" #include "systm.h" @@ -61,54 +59,52 @@ int sw_dkn = -1; /* Statistics slot number */ //#define RD_PULSE 4 typedef union { - unsigned value; - struct { -unsigned nib1: 4; // lowest nibble -unsigned nib2: 4; -unsigned nib3: 4; -unsigned nib4: 4; -unsigned nib5: 4; -unsigned nib6: 4; -unsigned nib7: 4; -unsigned nib8: 4; // highest nibble - }; -} nybbles ; - + unsigned value; + struct { + unsigned nib1 : 4; // lowest nibble + unsigned nib2 : 4; + unsigned nib3 : 4; + unsigned nib4 : 4; + unsigned nib5 : 4; + unsigned nib6 : 4; + unsigned nib7 : 4; + unsigned nib8 : 4; // highest nibble + }; +} nybbles; /* * Load the 24 bit address to Ramdisk. - * + * */ inline static void dev_load_address (addr) unsigned addr; { - nybbles temp; - temp.value = addr; + nybbles temp; + temp.value = addr; - while(PMMODE & 0x8000); // Poll - if busy, wait + while(PMMODE & 0x8000); // Poll - if busy, wait - PMADDR = 1; // set ADR mode (1) to write the Address + PMADDR = 1; // set ADR mode (1) to write the Address - PMMODE = 0b10<<8 | (ADR_PULSE<<2); // full ADR speed + PMMODE = 0b10<<8 | (ADR_PULSE<<2); // full ADR speed - PMDIN = temp.nib6; /* write 4 bits */ - - while(PMMODE & 0x8000); // Poll - if busy, wait - PMDIN = temp.nib5; /* write 4 bits */ - - while(PMMODE & 0x8000); // Poll - if busy, wait - PMDIN = temp.nib4; /* write 4 bits */ - - while(PMMODE & 0x8000); // Poll - if busy, wait - PMDIN = temp.nib3; /* write 4 bits */ + PMDIN = temp.nib6; /* write 4 bits */ - while(PMMODE & 0x8000); // Poll - if busy, wait - PMDIN = temp.nib2; /* write 4 bits */ + while(PMMODE & 0x8000); // Poll - if busy, wait + PMDIN = temp.nib5; /* write 4 bits */ - while(PMMODE & 0x8000); // Poll - if busy, wait - PMDIN = temp.nib1; /* write 4 bits */ + while(PMMODE & 0x8000); // Poll - if busy, wait + PMDIN = temp.nib4; /* write 4 bits */ + while(PMMODE & 0x8000); // Poll - if busy, wait + PMDIN = temp.nib3; /* write 4 bits */ + + while(PMMODE & 0x8000); // Poll - if busy, wait + PMDIN = temp.nib2; /* write 4 bits */ + + while(PMMODE & 0x8000); // Poll - if busy, wait + PMDIN = temp.nib1; /* write 4 bits */ } /* @@ -117,7 +113,7 @@ dev_load_address (addr) */ int sramc_size ( int unit ) { - return 8192; // 4096 for 4MB ramdisk + return 8192; // 4096 for 4MB ramdisk } /* @@ -125,29 +121,27 @@ int sramc_size ( int unit ) */ inline int sramc_read (int unit, unsigned int blockno, char *data, unsigned int nbytes) { - int i; + int i; - //DEBUG9("sramc%d: read block %u, length %u bytes, addr %p\n", - // major(dev), blockno, nbytes, data); + //DEBUG9("sramc%d: read block %u, length %u bytes, addr %p\n", major(dev), blockno, nbytes, data); - dev_load_address (blockno * DEV_BSIZE); + dev_load_address (blockno * DEV_BSIZE); /* Read data. */ - while(PMMODE & 0x8000); // Poll - if busy, wait + while(PMMODE & 0x8000); // Poll - if busy, wait - PMADDR = 0; // set DATA mode (0) + PMADDR = 0; // set DATA mode (0) + + PMMODE = 0b10<<8 | (RD_PULSE<<2); // read slowly - PMMODE = 0b10<<8 | (RD_PULSE<<2); // read slowly - PMDIN; // Read the PMDIN to clear previous data and latch new data - - for (i=0; i, use A0 only + PMAEN = 1; // PMA<0>, use A0 only - PMADDR = 0; // start with DATA mode + PMADDR = 0; // start with DATA mode - PMCONSET = 1<<15; // PMP enabled - asm volatile ("nop"); + PMCONSET = 1<<15; // PMP enabled + asm volatile ("nop"); // make a couple of dummy reads - it refreshes the cpld internals a little bit :) - while(PMMODE & 0x8000); // Poll - if busy, wait before reading - PMDIN; /* read a byte of data */ - while(PMMODE & 0x8000); // Poll - if busy, wait before reading - PMDIN; /* read a byte of data */ + while(PMMODE & 0x8000); // Poll - if busy, wait before reading + PMDIN; /* read a byte of data */ + while(PMMODE & 0x8000); // Poll - if busy, wait before reading + PMDIN; /* read a byte of data */ - PMADDR = 1; // go with with ADDRESS mode now + PMADDR = 1; // go with with ADDRESS mode now - - DEBUG3("sramc%d: init done\n",unit); - bp = prepartition_device("sramc0"); - if(bp) - { - sramc_write(0, 0, bp->b_addr, 512); - brelse(bp); - } - - return; + DEBUG3("sramc%d: init done\n",unit); + bp = prepartition_device("sramc0"); + if (bp) { + sramc_write(0, 0, bp->b_addr, 512); + brelse(bp); + } } /* @@ -228,6 +215,6 @@ void sramc_init (int unit) */ int sramc_open (int unit) { - DEBUG3("sramc%d: open\n",unit); - return 0; + DEBUG3("sramc%d: open\n",unit); + return 0; } diff --git a/sys/pic32/sdram.S b/sys/pic32/sdram.S index ee9d2a0..47b86cb 100644 --- a/sys/pic32/sdram.S +++ b/sys/pic32/sdram.S @@ -1,13 +1,13 @@ /* * SDRAM Access Routines for PIC32. - * + * * Retromaster - 10.05.2010 - * + * * This file is in the public domain. You can use, modify, and distribute the source code - * and executable programs based on the source code. This file is provided "as is" and + * and executable programs based on the source code. This file is provided "as is" and * without any express or implied warranties whatsoever. Use at your own risk! * - * Changes by jmcgee for inclusion in the retrobsd project. + * Changes by jmcgee for inclusion in the retrobsd project. */ /* SDRAM Used: HY57V281620 */ @@ -29,30 +29,30 @@ #define SET_OP_OFFSET (TRISASET-TRISA) #define INV_OP_OFFSET (TRISAINV-TRISA) - /* Global Symbols */ - .globl sdram_init - .globl sdram_read - .globl sdram_write - .globl sdram_active - .globl sdram_auto_refresh - .globl sdram_precharge - .globl sdram_precharge_all - .globl sdram_sleep - .globl sdram_wake - .globl sdram_bank - - .type sdram_init, @function - .type sdram_read, @function - .type sdram_write, @function - .type sdram_active, @function - .type sdram_auto_refresh, @function - .type sdram_precharge, @function - .type sdram_precharge_all, @function - .type sdram_sleep, @function - .type sdram_wake, @function - .type sdram_bank, @function + /* Global Symbols */ + .globl sdram_init + .globl sdram_read + .globl sdram_write + .globl sdram_active + .globl sdram_auto_refresh + .globl sdram_precharge + .globl sdram_precharge_all + .globl sdram_sleep + .globl sdram_wake + .globl sdram_bank - /* + .type sdram_init, @function + .type sdram_read, @function + .type sdram_write, @function + .type sdram_active, @function + .type sdram_auto_refresh, @function + .type sdram_precharge, @function + .type sdram_precharge_all, @function + .type sdram_sleep, @function + .type sdram_wake, @function + .type sdram_bank, @function + + /* * This code MUST execute from ram and the ram MUST be configured * for zero wait states. Interrupts MUST disabled before * calling any of these functions, and any DMA MUST also be @@ -61,46 +61,38 @@ * Also, the peripheral bus divisor must be set to 1. */ - .section .ramfunc,"ax",@progbits + .section .ramfunc,"ax",@progbits /* No instruction reordering */ - .set noreorder + .set noreorder -#define clock4 \ - nop;nop;nop;nop - -#define clock3 \ - nop;nop;nop - -#define clock2 \ - nop;nop - -#define clock1 \ - nop +#define clock4 nop;nop;nop;nop +#define clock3 nop;nop;nop +#define clock2 nop;nop +#define clock1 nop /* - * The SDRAM clock is output from the output compare unit. + * The SDRAM clock is output from the output compare unit. * This macro synchronizes with that clock so that we are - * sure to have at least two clock cycles to issue control + * sure to have at least two clock cycles to issue control * line changes and access the data bus before the rising * edge. */ - #define sync_clock \ - la $t8, TMR2; \ - li $v0, 2; \ - lw $v1, ($t8); \ - bge $v1, $v0, 1f; \ - nop; \ - nop; \ - nop; \ - 1: \ - nop; + la $t8, TMR2; \ + li $v0, 2; \ + lw $v1, ($t8); \ + bge $v1, $v0, 1f; \ + nop; \ + nop; \ + nop; \ + 1: \ + nop; /* - * Initializes the SDRAM. + * Initializes the SDRAM. * Should be called once sometime after startup * C Prototype: * extern __attribute__((far)) void sdram_init(); @@ -110,89 +102,89 @@ sdram_init: - /* Initialize address lines */ - la $t0, TRISA /* base of io addresses */ + /* Initialize address lines */ + la $t0, TRISA /* base of io addresses */ - /* Get ready for the commands we are about to issue. */ - li $t4, (1< typedef unsigned short uint16_t; typedef unsigned char uint8_t; typedef unsigned long long uint64_t; diff --git a/sys/pic32/signal.c b/sys/pic32/signal.c index 2fdcd04..c25e170 100644 --- a/sys/pic32/signal.c +++ b/sys/pic32/signal.c @@ -26,102 +26,102 @@ */ void sendsig (p, sig, mask) - sig_t p; - int sig; - long mask; + sig_t p; + int sig; + long mask; { - struct sigframe { - int sf_space [4]; - struct sigcontext sf_sc; - }; - register int *regs = u.u_frame; - register struct sigframe *sfp; - int oonstack; + struct sigframe { + int sf_space [4]; + struct sigcontext sf_sc; + }; + register int *regs = u.u_frame; + register struct sigframe *sfp; + int oonstack; #ifdef DIAGNOSTIC - printf("(%u)sendsig %d, mask=%#x, handler=%#x, tramp=%#x\n", - u.u_procp->p_pid, sig, mask, p, u.u_sigtramp); + printf("(%u)sendsig %d, mask=%#x, handler=%#x, tramp=%#x\n", + u.u_procp->p_pid, sig, mask, p, u.u_sigtramp); #endif - oonstack = u.u_sigstk.ss_flags & SA_ONSTACK; + oonstack = u.u_sigstk.ss_flags & SA_ONSTACK; - /* - * Allocate and validate space for the signal frame. - */ - if ((u.u_psflags & SAS_ALTSTACK) && - ! (u.u_sigstk.ss_flags & SA_ONSTACK) && - (u.u_sigonstack & sigmask(sig))) { - sfp = (struct sigframe*) (u.u_sigstk.ss_base + - u.u_sigstk.ss_size); - u.u_sigstk.ss_flags |= SA_ONSTACK; - } else - sfp = (struct sigframe*) regs [FRAME_SP]; + /* + * Allocate and validate space for the signal frame. + */ + if ((u.u_psflags & SAS_ALTSTACK) && + ! (u.u_sigstk.ss_flags & SA_ONSTACK) && + (u.u_sigonstack & sigmask(sig))) { + sfp = (struct sigframe*) (u.u_sigstk.ss_base + + u.u_sigstk.ss_size); + u.u_sigstk.ss_flags |= SA_ONSTACK; + } else + sfp = (struct sigframe*) regs [FRAME_SP]; - sfp--; - if (! (u.u_sigstk.ss_flags & SA_ONSTACK)) { - if ((caddr_t) sfp < (caddr_t) u.u_procp->p_daddr + u.u_dsize) { - /* - * Process has trashed its stack; give it an illegal - * instruction violation to halt it in its tracks. - */ - fatalsig(SIGILL); - return; - } - if (u.u_procp->p_ssize < USER_DATA_END - (unsigned) sfp) { - u.u_procp->p_ssize = USER_DATA_END - (unsigned) sfp; - u.u_procp->p_saddr = (unsigned) sfp; - u.u_ssize = u.u_procp->p_ssize; - } + sfp--; + if (! (u.u_sigstk.ss_flags & SA_ONSTACK)) { + if ((caddr_t) sfp < (caddr_t) u.u_procp->p_daddr + u.u_dsize) { + /* + * Process has trashed its stack; give it an illegal + * instruction violation to halt it in its tracks. + */ + fatalsig(SIGILL); + return; } + if (u.u_procp->p_ssize < USER_DATA_END - (unsigned) sfp) { + u.u_procp->p_ssize = USER_DATA_END - (unsigned) sfp; + u.u_procp->p_saddr = (unsigned) sfp; + u.u_ssize = u.u_procp->p_ssize; + } + } - /* - * Build the signal context to be used by sigreturn. - */ - sfp->sf_sc.sc_onstack = oonstack; - sfp->sf_sc.sc_mask = mask; - sfp->sf_sc.sc_r1 = regs [FRAME_R1]; - sfp->sf_sc.sc_r2 = regs [FRAME_R2]; - sfp->sf_sc.sc_r3 = regs [FRAME_R3]; - sfp->sf_sc.sc_r4 = regs [FRAME_R4]; - sfp->sf_sc.sc_r5 = regs [FRAME_R5]; - sfp->sf_sc.sc_r6 = regs [FRAME_R6]; - sfp->sf_sc.sc_r7 = regs [FRAME_R7]; - sfp->sf_sc.sc_r8 = regs [FRAME_R8]; - sfp->sf_sc.sc_r9 = regs [FRAME_R9]; - sfp->sf_sc.sc_r10 = regs [FRAME_R10]; - sfp->sf_sc.sc_r11 = regs [FRAME_R11]; - sfp->sf_sc.sc_r12 = regs [FRAME_R12]; - sfp->sf_sc.sc_r13 = regs [FRAME_R13]; - sfp->sf_sc.sc_r14 = regs [FRAME_R14]; - sfp->sf_sc.sc_r15 = regs [FRAME_R15]; - sfp->sf_sc.sc_r16 = regs [FRAME_R16]; - sfp->sf_sc.sc_r17 = regs [FRAME_R17]; - sfp->sf_sc.sc_r18 = regs [FRAME_R18]; - sfp->sf_sc.sc_r19 = regs [FRAME_R19]; - sfp->sf_sc.sc_r20 = regs [FRAME_R20]; - sfp->sf_sc.sc_r21 = regs [FRAME_R21]; - sfp->sf_sc.sc_r22 = regs [FRAME_R22]; - sfp->sf_sc.sc_r23 = regs [FRAME_R23]; - sfp->sf_sc.sc_r24 = regs [FRAME_R24]; - sfp->sf_sc.sc_r25 = regs [FRAME_R25]; - sfp->sf_sc.sc_gp = regs [FRAME_GP]; - sfp->sf_sc.sc_sp = regs [FRAME_SP]; - sfp->sf_sc.sc_fp = regs [FRAME_FP]; - sfp->sf_sc.sc_ra = regs [FRAME_RA]; - sfp->sf_sc.sc_lo = regs [FRAME_LO]; - sfp->sf_sc.sc_hi = regs [FRAME_HI]; - sfp->sf_sc.sc_pc = regs [FRAME_PC]; + /* + * Build the signal context to be used by sigreturn. + */ + sfp->sf_sc.sc_onstack = oonstack; + sfp->sf_sc.sc_mask = mask; + sfp->sf_sc.sc_r1 = regs [FRAME_R1]; + sfp->sf_sc.sc_r2 = regs [FRAME_R2]; + sfp->sf_sc.sc_r3 = regs [FRAME_R3]; + sfp->sf_sc.sc_r4 = regs [FRAME_R4]; + sfp->sf_sc.sc_r5 = regs [FRAME_R5]; + sfp->sf_sc.sc_r6 = regs [FRAME_R6]; + sfp->sf_sc.sc_r7 = regs [FRAME_R7]; + sfp->sf_sc.sc_r8 = regs [FRAME_R8]; + sfp->sf_sc.sc_r9 = regs [FRAME_R9]; + sfp->sf_sc.sc_r10 = regs [FRAME_R10]; + sfp->sf_sc.sc_r11 = regs [FRAME_R11]; + sfp->sf_sc.sc_r12 = regs [FRAME_R12]; + sfp->sf_sc.sc_r13 = regs [FRAME_R13]; + sfp->sf_sc.sc_r14 = regs [FRAME_R14]; + sfp->sf_sc.sc_r15 = regs [FRAME_R15]; + sfp->sf_sc.sc_r16 = regs [FRAME_R16]; + sfp->sf_sc.sc_r17 = regs [FRAME_R17]; + sfp->sf_sc.sc_r18 = regs [FRAME_R18]; + sfp->sf_sc.sc_r19 = regs [FRAME_R19]; + sfp->sf_sc.sc_r20 = regs [FRAME_R20]; + sfp->sf_sc.sc_r21 = regs [FRAME_R21]; + sfp->sf_sc.sc_r22 = regs [FRAME_R22]; + sfp->sf_sc.sc_r23 = regs [FRAME_R23]; + sfp->sf_sc.sc_r24 = regs [FRAME_R24]; + sfp->sf_sc.sc_r25 = regs [FRAME_R25]; + sfp->sf_sc.sc_gp = regs [FRAME_GP]; + sfp->sf_sc.sc_sp = regs [FRAME_SP]; + sfp->sf_sc.sc_fp = regs [FRAME_FP]; + sfp->sf_sc.sc_ra = regs [FRAME_RA]; + sfp->sf_sc.sc_lo = regs [FRAME_LO]; + sfp->sf_sc.sc_hi = regs [FRAME_HI]; + sfp->sf_sc.sc_pc = regs [FRAME_PC]; - /* Call signal handler */ - regs [FRAME_R4] = sig; /* $a0 - signal number */ - regs [FRAME_R5] = u.u_code; /* $a1 - code */ - regs [FRAME_R6] = (int) &sfp->sf_sc; /* $a2 - address of sigcontext */ - regs [FRAME_RA] = (int) u.u_sigtramp; /* $ra - sigtramp */ - regs [FRAME_SP] = (int) sfp; - regs [FRAME_PC] = (int) p; + /* Call signal handler */ + regs [FRAME_R4] = sig; /* $a0 - signal number */ + regs [FRAME_R5] = u.u_code; /* $a1 - code */ + regs [FRAME_R6] = (int) &sfp->sf_sc; /* $a2 - address of sigcontext */ + regs [FRAME_RA] = (int) u.u_sigtramp; /* $ra - sigtramp */ + regs [FRAME_SP] = (int) sfp; + regs [FRAME_PC] = (int) p; #ifdef DIAGNOSTIC - printf(" ...call handler %p (sig=%d, code=%#x, context=%p)\n", - p, sig, u.u_code, &sfp->sf_sc); - printf(" ...stack=%p, return to %p\n", sfp, u.u_sigtramp); + printf(" ...call handler %p (sig=%d, code=%#x, context=%p)\n", + p, sig, u.u_code, &sfp->sf_sc); + printf(" ...stack=%p, return to %p\n", sfp, u.u_sigtramp); #endif } @@ -138,60 +138,60 @@ sendsig (p, sig, mask) void sigreturn() { - register int *regs = u.u_frame; - register struct sigcontext *scp = - (struct sigcontext*) (regs [FRAME_SP] + 16); + register int *regs = u.u_frame; + register struct sigcontext *scp = + (struct sigcontext*) (regs [FRAME_SP] + 16); #ifdef DIAGNOSTIC - printf("(%u)sigreturn stack=%#x, context=%p\n", - u.u_procp->p_pid, regs [FRAME_SP], scp); + printf("(%u)sigreturn stack=%#x, context=%p\n", + u.u_procp->p_pid, regs [FRAME_SP], scp); #endif - if (baduaddr ((caddr_t) scp) || - baduaddr ((caddr_t) scp + sizeof(*scp))) { - u.u_error = EFAULT; - return; - } - u.u_error = EJUSTRETURN; - if (scp->sc_onstack & SA_ONSTACK) - u.u_sigstk.ss_flags |= SA_ONSTACK; - else - u.u_sigstk.ss_flags &= ~SA_ONSTACK; - u.u_procp->p_sigmask = scp->sc_mask & ~sigcantmask; + if (baduaddr ((caddr_t) scp) || + baduaddr ((caddr_t) scp + sizeof(*scp))) { + u.u_error = EFAULT; + return; + } + u.u_error = EJUSTRETURN; + if (scp->sc_onstack & SA_ONSTACK) + u.u_sigstk.ss_flags |= SA_ONSTACK; + else + u.u_sigstk.ss_flags &= ~SA_ONSTACK; + u.u_procp->p_sigmask = scp->sc_mask & ~sigcantmask; - /* Return from signal handler */ - regs [FRAME_R1] = scp->sc_r1; - regs [FRAME_R2] = scp->sc_r2; - regs [FRAME_R3] = scp->sc_r3; - regs [FRAME_R4] = scp->sc_r4; - regs [FRAME_R5] = scp->sc_r5; - regs [FRAME_R6] = scp->sc_r6; - regs [FRAME_R7] = scp->sc_r7; - regs [FRAME_R8] = scp->sc_r8; - regs [FRAME_R9] = scp->sc_r9; - regs [FRAME_R10] = scp->sc_r10; - regs [FRAME_R11] = scp->sc_r11; - regs [FRAME_R12] = scp->sc_r12; - regs [FRAME_R13] = scp->sc_r13; - regs [FRAME_R14] = scp->sc_r14; - regs [FRAME_R15] = scp->sc_r15; - regs [FRAME_R16] = scp->sc_r16; - regs [FRAME_R17] = scp->sc_r17; - regs [FRAME_R18] = scp->sc_r18; - regs [FRAME_R19] = scp->sc_r19; - regs [FRAME_R20] = scp->sc_r20; - regs [FRAME_R21] = scp->sc_r21; - regs [FRAME_R22] = scp->sc_r22; - regs [FRAME_R23] = scp->sc_r23; - regs [FRAME_R24] = scp->sc_r24; - regs [FRAME_R25] = scp->sc_r25; - regs [FRAME_GP] = scp->sc_gp; - regs [FRAME_SP] = scp->sc_sp; - regs [FRAME_FP] = scp->sc_fp; - regs [FRAME_RA] = scp->sc_ra; - regs [FRAME_LO] = scp->sc_lo; - regs [FRAME_HI] = scp->sc_hi; - regs [FRAME_PC] = scp->sc_pc; + /* Return from signal handler */ + regs [FRAME_R1] = scp->sc_r1; + regs [FRAME_R2] = scp->sc_r2; + regs [FRAME_R3] = scp->sc_r3; + regs [FRAME_R4] = scp->sc_r4; + regs [FRAME_R5] = scp->sc_r5; + regs [FRAME_R6] = scp->sc_r6; + regs [FRAME_R7] = scp->sc_r7; + regs [FRAME_R8] = scp->sc_r8; + regs [FRAME_R9] = scp->sc_r9; + regs [FRAME_R10] = scp->sc_r10; + regs [FRAME_R11] = scp->sc_r11; + regs [FRAME_R12] = scp->sc_r12; + regs [FRAME_R13] = scp->sc_r13; + regs [FRAME_R14] = scp->sc_r14; + regs [FRAME_R15] = scp->sc_r15; + regs [FRAME_R16] = scp->sc_r16; + regs [FRAME_R17] = scp->sc_r17; + regs [FRAME_R18] = scp->sc_r18; + regs [FRAME_R19] = scp->sc_r19; + regs [FRAME_R20] = scp->sc_r20; + regs [FRAME_R21] = scp->sc_r21; + regs [FRAME_R22] = scp->sc_r22; + regs [FRAME_R23] = scp->sc_r23; + regs [FRAME_R24] = scp->sc_r24; + regs [FRAME_R25] = scp->sc_r25; + regs [FRAME_GP] = scp->sc_gp; + regs [FRAME_SP] = scp->sc_sp; + regs [FRAME_FP] = scp->sc_fp; + regs [FRAME_RA] = scp->sc_ra; + regs [FRAME_LO] = scp->sc_lo; + regs [FRAME_HI] = scp->sc_hi; + regs [FRAME_PC] = scp->sc_pc; #ifdef DIAGNOSTIC - printf(" ...to %#x, stack %#x\n", regs[FRAME_PC], regs[FRAME_SP]); + printf(" ...to %#x, stack %#x\n", regs[FRAME_PC], regs[FRAME_SP]); #endif } diff --git a/sys/pic32/skel.c b/sys/pic32/skel.c index 5dc8f3e..015085e 100644 --- a/sys/pic32/skel.c +++ b/sys/pic32/skel.c @@ -63,7 +63,7 @@ int skeldev_open(dev_t dev, int flag, int mode) return ENXIO; if (u.u_uid != 0) - return EPERM; + return EPERM; // TODO: initialize the port. PRINTDBG("--- %s() unit=%u, flag=%d, mode=%d\n", __func__, unit, flag, mode); @@ -78,7 +78,7 @@ int skeldev_close(dev_t dev, int flag, int mode) int unit = minor(dev); if (u.u_uid != 0) - return EPERM; + return EPERM; // TODO: disable the port. PRINTDBG("--- %s() unit=%u, flag=%d, mode=%d\n", __func__, unit, flag, mode); diff --git a/sys/pic32/ssd1926.h b/sys/pic32/ssd1926.h index 2dadea2..9e4f7e5 100644 --- a/sys/pic32/ssd1926.h +++ b/sys/pic32/ssd1926.h @@ -93,7 +93,7 @@ #define CMD_SET_DSR 4 #define CMD_IO_SEND_OCR 5 // R4, unique to IO cards #define CMD_SELECT_CARD 7 // R1, arg=rca[31..16] or 0 -#define CMD_SEND_IF_COND 8 +#define CMD_SEND_IF_COND 8 #define CMD_SEND_CSD 9 // R2: R136 #define CMD_SEND_CID 10 // R2: R136 #define CMD_STOP_TRANSMISSION 12 // R1b: arg=stuff bits diff --git a/sys/pic32/startup.S b/sys/pic32/startup.S index 44b0bd4..e2c17b9 100644 --- a/sys/pic32/startup.S +++ b/sys/pic32/startup.S @@ -24,86 +24,86 @@ # #include "machine/io.h" -#define UBASE 0x7f008000 /* User space base address */ +#define UBASE 0x7f008000 /* User space base address */ - .set noreorder - .set mips32r2 - .set nomips16 + .set noreorder + .set mips32r2 + .set nomips16 - .extern u - .extern u_end - .extern u0 - .extern main - .extern exception + .extern u + .extern u_end + .extern u0 + .extern main + .extern exception #--------------------------------------- # Reset vector: main entry point # - .section .startup,"ax",@progbits - .org 0 - .type _reset_vector_, @function -_reset_vector_: .globl _reset_vector_ + .section .startup,"ax",@progbits + .org 0 + .type _reset_vector_, @function +_reset_vector_: .globl _reset_vector_ - .set noat - move $1, $zero # Clear all regs - move $2, $zero - move $3, $zero - move $4, $zero - move $5, $zero - move $6, $zero - move $7, $zero - move $8, $zero - move $9, $zero - move $10, $zero - move $11, $zero - move $12, $zero - move $13, $zero - move $14, $zero - move $15, $zero - move $16, $zero - move $17, $zero - move $18, $zero - move $19, $zero - move $20, $zero - move $21, $zero - move $22, $zero - move $23, $zero - move $24, $zero - move $25, $zero - move $26, $zero - move $27, $zero - move $28, $zero - move $29, $zero - move $30, $zero - move $31, $zero - mtlo $zero - mthi $zero - .set at + .set noat + move $1, $zero # Clear all regs + move $2, $zero + move $3, $zero + move $4, $zero + move $5, $zero + move $6, $zero + move $7, $zero + move $8, $zero + move $9, $zero + move $10, $zero + move $11, $zero + move $12, $zero + move $13, $zero + move $14, $zero + move $15, $zero + move $16, $zero + move $17, $zero + move $18, $zero + move $19, $zero + move $20, $zero + move $21, $zero + move $22, $zero + move $23, $zero + move $24, $zero + move $25, $zero + move $26, $zero + move $27, $zero + move $28, $zero + move $29, $zero + move $30, $zero + move $31, $zero + mtlo $zero + mthi $zero + .set at - la $sp, u_end - 16 # Stack at end of U area + la $sp, u_end - 16 # Stack at end of U area la $a0, main - jalr $a0 # Jump to main() - lui $gp, 0x8000 # Set global pointer (delay slot) + jalr $a0 # Jump to main() + lui $gp, 0x8000 # Set global pointer (delay slot) la $k0, UBASE - mtc0 $k0, $C0_EPC # Entry to user code. + mtc0 $k0, $C0_EPC # Entry to user code. - mfc0 $k0, $C0_STATUS - ori $k0, $k0, ST_UM | ST_EXL | ST_IE # Set user mode and enable interrupts - mtc0 $k0, $C0_STATUS # Put SR back - ehb - eret # PC <= EPC; EXL <= 0 - nop # just to be safe + mfc0 $k0, $C0_STATUS + ori $k0, $k0, ST_UM | ST_EXL | ST_IE # Set user mode and enable interrupts + mtc0 $k0, $C0_STATUS # Put SR back + ehb + eret # PC <= EPC; EXL <= 0 + nop # just to be safe #--------------------------------------- # Secondary entry point for RetroBSD bootloader. # - .section .exception,"ax",@progbits + .section .exception,"ax",@progbits _exception_base_: .globl _exception_base_ - .org 0 - .type _entry_vector_, @function + .org 0 + .type _entry_vector_, @function _entry_vector_: .globl _entry_vector_ la $k0, _reset_vector_ jr $k0 @@ -123,204 +123,204 @@ _imgptr: .word -1 # Image header pointer #--------------------------------------- # Exception vector: handle interrupts and exceptions # - .org 0x200 - .type _exception_vector_, @function + .org 0x200 + .type _exception_vector_, @function _exception_vector_: .globl _exception_vector_ - mfc0 $k0, $C0_STATUS - andi $k1, $k0, ST_UM # Check user mode - beqz $k1, kernel_exception - move $k1, $sp + mfc0 $k0, $C0_STATUS + andi $k1, $k0, ST_UM # Check user mode + beqz $k1, kernel_exception + move $k1, $sp - # - # Exception in user mode: switch stack. - # + # + # Exception in user mode: switch stack. + # user_exception: - la $sp, u_end # Stack at end of U area + la $sp, u_end # Stack at end of U area kernel_exception: - addi $sp, -16-FRAME_WORDS*4 # Allocate space for registers + addi $sp, -16-FRAME_WORDS*4 # Allocate space for registers save_regs: - sw $k0, (16+FRAME_STATUS*4) ($sp) + sw $k0, (16+FRAME_STATUS*4) ($sp) sw $k1, (16+FRAME_SP*4) ($sp) - .set noat - sw $1, (16+FRAME_R1*4) ($sp) # Save general registers - sw $2, (16+FRAME_R2*4) ($sp) - sw $3, (16+FRAME_R3*4) ($sp) - sw $4, (16+FRAME_R4*4) ($sp) - sw $5, (16+FRAME_R5*4) ($sp) - sw $6, (16+FRAME_R6*4) ($sp) - sw $7, (16+FRAME_R7*4) ($sp) - sw $8, (16+FRAME_R8*4) ($sp) - sw $9, (16+FRAME_R9*4) ($sp) - sw $10, (16+FRAME_R10*4) ($sp) - sw $11, (16+FRAME_R11*4) ($sp) - sw $12, (16+FRAME_R12*4) ($sp) - sw $13, (16+FRAME_R13*4) ($sp) - sw $14, (16+FRAME_R14*4) ($sp) - sw $15, (16+FRAME_R15*4) ($sp) - sw $16, (16+FRAME_R16*4) ($sp) - sw $17, (16+FRAME_R17*4) ($sp) - sw $18, (16+FRAME_R18*4) ($sp) - sw $19, (16+FRAME_R19*4) ($sp) - sw $20, (16+FRAME_R20*4) ($sp) - sw $21, (16+FRAME_R21*4) ($sp) - sw $22, (16+FRAME_R22*4) ($sp) - sw $23, (16+FRAME_R23*4) ($sp) - sw $24, (16+FRAME_R24*4) ($sp) - sw $25, (16+FRAME_R25*4) ($sp) - # Skip $26 - K0 - # Skip $27 - K1 - sw $28, (16+FRAME_GP*4) ($sp) - # Skip $29 - SP - sw $30, (16+FRAME_FP*4) ($sp) - sw $31, (16+FRAME_RA*4) ($sp) - .set at + .set noat + sw $1, (16+FRAME_R1*4) ($sp) # Save general registers + sw $2, (16+FRAME_R2*4) ($sp) + sw $3, (16+FRAME_R3*4) ($sp) + sw $4, (16+FRAME_R4*4) ($sp) + sw $5, (16+FRAME_R5*4) ($sp) + sw $6, (16+FRAME_R6*4) ($sp) + sw $7, (16+FRAME_R7*4) ($sp) + sw $8, (16+FRAME_R8*4) ($sp) + sw $9, (16+FRAME_R9*4) ($sp) + sw $10, (16+FRAME_R10*4) ($sp) + sw $11, (16+FRAME_R11*4) ($sp) + sw $12, (16+FRAME_R12*4) ($sp) + sw $13, (16+FRAME_R13*4) ($sp) + sw $14, (16+FRAME_R14*4) ($sp) + sw $15, (16+FRAME_R15*4) ($sp) + sw $16, (16+FRAME_R16*4) ($sp) + sw $17, (16+FRAME_R17*4) ($sp) + sw $18, (16+FRAME_R18*4) ($sp) + sw $19, (16+FRAME_R19*4) ($sp) + sw $20, (16+FRAME_R20*4) ($sp) + sw $21, (16+FRAME_R21*4) ($sp) + sw $22, (16+FRAME_R22*4) ($sp) + sw $23, (16+FRAME_R23*4) ($sp) + sw $24, (16+FRAME_R24*4) ($sp) + sw $25, (16+FRAME_R25*4) ($sp) + # Skip $26 - K0 + # Skip $27 - K1 + sw $28, (16+FRAME_GP*4) ($sp) + # Skip $29 - SP + sw $30, (16+FRAME_FP*4) ($sp) + sw $31, (16+FRAME_RA*4) ($sp) + .set at - mfhi $k0 # Save special registers - sw $k0, (16+FRAME_HI*4) ($sp) + mfhi $k0 # Save special registers + sw $k0, (16+FRAME_HI*4) ($sp) - mflo $k0 - sw $k0, (16+FRAME_LO*4) ($sp) + mflo $k0 + sw $k0, (16+FRAME_LO*4) ($sp) - mfc0 $k0, $C0_EPC - sw $k0, (16+FRAME_PC*4) ($sp) + mfc0 $k0, $C0_EPC + sw $k0, (16+FRAME_PC*4) ($sp) - move $a0, $sp - addi $a0, 16 # Arg 0: saved regs. - jal exception # Call C code. - lui $gp, 0x8000 # Set global pointer (delay slot) + move $a0, $sp + addi $a0, 16 # Arg 0: saved regs. + jal exception # Call C code. + lui $gp, 0x8000 # Set global pointer (delay slot) - # - # Restore CPU state and return from interrupt. - # + # + # Restore CPU state and return from interrupt. + # restore_regs: - lw $a0, (16+FRAME_LO*4) ($sp) # Load HI, LO registers - mtlo $a0 - lw $a0, (16+FRAME_HI*4) ($sp) - mthi $a0 + lw $a0, (16+FRAME_LO*4) ($sp) # Load HI, LO registers + mtlo $a0 + lw $a0, (16+FRAME_HI*4) ($sp) + mthi $a0 - .set noat - lw $1, (16+FRAME_R1*4) ($sp) # Load general registers - lw $2, (16+FRAME_R2*4) ($sp) - lw $3, (16+FRAME_R3*4) ($sp) - lw $4, (16+FRAME_R4*4) ($sp) - lw $5, (16+FRAME_R5*4) ($sp) - lw $6, (16+FRAME_R6*4) ($sp) - lw $7, (16+FRAME_R7*4) ($sp) - lw $8, (16+FRAME_R8*4) ($sp) - lw $9, (16+FRAME_R9*4) ($sp) - lw $10, (16+FRAME_R10*4) ($sp) - lw $11, (16+FRAME_R11*4) ($sp) - lw $12, (16+FRAME_R12*4) ($sp) - lw $13, (16+FRAME_R13*4) ($sp) - lw $14, (16+FRAME_R14*4) ($sp) - lw $15, (16+FRAME_R15*4) ($sp) - lw $16, (16+FRAME_R16*4) ($sp) - lw $17, (16+FRAME_R17*4) ($sp) - lw $18, (16+FRAME_R18*4) ($sp) - lw $19, (16+FRAME_R19*4) ($sp) - lw $20, (16+FRAME_R20*4) ($sp) - lw $21, (16+FRAME_R21*4) ($sp) - lw $22, (16+FRAME_R22*4) ($sp) - lw $23, (16+FRAME_R23*4) ($sp) - lw $24, (16+FRAME_R24*4) ($sp) - lw $25, (16+FRAME_R25*4) ($sp) - # Skip $26 - K0 - # Skip $27 - K1 - lw $28, (16+FRAME_GP*4) ($sp) - # Skip $29 - SP - lw $30, (16+FRAME_FP*4) ($sp) - .set at + .set noat + lw $1, (16+FRAME_R1*4) ($sp) # Load general registers + lw $2, (16+FRAME_R2*4) ($sp) + lw $3, (16+FRAME_R3*4) ($sp) + lw $4, (16+FRAME_R4*4) ($sp) + lw $5, (16+FRAME_R5*4) ($sp) + lw $6, (16+FRAME_R6*4) ($sp) + lw $7, (16+FRAME_R7*4) ($sp) + lw $8, (16+FRAME_R8*4) ($sp) + lw $9, (16+FRAME_R9*4) ($sp) + lw $10, (16+FRAME_R10*4) ($sp) + lw $11, (16+FRAME_R11*4) ($sp) + lw $12, (16+FRAME_R12*4) ($sp) + lw $13, (16+FRAME_R13*4) ($sp) + lw $14, (16+FRAME_R14*4) ($sp) + lw $15, (16+FRAME_R15*4) ($sp) + lw $16, (16+FRAME_R16*4) ($sp) + lw $17, (16+FRAME_R17*4) ($sp) + lw $18, (16+FRAME_R18*4) ($sp) + lw $19, (16+FRAME_R19*4) ($sp) + lw $20, (16+FRAME_R20*4) ($sp) + lw $21, (16+FRAME_R21*4) ($sp) + lw $22, (16+FRAME_R22*4) ($sp) + lw $23, (16+FRAME_R23*4) ($sp) + lw $24, (16+FRAME_R24*4) ($sp) + lw $25, (16+FRAME_R25*4) ($sp) + # Skip $26 - K0 + # Skip $27 - K1 + lw $28, (16+FRAME_GP*4) ($sp) + # Skip $29 - SP + lw $30, (16+FRAME_FP*4) ($sp) + .set at # Do not use k0/k1 here, as interrupts are still enabled - lw $31, (16+FRAME_STATUS*4) ($sp) # K0 = saved status - ori $31, ST_EXL # Set EXL - mtc0 $31, $C0_STATUS # put SR back: disable interrupts + lw $31, (16+FRAME_STATUS*4) ($sp) # K0 = saved status + ori $31, ST_EXL # Set EXL + mtc0 $31, $C0_STATUS # put SR back: disable interrupts ehb - lw $k0, (16+FRAME_PC*4) ($sp) # K0 = EPC - mtc0 $k0, $C0_EPC # put PC in EPC + lw $k0, (16+FRAME_PC*4) ($sp) # K0 = EPC + mtc0 $k0, $C0_EPC # put PC in EPC ext $k1, $31, 27, 1 # get RP bit: single-step request - lw $31, (16+FRAME_RA*4) ($sp) - lw $sp, (16+FRAME_SP*4) ($sp) # Restore stack + lw $31, (16+FRAME_RA*4) ($sp) + lw $sp, (16+FRAME_SP*4) ($sp) # Restore stack - # Return from exception + # Return from exception bnez $k1, debug_request # single-step request - ehb - eret # PC <= EPC; EXL <= 0 + ehb + eret # PC <= EPC; EXL <= 0 debug_request: - sdbbp # enter debug mode + sdbbp # enter debug mode #--------------------------------------- # Debug exception processing. # - .org 0x480 - .type _debug_vector_, @function + .org 0x480 + .type _debug_vector_, @function _debug_vector_: .globl _debug_vector_ - mfc0 $k0, $C0_DEPC - la $k1, debug_request - bne $k0, $k1, single_step_done - nop + mfc0 $k0, $C0_DEPC + la $k1, debug_request + bne $k0, $k1, single_step_done + nop # single step request - mfc0 $k0, $C0_DEBUG - ori $k0, DB_SST # set SST bit - mtc0 $k0, $C0_DEBUG + mfc0 $k0, $C0_DEBUG + ori $k0, DB_SST # set SST bit + mtc0 $k0, $C0_DEBUG - mfc0 $k1, $C0_EPC - mtc0 $k1, $C0_DEPC # DEPC <= EPC - mfc0 $k0, $C0_STATUS - xori $k0, ST_EXL # Clear EXL - mtc0 $k0, $C0_STATUS - ehb - deret # PC <= DEPC; DM <= 0 + mfc0 $k1, $C0_EPC + mtc0 $k1, $C0_DEPC # DEPC <= EPC + mfc0 $k0, $C0_STATUS + xori $k0, ST_EXL # Clear EXL + mtc0 $k0, $C0_STATUS + ehb + deret # PC <= DEPC; DM <= 0 single_step_done: - mtc0 $k0, $C0_EPC # EPC <= DEPC + mtc0 $k0, $C0_EPC # EPC <= DEPC - la $k1, _exception_vector_ - mtc0 $k1, $C0_DEPC # DEPC <= exception handler + la $k1, _exception_vector_ + mtc0 $k1, $C0_DEPC # DEPC <= exception handler - mfc0 $k0, $C0_DEBUG - sw $k0, c0_debug # save Debug register - ori $k0, DB_SST - xori $k0, DB_SST # clear SST bit - mtc0 $k0, $C0_DEBUG + mfc0 $k0, $C0_DEBUG + sw $k0, c0_debug # save Debug register + ori $k0, DB_SST + xori $k0, DB_SST # clear SST bit + mtc0 $k0, $C0_DEBUG - mfc0 $k1, $C0_STATUS - ori $k1, ST_EXL # Set EXL - mtc0 $k1, $C0_STATUS - ehb - deret # PC <= DEPC; DM <= 0 + mfc0 $k1, $C0_STATUS + ori $k1, ST_EXL # Set EXL + mtc0 $k1, $C0_STATUS + ehb + deret # PC <= DEPC; DM <= 0 #--------------------------------------- # Icode is copied out to process 1 to exec /sbin/init. # If the exec fails, process 1 exits. # - .globl icode, icodeend - .type icode, @function - .type icodeend, @function + .globl icode, icodeend + .type icode, @function + .type icodeend, @function icode: - la $a0, UBASE - move $a1, $a0 - addi $a0, etcinit - icode - addi $a1, argv - icode - syscall 11 # SYS_execv - move $a0, $v0 - syscall 1 # SYS_exit + la $a0, UBASE + move $a1, $a0 + addi $a0, etcinit - icode + addi $a1, argv - icode + syscall 11 # SYS_execv + move $a0, $v0 + syscall 1 # SYS_exit etcinit: - .ascii "/sbin/init\0" + .ascii "/sbin/init\0" initflags: - .ascii "-\0" # ASCII initflags + .ascii "-\0" # ASCII initflags argv: - .word etcinit + 6 - icode + UBASE # address of "init\0" - .word initflags - icode + UBASE # init options - .word 0 + .word etcinit + 6 - icode + UBASE # address of "init\0" + .word initflags - icode + UBASE # init options + .word 0 -icodeend: nop +icodeend: nop #--------------------------------------- # int setjmp (label_t *env); @@ -328,22 +328,22 @@ icodeend: nop # Setjmp(env) will save the process' current register variables, stack # and program counter context and return a zero. # - .type setjmp, @function -setjmp: .globl setjmp - sw $s0, (0 * 4) ($a0) # save register variables s0-s8 - sw $s1, (1 * 4) ($a0) - sw $s2, (2 * 4) ($a0) - sw $s3, (3 * 4) ($a0) - sw $s4, (4 * 4) ($a0) - sw $s5, (5 * 4) ($a0) - sw $s6, (6 * 4) ($a0) - sw $s7, (7 * 4) ($a0) - sw $s8, (8 * 4) ($a0) # frame pointer - sw $ra, (9 * 4) ($a0) # return address - sw $gp, (10 * 4) ($a0) # global data pointer - sw $sp, (11 * 4) ($a0) # stack pointer - j $ra - move $v0, $zero # return a zero for the setjmp call + .type setjmp, @function +setjmp: .globl setjmp + sw $s0, (0 * 4) ($a0) # save register variables s0-s8 + sw $s1, (1 * 4) ($a0) + sw $s2, (2 * 4) ($a0) + sw $s3, (3 * 4) ($a0) + sw $s4, (4 * 4) ($a0) + sw $s5, (5 * 4) ($a0) + sw $s6, (6 * 4) ($a0) + sw $s7, (7 * 4) ($a0) + sw $s8, (8 * 4) ($a0) # frame pointer + sw $ra, (9 * 4) ($a0) # return address + sw $gp, (10 * 4) ($a0) # global data pointer + sw $sp, (11 * 4) ($a0) # stack pointer + j $ra + move $v0, $zero # return a zero for the setjmp call #--------------------------------------- # void longjmp (memaddr uaddr, label_t *env); @@ -357,60 +357,60 @@ setjmp: .globl setjmp # This longjmp differs from the longjmp found in the standard library - # it's actually closer to the resume routine of the 4.3BSD kernel. # - .type longjmp, @function -longjmp: .globl longjmp + .type longjmp, @function +longjmp: .globl longjmp - di # can't let anything in till we get a valid stack... + di # can't let anything in till we get a valid stack... - la $v0, u # pointer to &u - beq $v0, $a0, 2f # if uaddr == &u... - nop # ...no need to remap U area + la $v0, u # pointer to &u + beq $v0, $a0, 2f # if uaddr == &u... + nop # ...no need to remap U area - la $a3, u_end # pointer to &u + USIZE - la $a0, u0 # pointer to &u0 + la $a3, u_end # pointer to &u + USIZE + la $a0, u0 # pointer to &u0 - lw $v1, 0($v0) # u.u_procp - sw $a0, 60($v1) # u.u_procp->p_addr = &u0 + lw $v1, 0($v0) # u.u_procp + sw $a0, 60($v1) # u.u_procp->p_addr = &u0 - # exchange contents of u and u0 - move $v1, $v0 + # exchange contents of u and u0 + move $v1, $v0 1: - lw $t1, 0($v1) - lw $t0, 0($a0) - sw $t0, 0($v1) - sw $t1, 0($a0) - lw $t1, 4($v1) - lw $t0, 4($a0) - sw $t0, 4($v1) - sw $t1, 4($a0) - lw $t1, 8($v1) - lw $t0, 8($a0) - sw $t0, 8($v1) - sw $t1, 8($a0) - lw $t1, 12($v1) - lw $t0, 12($a0) - sw $t0, 12($v1) - sw $t1, 12($a0) - addiu $v1, $v1, 16 - bne $a3, $v1, 1b - addiu $a0, $a0, 16 + lw $t1, 0($v1) + lw $t0, 0($a0) + sw $t0, 0($v1) + sw $t1, 0($a0) + lw $t1, 4($v1) + lw $t0, 4($a0) + sw $t0, 4($v1) + sw $t1, 4($a0) + lw $t1, 8($v1) + lw $t0, 8($a0) + sw $t0, 8($v1) + sw $t1, 8($a0) + lw $t1, 12($v1) + lw $t0, 12($a0) + sw $t0, 12($v1) + sw $t1, 12($a0) + addiu $v1, $v1, 16 + bne $a3, $v1, 1b + addiu $a0, $a0, 16 - lw $v1, 0($v0) # u.u_procp - sw $v0, 60($v1) # u.u_procp->p_addr = &u + lw $v1, 0($v0) # u.u_procp + sw $v0, 60($v1) # u.u_procp->p_addr = &u 2: - lw $s0, (0 * 4) ($a1) # restore register variables s0-s8 - lw $s1, (1 * 4) ($a1) - lw $s2, (2 * 4) ($a1) - lw $s3, (3 * 4) ($a1) - lw $s4, (4 * 4) ($a1) - lw $s5, (5 * 4) ($a1) - lw $s6, (6 * 4) ($a1) - lw $s7, (7 * 4) ($a1) - lw $s8, (8 * 4) ($a1) # frame pointer - lw $ra, (9 * 4) ($a1) # return address - lw $gp, (10 * 4) ($a1) # global data pointer - lw $sp, (11 * 4) ($a1) # stack pointer + lw $s0, (0 * 4) ($a1) # restore register variables s0-s8 + lw $s1, (1 * 4) ($a1) + lw $s2, (2 * 4) ($a1) + lw $s3, (3 * 4) ($a1) + lw $s4, (4 * 4) ($a1) + lw $s5, (5 * 4) ($a1) + lw $s6, (6 * 4) ($a1) + lw $s7, (7 * 4) ($a1) + lw $s8, (8 * 4) ($a1) # frame pointer + lw $ra, (9 * 4) ($a1) # return address + lw $gp, (10 * 4) ($a1) # global data pointer + lw $sp, (11 * 4) ($a1) # stack pointer - ei # release interrupts - j $ra # transfer back to setjmp() - li $v0, 1 # return value of 1 + ei # release interrupts + j $ra # transfer back to setjmp() + li $v0, 1 # return value of 1 diff --git a/sys/pic32/swap.c b/sys/pic32/swap.c index 5ad63a2..1feb0fa 100644 --- a/sys/pic32/swap.c +++ b/sys/pic32/swap.c @@ -24,15 +24,12 @@ const struct devspec swapcdevs[] = { { 0, "temp0" }, { 1, "temp1" }, { 2, "temp2 extern struct buf *getnewbuf(); -static unsigned int tdsize[NTMP]; // Number of blocks allocated +static unsigned int tdsize[NTMP]; // Number of blocks allocated static unsigned int tdstart[NTMP]; // Starting location in map extern dev_t swapdev; extern int physio(void (*strat) (struct buf*), - register struct buf *bp, - dev_t dev, - int rw, - register struct uio *uio); + struct buf *bp, dev_t dev, int rw, struct uio *uio); extern void swap(size_t blkno, size_t coreaddr, register int count, int rdflg); @@ -81,7 +78,7 @@ int swcopen(dev_t dev, int mode, int flag) printf("temp%d: Device number out of range\n", minor(dev)); return ENODEV; } - return 0; + return 0; } int swcclose(dev_t dev, int mode, int flag) @@ -91,16 +88,16 @@ int swcclose(dev_t dev, int mode, int flag) if (unit >= NTMP) return ENODEV; - return 0; + return 0; } int swcread(dev_t dev, register struct uio *uio, int flag) { - unsigned int block; - unsigned int boff; - struct buf *bp; - unsigned int rsize; - unsigned int rlen; + unsigned int block; + unsigned int boff; + struct buf *bp; + unsigned int rsize; + unsigned int rlen; int unit = minor(dev); if (unit >= NTMP) { @@ -108,40 +105,40 @@ int swcread(dev_t dev, register struct uio *uio, int flag) return ENODEV; } - if (tdstart[unit] == 0) - return EIO; + if (tdstart[unit] == 0) + return EIO; - if (uio->uio_offset >= tdsize[unit] << 10) - return EIO; + if (uio->uio_offset >= tdsize[unit] << 10) + return EIO; - bp = getnewbuf(); + bp = getnewbuf(); - block = uio->uio_offset >> 10; - boff = uio->uio_offset - (block << 10); + block = uio->uio_offset >> 10; + boff = uio->uio_offset - (block << 10); - rsize = DEV_BSIZE - boff; - rlen = uio->uio_iov->iov_len; + rsize = DEV_BSIZE - boff; + rlen = uio->uio_iov->iov_len; - while((rlen > 0) && (block < tdsize[unit])) { - swap(tdstart[unit] + block, (size_t)bp->b_addr, DEV_BSIZE, B_READ); - uiomove(bp->b_addr+boff, rsize, uio); - boff = 0; - block++; - rlen -= rsize; - rsize = rlen >= DEV_BSIZE ? DEV_BSIZE : rlen; - } + while((rlen > 0) && (block < tdsize[unit])) { + swap(tdstart[unit] + block, (size_t)bp->b_addr, DEV_BSIZE, B_READ); + uiomove(bp->b_addr+boff, rsize, uio); + boff = 0; + block++; + rlen -= rsize; + rsize = rlen >= DEV_BSIZE ? DEV_BSIZE : rlen; + } - brelse(bp); - return 0; + brelse(bp); + return 0; } int swcwrite(dev_t dev, register struct uio *uio, int flag) { - unsigned int block; - unsigned int boff; - struct buf *bp; - unsigned int rsize; - unsigned int rlen; + unsigned int block; + unsigned int boff; + struct buf *bp; + unsigned int rsize; + unsigned int rlen; int unit = minor(dev); if (unit >= NTMP) { @@ -149,40 +146,40 @@ int swcwrite(dev_t dev, register struct uio *uio, int flag) return ENODEV; } - if (tdstart[unit] == 0) { + if (tdstart[unit] == 0) { printf("temp%d: attempt to write with no allocation\n", unit); - return EIO; + return EIO; } - if (uio->uio_offset >= tdsize[unit] << 10) { + if (uio->uio_offset >= tdsize[unit] << 10) { printf("temp%d: attempt to write past end of allocation\n", unit); - return EIO; + return EIO; } - bp = getnewbuf(); + bp = getnewbuf(); - block = uio->uio_offset >> 10; - boff = uio->uio_offset - (block << 10); + block = uio->uio_offset >> 10; + boff = uio->uio_offset - (block << 10); - rsize = DEV_BSIZE - boff; - rlen = uio->uio_iov->iov_len; + rsize = DEV_BSIZE - boff; + rlen = uio->uio_iov->iov_len; - while((rlen > 0) && (block < tdsize[unit])) { - uiomove(bp->b_addr+boff, rsize, uio); - swap(tdstart[unit] + block, (size_t)bp->b_addr, DEV_BSIZE, B_WRITE); - boff = 0; - block++; - rlen -= rsize; - rsize = rlen >= DEV_BSIZE ? DEV_BSIZE : rlen; - } + while (rlen > 0 && block < tdsize[unit]) { + uiomove(bp->b_addr+boff, rsize, uio); + swap(tdstart[unit] + block, (size_t)bp->b_addr, DEV_BSIZE, B_WRITE); + boff = 0; + block++; + rlen -= rsize; + rsize = rlen >= DEV_BSIZE ? DEV_BSIZE : rlen; + } - brelse(bp); - return 0; + brelse(bp); + return 0; } int swcioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag) { - unsigned int *uival; + unsigned int *uival; off_t *offtval; int unit = minor(dev); @@ -191,35 +188,34 @@ int swcioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag) return ENODEV; } - uival = (unsigned int *)addr; + uival = (unsigned int *)addr; offtval = (off_t *)addr; - switch(cmd) - { - case TFALLOC: - if (tdstart[unit] > 0) - mfree(swapmap, tdsize[unit], tdstart[unit]); + switch (cmd) { + case TFALLOC: + if (tdstart[unit] > 0) + mfree(swapmap, tdsize[unit], tdstart[unit]); - if (*offtval > 0) { - tdstart[unit] = malloc(swapmap, *offtval); - if (tdstart[unit] > 0) { - tdsize[unit] = *offtval; - //printf("temp%d: allocated %lu blocks\n", unit, tdsize[unit]); - return 0; - } - *offtval = 0; - printf("temp%d: failed to allocate %lu blocks\n", tdsize[unit]); + if (*offtval > 0) { + tdstart[unit] = malloc(swapmap, *offtval); + if (tdstart[unit] > 0) { + tdsize[unit] = *offtval; + //printf("temp%d: allocated %lu blocks\n", unit, tdsize[unit]); return 0; - } else { - //printf("temp%d: released allocation\n", unit); } - break; + *offtval = 0; + printf("temp%d: failed to allocate %lu blocks\n", tdsize[unit]); + return 0; + } else { + //printf("temp%d: released allocation\n", unit); + } + break; - case RDGETMEDIASIZE: - *uival = swsize(dev); - break; + case RDGETMEDIASIZE: + *uival = swsize(dev); + break; } - return EINVAL; + return EINVAL; } void swstrategy(register struct buf *bp) diff --git a/sys/pic32/sysctl.c b/sys/pic32/sysctl.c index db5c8a7..230e762 100644 --- a/sys/pic32/sysctl.c +++ b/sys/pic32/sysctl.c @@ -26,158 +26,158 @@ * Errno messages. */ static const char *errlist[] = { - "Undefined error: 0", /* 0 - ENOERROR */ - "Operation not permitted", /* 1 - EPERM */ - "No such file or directory", /* 2 - ENOENT */ - "No such process", /* 3 - ESRCH */ - "Interrupted system call", /* 4 - EINTR */ - "Input/output error", /* 5 - EIO */ - "Device not configured", /* 6 - ENXIO */ - "Argument list too long", /* 7 - E2BIG */ - "Exec format error", /* 8 - ENOEXEC */ - "Bad file descriptor", /* 9 - EBADF */ - "No child processes", /* 10 - ECHILD */ - "No more processes", /* 11 - EAGAIN */ - "Cannot allocate memory", /* 12 - ENOMEM */ - "Permission denied", /* 13 - EACCES */ - "Bad address", /* 14 - EFAULT */ - "Block device required", /* 15 - ENOTBLK */ - "Device busy", /* 16 - EBUSY */ - "File exists", /* 17 - EEXIST */ - "Cross-device link", /* 18 - EXDEV */ - "Operation not supported by device", /* 19 - ENODEV */ - "Not a directory", /* 20 - ENOTDIR */ - "Is a directory", /* 21 - EISDIR */ - "Invalid argument", /* 22 - EINVAL */ - "Too many open files in system", /* 23 - ENFILE */ - "Too many open files", /* 24 - EMFILE */ - "Inappropriate ioctl for device", /* 25 - ENOTTY */ - "Text file busy", /* 26 - ETXTBSY */ - "File too large", /* 27 - EFBIG */ - "No space left on device", /* 28 - ENOSPC */ - "Illegal seek", /* 29 - ESPIPE */ - "Read-only file system", /* 30 - EROFS */ - "Too many links", /* 31 - EMLINK */ - "Broken pipe", /* 32 - EPIPE */ + "Undefined error: 0", /* 0 - ENOERROR */ + "Operation not permitted", /* 1 - EPERM */ + "No such file or directory", /* 2 - ENOENT */ + "No such process", /* 3 - ESRCH */ + "Interrupted system call", /* 4 - EINTR */ + "Input/output error", /* 5 - EIO */ + "Device not configured", /* 6 - ENXIO */ + "Argument list too long", /* 7 - E2BIG */ + "Exec format error", /* 8 - ENOEXEC */ + "Bad file descriptor", /* 9 - EBADF */ + "No child processes", /* 10 - ECHILD */ + "No more processes", /* 11 - EAGAIN */ + "Cannot allocate memory", /* 12 - ENOMEM */ + "Permission denied", /* 13 - EACCES */ + "Bad address", /* 14 - EFAULT */ + "Block device required", /* 15 - ENOTBLK */ + "Device busy", /* 16 - EBUSY */ + "File exists", /* 17 - EEXIST */ + "Cross-device link", /* 18 - EXDEV */ + "Operation not supported by device", /* 19 - ENODEV */ + "Not a directory", /* 20 - ENOTDIR */ + "Is a directory", /* 21 - EISDIR */ + "Invalid argument", /* 22 - EINVAL */ + "Too many open files in system", /* 23 - ENFILE */ + "Too many open files", /* 24 - EMFILE */ + "Inappropriate ioctl for device", /* 25 - ENOTTY */ + "Text file busy", /* 26 - ETXTBSY */ + "File too large", /* 27 - EFBIG */ + "No space left on device", /* 28 - ENOSPC */ + "Illegal seek", /* 29 - ESPIPE */ + "Read-only file system", /* 30 - EROFS */ + "Too many links", /* 31 - EMLINK */ + "Broken pipe", /* 32 - EPIPE */ /* math software */ - "Numerical argument out of domain", /* 33 - EDOM */ - "Result too large", /* 34 - ERANGE */ + "Numerical argument out of domain", /* 33 - EDOM */ + "Result too large", /* 34 - ERANGE */ /* non-blocking and interrupt i/o */ - "Resource temporarily unavailable", /* 35 - EWOULDBLOCK */ - "Operation now in progress", /* 36 - EINPROGRESS */ - "Operation already in progress", /* 37 - EALREADY */ + "Resource temporarily unavailable", /* 35 - EWOULDBLOCK */ + "Operation now in progress", /* 36 - EINPROGRESS */ + "Operation already in progress", /* 37 - EALREADY */ /* ipc/network software -- argument errors */ - "Socket operation on non-socket", /* 38 - ENOTSOCK */ - "Destination address required", /* 39 - EDESTADDRREQ */ - "Message too long", /* 40 - EMSGSIZE */ - "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ - "Protocol not available", /* 42 - ENOPROTOOPT */ - "Protocol not supported", /* 43 - EPROTONOSUPPORT */ - "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ - "Operation not supported", /* 45 - EOPNOTSUPP */ - "Protocol family not supported", /* 46 - EPFNOSUPPORT */ - /* 47 - EAFNOSUPPORT */ - "Address family not supported by protocol family", - "Address already in use", /* 48 - EADDRINUSE */ - "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ + "Socket operation on non-socket", /* 38 - ENOTSOCK */ + "Destination address required", /* 39 - EDESTADDRREQ */ + "Message too long", /* 40 - EMSGSIZE */ + "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ + "Protocol not available", /* 42 - ENOPROTOOPT */ + "Protocol not supported", /* 43 - EPROTONOSUPPORT */ + "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ + "Operation not supported", /* 45 - EOPNOTSUPP */ + "Protocol family not supported", /* 46 - EPFNOSUPPORT */ + /* 47 - EAFNOSUPPORT */ + "Address family not supported by protocol family", + "Address already in use", /* 48 - EADDRINUSE */ + "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ /* ipc/network software -- operational errors */ - "Network is down", /* 50 - ENETDOWN */ - "Network is unreachable", /* 51 - ENETUNREACH */ - "Network dropped connection on reset", /* 52 - ENETRESET */ - "Software caused connection abort", /* 53 - ECONNABORTED */ - "Connection reset by peer", /* 54 - ECONNRESET */ - "No buffer space available", /* 55 - ENOBUFS */ - "Socket is already connected", /* 56 - EISCONN */ - "Socket is not connected", /* 57 - ENOTCONN */ - "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ - "Too many references: can't splice", /* 59 - ETOOMANYREFS */ - "Operation timed out", /* 60 - ETIMEDOUT */ - "Connection refused", /* 61 - ECONNREFUSED */ + "Network is down", /* 50 - ENETDOWN */ + "Network is unreachable", /* 51 - ENETUNREACH */ + "Network dropped connection on reset", /* 52 - ENETRESET */ + "Software caused connection abort", /* 53 - ECONNABORTED */ + "Connection reset by peer", /* 54 - ECONNRESET */ + "No buffer space available", /* 55 - ENOBUFS */ + "Socket is already connected", /* 56 - EISCONN */ + "Socket is not connected", /* 57 - ENOTCONN */ + "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ + "Too many references: can't splice", /* 59 - ETOOMANYREFS */ + "Operation timed out", /* 60 - ETIMEDOUT */ + "Connection refused", /* 61 - ECONNREFUSED */ - "Too many levels of symbolic links", /* 62 - ELOOP */ - "File name too long", /* 63 - ENAMETOOLONG */ + "Too many levels of symbolic links", /* 62 - ELOOP */ + "File name too long", /* 63 - ENAMETOOLONG */ /* should be rearranged */ - "Host is down", /* 64 - EHOSTDOWN */ - "No route to host", /* 65 - EHOSTUNREACH */ - "Directory not empty", /* 66 - ENOTEMPTY */ + "Host is down", /* 64 - EHOSTDOWN */ + "No route to host", /* 65 - EHOSTUNREACH */ + "Directory not empty", /* 66 - ENOTEMPTY */ /* quotas & mush */ - "Too many processes", /* 67 - EPROCLIM */ - "Too many users", /* 68 - EUSERS */ - "Disc quota exceeded", /* 69 - EDQUOT */ + "Too many processes", /* 67 - EPROCLIM */ + "Too many users", /* 68 - EUSERS */ + "Disc quota exceeded", /* 69 - EDQUOT */ /* Network File System */ - "Stale NFS file handle", /* 70 - ESTALE */ - "Too many levels of remote in path", /* 71 - EREMOTE */ - "RPC struct is bad", /* 72 - EBADRPC */ - "RPC version wrong", /* 73 - ERPCMISMATCH */ - "RPC prog. not avail", /* 74 - EPROGUNAVAIL */ - "Program version wrong", /* 75 - EPROGMISMATCH */ - "Bad procedure for program", /* 76 - EPROCUNAVAIL */ + "Stale NFS file handle", /* 70 - ESTALE */ + "Too many levels of remote in path", /* 71 - EREMOTE */ + "RPC struct is bad", /* 72 - EBADRPC */ + "RPC version wrong", /* 73 - ERPCMISMATCH */ + "RPC prog. not avail", /* 74 - EPROGUNAVAIL */ + "Program version wrong", /* 75 - EPROGMISMATCH */ + "Bad procedure for program", /* 76 - EPROCUNAVAIL */ - "No locks available", /* 77 - ENOLCK */ - "Function not implemented", /* 78 - ENOSYS */ - "Inappropriate file type or format", /* 79 - EFTYPE */ - "Authentication error", /* 80 - EAUTH */ - "Need authenticator", /* 81 - ENEEDAUTH */ + "No locks available", /* 77 - ENOLCK */ + "Function not implemented", /* 78 - ENOSYS */ + "Inappropriate file type or format", /* 79 - EFTYPE */ + "Authentication error", /* 80 - EAUTH */ + "Need authenticator", /* 81 - ENEEDAUTH */ }; /* * Kernel symbol name list. */ static const struct { - const char *name; - int addr; + const char *name; + int addr; } nlist[] = { - { "_boottime", (int) &boottime }, /* vmstat */ - { "_cnttys", (int) &cnttys }, /* pstat */ - { "_cp_time", (int) &cp_time }, /* iostat vmstat */ - { "_dk_busy", (int) &dk_busy }, /* iostat */ - { "_dk_name", (int) &dk_name }, /* iostat vmstat */ - { "_dk_ndrive", (int) &dk_ndrive }, /* iostat vmstat */ - { "_dk_unit", (int) &dk_unit }, /* iostat vmstat */ - { "_dk_bytes", (int) &dk_bytes }, /* iostat */ - { "_dk_xfer", (int) &dk_xfer }, /* iostat vmstat */ - { "_file", (int) &file }, /* pstat */ - { "_forkstat", (int) &forkstat }, /* vmstat */ + { "_boottime", (int) &boottime }, /* vmstat */ + { "_cnttys", (int) &cnttys }, /* pstat */ + { "_cp_time", (int) &cp_time }, /* iostat vmstat */ + { "_dk_busy", (int) &dk_busy }, /* iostat */ + { "_dk_name", (int) &dk_name }, /* iostat vmstat */ + { "_dk_ndrive", (int) &dk_ndrive }, /* iostat vmstat */ + { "_dk_unit", (int) &dk_unit }, /* iostat vmstat */ + { "_dk_bytes", (int) &dk_bytes }, /* iostat */ + { "_dk_xfer", (int) &dk_xfer }, /* iostat vmstat */ + { "_file", (int) &file }, /* pstat */ + { "_forkstat", (int) &forkstat }, /* vmstat */ #ifdef UCB_METER - { "_freemem", (int) &freemem }, /* vmstat */ + { "_freemem", (int) &freemem }, /* vmstat */ #endif - { "_hz", (int) &hz }, /* ps */ - { "_inode", (int) &inode }, /* pstat */ - { "_ipc", (int) &ipc }, /* ps */ - { "_lbolt", (int) &lbolt }, /* ps */ - { "_memlock", (int) &memlock }, /* ps */ - { "_nchstats", (int) &nchstats }, /* vmstat */ - { "_nproc", (int) &nproc }, /* ps pstat */ - { "_nswap", (int) &nswap }, /* pstat */ - { "_proc", (int) &proc }, /* ps pstat */ - { "_runin", (int) &runin }, /* ps */ - { "_runout", (int) &runout }, /* ps */ - { "_selwait", (int) &selwait }, /* ps */ - { "_swapmap", (int) &swapmap }, /* pstat */ - { "_tk_nin", (int) &tk_nin }, /* iostat */ - { "_tk_nout", (int) &tk_nout }, /* iostat */ - { "_total", (int) &total }, /* vmstat */ - { "_u", (int) &u }, /* ps */ + { "_hz", (int) &hz }, /* ps */ + { "_inode", (int) &inode }, /* pstat */ + { "_ipc", (int) &ipc }, /* ps */ + { "_lbolt", (int) &lbolt }, /* ps */ + { "_memlock", (int) &memlock }, /* ps */ + { "_nchstats", (int) &nchstats }, /* vmstat */ + { "_nproc", (int) &nproc }, /* ps pstat */ + { "_nswap", (int) &nswap }, /* pstat */ + { "_proc", (int) &proc }, /* ps pstat */ + { "_runin", (int) &runin }, /* ps */ + { "_runout", (int) &runout }, /* ps */ + { "_selwait", (int) &selwait }, /* ps */ + { "_swapmap", (int) &swapmap }, /* pstat */ + { "_tk_nin", (int) &tk_nin }, /* iostat */ + { "_tk_nout", (int) &tk_nout }, /* iostat */ + { "_total", (int) &total }, /* vmstat */ + { "_u", (int) &u }, /* ps */ #if NPTY > 0 - { "_npty", (int) &npty }, /* pstat */ - { "_pt_tty", (int) &pt_tty }, /* pstat */ + { "_npty", (int) &npty }, /* pstat */ + { "_pt_tty", (int) &pt_tty }, /* pstat */ #endif #ifdef UCB_METER - { "_rate", (int) &rate }, /* vmstat */ - { "_sum", (int) &sum }, /* vmstat */ + { "_rate", (int) &rate }, /* vmstat */ + { "_sum", (int) &sum }, /* vmstat */ #endif - { "_bdevsw", (int) &bdevsw }, /* devupdate */ - { "_cdevsw", (int) &cdevsw }, /* devupdate */ - { "_nblkdev", (int) &nblkdev }, /* devupdate */ - { "_nchrdev", (int) &nchrdev }, /* devupdate */ - { 0, 0 }, + { "_bdevsw", (int) &bdevsw }, /* devupdate */ + { "_cdevsw", (int) &cdevsw }, /* devupdate */ + { "_nblkdev", (int) &nblkdev }, /* devupdate */ + { "_nchrdev", (int) &nchrdev }, /* devupdate */ + { 0, 0 }, }; /* @@ -188,26 +188,26 @@ static const struct { void ucall() { - register struct a { - int priority; - int (*routine)(); - int arg1; - int arg2; - } *uap = (struct a *)u.u_arg; - int s; + register struct a { + int priority; + int (*routine)(); + int arg1; + int arg2; + } *uap = (struct a *)u.u_arg; + int s; - if (!suser()) - return; - switch (uap->priority) { - case 0: - s = spl0(); - break; - default: - s = splhigh(); - break; - } - u.u_rval = (*uap->routine) (uap->arg1, uap->arg2); - splx(s); + if (!suser()) + return; + switch (uap->priority) { + case 0: + s = spl0(); + break; + default: + s = splhigh(); + break; + } + u.u_rval = (*uap->routine) (uap->arg1, uap->arg2); + splx(s); } /* @@ -218,31 +218,31 @@ ucall() void ufetch() { - unsigned addr = *(unsigned*) u.u_arg & ~3; + unsigned addr = *(unsigned*) u.u_arg & ~3; - /* Check root privileges */ - if (! suser()) - return; + /* Check root privileges */ + if (! suser()) + return; - /* Low memory address - assume peripheral i/o space. */ - if (addr < 0x90000) - addr += 0xbf800000; + /* Low memory address - assume peripheral i/o space. */ + if (addr < 0x90000) + addr += 0xbf800000; - /* Check address */ - if (! (addr >= 0x9d000000 && addr < 0x9d000000 + FLASH_SIZE) && - ! (addr >= 0xbd000000 && addr < 0xbd000000 + FLASH_SIZE) && + /* Check address */ + if (! (addr >= 0x9d000000 && addr < 0x9d000000 + FLASH_SIZE) && + ! (addr >= 0xbd000000 && addr < 0xbd000000 + FLASH_SIZE) && - /* Boot flash memory */ - ! (addr >= 0x9fc00000 && addr < 0x9fc00000 + 12*1024) && - ! (addr >= 0xbfc00000 && addr < 0xbfc00000 + 12*1024) && + /* Boot flash memory */ + ! (addr >= 0x9fc00000 && addr < 0x9fc00000 + 12*1024) && + ! (addr >= 0xbfc00000 && addr < 0xbfc00000 + 12*1024) && - /* Peripheral registers */ - ! (addr >= 0xbf800000 && addr < 0xbf810000) && - ! (addr >= 0xbf880000 && addr < 0xbf890000)) { - u.u_error = EFAULT; - return; - } - u.u_rval = *(unsigned*) addr; + /* Peripheral registers */ + ! (addr >= 0xbf800000 && addr < 0xbf810000) && + ! (addr >= 0xbf880000 && addr < 0xbf890000)) { + u.u_error = EFAULT; + return; + } + u.u_rval = *(unsigned*) addr; } /* @@ -251,27 +251,27 @@ ufetch() void ustore() { - register struct a { - unsigned addr; - unsigned value; - } *uap = (struct a *)u.u_arg; - unsigned addr = uap->addr & ~3; + register struct a { + unsigned addr; + unsigned value; + } *uap = (struct a *)u.u_arg; + unsigned addr = uap->addr & ~3; - /* Check root privileges */ - if (! suser()) - return; + /* Check root privileges */ + if (! suser()) + return; - /* Low memory address - assume peripheral i/o space. */ - if (addr < 0x90000) - addr += 0xbf800000; + /* Low memory address - assume peripheral i/o space. */ + if (addr < 0x90000) + addr += 0xbf800000; - /* Check address */ - if (! (addr >= 0xbf800000 && addr < 0xbf810000) && - ! (addr >= 0xbf880000 && addr < 0xbf890000)) { - u.u_error = EFAULT; - return; - } - *(unsigned*) addr = uap->value; + /* Check address */ + if (! (addr >= 0xbf800000 && addr < 0xbf810000) && + ! (addr >= 0xbf880000 && addr < 0xbf890000)) { + u.u_error = EFAULT; + return; + } + *(unsigned*) addr = uap->value; } /* @@ -280,81 +280,81 @@ ustore() */ int cpu_sysctl (name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; + int *name; + u_int namelen; + void *oldp; + size_t *oldlenp; + void *newp; + size_t newlen; { - int i; + int i; - switch (name[0]) { - case CPU_CONSDEV: - if (namelen != 1) - return ENOTDIR; - return sysctl_rdstruct (oldp, oldlenp, newp, - &cnttys[0].t_dev, sizeof &cnttys[0].t_dev); + switch (name[0]) { + case CPU_CONSDEV: + if (namelen != 1) + return ENOTDIR; + return sysctl_rdstruct (oldp, oldlenp, newp, + &cnttys[0].t_dev, sizeof &cnttys[0].t_dev); #if NTMSCP > 0 - case CPU_TMSCP: - /* All sysctl names at this level are terminal */ - if (namelen != 2) - return ENOTDIR; - switch (name[1]) { - case TMSCP_CACHE: - return sysctl_int (oldp, oldlenp, newp, - newlen, &tmscpcache); - case TMSCP_PRINTF: - return sysctl_int (oldp, oldlenp, newp, - newlen, &tmscpprintf); - default: - } + case CPU_TMSCP: + /* All sysctl names at this level are terminal */ + if (namelen != 2) + return ENOTDIR; + switch (name[1]) { + case TMSCP_CACHE: + return sysctl_int (oldp, oldlenp, newp, + newlen, &tmscpcache); + case TMSCP_PRINTF: + return sysctl_int (oldp, oldlenp, newp, + newlen, &tmscpprintf); + default: + } #endif - case CPU_ERRMSG: - if (namelen != 2) - return ENOTDIR; - if (name[1] < 1 || - name[1] >= sizeof(errlist) / sizeof(errlist[0])) - return EOPNOTSUPP; - return sysctl_string(oldp, oldlenp, 0, 0, - (char*) errlist[name[1]], - 1 + strlen(errlist[name[1]])); + case CPU_ERRMSG: + if (namelen != 2) + return ENOTDIR; + if (name[1] < 1 || + name[1] >= sizeof(errlist) / sizeof(errlist[0])) + return EOPNOTSUPP; + return sysctl_string(oldp, oldlenp, 0, 0, + (char*) errlist[name[1]], + 1 + strlen(errlist[name[1]])); - case CPU_NLIST: - for (i=0; nlist[i].name; i++) { - if (strncmp (newp, nlist[i].name, newlen) == 0) { - int addr = nlist[i].addr; - if (! oldp) - return 0; - if (*oldlenp < sizeof(int)) - return ENOMEM; - *oldlenp = sizeof(int); - return copyout ((caddr_t) &addr, (caddr_t) oldp, sizeof(int)); - } - } - return EOPNOTSUPP; + case CPU_NLIST: + for (i=0; nlist[i].name; i++) { + if (strncmp (newp, nlist[i].name, newlen) == 0) { + int addr = nlist[i].addr; + if (! oldp) + return 0; + if (*oldlenp < sizeof(int)) + return ENOMEM; + *oldlenp = sizeof(int); + return copyout ((caddr_t) &addr, (caddr_t) oldp, sizeof(int)); + } + } + return EOPNOTSUPP; - case CPU_TIMO_CMD: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_cmd); - case CPU_TIMO_SEND_OP: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_send_op); - case CPU_TIMO_SEND_CSD: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_send_csd); - case CPU_TIMO_READ: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_read); - case CPU_TIMO_WAIT_CMD: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_cmd); - case CPU_TIMO_WAIT_WDATA: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_wdata); - case CPU_TIMO_WAIT_WDONE: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_wdone); - case CPU_TIMO_WAIT_WSTOP: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_wstop); - case CPU_TIMO_WAIT_WIDLE: - return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_widle); + case CPU_TIMO_CMD: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_cmd); + case CPU_TIMO_SEND_OP: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_send_op); + case CPU_TIMO_SEND_CSD: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_send_csd); + case CPU_TIMO_READ: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_read); + case CPU_TIMO_WAIT_CMD: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_cmd); + case CPU_TIMO_WAIT_WDATA: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_wdata); + case CPU_TIMO_WAIT_WDONE: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_wdone); + case CPU_TIMO_WAIT_WSTOP: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_wstop); + case CPU_TIMO_WAIT_WIDLE: + return sysctl_int(oldp, oldlenp, newp, newlen, &sd_timo_wait_widle); - default: - return EOPNOTSUPP; - } - /* NOTREACHED */ + default: + return EOPNOTSUPP; + } + /* NOTREACHED */ } diff --git a/sys/pic32/usb_boot.c b/sys/pic32/usb_boot.c index 3bc337c..8057a7c 100644 --- a/sys/pic32/usb_boot.c +++ b/sys/pic32/usb_boot.c @@ -44,27 +44,27 @@ /* * Commands of bootloader protocol. */ -#define QUERY_DEVICE 0x02 // Command that the host uses to learn +#define QUERY_DEVICE 0x02 // Command that the host uses to learn // about the device (what regions can be // programmed, and what type of memory // is the region) -#define UNLOCK_CONFIG 0x03 // Note, this command is used for both +#define UNLOCK_CONFIG 0x03 // Note, this command is used for both // locking and unlocking the config bits -#define ERASE_DEVICE 0x04 // Host sends this command to start +#define ERASE_DEVICE 0x04 // Host sends this command to start // an erase operation. Firmware controls // which pages should be erased. -#define PROGRAM_DEVICE 0x05 // If host is going to send a full +#define PROGRAM_DEVICE 0x05 // If host is going to send a full // REQUEST_SIZE to be programmed, it // uses this command. -#define PROGRAM_COMPLETE 0x06 // If host send less than a REQUEST_SIZE +#define PROGRAM_COMPLETE 0x06 // If host send less than a REQUEST_SIZE // to be programmed, or if it wished // to program whatever was left in // the buffer, it uses this command. -#define GET_DATA 0x07 // The host sends this command in order +#define GET_DATA 0x07 // The host sends this command in order // to read out memory from the device. // Used during verify (and read/export // hex operations) -#define RESET_DEVICE 0x08 // Resets the microcontroller, so it can +#define RESET_DEVICE 0x08 // Resets the microcontroller, so it can // update the config bits (if they were // programmed, and so as to leave // the bootloader (and potentially go back @@ -73,7 +73,7 @@ /* * HID packet structure. */ -#define PACKET_SIZE 64 // HID packet size +#define PACKET_SIZE 64 // HID packet size #define REQUEST_SIZE 56 // Number of bytes of a standard request typedef union __attribute__ ((packed)) @@ -101,7 +101,7 @@ typedef union __attribute__ ((packed)) unsigned char Type3; unsigned long Address3; unsigned long Length3; - unsigned char Type4; // End of sections list indicator goes here, fill with 0xFF. + unsigned char Type4; // End of sections list indicator goes here, fill with 0xFF. unsigned char ExtraPadBytes[33]; } query; } packet_t; @@ -279,10 +279,10 @@ static inline void cinit() */ U1BRG = PIC32_BRG_BAUD (CPU_KHZ * 1000, 115200); U1STA = 0; - U1MODE = PIC32_UMODE_PDSEL_8NPAR | /* 8-bit data, no parity */ - PIC32_UMODE_ON; /* UART Enable */ - U1STASET = PIC32_USTA_URXEN | /* Receiver Enable */ - PIC32_USTA_UTXEN; /* Transmit Enable */ + U1MODE = PIC32_UMODE_PDSEL_8NPAR | /* 8-bit data, no parity */ + PIC32_UMODE_ON; /* UART Enable */ + U1STASET = PIC32_USTA_URXEN | /* Receiver Enable */ + PIC32_USTA_UTXEN; /* Transmit Enable */ } /* @@ -605,16 +605,16 @@ int main() (! (RCON & PIC32_RCON_SWR) || reset_key != 0x12345678)) { // Must clear out software key - reset_key = 0; + reset_key = 0; // If there is NO real program to execute, then fall through to the bootloader - if (*(int*) FLASH_JUMP != 0xFFFFFFFF) { + if (*(int*) FLASH_JUMP != 0xFFFFFFFF) { void (*fptr)(void) = (void (*)(void)) FLASH_JUMP; fptr(); for (;;) continue; - } + } } // Must clear out software key. reset_key = 0; @@ -629,7 +629,7 @@ int main() USB_HANDLE reply_handle = 0; int packet_received = 0; for (;;) { - // Check bus status and service USB interrupts. + // Check bus status and service USB interrupts. usb_device_tasks(); // Blink the LEDs according to the USB device status diff --git a/sys/pic32/usb_ch9.h b/sys/pic32/usb_ch9.h index d9fbef5..13ffad4 100644 --- a/sys/pic32/usb_ch9.h +++ b/sys/pic32/usb_ch9.h @@ -29,15 +29,15 @@ // // Section: USB Descriptors // -#define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor. -#define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor. -#define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor. -#define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor. -#define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor. -#define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier. -#define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration. -#define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power. -#define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor. +#define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor. +#define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor. +#define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor. +#define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor. +#define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor. +#define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier. +#define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration. +#define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power. +#define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor. /* * USB Device Descriptor Structure @@ -48,20 +48,20 @@ */ typedef struct __attribute__ ((packed)) _USB_DEVICE_DESCRIPTOR { - unsigned char bLength; // Length of this descriptor. - unsigned char bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE). - unsigned short bcdUSB; // USB Spec Release Number (BCD). - unsigned char bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. - unsigned char bDeviceSubClass; // Subclass code (assigned by the USB-IF). - unsigned char bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. - unsigned char bMaxPacketSize0; // Maximum packet size for endpoint 0. - unsigned short idVendor; // Vendor ID (assigned by the USB-IF). - unsigned short idProduct; // Product ID (assigned by the manufacturer). - unsigned short bcdDevice; // Device release number (BCD). - unsigned char iManufacturer; // Index of String Descriptor describing the manufacturer. - unsigned char iProduct; // Index of String Descriptor describing the product. - unsigned char iSerialNumber; // Index of String Descriptor with the device's serial number. - unsigned char bNumConfigurations; // Number of possible configurations. + unsigned char bLength; // Length of this descriptor. + unsigned char bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE). + unsigned short bcdUSB; // USB Spec Release Number (BCD). + unsigned char bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. + unsigned char bDeviceSubClass; // Subclass code (assigned by the USB-IF). + unsigned char bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. + unsigned char bMaxPacketSize0; // Maximum packet size for endpoint 0. + unsigned short idVendor; // Vendor ID (assigned by the USB-IF). + unsigned short idProduct; // Product ID (assigned by the manufacturer). + unsigned short bcdDevice; // Device release number (BCD). + unsigned char iManufacturer; // Index of String Descriptor describing the manufacturer. + unsigned char iProduct; // Index of String Descriptor describing the product. + unsigned char iSerialNumber; // Index of String Descriptor with the device's serial number. + unsigned char bNumConfigurations; // Number of possible configurations. } USB_DEVICE_DESCRIPTOR; @@ -74,20 +74,20 @@ typedef struct __attribute__ ((packed)) _USB_DEVICE_DESCRIPTOR */ typedef struct __attribute__ ((packed)) _USB_CONFIGURATION_DESCRIPTOR { - unsigned char bLength; // Length of this descriptor. - unsigned char bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION). - unsigned short wTotalLength; // Total length of all descriptors for this configuration. - unsigned char bNumInterfaces; // Number of interfaces in this configuration. - unsigned char bConfigurationValue; // Value of this configuration (1 based). - unsigned char iConfiguration; // Index of String Descriptor describing the configuration. - unsigned char bmAttributes; // Configuration characteristics. - unsigned char bMaxPower; // Maximum power consumed by this configuration. + unsigned char bLength; // Length of this descriptor. + unsigned char bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION). + unsigned short wTotalLength; // Total length of all descriptors for this configuration. + unsigned char bNumInterfaces; // Number of interfaces in this configuration. + unsigned char bConfigurationValue; // Value of this configuration (1 based). + unsigned char iConfiguration; // Index of String Descriptor describing the configuration. + unsigned char bmAttributes; // Configuration characteristics. + unsigned char bMaxPower; // Maximum power consumed by this configuration. } USB_CONFIGURATION_DESCRIPTOR; // Attributes bits -#define USB_CFG_DSC_REQUIRED 0x80 // Required attribute -#define USB_CFG_DSC_SELF_PWR (0x40 | USB_CFG_DSC_REQUIRED) // Device is self powered. -#define USB_CFG_DSC_REM_WAKE (0x20 | USB_CFG_DSC_REQUIRED) // Device can request remote wakup +#define USB_CFG_DSC_REQUIRED 0x80 // Required attribute +#define USB_CFG_DSC_SELF_PWR (0x40 | USB_CFG_DSC_REQUIRED) // Device is self powered. +#define USB_CFG_DSC_REM_WAKE (0x20 | USB_CFG_DSC_REQUIRED) // Device can request remote wakup /* @@ -99,15 +99,15 @@ typedef struct __attribute__ ((packed)) _USB_CONFIGURATION_DESCRIPTOR */ typedef struct __attribute__ ((packed)) _USB_INTERFACE_DESCRIPTOR { - unsigned char bLength; // Length of this descriptor. - unsigned char bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE). - unsigned char bInterfaceNumber; // Number of this interface (0 based). - unsigned char bAlternateSetting; // Value of this alternate interface setting. - unsigned char bNumEndpoints; // Number of endpoints in this interface. - unsigned char bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. - unsigned char bInterfaceSubClass; // Subclass code (assigned by the USB-IF). - unsigned char bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. - unsigned char iInterface; // Index of String Descriptor describing the interface. + unsigned char bLength; // Length of this descriptor. + unsigned char bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE). + unsigned char bInterfaceNumber; // Number of this interface (0 based). + unsigned char bAlternateSetting; // Value of this alternate interface setting. + unsigned char bNumEndpoints; // Number of endpoints in this interface. + unsigned char bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific. + unsigned char bInterfaceSubClass; // Subclass code (assigned by the USB-IF). + unsigned char bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific. + unsigned char iInterface; // Index of String Descriptor describing the interface. } USB_INTERFACE_DESCRIPTOR; @@ -120,12 +120,12 @@ the correct fields when used on some device architectures. */ typedef struct __attribute__ ((packed)) _USB_ENDPOINT_DESCRIPTOR { - unsigned char bLength; // Length of this descriptor. - unsigned char bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT). - unsigned char bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN). - unsigned char bmAttributes; // Endpoint transfer type. - unsigned short wMaxPacketSize; // Maximum packet size. - unsigned char bInterval; // Polling interval in frames. + unsigned char bLength; // Length of this descriptor. + unsigned char bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT). + unsigned char bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN). + unsigned char bmAttributes; // Endpoint transfer type. + unsigned short wMaxPacketSize; // Maximum packet size. + unsigned char bInterval; // Polling interval in frames. } USB_ENDPOINT_DESCRIPTOR; @@ -174,9 +174,9 @@ the correct fields when used on some device architectures. */ typedef struct __attribute__ ((packed)) _USB_OTG_DESCRIPTOR { - unsigned char bLength; // Length of this descriptor. - unsigned char bDescriptorType; // OTG descriptor type (USB_DESCRIPTOR_OTG). - unsigned char bmAttributes; // OTG attributes. + unsigned char bLength; // Length of this descriptor. + unsigned char bDescriptorType; // OTG descriptor type (USB_DESCRIPTOR_OTG). + unsigned char bmAttributes; // OTG attributes. } USB_OTG_DESCRIPTOR; @@ -198,15 +198,15 @@ typedef struct __attribute__ ((packed)) _USB_OTG_DESCRIPTOR typedef struct __attribute__ ((packed)) _USB_STRING_DSC { - unsigned char bLength; // Size of this descriptor - unsigned char bDescriptorType; // Type, USB_DSC_STRING + unsigned char bLength; // Size of this descriptor + unsigned char bDescriptorType; // Type, USB_DSC_STRING } USB_STRING_DESCRIPTOR; #define USB_STRING_INIT(nchars) struct {\ - unsigned char bLength; \ - unsigned char bDescriptorType; \ - unsigned short string[nchars]; \ + unsigned char bLength; \ + unsigned char bDescriptorType; \ + unsigned short string[nchars]; \ } @@ -223,15 +223,15 @@ typedef struct __attribute__ ((packed)) _USB_STRING_DSC typedef struct __attribute__ ((packed)) _USB_DEVICE_QUALIFIER_DESCRIPTOR { - unsigned char bLength; // Size of this descriptor - unsigned char bType; // Type, always USB_DESCRIPTOR_DEVICE_QUALIFIER - unsigned short bcdUSB; // USB spec version, in BCD - unsigned char bDeviceClass; // Device class code - unsigned char bDeviceSubClass; // Device sub-class code - unsigned char bDeviceProtocol; // Device protocol - unsigned char bMaxPacketSize0; // EP0, max packet size - unsigned char bNumConfigurations; // Number of "other-speed" configurations - unsigned char bReserved; // Always zero (0) + unsigned char bLength; // Size of this descriptor + unsigned char bType; // Type, always USB_DESCRIPTOR_DEVICE_QUALIFIER + unsigned short bcdUSB; // USB spec version, in BCD + unsigned char bDeviceClass; // Device class code + unsigned char bDeviceSubClass; // Device sub-class code + unsigned char bDeviceProtocol; // Device protocol + unsigned char bMaxPacketSize0; // EP0, max packet size + unsigned char bNumConfigurations; // Number of "other-speed" configurations + unsigned char bReserved; // Always zero (0) } USB_DEVICE_QUALIFIER_DESCRIPTOR; @@ -248,20 +248,20 @@ typedef struct __attribute__ ((packed)) _USB_DEVICE_QUALIFIER_DESCRIPTOR typedef struct __attribute__ ((packed)) { - union // offset description - { // ------ ------------------------ - unsigned char bmRequestType; // 0 Bit-map of request type - struct { - unsigned recipient: 5; // Recipient of the request - unsigned type: 2; // Type of request - unsigned direction: 1; // Direction of data X-fer - }; - } requestInfo; + union // offset description + { // ------ ------------------------ + unsigned char bmRequestType; // 0 Bit-map of request type + struct { + unsigned recipient: 5; // Recipient of the request + unsigned type: 2; // Type of request + unsigned direction: 1; // Direction of data X-fer + }; + } requestInfo; - unsigned char bRequest; // 1 Request type - unsigned short wValue; // 2 Depends on bRequest - unsigned short wIndex; // 4 Depends on bRequest - unsigned short wLength; // 6 Depends on bRequest + unsigned char bRequest; // 1 Request type + unsigned short wValue; // 2 Depends on bRequest + unsigned short wIndex; // 4 Depends on bRequest + unsigned short wLength; // 6 Depends on bRequest } SETUP_PKT, *PSETUP_PKT; @@ -271,95 +271,91 @@ typedef struct __attribute__ ((packed)) // // Section: Valid PID Values -//DOM-IGNORE-BEGIN -#define PID_OUT 0x1 // PID for an OUT token -#define PID_ACK 0x2 // PID for an ACK handshake -#define PID_DATA0 0x3 // PID for DATA0 data -#define PID_PING 0x4 // Special PID PING -#define PID_SOF 0x5 // PID for a SOF token -#define PID_NYET 0x6 // PID for a NYET handshake -#define PID_DATA2 0x7 // PID for DATA2 data -#define PID_SPLIT 0x8 // Special PID SPLIT -#define PID_IN 0x9 // PID for a IN token -#define PID_NAK 0xA // PID for a NAK handshake -#define PID_DATA1 0xB // PID for DATA1 data -#define PID_PRE 0xC // Special PID PRE (Same as PID_ERR) -#define PID_ERR 0xC // Special PID ERR (Same as PID_PRE) -#define PID_SETUP 0xD // PID for a SETUP token -#define PID_STALL 0xE // PID for a STALL handshake -#define PID_MDATA 0xF // PID for MDATA data +#define PID_OUT 0x1 // PID for an OUT token +#define PID_ACK 0x2 // PID for an ACK handshake +#define PID_DATA0 0x3 // PID for DATA0 data +#define PID_PING 0x4 // Special PID PING +#define PID_SOF 0x5 // PID for a SOF token +#define PID_NYET 0x6 // PID for a NYET handshake +#define PID_DATA2 0x7 // PID for DATA2 data +#define PID_SPLIT 0x8 // Special PID SPLIT +#define PID_IN 0x9 // PID for a IN token +#define PID_NAK 0xA // PID for a NAK handshake +#define PID_DATA1 0xB // PID for DATA1 data +#define PID_PRE 0xC // Special PID PRE (Same as PID_ERR) +#define PID_ERR 0xC // Special PID ERR (Same as PID_PRE) +#define PID_SETUP 0xD // PID for a SETUP token +#define PID_STALL 0xE // PID for a STALL handshake +#define PID_MDATA 0xF // PID for MDATA data -#define PID_MASK_DATA 0x03 // Data PID mask -#define PID_MASK_DATA_SHIFTED (PID_MASK_DATA << 2) // Data PID shift to proper position -//DOM-IGNORE-END +#define PID_MASK_DATA 0x03 // Data PID mask +#define PID_MASK_DATA_SHIFTED (PID_MASK_DATA << 2) // Data PID shift to proper position // Section: USB Token Types -//DOM-IGNORE-BEGIN -#define USB_TOKEN_OUT 0x01 // U1TOK - OUT token -#define USB_TOKEN_IN 0x09 // U1TOK - IN token -#define USB_TOKEN_SETUP 0x0D // U1TOK - SETUP token -//DOM-IGNORE-END +#define USB_TOKEN_OUT 0x01 // U1TOK - OUT token +#define USB_TOKEN_IN 0x09 // U1TOK - IN token +#define USB_TOKEN_SETUP 0x0D // U1TOK - SETUP token // Section: OTG Descriptor Constants -#define OTG_HNP_SUPPORT 0x02 // OTG Descriptor bmAttributes - HNP support flag -#define OTG_SRP_SUPPORT 0x01 // OTG Descriptor bmAttributes - SRP support flag +#define OTG_HNP_SUPPORT 0x02 // OTG Descriptor bmAttributes - HNP support flag +#define OTG_SRP_SUPPORT 0x01 // OTG Descriptor bmAttributes - SRP support flag // Section: Endpoint Directions -#define USB_IN_EP 0x80 // IN endpoint mask -#define USB_OUT_EP 0x00 // OUT endpoint mask +#define USB_IN_EP 0x80 // IN endpoint mask +#define USB_OUT_EP 0x00 // OUT endpoint mask // Section: Standard Device Requests -#define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS -#define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE -#define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE -#define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS -#define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR -#define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR -#define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION -#define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION -#define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE -#define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE -#define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME +#define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS +#define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE +#define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE +#define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS +#define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR +#define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR +#define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION +#define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION +#define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE +#define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE +#define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME -#define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt -#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up -#define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode +#define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt +#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up +#define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode // Section: Setup Data Constants -#define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer -#define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer -#define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard -#define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class -#define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor -#define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device -#define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface -#define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint -#define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other +#define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer +#define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer +#define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard +#define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class +#define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor +#define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device +#define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface +#define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint +#define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other // Section: OTG SET FEATURE Constants -#define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP -#define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP -#define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP +#define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP +#define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP +#define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP // Section: USB Endpoint Transfer Types -#define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint. -#define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint. -#define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint. -#define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint. +#define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint. +#define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint. +#define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint. +#define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint. // Section: Standard Feature Selectors for CLEAR_FEATURE Requests -#define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient -#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient -#define USB_FEATURE_TEST_MODE 2 // Device recipient +#define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient +#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient +#define USB_FEATURE_TEST_MODE 2 // Device recipient // Section: USB Class Code Definitions -#define USB_HUB_CLASSCODE 0x09 // Class code for a hub. +#define USB_HUB_CLASSCODE 0x09 // Class code for a hub. #endif // _USB_CH9_H_ diff --git a/sys/pic32/usb_console.c b/sys/pic32/usb_console.c index 01830d0..c13cbb8 100644 --- a/sys/pic32/usb_console.c +++ b/sys/pic32/usb_console.c @@ -131,7 +131,7 @@ void cnstart (tp) s = spltty(); if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) { -out: /* Disable transmit_interrupt. */ +out: /* Disable transmit_interrupt. */ led_control (LED_TTY, 0); splx (s); return; @@ -327,8 +327,8 @@ const unsigned char usb_config1_descriptor[] = { /* Configuration Descriptor */ 9, // sizeof(USB_CFG_DSC) - USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type - 67, 0, // Total length of data for this cfg + USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type + 67, 0, // Total length of data for this cfg 2, // Number of interfaces in this cfg 1, // Index value of this configuration 0, // Configuration string index @@ -342,8 +342,8 @@ const unsigned char usb_config1_descriptor[] = 0, // Alternate Setting Number 1, // Number of endpoints in this intf COMM_INTF, // Class code - ABSTRACT_CONTROL_MODEL, // Subclass code - V25TER, // Protocol code + ABSTRACT_CONTROL_MODEL, // Subclass code + V25TER, // Protocol code 0, // Interface string index /* CDC Class-Specific Descriptors */ @@ -371,38 +371,38 @@ const unsigned char usb_config1_descriptor[] = /* Endpoint Descriptor */ 7, // sizeof(USB_EP_DSC) - USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor - _EP02_IN, // EndpointAddress - _INTERRUPT, // Attributes - 0x08, 0x00, // size - 0x02, // Interval + USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor + _EP02_IN, // EndpointAddress + _INTERRUPT, // Attributes + 0x08, 0x00, // size + 0x02, // Interval /* Interface Descriptor */ - 9, // sizeof(USB_INTF_DSC) - USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type - 1, // Interface Number - 0, // Alternate Setting Number - 2, // Number of endpoints in this intf - DATA_INTF, // Class code - 0, // Subclass code - NO_PROTOCOL, // Protocol code - 0, // Interface string index + 9, // sizeof(USB_INTF_DSC) + USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type + 1, // Interface Number + 0, // Alternate Setting Number + 2, // Number of endpoints in this intf + DATA_INTF, // Class code + 0, // Subclass code + NO_PROTOCOL, // Protocol code + 0, // Interface string index /* Endpoint Descriptor */ 7, // sizeof(USB_EP_DSC) - USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor - _EP03_OUT, // EndpointAddress - _BULK, // Attributes - 0x40, 0x00, // size - 0x00, // Interval + USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor + _EP03_OUT, // EndpointAddress + _BULK, // Attributes + 0x40, 0x00, // size + 0x00, // Interval /* Endpoint Descriptor */ 7, // sizeof(USB_EP_DSC) - USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor - _EP03_IN, // EndpointAddress - _BULK, // Attributes - 0x40, 0x00, // size - 0x00, // Interval + USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor + _EP03_IN, // EndpointAddress + _BULK, // Attributes + 0x40, 0x00, // size + 0x00, // Interval }; diff --git a/sys/pic32/usb_device.c b/sys/pic32/usb_device.c index f8f5bac..f8556ba 100644 --- a/sys/pic32/usb_device.c +++ b/sys/pic32/usb_device.c @@ -183,7 +183,7 @@ void usb_device_tasks(void) // if we are in the detached state if (usb_device_state == DETACHED_STATE) { - // Disable module & detach from bus + // Disable module & detach from bus U1CON = 0; // Mask all USB interrupts @@ -191,8 +191,8 @@ void usb_device_tasks(void) // Enable module & attach to bus while (! (U1CON & PIC32_U1CON_USBEN)) { - U1CON |= PIC32_U1CON_USBEN; - } + U1CON |= PIC32_U1CON_USBEN; + } // moved to the attached state usb_device_state = ATTACHED_STATE; @@ -202,7 +202,7 @@ void usb_device_tasks(void) SetConfigurationOptions(); #ifdef USB_SUPPORT_OTG - U1OTGCON = USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; + U1OTGCON = USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; #endif } @@ -215,11 +215,11 @@ void usb_device_tasks(void) * prevent the firmware from misinterpreting this unique event * as a USB bus reset from the USB host. */ - U1IR = 0; // Clear all USB interrupts - U1IE = 0; // Mask all USB interrupts - U1IE = PIC32_U1I_URST | // Unmask RESET interrupt - PIC32_U1I_IDLE; // Unmask IDLE interrupt - usb_device_state = POWERED_STATE; + U1IR = 0; // Clear all USB interrupts + U1IE = 0; // Mask all USB interrupts + U1IE = PIC32_U1I_URST | // Unmask RESET interrupt + PIC32_U1I_IDLE; // Unmask IDLE interrupt + usb_device_state = POWERED_STATE; } #ifdef USB_SUPPORT_OTG @@ -340,9 +340,9 @@ void usb_device_tasks(void) // If the USB FIFO ever gets full, USB bandwidth // utilization can be compromised, and the device // won't be able to receive SETUP packets. - for (i = 0; i < 4; i++) { - if (! (U1IR & PIC32_U1I_TRN)) - break; // USTAT FIFO must be empty. + for (i = 0; i < 4; i++) { + if (! (U1IR & PIC32_U1I_TRN)) + break; // USTAT FIFO must be empty. ustat_saved = U1STAT; U1IR = PIC32_U1I_TRN; @@ -381,8 +381,8 @@ void usb_stall_handler(void) // Set ep0Bo to stall also pBDTEntryEP0OutCurrent->STAT.Val = _USIE|_DAT0|_DTSEN|_BSTALL; } - // Clear stall status - U1EP(0) &= ~PIC32_U1EP_EPSTALL; + // Clear stall status + U1EP(0) &= ~PIC32_U1EP_EPSTALL; } U1IR = PIC32_U1I_STALL; @@ -417,7 +417,7 @@ void usb_suspend(void) * mode. */ - U1OTGIE |= PIC32_U1OTGI_ACTV; // Enable bus activity interrupt + U1OTGIE |= PIC32_U1OTGI_ACTV; // Enable bus activity interrupt U1IR = PIC32_U1I_IDLE; /* @@ -472,17 +472,17 @@ void usb_ctrl_ep_service(void) // If the last packet was a EP0 OUT packet if ((ustat_saved & USTAT_EP0_PP_MASK) == USTAT_EP0_OUT_EVEN) { - // Point to the EP0 OUT buffer of the buffer that arrived + // Point to the EP0 OUT buffer of the buffer that arrived pBDTEntryEP0OutCurrent = (volatile BDT_ENTRY*) &usb_buffer [(ustat_saved & USTAT_EP_MASK) >> 2]; - // Set the next out to the current out packet + // Set the next out to the current out packet pBDTEntryEP0OutNext = pBDTEntryEP0OutCurrent; - // Toggle it to the next ping pong buffer (if applicable) + // Toggle it to the next ping pong buffer (if applicable) *(unsigned char*)&pBDTEntryEP0OutNext ^= USB_NEXT_EP0_OUT_PING_PONG; - // If the current EP0 OUT buffer has a SETUP token + // If the current EP0 OUT buffer has a SETUP token if (pBDTEntryEP0OutCurrent->STAT.PID == SETUP_TOKEN) { // Handle the control transfer @@ -493,8 +493,8 @@ void usb_ctrl_ep_service(void) } } else if ((ustat_saved & USTAT_EP0_PP_MASK) == USTAT_EP0_IN) { - // Otherwise the transmission was and EP0 IN - // so take care of the IN transfer + // Otherwise the transmission was and EP0 IN + // so take care of the IN transfer usb_ctrl_trf_in_handler(); } } @@ -535,8 +535,8 @@ void usb_ctrl_trf_setup_handler(void) //if the SIE currently owns the buffer if (pBDTEntryIn[0]->STAT.UOWN != 0) { - // give control back to the CPU - // Compensate for after a STALL + // give control back to the CPU + // Compensate for after a STALL pBDTEntryIn[0]->STAT.Val = _UCPU; } @@ -760,9 +760,9 @@ void usb_check_std_request(void) usb_std_set_cfg_handler(); break; case GET_CFG: - usb_in_pipe[0].pSrc.bRam = (unsigned char*)&usb_active_configuration; // Set Source - usb_in_pipe[0].info.bits.ctrl_trf_mem = _RAM; // Set memory type - usb_in_pipe[0].wCount |= 0xff; // Set data count + usb_in_pipe[0].pSrc.bRam = (unsigned char*)&usb_active_configuration; // Set Source + usb_in_pipe[0].info.bits.ctrl_trf_mem = _RAM; // Set memory type + usb_in_pipe[0].wCount |= 0xff; // Set data count usb_in_pipe[0].info.bits.busy = 1; break; case GET_STATUS: @@ -774,9 +774,9 @@ void usb_check_std_request(void) break; case GET_INTF: usb_in_pipe[0].pSrc.bRam = (unsigned char*)&usb_alternate_interface + - usb_setup_pkt.bIntfID; // Set source - usb_in_pipe[0].info.bits.ctrl_trf_mem = _RAM; // Set memory type - usb_in_pipe[0].wCount |= 0xff; // Set data count + usb_setup_pkt.bIntfID; // Set source + usb_in_pipe[0].info.bits.ctrl_trf_mem = _RAM; // Set memory type + usb_in_pipe[0].wCount |= 0xff; // Set data count usb_in_pipe[0].info.bits.busy = 1; break; case SET_INTF: @@ -801,7 +801,7 @@ void usb_std_feature_req_handler(void) BDT_ENTRY *p; unsigned int *pUEP; -#ifdef USB_SUPPORT_OTG +#ifdef USB_SUPPORT_OTG if ((usb_setup_pkt.bFeature == OTG_FEATURE_B_HNP_ENABLE)&& (usb_setup_pkt.Recipient == RCPT_DEV)) { @@ -857,7 +857,7 @@ void usb_std_feature_req_handler(void) p = (BDT_ENTRY*)pBDTEntryIn[usb_setup_pkt.EPNum]; } - //if it was a SET_FEATURE request + //if it was a SET_FEATURE request if (usb_setup_pkt.bRequest == SET_FEATURE) { // Then STALL the endpoint @@ -868,14 +868,14 @@ void usb_std_feature_req_handler(void) pUEP = (unsigned int*) &U1EP(0); pUEP += usb_setup_pkt.EPNum * 4; - //Clear the STALL bit in the UEP register + //Clear the STALL bit in the UEP register *pUEP &= ~UEP_STALL; if (usb_setup_pkt.EPDir == 1) // IN { - // If the endpoint is an IN endpoint then we - // need to return it to the CPU and reset the - // DTS bit so that the next transfer is correct + // If the endpoint is an IN endpoint then we + // need to return it to the CPU and reset the + // DTS bit so that the next transfer is correct #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || \ (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) p->STAT.Val = _UCPU | _DAT0; @@ -886,12 +886,12 @@ void usb_std_feature_req_handler(void) p->STAT.Val = _UCPU | _DAT1; #endif } else { - // If the endpoint was an OUT endpoint then we - // need to give control of the endpoint back to - // the SIE so that the function driver can - // receive the data as they expected. Also need - // to set the DTS bit so the next packet will be - // correct + // If the endpoint was an OUT endpoint then we + // need to give control of the endpoint back to + // the SIE so that the function driver can + // receive the data as they expected. Also need + // to set the DTS bit so the next packet will be + // correct #if (USB_PING_PONG_MODE == USB_PING_PONG__ALL_BUT_EP0) || \ (USB_PING_PONG_MODE == USB_PING_PONG__FULL_PING_PONG) p->STAT.Val = _USIE|_DAT0|_DTSEN; @@ -927,7 +927,7 @@ void usb_std_get_dsc_handler(void) break; case USB_DESCRIPTOR_STRING: #if defined(USB_NUM_STRING_DESCRIPTORS) - if (usb_setup_pkt.bDscIndex < USB_NUM_STRING_DESCRIPTORS) + if (usb_setup_pkt.bDscIndex < USB_NUM_STRING_DESCRIPTORS) #else if (1) #endif @@ -965,7 +965,7 @@ void usb_std_get_status_handler(void) * [0]: bit0: Self-Powered Status [0] Bus-Powered [1] Self-Powered * bit1: RemoteWakeup [0] Disabled [1] Enabled */ - ctrl_trf_data[0] |= 1; // self powered + ctrl_trf_data[0] |= 1; // self powered if (usb_remote_wakeup == 1) { ctrl_trf_data[0] |= 2; diff --git a/sys/pic32/usb_device.h b/sys/pic32/usb_device.h index c5cde64..eb5c011 100644 --- a/sys/pic32/usb_device.h +++ b/sys/pic32/usb_device.h @@ -38,70 +38,70 @@ * NOTE: Do not use these values for checking against USTAT. * To check against USTAT, use values defined in usbd.h. */ -#define _EP_IN 0x80 -#define _EP_OUT 0x00 -#define _EP01_OUT 0x01 -#define _EP01_IN 0x81 -#define _EP02_OUT 0x02 -#define _EP02_IN 0x82 -#define _EP03_OUT 0x03 -#define _EP03_IN 0x83 -#define _EP04_OUT 0x04 -#define _EP04_IN 0x84 -#define _EP05_OUT 0x05 -#define _EP05_IN 0x85 -#define _EP06_OUT 0x06 -#define _EP06_IN 0x86 -#define _EP07_OUT 0x07 -#define _EP07_IN 0x87 -#define _EP08_OUT 0x08 -#define _EP08_IN 0x88 -#define _EP09_OUT 0x09 -#define _EP09_IN 0x89 -#define _EP10_OUT 0x0A -#define _EP10_IN 0x8A -#define _EP11_OUT 0x0B -#define _EP11_IN 0x8B -#define _EP12_OUT 0x0C -#define _EP12_IN 0x8C -#define _EP13_OUT 0x0D -#define _EP13_IN 0x8D -#define _EP14_OUT 0x0E -#define _EP14_IN 0x8E -#define _EP15_OUT 0x0F -#define _EP15_IN 0x8F +#define _EP_IN 0x80 +#define _EP_OUT 0x00 +#define _EP01_OUT 0x01 +#define _EP01_IN 0x81 +#define _EP02_OUT 0x02 +#define _EP02_IN 0x82 +#define _EP03_OUT 0x03 +#define _EP03_IN 0x83 +#define _EP04_OUT 0x04 +#define _EP04_IN 0x84 +#define _EP05_OUT 0x05 +#define _EP05_IN 0x85 +#define _EP06_OUT 0x06 +#define _EP06_IN 0x86 +#define _EP07_OUT 0x07 +#define _EP07_IN 0x87 +#define _EP08_OUT 0x08 +#define _EP08_IN 0x88 +#define _EP09_OUT 0x09 +#define _EP09_IN 0x89 +#define _EP10_OUT 0x0A +#define _EP10_IN 0x8A +#define _EP11_OUT 0x0B +#define _EP11_IN 0x8B +#define _EP12_OUT 0x0C +#define _EP12_IN 0x8C +#define _EP13_OUT 0x0D +#define _EP13_IN 0x8D +#define _EP14_OUT 0x0E +#define _EP14_IN 0x8E +#define _EP15_OUT 0x0F +#define _EP15_IN 0x8F /* Configuration Attributes */ -#define _DEFAULT (0x01 << 7) // Default Value (Bit 7 is set) -#define _SELF (0x01 << 6) // Self-powered (Supports if set) -#define _RWU (0x01 << 5) // Remote Wakeup (Supports if set) -#define _HNP (0x01 << 1) // HNP (Supports if set) -#define _SRP (0x01) // SRP (Supports if set) +#define _DEFAULT (0x01 << 7) // Default Value (Bit 7 is set) +#define _SELF (0x01 << 6) // Self-powered (Supports if set) +#define _RWU (0x01 << 5) // Remote Wakeup (Supports if set) +#define _HNP (0x01 << 1) // HNP (Supports if set) +#define _SRP (0x01) // SRP (Supports if set) /* Endpoint Transfer Type */ -#define _CTRL 0x00 // Control Transfer -#define _ISO 0x01 // Isochronous Transfer -#define _BULK 0x02 // Bulk Transfer -#define _INTERRUPT 0x03 // Interrupt Transfer +#define _CTRL 0x00 // Control Transfer +#define _ISO 0x01 // Isochronous Transfer +#define _BULK 0x02 // Bulk Transfer +#define _INTERRUPT 0x03 // Interrupt Transfer /* Isochronous Endpoint Synchronization Type */ -#define _NS (0x00 << 2) // No Synchronization -#define _AS (0x01 << 2) // Asynchronous -#define _AD (0x02 << 2) // Adaptive -#define _SY (0x03 << 2) // Synchronous +#define _NS (0x00 << 2) // No Synchronization +#define _AS (0x01 << 2) // Asynchronous +#define _AD (0x02 << 2) // Adaptive +#define _SY (0x03 << 2) // Synchronous /* Isochronous Endpoint Usage Type */ -#define _DE (0x00 << 4) // Data endpoint -#define _FE (0x01 << 4) // Feedback endpoint -#define _IE (0x02 << 4) // Implicit feedback Data endpoint +#define _DE (0x00 << 4) // Data endpoint +#define _FE (0x01 << 4) // Feedback endpoint +#define _IE (0x02 << 4) // Implicit feedback Data endpoint -#define _ROM USB_INPIPES_ROM -#define _RAM USB_INPIPES_RAM +#define _ROM USB_INPIPES_ROM +#define _RAM USB_INPIPES_RAM //These are the directional indicators used for the usb_transfer_one_packet() // function. -#define OUT_FROM_HOST 0 -#define IN_TO_HOST 1 +#define OUT_FROM_HOST 0 +#define IN_TO_HOST 1 /* * CTRL_TRF_SETUP: Every setup packet has 8 bytes. This structure @@ -114,26 +114,26 @@ typedef union __attribute__ ((packed)) _CTRL_TRF_SETUP struct __attribute__ ((packed)) { unsigned char bmRequestType; //from table 9-2 of USB2.0 spec - unsigned char bRequest; //from table 9-2 of USB2.0 spec - unsigned short wValue; //from table 9-2 of USB2.0 spec - unsigned short wIndex; //from table 9-2 of USB2.0 spec - unsigned short wLength; //from table 9-2 of USB2.0 spec + unsigned char bRequest; //from table 9-2 of USB2.0 spec + unsigned short wValue; //from table 9-2 of USB2.0 spec + unsigned short wIndex; //from table 9-2 of USB2.0 spec + unsigned short wLength; //from table 9-2 of USB2.0 spec }; struct __attribute__ ((packed)) { unsigned :8; unsigned :8; - unsigned short W_Value; //from table 9-2 of USB2.0 spec, allows byte/bitwise access - unsigned short W_Index; //from table 9-2 of USB2.0 spec, allows byte/bitwise access - unsigned short W_Length; //from table 9-2 of USB2.0 spec, allows byte/bitwise access + unsigned short W_Value; //from table 9-2 of USB2.0 spec, allows byte/bitwise access + unsigned short W_Index; //from table 9-2 of USB2.0 spec, allows byte/bitwise access + unsigned short W_Length; //from table 9-2 of USB2.0 spec, allows byte/bitwise access }; struct __attribute__ ((packed)) { - unsigned Recipient:5; //Device,Interface,Endpoint,Other - unsigned RequestType:2; //Standard,Class,Vendor,Reserved - unsigned DataDir:1; //Host-to-device,Device-to-host + unsigned Recipient:5; //Device,Interface,Endpoint,Other + unsigned RequestType:2; //Standard,Class,Vendor,Reserved + unsigned DataDir:1; //Host-to-device,Device-to-host unsigned :8; - unsigned char bFeature; //DEVICE_REMOTE_WAKEUP,ENDPOINT_HALT + unsigned char bFeature; //DEVICE_REMOTE_WAKEUP,ENDPOINT_HALT unsigned :8; unsigned :8; unsigned :8; @@ -154,8 +154,8 @@ typedef union __attribute__ ((packed)) _CTRL_TRF_SETUP { unsigned :8; unsigned :8; - unsigned char bDevADR; //Device Address 0-127 - unsigned char bDevADRH; //Must equal zero + unsigned char bDevADR; //Device Address 0-127 + unsigned char bDevADRH; //Must equal zero unsigned :8; unsigned :8; unsigned :8; @@ -165,8 +165,8 @@ typedef union __attribute__ ((packed)) _CTRL_TRF_SETUP { unsigned :8; unsigned :8; - unsigned char bConfigurationValue; //Configuration Value 0-255 - unsigned char bCfgRSD; //Must equal zero (Reserved) + unsigned char bConfigurationValue; //Configuration Value 0-255 + unsigned char bCfgRSD; //Must equal zero (Reserved) unsigned :8; unsigned :8; unsigned :8; @@ -176,10 +176,10 @@ typedef union __attribute__ ((packed)) _CTRL_TRF_SETUP { unsigned :8; unsigned :8; - unsigned char bAltID; //Alternate Setting Value 0-255 - unsigned char bAltID_H; //Must equal zero - unsigned char bIntfID; //Interface Number Value 0-255 - unsigned char bIntfID_H; //Must equal zero + unsigned char bAltID; //Alternate Setting Value 0-255 + unsigned char bAltID_H; //Must equal zero + unsigned char bIntfID; //Interface Number Value 0-255 + unsigned char bIntfID_H; //Must equal zero unsigned :8; unsigned :8; }; @@ -189,8 +189,8 @@ typedef union __attribute__ ((packed)) _CTRL_TRF_SETUP unsigned :8; unsigned :8; unsigned :8; - unsigned char bEPID; //Endpoint ID (Number & Direction) - unsigned char bEPID_H; //Must equal zero + unsigned char bEPID; //Endpoint ID (Number & Direction) + unsigned char bEPID_H; //Must equal zero unsigned :8; unsigned :8; }; @@ -200,9 +200,9 @@ typedef union __attribute__ ((packed)) _CTRL_TRF_SETUP unsigned :8; unsigned :8; unsigned :8; - unsigned EPNum:4; //Endpoint Number 0-15 + unsigned EPNum:4; //Endpoint Number 0-15 unsigned :3; - unsigned EPDir:1; //Endpoint Direction: 0-OUT, 1-IN + unsigned EPDir:1; //Endpoint Direction: 0-OUT, 1-IN unsigned :8; unsigned :8; unsigned :8; @@ -356,12 +356,12 @@ typedef struct __attribute__ ((packed)) #define SetConfigurationOptions() {U1CNFG1 = 0;} /* UEPn Initialization Parameters */ -#define EP_CTRL 0x0C // Cfg Control pipe for this ep -#define EP_OUT 0x18 // Cfg OUT only pipe for this ep -#define EP_IN 0x14 // Cfg IN only pipe for this ep -#define EP_OUT_IN 0x1C // Cfg both OUT & IN pipes for this ep -#define HSHK_EN 0x01 // Enable handshake packet - // Handshake should be disable for isoch +#define EP_CTRL 0x0C // Cfg Control pipe for this ep +#define EP_OUT 0x18 // Cfg OUT only pipe for this ep +#define EP_IN 0x14 // Cfg IN only pipe for this ep +#define EP_OUT_IN 0x1C // Cfg both OUT & IN pipes for this ep +#define HSHK_EN 0x01 // Enable handshake packet + // Handshake should be disable for isoch #define USB_HANDSHAKE_ENABLED 0x01 #define USB_HANDSHAKE_DISABLED 0x00 @@ -395,14 +395,14 @@ typedef struct __attribute__ ((packed)) * application related data. */ #ifndef USB_EP0_BUFF_SIZE -# define USB_EP0_BUFF_SIZE 8 +# define USB_EP0_BUFF_SIZE 8 #endif /* * Only one interface by default. */ #ifndef USB_MAX_NUM_INT -# define USB_MAX_NUM_INT 1 +# define USB_MAX_NUM_INT 1 #endif // Definitions for the BDT @@ -422,32 +422,32 @@ extern const unsigned char *const usb_string[]; extern volatile CTRL_TRF_SETUP usb_setup_pkt; // 8-byte only /* Control Transfer States */ -#define WAIT_SETUP 0 -#define CTRL_TRF_TX 1 -#define CTRL_TRF_RX 2 +#define WAIT_SETUP 0 +#define CTRL_TRF_TX 1 +#define CTRL_TRF_RX 2 /* v2.1 fix - Short Packet States - Used by Control Transfer Read - CTRL_TRF_TX */ -#define SHORT_PKT_NOT_USED 0 -#define SHORT_PKT_PENDING 1 -#define SHORT_PKT_SENT 2 +#define SHORT_PKT_NOT_USED 0 +#define SHORT_PKT_PENDING 1 +#define SHORT_PKT_SENT 2 /* USB PID: Token Types - See chapter 8 in the USB specification */ -#define SETUP_TOKEN 0x0D // 0b00001101 -#define OUT_TOKEN 0x01 // 0b00000001 -#define IN_TOKEN 0x09 // 0b00001001 +#define SETUP_TOKEN 0x0D // 0b00001101 +#define OUT_TOKEN 0x01 // 0b00000001 +#define IN_TOKEN 0x09 // 0b00001001 /* bmRequestType Definitions */ -#define HOST_TO_DEV 0 -#define DEV_TO_HOST 1 +#define HOST_TO_DEV 0 +#define DEV_TO_HOST 1 -#define STANDARD 0x00 -#define CLASS 0x01 -#define VENDOR 0x02 +#define STANDARD 0x00 +#define CLASS 0x01 +#define VENDOR 0x02 -#define RCPT_DEV 0 -#define RCPT_INTF 1 -#define RCPT_EP 2 -#define RCPT_OTH 3 +#define RCPT_DEV 0 +#define RCPT_INTF 1 +#define RCPT_EP 2 +#define RCPT_OTH 3 extern unsigned usb_device_state; extern unsigned usb_active_configuration; diff --git a/sys/pic32/usb_function_cdc.c b/sys/pic32/usb_function_cdc.c index fa4a6e1..2b257a5 100644 --- a/sys/pic32/usb_function_cdc.c +++ b/sys/pic32/usb_function_cdc.c @@ -28,7 +28,7 @@ unsigned cdc_trf_state; // States are defined cdc.h unsigned cdc_tx_len; // total tx length -LINE_CODING cdc_line_coding; // Buffer to store line coding information +LINE_CODING cdc_line_coding; // Buffer to store line coding information static USB_HANDLE data_out; static USB_HANDLE data_in; @@ -130,10 +130,10 @@ void cdc_check_request() void cdc_init_ep() { // Abstract line coding information - cdc_line_coding.dwDTERate = 115200; // baud rate - cdc_line_coding.bCharFormat = 0; // 1 stop bit - cdc_line_coding.bParityType = 0; // None - cdc_line_coding.bDataBits = 8; // 5,6,7,8, or 16 + cdc_line_coding.dwDTERate = 115200; // baud rate + cdc_line_coding.bCharFormat = 0; // 1 stop bit + cdc_line_coding.bParityType = 0; // None + cdc_line_coding.bDataBits = 8; // 5,6,7,8, or 16 cdc_trf_state = CDC_TX_READY; cdc_tx_len = 0; diff --git a/sys/pic32/usb_function_cdc.h b/sys/pic32/usb_function_cdc.h index 37f632d..6f06d25 100644 --- a/sys/pic32/usb_function_cdc.h +++ b/sys/pic32/usb_function_cdc.h @@ -32,25 +32,25 @@ * Default CDC configuration. */ #ifndef CDC_COMM_INTF_ID -# define CDC_COMM_INTF_ID 0x0 +# define CDC_COMM_INTF_ID 0x0 #endif #ifndef CDC_COMM_EP -# define CDC_COMM_EP 2 +# define CDC_COMM_EP 2 #endif #ifndef CDC_COMM_IN_EP_SIZE -# define CDC_COMM_IN_EP_SIZE 8 +# define CDC_COMM_IN_EP_SIZE 8 #endif #ifndef CDC_DATA_INTF_ID -# define CDC_DATA_INTF_ID 0x01 +# define CDC_DATA_INTF_ID 0x01 #endif #ifndef CDC_DATA_EP -# define CDC_DATA_EP 3 +# define CDC_DATA_EP 3 #endif #ifndef CDC_DATA_OUT_EP_SIZE -# define CDC_DATA_OUT_EP_SIZE 64 +# define CDC_DATA_OUT_EP_SIZE 64 #endif #ifndef CDC_DATA_IN_EP_SIZE -# define CDC_DATA_IN_EP_SIZE 64 +# define CDC_DATA_IN_EP_SIZE 64 #endif /* Class-Specific Requests */ diff --git a/sys/pic32/usb_hal_pic32.h b/sys/pic32/usb_hal_pic32.h index 8af3aba..626fc9f 100644 --- a/sys/pic32/usb_hal_pic32.h +++ b/sys/pic32/usb_hal_pic32.h @@ -71,7 +71,7 @@ typedef union __attribute__ ((packed)) _BD_STAT }; struct __attribute__ ((packed)){ unsigned :2; - unsigned PID :4; //Packet Identifier + unsigned PID :4; //Packet Identifier }; unsigned short Val; } BD_STAT; @@ -83,7 +83,7 @@ typedef union __attribute__ ((packed))__BDT { BD_STAT STAT; unsigned CNT:10; - unsigned char *ADR; //Buffer Address + unsigned char *ADR; //Buffer Address }; struct __attribute__ ((packed)) { @@ -107,10 +107,10 @@ typedef union __attribute__ ((packed))__BDT #define UEP_STALL 0x0002 -//#define USB_PING_PONG__NO_PING_PONG 0x00 -//#define USB_PING_PONG__EP0_OUT_ONLY 0x01 -#define USB_PING_PONG__FULL_PING_PONG 0x02 -//#define USB_PING_PONG__ALL_BUT_EP0 0x03 +//#define USB_PING_PONG__NO_PING_PONG 0x00 +//#define USB_PING_PONG__EP0_OUT_ONLY 0x01 +#define USB_PING_PONG__FULL_PING_PONG 0x02 +//#define USB_PING_PONG__ALL_BUT_EP0 0x03 /* * Translate virtual address to physical one. @@ -130,7 +130,7 @@ static inline void *ConvertToPhysicalAddress (volatile void *addr) phys = virt & 0x1fffffff; } } else { - // kuseg + // kuseg phys = virt + 0x40000000; } return (void*) phys; @@ -140,10 +140,10 @@ static inline void *ConvertToPhysicalAddress (volatile void *addr) * This macro is used to disable the USB module */ #define usb_module_disable() {\ - U1CON = 0;\ - U1IE = 0;\ - U1OTGIE = 0;\ - U1PWR |= PIC32_U1PWR_USBPWR;\ - usb_device_state = DETACHED_STATE;\ + U1CON = 0;\ + U1IE = 0;\ + U1OTGIE = 0;\ + U1PWR |= PIC32_U1PWR_USBPWR;\ + usb_device_state = DETACHED_STATE;\ } #endif diff --git a/sys/pic32/usb_uart.c b/sys/pic32/usb_uart.c index 22822f2..438e4b8 100644 --- a/sys/pic32/usb_uart.c +++ b/sys/pic32/usb_uart.c @@ -81,28 +81,26 @@ void usbinit() int usbopen (dev_t dev, int flag, int mode) { - register struct tty *tp = &usbttys[0]; + register struct tty *tp = &usbttys[0]; - tp->t_oproc = usbstart; + tp->t_oproc = usbstart; - if ((tp->t_state & TS_ISOPEN) == 0) - { - tp->t_ispeed = BBAUD(UARTUSB_BAUD); - tp->t_ospeed = BBAUD(UARTUSB_BAUD); - ttychars(tp); - tp->t_state = TS_ISOPEN | TS_CARR_ON; - tp->t_flags = ECHO | XTABS | CRMOD | CRTBS | CRTERA | CTLECH | CRTKIL; - } - if ((tp->t_state & TS_XCLUDE) && u.u_uid != 0) - return (EBUSY); + if ((tp->t_state & TS_ISOPEN) == 0) { + tp->t_ispeed = BBAUD(UARTUSB_BAUD); + tp->t_ospeed = BBAUD(UARTUSB_BAUD); + ttychars(tp); + tp->t_state = TS_ISOPEN | TS_CARR_ON; + tp->t_flags = ECHO | XTABS | CRMOD | CRTBS | CRTERA | CTLECH | CRTKIL; + } + if ((tp->t_state & TS_XCLUDE) && u.u_uid != 0) + return (EBUSY); - if(tp->t_ispeed == 0) - { - tp->t_ispeed = BBAUD(UARTUSB_BAUD); - tp->t_ospeed = BBAUD(UARTUSB_BAUD); - } - cdc_set_line_coding(speed_bps[tp->t_ospeed], NUM_STOP_BITS_1, PARITY_NONE, 8); - return ttyopen (dev, tp); + if (tp->t_ispeed == 0) { + tp->t_ispeed = BBAUD(UARTUSB_BAUD); + tp->t_ospeed = BBAUD(UARTUSB_BAUD); + } + cdc_set_line_coding(speed_bps[tp->t_ospeed], NUM_STOP_BITS_1, PARITY_NONE, 8); + return ttyopen (dev, tp); } int usbclose (dev, flag, mode) @@ -165,7 +163,7 @@ void usbstart (tp) s = spltty(); if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) { -out: /* Disable transmit_interrupt. */ +out: /* Disable transmit_interrupt. */ led_control (LED_TTY, 0); splx (s); return; @@ -263,7 +261,7 @@ void usbintr (int chan) // Check that USB connection is established. if (usb_device_state < CONFIGURED_STATE || (U1PWRC & PIC32_U1PWRC_USUSPEND)) - return; + return; // Receive data from user. cdc_consume (usb_rx); @@ -354,8 +352,8 @@ const unsigned char usb_config1_descriptor[] = { /* Configuration Descriptor */ 9, // sizeof(USB_CFG_DSC) - USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type - 67, 0, // Total length of data for this cfg + USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type + 67, 0, // Total length of data for this cfg 2, // Number of interfaces in this cfg 1, // Index value of this configuration 0, // Configuration string index @@ -369,8 +367,8 @@ const unsigned char usb_config1_descriptor[] = 0, // Alternate Setting Number 1, // Number of endpoints in this intf COMM_INTF, // Class code - ABSTRACT_CONTROL_MODEL, // Subclass code - V25TER, // Protocol code + ABSTRACT_CONTROL_MODEL, // Subclass code + V25TER, // Protocol code 0, // Interface string index /* CDC Class-Specific Descriptors */ @@ -398,38 +396,38 @@ const unsigned char usb_config1_descriptor[] = /* Endpoint Descriptor */ 7, // sizeof(USB_EP_DSC) - USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor - _EP02_IN, // EndpointAddress - _INTERRUPT, // Attributes - 0x08, 0x00, // size - 0x02, // Interval + USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor + _EP02_IN, // EndpointAddress + _INTERRUPT, // Attributes + 0x08, 0x00, // size + 0x02, // Interval /* Interface Descriptor */ - 9, // sizeof(USB_INTF_DSC) - USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type - 1, // Interface Number - 0, // Alternate Setting Number - 2, // Number of endpoints in this intf - DATA_INTF, // Class code - 0, // Subclass code - NO_PROTOCOL, // Protocol code - 0, // Interface string index + 9, // sizeof(USB_INTF_DSC) + USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type + 1, // Interface Number + 0, // Alternate Setting Number + 2, // Number of endpoints in this intf + DATA_INTF, // Class code + 0, // Subclass code + NO_PROTOCOL, // Protocol code + 0, // Interface string index /* Endpoint Descriptor */ 7, // sizeof(USB_EP_DSC) - USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor - _EP03_OUT, // EndpointAddress - _BULK, // Attributes - 0x40, 0x00, // size - 0x00, // Interval + USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor + _EP03_OUT, // EndpointAddress + _BULK, // Attributes + 0x40, 0x00, // size + 0x00, // Interval /* Endpoint Descriptor */ 7, // sizeof(USB_EP_DSC) - USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor - _EP03_IN, // EndpointAddress - _BULK, // Attributes - 0x40, 0x00, // size - 0x00, // Interval + USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor + _EP03_IN, // EndpointAddress + _BULK, // Attributes + 0x40, 0x00, // size + 0x00, // Interval };