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>
14 #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 */
42 #include <sys/errno.h>
43 #include <sys/types.h>
55 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
57 #include <sys/mnttab.h>
58 #include <sys/mntent.h>
63 #if defined(AFS_SGI_ENV)
67 #ifdef AFS_LINUX22_ENV
73 #endif /* AFS_SGI_ENV */
74 #endif /* AFS_HPUX_ENV */
77 #include <netinet/in.h>
82 #endif /* ITIMER_REAL */
84 #include "partition.h"
86 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
87 * returns pointer to static storage; copy it out quickly!
90 vol_DevName(dev_t adev, char *wpath)
92 static char pbuffer[128];
98 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
99 struct mntent *mntent;
107 struct vmount *vmountp;
111 if ((nmounts = getmount(&vmountp)) <= 0) {
116 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
117 char *part = vmt2dataptr(vmountp, VMT_STUB);
120 if (!(mntfile = fopen(MNTTAB, "r"))) {
123 while (!getmntent(mntfile, &mnt)) {
124 char *part = mnt.mnt_mountp;
126 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
127 #ifdef AFS_LINUX22_ENV
128 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
129 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
134 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
138 while ((mntent = getmntent(mfd))) {
139 char *part = mntent->mnt_dir;
142 while ((fsent = getfsent())) {
143 char *part = fsent->fs_file;
145 #endif /* AFS_SGI_ENV */
149 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
150 continue; /* Ignore any "special" partitions */
153 /* Ignore non ufs or non read/write partitions */
154 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
155 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
158 #if defined(AFS_LINUX22_ENV)
159 if (strcmp(mntent->mnt_type, "ext2"))
162 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
163 if (!hasmntopt(mntent, MNTOPT_RW))
166 if (strcmp(fsent->fs_type, "rw") != 0)
167 continue; /* Ignore non read/write partitions */
168 #endif /* AFS_LINUX22_ENV */
169 #endif /* AFS_SGI_ENV */
172 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
173 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
174 continue; /* Non /vicepx; ignore */
176 if (stat(part, &status) == -1) {
179 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_ARM_DARWIN_ENV)
180 if ((status.st_ino !=
181 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
185 if (status.st_dev == adev) {
187 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
190 strcpy(pbuffer, mnt.mnt_special);
192 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
193 strcpy(pbuffer, mntent->mnt_fsname);
195 strcpy(pbuffer, fsent->fs_spec);
197 #endif /* AFS_SGI_ENV */
200 strcpy(pbuf, pbuffer);
201 ptr = (char *)strrchr(pbuf, OS_DIRSEPC);
208 ptr = (char *)strrchr(pbuffer, OS_DIRSEPC);
210 strcpy(pbuffer, ptr + 1);
217 (void)fclose(mntfile);
219 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
226 #endif /* AFS_SGI_ENV */
230 /* Search for the raw device name. Will put an "r" in front of each
231 * directory and file entry of the pathname until we find a character
235 afs_rawname(char *devfile)
237 static char rawname[100];
243 strcpy(rawname, devfile);
244 if (devfile[i] == OS_DIRSEPC) {
245 rawname[i + 1] = 'r';
247 strcat(rawname, &devfile[i + 1]);
250 code = stat(rawname, &statbuf);
251 if (!code && S_ISCHR(statbuf.st_mode))
254 while ((--i >= 0) && (devfile[i] != OS_DIRSEPC));