summaryrefslogtreecommitdiff
path: root/appl/demo/ns
diff options
context:
space:
mode:
Diffstat (limited to 'appl/demo/ns')
-rw-r--r--appl/demo/ns/mkfile27
-rw-r--r--appl/demo/ns/ns.b124
-rw-r--r--appl/demo/ns/ns.disbin0 -> 1973 bytes
-rw-r--r--appl/demo/ns/ns.sbl420
-rwxr-xr-xappl/demo/ns/runns.sh7
5 files changed, 578 insertions, 0 deletions
diff --git a/appl/demo/ns/mkfile b/appl/demo/ns/mkfile
new file mode 100644
index 00000000..c701e498
--- /dev/null
+++ b/appl/demo/ns/mkfile
@@ -0,0 +1,27 @@
+<../../../mkconfig
+
+TARG=\
+ ns.dis\
+
+SHTARG=\
+ runns.sh\
+
+MODULES=\
+
+SYSMODULES= \
+ arg.m\
+ draw.m\
+ sh.m\
+ sys.m\
+
+DISBIN=$ROOT/dis/demo/ns
+
+<$ROOT/mkfiles/mkdis
+
+SHFILES=${SHTARG:%.sh=$DISBIN/%}
+install:V: $SHFILES
+%.install:V: $DISBIN/%
+%.installall:V: $DISBIN/%
+
+$DISBIN/%: %.sh
+ cp $stem.sh $target && chmod a+rx $target
diff --git a/appl/demo/ns/ns.b b/appl/demo/ns/ns.b
new file mode 100644
index 00000000..266a07ff
--- /dev/null
+++ b/appl/demo/ns/ns.b
@@ -0,0 +1,124 @@
+implement Ns;
+
+#
+# Copyright © 2003 Vita Nuova Holdings Limited. All rights reserved.
+#
+
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "arg.m";
+include "sh.m";
+ sh: Sh;
+
+ns : list of string;
+
+Ns: module {
+ init: fn(nil: ref Draw->Context, argv: list of string);
+};
+
+init(nil: ref Draw->Context, argv: list of string)
+{
+ sys = load Sys Sys->PATH;
+ if (sys == nil)
+ badmod(Sys->PATH);
+ sh = load Sh Sh->PATH;
+ if (sh == nil)
+ badmod(Sh->PATH);
+ # sys->pctl(sys->FORKNS, nil);
+ sys->unmount(nil, "/n/remote");
+ arg := load Arg Arg->PATH;
+ if (arg == nil)
+ badmod(Arg->PATH);
+
+ arg->init(argv);
+ arg->setusage("ns [-v] [-r relpath] paths...");
+ verbose := 0;
+ relpath := "";
+ while ((opt := arg->opt()) != 0) {
+ case opt {
+ 'v' =>
+ verbose = 1;
+ 'r' =>
+ relpath = arg->earg();
+ if (relpath == nil)
+ arg->usage();
+ if (relpath[len relpath - 1] != '/')
+ relpath[len relpath] = '/';
+ * =>
+ arg->usage();
+ }
+ }
+
+ ns = arg->argv();
+ arg = nil;
+ if (ns == nil) {
+ sys->fprint(fdout(), "error no namespace selected\n");
+ exit;
+ }
+ spawn buildns(relpath, verbose);
+}
+
+fdout(): ref sys->FD
+{
+ return sys->fildes(1);
+}
+
+buildns(relpath: string, verbose: int)
+{
+ # sys->pctl(sys->FORKNS, nil);
+ if (sh->run(nil, "memfs"::"/n/remote"::nil) != nil) {
+ sys->fprint(fdout(), "error MemFS mount failed\n");
+ exit;
+ }
+ for (tmpl := ns; tmpl != nil; tmpl = tl tmpl) {
+ nspath := hd tmpl;
+ if (nspath[len nspath - 1] != '/')
+ nspath[len nspath] = '/';
+
+ bindpath := nspath;
+ if (bindpath[:len relpath] == relpath) {
+ bindpath = "/n/remote/"+bindpath[len relpath:];
+ if (createdir(bindpath) != -1) {
+ if (sys->bind(nspath, bindpath, sys->MBEFORE | sys->MCREATE) == -1) {
+ if (sys->bind(nspath, bindpath, sys->MBEFORE) == -1)
+ sys->fprint(fdout(), "error bind failed %s: %r\n",bindpath);
+ else if (verbose)
+ sys->fprint(fdout(), "data nspath %s\n", nspath);
+ }
+ else if (verbose)
+ sys->fprint(fdout(), "data nspath %s\n", nspath);
+ }
+ else
+ sys->fprint(fdout(), "error create failed %s\n",bindpath);
+ }
+ }
+ spawn exportns();
+}
+
+exportns()
+{
+ sys->export(sys->fildes(0), "/n/remote", sys->EXPWAIT);
+}
+
+createdir(path: string): int
+{
+ (nil, lst) := sys->tokenize(path, "/");
+ npath := "";
+ for (; lst != nil; lst = tl lst) {
+ (n, nil) := sys->stat(npath + "/" + hd lst);
+ if (n == -1) {
+ fd := sys->create(npath + "/" + hd lst, sys->OREAD, 8r777 | sys->DMDIR);
+ if (fd == nil)
+ return -1;
+ }
+ npath += "/" + hd lst;
+ }
+ return 0;
+}
+
+badmod(path: string)
+{
+ sys->fprint(fdout(), "error Ns: failed to load: %s\n",path);
+ exit;
+}
diff --git a/appl/demo/ns/ns.dis b/appl/demo/ns/ns.dis
new file mode 100644
index 00000000..48a9a1f5
--- /dev/null
+++ b/appl/demo/ns/ns.dis
Binary files differ
diff --git a/appl/demo/ns/ns.sbl b/appl/demo/ns/ns.sbl
new file mode 100644
index 00000000..52233184
--- /dev/null
+++ b/appl/demo/ns/ns.sbl
@@ -0,0 +1,420 @@
+limbo .sbl 2.1
+Ns
+5
+ns.b
+sys.m
+draw.m
+arg.m
+sh.m
+263
+22.1,25 0
+23.5,15 1
+24.2,19 2
+9,18 2
+2,19 2
+25.1,22 3
+26.5,14 4
+27.2,18 5
+9,17 5
+2,18 5
+29.1,31 6
+14,17 6
+19,30 6
+1,31 6
+1,31 6
+30.1,26 7
+31.5,15 8
+32.2,19 9
+9,18 9
+2,19 9
+34.1,16 10
+11,15 10
+1,16 10
+35.1,47 11
+15,46 11
+1,47 11
+36.1,13 12
+37.1,14 13
+38.8,27 14
+8,27 14
+8,27 14
+8,27 14
+8,32 14
+39.7,10 15
+7,10 15
+7,10 15
+7,10 15
+41.3,14 16
+3,14 15
+43.3,24 17
+3,24 17
+3,24 17
+44.7,21 18
+45.4,16 19
+4,16 19
+46.15,26 20
+15,30 20
+7,31 20
+7,38 20
+47.12,23 21
+4,30 21
+4,30 15
+49.3,15 22
+3,15 22
+3,15 15
+53.1,17 23
+1,17 23
+1,17 23
+54.1,10 24
+55.5,14 25
+56.14,21 26
+14,21 26
+14,21 26
+14,21 26
+2,55 26
+2,55 26
+2,55 27
+23,54 26
+2,55 26
+2,55 26
+57.2,6 28
+59.1,32 29
+15,22 29
+24,31 29
+1,32 29
+60.0,1 30
+70.5,44 31
+13,16 31
+40,43 31
+27,43 31
+18,43 31
+18,43 31
+18,43 32
+5,44 31
+5,44 31
+5,51 31
+5,51 33
+71.14,21 34
+14,21 34
+14,21 34
+14,21 34
+2,52 34
+2,52 34
+2,52 35
+23,51 34
+2,52 34
+2,52 34
+72.2,6 36
+74.6,16 37
+18,29 38
+75.2,19 39
+76.13,23 40
+13,27 40
+6,28 40
+6,35 40
+77.10,20 41
+3,27 41
+79.2,20 42
+80.16,27 43
+6,14 43
+6,28 43
+6,39 43
+6,39 44
+81.27,49 45
+36,47 45
+27,35 45
+27,49 45
+3,49 45
+3,49 46
+82.7,26 47
+17,25 47
+7,26 47
+7,26 47
+7,32 47
+83.8,64 48
+18,24 48
+26,34 48
+36,63 48
+8,64 48
+8,64 48
+8,70 48
+84.9,50 49
+19,25 49
+27,35 49
+37,49 49
+9,50 49
+9,50 49
+9,56 49
+85.18,25 50
+18,25 50
+18,25 50
+18,25 50
+6,65 50
+6,65 50
+6,65 51
+27,55 50
+56,64 50
+6,65 50
+6,65 50
+6,65 52
+86.14,21 53
+87.18,25 54
+18,25 54
+18,25 54
+18,25 54
+6,54 54
+6,54 54
+6,54 55
+27,45 54
+47,53 54
+6,54 54
+6,54 54
+6,54 56
+89.13,20 57
+90.17,24 58
+17,24 58
+17,24 58
+17,24 58
+5,53 58
+5,53 58
+5,53 59
+26,44 58
+46,52 58
+5,53 58
+5,53 58
+5,53 60
+93.16,23 61
+16,23 61
+16,23 61
+16,23 61
+4,61 61
+4,61 61
+4,61 62
+25,51 61
+52,60 61
+4,61 61
+4,61 61
+4,61 63
+4,61 64
+74.31,45 65
+31,45 65
+96.1,17 66
+1,17 66
+97.0,1 67
+101.13,27 68
+25,26 68
+13,27 68
+13,27 68
+1,55 68
+1,55 68
+1,55 69
+29,40 68
+42,54 68
+1,55 68
+1,55 68
+102.0,1 70
+106.15,39 71
+29,33 71
+35,38 71
+15,39 71
+15,39 71
+7,10 71
+7,10 72
+107.1,12 73
+108.8,18 74
+109.14,45 75
+24,35 75
+38,44 75
+24,44 75
+24,44 76
+24,44 77
+14,45 75
+14,45 75
+3,4 75
+3,4 78
+3,4 79
+3,4 80
+3,4 81
+110.6,13 82
+111.3,74 83
+21,32 83
+35,41 83
+21,41 83
+21,41 84
+21,41 85
+43,53 83
+55,73 83
+3,74 83
+3,74 83
+112.7,16 86
+113.11,13 87
+4,13 87
+4,13 88
+115.17,23 89
+11,23 89
+2,23 89
+2,23 90
+108.20,32 91
+20,32 91
+117.8,9 92
+1,9 92
+122.13,20 93
+13,20 93
+13,20 93
+13,20 93
+1,60 93
+1,60 93
+1,60 94
+22,54 93
+55,59 93
+1,60 93
+1,60 93
+123.1,5 95
+12
+aSys->Dir 1:26.1,39.2 64
+11
+0:name:28.2,6 s
+4:uid:29.2,5 s
+8:gid:30.2,5 s
+12:muid:31.2,6 s
+16:qid:32.2,5 @1
+
+32:mode:33.2,6 i
+36:atime:34.2,7 i
+40:mtime:35.2,7 i
+48:length:36.2,8 B
+56:dtype:37.2,7 i
+60:dev:38.2,5 i
+aSys->Qid 11.1,16.2 16
+3
+0:path:13.2,6 B
+8:vers:14.2,6 i
+12:qtype:15.2,7 i
+aDraw->Chans 2:70.1,82.2 4
+1
+0:desc:72.2,6 i
+aDraw->Context 274.1,279.2 12
+3
+0:display:276.2,9 R@4
+
+4:screen:277.2,8 R@8
+
+8:wm:278.2,4 Ct8.2
+0:t0:15,21 s
+4:t1:15,21 Ct8.2
+0:t0:32,38 s
+4:t1:32,38 R@9
+
+
+
+aDraw->Display 201.1,230.2 20
+5
+0:image:203.2,7 R@5
+
+4:white:204.2,7 R@5
+
+8:black:205.2,7 R@5
+
+12:opaque:206.2,8 R@5
+
+16:transparent:207.2,13 R@5
+
+aDraw->Image 142.1,198.2 56
+8
+0:r:146.2,3 @6
+
+16:clipr:147.2,7 @6
+
+32:depth:148.2,7 i
+36:chans:149.2,7 @2
+
+40:repl:150.2,6 i
+44:display:151.2,9 R@4
+
+48:screen:152.2,8 R@8
+
+52:iname:153.2,7 s
+aDraw->Rect 116.1,139.2 16
+2
+0:min:118.2,5 @7
+
+8:max:119.2,5 @7
+
+aDraw->Point 99.1,113.2 8
+2
+0:x:101.2,3 i
+4:y:102.2,3 i
+aDraw->Screen 249.1,263.2 16
+4
+0:id:251.2,4 i
+4:image:252.2,7 R@5
+
+8:fill:253.2,6 R@5
+
+12:display:254.2,9 R@4
+
+aDraw->Wmcontext 282.1,291.2 28
+7
+0:kbd:284.2,5 Ci
+4:ptr:285.2,5 CR@10
+
+8:ctl:286.2,5 Cs
+12:wctl:287.2,6 Cs
+16:images:288.2,8 CR@5
+
+20:connfd:289.2,8 R@11
+
+24:ctxt:290.2,6 R@3
+
+aDraw->Pointer 266.1,271.2 16
+3
+0:buttons:268.2,9 i
+4:xy:269.2,4 @7
+
+12:msec:270.2,6 i
+aSys->FD 1:45.1,48.2 4
+1
+0:fd:47.2,4 i
+5
+0:init
+1
+36:argv:0:20.29,33 Ls
+4
+40:arg:30.1,4 mArg
+3:1.0,14.1 0
+
+44:relpath:0:37.1,8 s
+48:verbose:36.1,8 i
+52:opt:38.9,12 i
+n76:buildns
+2
+32:relpath:67.8,15 s
+36:verbose:25,32 i
+3
+40:nspath:75.2,8 s
+44:bindpath:79.2,10 s
+48:tmpl:74.6,10 Ls
+n194:exportns
+0
+0
+n206:createdir
+1
+32:path:104.10,14 s
+4
+36:lst:106.7,10 Ls
+40:npath:107.1,6 s
+44:fd:111.3,5 R@11
+
+48:n:109.3,4 i
+i251:badmod
+1
+32:path:120.7,11 s
+0
+n3
+88:ns:14.0,2 Ls
+96:sh:12.1,3 mSh
+4:8.0,95.1 0
+
+100:sys:0:8.1,4 mSys
+1:4.0,160.1 0
+
diff --git a/appl/demo/ns/runns.sh b/appl/demo/ns/runns.sh
new file mode 100755
index 00000000..6394c468
--- /dev/null
+++ b/appl/demo/ns/runns.sh
@@ -0,0 +1,7 @@
+#!/dis/sh
+load std
+if {~ $#* 0} {
+ echo usage: runns path0 path1 ... pathn
+ raise usage
+}
+grid/register -a resource Namespace 'grid/srv/ns '^$"* | grid/srv/monitor 1 'Namespace'