📄 afs.c
字号:
/* $Id: afs.C,v 1.2 2001/04/10 06:08:56 dm Exp $ *//* * * Copyright (C) 2001 David Mazieres (dm@uun.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * */#include "cryptfs.h"class aiddir : public afsdir { sfs_aid aid;public: aiddir (afsdir *parent, sfs_aid a) : afsdir (parent), aid (a) {} void mkfattr3 (fattr3 *f, sfs_aid a); void nfs3_access (svccb *);};ref<afsroot> rootdir = afsroot::alloc ();ref<afsdir> uiddir = rootdir->mkdir (UDNAME);voidaiddir::mkfattr3 (fattr3 *f, sfs_aid a){ afsdir::mkfattr3 (f, a); f->uid = a; f->mode = 0500;}voidaiddir::nfs3_access (svccb *sbp){ if (sbp2aid (sbp) != aid && (!sbp->getaup () || sbp->getaup ()->aup_uid)) { access3res res (NFS3_OK); mkpoattr (res.resok->obj_attributes, sbp2aid (sbp)); res.resok->access = 0; sbp->reply (&res); } else afsdir::nfs3_access (sbp);}voidafsroot::mkfattr3 (fattr3 *f, sfs_aid aid){ /* BSD needs the seconds (not just milliseconds/nanoseconds) of the * mtime to change on every lookup/getattr in order to defeat the * name cache. */ if (aid != lastaid) { lastaid = aid; bumpmtime (); } afsdir::mkfattr3 (f, aid);}afsnode *afsroot::lookup (const str &name, sfs_aid aid){ if (afsnode *e = afsdir::lookup (name, aid)) return e; else if (ptr<afsdir> ud = utab[aid]) return ud->lookup (name, aid); return NULL;}voidafsroot::nfs_remove (svccb *sbp){ sfs_aid aid = sbp2aid (sbp); str name = sbp->vers () == 2 ? str (sbp->template getarg<diropargs> ()->name) : str (sbp->template getarg<diropargs3> ()->name); if (!lookup (name, aid)) nfs_error (sbp, NFSERR_NOENT); else if (name[0] == '.') nfs_error (sbp, NFSERR_ACCES); else if (!detach (aid, name)) nfs_error (sbp, EBUSY); else if (sbp->vers () == 2) sbp->replyref (NFS_OK); else sbp->replyref (wccstat3 (NFS3_OK));}boolafsroot::entryok (afsdirentry *de, sfs_aid aid){ return de->dir == this || (de->dir && de->dir == utab[aid]);}afsdirentry *afsroot::firstentry (sfs_aid aid){ if (afsdirentry *de = afsdir::firstentry (aid)) return de; if (ptr<afsdir> ud = utab[aid]) return ud->firstentry (aid); return NULL;}afsdirentry *afsroot::nextentry (afsdirentry *de, sfs_aid aid){ if (de->dir != this) return de->dir->nextentry (de, aid); if ((de = afsdir::nextentry (de, aid))) return de; if (ptr<afsdir> ud = utab[aid]) return ud->firstentry (aid); return NULL;}ptr<afslink>afsroot::aidlink (sfs_aid aid, const str &contents, const str &name){ ptr<afsdir> ud = utab[aid]; if (!ud) utab.insert (aid, (ud = afsdir::alloc ())); bumpmtime (); // XXX - unnecessary if failure, but who cares? return ud->symlink (contents, name);}boolafsroot::aidunlink (sfs_aid aid, const str &name){ ptr<afsdir> ud = utab[aid]; if (ud && ud->unlink (name)) { if (!ud->firstentry (aid)) utab.remove (aid); bumpmtime (); return true; } return false;}booluid_mkdir (sfs_aid aid, str name){ str aidstr (strbuf () << aid); ptr<aiddir> ud; if (afsnode *d = uiddir->lookup (aidstr, aid)) { assert (d->type == NF3DIR); ud = mkref (static_cast<aiddir *> (d)); } else{ ud = New refcounted<aiddir> (uiddir, aid); uiddir->link (ud, aidstr); } if (!ud->mkdir (name)) return false; rootdir->aidlink (aid, strbuf (UDNAME "/") << aidstr << "/" << name, name); return true;}voiduid_rmdir (sfs_aid aid, str name){ str aidstr (strbuf () << aid); ptr<aiddir> ud; if (afsnode *d = uiddir->lookup (aidstr, aid)) { assert (d->type == NF3DIR); ud = mkref (static_cast<aiddir *> (d)); } if (ud) { ud->unlink (name); if (!ud->firstentry (aid)) uiddir->unlink (aidstr); } rootdir->aidunlink (aid, name);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -