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>
20 #if !defined(AFS_SGI_ENV)
23 #else /* AFS_OSF_ENV */
24 #ifdef AFS_VFSINCL_ENV
27 #include <sys/fs/ufs_fs.h>
29 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
30 #include <ufs/ufs/dinode.h>
31 #include <ufs/ffs/fs.h>
36 #else /* AFS_VFSINCL_ENV */
37 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_XBSD_ENV)
40 #endif /* AFS_VFSINCL_ENV */
41 #endif /* AFS_OSF_ENV */
42 #endif /* AFS_SGI_ENV */
43 #include <sys/errno.h>
44 #include <sys/types.h>
56 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
58 #include <sys/mnttab.h>
59 #include <sys/mntent.h>
64 #if defined(AFS_SGI_ENV)
67 #ifdef AFS_SGI_EFS_IOPS_ENV
68 #define ROOTINO EFS_ROOTINO
69 #include "sgiefs/efs.h"
72 #ifdef AFS_LINUX22_ENV
78 #endif /* AFS_SGI_ENV */
79 #endif /* AFS_HPUX_ENV */
82 #include <netinet/in.h>
87 #endif /* ITIMER_REAL */
88 #include "partition.h"
100 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
101 * returns pointer to static storage; copy it out quickly!
104 vol_DevName(dev_t adev, char *wpath)
106 static char pbuffer[128];
107 char pbuf[128], *ptr;
113 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
114 struct mntent *mntent;
122 struct vmount *vmountp;
126 if ((nmounts = getmount(&vmountp)) <= 0) {
131 (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
132 char *part = vmt2dataptr(vmountp, VMT_STUB);
135 if (!(mntfile = fopen(MNTTAB, "r"))) {
138 while (!getmntent(mntfile, &mnt)) {
139 char *part = mnt.mnt_mountp;
141 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
142 #ifdef AFS_LINUX22_ENV
143 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
144 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
149 if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) {
153 while ((mntent = getmntent(mfd))) {
154 char *part = mntent->mnt_dir;
157 while ((fsent = getfsent())) {
158 char *part = fsent->fs_file;
160 #endif /* AFS_SGI_ENV */
164 if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE))
165 continue; /* Ignore any "special" partitions */
168 /* Ignore non ufs or non read/write partitions */
169 if ((strcmp(mnt.mnt_fstype, "ufs") != 0)
170 || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0))
173 #if defined(AFS_LINUX22_ENV)
174 if (strcmp(mntent->mnt_type, "ext2"))
177 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV)
178 if (!hasmntopt(mntent, MNTOPT_RW))
181 if (strcmp(fsent->fs_type, "rw") != 0)
182 continue; /* Ignore non read/write partitions */
183 #endif /* AFS_LINUX22_ENV */
184 #endif /* AFS_SGI_ENV */
187 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
188 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
189 continue; /* Non /vicepx; ignore */
191 if (stat(part, &status) == -1) {
194 #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV)
195 if ((status.st_ino !=
196 ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) {
200 if (status.st_dev == adev) {
202 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
205 strcpy(pbuffer, mnt.mnt_special);
207 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
208 strcpy(pbuffer, mntent->mnt_fsname);
210 strcpy(pbuffer, fsent->fs_spec);
212 #endif /* AFS_SGI_ENV */
215 strcpy(pbuf, pbuffer);
216 ptr = (char *)strrchr(pbuf, '/');
223 ptr = (char *)strrchr(pbuffer, '/');
225 strcpy(pbuffer, ptr + 1);
232 (void)fclose(mntfile);
234 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
241 #endif /* AFS_SGI_ENV */
245 /* Search for the raw device name. Will put an "r" in front of each
246 * directory and file entry of the pathname until we find a character
250 afs_rawname(char *devfile)
252 static char rawname[100];
259 strcpy(rawname, devfile);
260 if (devfile[i] == '/') {
261 rawname[i + 1] = 'r';
263 strcat(rawname, &devfile[i + 1]);
266 code = stat(rawname, &statbuf);
267 if (!code && S_ISCHR(statbuf.st_mode))
270 while ((--i >= 0) && (devfile[i] != '/'));