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