macos: make the OpenAFS client aware of APFS
[openafs.git] / src / afs / DARWIN / osi_file.c
index b15ceb7..19bfdf9 100644 (file)
@@ -53,6 +53,10 @@ afs_InitDualFSCacheOps(struct vnode *vp)
     else if (strncmp("ufs", vp->v_mount->mnt_vfc->vfc_name, 3) == 0)
 #endif
        afs_CacheFSType = AFS_APPL_UFS_CACHE;
+#ifdef AFS_DARWIN80_ENV
+    else if (strncmp("apfs", buffer, 4) == 0)
+       afs_CacheFSType = AFS_APPL_APFS_CACHE;
+#endif
     else
        osi_Panic("Unknown cache vnode type\n");
 #ifdef AFS_DARWIN80_ENV
@@ -130,12 +134,12 @@ VnodeToDev(vnode_t avp)
 #endif
 }
 
-struct osi_file *
+void *
 osi_UFSOpen(afs_dcache_id_t *ainode)
 {
     struct vnode *vp;
     struct vattr va;
-    register struct osi_file *afile = NULL;
+    struct osi_file *afile = NULL;
     extern int cacheDiskType;
     afs_int32 code = 0;
     int dummy;
@@ -150,32 +154,19 @@ osi_UFSOpen(afs_dcache_id_t *ainode)
        /* valid for alpha_osf, SunOS, Ultrix */
        memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
        afs_osi_cred.cr_ref++;
+#ifndef AFS_DARWIN110_ENV
        afs_osi_cred.cr_ngroups = 1;
+#endif
        afs_osicred_initialized = 1;
     }
-    afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
+    afile = osi_AllocSmallSpace(sizeof(struct osi_file));
     AFS_GUNLOCK();
 #ifdef AFS_CACHE_VNODE_PATH
-    if (ainode->ufs < 0) {
-       switch (ainode->ufs) {
-       case AFS_CACHE_CELLS_INODE:
-           snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CellItems");
-           break;
-       case AFS_CACHE_ITEMS_INODE:
-           snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CacheItems");
-           break;
-       case AFS_CACHE_VOLUME_INODE:
-           snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "VolumeItems");
-           break;
-       default:
-           osi_Panic("Invalid negative inode");
-       }
-    } else {
-       dummy = ainode->ufs / afs_numfilesperdir;
-       snprintf(fname, 1024, "%s/D%d/V%d", afs_cachebasedir, dummy, ainode->ufs);
+    if (!ainode->ufs) {
+       osi_Panic("No cache inode\n");
     }
 
-    code = vnode_open(fname, O_RDWR, 0, 0, &vp, afs_osi_ctxtp);
+    code = vnode_open(ainode->ufs, O_RDWR, 0, 0, &vp, afs_osi_ctxtp);
 #else
 #ifndef AFS_DARWIN80_ENV
     if (afs_CacheFSType == AFS_APPL_HFS_CACHE)
@@ -204,13 +195,13 @@ osi_UFSOpen(afs_dcache_id_t *ainode)
     code = afs_osi_Stat(afile, &tstat);
     afile->size = tstat.size;
 #endif
-    return afile;
+    return (void *)afile;
 }
 
 int
-afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
+afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct vattr tvattr;
     AFS_STATCNT(osi_Stat);
     ObtainWriteLock(&afs_xosi, 320);
@@ -238,7 +229,7 @@ afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
 }
 
 int
-osi_UFSClose(register struct osi_file *afile)
+osi_UFSClose(struct osi_file *afile)
 {
     AFS_STATCNT(osi_Close);
     if (afile->vnode) {
@@ -254,11 +245,11 @@ osi_UFSClose(register struct osi_file *afile)
 }
 
 int
-osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
+osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
 {
     afs_ucred_t *oldCred;
     struct vattr tvattr;
-    register afs_int32 code;
+    afs_int32 code;
     struct osi_stat tstat;
     AFS_STATCNT(osi_Truncate);
 
@@ -315,12 +306,12 @@ osi_DisableAtimes(struct vnode *avp)
 
 /* Generic read interface */
 int
-afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
+afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
             afs_int32 asize)
 {
     afs_ucred_t *oldCred;
     afs_size_t resid;
-    register afs_int32 code;
+    afs_int32 code;
 #ifdef AFS_DARWIN80_ENV
     uio_t uio;
 #endif
@@ -331,10 +322,10 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
       * down. No point in crashing when we are already shutting down
       */
     if (!afile) {
-       if (!afs_shuttingdown)
+       if (afs_shuttingdown == AFS_RUNNING)
            osi_Panic("osi_Read called with null param");
        else
-           return EIO;
+           return -EIO;
     }
 
     if (offset != -1)
@@ -359,19 +350,21 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
     } else {
        afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
                   ICL_TYPE_INT32, code);
-       code = -1;
+       if (code > 0) {
+           code = -code;
+       }
     }
     return code;
 }
 
 /* Generic write interface */
 int
-afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
+afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
              afs_int32 asize)
 {
     afs_ucred_t *oldCred;
     afs_size_t resid;
-    register afs_int32 code;
+    afs_int32 code;
 #ifdef AFS_DARWIN80_ENV
     uio_t uio;
 #endif
@@ -400,7 +393,9 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
        code = asize - resid;
        afile->offset += code;
     } else {
-       code = -1;
+       if (code > 0) {
+           code = -code;
+       }
     }
     if (afile->proc) {
        (*afile->proc) (afile, code);