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>
15 #include <afs/param.h>
17 #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_LINUX22_ENV) && !defined(AFS_XBSD_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)
66 #ifdef AFS_SGI_EFS_IOPS_ENV
67 #define ROOTINO EFS_ROOTINO
68 #include "sgiefs/efs.h"
71 #ifdef AFS_LINUX22_ENV
77 #endif /* AFS_SGI_ENV */
78 #endif /* AFS_HPUX_ENV */
81 #include <netinet/in.h>
86 #endif /* ITIMER_REAL */
87 #include "partition.h"
88 #ifdef AFS_LINUX22_ENV
89 #include <asm/types.h>
90 #include <linux/ext2_fs.h>
91 #define ROOTINO EXT2_ROOT_INO /* Assuming we do this on ext2, of course. */
104 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
105 * returns pointer to static storage; copy it out quickly!
107 char *vol_DevName(dev_t adev, char *wpath)
109 static char pbuffer[128];
110 char pbuf[128], *ptr;
116 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
117 struct mntent *mntent;
125 struct vmount *vmountp;
129 if ((nmounts = getmount(&vmountp)) <= 0) {
132 for (; nmounts; nmounts--, vmountp = (struct vmount *)((int)vmountp + vmountp->vmt_length)) {
133 char *part = vmt2dataptr(vmountp, VMT_STUB);
136 if (!(mntfile = fopen(MNTTAB, "r"))) {
139 while (!getmntent(mntfile, &mnt)) {
140 char *part = mnt.mnt_mountp;
142 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
143 #ifdef AFS_LINUX22_ENV
144 if ((mfd = setmntent("/proc/mounts", "r")) == NULL) {
145 if ((mfd = setmntent("/etc/mtab", "r")) == NULL) {
150 if ((mfd = setmntent(MOUNTED/*MNTTAB*/, "r")) == NULL) {
154 while ((mntent = getmntent(mfd))) {
155 char *part = mntent->mnt_dir;
158 while ((fsent = getfsent())) {
159 char *part = fsent->fs_file;
161 #endif /* AFS_SGI_ENV */
165 if (vmountp->vmt_flags & (MNT_READONLY|MNT_REMOVABLE|MNT_REMOTE)) 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)) continue;
180 if (strcmp(fsent->fs_type, "rw") != 0) continue; /* Ignore non read/write partitions */
181 #endif /* AFS_LINUX22_ENV */
182 #endif /* AFS_SGI_ENV */
185 /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */
186 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
187 continue; /* Non /vicepx; ignore */
189 if (stat(part, &status) == -1) {
192 #ifndef AFS_SGI_XFS_IOPS_ENV
193 if ((status.st_ino != ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK)*/) {
197 if (status.st_dev == adev) {
199 strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT));
202 strcpy(pbuffer, mnt.mnt_special);
204 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
205 strcpy(pbuffer, mntent->mnt_fsname);
207 strcpy(pbuffer, fsent->fs_spec);
209 #endif /* AFS_SGI_ENV */
212 strcpy(pbuf, pbuffer);
213 ptr = (char *)strrchr(pbuf, '/');
220 ptr = (char *)strrchr(pbuffer, '/');
222 strcpy(pbuffer, ptr+1);
229 (void) fclose(mntfile);
231 #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV)
238 #endif /* AFS_SGI_ENV */
242 /* Search for the raw device name. Will put an "r" in front of each
243 * directory and file entry of the pathname until we find a character
246 char *afs_rawname(char *devfile)
248 static char rawname[100];
255 strcpy(rawname, devfile);
256 if (devfile[i] == '/') {
259 strcat(rawname, &devfile[i+1]);
262 code = stat(rawname, &statbuf);
263 if (!code && S_ISCHR(statbuf.st_mode))
266 while((--i>=0) && (devfile[i] != '/'));