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 <rx/rx_queue.h>
19 #include <afs/afsint.h>
21 #if !defined(AFS_SGI_ENV)
22 #ifdef AFS_VFSINCL_ENV
25 #include <sys/fs/ufs_fs.h>
27 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
28 #include <ufs/ufs/dinode.h>
29 #include <ufs/ffs/fs.h>
34 #else /* AFS_VFSINCL_ENV */
35 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_DARWIN_ENV)
38 #endif /* AFS_VFSINCL_ENV */
39 #endif /* AFS_SGI_ENV */
47 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
49 #include <sys/mnttab.h>
50 #include <sys/mntent.h>
55 #if defined(AFS_SGI_ENV)
58 #ifdef AFS_LINUX22_ENV
64 #endif /* AFS_SGI_ENV */
65 #endif /* AFS_HPUX_ENV */
71 #include "partition.h"
73 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
74 * returns pointer to static storage; copy it out quickly!
77 vol_DevName(dev_t adev, char *wpath)
79 static char pbuffer[128];
85 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
86 struct mntent *mntent;
94 struct vmount *vmountp;
98 if ((nmounts = getmount(&vmountp)) <= 0) {
103 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
104 char *part = vmt2dataptr(vmountp, VMT_STUB);
107 if (!(mntfile = fopen(MNTTAB, "r"))) {
110 while (!getmntent(mntfile, &mnt)) {
111 char *part = mnt.mnt_mountp;
113 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
114 #ifdef AFS_LINUX22_ENV
115 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
116 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
121 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
125 while ((mntent = getmntent(mfd))) {
126 char *part = mntent->mnt_dir;
129 while ((fsent = getfsent())) {
130 char *part = fsent->fs_file;
132 #endif /* AFS_SGI_ENV */
136 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
137 continue; /* Ignore any "special" partitions */
140 /* Ignore non ufs or non read/write partitions */
141 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
142 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
145 #if defined(AFS_LINUX22_ENV)
146 if (strcmp(mntent->mnt_type, "ext2"))
149 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
150 if (!hasmntopt(mntent, MNTOPT_RW))
153 if (strcmp(fsent->fs_type, "rw") != 0)
154 continue; /* Ignore non read/write partitions */
155 #endif /* AFS_LINUX22_ENV */
156 #endif /* AFS_SGI_ENV */
159 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
160 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
161 continue; /* Non /vicepx; ignore */
163 if (stat(part, &status) == -1) {
166 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV)
167 if ((status.st_ino !=
168 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
172 if (status.st_dev == adev) {
174 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
177 strcpy(pbuffer, mnt.mnt_special);
179 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
180 strcpy(pbuffer, mntent->mnt_fsname);
182 strcpy(pbuffer, fsent->fs_spec);
184 #endif /* AFS_SGI_ENV */
187 strcpy(pbuf, pbuffer);
188 ptr = (char *)strrchr(pbuf, OS_DIRSEPC);
195 ptr = (char *)strrchr(pbuffer, OS_DIRSEPC);
197 strcpy(pbuffer, ptr + 1);
204 (void)fclose(mntfile);
206 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
213 #endif /* AFS_SGI_ENV */
217 /* Search for the raw device name. Will put an "r" in front of each
218 * directory and file entry of the pathname until we find a character
222 afs_rawname(char *devfile)
224 static char rawname[100];
230 strcpy(rawname, devfile);
231 if (devfile[i] == OS_DIRSEPC) {
232 rawname[i + 1] = 'r';
234 strcat(rawname, &devfile[i + 1]);
237 code = stat(rawname, &statbuf);
238 if (!code && S_ISCHR(statbuf.st_mode))
241 while ((--i >= 0) && (devfile[i] != OS_DIRSEPC));