📄 nfs.h
字号:
// -*-c++-*-/* $Id: nfs.h,v 1.1 2001/10/12 21:27:28 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 * */#ifdef CLASSFS# include "classfscli.h"#endif /* CLASSFS */#include "nfsserv.h"#include "crypt.h"#include "aes.h"#include "nfs3_prot.h"#include "afsnode.h"#include "qhash.h"#include "nfstrans.h"#undef CFSASYNC/* * nfs.C */const u_int blocksize = 16;const u_int64_t blockmask = blocksize-1;class cryptfs : public virtual refcount { enum { datashift = 512 }; class fhiv { cryptfs *const cfs; static u_int64_t attr2iv (const fattr3exp *f); void init (); void fetchcb (ref<cryptfs> hold, ref<read3res> resp, clnt_stat); void createcb (ref<cryptfs> hold, ref<write3res> resp, clnt_stat); void wake (); public: static u_int nfhiv; const nfs_fh3 fh; u_int64_t iv; bool valid; bool stable; bool err; ihash_entry<fhiv> hlink; tailq_entry<fhiv> lrulink; fhiv (cryptfs *cfs, const nfs_fh3 &fh, bool isdir); fhiv (cryptfs *cfs, const nfs_fh3 &fh, const fattr3exp *f); ~fhiv (); void touch (); }; friend struct fhiv; static AUTH *ao; static tailq<fhiv, &fhiv::lrulink> ivlruq; aes fskey;#ifndef CLASSFS typedef ref<aclnt> clnt_t;#else /* CLASSFS */ typedef ref<sfsuclnt> clnt_t;#endif /* CLASSFS */ clnt_t nfsc; ptr<nfsserv> nfss; int fsfd; // Keep open so automounter doesn't unmount it ihash<const nfs_fh3, fhiv, &cryptfs::fhiv::fh, &cryptfs::fhiv::hlink> ivtab; qhash<nfs_fh3, vec<cbv> > ivwait;#ifdef CFSASYNC writeverf3 verf;#endif /* CFSASYNC */ void call (u_int32_t proc, const void *arg, void *res, aclnt_cb cb, AUTH *a) {#ifndef CLASSFS nfsc->call (proc, arg, res, cb, a);#else /* CLASSFS */ // XXX - const_cast for old classfs, should be removed nfsc->call (proc, const_cast<void *> (arg), res, cb);#endif /* CLASSFS */ } void encrypt (u_int64_t offset, u_int64_t iv, char *out, const char *in); void decrypt (u_int64_t offset, u_int64_t iv, char *out, const char *in); str encodename (u_int64_t diriv, str name); str decodename (u_int64_t diriv, str name); int getiv (nfs_fh3 &fh, bool stable, const authunix_parms *aup, cbv::ptr cb = NULL, u_int64_t *ivp = NULL); void fixdirop (diropargs3 *doa) { doa->name = encodename (0, doa->name); } u_int64_t fixsize (ftype3 type, u_int64_t size); template<class T> u_int64_t fixentries (rpc_ptr<T> &head); template<int N> bool fixreaddir (nfscall *nc); void fillpoa (nfscall *nc, const nfs_fh3 *fhp, post_op_attr *poa, aclnt_cb cb); void fillpoa_1 (nfscall *nc, post_op_attr *poa, ref<getattr3res> ares, aclnt_cb cb, clnt_stat); void reply (nfscall *nc, clnt_stat stat); void reply_create (nfscall *nc, ptr<lookup3res> lres, ptr<getattr3res> ares, clnt_stat stat); void reply_read (nfscall *nc, clnt_stat stat); void reply_write (nfscall *nc, u_int64_t end, clnt_stat stat); void reply_write_read (nfscall *nc, ptr<read3res> rres, clnt_stat stat); void nfsdispatch (nfscall *sbp);protected: cryptfs (sfs_aid aid, ref<nfsserv> nfss, clnt_t nfsc, str pwd, int fsfd); ~cryptfs () { close (fsfd); ivtab.deleteall (); }public: void kill () { nfss = NULL; } const sfs_aid aid;};inline u_int64_tcryptfs::fixsize (ftype3 type, u_int64_t size){ switch (type) { case NF3REG: size -= datashift; if (size & blockmask) size -= blocksize; break; case NF3LNK: size = size * 3 / 4 - 6; break; default: break; } if (implicit_cast<int64_t> (size) < 0) size = 0; return size;}template<class T> inline u_int64_tcryptfs::fixentries (rpc_ptr<T> &head){ u_int64_t lastcookie = 0; rpc_ptr<T> *ep = &head; while (T *e = *ep) { lastcookie = e->cookie; if (str name = decodename (0, e->name)) { e->name = name; ep = &e->nextentry; } else ep->assign (e->nextentry.release ()); } return head ? 0 : lastcookie;}template<int N> boolcryptfs::fixreaddir (nfscall *nc){ typename nfs3proc<N>::arg_type *arg = static_cast<typename nfs3proc<N>::arg_type *> (nc->getvoidarg ()); typename nfs3proc<N>::res_type *res = static_cast<typename nfs3proc<N>::res_type *> (nc->getvoidres ()); arg->cookie = fixentries (res->resok->reply.entries); if (res->resok->reply.eof || !arg->cookie) return true; authopaque_set (ao, nc->getaup ()); call (nc->proc (), nc->getvoidarg (), nc->getvoidres (), wrap (this, &cryptfs::reply, nc), ao); return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -