Make the major numbers accessible to init

上级 c822bacf
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "user.h" #include "user.h"
#include "fcntl.h" #include "fcntl.h"
#include "lib.h" #include "lib.h"
#include "major.h"
static const char *sh_argv[] = { "sh", 0 }; static const char *sh_argv[] = { "sh", 0 };
static const char *app_argv[][MAXARG] = { static const char *app_argv[][MAXARG] = {
...@@ -18,11 +19,11 @@ static struct { ...@@ -18,11 +19,11 @@ static struct {
const char* name; const char* name;
int major; int major;
} dev[] = { } dev[] = {
{ "/dev/netif", 2 }, { "/dev/netif", MAJ_NETIF },
{ "/dev/sampler", 3 }, { "/dev/sampler", MAJ_SAMPLER },
{ "/dev/lockstat", 4 }, { "/dev/lockstat", MAJ_LOCKSTAT },
{ "/dev/stat", 5 }, { "/dev/stat", MAJ_STAT },
{ "/dev/cmdline", 6}, { "/dev/cmdline", MAJ_CMDLINE},
}; };
static int static int
......
...@@ -80,10 +80,3 @@ struct devsw { ...@@ -80,10 +80,3 @@ struct devsw {
}; };
extern struct devsw devsw[]; extern struct devsw devsw[];
#define CONSOLE 1
#define NETIF 2
#define SAMPLER 3
#define DEVLOCKSTAT 4
#define DEVSTAT 5
#define DEVCMDLINE 6
#define MAJ_CONSOLE 1
#define MAJ_NETIF 2
#define MAJ_SAMPLER 3
#define MAJ_LOCKSTAT 4
#define MAJ_STAT 5
#define MAJ_CMDLINE 6
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "condvar.h" #include "condvar.h"
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
#include "major.h"
extern char cmdline[]; extern char cmdline[];
...@@ -28,6 +29,6 @@ initcmdline(void) ...@@ -28,6 +29,6 @@ initcmdline(void)
if (VERBOSE) if (VERBOSE)
cprintf("cmdline: %s\n", cmdline); cprintf("cmdline: %s\n", cmdline);
devsw[DEVCMDLINE].write = nullptr; devsw[MAJ_CMDLINE].write = nullptr;
devsw[DEVCMDLINE].read = cmdlineread; devsw[MAJ_CMDLINE].read = cmdlineread;
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "fmt.hh" #include "fmt.hh"
#include "sperf.hh" #include "sperf.hh"
#include "wq.hh" #include "wq.hh"
#include "major.h"
#define BACKSPACE 0x100 #define BACKSPACE 0x100
...@@ -341,8 +342,8 @@ initconsole(void) ...@@ -341,8 +342,8 @@ initconsole(void)
initlock(&cons.lock, "console", LOCKSTAT_CONSOLE); initlock(&cons.lock, "console", LOCKSTAT_CONSOLE);
cons.locking = 1; cons.locking = 1;
devsw[CONSOLE].write = consolewrite; devsw[MAJ_CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread; devsw[MAJ_CONSOLE].read = consoleread;
picenable(IRQ_KBD); picenable(IRQ_KBD);
ioapicenable(IRQ_KBD, 0); ioapicenable(IRQ_KBD, 0);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
#include "net.hh" #include "net.hh"
#include "major.h"
#ifdef LWIP #ifdef LWIP
extern "C" { extern "C" {
...@@ -249,8 +250,8 @@ initnet(void) ...@@ -249,8 +250,8 @@ initnet(void)
{ {
struct proc *t; struct proc *t;
devsw[NETIF].write = nullptr; devsw[MAJ_NETIF].write = nullptr;
devsw[NETIF].read = netifread; devsw[MAJ_NETIF].read = netifread;
t = threadalloc(initnet_worker, nullptr); t = threadalloc(initnet_worker, nullptr);
if (t == nullptr) if (t == nullptr)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "amd64.h" #include "amd64.h"
#include "cpu.hh" #include "cpu.hh"
#include "sampler.h" #include "sampler.h"
#include "major.h"
#define LOGHEADER_SZ (sizeof(struct logheader) + \ #define LOGHEADER_SZ (sizeof(struct logheader) + \
sizeof(((struct logheader*)0)->cpu[0])*NCPU) sizeof(((struct logheader*)0)->cpu[0])*NCPU)
...@@ -273,7 +274,7 @@ initsamp(void) ...@@ -273,7 +274,7 @@ initsamp(void)
pmulog[myid()].event = (pmuevent*) p; pmulog[myid()].event = (pmuevent*) p;
pmulog[myid()].capacity = PERFSIZE / sizeof(struct pmuevent); pmulog[myid()].capacity = PERFSIZE / sizeof(struct pmuevent);
devsw[SAMPLER].write = sampwrite; devsw[MAJ_SAMPLER].write = sampwrite;
devsw[SAMPLER].read = sampread; devsw[MAJ_SAMPLER].read = sampread;
devsw[SAMPLER].stat = sampstat; devsw[MAJ_SAMPLER].stat = sampstat;
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "wq.hh" #include "wq.hh"
#include "percpu.hh" #include "percpu.hh"
#include "sperf.hh" #include "sperf.hh"
#include "major.h"
enum { sched_debug = 0 }; enum { sched_debug = 0 };
enum { steal_nonexec = 1 }; enum { steal_nonexec = 1 };
...@@ -327,6 +328,6 @@ initsched(void) ...@@ -327,6 +328,6 @@ initsched(void)
for (int i = 0; i < NCPU; i++) for (int i = 0; i < NCPU; i++)
new (&schedule_[i]) schedule(); new (&schedule_[i]) schedule();
devsw[DEVSTAT].write = nullptr; devsw[MAJ_STAT].write = nullptr;
devsw[DEVSTAT].read = statread; devsw[MAJ_STAT].read = statread;
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "condvar.h" #include "condvar.h"
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
#include "major.h"
#if LOCKSTAT #if LOCKSTAT
static int lockstat_enable; static int lockstat_enable;
...@@ -241,8 +242,8 @@ lockstat_write(struct inode *ip, const char *buf, u32 off, u32 n) ...@@ -241,8 +242,8 @@ lockstat_write(struct inode *ip, const char *buf, u32 off, u32 n)
void void
initlockstat(void) initlockstat(void)
{ {
devsw[DEVLOCKSTAT].write = lockstat_write; devsw[MAJ_LOCKSTAT].write = lockstat_write;
devsw[DEVLOCKSTAT].read = lockstat_read; devsw[MAJ_LOCKSTAT].read = lockstat_read;
} }
#else #else
void void
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论