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)
68 #ifdef AFS_SGI_EFS_IOPS_ENV
69 #define ROOTINO EFS_ROOTINO
70 #include "sgiefs/efs.h"
73 #ifdef AFS_LINUX22_ENV
79 #endif /* AFS_SGI_ENV */
80 #endif /* AFS_HPUX_ENV */
83 #include <netinet/in.h>
88 #endif /* ITIMER_REAL */
89 #include "partition.h"
91 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
92 * returns pointer to static storage; copy it out quickly!
95 vol_DevName(dev_t adev, char *wpath)
97 static char pbuffer[128];
104 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
105 struct mntent *mntent;
113 struct vmount *vmountp;
117 if ((nmounts = getmount(&vmountp)) <= 0) {
122 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
123 char *part = vmt2dataptr(vmountp, VMT_STUB);
126 if (!(mntfile = fopen(MNTTAB, "r"))) {
129 while (!getmntent(mntfile, &mnt)) {
130 char *part = mnt.mnt_mountp;
132 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
133 #ifdef AFS_LINUX22_ENV
134 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
135 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
140 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
144 while ((mntent = getmntent(mfd))) {
145 char *part = mntent->mnt_dir;
148 while ((fsent = getfsent())) {
149 char *part = fsent->fs_file;
151 #endif /* AFS_SGI_ENV */
155 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
156 continue; /* Ignore any "special" partitions */
159 /* Ignore non ufs or non read/write partitions */
160 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
161 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
164 #if defined(AFS_LINUX22_ENV)
165 if (strcmp(mntent->mnt_type, "ext2"))
168 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
169 if (!hasmntopt(mntent, MNTOPT_RW))
172 if (strcmp(fsent->fs_type, "rw") != 0)
173 continue; /* Ignore non read/write partitions */
174 #endif /* AFS_LINUX22_ENV */
175 #endif /* AFS_SGI_ENV */
178 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
179 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
180 continue; /* Non /vicepx; ignore */
182 if (stat(part, &status) == -1) {
185 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV)
186 if ((status.st_ino !=
187 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
191 if (status.st_dev == adev) {
193 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
196 strcpy(pbuffer, mnt.mnt_special);
198 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
199 strcpy(pbuffer, mntent->mnt_fsname);
201 strcpy(pbuffer, fsent->fs_spec);
203 #endif /* AFS_SGI_ENV */
206 strcpy(pbuf, pbuffer);
207 ptr = (char *)strrchr(pbuf, '/');
214 ptr = (char *)strrchr(pbuffer, '/');
216 strcpy(pbuffer, ptr + 1);
223 (void)fclose(mntfile);
225 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
232 #endif /* AFS_SGI_ENV */
236 /* Search for the raw device name. Will put an "r" in front of each
237 * directory and file entry of the pathname until we find a character
241 afs_rawname(char *devfile)
243 static char rawname[100];
250 strcpy(rawname, devfile);
251 if (devfile[i] == '/') {
252 rawname[i + 1] = 'r';
254 strcat(rawname, &devfile[i + 1]);
257 code = stat(rawname, &statbuf);
258 if (!code && S_ISCHR(statbuf.st_mode))
261 while ((--i >= 0) && (devfile[i] != '/'));