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)
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_LINUX20_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_DARWIN_ENV)
41 #endif /* AFS_VFSINCL_ENV */
42 #endif /* AFS_OSF_ENV */
43 #endif /* AFS_SGI_ENV */
51 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
53 #include <sys/mnttab.h>
54 #include <sys/mntent.h>
59 #if defined(AFS_SGI_ENV)
62 #ifdef AFS_LINUX22_ENV
68 #endif /* AFS_SGI_ENV */
69 #endif /* AFS_HPUX_ENV */
75 #include "partition.h"
77 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
78 * returns pointer to static storage; copy it out quickly!
81 vol_DevName(dev_t adev, char *wpath)
83 static char pbuffer[128];
89 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
90 struct mntent *mntent;
98 struct vmount *vmountp;
102 if ((nmounts = getmount(&vmountp)) <= 0) {
107 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
108 char *part = vmt2dataptr(vmountp, VMT_STUB);
111 if (!(mntfile = fopen(MNTTAB, "r"))) {
114 while (!getmntent(mntfile, &mnt)) {
115 char *part = mnt.mnt_mountp;
117 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
118 #ifdef AFS_LINUX22_ENV
119 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
120 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
125 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
129 while ((mntent = getmntent(mfd))) {
130 char *part = mntent->mnt_dir;
133 while ((fsent = getfsent())) {
134 char *part = fsent->fs_file;
136 #endif /* AFS_SGI_ENV */
140 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
141 continue; /* Ignore any "special" partitions */
144 /* Ignore non ufs or non read/write partitions */
145 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
146 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
149 #if defined(AFS_LINUX22_ENV)
150 if (strcmp(mntent->mnt_type, "ext2"))
153 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
154 if (!hasmntopt(mntent, MNTOPT_RW))
157 if (strcmp(fsent->fs_type, "rw") != 0)
158 continue; /* Ignore non read/write partitions */
159 #endif /* AFS_LINUX22_ENV */
160 #endif /* AFS_SGI_ENV */
163 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
164 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
165 continue; /* Non /vicepx; ignore */
167 if (stat(part, &status) == -1) {
170 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV)
171 if ((status.st_ino !=
172 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
176 if (status.st_dev == adev) {
178 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
181 strcpy(pbuffer, mnt.mnt_special);
183 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
184 strcpy(pbuffer, mntent->mnt_fsname);
186 strcpy(pbuffer, fsent->fs_spec);
188 #endif /* AFS_SGI_ENV */
191 strcpy(pbuf, pbuffer);
192 ptr = (char *)strrchr(pbuf, OS_DIRSEPC);
199 ptr = (char *)strrchr(pbuffer, OS_DIRSEPC);
201 strcpy(pbuffer, ptr + 1);
208 (void)fclose(mntfile);
210 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
217 #endif /* AFS_SGI_ENV */
221 /* Search for the raw device name. Will put an "r" in front of each
222 * directory and file entry of the pathname until we find a character
226 afs_rawname(char *devfile)
228 static char rawname[100];
234 strcpy(rawname, devfile);
235 if (devfile[i] == OS_DIRSEPC) {
236 rawname[i + 1] = 'r';
238 strcat(rawname, &devfile[i + 1]);
241 code = stat(rawname, &statbuf);
242 if (!code && S_ISCHR(statbuf.st_mode))
245 while ((--i >= 0) && (devfile[i] != OS_DIRSEPC));