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>
15 #if defined(AFS_DUX40_ENV) || (defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV)) || defined(AFS_SUN54_ENV)
16 #if defined AFS_DUX40_ENV
17 #define OSVERS "DUX 4.0D"
19 #if defined(AFS_SUN54_ENV)
20 #define OSVERS "SunOS 5.6"
22 #define OSVERS "SunOS 4.1.1"
25 #include <sys/types.h>
27 #include <afs/afsint.h>
28 #include <sys/param.h>
31 #include <sys/fs/ufs_fs.h>
37 #include <sys/mount.h>
41 #endif /* ITIMER_REAL */
43 #ifdef AFS_VFSINCL_ENV
44 #include <sys/vnode.h>
46 #include <sys/fs/ufs_inode.h>
48 #include <ufs/inode.h>
50 #else /* AFS_VFSINCL_ENV */
52 #include <ufs/inode.h>
54 #include <sys/inode.h>
56 #endif /* AFS_VFSINCL_ENV */
59 #include <sys/lockf.h>
63 #include <checklist.h>
66 #include <sys/mnttab.h>
67 #include <sys/mntent.h>
68 #include <sys/vfstab.h>
75 #include <afs/osi_inode.h>
79 #include <partition.h>
84 int icount=0, iarraysize=0, *iarray;
86 char *rawname(), *unrawname(), *vol_DevName(), *blockcheck();
89 int force = 0, verbose = 0, unconv = 0;
95 if (*a < *b) return -1;
96 if (*a > *b) return +1;
100 int BuildInodes(path)
111 printf("Cannot open %s: error %d\n", path, errno);
115 while (de = readdir(d)) {
116 if (iarraysize == 0) {
118 iarray = (int *) malloc(iarraysize * sizeof(int));
120 if (icount >= iarraysize) {
122 iarray = (int *) realloc(iarray, iarraysize * sizeof(int));
124 iarray[icount] = de->d_ino;
127 if ( (strcmp(de->d_name,".") == 0) || (strcmp(de->d_name,"..") == 0) )
132 strcat(p, de->d_name);
134 code = stat(p, &stats);
136 printf("Cannot stat %s: error %d\n", path, errno);
139 if (S_ISDIR(stats.st_mode)) {
140 code = BuildInodes(p);
151 struct cmd_syndesc *as;
158 struct cmd_syndesc *as;
164 #if defined(AFS_SUN54_ENV)
167 struct cmd_syndesc *as;
169 register struct cmd_item *ti;
171 afs_int32 haspart = 0, hasDevice = 0;
174 if (as->parms[1].items)
178 if (as->parms[2].items)
184 printf("Unconverts from a %s AFS partition to a pre-%s compatible format.\n\n",
188 printf("Converts a pre-%s AFS partition to a %s compatible format.\n\n",
192 printf("*** Must use the '-force' option for command to have effect! ***\n");
194 printf("*** Use the '-verbose' option to report what will be converted ***\n");
199 for (ti = as->parms[0].items; ti; ti=ti->next) {
201 char *namep = ti->data;
205 if ( ( fsent = fopen(VFSTAB, "r")) == NULL )
207 printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno);
210 while (!getvfsent(fsent, &mnt)) {
211 char *part = mnt.vfs_mountp;
216 if (!strncmp(namep, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
217 if (!strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
218 if (!strncmp(part, namep, strlen(part)+1)) {
219 if (dname = mnt.vfs_fsckdev) {
220 printf("ProcessFileSys %s %s\n", dname, namep);
221 ProcessFileSys(dname, namep);
230 printf("Unknown input AFS partition name or device: %s\n", namep);
234 /* if raw devices are specified */
235 for (ti = as->parms[3].items; ti; ti=ti->next) {
236 char *namep = ti->data;
241 if ( !CheckMountedDevice(namep) )
243 printf("Device %s may be mounted, aborting...\n", namep);
246 ProcessFileSys(namep, namep);
250 if (!haspart && !hasDevice) {
254 if ( ( fsent = fopen(VFSTAB, "r")) ==NULL )
256 printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno);
259 while (!getvfsent(fsent, &mnt)) {
260 char *part = mnt.vfs_mountp;
265 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE) == 0) {
266 if (dname = mnt.vfs_fsckdev )
267 ProcessFileSys(dname, part);
273 printf("No file system partitions named %s* found; not processed\n",VICE_PARTITION_PREFIX);
277 #else /* AFS_SUN54_ENV */
280 struct cmd_syndesc *as;
282 register struct cmd_item *ti;
284 afs_int32 haspart = 0;
286 if (as->parms[1].items)
290 if (as->parms[2].items)
296 printf("Unconverts from a %s AFS partition to a pre-%s compatible format.\n\n",
300 printf("Converts a pre-%s AFS partition to a %s compatible format.\n\n",
304 printf("*** Must use the '-force' option for command to have effect! ***\n");
306 printf("*** Use the '-verbose' option to report what will be converted ***\n");
311 for (ti = as->parms[0].items; ti; ti=ti->next) {
313 char *namep = ti->data;
318 while (fsent = getfsent()) {
319 char *part = fsent->fs_file;
321 if (!strncmp(namep, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
322 if (!strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) {
323 if (!strncmp(part, namep, strlen(part)+1)) {
324 if (dname = unrawname(fsent->fs_spec)) {
325 ProcessFileSys(dname, namep);
332 if (!rawname(namep) || !unrawname(namep))
334 if (!strcmp(fsent->fs_spec, rawname(namep)) ||
335 !strcmp(fsent->fs_spec, unrawname(namep))) {
336 if (dname = unrawname(fsent->fs_spec)) {
337 ProcessFileSys(dname, fsent->fs_file);
345 printf("Unknown input AFS partition name or device: %s\n", namep);
354 while (fsent = getfsent()) {
355 char *part = fsent->fs_file;
357 if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE) == 0) {
358 if (dname = unrawname(fsent->fs_spec)) {
359 ProcessFileSys(dname, part);
366 printf("No file system partitions named %s* found; not processed\n",VICE_PARTITION_PREFIX);
369 #endif /* AFS_SUN54_ENV */
372 #include "AFS_component_version_number.c"
377 register struct cmd_syndesc *ts;
380 if (geteuid() != 0) {
381 printf("must be run as root; sorry\n");
385 ts = cmd_CreateSyntax("convert", ConvCmd, 0, "Convert to DUX 4.0D format");
387 #if defined(AFS_SUN54_ENV)
388 ts = cmd_CreateSyntax("convert", ConvCmd, 0, "Convert to AFS SunOS 5.6 format");
390 ts = cmd_CreateSyntax("convert", ConvCmd, 0, "Convert to AFS 4.1.1 format");
393 cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name");
394 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose mode");
395 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Safeguard enforce switch");
396 cmd_AddParm(ts, "-device", CMD_LIST, CMD_OPTIONAL, "AFS raw device name");
398 ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, "Convert back from OSF 4.0D to earlier formats");
400 #if defined(AFS_SUN54_ENV)
401 ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, "Convert back from AFS SunOS 5.6 to earlier formats");
403 ts = cmd_CreateSyntax("unconvert", UnConvCmd, 0, "Convert back from AFS 4.1.1 to earlier formats");
406 cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name");
407 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose mode");
408 cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Safeguard enforce switch");
409 cmd_AddParm(ts, "-device", CMD_LIST, CMD_OPTIONAL, "AFS raw device name");
411 code = cmd_Dispatch(argc, argv);
416 ProcessFileSys(dname, path)
419 struct stat status, stat1;
420 #if !defined(AFS_SUN54_ENV)
421 struct ufs_args ufsargs;
423 char devbuffer[120], *devname;
424 int i, j, mounted = 0, code;
426 if (stat(path,&status) == -1) {
427 printf("Couldn't find file system \"%s\"\n", path);
430 if (status.st_ino == ROOTINODE) {
432 printf("Partition %s is mounted; only unmounted partitions are processed\n", path);
437 strcpy(devbuffer, dname);
439 #if !defined(AFS_SUN54_ENV)
440 EnsureDevice(devname);
444 ufsargs.fspec = devname;
445 code = mount(MOUNT_UFS, path, 0, &ufsargs);
447 #if defined(AFS_SUN54_ENV)
450 ufsargs.fspec = devname;
451 code = mount("4.2", path, M_NEWTYPE, &ufsargs);
455 printf("Couldn't mount %s on %s (err=%d)\n", devname, path, errno);
460 if (stat(path,&status) == -1) {
461 printf("Couldn't find file system \"%s\"\n", path);
467 code = BuildInodes(path);
469 printf("Couldn't generate list of all inodes in directory %s\n", path);
473 qsort(iarray, icount, sizeof(int), sortinodes);
476 #if !defined(AFS_SUN54_ENV)
477 if (!(devname = vol_DevName(status.st_dev))) {
478 printf("Couldn't get devname for %d\n", status.st_dev);
483 if (ProcessAfsInodes(devname, path) == -1)
484 printf("Unable to get inodes for \"%s\"; not processed\n", path);
493 int ProcessAfsInodes(devname, partition)
494 char *devname, *partition;
500 int pfd, i, c, e, bufsize, cnt =0, mod = 0, wcnt = 0, ccnt = 0, ncnt;
501 FILE *inodeFile = NULL;
503 struct dinode *inodes = NULL, *einodes, *p;
508 #if defined(AFS_SUN54_ENV)
509 sprintf(rdev, "%s", devname);
511 sprintf(rdev, "/dev/r%s", devname);
513 pfd = open(rdev, O_RDWR);
515 printf("Could not read device %s to get inode list\n", rdev);
516 printf("errno %d: %s\n", errno, strerror(errno));
519 if (bread(pfd, super.block, SBLOCK, SBSIZE) == -1) {
520 printf("Unable to read superblock, partition %s\n", partition);
525 * run a few consistency checks of the superblock
526 * (Cribbed from vfsck)
528 if ((super.fs.fs_magic != FS_MAGIC) || (super.fs.fs_ncg < 1) || (super.fs.fs_cpg < 1) ||
529 (super.fs.fs_ncg * super.fs.fs_cpg < super.fs.fs_ncyl ||
530 (super.fs.fs_ncg - 1) * super.fs.fs_cpg >= super.fs.fs_ncyl) ||
531 (super.fs.fs_sbsize > SBSIZE)) {
532 printf("There's something wrong with the superblock for partition %s; run vfsck\n", partition);
535 bufsize = super.fs.fs_ipg * sizeof(struct dinode);
536 if (!(inodes = (struct dinode *) malloc(bufsize))) {
537 printf("Unable to allocate enough memory to scan inodes; help!\n");
540 einodes = (struct dinode *) (((char *)inodes) + bufsize);
541 printf("Processing all AFS inodes on partition %s (device %s)...\n", partition, rdev);
542 for (c = 0; c < super.fs.fs_ncg; c++) {
544 #if defined(AFS_SUN54_ENV)
549 i = c*super.fs.fs_ipg;
550 e = i+super.fs.fs_ipg;
552 dblk1 = fsbtodb(&super.fs, itod(&super.fs, i));
553 code = lseek(pfd, (off_t) ((off_t)dblk1 * DEV_BSIZE), L_SET);
555 #if defined(AFS_SUN54_ENV)
556 f1 = fsbtodb(&super.fs,itod(&super.fs,i));
557 off = (offset_t)f1 << DEV_BSHIFT;
558 code = llseek(pfd, off, L_SET) ;
560 code = lseek(pfd, dbtob(fsbtodb(&super.fs,itod(&super.fs,i))), L_SET);
564 printf("Error reading inodes for partition %s; run vfsck\n", partition);
565 printf("%d: %s\n", errno, strerror(errno));
566 #if defined(AFS_SUN54_ENV)
567 printf("file number = %d; offset = %ld\n", pfd, off);
569 printf("file number = %d\n", pfd);
574 wcnt = ncnt = mod = 0;
575 code = read(pfd, inodes, bufsize);
576 if (code != bufsize) {
577 printf("Error reading inodes for partition %s; run vfsck\n", partition);
579 printf("errno %d: %s\n", errno, strerror(errno));
584 /* Step through each inode */
585 for (p = inodes; p < einodes && i < e; i++, p++)
588 afs_uint32 v1, v2, v3, v4;
589 afs_uint32 volid, vnode, uniq, vers;
590 afs_uint32 type, rwvol;
594 if ((p->di_mode&IFMT) != IFREG) {
595 /* This inode is not an AFS inode so
596 * zero out all the spare fields.
599 if (!(p->di_flags & IC_PROPLIST)) {
602 if (!(p->di_flags & IC_XUID)) {
605 if (!(p->di_flags & IC_XGID)) {
613 /* printf("Inode %d: proplb=%u, uid=%u, bcuid=0x%x, bcgid=0x%x, gid=0x%x\n",
614 * i , p->di_proplb, p->di_uid, p->di_bcuid, p->di_bcgid,
618 if (unconv) { /*unconvert*/
619 /* Check if the inode is not a DUX40D AFS inode */
620 if (p->di_proplb != VICEMAGIC || (p->di_flags & IC_PROPLIST)) {
623 printf(" AFS Inode %d: already unconverted\n", i);
629 v3 = ((u_int)(p->di_bcuid)) << 16 | ((u_int)(p->di_bcgid));
631 /* We have a sorted list of ufs inodes. Is it one of these */
632 while ((istep < icount) && (i > iarray[istep])) {
635 if ((istep < icount) && (i == iarray[istep])) {
636 /* Yes, its a ufs inode */
638 printf(" Inode %d: Not an AFS Inode\n", i);
642 /* Is it not an AFS inode. !IS_VICEMAGIC check */
645 printf("Warning: Inode %d: Unreferenced inode\n", i);
646 continue; /* skip, making no change */
650 if (((v2 >> 3) == 0x1fffffff) && (v2 & 0x3)) {
651 special = 1; /* INODESPECIAL */
655 printf(" %s AFS Inode %d: Vol=%u, RWVol=%u, Type=%d\n",
656 (force?"Unconverting":"Would have unconverted"), i,
661 vnode = ((v2 >> 27) << 16) + (v3 & 0xffff);
662 uniq = (v2 & 0x3fffff);
663 vers = (((v2 >> 22) & 0x1f) << 16) + ((v3 >> 16) & 0xffff);
665 printf(" %s AFS Inode %d: RWVol=%u, VNode=%u, Uniq=%u, Vers=%u\n",
666 (force?"Unconverting":"Would have unconverted"), i,
667 volid, vnode, uniq, vers);
671 /* Now unconvert the DUX40D AFS inode to the OSF30 version */
675 p->di_flags &= ~(IC_PROPLIST|IC_XUID|IC_XGID);
678 mod = 1; cnt++; wcnt++;
681 if ((p->di_proplb == VICEMAGIC && !(p->di_flags & IC_PROPLIST))
682 || (p->di_uid == 0 && p->di_gid == 0)
683 || (p->di_flags & (IC_XUID|IC_XGID))) {
684 /* This inode is either already converted or not an AFS inode */
685 /* We have a sorted list of ufs inodes. Is it one of these */
686 while ((istep < icount) && (i > iarray[istep])) {
689 if ((istep < icount) && (i == iarray[istep])) {
690 /* Yes, its a ufs inode */
692 printf(" Inode %d: Not an AFS Inode %s\n",
693 i, ((p->di_spare[1] || p->di_spare[2])?"(fixed)":""));
698 /* Is it a AFS inode. IS_VICEMAGIC check */
699 if ((p->di_uid || p->di_gid)
700 && !(p->di_flags & (IC_XUID|IC_XGID))) {
703 printf(" AFS Inode %d: already converted\n", i);
707 /* Not an AFS nor UFS inode */
708 printf("Warning: Inode %d: Unreferenced inode\n", i);
709 continue; /* skip, making no changes */
717 if (((v2 >> 3) == 0x1fffffff) && (v2 & 0x3)) {
718 special = 1; /* INODESPECIAL */
722 printf(" %s AFS Inode %d: Vol=%u, RWVol=%u, Type=%d\n",
723 (force?"Converting":"Would have converted"),i,
728 vnode = ((v2 >> 27) << 16) + (v3 & 0xffff);
729 uniq = (v2 & 0x3fffff);
730 vers = (((v2 >> 22) & 0x1f) << 16) + ((v3 >> 16) & 0xffff);
732 printf(" %s AFS Inode %d: RWVol=%u, VNode=%u, Uniq=%u, Vers=%u\n",
733 (force?"Converting":"Would have converted"),i,
734 volid, (vnode & 0x1fffff), (uniq & 0x3fffff),
739 /* Now convert the OSF30 AFS inode to the DUX40D version */
740 p->di_proplb = VICEMAGIC;
743 p->di_bcuid = (u_short)(v3 >> 16);
744 p->di_bcgid = (u_short)v3;
745 p->di_flags &= ~(IC_PROPLIST);
746 p->di_flags |= (IC_XUID|IC_XGID);
747 mod = 1; cnt++; wcnt++;
752 afs_uint32 p1, p2, p3, p4;
756 #if defined(AFS_SUN56_ENV)
757 q = (quad *)&(p->di_ic.ic_lsize);
759 q = &(p->di_ic.ic_size);
763 p2 = p->di_ic.ic_flags;
765 p4 = p->di_ic.ic_uid;
766 p5 = p->di_ic.ic_gid;
768 /* the game is afoot, Dr Watson! */
769 if ( !verbose && ! ((ccnt+cnt+ncnt) % 5000 ) )
777 * Convert from a 5.6 format to a pre 5.6 format
779 if ( (p2 || p3) && !p4 && (p5 == -2) )
782 printf("AFS Inode %d: Already in pre-%s AFS format (%x,%x,%x,%x,%x) ignoring..\n",
783 i, OSVERS, p1, p2, p3,p4, p5);
788 if ( p5 == VICEMAGIC)
790 /* This is a sol 2.6 AFS inode */
794 printf("AFS Inode %d: %s from Sol5.6 (%x,%x,%x,%x,%x) \n",
795 i, (force ? "Unconverting" :
796 "Would have unconverted"), p1,p2,p3,p4,p5);
799 q->val[0] = p->di_uid;
802 p->di_suid = UID_LONG;
803 p->di_sgid = GID_LONG;
809 { /* Assume an already converted 5.6 afs inode */
811 printf("AFS Inode %d: Already in %s AFS format (p1=%x,p2=%x,p3=%x,p4=%x,p5=%x); ignoring..\n",
812 i, OSVERS, p1,p2,p3,p4, p5);
817 /* for inodes created in solaris 2.4, there is a possibility
818 ** that the gid gets chopped off to an unsigned short(2 bytes)
820 if ( (p2 || p3) && !p4 && ((p5 == -2) ||
821 ((unsigned short)p5 == (unsigned short)-2) ))
823 /* This is a pre Sol2.6 inode */
827 printf("AFS Inode %d: %s to 5.6 format (p1=%x,p2=%x,p3=%x,p4=%x, p5=%x)\n",
828 i, (force ? "Converting" : "Would have converted"),
832 p->di_gid = VICEMAGIC;
833 p->di_uid = q->val[0];
834 p->di_suid = UID_LONG;
835 p->di_sgid = GID_LONG;
841 /* If not an AFS inode, ignore */
844 printf("Non AFS Inode %d: (p1=%x,p2=%x,p3=%x, p4=%x,p5=%x) ignoring..\n",
845 i, p1, p2, p3, p4,p5);
850 if (lseek(pfd, -bufsize, SEEK_CUR) == -1) { /* Point to loc bef read */
851 printf("Error Seeking backwards %d bytes\n", bufsize);
852 printf("errno %d: %s\n", errno, strerror(errno));
855 code = write(pfd, inodes, bufsize);
856 if (code != bufsize) { /* Update inodes */
857 printf("Error writing modified inodes for partition %s\n", partition);
859 printf("errno %d: %s\n", errno, strerror(errno));
863 printf(" Write %d AFS inodes and %d non-AFS inodes to disk\n",
870 printf("\n%s: %d AFS inodes %s ", partition, cnt, (force?"were":"would have been"));
872 printf("unconverted to a pre-%s format; %d already unconverted.\n", OSVERS, ccnt);
874 printf("converted to a %s format; %d already converted.\n", OSVERS, ccnt);
887 int bread(fd, buf, blk, size)
893 if (lseek(fd, (off_t)dbtob(blk), L_SET) < 0 || read(fd, buf, size) != size) {
894 printf("bread: lseek failed (errno = %d)\n", errno);
902 * Ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
903 * returns pointer to static storage; copy it out quickly!
905 char *vol_DevName(adev)
909 static char pbuffer[128];
915 /* now, look in /dev for the appropriate file */
916 dirp = opendir(dirName = "/dev");
917 while (dp = readdir(dirp)) {
918 strcpy(pbuffer, dirName);
919 strcat(pbuffer, "/");
920 strcat(pbuffer, dp->d_name);
921 if (stat(pbuffer, &tstat) != -1 &&
922 (tstat.st_mode & S_IFMT) == S_IFBLK &&
923 (tstat.st_rdev == adev)) {
924 strcpy(pbuffer, dp->d_name);
930 return NULL; /* failed */
933 char *unrawname(name)
939 if ((dp = strrchr(name, '/')) == 0)
941 if (stat(name, &stb) < 0)
943 if ((stb.st_mode & S_IFMT) != S_IFCHR)
945 if (*(dp + 1) != 'r')
947 (void)strcpy(dp + 1, dp + 2);
955 static char rawbuf[32];
958 if ((dp = strrchr(name, '/')) == 0)
961 (void)strcpy(rawbuf, name);
963 (void)strcat(rawbuf, "/r");
964 (void)strcat(rawbuf, dp + 1);
968 char *blockcheck(name)
971 struct stat stslash, stblock, stchar;
976 if (stat(name, &stblock) < 0) {
978 printf("Can't stat %s\n", name);
981 if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
983 if (stat(raw, &stchar) < 0) {
985 printf("Can't stat %s\n", raw);
988 if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
991 printf("%s is not a character device\n", raw);
994 } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
995 name = unrawname(name);
999 printf("Can't make sense out of name %s\n", name);
1004 /* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device.
1005 * Overwrites abuffer with the corrected name.
1007 EnsureDevice(abuffer)
1017 code = stat(abuffer, &tstat);
1018 if (code) return code;
1019 if (((tstat.st_mode & S_IFMT) == S_IFBLK) || ((tstat.st_mode & S_IFMT) == S_IFCHR)) {
1020 return 0; /* already a block or char device */
1022 /* otherwise, assume we've got a normal file, and we look up its device */
1023 dev = tstat.st_dev; /* remember device for this file */
1025 /* now, look in /dev for the appropriate file */
1026 dirp = opendir(dirName = "/dev");
1028 while (dp=readdir(dirp)) {
1029 strcpy(pbuffer, dirName);
1030 strcat(pbuffer, "/");
1031 strcat(pbuffer, dp->d_name);
1032 if (stat(pbuffer, &tstat) != -1 &&
1033 (tstat.st_mode & S_IFMT) == S_IFBLK &&
1034 (tstat.st_rdev == dev)) {
1035 strcpy(abuffer, pbuffer);
1041 return 1; /* failed */
1045 #include "AFS_component_version_number.c"
1051 printf("%s: **ONLY** supported for SunOS 3.5-4.x and dux4.0D systems ...\n",
1054 #endif /* defined(AFS_SUN_ENV) && !defined(AFS_SUN5_ENV) */
1056 #if defined(AFS_SUN54_ENV)
1059 ** Open the /etc/vfstab file to map the raw device name to the mountable
1060 ** device name. Then open the /etc/mnttab file to see if this mountable
1061 ** device is mounted.
1063 ** Returns 1 if the conversion process should continue, otherwise returns 0
1065 CheckMountedDevice(devName)
1066 char* devName; /* raw device name */
1068 FILE *vfsent, *mntent;
1075 if ( ( vfsent = fopen(VFSTAB, "r")) == NULL )
1077 printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno);
1080 while (!getvfsent(vfsent, &vnt))
1082 char *rawDev = vnt.vfs_fsckdev;
1083 if ( rawDev && !strcmp(rawDev, devName) )
1085 /* this is the device we are looking for */
1086 unRawDev = vnt.vfs_special;
1092 if ( !unRawDev ) goto done; /* could not find it in /etc/vfstab */
1094 /* we found the entry in /etc/vfstab. Now we open /etc/mnnttab and
1095 ** verify that it is not mounted
1097 if ( ( mntent = fopen(MNTTAB, "r")) == NULL )
1099 printf("Unable to open %s ( errno = %d)\n", VFSTAB, errno);
1103 while (!getmntent(mntent, &mnt))
1105 char* resource = mnt.mnt_special;
1106 if ( resource && !strcmp(resource, unRawDev) )
1115 /* if we found an entry in the /etc/mnttab file, then this
1116 ** device must be mounted
1123 printf("Device %s may be mounted. Can corrupt data. Continue anyway(y/n)?", devName);
1126 YesNo = getc(stdin);
1128 while ( YesNo != 'y' && YesNo != 'Y' &&
1129 YesNo != 'n' && YesNo != 'N' );
1131 if ( (YesNo == 'y') || ( YesNo == 'Y' ) )
1136 #endif /* AFS_SUN54_ENV */