9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] autofs
@ 2002-07-16  8:58 Fco.J.Ballesteros
  0 siblings, 0 replies; 3+ messages in thread
From: Fco.J.Ballesteros @ 2002-07-16  8:58 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 61 bytes --]

I loved the idea so much, that I couldn't wait.

Enjoy.


[-- Attachment #2: autofs --]
[-- Type: text/plain, Size: 433 bytes --]

.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

[-- Attachment #3: autofs.c --]
[-- Type: text/plain, Size: 2774 bytes --]

#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#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);	
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] autofs
@ 2002-07-16 12:23 rog
  2002-07-16 11:42 ` Sam
  0 siblings, 1 reply; 3+ messages in thread
From: rog @ 2002-07-16 12:23 UTC (permalink / raw)
  To: 9fans

it's better, i think, if the directories are refcounted and disappear
when not referenced, otherwise the directory tends to fill up with
garbage.
(e.g. try:
	autofs
	cd /n
	sdfvgsdf
	ls -l
)

that was the most tricky thing about the original implementation
(remember to account for walk to "..")

i *think* i preferred autodir as a name (after all, it only
automatically creates directories, not files) but that's just a matter
of taste.  maybe "autodirfs"...?

the other thing is perhaps it should by default bind itself *after*
the usual contents of /n.  this means it doesn't obscure any currently
mounted stuff; also, there's a potential performance hit from using it
(an additional interaction with a user-level program when walking to
directories through /n), so perhaps one should continue to allow the
old statically created /n directories too where that might be an
issue.

  cheers,
    rog.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] autofs
  2002-07-16 12:23 rog
@ 2002-07-16 11:42 ` Sam
  0 siblings, 0 replies; 3+ messages in thread
From: Sam @ 2002-07-16 11:42 UTC (permalink / raw)
  To: 9fans

> i *think* i preferred autodir as a name (after all, it only
> automatically creates directories, not files) but that's just a matter
> of taste.  maybe "autodirfs"...?

Personally, I prefer automountsrv-devtodirfs.

...

'Second the notion for autodir.

Sam




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-07-16 12:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-16  8:58 [9fans] autofs Fco.J.Ballesteros
2002-07-16 12:23 rog
2002-07-16 11:42 ` Sam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).