reply_mess.DEV_MINOR = mess.DEVICE;
reply_mess.DEV_SEL_OPS = r;
}
- else if (mess.m_type == DIAGNOSTICS_S)
- {
-#if 0
- if (device_caller == FS_PROC_NR)
- printf("driver_task: sending DIAG_REPL to FS\n");
-#endif
- reply_mess.m_type = DIAG_REPL;
- reply_mess.REP_STATUS = r;
- }
else
{
#if 0
LIBS = -ldriver -lsys
LIB_DEP = ../libdriver_asyn/libdriver.a
-OBJ = log.o diag.o kputc.o
+OBJ = log.o diag.o
# build local binary
all build: $(DRIVER)
}
log_append(diagbuf, i);
- if(m->m_type == ASYN_DIAGNOSTICS) return EDONTREPLY;
+ if(m->m_type == ASYN_DIAGNOSTICS_OLD) return EDONTREPLY;
return OK;
}
+++ /dev/null
-/* A server must occasionally print some message. It uses a simple version of
- * printf() found in the system library that calls putk() to output characters.
- * The LOG driver cannot use the regular putk(). Hence, it uses a special
- * version of putk() that directly sends to the TTY task.
- *
- * Changes:
- * 21 July 2005: Created (Jorrit N. Herder)
- */
-
-#include "log.h"
-
-/*===========================================================================*
- * kputc *
- *===========================================================================*/
-void kputc(c)
-int c;
-{
-/* Accumulate another character. If 0 or buffer full, print it. */
- static int buf_count; /* # characters in the buffer */
- static char print_buf[80]; /* output is buffered here */
- message m;
-
- if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
- m.DIAG_BUF_COUNT = buf_count;
- m.DIAG_PRINT_BUF_G = print_buf;
- m.m_type = DIAGNOSTICS; /* request TTY to output this buffer */
- _sendrec(TTY_PROC_NR, &m); /* if it fails, we give up */
- buf_count = 0; /* clear buffer for next batch */
- }
- if (c != 0) {
- print_buf[buf_count++] = c;
- }
-}
-
* understand.
*/
switch(m_ptr->m_type) {
- case DIAGNOSTICS: {
+ case DIAGNOSTICS_OLD: {
r = do_diagnostics(m_ptr, 0);
break;
}
- case ASYN_DIAGNOSTICS:
- case DIAGNOSTICS_S:
+ case ASYN_DIAGNOSTICS_OLD:
+ case DIAGNOSTICS_S_OLD:
r = do_diagnostics(m_ptr, 1);
break;
case DEV_STATUS: {
};
/* Function prototypes. */
-_PROTOTYPE( void kputc, (int c) );
_PROTOTYPE( int do_new_kmess, (message *m) );
_PROTOTYPE( int do_diagnostics, (message *m, int safe) );
_PROTOTYPE( void log_append, (char *buf, int len) );
}
cons_putk(0); /* always terminate, even with EFAULT */
- if(m_ptr->m_type != ASYN_DIAGNOSTICS) {
- m_ptr->m_type = DIAG_REPL;
+ if(m_ptr->m_type != ASYN_DIAGNOSTICS_OLD) {
+ m_ptr->m_type = DIAG_REPL_OLD;
m_ptr->REP_STATUS = result;
send(m_ptr->m_source, m_ptr);
}
if (sigismember(&sigset, SIGKMESS)) do_new_kmess(&tty_mess);
continue;
}
- case DIAGNOSTICS: /* a server wants to print some */
+ case DIAGNOSTICS_OLD: /* a server wants to print some */
#if 0
if (tty_mess.m_source != LOG_PROC_NR)
{
#endif
do_diagnostics(&tty_mess, 0);
continue;
- case DIAGNOSTICS_S:
- case ASYN_DIAGNOSTICS:
+ case DIAGNOSTICS_S_OLD:
+ case ASYN_DIAGNOSTICS_OLD:
do_diagnostics(&tty_mess, 1);
continue;
case GET_KMESS:
SAFECOPYFROM # 31
SAFECOPYTO # 32
PROFBUF # 38
+ SYSCTL
;
};
SAFECOPYTO # 32
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
pci device 10ec/8029;
uid 0;
SAFECOPYTO # 32
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
SAFECOPYTO # 32
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
pci device 1022/2000;
uid 0;
SETGRANT # 34
MAPDMA # 41
PROFBUF # 38
+ SYSCTL
;
pci device 10ec/8139;
ipc
SAFECOPYTO # 32
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
pci device 8086/1229;
ipc
GETINFO # 26
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
};
VSAFECOPY # 33
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
SAFECOPYTO # 32
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
};
SETGRANT # 34
READBIOS # 35
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
GETINFO # 26
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
SAFECOPYTO # 32
SETGRANT # 34
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
SETGRANT # 34
READBIOS # 35
PROFBUF # 38
+ SYSCTL
;
pci class
1/1 # Mass storage / IDE
SETGRANT # 34
UMAP # 14
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
SAFECOPYFROM # 31
SAFECOPYTO # 32
PROFBUF # 38
+ SYSCTL
;
};
SETGRANT # 34
VM_MAP # 30
PROFBUF # 38
+ SYSCTL
;
pci device 1260/3873;
uid 0;
IRQCTL # 19
DEVIO # 21
PROFBUF # 38
+ SYSCTL
;
pci device 1274/5000;
};
IRQCTL # 19
DEVIO # 21
PROFBUF # 38
+ SYSCTL
;
pci device 1274/1371;
};
GETINFO
REGDEV # 40
PROFBUF # 38
+ SYSCTL
;
uid 0;
};
# define SYS_MAPDMA (KERNEL_CALL + 42) /* sys_mapdma() */
# define SYS_VMCTL (KERNEL_CALL + 43) /* sys_vmctl() */
+# define SYS_SYSCTL (KERNEL_CALL + 44) /* sys_sysctl() */
-#define NR_SYS_CALLS 44 /* number of system calls */
+#define NR_SYS_CALLS 45 /* number of system calls */
/* Pseudo call for use in kernel/table.c. */
#define SYS_ALL_CALLS (NR_SYS_CALLS)
#define SVMCTL_MRG_WRITE m1_i2 /* MEMREQ_GET reply: writeflag */
#define SVMCTL_MRG_EP m1_i3 /* MEMREQ_GET reply: process */
+/* Codes and field names for SYS_SYSCTL. */
+#define SYSCTL_CODE m1_i1 /* SYSCTL_CODE_* below */
+#define SYSCTL_ARG1 m1_p1
+#define SYSCTL_ARG2 m1_i2
+#define SYSCTL_CODE_DIAG 1 /* Print diagnostics. */
+#define DIAG_BUFSIZE (80*25)
+
/* Values for SVMCTL_PARAM. */
#define VMCTL_I386_SETCR3 10
#define VMCTL_GET_PAGEFAULT 11
# define FKEY_FKEYS m2_l1 /* F1-F12 keys pressed */
# define FKEY_SFKEYS m2_l2 /* Shift-F1-F12 keys pressed */
#define DIAG_BASE 0xa00
-#define DIAGNOSTICS (DIAG_BASE+1) /* output a string without FS in between */
-#define DIAGNOSTICS_S (DIAG_BASE+2) /* grant-based version of DIAGNOSTICS */
+#define DIAGNOSTICS_OLD (DIAG_BASE+1) /* output a string without FS in between */
+#define DIAGNOSTICS_S_OLD (DIAG_BASE+2) /* grant-based version of DIAGNOSTICS */
# define DIAG_PRINT_BUF_G m1_p1
# define DIAG_BUF_COUNT m1_i1
#define GET_KMESS (DIAG_BASE+3) /* get kmess from TTY */
# define GETKM_PTR m1_p1
#define GET_KMESS_S (DIAG_BASE+4) /* get kmess from TTY */
# define GETKM_GRANT m1_i1
-#define ASYN_DIAGNOSTICS (DIAG_BASE+5) /* grant-based, replyless DIAGNOSTICS */
+#define ASYN_DIAGNOSTICS_OLD (DIAG_BASE+5) /* grant-based, replyless DIAGNOSTICS */
-#define DIAG_REPL (DIAG_BASE+0x80+0) /* reply to DIAGNOSTICS(_S) */
+#define DIAG_REPL_OLD (DIAG_BASE+0x80+0) /* reply to DIAGNOSTICS(_S) */
#define PM_BASE 0x900
#define PM_GET_WORK (PM_BASE + 1) /* Get work from PM */
_PROTOTYPE( int sys_readbios, (phys_bytes address, void *buf, size_t size));
_PROTOTYPE( int sys_stime, (time_t boottime));
+_PROTOTYPE( int sys_sysctl, (int ctl, char *arg1, int arg2));
/* Shorthands for sys_sdevio() system call. */
#define sys_insb(port, proc_nr, buffer, count) \
#define INTS_ORIG 0 /* restore interrupts */
#define INTS_MINIX 1 /* initialize interrupts for minix */
+/* for kputc() */
+#define END_OF_KMESS 0
+
#endif /* CONST_H */
_PROTOTYPE( int verify_grant, (endpoint_t, endpoint_t, cp_grant_id_t, vir_bytes,
int, vir_bytes, vir_bytes *, endpoint_t *));
+/* system/do_sysctl.c */
+_PROTOTYPE( int do_sysctl, (message *m));
+
#if SPROFILE
/* profile.c */
_PROTOTYPE( void init_profile_clock, (u32_t) );
/* System control. */
map(SYS_ABORT, do_abort); /* abort MINIX */
map(SYS_GETINFO, do_getinfo); /* request system information */
+ map(SYS_SYSCTL, do_sysctl); /* misc system manipulation */
/* Profiling. */
map(SYS_SPROF, do_sprofile); /* start/stop statistical profiling */
$(SYSTEM)(do_privctl.o) \
$(SYSTEM)(do_segctl.o) \
$(SYSTEM)(do_safecopy.o) \
+ $(SYSTEM)(do_sysctl.o) \
$(SYSTEM)(do_getksig.o) \
$(SYSTEM)(do_endksig.o) \
$(SYSTEM)(do_kill.o) \
$(SYSTEM)(do_safecopy.o): do_safecopy.c
$(CC) do_safecopy.c
+$(SYSTEM)(do_sysctl.o): do_sysctl.c
+ $(CC) do_sysctl.c
+
$(SYSTEM)(do_segctl.o): do_segctl.c
$(CC) do_segctl.c
--- /dev/null
+/* The kernel call implemented in this file:
+ * m_type: SYS_SYSCTL
+ *
+ * The parameters for this kernel call are:
+ * SYSCTL_CODE request
+ * and then request-specific arguments in SYSCTL_ARG1 and SYSCTL_ARG2.
+ */
+
+#include "../system.h"
+#include "../vm.h"
+
+
+/*===========================================================================*
+ * do_sysctl *
+ *===========================================================================*/
+PUBLIC int do_sysctl(m_ptr)
+register message *m_ptr; /* pointer to request message */
+{
+ phys_bytes ph;
+ vir_bytes len, buf;
+ static char mybuf[DIAG_BUFSIZE];
+ struct proc *caller;
+ int s, i;
+
+ caller = proc_addr(who_p);
+
+ switch (m_ptr->SYSCTL_CODE) {
+ case SYSCTL_CODE_DIAG:
+ buf = (vir_bytes) m_ptr->SYSCTL_ARG1;
+ len = (vir_bytes) m_ptr->SYSCTL_ARG2;
+ if(len < 1 || len > DIAG_BUFSIZE) {
+ kprintf("do_sysctl: diag for %d: len %d out of range\n",
+ caller->p_endpoint, len);
+ return EINVAL;
+ }
+ if((ph=umap_local(caller, D, buf, len)) == 0)
+ return EFAULT;
+ CHECKRANGE_OR_SUSPEND(caller, ph, len, 1);
+ if((s=data_copy(who_e, buf, SYSTEM, (vir_bytes) mybuf, len)) != OK) {
+ kprintf("do_sysctl: diag for %d: len %d: copy failed: %d\n",
+ caller->p_endpoint, len, s);
+ return s;
+ }
+ for(i = 0; i < len; i++)
+ kputc(mybuf[i]);
+ kputc(END_OF_KMESS);
+ return OK;
+ break;
+ default:
+ kprintf("do_sysctl: invalid request %d\n", m_ptr->SYSCTL_CODE);
+ return(EINVAL);
+ }
+
+ minix_panic("do_sysctl: can't happen", NO_NUM);
+
+ return(OK);
+}
+
*/
#define FS_C SYS_KILL, SYS_VIRCOPY, SYS_SAFECOPYFROM, SYS_SAFECOPYTO, \
SYS_VIRVCOPY, SYS_UMAP, SYS_GETINFO, SYS_EXIT, SYS_TIMES, SYS_SETALARM, \
- SYS_PRIVCTL, SYS_TRACE , SYS_SETGRANT, SYS_PROFBUF
+ SYS_PRIVCTL, SYS_TRACE , SYS_SETGRANT, SYS_PROFBUF, SYS_SYSCTL
#define DRV_C FS_C, SYS_SEGCTL, SYS_IRQCTL, SYS_INT86, SYS_DEVIO, \
- SYS_SDEVIO, SYS_VDEVIO, SYS_SETGRANT, SYS_PROFBUF
+ SYS_SDEVIO, SYS_VDEVIO, SYS_SETGRANT, SYS_PROFBUF, SYS_SYSCTL
PRIVATE int
fs_c[] = { FS_C },
#define printf kprintf
#include "../lib/sysutil/kprintf.c"
-#define END_OF_KMESS 0
-
/*===========================================================================*
* kputc *
*===========================================================================*/
sys_physcopy.c \
sys_readbios.c \
sys_safecopy.c \
+ sys_sysctl.c \
sys_vsafecopy.c \
sys_profbuf.c \
sys_sdevio.c \
--- /dev/null
+
+#include "syslib.h"
+
+PUBLIC int sys_sysctl(int code, char *arg1, int arg2)
+{
+ message m;
+
+ m.SYSCTL_CODE = code;
+ m.SYSCTL_ARG1 = arg1;
+ m.SYSCTL_ARG2 = arg2;
+
+ return(_taskcall(SYSTASK, SYS_SYSCTL, &m));
+
+}
#include "sysutil.h"
-static char print_buf[80*25]; /* output is buffered here */
-
-int kputc_use_private_grants= 0;
+static char print_buf[DIAG_BUFSIZE]; /* output is buffered here */
/*===========================================================================*
* kputc *
message m;
if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
-#define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
- int procs[] = OUTPUT_PROCS_ARRAY;
- static int firstprint = 1;
- static cp_grant_id_t printgrants[PRINTPROCS];
- int p;
-
- if (kputc_use_private_grants)
- {
- for (p= 0; p<PRINTPROCS; p++)
- printgrants[p]= GRANT_INVALID;
- firstprint= 0;
- }
- if(firstprint) {
- for(p = 0; procs[p] != NONE; p++) {
- printgrants[p] = GRANT_INVALID;
- }
-
- firstprint = 0;
-
- /* First time? Initialize grant table;
- * Grant printing processes read copy access to our
- * print buffer forever. (So buffer can't be on stack!)
- */
- for(p = 0; procs[p] != NONE; p++) {
- printgrants[p] = cpf_grant_direct(procs[p],
- (vir_bytes) print_buf,
- sizeof(print_buf), CPF_READ);
- }
- }
-
- for(p = 0; procs[p] != NONE; p++) {
- /* Send the buffer to this output driver. */
- int may_asyn = 0;
- m.DIAG_BUF_COUNT = buf_count;
- if(GRANT_VALID(printgrants[p])) {
- m.m_type = DIAGNOSTICS_S;
- m.DIAG_PRINT_BUF_G = (char *) printgrants[p];
- may_asyn = 1;
- } else {
- m.m_type = DIAGNOSTICS;
- m.DIAG_PRINT_BUF_G = print_buf;
- }
- if(may_asyn && procs[p] == LOG_PROC_NR) {
- m.m_type = ASYN_DIAGNOSTICS;
- (void) asynsend(procs[p], &m);
- } else {
- sendrec(procs[p], &m);
- }
- }
-
+ sys_sysctl(SYSCTL_CODE_DIAG, print_buf, buf_count);
buf_count = 0;
-
- /* If the output fails, e.g., due to an ELOCKED, do not retry output
- * at the FS as if this were a normal user-land printf(). This may
- * result in even worse problems.
- */
}
if (c != 0) {
fs_m_in.REQ_INODE_INDEX < NR_INODES &&
inode[fs_m_in.REQ_INODE_INDEX].i_num == fs_m_in.REQ_INODE_NR) {
rip = &inode[fs_m_in.REQ_INODE_INDEX];
+ if(!rip) {
+ panic(__FILE__, "null rip", NO_NUM);
+ }
}
/* Otherwise find it */
else {
- rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR);
+ if(!(rip = find_inode(fs_dev, fs_m_in.REQ_INODE_NR))) {
+ printf("FSput_inode: inode #%d dev: %d not found, req_nr: %d\n",
+ fs_m_in.REQ_INODE_NR, fs_dev, req_nr);
+ }
}
if (!rip)
{
- printf("FSput_inode: inode #%d dev: %d couldn't be put, req_nr: %d\n",
- fs_m_in.REQ_INODE_NR, fs_dev, req_nr);
panic(__FILE__, "fs_putnode failed", NO_NUM);
}
OBJ = main.o forkexit.o break.o exec.o time.o timers.o \
signal.o utility.o table.o trace.o getset.o misc.o \
- profile.o kputc.o dma.o
+ profile.o dma.o
# build local binary
all build: $(SERVER)
+++ /dev/null
-/* A server must occasionally print some message. It uses a simple version of
- * printf() found in the system lib that calls kputc() to output characters.
- * Printing is done with a call to the kernel, and not by going through FS.
- *
- * This routine can only be used by servers and device drivers. The kernel
- * must define its own kputc(). Note that the log driver also defines its own
- * kputc() to directly call the TTY instead of going through this library.
- */
-
-#include "pm.h"
-#include <string.h>
-#include <minix/com.h>
-
-#define OVERFLOW_STR "[...]\n"
-
-#define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
-
-static char print_buf[800]; /* output is buffered here */
-
-int kputc_use_private_grants= 0;
-
-static int buf_count = 0; /* # characters in the buffer */
-static int buf_offset = 0; /* Start of current line in buffer */
-static int procs[] = OUTPUT_PROCS_ARRAY;
-static cp_grant_id_t printgrants[PRINTPROCS];
-static int procbusy[PRINTPROCS];
-static int do_flush = FALSE;
-static int overflow = FALSE;
-
-/*===========================================================================*
- * kputc *
- *===========================================================================*/
-void kputc(c)
-int c;
-{
-/* Accumulate another character. If 0 or buffer full, print it. */
- int p;
- message m;
-
- static int firstprint = 1;
-
- if (c == 0)
- {
- if (buf_count > buf_offset)
- do_flush= TRUE;
- }
- else if (buf_count >= sizeof(print_buf))
- {
- overflow= TRUE;
- if (buf_count > buf_offset)
- do_flush= TRUE;
- }
- else
- print_buf[buf_count++] = c;
-
- if (!do_flush || buf_offset != 0)
- return;
-
- buf_offset= buf_count;
- if (kputc_use_private_grants)
- {
- for (p= 0; p<PRINTPROCS; p++)
- printgrants[p]= GRANT_INVALID;
- firstprint= 0;
- }
- if(firstprint) {
- for(p = 0; procs[p] != NONE; p++) {
- printgrants[p] = GRANT_INVALID;
- }
-
- firstprint = 0;
-
- /* First time? Initialize grant table;
- * Grant printing processes read copy access to our
- * print buffer forever. (So buffer can't be on stack!)
- */
- for(p = 0; procs[p] != NONE; p++) {
- printgrants[p] = cpf_grant_direct(procs[p],
- (vir_bytes) print_buf,
- sizeof(print_buf), CPF_READ);
- }
- }
-
- do_flush= FALSE;
- for(p = 0; procs[p] != NONE; p++) {
- /* Send the buffer to this output driver. */
- m.DIAG_BUF_COUNT = buf_count;
- if(GRANT_VALID(printgrants[p])) {
- m.m_type = DIAGNOSTICS_S;
- m.DIAG_PRINT_BUF_G = (char *) printgrants[p];
- } else {
- m.m_type = DIAGNOSTICS;
- m.DIAG_PRINT_BUF_G = print_buf;
- }
- if (procs[p] == LOG_PROC_NR)
- {
- procbusy[p]= TRUE;
- (void) asynsend(procs[p], &m);
- }
- else
- {
- sendrec(procs[p], &m);
- }
- }
-}
-
-PUBLIC void diag_repl()
-{
- endpoint_t driver_e;
- int p;
-
- driver_e= m_in.m_source;
-
- /* Find busy flag to clear */
- for(p = 0; procs[p] != NONE; p++)
- {
- if (procs[p] == driver_e)
- break;
- }
- if (procs[p] == NONE)
- {
- /* Message from wrong source */
- return;
- }
- procbusy[p]= FALSE;
-
- /* Wait for more replies? */
- for(p = 0; procs[p] != NONE; p++)
- {
- if (procbusy[p])
- return;
- }
- if (buf_count > buf_offset)
- {
- memmove(&print_buf[0], &print_buf[buf_offset],
- buf_count-buf_offset);
- }
- buf_count -= buf_offset;
- buf_offset= 0;
- if (overflow)
- {
- if (buf_count + sizeof(OVERFLOW_STR) > sizeof(print_buf))
- buf_count= sizeof(print_buf)-sizeof(OVERFLOW_STR);
- overflow= FALSE;
- do_flush= FALSE;
- printf("%s", OVERFLOW_STR);
- }
- kputc(0);
-}
case GETPUID:
result= do_getpuid();
break;
- case DIAG_REPL :
- diag_repl();
- result= SUSPEND;
- break;
default:
/* Else, if the system call number is valid, perform the
* call.
{
int r;
phys_bytes retmembase;
- r = vm_allocmem(m_in.memsize, &retmembase);
+ r = vm_allocmem(m_in.memsize, (phys_clicks *) &retmembase);
if(r == OK)
mp->mp_reply.membase = retmembase;
return r;
case 0:
execle(rp->r_script, rp->r_script, rp->r_label, reason,
incarnation_str, NULL, NULL);
- {
- extern int kputc_use_private_grants;
- kputc_use_private_grants= 1;
- }
printf("RS: run_script: execl '%s' failed: %s\n",
rp->r_script, strerror(errno));
exit(1);
{ "MAPDMA", SYS_MAPDMA },
{ "VMCTL", SYS_VMCTL },
{ "PROFBUF", SYS_PROFBUF },
+ { "SYSCTL", SYS_SYSCTL },
{ NULL, 0 }
};
path.o device.o mount.o link.o exec.o \
filedes.o stadir.o protect.o time.o \
lock.o misc.o utility.o select.o timers.o table.o \
- vnode.o vmnt.o request.o kputc.o mmap.o
+ vnode.o vmnt.o request.o mmap.o
# build local binary
install all build: $(SERVER)
printf(
"VFSdev_up: error sending new driver endpoint. FS_e: %d req_nr: %d\n",
vmp->m_fs_e, REQ_NEW_DRIVER);
- else
- vmp->m_driver_e = new_driver_e;
}
/* Look for processes that are suspened in an OPEN call. Set SUSP_REOPEN
+++ /dev/null
-/* A server must occasionally print some message. It uses a simple version of
- * printf() found in the system lib that calls kputc() to output characters.
- * Printing is done with a call to the kernel, and not by going through FS.
- *
- * This routine can only be used by servers and device drivers. The kernel
- * must define its own kputc(). Note that the log driver also defines its own
- * kputc() to directly call the TTY instead of going through this library.
- */
-
-#include "fs.h"
-#include <string.h>
-#include <minix/com.h>
-
-#define OVERFLOW_STR "[...]\n"
-
-#define PRINTPROCS (sizeof(procs)/sizeof(procs[0]))
-
-static char print_buf[800]; /* output is buffered here */
-
-int kputc_use_private_grants= 0;
-
-static int buf_count = 0; /* # characters in the buffer */
-static int buf_offset = 0; /* Start of current line in buffer */
-static int procs[] = OUTPUT_PROCS_ARRAY;
-static cp_grant_id_t printgrants[PRINTPROCS];
-static int procbusy[PRINTPROCS];
-static int do_flush = FALSE;
-static int overflow = FALSE;
-
-/*===========================================================================*
- * kputc *
- *===========================================================================*/
-void kputc(c)
-int c;
-{
-/* Accumulate another character. If 0 or buffer full, print it. */
- int p;
- message m;
-
- static int firstprint = 1;
-
- if (c == 0)
- {
- if (buf_count > buf_offset)
- do_flush= TRUE;
- }
- else if (buf_count >= sizeof(print_buf))
- {
- overflow= TRUE;
- if (buf_count > buf_offset)
- do_flush= TRUE;
- }
- else
- print_buf[buf_count++] = c;
-
- if (!do_flush || buf_offset != 0)
- return;
-
- buf_offset= buf_count;
- if (kputc_use_private_grants)
- {
- for (p= 0; p<PRINTPROCS; p++)
- printgrants[p]= GRANT_INVALID;
- firstprint= 0;
- }
- if(firstprint) {
- for(p = 0; procs[p] != NONE; p++) {
- printgrants[p] = GRANT_INVALID;
- }
-
- firstprint = 0;
-
- /* First time? Initialize grant table;
- * Grant printing processes read copy access to our
- * print buffer forever. (So buffer can't be on stack!)
- */
- for(p = 0; procs[p] != NONE; p++) {
- printgrants[p] = cpf_grant_direct(procs[p],
- (vir_bytes) print_buf,
- sizeof(print_buf), CPF_READ);
- }
- }
-
- do_flush= FALSE;
- for(p = 0; procs[p] != NONE; p++) {
- /* Send the buffer to this output driver. */
- m.DIAG_BUF_COUNT = buf_count;
- if(GRANT_VALID(printgrants[p])) {
- m.m_type = DIAGNOSTICS_S;
- m.DIAG_PRINT_BUF_G = (char *) printgrants[p];
- } else {
- m.m_type = DIAGNOSTICS;
- m.DIAG_PRINT_BUF_G = print_buf;
- }
- if (procs[p] == LOG_PROC_NR)
- {
- procbusy[p]= TRUE;
- (void) asynsend(procs[p], &m);
- }
- else
- {
- sendrec(procs[p], &m);
- }
- }
-}
-
-PUBLIC void diag_repl()
-{
- endpoint_t driver_e;
- int p;
-
- driver_e= m_in.m_source;
-
- /* Find busy flag to clear */
- for(p = 0; procs[p] != NONE; p++)
- {
- if (procs[p] == driver_e)
- break;
- }
- if (procs[p] == NONE)
- {
- /* Message from wrong source */
- return;
- }
- procbusy[p]= FALSE;
-
- /* Wait for more replies? */
- for(p = 0; procs[p] != NONE; p++)
- {
- if (procbusy[p])
- return;
- }
- if (buf_count > buf_offset)
- {
- memmove(&print_buf[0], &print_buf[buf_offset],
- buf_count-buf_offset);
- }
- buf_count -= buf_offset;
- buf_offset= 0;
- if (overflow)
- {
- if (buf_count + sizeof(OVERFLOW_STR) > sizeof(print_buf))
- buf_count= sizeof(print_buf)-sizeof(OVERFLOW_STR);
- overflow= FALSE;
- do_flush= FALSE;
- printf("%s", OVERFLOW_STR);
- }
- kputc(0);
-}
if (who_e == PM_PROC_NR && call_nr != PROC_EVENT)
printf("FS: strange, got message %d from PM\n", call_nr);
-#if 0
- printf("VFS: got call %d from %d\n", call_nr, who_e);
-#endif
-
if (call_nr == DEV_REVIVE)
{
endpoint_t endpt;
select_reply2();
continue;
}
- if (call_nr == DIAG_REPL)
- {
- diag_repl();
- continue;
- }
/* Check for special control messages first. */
if ((call_nr & NOTIFY_MESSAGE)) {
/* Fill in max file size and blocksize for the vmnt */
vmp->m_fs_e = resX.fs_e;
vmp->m_dev = root_dev;
- vmp->m_driver_e = dp->dmap_driver;
vmp->m_flags = 0;
/* Root node is indeed on the partition */
root_node->v_vmnt = vmp;
root_node->v_dev = vmp->m_dev;
- /* Root directory is mounted on itself */
- vmp->m_mounted_on = root_node;
- root_node->v_ref_count++;
+ /* Root directory is not mounted on a vnode. */
+ vmp->m_mounted_on = NULL;
vmp->m_root_node = root_node;
}
{
/* Perform the FS side of the reboot call. */
int i;
- struct vnode vdummy;
struct vmnt *vmp;
+ do_sync();
+
+ CHECK_VREFS;
+
/* Do exit processing for all leftover processes and servers,
* but don't actually exit them (if they were really gone, PM
* will tell us about it).
*/
for (i = 0; i < NR_PROCS; i++)
if((m_in.endpt1 = fproc[i].fp_endpoint) != NONE)
- free_proc(&fproc[i], 0);
+ free_proc(&fproc[i], FP_EXITING);
+ CHECK_VREFS;
/* The root file system is mounted onto itself, which keeps it from being
* unmounted. Pull an inode out of thin air and put the root on it.
*/
-
- put_vnode(vmnt[0].m_mounted_on);
- vmnt[0].m_mounted_on = &vdummy;
- vmnt[0].m_root_node = &vdummy;
- vdummy.v_fs_count = 0; /* Is this right? */
- vdummy.v_ref_count = 1;
/* Unmount all filesystems. File systems are mounted on other file systems,
* so you have to pull off the loose bits repeatedly to get it all undone.
for (i= 0; i < NR_SUPERS; i++) {
/* Unmount at least one. */
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) {
- if (vmp->m_dev != NO_DEV) (void) unmount(vmp->m_dev);
+ if (vmp->m_dev != NO_DEV) {
+ printf("VFS: pm_reboot: unmount 0x%x, FS %d\n",
+ vmp->m_dev, vmp->m_fs_e);
+ CHECK_VREFS;
+ (void) unmount(vmp->m_dev);
+ CHECK_VREFS;
+ }
}
}
+
+ CHECK_VREFS;
+
}
/*===========================================================================*
dev_t dev;
message m;
struct vnode *vp, *root_node, *mounted_on, *bspec;
- struct vmnt *vmp, *vmp2;
+ struct vmnt *vmp;
char *label;
struct node_details res;
if (found) {
/* It is possible that we have an old root lying around that
* needs to be remounted. */
- if (vmp->m_mounted_on != vmp->m_root_node ||
- vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
+ if (vmp->m_mounted_on || vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) {
/* Normally, m_mounted_on refers to the mount point. For a
* root filesystem, m_mounted_on is equal to the root vnode.
* We assume that the root of FS is always the real root. If
return EBUSY; /* already mounted */
}
+ if(vmp->m_mounted_on)
+ panic("vfs", "root unexpectedly mounted somewhere", NO_NUM);
+
if (root_dev == vmp->m_dev)
panic("fs", "inconsistency remounting old root", NO_NUM);
}
/* Nothing else can go wrong. Perform the mount. */
- put_vnode(vmp->m_mounted_on);
vmp->m_mounted_on = mounted_on;
vmp->m_flags = m_in.rd_only;
allow_newroot = 0; /* The root is now fixed */
vmp->m_fs_e = res.fs_e;
vmp->m_dev = dev;
vmp->m_flags = m_in.rd_only;
- vmp->m_driver_e = dp->dmap_driver;
/* Root node is indeed on the partition */
root_node->v_vmnt = vmp;
/* Superblock and root node already read.
* Nothing else can go wrong. Perform the mount. */
vmp->m_root_node = root_node;
- root_node->v_ref_count++;
- vmp->m_mounted_on = root_node;
+ vmp->m_mounted_on = NULL;
root_dev = dev;
ROOT_FS_E = fs_e;
{
/* Perform the umount(name) system call. */
dev_t dev;
+ CHECK_VREFS;
/* Only the super-user may do UMOUNT. */
if (!super_user) return(EPERM);
+ CHECK_VREFS;
/* If 'name' is not for a block special file, return error. */
if (fetch_name(m_in.name, m_in.name_length, M3) != OK) return(err_code);
+ CHECK_VREFS;
if ( (dev = name_to_dev()) == NO_DEV) return(err_code);
+ CHECK_VREFS;
return(unmount(dev));
}
PUBLIC int unmount(dev)
Dev_t dev;
{
- struct vnode *vp;
+ struct vnode *vp, *vi;
struct vmnt *vmp_i = NULL, *vmp = NULL;
struct dmap *dp;
int count, r;
#if 1
int i;
struct fproc *tfp;
- printf("unmount: vnode %d in use %d times\n",
- vp->v_inode_nr, vp->v_ref_count);
+ printf("unmount: vnode 0x%x/%d in use %d times\n",
+ dev, vp->v_inode_nr, vp->v_ref_count);
for (i= 0, tfp= fproc; i<NR_PROCS; i++, tfp++) {
int n;
if (tfp->fp_pid == PID_FREE)
vp->v_inode_nr, n, tfp->fp_pid);
}
}
+
+ for (vmp_i = &vmnt[0]; vmp_i < &vmnt[NR_MNTS]; ++vmp_i) {
+ if (vmp_i->m_dev != NO_DEV) {
+ if(vmp_i->m_mounted_on == vp) {
+ printf("\tvnode %d: is a mount point\n",
+ vp->v_inode_nr);
+ }
+ if(vmp_i->m_root_node == vp) {
+ printf("\tvnode %d: is a root node\n",
+ vp->v_inode_nr);
+ }
+ }
+ }
#endif
count += vp->v_ref_count;
}
}
+ CHECK_VREFS;
if (count > 1) {
return(EBUSY); /* can't umount a busy file system */
}
+ CHECK_VREFS;
+
vnode_clean_refs(vmp->m_root_node);
+ CHECK_VREFS;
+
+ if (vmp->m_mounted_on) {
+ put_vnode(vmp->m_mounted_on);
+ vmp->m_mounted_on->v_fs_count--;
+ vmp->m_mounted_on = NIL_VNODE;
+ }
+
+ put_vnode(vmp->m_root_node);
+ vmp->m_root_node->v_ref_count = 0;
+ vmp->m_root_node = NIL_VNODE;
/* Request FS the unmount */
- if(vmp->m_fs_e <= 0)
+ if(vmp->m_fs_e <= 0 || vmp->m_fs_e == NONE)
panic(__FILE__, "unmount: strange fs endpoint", vmp->m_fs_e);
- if ((r = req_unmount(vmp->m_fs_e)) != OK) return r;
+ if ((r = req_unmount(vmp->m_fs_e)) != OK) {
+ /* Not recoverable. */
+ printf("VFS: ignoring unmount failure %d from %d\n", r, vmp->m_fs_e);
+ }
+
+ vmp->m_dev = NO_DEV;
+ vmp->m_fs_e = NONE;
+
+ CHECK_VREFS;
/* Is there a block special file that was handled by that partition? */
for (vp = &vnode[0]; vp < &vnode[NR_VNODES]; vp++) {
}
}
- /* Root device is mounted on itself */
- if (vmp->m_root_node != vmp->m_mounted_on) {
- put_vnode(vmp->m_mounted_on);
- vmp->m_root_node->v_ref_count = 0;
- }
- else {
- vmp->m_mounted_on->v_fs_count--;
- }
-
- fs_e = vmp->m_fs_e;
-
- vmp->m_root_node = NIL_VNODE;
- vmp->m_mounted_on = NIL_VNODE;
- vmp->m_dev = NO_DEV;
- vmp->m_fs_e = NONE;
- vmp->m_driver_e = NONE;
CHECK_VREFS;
return(OK);
_PROTOTYPE( struct vnode *get_vnode_x, (int fs_e, int inode_nr) );
_PROTOTYPE( void mark_vn, (struct vnode *vp, char *file, int line) );
#endif
-#define CHECK_VREFS do { if(!check_vrefs()) panic("VFS", "check_vrefs failed", NO_NUM);} while(0)
+#define CHECK_VREFS do { if(!check_vrefs()) { \
+ printf("VFS:%s:%d: check_vrefs failed\n", __FILE__, __LINE__); \
+ panic("VFS", "check_vrefs failed", NO_NUM);} } while(0)
_PROTOTYPE( int check_vrefs, (void) );
/* write.c */
/* Issue request */
if ((r = sendrec(fs_e, &m)) != OK) {
printf("VFSreq_newdriver: error sending message to %d: %d\n", fs_e, r);
+ util_stacktrace();
return r;
}
message origm, m;
struct vmnt *vmp;
- if (fs_e == PM_PROC_NR)
- {
- printf("from %s, %d\n", file, line);
- panic(__FILE__, "talking to PM", NO_NUM);
- }
+ if(fs_e <= 0 || fs_e == NONE)
+ panic(__FILE__, "talking to bogus endpoint", fs_e);
/* Make a copy of the request so that we can load it back in
* case of a dead driver */
if (OK != (r=sendrec(fs_e, reqm))) {
printf("VFS:fs_sendrec:%s:%d: error sending message. FS_e: %d req_nr: %d err: %d\n",
file, line, fs_e, reqm->m_type, r);
+ util_stacktrace();
return r;
}
/* Find old driver by endpoint */
for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) {
if (vmp->m_fs_e == fs_e) { /* found FS */
+#if 0
old_driver_e = vmp->m_driver_e;
+#endif
dmap_unmap_by_endpt(old_driver_e); /* unmap driver */
break;
}
EXTERN struct vmnt {
int m_fs_e; /* FS process' kernel endpoint */
dev_t m_dev; /* device number */
- int m_driver_e; /* device driver process' kernel endpoint */
int m_flags; /* mount flags */
struct vnode *m_mounted_on; /* the vnode on which the partition is mounted */
struct vnode *m_root_node; /* root vnode */
#include <minix/vfsif.h>
+/* Is vnode pointer reasonable? */
+#define SANEVP(v) ((((v) >= &vnode[0] && (v) < &vnode[NR_VNODES])))
+
+#define BADVP(v, f, l) printf("%s:%d: bad vp 0x%x\n", f, l, v)
+
+/* vp check that returns 0 for use in check_vrefs() */
+#define CHECKVN(v) if(!SANEVP(v)) { \
+ BADVP(v, __FILE__, __LINE__); \
+ return 0; \
+}
+
+/* vp check that panics */
+#define ASSERTVP(v) if(!SANEVP(v)) { \
+ BADVP(v, __FILE__, __LINE__); panic("vfs", "bad vp", NO_NUM); }
/*===========================================================================*
* get_free_vnode *
/* dup_vnode() is called to increment the vnode and therefore the
* referred inode's counter.
*/
- if (vp == NIL_VNODE) {
- printf("VFSdup_vnode NIL_VNODE\n");
- return;
- }
-
+ ASSERTVP(vp);
vp->v_ref_count++;
}
/* Decrease vnode's usage counter and decrease inode's usage counter in the
* corresponding FS process.
*/
- if (vp == NIL_VNODE) {
- /*printf("VFSput_vnode NIL_VNODE\n");*/
- return;
- }
-
- if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
- {
- printf("put_vnode: &vnode[0] = %p, &vnode[NR_VNODES] = %p, vp = %p\n",
- &vnode[0], &vnode[NR_VNODES], vp);
- panic(__FILE__, "put_vnode: bad vnode pointer", NO_NUM);
- }
+ ASSERTVP(vp);
if (vp->v_ref_count > 1)
{
}
#endif
+#define REFVP(v) { vp = (v); CHECKVN(v); vp->v_ref_check++; }
+
/*===========================================================================*
* check_vrefs *
*===========================================================================*/
for (rfp=&fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
if (rfp->fp_pid == PID_FREE)
continue;
- vp= rfp->fp_rd;
- if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
- panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
- vp->v_ref_check++;
-
- vp= rfp->fp_wd;
- if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
- panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
- vp->v_ref_check++;
-
+ REFVP(rfp->fp_rd);
+ REFVP(rfp->fp_wd);
}
/* Count references from filedescriptors */
{
if (f->filp_count == 0)
continue;
- vp= f->filp_vno;
- if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
- panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
- vp->v_ref_check++;
+ REFVP(f->filp_vno);
}
/* Count references to mount points */
{
if (vmp->m_dev == NO_DEV)
continue;
- vp= vmp->m_mounted_on;
- if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
- panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
- vp->v_ref_check++;
-
- vp= vmp->m_root_node;
- if (vp < &vnode[0] || vp >= &vnode[NR_VNODES])
- panic(__FILE__, "check_vrefs: bad vnode", NO_NUM);
- vp->v_ref_check++;
+ REFVP(vmp->m_root_node);
+ if(vmp->m_mounted_on)
+ REFVP(vmp->m_mounted_on);
}
/* Check references */