From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <69c0bc11b75703468171eb698a635ec5@plan9.escet.urjc.es> To: 9fans@cse.psu.edu From: Fco.J.Ballesteros MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-xkhgrtcaofjdqwjgvuvukobvbj" Subject: [9fans] autofs Date: Tue, 16 Jul 2002 10:58:18 +0200 Topicbox-Message-UUID: cca6de12-eaca-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-xkhgrtcaofjdqwjgvuvukobvbj Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I loved the idea so much, that I couldn't wait. Enjoy. --upas-xkhgrtcaofjdqwjgvuvukobvbj Content-Disposition: attachment; filename=autofs Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit .TH AUTOFS 4 .SH NAME autofs \- automatically supply mount points for file systems .SH SYNOPSIS .B autofs [ .I mnt ] .SH DESCRIPTION .I Autofs implements a single directory that creates inner directories on demand, when referenced. It is intended to supply mount points automatically. .PP By default .I autofs mounts itself at .B /n unless a .I mnt mount point is specified. .SH SOURCE .B /sys/src/cmd/autofs.c --upas-xkhgrtcaofjdqwjgvuvukobvbj Content-Disposition: attachment; filename=autofs.c Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit #include #include #include #include #include <9p.h> enum { Qroot = ~0, }; static void aopen(Req*); static void aread(Req*); static void astat(Req*); static void awstat(Req*); static char* awalk1(Fid* fid, char *name, Qid *qid); static void aattach(Req*); char** names; int nnames; Srv asrv = { .tree = nil, .attach = aattach, .auth = nil, .open = aopen, .create = nil, .read = aread, .write = nil, .remove = nil, .flush = nil, .stat = astat, .wstat = awstat, .walk = nil, .walk1 = awalk1, .clone = nil, .destroyfid = nil, .destroyreq = nil, .end = nil, .aux = nil, .infd = -1, .outfd = -1, .nopipe = 0, .srvfd = -1, }; static void usage(void) { fprint(2, "usage: %s [mnt]\n", argv0); exits("usage"); } static void aattach(Req* r) { Qid q; q.type = QTDIR; q.path = Qroot; q.vers = 0; r->fid->qid = q; r->ofcall.qid = q; respond(r, nil); } static void aopen(Req* r) { respond(r, nil); } static int agen(int n, Dir *dir, void* a) { if (a == nil || n < 0 || n >= nnames) return -1; dir->qid.type = QTDIR; dir->qid.path = n; dir->qid.vers = 0; dir->name = estrdup9p(names[n]); dir->uid = estrdup9p("sys"); dir->gid = estrdup9p("sys"); dir->mode= 0555|DMDIR; dir->length= 0; return 0; } static void aread(Req* r) { Qid q; q = r->fid->qid; if (q.path < 0 || q.path >= nnames && q.path != Qroot) respond(r, "bug: bad qid"); if (q.path == Qroot) dirread9p(r, agen, names); else dirread9p(r, agen, nil); respond(r, nil); } static void astat(Req* r) { Qid q; q = r->fid->qid; if (q.path < 0 || q.path >= nnames && q.path != Qroot) respond(r, "bug: bad qid"); r->d.qid = q; if (q.path == Qroot) r->d.name = estrdup9p("/"); else r->d.name = estrdup9p(names[q.path]); r->d.uid = estrdup9p("sys"); r->d.gid = estrdup9p("sys"); r->d.length= 0; r->d.mode= 0555|DMDIR; respond(r, nil); } static void awstat(Req* r) { respond(r, "wstat not allowed"); } static char* awalk1(Fid* fid, char *name, Qid *qid) { int i; if (fid->qid.path != Qroot) return "no such name"; for (i = 0; i < nnames; i++) if (strcmp(name, names[i]) == 0) break; if (i == nnames){ if ((nnames % 100) == 0) names = realloc(names, (nnames+100)*sizeof(char*)); names[nnames++] = strdup(name); } qid->path = i; qid->type = QTDIR; qid->vers = 0; fid->qid = *qid; return nil; } void main(int argc, char* argv[]) { char* mnt; ARGBEGIN{ default: usage(); }ARGEND; if (argc > 1) usage(); if (argc == 0) mnt = "/n"; else mnt = *argv; postmountsrv(&asrv, nil, mnt, MREPL); exits(nil); } --upas-xkhgrtcaofjdqwjgvuvukobvbj--