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 <sys/param.h>
11 #include <afsconfig.h>
16 #include <afs/param.h>
18 #include <afs/afsint.h>
21 #if !defined(AFS_SGI_ENV)
24 #else /* AFS_OSF_ENV */
25 #ifdef AFS_VFSINCL_ENV
28 #include <sys/fs/ufs_fs.h>
30 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
31 #include <ufs/ufs/dinode.h>
32 #include <ufs/ffs/fs.h>
37 #else /* AFS_VFSINCL_ENV */
38 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_XBSD_ENV)
41 #endif /* AFS_VFSINCL_ENV */
42 #endif /* AFS_OSF_ENV */
43 #endif /* AFS_SGI_ENV */
44 #include <sys/errno.h>
45 #include <sys/types.h>
57 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
59 #include <sys/mnttab.h>
60 #include <sys/mntent.h>
65 #if defined(AFS_SGI_ENV)
69 #ifdef AFS_LINUX22_ENV
75 #endif /* AFS_SGI_ENV */
76 #endif /* AFS_HPUX_ENV */
79 #include <netinet/in.h>
84 #endif /* ITIMER_REAL */
85 #include "partition.h"
87 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
88 * returns pointer to static storage; copy it out quickly!
91 vol_DevName(dev_t adev, char *wpath)
93 static char pbuffer[128];
100 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
101 struct mntent *mntent;
109 struct vmount *vmountp;
113 if ((nmounts = getmount(&vmountp)) <= 0) {
118 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
119 char *part = vmt2dataptr(vmountp, VMT_STUB);
122 if (!(mntfile = fopen(MNTTAB, "r"))) {
125 while (!getmntent(mntfile, &mnt)) {
126 char *part = mnt.mnt_mountp;
128 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
129 #ifdef AFS_LINUX22_ENV
130 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
131 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
136 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
140 while ((mntent = getmntent(mfd))) {
141 char *part = mntent->mnt_dir;
144 while ((fsent = getfsent())) {
145 char *part = fsent->fs_file;
147 #endif /* AFS_SGI_ENV */
151 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
152 continue; /* Ignore any "special" partitions */
155 /* Ignore non ufs or non read/write partitions */
156 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
157 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
160 #if defined(AFS_LINUX22_ENV)
161 if (strcmp(mntent->mnt_type, "ext2"))
164 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
165 if (!hasmntopt(mntent, MNTOPT_RW))
168 if (strcmp(fsent->fs_type, "rw") != 0)
169 continue; /* Ignore non read/write partitions */
170 #endif /* AFS_LINUX22_ENV */
171 #endif /* AFS_SGI_ENV */
174 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
175 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
176 continue; /* Non /vicepx; ignore */
178 if (stat(part, &status) == -1) {
181 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV)
182 if ((status.st_ino !=
183 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
187 if (status.st_dev == adev) {
189 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
192 strcpy(pbuffer, mnt.mnt_special);
194 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
195 strcpy(pbuffer, mntent->mnt_fsname);
197 strcpy(pbuffer, fsent->fs_spec);
199 #endif /* AFS_SGI_ENV */
202 strcpy(pbuf, pbuffer);
203 ptr = (char *)strrchr(pbuf, '/');
210 ptr = (char *)strrchr(pbuffer, '/');
212 strcpy(pbuffer, ptr + 1);
219 (void)fclose(mntfile);
221 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
228 #endif /* AFS_SGI_ENV */
232 /* Search for the raw device name. Will put an "r" in front of each
233 * directory and file entry of the pathname until we find a character
237 afs_rawname(char *devfile)
239 static char rawname[100];
246 strcpy(rawname, devfile);
247 if (devfile[i] == '/') {
248 rawname[i + 1] = 'r';
250 strcat(rawname, &devfile[i + 1]);
253 code = stat(rawname, &statbuf);
254 if (!code && S_ISCHR(statbuf.st_mode))
257 while ((--i >= 0) && (devfile[i] != '/'));