Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / vol / partition.c
blob1b889195654aa84eb1040385746b6181fafa11af
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
9 * Portions Copyright (c) 2003 Apple Computer, Inc.
10 * Portions Copyright (c) 2006 Sine Nomine Associates
15 System: VICE-TWO
16 Module: partition.c
17 Institution: The Information Technology Center, Carnegie-Mellon University
21 #include <afsconfig.h>
22 #include <afs/param.h>
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>
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
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
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 #include "common.h"
119 #ifdef AFS_NAMEI_ENV
120 #ifdef AFS_NT40_ENV
121 #include "ntops.h"
122 #else
123 #include "namei_ops.h"
124 #include <dirent.h>
125 #endif /* AFS_NT40_ENV */
126 #endif /* AFS_NAMEI_ENV */
127 #include "vnode.h"
128 #include "volume.h"
129 #include "partition.h"
130 #include <afs/afs_assert.h>
132 #if defined(AFS_HPUX_ENV)
133 #include <sys/types.h>
134 #include <sys/privgrp.h>
135 #endif /* defined(AFS_HPUX_ENV) */
137 #ifdef AFS_AIX42_ENV
138 #include <jfs/filsys.h>
139 #endif
141 #ifdef O_LARGEFILE
143 #define afs_stat stat64
144 #define afs_open open64
145 #define afs_fopen fopen64
146 #ifndef AFS_NT40_ENV
147 #if AFS_HAVE_STATVFS64
148 # define afs_statvfs statvfs64
149 #else
150 # if AFS_HAVE_STATFS64
151 # define afs_statfs statfs64
152 #else
153 # if AFS_HAVE_STATVFS
154 # define afs_statvfs statvfs
155 # else
156 # define afs_statfs statfs
157 # endif /* !AFS_HAVE_STATVFS */
158 # endif /* !AFS_HAVE_STATFS64 */
159 #endif /* !AFS_HAVE_STATVFS64 */
160 #endif /* !AFS_NT40_ENV */
162 #else /* !O_LARGEFILE */
164 #define afs_stat stat
165 #define afs_open open
166 #define afs_fopen fopen
167 #ifndef AFS_NT40_ENV
168 #if AFS_HAVE_STATVFS
169 #define afs_statvfs statvfs
170 #else /* !AFS_HAVE_STATVFS */
171 #define afs_statfs statfs
172 #endif /* !AFS_HAVE_STATVFS */
173 #endif /* !AFS_NT40_ENV */
175 #endif /* !O_LARGEFILE */
177 int aixlow_water = 8; /* default 8% */
178 struct DiskPartition64 *DiskPartitionList;
180 #ifdef AFS_DEMAND_ATTACH_FS
181 /* file to lock to conceptually "lock" the vol headers on a partition */
182 #define AFS_PARTLOCK_FILE ".volheaders.lock"
183 #define AFS_VOLUMELOCK_FILE ".volume.lock"
185 static struct DiskPartition64 *DiskPartitionTable[VOLMAXPARTS+1];
187 static struct DiskPartition64 * VLookupPartition_r(char * path);
188 static void AddPartitionToTable_r(struct DiskPartition64 *);
189 #endif /* AFS_DEMAND_ATTACH_FS */
191 #ifdef AFS_SGI_XFS_IOPS_ENV
192 /* Verify that the on disk XFS inodes on the partition are large enough to
193 * hold the AFS attribute. Returns -1 if the attribute can't be set or is
194 * too small to fit in the inode. Returns 0 if the attribute does fit in
195 * the XFS inode.
197 #include <afs/xfsattrs.h>
198 static int
199 VerifyXFSInodeSize(char *part, char *fstype)
201 afs_xfs_attr_t junk;
202 int length = SIZEOF_XFS_ATTR_T;
203 int fd = 0;
204 int code = -1;
205 struct fsxattr fsx;
207 if (strcmp("xfs", fstype))
208 return 0;
210 if (attr_set(part, AFS_XFS_ATTR, &junk, length, ATTR_ROOT) == 0) {
211 if (((fd = open(part, O_RDONLY, 0)) != -1)
212 && (fcntl(fd, F_FSGETXATTRA, &fsx) == 0)) {
214 if (fsx.fsx_nextents) {
215 Log("Partition %s: XFS inodes too small, exiting.\n", part);
216 Log("Run xfs_size_check utility and remake partitions.\n");
217 } else
218 code = 0;
221 if (fd > 0)
222 close(fd);
223 (void)attr_remove(part, AFS_XFS_ATTR, ATTR_ROOT);
225 return code;
227 #endif /* AFS_SGI_XFS_IOPS_ENV */
230 VInitPartitionPackage(void)
232 #ifdef AFS_DEMAND_ATTACH_FS
233 memset(&DiskPartitionTable, 0, sizeof(DiskPartitionTable));
234 #endif /* AFS_DEMAND_ATTACH_FS */
235 return 0;
238 static void
239 VInitPartition_r(char *path, char *devname, Device dev)
241 struct DiskPartition64 *dp, *op;
243 dp = (struct DiskPartition64 *)malloc(sizeof(struct DiskPartition64));
244 /* Add it to the end, to preserve order when we print statistics */
245 for (op = DiskPartitionList; op; op = op->next) {
246 if (!op->next)
247 break;
249 if (op)
250 op->next = dp;
251 else
252 DiskPartitionList = dp;
253 dp->next = 0;
254 dp->name = (char *)malloc(strlen(path) + 1);
255 strncpy(dp->name, path, strlen(path) + 1);
256 dp->index = volutil_GetPartitionID(path);
257 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
258 /* Create a lockfile for the partition, of the form /vicepa/Lock/vicepa */
259 dp->devName = (char *)malloc(2 * strlen(path) + 6);
260 strcpy(dp->devName, path);
261 strcat(dp->devName, OS_DIRSEP);
262 strcat(dp->devName, "Lock");
263 mkdir(dp->devName, 0700);
264 strcat(dp->devName, path);
265 close(afs_open(dp->devName, O_RDWR | O_CREAT, 0600));
266 dp->device = dp->index;
267 #else
268 dp->devName = (char *)malloc(strlen(devname) + 1);
269 strncpy(dp->devName, devname, strlen(devname) + 1);
270 dp->device = dev;
271 #endif
272 dp->lock_fd = INVALID_FD;
273 dp->flags = 0;
274 dp->f_files = 1; /* just a default value */
275 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
276 if (programType == fileServer)
277 (void)namei_ViceREADME(VPartitionPath(dp));
278 #endif
279 VSetPartitionDiskUsage_r(dp);
280 #ifdef AFS_DEMAND_ATTACH_FS
281 AddPartitionToTable_r(dp);
282 queue_Init(&dp->vol_list.head);
283 CV_INIT(&dp->vol_list.cv, "vol list", CV_DEFAULT, 0);
284 dp->vol_list.len = 0;
285 dp->vol_list.busy = 0;
287 char lockpath[MAXPATHLEN+1];
288 afs_snprintf(lockpath, MAXPATHLEN, "%s/" AFS_PARTLOCK_FILE, dp->name);
289 lockpath[MAXPATHLEN] = '\0';
290 VLockFileInit(&dp->headerLockFile, lockpath);
292 afs_snprintf(lockpath, MAXPATHLEN, "%s/" AFS_VOLUMELOCK_FILE, dp->name);
293 lockpath[MAXPATHLEN] = '\0';
294 VLockFileInit(&dp->volLockFile, lockpath);
296 VDiskLockInit(&dp->headerLock, &dp->headerLockFile, 1);
297 #endif /* AFS_DEMAND_ATTACH_FS */
300 static void
301 VInitPartition(char *path, char *devname, Device dev)
303 VOL_LOCK;
304 VInitPartition_r(path, devname, dev);
305 VOL_UNLOCK;
308 #ifndef AFS_NT40_ENV
309 /* VAttachPartitions() finds the vice partitions on this server. Calls
310 * VCheckPartition() to do some basic checks on the partition. If the partition
311 * is a valid vice partition, VCheckPartition will add it to the DiskPartition
312 * list.
313 * Returns the number of errors returned by VCheckPartition. An error in
314 * VCheckPartition means that partition is a valid vice partition but the
315 * fileserver should not start because of the error found on that partition.
317 * AFS_NAMEI_ENV
318 * No specific user space file system checks, since we don't know what
319 * is being used for vice partitions.
321 * Use partition name as devname.
324 VCheckPartition(char *part, char *devname, int logging)
326 struct afs_stat status;
327 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV)
328 char AFSIDatPath[MAXPATHLEN];
329 #endif
331 /* Only keep track of "/vicepx" partitions since it can get hairy
332 * when NFS mounts are involved.. */
333 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
334 return 0;
336 if (afs_stat(part, &status) < 0) {
337 Log("VInitVnodes: Couldn't find file system %s; ignored\n", part);
338 return 0;
340 if (logging) {
341 Log("This program is compiled without AFS_NAMEI_ENV, and "
342 "partition %s is mounted with the 'logging' option. "
343 "Using the inode fileserver backend with 'logging' UFS "
344 "partitions causes volume corruption, so please either "
345 "mount the partition without logging, or use the namei "
346 "fileserver backend. Aborting...\n", part);
347 return -1;
349 #ifndef AFS_AIX32_ENV
350 if (programType == fileServer) {
351 char salvpath[MAXPATHLEN];
352 strcpy(salvpath, part);
353 strcat(salvpath, "/FORCESALVAGE");
354 if (afs_stat(salvpath, &status) == 0) {
355 Log("VInitVnodes: Found %s; aborting\n", salvpath);
356 return -1;
359 #endif
361 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_NT40_ENV)
362 strcpy(AFSIDatPath, part);
363 strcat(AFSIDatPath, "/AFSIDat");
364 #ifdef AFS_NAMEI_ENV
365 if (afs_stat(AFSIDatPath, &status) < 0) {
366 DIR *dirp;
367 struct dirent *dp;
369 dirp = opendir(part);
370 osi_Assert(dirp);
371 while ((dp = readdir(dirp))) {
372 if (dp->d_name[0] == 'V') {
373 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);
374 closedir(dirp);
375 return -1;
378 closedir(dirp);
380 #else /* AFS_NAMEI_ENV */
381 if (afs_stat(AFSIDatPath, &status) == 0) {
382 Log("This program is compiled without AFS_NAMEI_ENV, but partition %s seems to contain volumes which use the namei-interface; aborting\n", part);
383 return -1;
386 #ifdef AFS_SGI_XFS_IOPS_ENV
387 if (VerifyXFSInodeSize(part, status.st_fstype) < 0)
388 return -1;
389 #endif
390 #endif /* AFS_NAMEI_ENV */
391 #endif /* !AFS_LINUX20_ENV && !AFS_NT40_ENV */
393 #if defined(AFS_DUX40_ENV) && !defined(AFS_NAMEI_ENV)
394 if (status.st_ino != ROOTINO) {
395 Log("%s is not a mounted file system; ignored.\n", part);
396 return 0;
398 #endif
400 VInitPartition(part, devname, status.st_dev);
402 return 0;
405 /* VIsAlwaysAttach() checks whether a /vicepX directory should always be
406 * attached (return value 1), or only attached when it is a separately
407 * mounted partition (return value 0). For non-NAMEI environments, it
408 * always returns 0.
410 * *awouldattach will be set to 1 if the given path at least looks like a vice
411 * partition (that is, if we return 0, the only thing preventing this partition
412 * from being attached is the existence of the AlwaysAttach file), or to 0
413 * otherwise. *awouldattach is set regardless of whether or not the partition
414 * should always be attached or not.
416 static int
417 VIsAlwaysAttach(char *part, int *awouldattach)
419 #ifdef AFS_NAMEI_ENV
420 struct afs_stat st;
421 char checkfile[256];
422 int ret;
423 #endif /* AFS_NAMEI_ENV */
425 if (awouldattach) {
426 *awouldattach = 0;
429 #ifdef AFS_NAMEI_ENV
430 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
431 return 0;
433 if (awouldattach) {
434 *awouldattach = 1;
437 strncpy(checkfile, part, 100);
438 strcat(checkfile, OS_DIRSEP);
439 strcat(checkfile, VICE_ALWAYSATTACH_FILE);
441 ret = afs_stat(checkfile, &st);
442 return (ret < 0) ? 0 : 1;
443 #else /* AFS_NAMEI_ENV */
444 return 0;
445 #endif /* AFS_NAMEI_ENV */
448 /* VIsNeverAttach() checks whether a /vicepX directory should never be
449 * attached (return value 1), or follow the normal mounting logic. The
450 * Always Attach flag may override the NeverAttach flag.
452 static int
453 VIsNeverAttach(char *part)
455 struct afs_stat st;
456 char checkfile[256];
457 int ret;
459 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
460 return 0;
462 strncpy(checkfile, part, 100);
463 strcat(checkfile, OS_DIRSEP);
464 strcat(checkfile, VICE_NEVERATTACH_FILE);
466 ret = afs_stat(checkfile, &st);
467 return (ret < 0) ? 0 : 1;
470 /* VAttachPartitions2() looks for and attaches /vicepX partitions
471 * where a special file (VICE_ALWAYSATTACH_FILE) exists. This is
472 * used to attach /vicepX directories which aren't on dedicated
473 * partitions, in the NAMEI fileserver.
475 void
476 VAttachPartitions2(void)
478 #ifdef AFS_NAMEI_ENV
479 DIR *dirp;
480 struct dirent *de;
481 char pname[32];
482 int wouldattach;
484 dirp = opendir(OS_DIRSEP);
485 while ((de = readdir(dirp))) {
486 strcpy(pname, OS_DIRSEP);
487 strncat(pname, de->d_name, 20);
488 pname[sizeof(pname) - 1] = '\0';
490 /* Only keep track of "/vicepx" partitions since automounter
491 * may hose us */
492 if (VIsAlwaysAttach(pname, &wouldattach)) {
493 VCheckPartition(pname, "", 0);
494 } else {
495 struct afs_stat st;
496 if (wouldattach && VGetPartition(pname, 0) == NULL &&
497 afs_stat(pname, &st) == 0 && S_ISDIR(st.st_mode)) {
499 /* This is a /vicep* dir, and it has not been attached as a
500 * partition. This probably means that this is a /vicep* dir
501 * that is not a separate partition, so just give a notice so
502 * admins are not confused as to why their /vicep* dirs are not
503 * being attached.
505 * It is possible that the dir _is_ a separate partition and we
506 * failed to attach it earlier, making this message a bit
507 * confusing. But that should be rare, and an error message
508 * about the failure will already be logged right before this,
509 * so it should be clear enough. */
511 Log("VAttachPartitions: not attaching %s; either it is not a "
512 "separate partition, or it failed to attach (create the "
513 "file %s/" VICE_ALWAYSATTACH_FILE " to force attachment)\n",
514 pname, pname);
518 closedir(dirp);
519 #endif /* AFS_NAMEI_ENV */
521 #endif /* AFS_NT40_ENV */
523 #ifdef AFS_SUN5_ENV
525 VAttachPartitions(void)
527 int errors = 0;
528 struct mnttab mnt;
529 FILE *mntfile;
531 if (!(mntfile = afs_fopen(MNTTAB, "r"))) {
532 Log("Can't open %s\n", MNTTAB);
533 perror(MNTTAB);
534 exit(-1);
536 while (!getmntent(mntfile, &mnt)) {
537 int logging = 0;
538 /* Ignore non ufs or non read/write partitions */
539 /* but allow zfs too if we're in the NAMEI environment */
540 if (
541 #ifdef AFS_NAMEI_ENV
542 (((strcmp(mnt.mnt_fstype, "ufs") &&
543 strcmp(mnt.mnt_fstype, "zfs"))))
544 #else
545 (strcmp(mnt.mnt_fstype, "ufs") != 0)
546 #endif
547 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
548 continue;
550 /* Skip this Partition? */
551 if (VIsNeverAttach(mnt.mnt_mountp))
552 continue;
554 /* If we're going to always attach this partition, do it later. */
555 if (VIsAlwaysAttach(mnt.mnt_mountp, NULL))
556 continue;
558 #ifndef AFS_NAMEI_ENV
559 if (hasmntopt(&mnt, "logging") != NULL) {
560 logging = 1;
562 #endif /* !AFS_NAMEI_ENV */
564 if (VCheckPartition(mnt.mnt_mountp, mnt.mnt_special, logging) < 0)
565 errors++;
568 (void)fclose(mntfile);
570 /* Process the always-attach partitions, if any. */
571 VAttachPartitions2();
573 return errors;
576 #endif /* AFS_SUN5_ENV */
577 #if defined(AFS_SGI_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_HPUX_ENV)
579 VAttachPartitions(void)
581 int errors = 0;
582 FILE *mfd;
583 struct mntent *mntent;
585 if ((mfd = setmntent(MOUNTED, "r")) == NULL) {
586 Log("Problems in getting mount entries(setmntent)\n");
587 exit(-1);
589 while (mntent = getmntent(mfd)) {
590 if (!hasmntopt(mntent, MNTOPT_RW))
591 continue;
593 /* Skip this Partition? */
594 if (VIsNeverAttach(mntent->mnt_dir))
595 continue;
597 /* If we're going to always attach this partition, do it later. */
598 if (VIsAlwaysAttach(mntent->mnt_dir, NULL))
599 continue;
601 if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname, 0) < 0)
602 errors++;
605 endmntent(mfd);
607 /* Process the always-attach partitions, if any. */
608 VAttachPartitions2();
610 return errors;
612 #endif
613 #ifdef AFS_AIX_ENV
615 * (This function was grabbed from df.c)
618 getmount(struct vmount **vmountpp)
620 int size;
621 struct vmount *vm;
622 int nmounts;
624 /* set initial size of mntctl buffer to a MAGIC NUMBER */
625 size = BUFSIZ;
627 /* try the operation until ok or a fatal error */
628 while (1) {
629 if ((vm = (struct vmount *)malloc(size)) == NULL) {
630 /* failed getting memory for mount status buf */
631 perror("FATAL ERROR: get_stat malloc failed\n");
632 exit(-1);
636 * perform the QUERY mntctl - if it returns > 0, that is the
637 * number of vmount structures in the buffer. If it returns
638 * -1, an error occured. If it returned 0, then look in
639 * first word of buffer for needed size.
641 if ((nmounts = mntctl(MCTL_QUERY, size, (caddr_t) vm)) > 0) {
642 /* OK, got it, now return */
643 *vmountpp = vm;
644 return (nmounts);
646 } else if (nmounts == 0) {
647 /* the buffer wasn't big enough .... */
648 /* .... get required buffer size */
649 size = *(int *)vm;
650 free(vm);
652 } else {
653 /* some other kind of error occurred */
654 free(vm);
655 return (-1);
661 VAttachPartitions(void)
663 int errors = 0;
664 int nmounts;
665 struct vmount *vmountp;
667 if ((nmounts = getmount(&vmountp)) <= 0) {
668 Log("Problems in getting # of mount entries(getmount)\n");
669 exit(-1);
671 for (; nmounts;
672 nmounts--, vmountp =
673 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
674 char *part = vmt2dataptr(vmountp, VMT_STUB);
676 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
677 continue; /* Ignore any "special" partitions */
679 #ifdef AFS_AIX42_ENV
680 #ifndef AFS_NAMEI_ENV
682 struct superblock fs;
683 /* The Log statements are non-sequiters in the SalvageLog and don't
684 * even appear in the VolserLog, so restrict them to the FileLog.
686 if (ReadSuper(&fs, vmt2dataptr(vmountp, VMT_OBJECT)) < 0) {
687 if (programType == fileServer)
688 Log("Can't read superblock for %s, ignoring it.\n", part);
689 continue;
691 if (IsBigFilesFileSystem(&fs)) {
692 if (programType == fileServer)
693 Log("%s is a big files filesystem, ignoring it.\n", part);
694 continue;
697 #endif
698 #endif
700 /* Skip this Partition? */
701 if (VIsNeverAttach(part))
702 continue;
704 /* If we're going to always attach this partition, do it later. */
705 if (VIsAlwaysAttach(part, NULL))
706 continue;
708 if (VCheckPartition(part, vmt2dataptr(vmountp, VMT_OBJECT), 0) < 0)
709 errors++;
712 /* Process the always-attach partitions, if any. */
713 VAttachPartitions2();
715 return errors;
717 #endif
718 #if defined(AFS_DUX40_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
720 VAttachPartitions(void)
722 int errors = 0;
723 struct fstab *fsent;
725 if (setfsent() < 0) {
726 Log("Error listing filesystems.\n");
727 exit(-1);
730 while ((fsent = getfsent())) {
731 if (strcmp(fsent->fs_type, "rw") != 0)
732 continue;
734 /* Skip this Partition? */
735 if (VIsNeverAttach(fsent->fs_file))
736 continue;
738 /* If we're going to always attach this partition, do it later. */
739 if (VIsAlwaysAttach(fsent->fs_file, NULL))
740 continue;
742 if (VCheckPartition(fsent->fs_file, fsent->fs_spec, 0) < 0)
743 errors++;
745 endfsent();
747 /* Process the always-attach partitions, if any. */
748 VAttachPartitions2();
750 return errors;
752 #endif
754 #ifdef AFS_NT40_ENV
755 #include <string.h>
756 #include <sys/stat.h>
757 /* VValidVPTEntry
759 * validate names in vptab.
761 * Return value:
762 * 1 valid entry
763 * 0 invalid entry
767 VValidVPTEntry(struct vptab *vpe)
769 int len = strlen(vpe->vp_name);
770 int i;
772 if (len < VICE_PREFIX_SIZE + 1 || len > VICE_PREFIX_SIZE + 2)
773 return 0;
774 if (strncmp(vpe->vp_name, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE))
775 return 0;
777 for (i = VICE_PREFIX_SIZE; i < len; i++) {
778 if (vpe->vp_name[i] < 'a' || vpe->vp_name[i] > 'z') {
779 Log("Invalid partition name %s in registry, ignoring it.\n",
780 vpe->vp_name);
781 return 0;
784 if (len == VICE_PREFIX_SIZE + 2) {
785 i = (int)(vpe->vp_name[VICE_PREFIX_SIZE] - 'a') * 26 +
786 (int)(vpe->vp_name[VICE_PREFIX_SIZE + 1] - 'a');
787 if (i > 255) {
788 Log("Invalid partition name %s in registry, ignoring it.\n",
789 vpe->vp_name);
790 return 0;
794 len = strlen(vpe->vp_dev);
795 if (len != 2 || vpe->vp_dev[1] != ':' || vpe->vp_dev[0] < 'A'
796 || vpe->vp_dev[0] > 'Z') {
797 Log("Invalid device name %s in registry, ignoring it.\n",
798 vpe->vp_dev);
799 return 0;
802 return 1;
806 VCheckPartition(char *partName)
808 char volRoot[4];
809 char volFsType[64];
810 DWORD dwDummy;
811 int err;
813 /* partName is presumed to be of the form "X:" */
814 (void)sprintf(volRoot, "%c:\\", *partName);
816 if (!GetVolumeInformation(volRoot, /* volume root directory */
817 NULL, /* volume name buffer */
818 0, /* volume name size */
819 NULL, /* volume serial number */
820 &dwDummy, /* max component length */
821 &dwDummy, /* file system flags */
822 volFsType, /* file system name */
823 sizeof(volFsType))) {
824 err = GetLastError();
825 Log("VCheckPartition: Failed to get partition information for %s, ignoring it.\n", partName);
826 return -1;
829 if (strcmp(volFsType, "NTFS")) {
830 Log("VCheckPartition: Partition %s is not an NTFS partition, ignoring it.\n", partName);
831 return -1;
834 return 0;
839 VAttachPartitions(void)
841 struct DiskPartition64 *partP, *prevP, *nextP;
842 struct vpt_iter iter;
843 struct vptab entry;
845 if (vpt_Start(&iter) < 0) {
846 Log("No partitions to attach.\n");
847 return 0;
850 while (0 == vpt_NextEntry(&iter, &entry)) {
851 if (!VValidVPTEntry(&entry)) {
852 continue;
855 /* This test for duplicates relies on the fact that the method
856 * of storing the partition names in the NT registry means the same
857 * partition name will never appear twice in the list.
859 for (partP = DiskPartitionList; partP; partP = partP->next) {
860 if (*partP->devName == *entry.vp_dev) {
861 Log("Same drive (%s) used for both partition %s and partition %s, ignoring both.\n", entry.vp_dev, partP->name, entry.vp_name);
862 partP->flags = PART_DUPLICATE;
863 break; /* Only one entry will ever be in this list. */
866 if (partP)
867 continue; /* found a duplicate */
869 if (VCheckPartition(entry.vp_dev) < 0)
870 continue;
871 /* This test allows for manually inserting the FORCESALVAGE flag
872 * and thereby invoking the salvager. scandisk obviously won't be
873 * doing this for us.
875 if (programType == fileServer) {
876 struct afs_stat status;
877 char salvpath[MAXPATHLEN];
878 strcpy(salvpath, entry.vp_dev);
879 strcat(salvpath, "\\FORCESALVAGE");
880 if (afs_stat(salvpath, &status) == 0) {
881 Log("VAttachPartitions: Found %s; aborting\n", salvpath);
882 exit(1);
885 VInitPartition(entry.vp_name, entry.vp_dev, *entry.vp_dev - 'A');
887 vpt_Finish(&iter);
889 /* Run through partition list and clear out the dupes. */
890 prevP = nextP = NULL;
891 for (partP = DiskPartitionList; partP; partP = nextP) {
892 nextP = partP->next;
893 if (partP->flags == PART_DUPLICATE) {
894 if (prevP)
895 prevP->next = partP->next;
896 else
897 DiskPartitionList = partP->next;
898 free(partP);
899 } else
900 prevP = partP;
903 return 0;
905 #endif
907 #ifdef AFS_LINUX22_ENV
909 VAttachPartitions(void)
911 int errors = 0;
912 FILE *mfd;
913 struct mntent *mntent;
915 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
916 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
917 Log("Problems in getting mount entries(setmntent)\n");
918 exit(-1);
921 while ((mntent = getmntent(mfd))) {
922 /* Skip this Partition? */
923 if (VIsNeverAttach(mntent->mnt_dir))
924 continue;
926 /* If we're going to always attach this partition, do it later. */
927 if (VIsAlwaysAttach(mntent->mnt_dir, NULL))
928 continue;
930 if (VCheckPartition(mntent->mnt_dir, mntent->mnt_fsname, 0) < 0)
931 errors++;
933 endmntent(mfd);
935 /* Process the always-attach partitions, if any. */
936 VAttachPartitions2();
938 return errors;
940 #endif /* AFS_LINUX22_ENV */
942 /* This routine is to be called whenever the actual name of the partition
943 * is required. The canonical name is still in part->name.
945 char *
946 VPartitionPath(struct DiskPartition64 *part)
948 #ifdef AFS_NT40_ENV
949 return part->devName;
950 #else
951 return part->name;
952 #endif
955 /* get partition structure, abortp tells us if we should abort on failure */
956 struct DiskPartition64 *
957 VGetPartition_r(char *name, int abortp)
959 struct DiskPartition64 *dp;
960 #ifdef AFS_DEMAND_ATTACH_FS
961 dp = VLookupPartition_r(name);
962 #else /* AFS_DEMAND_ATTACH_FS */
963 for (dp = DiskPartitionList; dp; dp = dp->next) {
964 if (strcmp(dp->name, name) == 0)
965 break;
967 #endif /* AFS_DEMAND_ATTACH_FS */
968 if (abortp)
969 osi_Assert(dp != NULL);
970 return dp;
973 struct DiskPartition64 *
974 VGetPartition(char *name, int abortp)
976 struct DiskPartition64 *retVal;
977 VOL_LOCK;
978 retVal = VGetPartition_r(name, abortp);
979 VOL_UNLOCK;
980 return retVal;
983 #ifdef AFS_NT40_ENV
984 void
985 VSetPartitionDiskUsage_r(struct DiskPartition64 *dp)
987 ULARGE_INTEGER free_user, total, free_total;
988 int ufree, tot, tfree;
990 if (!GetDiskFreeSpaceEx
991 (VPartitionPath(dp), &free_user, &total, &free_total)) {
992 printf("Failed to get disk space info for %s, error = %d\n", dp->name,
993 GetLastError());
994 return;
997 /* Convert to 1K units. */
998 ufree = (int)Int64ShraMod32(free_user.QuadPart, 10);
999 tot = (int)Int64ShraMod32(total.QuadPart, 10);
1000 tfree = (int)Int64ShraMod32(free_total.QuadPart, 10);
1002 dp->minFree = tfree - ufree; /* only used in VPrintDiskStats_r */
1003 dp->totalUsable = tot;
1004 dp->free = tfree;
1007 #else
1008 void
1009 VSetPartitionDiskUsage_r(struct DiskPartition64 *dp)
1011 int bsize, code;
1012 afs_int64 totalblks, free, used, availblks;
1013 int reserved;
1014 #ifdef afs_statvfs
1015 struct afs_statvfs statbuf;
1016 #else
1017 struct afs_statfs statbuf;
1018 #endif
1020 if (dp->flags & PART_DONTUPDATE)
1021 return;
1022 /* Note: we don't bother syncing because it's only an estimate, update
1023 * is syncing every 30 seconds anyway, we only have to keep the disk
1024 * approximately 10% from full--you just can't get the stuff in from
1025 * the net fast enough to worry */
1026 #ifdef afs_statvfs
1027 code = afs_statvfs(dp->name, &statbuf);
1028 #else
1029 code = afs_statfs(dp->name, &statbuf);
1030 #endif
1031 if (code < 0) {
1032 Log("statfs of %s failed in VSetPartitionDiskUsage (errno = %d)\n",
1033 dp->name, errno);
1034 return;
1036 if (statbuf.f_blocks == -1) { /* Undefined; skip stats.. */
1037 Log("statfs of %s failed in VSetPartitionDiskUsage\n", dp->name);
1038 return;
1040 totalblks = statbuf.f_blocks;
1041 free = statbuf.f_bfree;
1042 reserved = free - statbuf.f_bavail;
1043 #ifdef afs_statvfs
1044 bsize = statbuf.f_frsize;
1045 #else
1046 bsize = statbuf.f_bsize;
1047 #endif
1048 availblks = totalblks - reserved;
1049 dp->f_files = statbuf.f_files; /* max # of files in partition */
1051 /* Now free and totalblks are in fragment units, but we want them in
1052 * 1K units.
1054 if (bsize >= 1024) {
1055 free *= (bsize / 1024);
1056 totalblks *= (bsize / 1024);
1057 availblks *= (bsize / 1024);
1058 reserved *= (bsize / 1024);
1059 } else {
1060 free /= (1024 / bsize);
1061 totalblks /= (1024 / bsize);
1062 availblks /= (1024 / bsize);
1063 reserved /= (1024 / bsize);
1065 /* now compute remaining figures */
1066 used = totalblks - free;
1068 dp->minFree = reserved; /* only used in VPrintDiskStats_r */
1069 dp->totalUsable = availblks;
1070 dp->free = availblks - used; /* this is exactly f_bavail */
1072 #endif /* AFS_NT40_ENV */
1074 void
1075 VSetPartitionDiskUsage(struct DiskPartition64 *dp)
1077 VOL_LOCK;
1078 VSetPartitionDiskUsage_r(dp);
1079 VOL_UNLOCK;
1082 void
1083 VResetDiskUsage_r(void)
1085 struct DiskPartition64 *dp;
1086 for (dp = DiskPartitionList; dp; dp = dp->next) {
1087 VSetPartitionDiskUsage_r(dp);
1088 #ifndef AFS_PTHREAD_ENV
1089 IOMGR_Poll();
1090 #endif /* !AFS_PTHREAD_ENV */
1094 void
1095 VResetDiskUsage(void)
1097 VOL_LOCK;
1098 VResetDiskUsage_r();
1099 VOL_UNLOCK;
1102 void
1103 VAdjustDiskUsage_r(Error * ec, Volume * vp, afs_sfsize_t blocks,
1104 afs_sfsize_t checkBlocks)
1106 *ec = 0;
1107 /* why blocks instead of checkBlocks in the check below? Otherwise, any check
1108 * for less than BlocksSpare would skip the error-checking path, and we
1109 * could grow existing files forever, not just for another BlocksSpare
1110 * blocks. */
1111 if (blocks > 0) {
1112 #ifdef AFS_AIX32_ENV
1113 afs_int32 rem, minavail;
1115 if ((rem = vp->partition->free - checkBlocks) < (minavail =
1116 (vp->partition->
1117 totalUsable *
1118 aixlow_water) /
1119 100))
1120 #else
1121 if (vp->partition->free - checkBlocks < 0)
1122 #endif
1123 *ec = VDISKFULL;
1124 else if (V_maxquota(vp)
1125 && V_diskused(vp) + checkBlocks > V_maxquota(vp))
1126 *ec = VOVERQUOTA;
1128 vp->partition->free -= blocks;
1129 V_diskused(vp) += blocks;
1132 void
1133 VAdjustDiskUsage(Error * ec, Volume * vp, afs_sfsize_t blocks,
1134 afs_sfsize_t checkBlocks)
1136 VOL_LOCK;
1137 VAdjustDiskUsage_r(ec, vp, blocks, checkBlocks);
1138 VOL_UNLOCK;
1142 VDiskUsage_r(Volume * vp, afs_sfsize_t blocks)
1144 if (blocks > 0) {
1145 #ifdef AFS_AIX32_ENV
1146 afs_int32 rem, minavail;
1148 if ((rem = vp->partition->free - blocks) < (minavail =
1149 (vp->partition->
1150 totalUsable *
1151 aixlow_water) / 100))
1152 #else
1153 if (vp->partition->free - blocks < 0)
1154 #endif
1155 return (VDISKFULL);
1157 vp->partition->free -= blocks;
1158 return 0;
1162 VDiskUsage(Volume * vp, afs_sfsize_t blocks)
1164 int retVal;
1165 VOL_LOCK;
1166 retVal = VDiskUsage_r(vp, blocks);
1167 VOL_UNLOCK;
1168 return retVal;
1171 void
1172 VPrintDiskStats_r(void)
1174 struct DiskPartition64 *dp;
1175 for (dp = DiskPartitionList; dp; dp = dp->next) {
1176 if (dp->free < 0) {
1177 Log("Partition %s: %"AFS_INT64_FMT
1178 " available 1K blocks (minfree=%"AFS_INT64_FMT"), "
1179 "overallocated by %"AFS_INT64_FMT" blocks\n", dp->name,
1180 dp->totalUsable, dp->minFree, -dp->free);
1181 } else {
1182 Log("Partition %s: %"AFS_INT64_FMT
1183 " available 1K blocks (minfree=%"AFS_INT64_FMT"), "
1184 "%"AFS_INT64_FMT" free blocks\n", dp->name,
1185 dp->totalUsable, dp->minFree, dp->free);
1190 void
1191 VPrintDiskStats(void)
1193 VOL_LOCK;
1194 VPrintDiskStats_r();
1195 VOL_UNLOCK;
1198 #ifdef AFS_NT40_ENV
1199 /* Need a separate lock file on NT, since NT only has mandatory file locks. */
1200 #define LOCKFILE "LOCKFILE"
1201 void
1202 VLockPartition_r(char *name)
1204 struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1205 OVERLAPPED lap;
1207 if (!dp)
1208 return;
1209 if (dp->lock_fd == INVALID_FD) {
1210 char path[64];
1211 int rc;
1212 (void)sprintf(path, "%s\\%s", VPartitionPath(dp), LOCKFILE);
1213 dp->lock_fd =
1214 (FD_t)CreateFile(path, GENERIC_WRITE,
1215 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
1216 CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
1217 osi_Assert(dp->lock_fd != INVALID_FD);
1219 memset(&lap, 0, sizeof(lap));
1220 rc = LockFileEx((HANDLE) dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1,
1221 0, &lap);
1222 osi_Assert(rc);
1226 void
1227 VUnlockPartition_r(char *name)
1229 struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1230 OVERLAPPED lap;
1232 if (!dp)
1233 return; /* no partition, will fail later */
1234 memset(&lap, 0, sizeof(lap));
1236 UnlockFileEx((HANDLE) dp->lock_fd, 0, 1, 0, &lap);
1237 CloseHandle((HANDLE) dp->lock_fd);
1238 dp->lock_fd = INVALID_FD;
1240 #else /* AFS_NT40_ENV */
1242 #if defined(AFS_HPUX_ENV)
1243 #define BITS_PER_CHAR (8)
1244 #define BITS(type) (sizeof(type) * BITS_PER_CHAR)
1246 #define LOCKRDONLY_OFFSET ((PRIV_LOCKRDONLY - 1) / BITS(int))
1247 #endif /* defined(AFS_HPUX_ENV) */
1249 void
1250 VLockPartition_r(char *name)
1252 struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1253 char *partitionName;
1254 int retries, code;
1255 struct timeval pausing;
1256 #if defined(AFS_HPUX_ENV)
1257 int lockfRtn;
1258 struct privgrp_map privGrpList[PRIV_MAXGRPS];
1259 unsigned int *globalMask;
1260 int globalMaskIndex;
1261 #endif /* defined(AFS_HPUX_ENV) */
1262 #if defined(AFS_DARWIN_ENV)
1263 char lockfile[MAXPATHLEN];
1264 #endif /* defined(AFS_DARWIN_ENV) */
1265 #ifdef AFS_NAMEI_ENV
1266 #ifdef AFS_AIX42_ENV
1267 char LockFileName[MAXPATHLEN + 1];
1269 sprintf((char *)&LockFileName, "%s/AFSINODE_FSLock", name);
1270 partitionName = (char *)&LockFileName;
1271 #endif
1272 #endif
1274 if (!dp)
1275 return; /* no partition, will fail later */
1276 if (dp->lock_fd != INVALID_FD)
1277 return;
1279 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
1280 #if !defined(AFS_AIX42_ENV) || !defined(AFS_NAMEI_ENV)
1281 partitionName = dp->devName;
1282 #endif
1283 code = O_RDWR;
1284 #elif defined(AFS_DARWIN_ENV)
1285 strlcpy((partitionName = lockfile), dp->name, sizeof(lockfile));
1286 strlcat(lockfile, "/.lock.afs", sizeof(lockfile));
1287 code = O_RDONLY | O_CREAT;
1288 #else
1289 partitionName = dp->name;
1290 code = O_RDONLY;
1291 #endif
1293 for (retries = 25; retries; retries--) {
1294 if (code & O_CREAT)
1295 dp->lock_fd = afs_open(partitionName, code, 0644);
1296 else
1297 dp->lock_fd = afs_open(partitionName, code);
1299 if (dp->lock_fd != INVALID_FD)
1300 break;
1301 if (errno == ENOENT)
1302 code |= O_CREAT;
1303 pausing.tv_sec = 0;
1304 pausing.tv_usec = 500000;
1305 select(0, NULL, NULL, NULL, &pausing);
1307 osi_Assert(retries != 0);
1309 #if defined (AFS_HPUX_ENV)
1311 osi_Assert(getprivgrp(privGrpList) == 0);
1314 * In general, it will difficult and time-consuming ,if not impossible,
1315 * to try to find the privgroup to which this process belongs that has the
1316 * smallest membership, to minimise the security hole. So, we use the privgrp
1317 * to which everybody belongs.
1319 /* first, we have to find the global mask */
1320 for (globalMaskIndex = 0; globalMaskIndex < PRIV_MAXGRPS;
1321 globalMaskIndex++) {
1322 if (privGrpList[globalMaskIndex].priv_groupno == PRIV_GLOBAL) {
1323 globalMask =
1324 &(privGrpList[globalMaskIndex].priv_mask[LOCKRDONLY_OFFSET]);
1325 break;
1329 if (((*globalMask) & privmask(PRIV_LOCKRDONLY)) == 0) {
1330 /* allow everybody to set a lock on a read-only file descriptor */
1331 (*globalMask) |= privmask(PRIV_LOCKRDONLY);
1332 osi_Assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask)
1333 == 0);
1335 lockfRtn = lockf(dp->lock_fd, F_LOCK, 0);
1337 /* remove the privilege granted to everybody to lock a read-only fd */
1338 (*globalMask) &= ~(privmask(PRIV_LOCKRDONLY));
1339 osi_Assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask)
1340 == 0);
1341 } else {
1342 /* in this case, we should be able to do this with impunity, anyway */
1343 lockfRtn = lockf(dp->lock_fd, F_LOCK, 0);
1346 osi_Assert(lockfRtn != -1);
1347 #else
1348 #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
1349 osi_Assert(lockf(dp->lock_fd, F_LOCK, 0) != -1);
1350 #else
1351 osi_Assert(flock(dp->lock_fd, LOCK_EX) == 0);
1352 #endif /* defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) */
1353 #endif
1356 void
1357 VUnlockPartition_r(char *name)
1359 struct DiskPartition64 *dp = VGetPartition_r(name, 0);
1360 if (!dp)
1361 return; /* no partition, will fail later */
1362 close(dp->lock_fd);
1363 dp->lock_fd = INVALID_FD;
1366 #endif /* AFS_NT40_ENV */
1368 void
1369 VLockPartition(char *name)
1371 VOL_LOCK;
1372 VLockPartition_r(name);
1373 VOL_UNLOCK;
1376 void
1377 VUnlockPartition(char *name)
1379 VOL_LOCK;
1380 VUnlockPartition_r(name);
1381 VOL_UNLOCK;
1384 #ifdef AFS_DEMAND_ATTACH_FS
1386 /* new-style partition locks; these are only to have some mutual exclusion
1387 * between the VGC scanner and volume utilies creating/altering vol headers
1391 * lock a partition's vol headers.
1393 * @param[in] dp the partition to lock
1394 * @param[in] locktype READ_LOCK or WRITE_LOCK
1396 * @return operation status
1397 * @retval 0 success
1400 VPartHeaderLock(struct DiskPartition64 *dp, int locktype)
1402 int code;
1404 /* block on acquiring the lock */
1405 int nonblock = 0;
1407 code = VGetDiskLock(&dp->headerLock, locktype, nonblock);
1408 if (code) {
1409 Log("VPartHeaderLock: error %d locking partititon %s\n", code,
1410 VPartitionPath(dp));
1412 return code;
1416 * unlock a partition's vol headers.
1418 * @param[in] dp the partition to unlock
1419 * @param[in] locktype READ_LOCK or WRITE_LOCK
1421 void
1422 VPartHeaderUnlock(struct DiskPartition64 *dp, int locktype)
1424 VReleaseDiskLock(&dp->headerLock, locktype);
1427 /* XXX not sure this will work on AFS_NT40_ENV
1428 * needs to be tested!
1432 * lookup a disk partition object by its index number.
1434 * @param[in] id partition index number
1435 * @param[in] abortp see abortp usage note below
1437 * @return disk partition object
1438 * @retval NULL no such disk partition
1440 * @note when abortp is non-zero, lookups which would return
1441 * NULL will result in an assertion failure
1443 * @pre VOL_LOCK must be held
1445 * @internal volume package internal use only
1448 struct DiskPartition64 *
1449 VGetPartitionById_r(afs_int32 id, int abortp)
1451 struct DiskPartition64 *dp = NULL;
1453 if ((id >= 0) && (id <= VOLMAXPARTS)) {
1454 dp = DiskPartitionTable[id];
1457 if (abortp) {
1458 osi_Assert(dp != NULL);
1460 return dp;
1464 * lookup a disk partition object by its index number.
1466 * @param[in] id partition index number
1467 * @param[in] abortp see abortp usage note below
1469 * @return disk partition object
1470 * @retval NULL no such disk partition
1472 * @note when abortp is non-zero, lookups which would return
1473 * NULL will result in an assertion failure
1476 struct DiskPartition64 *
1477 VGetPartitionById(afs_int32 id, int abortp)
1479 struct DiskPartition64 * dp;
1481 VOL_LOCK;
1482 dp = VGetPartitionById_r(id, abortp);
1483 VOL_UNLOCK;
1485 return dp;
1488 static struct DiskPartition64 *
1489 VLookupPartition_r(char * path)
1491 afs_int32 id = volutil_GetPartitionID(path);
1493 if (id < 0 || id > VOLMAXPARTS)
1494 return NULL;
1496 return DiskPartitionTable[id];
1499 static void
1500 AddPartitionToTable_r(struct DiskPartition64 *dp)
1502 osi_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
1503 DiskPartitionTable[dp->index] = dp;
1506 #if 0
1507 static void
1508 DeletePartitionFromTable_r(struct DiskPartition64 *dp)
1510 osi_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS);
1511 DiskPartitionTable[dp->index] = NULL;
1513 #endif
1514 #endif /* AFS_DEMAND_ATTACH_FS */