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>
16 #include <afs/afsint.h>
19 #if !defined(AFS_SGI_ENV)
22 #else /* AFS_OSF_ENV */
23 #ifdef AFS_VFSINCL_ENV
26 #include <sys/fs/ufs_fs.h>
28 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
29 #include <ufs/ufs/dinode.h>
30 #include <ufs/ffs/fs.h>
35 #else /* AFS_VFSINCL_ENV */
36 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_ARM_DARWIN_ENV)
39 #endif /* AFS_VFSINCL_ENV */
40 #endif /* AFS_OSF_ENV */
41 #endif /* AFS_SGI_ENV */
49 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
51 #include <sys/mnttab.h>
52 #include <sys/mntent.h>
57 #if defined(AFS_SGI_ENV)
60 #ifdef AFS_LINUX22_ENV
66 #endif /* AFS_SGI_ENV */
67 #endif /* AFS_HPUX_ENV */
73 #include "partition.h"
75 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
76 * returns pointer to static storage; copy it out quickly!
79 vol_DevName(dev_t adev, char *wpath)
81 static char pbuffer[128];
87 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
88 struct mntent *mntent;
96 struct vmount *vmountp;
100 if ((nmounts = getmount(&vmountp)) <= 0) {
105 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
106 char *part = vmt2dataptr(vmountp, VMT_STUB);
109 if (!(mntfile = fopen(MNTTAB, "r"))) {
112 while (!getmntent(mntfile, &mnt)) {
113 char *part = mnt.mnt_mountp;
115 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
116 #ifdef AFS_LINUX22_ENV
117 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
118 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
123 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
127 while ((mntent = getmntent(mfd))) {
128 char *part = mntent->mnt_dir;
131 while ((fsent = getfsent())) {
132 char *part = fsent->fs_file;
134 #endif /* AFS_SGI_ENV */
138 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
139 continue; /* Ignore any "special" partitions */
142 /* Ignore non ufs or non read/write partitions */
143 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
144 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
147 #if defined(AFS_LINUX22_ENV)
148 if (strcmp(mntent->mnt_type, "ext2"))
151 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
152 if (!hasmntopt(mntent, MNTOPT_RW))
155 if (strcmp(fsent->fs_type, "rw") != 0)
156 continue; /* Ignore non read/write partitions */
157 #endif /* AFS_LINUX22_ENV */
158 #endif /* AFS_SGI_ENV */
161 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
162 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
163 continue; /* Non /vicepx; ignore */
165 if (stat(part, &status) == -1) {
168 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_ARM_DARWIN_ENV)
169 if ((status.st_ino !=
170 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
174 if (status.st_dev == adev) {
176 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
179 strcpy(pbuffer, mnt.mnt_special);
181 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
182 strcpy(pbuffer, mntent->mnt_fsname);
184 strcpy(pbuffer, fsent->fs_spec);
186 #endif /* AFS_SGI_ENV */
189 strcpy(pbuf, pbuffer);
190 ptr = (char *)strrchr(pbuf, OS_DIRSEPC);
197 ptr = (char *)strrchr(pbuffer, OS_DIRSEPC);
199 strcpy(pbuffer, ptr + 1);
206 (void)fclose(mntfile);
208 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
215 #endif /* AFS_SGI_ENV */
219 /* Search for the raw device name. Will put an "r" in front of each
220 * directory and file entry of the pathname until we find a character
224 afs_rawname(char *devfile)
226 static char rawname[100];
232 strcpy(rawname, devfile);
233 if (devfile[i] == OS_DIRSEPC) {
234 rawname[i + 1] = 'r';
236 strcat(rawname, &devfile[i + 1]);
239 code = stat(rawname, &statbuf);
240 if (!code && S_ISCHR(statbuf.st_mode))
243 while ((--i >= 0) && (devfile[i] != OS_DIRSEPC));