~mcf/plan9front

ref: 67a3b368bfbf7bf88f7561754392734c6c50bf5d plan9front/sys/src/cmd/vmx/9p.c -rw-r--r-- 1.1 KiB
67a3b368 vmx: avoid strdup() register names for register cache 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <fcall.h>
#include <9p.h>
#include "dat.h"
#include "fns.h"

extern int regsfd;
char Egreg[] = "the front fell off";

enum {
	Qregs,
	Qmem,
	Qmax
};

static Dir files[] = {
	[Qregs] {.name "regs", .mode 0440},
	[Qmem] {.name "mem", .mode 0440},
};

void
srvread(Req *r)
{
	int rc;

	switch((int)r->fid->qid.path){
	case Qregs:
		rc = pread(regsfd, r->ofcall.data, r->ifcall.count, r->ifcall.offset);
		if(rc < 0)
			responderror(r);
		else{
			r->ofcall.count = rc;
			respond(r, nil);
		}
		break;
	case Qmem:
		r->ofcall.count = vmemread(r->ofcall.data, r->ifcall.count, r->ifcall.offset);
		if(r->ofcall.count == 0)
			respond(r, "fault");
		else
			respond(r, nil);
		break;
	default:
		respond(r, Egreg);
	}
}

Srv vmxsrv = {
	.read srvread,
};

void
init9p(char *srvname)
{
	char *uid;
	int i;
	
	uid = getuser();
	vmxsrv.tree = alloctree(uid, uid, 0770, nil);
	for(i = 0; i < Qmax; i++)
		createfile(vmxsrv.tree->root, files[i].name, uid, files[i].mode, nil);
	threadpostmountsrv(&vmxsrv, srvname, nil, 0);
}