2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <afs/afsint.h>
20 #if !defined(AFS_SGI_ENV)
23 #else /* AFS_OSF_ENV */
24 #ifdef AFS_VFSINCL_ENV
27 #include <sys/fs/ufs_fs.h>
29 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
30 #include <ufs/ufs/dinode.h>
31 #include <ufs/ffs/fs.h>
36 #else /* AFS_VFSINCL_ENV */
37 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_DARWIN_ENV)
40 #endif /* AFS_VFSINCL_ENV */
41 #endif /* AFS_OSF_ENV */
42 #endif /* AFS_SGI_ENV */
50 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
52 #include <sys/mnttab.h>
53 #include <sys/mntent.h>
58 #if defined(AFS_SGI_ENV)
61 #ifdef AFS_LINUX22_ENV
67 #endif /* AFS_SGI_ENV */
68 #endif /* AFS_HPUX_ENV */
74 #include "partition.h"
76 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
77 * returns pointer to static storage; copy it out quickly!
80 vol_DevName(dev_t adev, char *wpath)
82 static char pbuffer[128];
88 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
89 struct mntent *mntent;
97 struct vmount *vmountp;
101 if ((nmounts = getmount(&vmountp)) <= 0) {
106 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
107 char *part = vmt2dataptr(vmountp, VMT_STUB);
110 if (!(mntfile = fopen(MNTTAB, "r"))) {
113 while (!getmntent(mntfile, &mnt)) {
114 char *part = mnt.mnt_mountp;
116 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
117 #ifdef AFS_LINUX22_ENV
118 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
119 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
124 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
128 while ((mntent = getmntent(mfd))) {
129 char *part = mntent->mnt_dir;
132 while ((fsent = getfsent())) {
133 char *part = fsent->fs_file;
135 #endif /* AFS_SGI_ENV */
139 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
140 continue; /* Ignore any "special" partitions */
143 /* Ignore non ufs or non read/write partitions */
144 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
145 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
148 #if defined(AFS_LINUX22_ENV)
149 if (strcmp(mntent->mnt_type, "ext2"))
152 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
153 if (!hasmntopt(mntent, MNTOPT_RW))
156 if (strcmp(fsent->fs_type, "rw") != 0)
157 continue; /* Ignore non read/write partitions */
158 #endif /* AFS_LINUX22_ENV */
159 #endif /* AFS_SGI_ENV */
162 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
163 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
164 continue; /* Non /vicepx; ignore */
166 if (stat(part, &status) == -1) {
169 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV)
170 if ((status.st_ino !=
171 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
175 if (status.st_dev == adev) {
177 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
180 strcpy(pbuffer, mnt.mnt_special);
182 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
183 strcpy(pbuffer, mntent->mnt_fsname);
185 strcpy(pbuffer, fsent->fs_spec);
187 #endif /* AFS_SGI_ENV */
190 strcpy(pbuf, pbuffer);
191 ptr = (char *)strrchr(pbuf, OS_DIRSEPC);
198 ptr = (char *)strrchr(pbuffer, OS_DIRSEPC);
200 strcpy(pbuffer, ptr + 1);
207 (void)fclose(mntfile);
209 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
216 #endif /* AFS_SGI_ENV */
220 /* Search for the raw device name. Will put an "r" in front of each
221 * directory and file entry of the pathname until we find a character
225 afs_rawname(char *devfile)
227 static char rawname[100];
233 strcpy(rawname, devfile);
234 if (devfile[i] == OS_DIRSEPC) {
235 rawname[i + 1] = 'r';
237 strcat(rawname, &devfile[i + 1]);
240 code = stat(rawname, &statbuf);
241 if (!code && S_ISCHR(statbuf.st_mode))
244 while ((--i >= 0) && (devfile[i] != OS_DIRSEPC));