FBSD, DFBSD (future) vnode_pager_setsize updates
[openafs.git] / src / afs / FBSD / osi_misc.c
index 00d91cf..6c2876d 100644 (file)
 /* 
  * osi_misc.c
  *
- * Implements:
- * afs_suser
  */
 
-#include "../afs/param.h"      /* Should be always first */
-#include "../afs/sysincludes.h"        /* Standard vendor system headers */
-#include "../afs/afsincludes.h"        /* Afs-based standard headers */
+#include <afsconfig.h>
+#include "afs/param.h"
+
+
+#include "afs/sysincludes.h"   /* Standard vendor system headers */
+#include "afsincludes.h"       /* Afs-based standard headers */
+#include <sys/namei.h>
+
+int
+osi_lookupname(char *aname, enum uio_seg seg, int followlink,
+              struct vnode **vpp)
+{
+    struct nameidata n;
+    int flags, error, glocked;
+
+    glocked = ISAFS_GLOCK();
+    if (glocked)
+       AFS_GUNLOCK();
+
+    flags = 0;
+    flags = LOCKLEAF;
+    if (followlink)
+       flags |= FOLLOW;
+    else
+       flags |= NOFOLLOW;
+#ifdef AFS_FBSD80_ENV
+    flags |= MPSAFE; /* namei must take GIANT if needed */
+#endif
+    NDINIT(&n, LOOKUP, flags, seg, aname, curthread);
+    if ((error = namei(&n)) != 0) {
+       if (glocked)
+           AFS_GLOCK();
+       return error;
+    }
+    *vpp = n.ni_vp;
+    /* XXX should we do this?  Usually NOT (matt) */
+#if defined(AFS_FBSD80_ENV)
+    /*VOP_UNLOCK(n.ni_vp, 0);*/
+#else
+    VOP_UNLOCK(n.ni_vp, 0, curthread);
+#endif
+    NDFREE(&n, NDF_ONLY_PNBUF);
+    if (glocked)
+       AFS_GLOCK();
+    return 0;
+}
 
 /*
- * afs_suser() returns true if the caller is superuser, false otherwise.
- *
- * Note that it must NOT set errno.
+ * does not implement security features of kern_time.c:settime()
  */
+void
+afs_osi_SetTime(osi_timeval_t * atv)
+{
+    printf("afs attempted to set clock; use \"afsd -nosettime\"\n");
+}
 
-afs_suser() {
-    int error;
+/*
+ * Replace all of the bogus special-purpose memory allocators...
+ */
+void *
+osi_fbsd_alloc(size_t size, int dropglobal)
+{
+       void *rv;
+       int glocked;
 
-    if (suser(curproc) == 0) {
-       return(1);
-    }
-    return(0);
+       if (dropglobal) {
+           glocked = ISAFS_GLOCK();
+           if (glocked)
+               AFS_GUNLOCK();
+           rv = malloc(size, M_AFS, M_WAITOK);
+           if (glocked)
+               AFS_GLOCK();
+       } else
+           rv = malloc(size, M_AFS, M_NOWAIT);
+
+       return (rv);
+}
+
+void
+osi_fbsd_free(void *p)
+{
+       free(p, M_AFS);
 }