source: trunk/athena/bin/attach/rvd.c @ 8843

Revision 8843, 3.7 KB checked in by ghudson, 28 years ago (diff)
BSD -> ANSI string and memory functions
Line 
1/*      Created by:     Robert French
2 *
3 *      $Source: /afs/dev.mit.edu/source/repository/athena/bin/attach/rvd.c,v $
4 *      $Author: ghudson $
5 *
6 *      Copyright (c) 1988 by the Massachusetts Institute of Technology.
7 */
8
9#ifndef lint
10static char rcsid_rvd_c[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/attach/rvd.c,v 1.8 1996-09-19 22:13:17 ghudson Exp $";
11#endif
12
13#include "attach.h"
14
15#ifdef RVD                      /* Don't do anything if RVD not defined */
16#include "rvdlib.h"
17#include <sys/wait.h>
18
19extern char     *rvd_error();
20
21/*
22 * Attach an RVD
23 */
24
25rvd_attach(at, mopt, errorout)
26        struct _attachtab *at;
27        struct mntopts  *mopt;
28        int errorout;
29{
30    char buf[BUFSIZ];
31    union wait waitb;
32    int vddrive, pid;
33    char *passwd;
34   
35    if (avail_drive(at->hostaddr[0], at->hostdir, &vddrive) == FAILURE) {
36        if (errorout)
37            fprintf(stderr, "%s: No free RVD drives\n", at->hesiodname);
38        return (FAILURE);
39    }
40
41    if (debug_flag)
42      printf("avail_drive returned %d\n", vddrive);
43
44    at->drivenum = vddrive;
45   
46    passwd = NULL;
47   
48    while (rvd_spinup(at->hostaddr[0], at->hostdir,
49                      vddrive, at->mode, at->host, passwd) == FAILURE &&
50           rvderrno == RVDEBPWD) {
51        fprintf(stderr, "%s: Need password for RVD spinup\n",
52                at->hesiodname);
53        if (!isatty(fileno(stdin))) {
54            error_status = ERR_ATTACHNEEDPW;
55            return (FAILURE);
56        }
57        passwd = (char *)getpass("Password:");
58        if (!*passwd) {
59            fprintf(stderr, "%s: Null password, ignoring filesystem\n",
60                    at->hesiodname);
61            return (FAILURE);
62        }
63    }
64
65    if (rvderrno && rvderrno != RVDEIDA &&
66        rvderrno != EBUSY /* kernel bug */) {
67        if (errorout)
68            fprintf(stderr, "%s: Error in RVD spinup: %d -> %s\n",
69                    at->hesiodname, rvderrno, rvd_error(rvderrno));
70        switch(rvderrno)
71          {
72          case RVDENOENT:
73          case RVDENOTAVAIL:
74          case RVDEPACK:
75          case RVDEPNM:
76            error_status = ERR_ATTACHNOFILSYS;
77            break;
78          default:
79            error_status = ERR_SOMETHING;
80          }
81        return (FAILURE);
82    }
83
84    if((pid = vfork()) == 0) {
85        execl(RVDGETM_FULLNAME, RVDGETM_SHORTNAME, at->host, 0);
86        _exit(0);
87    } else if(pid == -1) {
88        perror("vfork");
89    } else {
90        (void) wait(&waitb);
91    }
92   
93    if (at->mode == 'w' && rvderrno != RVDEIDA &&
94        rvderrno != EBUSY && !skip_fsck) {
95            if (perform_fsck(vdnam(buf, vddrive),
96                             at->hesiodname, 1) == FAILURE) {
97                    rvd_spindown(vddrive);
98                    return(FAILURE);
99            }
100    }
101           
102    /* XXX This is kind of bogus, because if a filesystem has a number
103     * of hesiod entries, and the mount point is busy, each one will
104     * be tried until the last one fails, then an error printed.
105     * C'est la vie.
106     */
107
108    if (mountfs(at, vdnam(buf, vddrive), mopt, errorout) == FAILURE) {
109        rvd_spindown(vddrive);
110        return (FAILURE);
111    }
112
113    return (SUCCESS);
114}
115
116/*
117 * Detach a RVD
118 */
119rvd_detach(at)
120    struct _attachtab *at;
121{
122        char buf[BUFSIZ];
123
124        if (at->flags & FLAG_PERMANENT) {
125                if (debug_flag)
126                        printf("Permanent flag on, skipping umount.\n");
127                return(SUCCESS);
128        }
129       
130        if (unmount_42(at->hesiodname, at->mntpt, vdnam(buf,at->drivenum)) == FAILURE)
131                return (FAILURE);
132        rvd_spindown(at->drivenum);
133        return (SUCCESS);
134}
135
136/*
137 * Parsing of explicit RVD file types
138 */
139char **rvd_explicit(name)
140    char *name;
141{
142    char temp[BUFSIZ];
143    char *pack;
144    char newmntpt[BUFSIZ];
145    extern char *exp_hesptr[2];
146       
147    strcpy(temp, name);
148    pack = strchr(temp, ':');
149    if (!pack) {
150        fprintf(stderr, "%s: Illegal explicit definition for type %s\n",
151                name, filsys_type);
152        return (0);
153    }
154    *pack = '\0';
155    pack++;
156    if (!mntpt) {
157        sprintf(newmntpt, "/%s/%s", temp, pack);
158    }
159    sprintf(exp_hesline, "RVD %s %s %c %s", pack, temp, override_mode ?
160            override_mode : 'w', mntpt ? mntpt : newmntpt);
161    exp_hesptr[0] = exp_hesline;
162    exp_hesptr[1] = 0;
163    return(exp_hesptr);
164}
165
166#endif /* RVD */
Note: See TracBrowser for help on using the repository browser.