Cleaned up src/lib/utils library. Renamed server_ functions to more logical
names. All system processes can now either use panic() or report() from libutils, or redefine their own function. Assertions are done via the standard <assert.h> functionality.
This commit is contained in:
+1
-1
@@ -69,7 +69,7 @@ int only_search; /* if NO_READ, don't read, else act normal */
|
||||
}
|
||||
|
||||
/* Desired block is not on available chain. Take oldest block ('front'). */
|
||||
if ((bp = front) == NIL_BUF) panic("all buffers in use", NR_BUFS);
|
||||
if ((bp = front) == NIL_BUF) panic(__FILE__,"all buffers in use", NR_BUFS);
|
||||
rm_lru(bp);
|
||||
|
||||
/* Remove the block that was just taken from its hash chain. */
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ int flags; /* mode bits and flags */
|
||||
if (major >= max_major) major = 0;
|
||||
dp = &dmap[major];
|
||||
r = (*dp->dmap_opcl)(DEV_OPEN, dev, proc, flags);
|
||||
if (r == SUSPEND) panic("Suspend on open from", dp->dmap_driver);
|
||||
if (r == SUSPEND) panic(__FILE__,"suspend on open from", dp->dmap_driver);
|
||||
return(r);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ message *mess_ptr; /* pointer to message for task */
|
||||
for (;;) {
|
||||
if (r != OK) {
|
||||
if (r == EDEADDST) return; /* give up */
|
||||
else panic("call_task: can't send/receive", r);
|
||||
else panic(__FILE__,"call_task: can't send/receive", r);
|
||||
}
|
||||
|
||||
/* Did the process we did the sendrec() for get a result? */
|
||||
|
||||
+15
-14
@@ -113,11 +113,11 @@ PRIVATE void get_work()
|
||||
reviving--;
|
||||
return;
|
||||
}
|
||||
panic("get_work couldn't revive anyone", NO_NUM);
|
||||
panic(__FILE__,"get_work couldn't revive anyone", NO_NUM);
|
||||
}
|
||||
|
||||
/* Normal case. No one to revive. */
|
||||
if (receive(ANY, &m_in) != OK) panic("fs receive error", NO_NUM);
|
||||
if (receive(ANY, &m_in) != OK) panic(__FILE__,"fs receive error", NO_NUM);
|
||||
who = m_in.m_source;
|
||||
call_nr = m_in.m_type;
|
||||
}
|
||||
@@ -180,11 +180,11 @@ PRIVATE void fs_init()
|
||||
/* Certain relations must hold for the file system to work at all. Some
|
||||
* extra block_size requirements are checked at super-block-read-in time.
|
||||
*/
|
||||
if (OPEN_MAX > 127) panic("OPEN_MAX > 127", NO_NUM);
|
||||
if (NR_BUFS < 6) panic("NR_BUFS < 6", NO_NUM);
|
||||
if (V1_INODE_SIZE != 32) panic("V1 inode size != 32", NO_NUM);
|
||||
if (V2_INODE_SIZE != 64) panic("V2 inode size != 64", NO_NUM);
|
||||
if (OPEN_MAX > 8 * sizeof(long)) panic("Too few bits in fp_cloexec", NO_NUM);
|
||||
if (OPEN_MAX > 127) panic(__FILE__,"OPEN_MAX > 127", NO_NUM);
|
||||
if (NR_BUFS < 6) panic(__FILE__,"NR_BUFS < 6", NO_NUM);
|
||||
if (V1_INODE_SIZE != 32) panic(__FILE__,"V1 inode size != 32", NO_NUM);
|
||||
if (V2_INODE_SIZE != 64) panic(__FILE__,"V2 inode size != 64", NO_NUM);
|
||||
if (OPEN_MAX > 8 * sizeof(long)) panic(__FILE__,"Too few bits in fp_cloexec", NO_NUM);
|
||||
|
||||
/* The following initializations are needed to let dev_opcl succeed .*/
|
||||
fp = (struct fproc *) NULL;
|
||||
@@ -203,7 +203,7 @@ PRIVATE void fs_init()
|
||||
*/
|
||||
do {
|
||||
if (OK != (s=receive(PM_PROC_NR, &mess)))
|
||||
panic("FS couldn't receive from PM", s);
|
||||
panic(__FILE__,"FS couldn't receive from PM", s);
|
||||
if (NONE == mess.PR_PROC_NR) break;
|
||||
|
||||
fp = &fproc[mess.PR_PROC_NR];
|
||||
@@ -275,19 +275,20 @@ PRIVATE void load_ram(void)
|
||||
|
||||
/* Open the root device. */
|
||||
if (dev_open(root_dev, FS_PROC_NR, R_BIT|W_BIT) != OK) {
|
||||
panic("Cannot open root device",NO_NUM);
|
||||
panic(__FILE__,"Cannot open root device",NO_NUM);
|
||||
}
|
||||
|
||||
/* If we must initialize a ram disk, get details from the image device. */
|
||||
if (root_dev == DEV_RAM || root_dev != image_dev) {
|
||||
u32_t fsmax;
|
||||
if (dev_open(image_dev, FS_PROC_NR, R_BIT) != OK)
|
||||
panic("Cannot open RAM image device", NO_NUM);
|
||||
panic(__FILE__,"Cannot open RAM image device", NO_NUM);
|
||||
|
||||
/* Get size of RAM disk image from the super block. */
|
||||
sp = &super_block[0];
|
||||
sp->s_dev = image_dev;
|
||||
if (read_super(sp) != OK) panic("Bad RAM disk image FS", NO_NUM);
|
||||
if (read_super(sp) != OK)
|
||||
panic(__FILE__,"Bad RAM disk image FS", NO_NUM);
|
||||
|
||||
lcount = sp->s_zones << sp->s_log_zone_size; /* # blks on root dev*/
|
||||
|
||||
@@ -309,7 +310,7 @@ PRIVATE void load_ram(void)
|
||||
m_out.REQUEST = MIOCRAMSIZE;
|
||||
m_out.POSITION = ram_size_kb*1024;
|
||||
if (sendrec(MEMORY, &m_out) != OK || m_out.REP_STATUS != OK)
|
||||
panic("Can't set RAM disk size", NO_NUM);
|
||||
panic(__FILE__,"can't set RAM disk size", NO_NUM);
|
||||
|
||||
|
||||
#if ENABLE_CACHE2
|
||||
@@ -335,7 +336,7 @@ PRIVATE void load_ram(void)
|
||||
if(block_size_ram != block_size_image) {
|
||||
printf("ram block size: %d image block size: %d\n",
|
||||
block_size_ram, block_size_image);
|
||||
panic("Sorry, ram disk and image disk block sizes have to be the same.", NO_NUM);
|
||||
panic(__FILE__,"ram disk and image disk block sizes must match", NO_NUM);
|
||||
}
|
||||
|
||||
for (b = 0; b < (block_t) lcount; b++) {
|
||||
@@ -401,7 +402,7 @@ dev_t super_dev; /* place to get superblock from */
|
||||
rip = get_inode(super_dev, ROOT_INODE); /* inode for root dir */
|
||||
if ( (rip->i_mode & I_TYPE) != I_DIRECTORY || rip->i_nlinks < 3) bad++;
|
||||
}
|
||||
if (bad) panic("Invalid root file system", NO_NUM);
|
||||
if (bad) panic(__FILE__,"Invalid root file system", NO_NUM);
|
||||
|
||||
sp->s_imount = rip;
|
||||
dup_inode(rip);
|
||||
|
||||
+1
-1
@@ -290,7 +290,7 @@ int flag; /* LOOK_UP, ENTER, DELETE or IS_EMPTY */
|
||||
bp = get_block(ldir_ptr->i_dev, b, NORMAL); /* get a dir block */
|
||||
|
||||
if(bp == NO_BLOCK)
|
||||
panic("get_block returned NO_BLOCK", NO_NUM);
|
||||
panic(__FILE__,"get_block returned NO_BLOCK", NO_NUM);
|
||||
|
||||
/* Search a directory block. */
|
||||
for (dp = &bp->b_dir[0]; dp < &bp->b_dir[NR_DIR_ENTRIES(ldir_ptr->i_sp->s_block_size)]; dp++) {
|
||||
|
||||
+6
-4
@@ -60,7 +60,8 @@ PUBLIC int do_pipe()
|
||||
return(err_code);
|
||||
}
|
||||
|
||||
if (read_only(rip) != OK) panic("pipe device is read only", NO_NUM);
|
||||
if (read_only(rip) != OK)
|
||||
panic(__FILE__,"pipe device is read only", NO_NUM);
|
||||
|
||||
rip->i_pipe = I_PIPE;
|
||||
rip->i_mode &= ~I_REGULAR;
|
||||
@@ -225,7 +226,7 @@ int bytes; /* if hanging on task, how many bytes read */
|
||||
register struct fproc *rfp;
|
||||
register int task;
|
||||
|
||||
if (proc_nr < 0 || proc_nr >= NR_PROCS) panic("revive err", proc_nr);
|
||||
if (proc_nr < 0 || proc_nr >= NR_PROCS) panic(__FILE__,"revive err", proc_nr);
|
||||
rfp = &fproc[proc_nr];
|
||||
if (rfp->fp_suspended == NOT_SUSPENDED || rfp->fp_revived == REVIVING)return;
|
||||
|
||||
@@ -269,7 +270,7 @@ PUBLIC int do_unpause()
|
||||
|
||||
if (who > PM_PROC_NR) return(EPERM);
|
||||
proc_nr = m_in.pro;
|
||||
if (proc_nr < 0 || proc_nr >= NR_PROCS) panic("unpause err 1", proc_nr);
|
||||
if (proc_nr < 0 || proc_nr >= NR_PROCS) panic(__FILE__,"unpause err 1", proc_nr);
|
||||
rfp = &fproc[proc_nr];
|
||||
if (rfp->fp_suspended == NOT_SUSPENDED) return(OK);
|
||||
task = -rfp->fp_task;
|
||||
@@ -286,7 +287,8 @@ PUBLIC int do_unpause()
|
||||
|
||||
default: /* process trying to do device I/O (e.g. tty)*/
|
||||
fild = (rfp->fp_fd >> 8) & BYTE;/* extract file descriptor */
|
||||
if (fild < 0 || fild >= OPEN_MAX)panic("unpause err 2",NO_NUM);
|
||||
if (fild < 0 || fild >= OPEN_MAX)
|
||||
panic(__FILE__,"unpause err 2",NO_NUM);
|
||||
f = rfp->fp_filp[fild];
|
||||
dev = (dev_t) f->filp_ino->i_zone[0]; /* device hung on */
|
||||
mess.TTY_LINE = (dev >> MINOR) & BYTE;
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ _PROTOTYPE( unsigned conv2, (int norm, int w) );
|
||||
_PROTOTYPE( long conv4, (int norm, long x) );
|
||||
_PROTOTYPE( int fetch_name, (char *path, int len, int flag) );
|
||||
_PROTOTYPE( int no_sys, (void) );
|
||||
_PROTOTYPE( void panic, (char *format, int num) );
|
||||
_PROTOTYPE( void panic, (char *who, char *mess, int num) );
|
||||
|
||||
/* write.c */
|
||||
_PROTOTYPE( void clear_zone, (struct inode *rip, off_t pos, int flag) );
|
||||
|
||||
+9
-9
@@ -79,7 +79,7 @@ int rw_flag; /* READING or WRITING */
|
||||
* it means something has gone wrong we can't repair now.
|
||||
*/
|
||||
if(copy_queue_used != 0) {
|
||||
panic("copy queue size nonzero when entering read_write().",
|
||||
panic(__FILE__,"copy queue size nonzero when entering read_write().",
|
||||
copy_queue_used);
|
||||
}
|
||||
|
||||
@@ -124,13 +124,13 @@ int rw_flag; /* READING or WRITING */
|
||||
|
||||
if((char_spec = (mode_word == I_CHAR_SPECIAL ? 1 : 0))) {
|
||||
if(rip->i_zone[0] == NO_DEV)
|
||||
panic("read_write tries to read from character device NO_DEV", NO_NUM);
|
||||
panic(__FILE__,"read_write tries to read from character device NO_DEV", NO_NUM);
|
||||
block_size = get_block_size(rip->i_zone[0]);
|
||||
}
|
||||
if((block_spec = (mode_word == I_BLOCK_SPECIAL ? 1 : 0))) {
|
||||
f_size = LONG_MAX;
|
||||
if(rip->i_zone[0] == NO_DEV)
|
||||
panic("read_write tries to read from block device NO_DEV", NO_NUM);
|
||||
panic(__FILE__,"read_write tries to read from block device NO_DEV", NO_NUM);
|
||||
block_size = get_block_size(rip->i_zone[0]);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ int *completed; /* number of bytes copied */
|
||||
|
||||
/* In all cases, bp now points to a valid buffer. */
|
||||
if(bp == NIL_BUF) {
|
||||
panic("bp not valid in rw_chunk, this can't happen", NO_NUM);
|
||||
panic(__FILE__,"bp not valid in rw_chunk, this can't happen", NO_NUM);
|
||||
}
|
||||
if (rw_flag == WRITING && chunk != block_size && !block_spec &&
|
||||
position >= rip->i_size && off == 0) {
|
||||
@@ -348,20 +348,20 @@ int *completed; /* number of bytes copied */
|
||||
#else
|
||||
/* have to copy a buffer now. remember to do it. */
|
||||
if(copy_queue_used < 0 || copy_queue_used > COPY_QUEUE_LEN) {
|
||||
panic("copy_queue_used illegal size", copy_queue_used);
|
||||
panic(__FILE__,"copy_queue_used illegal size", copy_queue_used);
|
||||
}
|
||||
|
||||
if(copy_queue_used == COPY_QUEUE_LEN) {
|
||||
r = rw_chunk_finish(completed);
|
||||
if(copy_queue_used != 0) {
|
||||
panic("copy_queue_used nonzero", copy_queue_used);
|
||||
panic(__FILE__,"copy_queue_used nonzero", copy_queue_used);
|
||||
}
|
||||
}
|
||||
|
||||
entry = copy_queue_used++;
|
||||
|
||||
if(entry < 0 || entry >= COPY_QUEUE_LEN) {
|
||||
panic("entry illegal slot", entry);
|
||||
panic(__FILE__,"entry illegal slot", entry);
|
||||
}
|
||||
|
||||
copy_queue[entry].bp = bp;
|
||||
@@ -422,7 +422,7 @@ PRIVATE int rw_chunk_finish(int *completed)
|
||||
m.VCP_VEC_ADDR = (char *) vir_cp_req;
|
||||
|
||||
if((r=sendrec(SYSTASK, &m)) < 0) {
|
||||
panic("rw_chunk_finish: virvcopy sendrec failed", r);
|
||||
panic(__FILE__,"rw_chunk_finish: virvcopy sendrec failed", r);
|
||||
}
|
||||
|
||||
*completed = total;
|
||||
@@ -524,7 +524,7 @@ int index; /* index into *bp */
|
||||
(zone < (zone_t) sp->s_firstdatazone || zone >= sp->s_zones)) {
|
||||
printf("Illegal zone number %ld in indirect block, index %d\n",
|
||||
(long) zone, index);
|
||||
panic("check file system", NO_NUM);
|
||||
panic(__FILE__,"check file system", NO_NUM);
|
||||
}
|
||||
return(zone);
|
||||
}
|
||||
|
||||
+7
-7
@@ -38,7 +38,7 @@ bit_t origin; /* number of bit to start searching at */
|
||||
bit_t i, b;
|
||||
|
||||
if (sp->s_rd_only)
|
||||
panic("can't allocate bit on read-only filesys.", NO_NUM);
|
||||
panic(__FILE__,"can't allocate bit on read-only filesys.", NO_NUM);
|
||||
|
||||
if (map == IMAP) {
|
||||
start_block = START_BLOCK;
|
||||
@@ -112,7 +112,7 @@ bit_t bit_returned; /* number of bit to insert into the map */
|
||||
block_t start_block;
|
||||
|
||||
if (sp->s_rd_only)
|
||||
panic("can't free bit on read-only filesys.", NO_NUM);
|
||||
panic(__FILE__,"can't free bit on read-only filesys.", NO_NUM);
|
||||
|
||||
if (map == IMAP) {
|
||||
start_block = START_BLOCK;
|
||||
@@ -128,7 +128,7 @@ bit_t bit_returned; /* number of bit to insert into the map */
|
||||
|
||||
k = conv2(sp->s_native, (int) bp->b_bitmap[word]);
|
||||
if (!(k & mask)) {
|
||||
panic(map == IMAP ? "tried to free unused inode" :
|
||||
panic(__FILE__,map == IMAP ? "tried to free unused inode" :
|
||||
"tried to free unused block", NO_NUM);
|
||||
}
|
||||
|
||||
@@ -151,13 +151,13 @@ dev_t dev; /* device number whose super_block is sought */
|
||||
register struct super_block *sp;
|
||||
|
||||
if(dev == NO_DEV)
|
||||
panic("request for super_block of NO_DEV in get_super()", NO_NUM);
|
||||
panic(__FILE__,"request for super_block of NO_DEV", NO_NUM);
|
||||
|
||||
for (sp = &super_block[0]; sp < &super_block[NR_SUPERS]; sp++)
|
||||
if (sp->s_dev == dev) return(sp);
|
||||
|
||||
/* Search failed. Something wrong. */
|
||||
panic("can't find superblock for device (in decimal)", (int) dev);
|
||||
panic(__FILE__,"can't find superblock for device (in decimal)", (int) dev);
|
||||
|
||||
return(NIL_SUPER); /* to keep the compiler and lint quiet */
|
||||
}
|
||||
@@ -172,7 +172,7 @@ PUBLIC int get_block_size(dev_t dev)
|
||||
register struct super_block *sp;
|
||||
|
||||
if(dev == NO_DEV)
|
||||
panic("request for block size of NO_DEV in get_block_size()", NO_NUM);
|
||||
panic(__FILE__,"request for block size of NO_DEV", NO_NUM);
|
||||
|
||||
for (sp = &super_block[0]; sp < &super_block[NR_SUPERS]; sp++)
|
||||
if (sp->s_dev == dev)
|
||||
@@ -219,7 +219,7 @@ register struct super_block *sp; /* pointer to a superblock */
|
||||
|
||||
dev = sp->s_dev; /* save device (will be overwritten by copy) */
|
||||
if(dev == NO_DEV)
|
||||
panic("request for super_block of NO_DEV in read_super()", NO_NUM);
|
||||
panic(__FILE__,"request for super_block of NO_DEV", NO_NUM);
|
||||
r = dev_io(DEV_READ, dev, FS_PROC_NR,
|
||||
sbbuf, SUPER_BLOCK_BYTES, MIN_BLOCK_SIZE, 0);
|
||||
if(r != MIN_BLOCK_SIZE) {
|
||||
|
||||
@@ -34,7 +34,7 @@ PUBLIC time_t clock_time()
|
||||
register int k;
|
||||
clock_t uptime;
|
||||
|
||||
if ( (k=sys_getuptime(&uptime)) != OK) panic("clock_time err", k);
|
||||
if ( (k=sys_getuptime(&uptime)) != OK) panic(__FILE__,"clock_time err", k);
|
||||
return( (time_t) (boottime + (uptime/HZ)));
|
||||
}
|
||||
|
||||
@@ -93,9 +93,10 @@ PUBLIC int no_sys()
|
||||
/*===========================================================================*
|
||||
* panic *
|
||||
*===========================================================================*/
|
||||
PUBLIC void panic(format, num)
|
||||
char *format; /* format string */
|
||||
int num; /* number to go with format string */
|
||||
PUBLIC void panic(who, mess, num)
|
||||
char *who; /* who caused the panic */
|
||||
char *mess; /* panic message string */
|
||||
int num; /* number to go with it */
|
||||
{
|
||||
/* Something awful has happened. Panics are caused when an internal
|
||||
* inconsistency is detected, e.g., a programming error or illegal value of a
|
||||
@@ -106,12 +107,10 @@ int num; /* number to go with format string */
|
||||
if (panicking) return; /* do not panic during a sync */
|
||||
panicking = TRUE; /* prevent another panic during the sync */
|
||||
|
||||
printf("File system panic: %s ", format);
|
||||
printf("FS panic (%s): %s ", who, mess);
|
||||
if (num != NO_NUM) printf("%d",num);
|
||||
(void) do_sync(); /* flush everything to the disk */
|
||||
sys_exit(1);
|
||||
printf("FS: I'm still alive after exit!\n");
|
||||
while(1) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user