vol: remove SYNC fatal_error processing
[openafs.git] / src / vol / partition.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  *
9  * Portions Copyright (c) 2003 Apple Computer, Inc.
10  * Portions Copyright (c) 2006 Sine Nomine Associates
11  */
12
13 /*
14
15         System:         VICE-TWO
16         Module:         partition.c
17         Institution:    The Information Technology Center, Carnegie-Mellon University
18
19  */
20
21 #include <afsconfig.h>
22 #include <afs/param.h>
23
24 #include <roken.h>
25
26 #include <ctype.h>
27
28 #ifdef AFS_NT40_ENV
29 #include <windows.h>
30 #include <winbase.h>
31 #include <winioctl.h>
32 #else
33
34 #if AFS_HAVE_STATVFS || AFS_HAVE_STATVFS64
35 #include <sys/statvfs.h>
36 #endif /* AFS_HAVE_STATVFS */
37 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
38 #include <sys/mount.h>
39 #endif
40
41 #if !defined(AFS_SGI_ENV)
42 #ifdef  AFS_OSF_ENV
43 #include <sys/mount.h>
44 #include <ufs/fs.h>
45 #else /* AFS_OSF_ENV */
46 #ifdef AFS_VFSINCL_ENV
47 #define VFS
48 #ifdef  AFS_SUN5_ENV
49 #include <sys/fs/ufs_fs.h>
50 #else
51 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
52 #include <ufs/ufs/dinode.h>
53 #include <ufs/ffs/fs.h>
54 #else
55 #include <ufs/fs.h>
56 #endif
57 #endif
58 #else /* AFS_VFSINCL_ENV */
59 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
60 #include <sys/fs.h>
61 #endif
62 #endif /* AFS_VFSINCL_ENV */
63 #endif /* AFS_OSF_ENV */
64 #include <sys/file.h>
65 #ifdef  AFS_AIX_ENV
66 #include <sys/vfs.h>
67 #include <sys/lockf.h>
68 #else
69 #ifdef  AFS_HPUX_ENV
70 #include <sys/vfs.h>
71 #include <checklist.h>
72 #else
73 #if     defined(AFS_SUN_ENV)
74 #include <sys/vfs.h>
75 #ifndef AFS_SUN5_ENV
76 #include <mntent.h>
77 #endif
78 #endif
79 #ifdef AFS_SUN5_ENV
80 #include <unistd.h>
81 #include <sys/mnttab.h>
82 #include <sys/mntent.h>
83 #else
84 #ifdef AFS_LINUX22_ENV
85 #include <mntent.h>
86 #include <sys/statfs.h>
87 #else
88 #include <fstab.h>
89 #endif
90 #endif
91 #endif
92 #endif
93 #endif /* AFS_SGI_ENV */
94 #endif /* AFS_NT40_ENV */
95 #if defined(AFS_SGI_ENV)
96 #include <sys/file.h>
97 #include <mntent.h>
98 #endif
99
100 #include <rx/xdr.h>
101 #include <afs/afsint.h>
102 #include "nfs.h"
103 #include <afs/errors.h>
104 #include "lock.h"
105 #include "lwp.h"
106 #include <afs/afssyscalls.h>
107 #include "ihandle.h"
108 #include "common.h"
109 #ifdef AFS_NAMEI_ENV
110 #ifdef AFS_NT40_ENV
111 #include "ntops.h"
112 #else
113 #include "namei_ops.h"
114 #include <dirent.h>
115 #endif /* AFS_NT40_ENV */
116 #endif /* AFS_NAMEI_ENV */
117 #include "vnode.h"
118 #include "volume.h"
119 #include "partition.h"
120
121 #if defined(AFS_HPUX_ENV)
122 #include <sys/types.h>
123 #include <sys/privgrp.h>
124 #endif /* defined(AFS_HPUX_ENV) */
125
126 #ifdef AFS_AIX42_ENV
127 #include <jfs/filsys.h>
128 #endif
129
130 int aixlow_water = 8;           /* default 8% */
131 struct DiskPartition64 *DiskPartitionList;
132
133 #ifdef AFS_DEMAND_ATTACH_FS
134 /* file to lock to conceptually "lock" the vol headers on a partition */
135 #define AFS_PARTLOCK_FILE ".volheaders.lock"
136 #define AFS_VOLUMELOCK_FILE ".volume.lock"
137
138 static struct DiskPartition64 *DiskPartitionTable[VOLMAXPARTS+1];
139
140 static struct DiskPartition64 * VLookupPartition_r(char * path);
141 static void AddPartitionToTable_r(struct DiskPartition64 *);
142 #endif /* AFS_DEMAND_ATTACH_FS */
143
144 #ifdef AFS_SGI_XFS_IOPS_ENV
145 /* Verify that the on disk XFS inodes on the partition are large enough to
146  * hold the AFS attribute. Returns -1 if the attribute can't be set or is
147  * too small to fit in the inode. Returns 0 if the attribute does fit in
148  * the XFS inode.
149  */
150 #include <afs/xfsattrs.h>
151 static int
152 VerifyXFSInodeSize(char *part, char *fstype)
153 {
154     afs_xfs_attr_t junk;
155     int length = SIZEOF_XFS_ATTR_T;
156     int fd = 0;
157     int code = -1;
158     struct fsxattr fsx;
159
160     if (strcmp("xfs", fstype))
161         return 0;
162
163     if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT) == 0) {
164         if (((fd = open(part, O_RDONLY, 0)) != -1)
165             && (fcntl(fd, F_FSGETXATTRA, &fsx) == 0)) {
166
167             if (fsx.fsx_nextents) {
168                 Log("Partition %s: XFS inodes too small, exiting.\n", part);
169                 Log("Run xfs_size_check utility and remake partitions.\n");
170             } else
171                 code = 0;
172         }
173
174         if (fd > 0)
175             close(fd);
176         (void)attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT);
177     }
178     return code;
179 }
180 #endif /* AFS_SGI_XFS_IOPS_ENV */
181
182 int
183 VInitPartitionPackage(void)
184 {
185 #ifdef AFS_DEMAND_ATTACH_FS
186     memset(&DiskPartitionTable, 0, sizeof(DiskPartitionTable));
187 #endif /* AFS_DEMAND_ATTACH_FS */
188     return 0;
189 }
190
191 static void
192 VInitPartition_r(char *path, char *devname, Device dev)
193 {
194     struct DiskPartition64 *dp, *op;
195
196     dp = (struct DiskPartition64 *)malloc(sizeof(struct DiskPartition64));
197     /* Add it to the end, to preserve order when we print statistics */
198     for (op = DiskPartitionList; op; op = op->next) {
199         if (!op->next)
200             break;
201     }
202     if (op)
203         op->next = dp;
204     else
205         DiskPartitionList = dp;
206     dp->next = 0;
207     dp->name = (char *)malloc(strlen(path) + 1);
208     strncpy(dp->name, path, strlen(path) + 1);
209     dp->index = volutil_GetPartitionID(path);
210 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
211     /* Create a lockfile for the partition, of the form /vicepa/Lock/vicepa */
212     dp->devName = (char *)malloc(2 * strlen(path) + 6);
213     strcpy(dp->devName, path);
214     strcat(dp->devName, OS_DIRSEP);
215     strcat(dp->devName, "Lock");
216     mkdir(dp->devName, 0700);
217     strcat(dp->devName, path);
218     close(afs_open(dp->devName, O_RDWR | O_CREAT, 0600));
219     dp->device = dp->index;
220 #else
221     dp->devName = (char *)malloc(strlen(devname) + 1);
222     strncpy(dp->devName, devname, strlen(devname) + 1);
223     dp->device = dev;
224 #endif
225     dp->lock_fd = INVALID_FD;
226     dp->flags = 0;
227     dp->f_files = 1;            /* just a default value */
228 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
229     if (programType == fileServer)
230         (void)namei_ViceREADME(VPartitionPath(dp));
231 #endif
232     VSetPartitionDiskUsage_r(dp);
233 #ifdef AFS_DEMAND_ATTACH_FS
234     AddPartitionToTable_r(dp);
235     queue_Init(&dp->vol_list.head);
236     CV_INIT(&dp->vol_list.cv, "vol list", CV_DEFAULT, 0);
237     dp->vol_list.len = 0;
238     dp->vol_list.busy = 0;
239     {
240         char lockpath[MAXPATHLEN+1];
241         snprintf(lockpath, MAXPATHLEN, "%s/" AFS_PARTLOCK_FILE, dp->name);
242         lockpath[MAXPATHLEN] = '\0';
243         VLockFileInit(&dp->headerLockFile, lockpath);
244
245         snprintf(lockpath, MAXPATHLEN, "%s/" AFS_VOLUMELOCK_FILE, dp->name);
246         lockpath[MAXPATHLEN] = '\0';
247         VLockFileInit(&dp->volLockFile, lockpath);
248     }
249     VDiskLockInit(&dp->headerLock, &dp->headerLockFile, 1);
250 #endif /* AFS_DEMAND_ATTACH_FS */
251 }
252
253 static void
254 VInitPartition(char *path, char *devname, Device dev)
255 {
256     VOL_LOCK;
257     VInitPartition_r(path, devname, dev);
258     VOL_UNLOCK;
259 }
260
261 #ifndef AFS_NT40_ENV
262 /* VAttachPartitions() finds the vice partitions on this server. Calls
263  * VCheckPartition() to do some basic checks on the partition. If the partition
264  * is a valid vice partition, VCheckPartition will add it to the DiskPartition
265  * list.
266  * Returns the number of errors returned by VCheckPartition. An error in
267  * VCheckPartition means that partition is a valid vice partition but the
268  * fileserver should not start because of the error found on that partition.
269  *
270  * AFS_NAMEI_ENV
271  * No specific user space file system checks, since we don't know what
272  * is being used for vice partitions.
273  *
274  * Use partition name as devname.
275  */
276 int
277 VCheckPartition(char *part, char *devname, int logging)
278 {
279     struct afs_stat_st status;
280 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV)
281     char AFSIDatPath[MAXPATHLEN];
282 #endif
283
284     /* Only keep track of "/vicepx" partitions since it can get hairy
285      * when NFS mounts are involved.. */
286     if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
287         return 0;
288     }
289     if (afs_stat(part, &status) < 0) {
290         Log("VInitVnodes: Couldn't find file system %s; ignored\n", part);
291         return 0;
292     }
293     if (logging) {
294         Log("This program is compiled without AFS_NAMEI_ENV, and "
295             "partition %s is mounted with the 'logging' option. "
296             "Using the inode fileserver backend with 'logging' UFS "
297             "partitions causes volume corruption, so please either "
298             "mount the partition without logging, or use the namei "
299             "fileserver backend. Aborting...\n", part);
300         return -1;
301     }
302 #ifndef AFS_AIX32_ENV
303     if (programType == fileServer) {
304         char salvpath[MAXPATHLEN];
305         strcpy(salvpath, part);
306         strcat(salvpath, "/FORCESALVAGE");
307         if (afs_stat(salvpath, &status) == 0) {
308             Log("VInitVnodes: Found %s; aborting\n", salvpath);
309             return -1;
310         }
311     }
312 #endif
313
314 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV)
315     strcpy(AFSIDatPath, part);
316     strcat(AFSIDatPath, "/AFSIDat");
317 #ifdef AFS_NAMEI_ENV
318     if (afs_stat(AFSIDatPath, &status) < 0) {
319         DIR *dirp;
320         struct dirent *dp;
321
322         dirp = opendir(part);
323         osi_Assert(dirp);
324         while ((dp = readdir(dirp))) {
325             if (dp->d_name[0] == 'V') {
326                 Log("This program is compiled with AFS_NAMEI_ENV, but partition %s seems to contain volumes which don't use the namei-interface; aborting\n", part);
327                 closedir(dirp);
328                 return -1;
329             }
330         }
331         closedir(dirp);
332     }
333 #else /* AFS_NAMEI_ENV */
334     if (afs_stat(AFSIDatPath, &status) == 0) {
335         Log("This program is compiled without AFS_NAMEI_ENV, but partition %s seems to contain volumes which use the namei-interface; aborting\n", part);
336         return -1;
337     }
338
339 #ifdef AFS_SGI_XFS_IOPS_ENV
340     if (VerifyXFSInodeSize(part, status.st_fstype) < 0)
341         return -1;
342 #endif
343 #endif /* AFS_NAMEI_ENV */
344 #endif /* !AFS_LINUX20_ENV && !AFS_NT40_ENV */
345
346 #if defined(AFS_DUX40_ENV) && !defined(AFS_NAMEI_ENV)
347     if (status.st_ino != ROOTINO) {
348         Log("%s is not a mounted file system; ignored.\n", part);
349         return 0;
350     }
351 #endif
352
353     VInitPartition(part, devname, status.st_dev);
354
355     return 0;
356 }
357
358 /* VIsAlwaysAttach() checks whether a /vicepX directory should always be
359  * attached (return value 1), or only attached when it is a separately
360  * mounted partition (return value 0).  For non-NAMEI environments, it
361  * always returns 0.
362  *
363  * *awouldattach will be set to 1 if the given path at least looks like a vice
364  * partition (that is, if we return 0, the only thing preventing this partition
365  * from being attached is the existence of the AlwaysAttach file), or to 0
366  * otherwise. *awouldattach is set regardless of whether or not the partition
367  * should always be attached or not.
368  */
369 static int
370 VIsAlwaysAttach(char *part, int *awouldattach)
371 {
372 #ifdef AFS_NAMEI_ENV
373     struct afs_stat_st st;
374     char checkfile[256];
375     int ret;
376 #endif /* AFS_NAMEI_ENV */
377
378     if (awouldattach) {
379         *awouldattach = 0;
380     }
381
382 #ifdef AFS_NAMEI_ENV
383     if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
384         return 0;
385
386     if (awouldattach) {
387         *awouldattach = 1;
388     }
389
390     strncpy(checkfile, part, 100);
391     strcat(checkfile, OS_DIRSEP);
392     strcat(checkfile, VICE_ALWAYSATTACH_FILE);
393
394     ret = afs_stat(checkfile, &st);
395     return (ret < 0) ? 0 : 1;
396 #else /* AFS_NAMEI_ENV */
397     return 0;
398 #endif /* AFS_NAMEI_ENV */
399 }
400
401 /* VAttachPartitions2() looks for and attaches /vicepX partitions
402  * where a special file (VICE_ALWAYSATTACH_FILE) exists.  This is
403  * used to attach /vicepX directories which aren't on dedicated
404  * partitions, in the NAMEI fileserver.
405  */
406 void
407 VAttachPartitions2(void)
408 {
409 #ifdef AFS_NAMEI_ENV
410     DIR *dirp;
411     struct dirent *de;
412     char pname[32];
413     int wouldattach;
414
415     dirp = opendir(OS_DIRSEP);
416     while ((de = readdir(dirp))) {
417         strcpy(pname, OS_DIRSEP);
418         strncat(pname, de->d_name, 20);
419         pname[sizeof(pname) - 1] = '\0';
420
421         /* Only keep track of "/vicepx" partitions since automounter
422          * may hose us */
423         if (VIsAlwaysAttach(pname, &wouldattach)) {
424             VCheckPartition(pname, "", 0);
425         } else {
426             struct afs_stat_st st;
427             if (wouldattach && VGetPartition(pname, 0) == NULL &&
428                 afs_stat(pname, &st) == 0 && S_ISDIR(st.st_mode)) {
429
430                 /* This is a /vicep* dir, and it has not been attached as a
431                  * partition. This probably means that this is a /vicep* dir
432                  * that is not a separate partition, so just give a notice so
433                  * admins are not confused as to why their /vicep* dirs are not
434                  * being attached.
435                  *
436                  * It is possible that the dir _is_ a separate partition and we
437                  * failed to attach it earlier, making this message a bit
438                  * confusing. But that should be rare, and an error message
439                  * about the failure will already be logged right before this,
440                  * so it should be clear enough. */
441
442                 Log("VAttachPartitions: not attaching %s; either it is not a "
443                     "separate partition, or it failed to attach (create the "
444                     "file %s/" VICE_ALWAYSATTACH_FILE " to force attachment)\n",
445                     pname, pname);
446             }
447         }
448     }
449     closedir(dirp);
450 #endif /* AFS_NAMEI_ENV */
451 }
452 #endif /* AFS_NT40_ENV */
453
454 #ifdef AFS_SUN5_ENV
455 int
456 VAttachPartitions(void)
457 {
458     int errors = 0;
459     struct mnttab mnt;
460     FILE *mntfile;
461
462     if (!(mntfile = afs_fopen(MNTTAB, "r"))) {
463         Log("Can't open %s\n", MNTTAB);
464         perror(MNTTAB);
465         exit(-1);
466     }
467     while (!getmntent(mntfile, &mnt)) {
468         int logging = 0;
469         /* Ignore non ufs or non read/write partitions */
470         /* but allow zfs too if we're in the NAMEI environment */
471         if (
472 #ifdef AFS_NAMEI_ENV
473             (((strcmp(mnt.mnt_fstype, "ufs") &&
474                 strcmp(mnt.mnt_fstype, "zfs"))))
475 #else
476             (strcmp(mnt.mnt_fstype, "ufs") != 0)
477 #endif
478             || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
479             continue;
480
481         /* If we're going to always attach this partition, do it later. */
482         if (VIsAlwaysAttach(mnt.mnt_mountp, NULL))
483             continue;
484
485 #ifndef AFS_NAMEI_ENV
486         if (hasmntopt(&mnt, "logging") != NULL) {
487             logging = 1;
488         }
489 #endif /* !AFS_NAMEI_ENV */
490
491         if (VCheckPartition(mnt.mnt_mountp, mnt.mnt_special, logging) < 0)
492             errors++;
493     }
494
495     (void)fclose(mntfile);
496
497     /* Process the always-attach partitions, if any. */
498     VAttachPartitions2();
499
500     return errors;
501 }
502
503 #endif /* AFS_SUN5_ENV */
504 #if defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_HPUX_ENV)
505 int
506 VAttachPartitions(void)
507 {
508     int errors = 0;
509     FILE *mfd;
510     struct mntent *mntent;
511
512     if ((mfd = setmntent(MOUNTED, "r")) == NULL) {
513         Log("Problems in getting mount entries(setmntent)\n");
514         exit(-1);
515     }
516     while (mntent = getmntent(mfd)) {
517         if (!hasmntopt(mntent, MNTOPT_RW))
518             continue;
519
520         /* If we're going to always attach this partition, do it later. */
521         if (VIsAlwaysAttach(mntent->mnt_dir, NULL))
522             continue;
523
524         if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname, 0) < 0)
525             errors++;
526     }
527
528     endmntent(mfd);
529
530     /* Process the always-attach partitions, if any. */
531     VAttachPartitions2();
532
533     return errors;
534 }
535 #endif
536 #ifdef AFS_AIX_ENV
537 /*
538  * (This function was grabbed from df.c)
539  */
540 int
541 getmount(struct vmount **vmountpp)
542 {
543     int size;
544     struct vmount *vm;
545     int nmounts;
546
547     /* set initial size of mntctl buffer to a MAGIC NUMBER */
548     size = BUFSIZ;
549
550     /* try the operation until ok or a fatal error */
551     while (1) {
552         if ((vm = (struct vmount *)malloc(size)) == NULL) {
553             /* failed getting memory for mount status buf */
554             perror("FATAL ERROR: get_stat malloc failed\n");
555             exit(-1);
556         }
557
558         /*
559          * perform the QUERY mntctl - if it returns > 0, that is the
560          * number of vmount structures in the buffer.  If it returns
561          * -1, an error occured.  If it returned 0, then look in
562          * first word of buffer for needed size.
563          */
564         if ((nmounts = mntctl(MCTL_QUERY, size, (caddr_t) vm)) > 0) {
565             /* OK, got it, now return */
566             *vmountpp = vm;
567             return (nmounts);
568
569         } else if (nmounts == 0) {
570             /* the buffer wasn't big enough .... */
571             /* .... get required buffer size */
572             size = *(int *)vm;
573             free(vm);
574
575         } else {
576             /* some other kind of error occurred */
577             free(vm);
578             return (-1);
579         }
580     }
581 }
582
583 int
584 VAttachPartitions(void)
585 {
586     int errors = 0;
587     int nmounts;
588     struct vmount *vmountp;
589
590     if ((nmounts = getmount(&vmountp)) <= 0) {
591         Log("Problems in getting # of mount entries(getmount)\n");
592         exit(-1);
593     }
594     for (; nmounts;
595          nmounts--, vmountp =
596          (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
597         char *part = vmt2dataptr(vmountp, VMT_STUB);
598
599         if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
600             continue;           /* Ignore any "special" partitions */
601
602 #ifdef AFS_AIX42_ENV
603 #ifndef AFS_NAMEI_ENV
604         {
605             struct superblock fs;
606             /* The Log statements are non-sequiters in the SalvageLog and don't
607              * even appear in the VolserLog, so restrict them to the FileLog.
608              */
609             if (ReadSuper(&fs, vmt2dataptr(vmountp, VMT_OBJECT)) < 0) {
610                 if (programType == fileServer)
611                     Log("Can't read superblock for %s, ignoring it.\n", part);
612                 continue;
613             }
614             if (IsBigFilesFileSystem(&fs)) {
615                 if (programType == fileServer)
616                     Log("%s is a big files filesystem, ignoring it.\n", part);
617                 continue;
618             }
619         }
620 #endif
621 #endif
622
623         /* If we're going to always attach this partition, do it later. */
624         if (VIsAlwaysAttach(part, NULL))
625             continue;
626
627         if (VCheckPartition(part, vmt2dataptr(vmountp, VMT_OBJECT), 0) < 0)
628             errors++;
629     }
630
631     /* Process the always-attach partitions, if any. */
632     VAttachPartitions2();
633
634     return errors;
635 }
636 #endif
637 #if defined(AFS_DUX40_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
638 int
639 VAttachPartitions(void)
640 {
641     int errors = 0;
642     struct fstab *fsent;
643
644     if (setfsent() < 0) {
645         Log("Error listing filesystems.\n");
646         exit(-1);
647     }
648
649     while ((fsent = getfsent())) {
650         if (strcmp(fsent->fs_type, "rw") != 0)
651             continue;
652
653         /* If we're going to always attach this partition, do it later. */
654         if (VIsAlwaysAttach(fsent->fs_file, NULL))
655             continue;
656
657         if (VCheckPartition(fsent->fs_file, fsent->fs_spec, 0) < 0)
658             errors++;
659     }
660     endfsent();
661
662     /* Process the always-attach partitions, if any. */
663     VAttachPartitions2();
664
665     return errors;
666 }
667 #endif
668
669 #ifdef AFS_NT40_ENV
670 #include <string.h>
671 #include <sys/stat.h>
672 /* VValidVPTEntry
673  *
674  * validate names in vptab.
675  *
676  * Return value:
677  * 1 valid entry
678  * 0 invalid entry
679  */
680
681 int
682 VValidVPTEntry(struct vptab *vpe)
683 {
684     int len = strlen(vpe->vp_name);
685     int i;
686
687     if (len < VICE_PREFIX_SIZE + 1 || len > VICE_PREFIX_SIZE + 2)
688         return 0;
689     if (strncmp(vpe->vp_name, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
690         return 0;
691
692     for (i = VICE_PREFIX_SIZE; i < len; i++) {
693         if (vpe->vp_name[i] < 'a' || vpe->vp_name[i] > 'z') {
694             Log("Invalid partition name %s in registry, ignoring it.\n",
695                 vpe->vp_name);
696             return 0;
697         }
698     }
699     if (len == VICE_PREFIX_SIZE + 2) {
700         i = (int)(vpe->vp_name[VICE_PREFIX_SIZE] - 'a') * 26 +
701             (int)(vpe->vp_name[VICE_PREFIX_SIZE + 1] - 'a');
702         if (i > 255) {
703             Log("Invalid partition name %s in registry, ignoring it.\n",
704                 vpe->vp_name);
705             return 0;
706         }
707     }
708
709     len = strlen(vpe->vp_dev);
710     if (len != 2 || vpe->vp_dev[1] != ':' || vpe->vp_dev[0] < 'A'
711         || vpe->vp_dev[0] > 'Z') {
712         Log("Invalid device name %s in registry, ignoring it.\n",
713             vpe->vp_dev);
714         return 0;
715     }
716
717     return 1;
718 }
719
720 int
721 VCheckPartition(char *partName)
722 {
723     char volRoot[4];
724     char volFsType[64];
725     DWORD dwDummy;
726     int err;
727
728     /* partName is presumed to be of the form "X:" */
729     (void)sprintf(volRoot, "%c:\\", *partName);
730
731     if (!GetVolumeInformation(volRoot,  /* volume root directory */
732                               NULL,     /* volume name buffer */
733                               0,        /* volume name size */
734                               NULL,     /* volume serial number */
735                               &dwDummy, /* max component length */
736                               &dwDummy, /* file system flags */
737                               volFsType,        /* file system name */
738                               sizeof(volFsType))) {
739         err = GetLastError();
740         Log("VCheckPartition: Failed to get partition information for %s, ignoring it.\n", partName);
741         return -1;
742     }
743
744     if (strcmp(volFsType, "NTFS")) {
745         Log("VCheckPartition: Partition %s is not an NTFS partition, ignoring it.\n", partName);
746         return -1;
747     }
748
749     return 0;
750 }
751
752
753 int
754 VAttachPartitions(void)
755 {
756     struct DiskPartition64 *partP, *prevP, *nextP;
757     struct vpt_iter iter;
758     struct vptab entry;
759
760     if (vpt_Start(&iter) < 0) {
761         Log("No partitions to attach.\n");
762         return 0;
763     }
764
765     while (0 == vpt_NextEntry(&iter, &entry)) {
766         if (!VValidVPTEntry(&entry)) {
767             continue;
768         }
769
770         /* This test for duplicates relies on the fact that the method
771          * of storing the partition names in the NT registry means the same
772          * partition name will never appear twice in the list.
773          */
774         for (partP = DiskPartitionList; partP; partP = partP->next) {
775             if (*partP->devName == *entry.vp_dev) {
776                 Log("Same drive (%s) used for both partition %s and partition %s, ignoring both.\n", entry.vp_dev, partP->name, entry.vp_name);
777                 partP->flags = PART_DUPLICATE;
778                 break;          /* Only one entry will ever be in this list. */
779             }
780         }
781         if (partP)
782             continue;           /* found a duplicate */
783
784         if (VCheckPartition(entry.vp_dev) < 0)
785             continue;
786         /* This test allows for manually inserting the FORCESALVAGE flag
787          * and thereby invoking the salvager. scandisk obviously won't be
788          * doing this for us.
789          */
790         if (programType == fileServer) {
791             struct afs_stat_st status;
792             char salvpath[MAXPATHLEN];
793             strcpy(salvpath, entry.vp_dev);
794             strcat(salvpath, "\\FORCESALVAGE");
795             if (afs_stat(salvpath, &status) == 0) {
796                 Log("VAttachPartitions: Found %s; aborting\n", salvpath);
797                 exit(1);
798             }
799         }
800         VInitPartition(entry.vp_name, entry.vp_dev, *entry.vp_dev - 'A');
801     }
802     vpt_Finish(&iter);
803
804     /* Run through partition list and clear out the dupes. */
805     prevP = nextP = NULL;
806     for (partP = DiskPartitionList; partP; partP = nextP) {
807         nextP = partP->next;
808         if (partP->flags == PART_DUPLICATE) {
809             if (prevP)
810                 prevP->next = partP->next;
811             else
812                 DiskPartitionList = partP->next;
813             free(partP);
814         } else
815             prevP = partP;
816     }
817
818     return 0;
819 }
820 #endif
821
822 #ifdef AFS_LINUX22_ENV
823 int
824 VAttachPartitions(void)
825 {
826     int errors = 0;
827     FILE *mfd;
828     struct mntent *mntent;
829
830     if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
831         if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
832             Log("Problems in getting mount entries(setmntent)\n");
833             exit(-1);
834         }
835     }
836     while ((mntent = getmntent(mfd))) {
837         /* If we're going to always attach this partition, do it later. */
838         if (VIsAlwaysAttach(mntent->mnt_dir, NULL))
839             continue;
840
841         if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname, 0) < 0)
842             errors++;
843     }
844     endmntent(mfd);
845
846     /* Process the always-attach partitions, if any. */
847     VAttachPartitions2();
848
849     return errors;
850 }
851 #endif /* AFS_LINUX22_ENV */
852
853 /* This routine is to be called whenever the actual name of the partition
854  * is required. The canonical name is still in part->name.
855  */
856 char *
857 VPartitionPath(struct DiskPartition64 *part)
858 {
859 #ifdef AFS_NT40_ENV
860     return part->devName;
861 #else
862     return part->name;
863 #endif
864 }
865
866 /* get partition structure, abortp tells us if we should abort on failure */
867 struct DiskPartition64 *
868 VGetPartition_r(char *name, int abortp)
869 {
870     struct DiskPartition64 *dp;
871 #ifdef AFS_DEMAND_ATTACH_FS
872     dp = VLookupPartition_r(name);
873 #else /* AFS_DEMAND_ATTACH_FS */
874     for (dp = DiskPartitionList; dp; dp = dp->next) {
875         if (strcmp(dp->name, name) == 0)
876             break;
877     }
878 #endif /* AFS_DEMAND_ATTACH_FS */
879     if (abortp)
880         osi_Assert(dp != NULL);
881     return dp;
882 }
883
884 struct DiskPartition64 *
885 VGetPartition(char *name, int abortp)
886 {
887     struct DiskPartition64 *retVal;
888     VOL_LOCK;
889     retVal = VGetPartition_r(name, abortp);
890     VOL_UNLOCK;
891     return retVal;
892 }
893
894 #ifdef AFS_NT40_ENV
895 void
896 VSetPartitionDiskUsage_r(struct DiskPartition64 *dp)
897 {
898     ULARGE_INTEGER free_user, total, free_total;
899     int ufree, tot, tfree;
900
901     if (!GetDiskFreeSpaceEx
902         (VPartitionPath(dp), &free_user, &total, &free_total)) {
903         printf("Failed to get disk space info for %s, error = %d\n", dp->name,
904                GetLastError());
905         return;
906     }
907
908     /* Convert to 1K units. */
909     ufree = (int)Int64ShraMod32(free_user.QuadPart, 10);
910     tot = (int)Int64ShraMod32(total.QuadPart, 10);
911     tfree = (int)Int64ShraMod32(free_total.QuadPart, 10);
912
913     dp->minFree = tfree - ufree;        /* only used in VPrintDiskStats_r */
914     dp->totalUsable = tot;
915     dp->free = tfree;
916 }
917
918 #else
919 void
920 VSetPartitionDiskUsage_r(struct DiskPartition64 *dp)
921 {
922     int bsize, code;
923     afs_int64 totalblks, free, used, availblks;
924     int reserved;
925 #ifdef afs_statvfs
926     struct afs_statvfs statbuf;
927 #else
928     struct afs_statfs statbuf;
929 #endif
930
931     if (dp->flags & PART_DONTUPDATE)
932         return;
933     /* Note:  we don't bother syncing because it's only an estimate, update
934      * is syncing every 30 seconds anyway, we only have to keep the disk
935      * approximately 10% from full--you just can't get the stuff in from
936      * the net fast enough to worry */
937 #ifdef afs_statvfs
938     code = afs_statvfs(dp->name, &statbuf);
939 #else
940     code = afs_statfs(dp->name, &statbuf);
941 #endif
942     if (code < 0) {
943         Log("statfs of %s failed in VSetPartitionDiskUsage (errno = %d)\n",
944             dp->name, errno);
945         return;
946     }
947     if (statbuf.f_blocks == -1) {       /* Undefined; skip stats.. */
948         Log("statfs of %s failed in VSetPartitionDiskUsage\n", dp->name);
949         return;
950     }
951     totalblks = statbuf.f_blocks;
952     free = statbuf.f_bfree;
953     reserved = free - statbuf.f_bavail;
954 #ifdef afs_statvfs
955     bsize = statbuf.f_frsize;
956 #else
957     bsize = statbuf.f_bsize;
958 #endif
959     availblks = totalblks - reserved;
960     dp->f_files = statbuf.f_files;      /* max # of files in partition */
961
962     /* Now free and totalblks are in fragment units, but we want them in
963      * 1K units.
964      */
965     if (bsize >= 1024) {
966         free *= (bsize / 1024);
967         totalblks *= (bsize / 1024);
968         availblks *= (bsize / 1024);
969         reserved *= (bsize / 1024);
970     } else {
971         free /= (1024 / bsize);
972         totalblks /= (1024 / bsize);
973         availblks /= (1024 / bsize);
974         reserved /= (1024 / bsize);
975     }
976     /* now compute remaining figures */
977     used = totalblks - free;
978
979     dp->minFree = reserved;     /* only used in VPrintDiskStats_r */
980     dp->totalUsable = availblks;
981     dp->free = availblks - used;        /* this is exactly f_bavail */
982 }
983 #endif /* AFS_NT40_ENV */
984
985 void
986 VSetPartitionDiskUsage(struct DiskPartition64 *dp)
987 {
988     VOL_LOCK;
989     VSetPartitionDiskUsage_r(dp);
990     VOL_UNLOCK;
991 }
992
993 void
994 VResetDiskUsage_r(void)
995 {
996     struct DiskPartition64 *dp;
997     for (dp = DiskPartitionList; dp; dp = dp->next) {
998         VSetPartitionDiskUsage_r(dp);
999 #ifndef AFS_PTHREAD_ENV
1000         IOMGR_Poll();
1001 #endif /* !AFS_PTHREAD_ENV */
1002     }
1003 }
1004
1005 void
1006 VResetDiskUsage(void)
1007 {
1008     VOL_LOCK;
1009     VResetDiskUsage_r();
1010     VOL_UNLOCK;
1011 }
1012
1013 void
1014 VAdjustDiskUsage_r(Error * ec, Volume * vp, afs_sfsize_t blocks,
1015                    afs_sfsize_t checkBlocks)
1016 {
1017     *ec = 0;
1018     /* why blocks instead of checkBlocks in the check below?  Otherwise, any check
1019      * for less than BlocksSpare would skip the error-checking path, and we
1020      * could grow existing files forever, not just for another BlocksSpare
1021      * blocks. */
1022     if (blocks > 0) {
1023 #ifdef  AFS_AIX32_ENV
1024         afs_int32 rem, minavail;
1025
1026         if ((rem = vp->partition->free - checkBlocks) < (minavail =
1027                                                          (vp->partition->
1028                                                           totalUsable *
1029                                                           aixlow_water) /
1030                                                          100))
1031 #else
1032         if (vp->partition->free - checkBlocks < 0)
1033 #endif
1034             *ec = VDISKFULL;
1035         else if (V_maxquota(vp)
1036                  && V_diskused(vp) + checkBlocks > V_maxquota(vp))
1037             *ec = VOVERQUOTA;
1038     }
1039     vp->partition->free -= blocks;
1040     V_diskused(vp) += blocks;
1041 }
1042
1043 void
1044 VAdjustDiskUsage(Error * ec, Volume * vp, afs_sfsize_t blocks,
1045                  afs_sfsize_t checkBlocks)
1046 {
1047     VOL_LOCK;
1048     VAdjustDiskUsage_r(ec, vp, blocks, checkBlocks);
1049     VOL_UNLOCK;
1050 }
1051
1052 int
1053 VDiskUsage_r(Volume * vp, afs_sfsize_t blocks)
1054 {
1055     if (blocks > 0) {
1056 #ifdef  AFS_AIX32_ENV
1057         afs_int32 rem, minavail;
1058
1059         if ((rem = vp->partition->free - blocks) < (minavail =
1060                                                     (vp->partition->
1061                                                      totalUsable *
1062                                                      aixlow_water) / 100))
1063 #else
1064         if (vp->partition->free - blocks < 0)
1065 #endif
1066             return (VDISKFULL);
1067     }
1068     vp->partition->free -= blocks;
1069     return 0;
1070 }
1071
1072 int
1073 VDiskUsage(Volume * vp, afs_sfsize_t blocks)
1074 {
1075     int retVal;
1076     VOL_LOCK;
1077     retVal = VDiskUsage_r(vp, blocks);
1078     VOL_UNLOCK;
1079     return retVal;
1080 }
1081
1082 void
1083 VPrintDiskStats_r(void)
1084 {
1085     struct DiskPartition64 *dp;
1086     for (dp = DiskPartitionList; dp; dp = dp->next) {
1087         if (dp->free < 0) {
1088             Log("Partition %s: %lld "
1089                 " available 1K blocks (minfree=%lld), "
1090                 "overallocated by %lld blocks\n", dp->name,
1091                 dp->totalUsable, dp->minFree, -dp->free);
1092         } else {
1093             Log("Partition %s: %lld"
1094                 " available 1K blocks (minfree=%lld), "
1095                 "%lld free blocks\n", dp->name,
1096                 dp->totalUsable, dp->minFree, dp->free);
1097         }
1098     }
1099 }
1100
1101 void
1102 VPrintDiskStats(void)
1103 {
1104     VOL_LOCK;
1105     VPrintDiskStats_r();
1106     VOL_UNLOCK;
1107 }
1108
1109 #ifdef AFS_NT40_ENV
1110 /* Need a separate lock file on NT, since NT only has mandatory file locks. */
1111 #define LOCKFILE "LOCKFILE"
1112 void
1113 VLockPartition_r(char *name)
1114 {
1115     struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1116     OVERLAPPED lap;
1117
1118     if (!dp)
1119         return;
1120     if (dp->lock_fd == INVALID_FD) {
1121         char path[64];
1122         int rc;
1123         (void)sprintf(path, "%s\\%s", VPartitionPath(dp), LOCKFILE);
1124         dp->lock_fd =
1125             (FD_t)CreateFile(path, GENERIC_WRITE,
1126                             FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1127                             CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
1128         osi_Assert(dp->lock_fd != INVALID_FD);
1129
1130         memset(&lap, 0, sizeof(lap));
1131         rc = LockFileEx((HANDLE) dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1,
1132                         0, &lap);
1133         osi_Assert(rc);
1134     }
1135 }
1136
1137 void
1138 VUnlockPartition_r(char *name)
1139 {
1140     struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1141     OVERLAPPED lap;
1142
1143     if (!dp)
1144         return;                 /* no partition, will fail later */
1145     memset(&lap, 0, sizeof(lap));
1146
1147     UnlockFileEx((HANDLE) dp->lock_fd, 0, 1, 0, &lap);
1148     CloseHandle((HANDLE) dp->lock_fd);
1149     dp->lock_fd = INVALID_FD;
1150 }
1151 #else /* AFS_NT40_ENV */
1152
1153 #if defined(AFS_HPUX_ENV)
1154 #define BITS_PER_CHAR   (8)
1155 #define BITS(type)      (sizeof(type) * BITS_PER_CHAR)
1156
1157 #define LOCKRDONLY_OFFSET       ((PRIV_LOCKRDONLY - 1) / BITS(int))
1158 #endif /* defined(AFS_HPUX_ENV) */
1159
1160 void
1161 VLockPartition_r(char *name)
1162 {
1163     struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1164     char *partitionName;
1165     int retries, code;
1166     struct timeval pausing;
1167 #if defined(AFS_HPUX_ENV)
1168     int lockfRtn;
1169     struct privgrp_map privGrpList[PRIV_MAXGRPS];
1170     unsigned int *globalMask;
1171     int globalMaskIndex;
1172 #endif /* defined(AFS_HPUX_ENV) */
1173 #if defined(AFS_DARWIN_ENV)
1174     char lockfile[MAXPATHLEN];
1175 #endif /* defined(AFS_DARWIN_ENV) */
1176 #ifdef AFS_NAMEI_ENV
1177 #ifdef AFS_AIX42_ENV
1178     char LockFileName[MAXPATHLEN + 1];
1179
1180     sprintf((char *)&LockFileName, "%s/AFSINODE_FSLock", name);
1181     partitionName = (char *)&LockFileName;
1182 #endif
1183 #endif
1184
1185     if (!dp)
1186         return;                 /* no partition, will fail later */
1187     if (dp->lock_fd != INVALID_FD)
1188         return;
1189
1190 #if    defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
1191 #if !defined(AFS_AIX42_ENV) || !defined(AFS_NAMEI_ENV)
1192     partitionName = dp->devName;
1193 #endif
1194     code = O_RDWR;
1195 #elif defined(AFS_DARWIN_ENV)
1196     strlcpy((partitionName = lockfile), dp->name, sizeof(lockfile));
1197     strlcat(lockfile, "/.lock.afs", sizeof(lockfile));
1198     code = O_RDONLY | O_CREAT;
1199 #else
1200     partitionName = dp->name;
1201     code = O_RDONLY;
1202 #endif
1203
1204     for (retries = 25; retries; retries--) {
1205         if (code & O_CREAT)
1206             dp->lock_fd = afs_open(partitionName, code, 0644);
1207         else
1208             dp->lock_fd = afs_open(partitionName, code);
1209
1210         if (dp->lock_fd != INVALID_FD)
1211             break;
1212         if (errno == ENOENT)
1213             code |= O_CREAT;
1214         pausing.tv_sec = 0;
1215         pausing.tv_usec = 500000;
1216         select(0, NULL, NULL, NULL, &pausing);
1217     }
1218     osi_Assert(retries != 0);
1219
1220 #if defined (AFS_HPUX_ENV)
1221
1222     osi_Assert(getprivgrp(privGrpList) == 0);
1223
1224     /*
1225      * In general, it will difficult and time-consuming ,if not impossible,
1226      * to try to find the privgroup to which this process belongs that has the
1227      * smallest membership, to minimise the security hole.  So, we use the privgrp
1228      * to which everybody belongs.
1229      */
1230     /* first, we have to find the global mask */
1231     for (globalMaskIndex = 0; globalMaskIndex < PRIV_MAXGRPS;
1232          globalMaskIndex++) {
1233         if (privGrpList[globalMaskIndex].priv_groupno == PRIV_GLOBAL) {
1234             globalMask =
1235                 &(privGrpList[globalMaskIndex].priv_mask[LOCKRDONLY_OFFSET]);
1236             break;
1237         }
1238     }
1239
1240     if (((*globalMask) & privmask(PRIV_LOCKRDONLY)) == 0) {
1241         /* allow everybody to set a lock on a read-only file descriptor */
1242         (*globalMask) |= privmask(PRIV_LOCKRDONLY);
1243         osi_Assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask)
1244                == 0);
1245
1246         lockfRtn = lockf(dp->lock_fd, F_LOCK, 0);
1247
1248         /* remove the privilege granted to everybody to lock a read-only fd */
1249         (*globalMask) &= ~(privmask(PRIV_LOCKRDONLY));
1250         osi_Assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask)
1251                == 0);
1252     } else {
1253         /* in this case, we should be able to do this with impunity, anyway */
1254         lockfRtn = lockf(dp->lock_fd, F_LOCK, 0);
1255     }
1256
1257     osi_Assert(lockfRtn != -1);
1258 #else
1259 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
1260     osi_Assert(lockf(dp->lock_fd, F_LOCK, 0) != -1);
1261 #else
1262     osi_Assert(flock(dp->lock_fd, LOCK_EX) == 0);
1263 #endif /* defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) */
1264 #endif
1265 }
1266
1267 void
1268 VUnlockPartition_r(char *name)
1269 {
1270     struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1271     if (!dp)
1272         return;                 /* no partition, will fail later */
1273     close(dp->lock_fd);
1274     dp->lock_fd = INVALID_FD;
1275 }
1276
1277 #endif /* AFS_NT40_ENV */
1278
1279 void
1280 VLockPartition(char *name)
1281 {
1282     VOL_LOCK;
1283     VLockPartition_r(name);
1284     VOL_UNLOCK;
1285 }
1286
1287 void
1288 VUnlockPartition(char *name)
1289 {
1290     VOL_LOCK;
1291     VUnlockPartition_r(name);
1292     VOL_UNLOCK;
1293 }
1294
1295 #ifdef AFS_DEMAND_ATTACH_FS
1296
1297 /* new-style partition locks; these are only to have some mutual exclusion
1298  * between the VGC scanner and volume utilies creating/altering vol headers
1299  */
1300
1301 /**
1302  * lock a partition's vol headers.
1303  *
1304  * @param[in] dp       the partition to lock
1305  * @param[in] locktype READ_LOCK or WRITE_LOCK
1306  *
1307  * @return operation status
1308  *  @retval 0 success
1309  */
1310 int
1311 VPartHeaderLock(struct DiskPartition64 *dp, int locktype)
1312 {
1313     int code;
1314
1315     /* block on acquiring the lock */
1316     int nonblock = 0;
1317
1318     code = VGetDiskLock(&dp->headerLock, locktype, nonblock);
1319     if (code) {
1320         Log("VPartHeaderLock: error %d locking partititon %s\n", code,
1321             VPartitionPath(dp));
1322     }
1323     return code;
1324 }
1325
1326 /**
1327  * unlock a partition's vol headers.
1328  *
1329  * @param[in] dp       the partition to unlock
1330  * @param[in] locktype READ_LOCK or WRITE_LOCK
1331  */
1332 void
1333 VPartHeaderUnlock(struct DiskPartition64 *dp, int locktype)
1334 {
1335     VReleaseDiskLock(&dp->headerLock, locktype);
1336 }
1337
1338 /* XXX not sure this will work on AFS_NT40_ENV
1339  * needs to be tested!
1340  */
1341
1342 /**
1343  * lookup a disk partition object by its index number.
1344  *
1345  * @param[in] id      partition index number
1346  * @param[in] abortp  see abortp usage note below
1347  *
1348  * @return disk partition object
1349  *   @retval NULL no such disk partition
1350  *
1351  * @note when abortp is non-zero, lookups which would return
1352  *       NULL will result in an assertion failure
1353  *
1354  * @pre VOL_LOCK must be held
1355  *
1356  * @internal volume package internal use only
1357  */
1358
1359 struct DiskPartition64 *
1360 VGetPartitionById_r(afs_int32 id, int abortp)
1361 {
1362     struct DiskPartition64 *dp = NULL;
1363
1364     if ((id >= 0) && (id <= VOLMAXPARTS)) {
1365         dp = DiskPartitionTable[id];
1366     }
1367
1368     if (abortp) {
1369         osi_Assert(dp != NULL);
1370     }
1371     return dp;
1372 }
1373
1374 /**
1375  * lookup a disk partition object by its index number.
1376  *
1377  * @param[in] id      partition index number
1378  * @param[in] abortp  see abortp usage note below
1379  *
1380  * @return disk partition object
1381  *   @retval NULL no such disk partition
1382  *
1383  * @note when abortp is non-zero, lookups which would return
1384  *       NULL will result in an assertion failure
1385  */
1386
1387 struct DiskPartition64 *
1388 VGetPartitionById(afs_int32 id, int abortp)
1389 {
1390     struct DiskPartition64 * dp;
1391
1392     VOL_LOCK;
1393     dp = VGetPartitionById_r(id, abortp);
1394     VOL_UNLOCK;
1395
1396     return dp;
1397 }
1398
1399 static struct DiskPartition64 *
1400 VLookupPartition_r(char * path)
1401 {
1402     afs_int32 id = volutil_GetPartitionID(path);
1403
1404     if (id < 0 || id > VOLMAXPARTS)
1405         return NULL;
1406
1407     return DiskPartitionTable[id];
1408 }
1409
1410 static void
1411 AddPartitionToTable_r(struct DiskPartition64 *dp)
1412 {
1413     osi_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
1414     DiskPartitionTable[dp->index] = dp;
1415 }
1416
1417 #if 0
1418 static void
1419 DeletePartitionFromTable_r(struct DiskPartition64 *dp)
1420 {
1421     osi_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
1422     DiskPartitionTable[dp->index] = NULL;
1423 }
1424 #endif
1425 #endif /* AFS_DEMAND_ATTACH_FS */