Commit | Line | Data |
---|---|---|
53102063 C |
1 | /* ftamaccess1.c - FPM: initiate file access */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/ftam/RCS/ftamaccess1.c,v 7.1 91/02/22 09:22:33 mrose Interim $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/ftam/RCS/ftamaccess1.c,v 7.1 91/02/22 09:22:33 mrose Interim $ | |
9 | * | |
10 | * | |
11 | * $Log: ftamaccess1.c,v $ | |
12 | * Revision 7.1 91/02/22 09:22:33 mrose | |
13 | * Interim 6.8 | |
14 | * | |
15 | * Revision 7.0 89/11/23 21:53:20 mrose | |
16 | * Release 6.0 | |
17 | * | |
18 | */ | |
19 | ||
20 | /* | |
21 | * NOTICE | |
22 | * | |
23 | * Acquisition, use, and distribution of this module and related | |
24 | * materials are subject to the restrictions of a license agreement. | |
25 | * Consult the Preface in the User's Manual for the full terms of | |
26 | * this agreement. | |
27 | * | |
28 | */ | |
29 | ||
30 | ||
31 | /* LINTLIBRARY */ | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <signal.h> | |
35 | #include "fpkt.h" | |
36 | ||
37 | /* \f F-{LOCATE,ERASE}.REQUEST */ | |
38 | ||
39 | int FAccessRequest (sd, operation, identity, lock, fti) | |
40 | int sd; | |
41 | int operation; | |
42 | struct FADUidentity *identity; | |
43 | int lock; /* F-LOCATE.REQUEST only */ | |
44 | struct FTAMindication *fti; | |
45 | { | |
46 | SBV smask; | |
47 | int result, | |
48 | state; | |
49 | register struct ftamblk *fsb; | |
50 | ||
51 | switch (operation) { | |
52 | case FA_OPS_LOCATE: | |
53 | state = FSB_LOCATE; | |
54 | break; | |
55 | ||
56 | case FA_OPS_ERASE: | |
57 | state = FSB_ERASE; | |
58 | break; | |
59 | ||
60 | default: | |
61 | return ftamlose (fti, FS_GEN_NOREASON, 0, NULLCP, | |
62 | "bad value for operation parameter"); | |
63 | } | |
64 | missingP (identity); | |
65 | missingP (fti); | |
66 | ||
67 | smask = sigioblock (); | |
68 | ||
69 | ftamPsig (fsb, sd); | |
70 | ||
71 | result = FAccessRequestAux (fsb, state, identity, lock, fti); | |
72 | ||
73 | (void) sigiomask (smask); | |
74 | ||
75 | return result; | |
76 | } | |
77 | ||
78 | /* \f */ | |
79 | ||
80 | static int FAccessRequestAux (fsb, state, identity, lock, fti) | |
81 | register struct ftamblk *fsb; | |
82 | int state; | |
83 | struct FADUidentity *identity; | |
84 | int lock; | |
85 | struct FTAMindication *fti; | |
86 | { | |
87 | int result; | |
88 | PE pe; | |
89 | struct PSAPindication pis; | |
90 | struct PSAPindication *pi = &pis; | |
91 | struct PSAPabort *pa = &pi -> pi_abort; | |
92 | register struct type_FTAM_PDU *pdu; | |
93 | register struct type_FTAM_F__LOCATE__request *req; | |
94 | ||
95 | if (!(fsb -> fsb_flags & FSB_INIT)) | |
96 | return ftamlose (fti, FS_GEN (fsb), 0, NULLCP, "not initiator"); | |
97 | if (fsb -> fsb_state != FSB_DATAIDLE) | |
98 | return ftamlose (fti, FS_GEN (fsb), 0, NULLCP, "wrong state"); | |
99 | if (!(fsb -> fsb_units & FUNIT_ACCESS)) | |
100 | return ftamlose (fti, FS_GEN (fsb), 0, NULLCP, | |
101 | "file access not allowed"); | |
102 | ||
103 | pe = NULLPE; | |
104 | if ((pdu = (struct type_FTAM_PDU *) calloc (1, sizeof *pdu)) == NULL) { | |
105 | no_mem: ; | |
106 | (void) ftamlose (fti, FS_GEN (fsb), 1, NULLCP, "out of memory"); | |
107 | out: ; | |
108 | if (pe) | |
109 | pe_free (pe); | |
110 | if (pdu) | |
111 | free_FTAM_PDU (pdu); | |
112 | if (fti -> fti_abort.fta_action == FACTION_PERM) | |
113 | freefsblk (fsb); | |
114 | return NOTOK; | |
115 | } | |
116 | /* F-ERASE-request is identical... */ | |
117 | pdu -> offset = state != FSB_LOCATE ? type_FTAM_PDU_f__erase__request | |
118 | : type_FTAM_PDU_f__locate__request; | |
119 | if ((req = (struct type_FTAM_F__LOCATE__request *) | |
120 | calloc (1, sizeof *req)) == NULL) | |
121 | goto no_mem; | |
122 | pdu -> un.f__locate__request = req; | |
123 | if ((req -> file__access__data__unit__identity = | |
124 | faduid2fpm (fsb, identity, fti)) == NULL) | |
125 | goto out; | |
126 | if ((fsb -> fsb_units & FUNIT_FADULOCK) && state == FSB_LOCATE) { | |
127 | if ((req -> fadu__lock = (struct type_FTAM_FADU__Lock *) | |
128 | calloc (1, sizeof *req -> fadu__lock)) | |
129 | == NULL) | |
130 | goto no_mem; | |
131 | req -> fadu__lock -> parm = lock ? int_FTAM_FADU__Lock_on | |
132 | : int_FTAM_FADU__Lock_off; | |
133 | } | |
134 | ||
135 | if (encode_FTAM_PDU (&pe, 1, 0, NULLCP, pdu) == NOTOK) { | |
136 | (void) ftamlose (fti, FS_GEN (fsb), 1, NULLCP, | |
137 | "error encoding PDU: %s", PY_pepy); | |
138 | goto out; | |
139 | } | |
140 | ||
141 | pe -> pe_context = fsb -> fsb_id; | |
142 | ||
143 | fsbtrace (fsb, (fsb -> fsb_fd, "P-DATA.REQUEST", | |
144 | state == FSB_LOCATE ? "F-LOCATE-request" | |
145 | : "F-ERASE-request", pe, 0)); | |
146 | ||
147 | result = PDataRequest (fsb -> fsb_fd, &pe, 1, pi); | |
148 | ||
149 | pe_free (pe); | |
150 | pe = NULLPE; | |
151 | free_FTAM_PDU (pdu); | |
152 | pdu = NULL; | |
153 | ||
154 | if (result == NOTOK) { | |
155 | (void) ps2ftamlose (fsb, fti, "PDataRequest", pa); | |
156 | goto out; | |
157 | } | |
158 | ||
159 | fsb -> fsb_state = state; | |
160 | ||
161 | return FWaitRequestAux (fsb, NOTOK, fti); | |
162 | } |