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