Bug Summary

File:afs/VNOPS/afs_vnop_symlink.c
Location:line 254, column 19
Description:The left operand of '+' is a garbage value

Annotated Source Code

1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
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
8 */
9
10/*
11 * afs_vnop_symlink.c - symlink and readlink vnodeops.
12 *
13 * Implements:
14 * afs_symlink
15 * afs_MemHandleLink
16 * afs_UFSHandleLink
17 * afs_readlink
18 *
19 */
20
21#include <afsconfig.h>
22#include "afs/param.h"
23
24
25#include "afs/sysincludes.h" /* Standard vendor system headers */
26#include "afsincludes.h" /* Afs-based standard headers */
27#include "afs/afs_stats.h" /* statistics */
28#include "afs/afs_cbqueue.h"
29#include "afs/nfsclient.h"
30#include "afs/afs_osidnlc.h"
31
32extern afs_rwlock_t afs_xvcache;
33extern afs_rwlock_t afs_xcbhash;
34
35/* Note: There is the bare bones beginning of symlink hints in the now
36 * defunct afs/afs_lookup.c file. Since they are not in use, making the call
37 * is just a performance hit.
38 */
39
40static int
41afs_DisconCreateSymlink(struct vcache *avc, char *aname,
42 struct vrequest *areq) {
43 struct dcache *tdc;
44 struct osi_file *tfile;
45 afs_size_t offset, len;
46
47 tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0);
48 if (!tdc) {
49 /* printf("afs_DisconCreateSymlink: can't get new dcache for symlink.\n"); */
50 return ENOENT2;
51 }
52
53 len = strlen(aname);
54 avc->f.m.Length = len;
55
56 ObtainWriteLock(&tdc->lock, 720)do { ; if (!(&tdc->lock)->excl_locked && !(
&tdc->lock)->readers_reading) (&tdc->lock) ->
excl_locked = 2; else Afs_Lock_Obtain(&tdc->lock, 2);
(&tdc->lock)->pid_writer = (((__curthread())->td_proc
)->p_pid ); (&tdc->lock)->src_indicator = 720; }
while (0)
;
57 afs_AdjustSize(tdc, len);
58 tdc->validPos = len;
59 tfile = afs_CFileOpen(&tdc->f.inode)(void *)(*(afs_cacheType->open))(&tdc->f.inode);
60 afs_CFileWrite(tfile, 0, aname, len)(*(afs_cacheType->fwrite))(tfile, 0, aname, len);
61 afs_CFileClose(tfile)(*(afs_cacheType->close))(tfile);
62 ReleaseWriteLock(&tdc->lock)do { ; (&tdc->lock)->excl_locked &= ~2; if ((&
tdc->lock)->wait_states) Afs_Lock_ReleaseR(&tdc->
lock); (&tdc->lock)->pid_writer=0; } while (0)
;
63 return 0;
64}
65
66/* don't set CDirty in here because RPC is called synchronously */
67int
68afs_symlink(OSI_VC_DECL(adp)struct vcache *adp, char *aname, struct vattr *attrs,
69 char *atargetName, afs_ucred_t *acred)
70{
71 afs_uint32 now = 0;
72 struct vrequest treq;
73 afs_int32 code = 0;
74 struct afs_conn *tc;
75 struct VenusFid newFid;
76 struct dcache *tdc;
77 afs_size_t offset, len;
78 afs_int32 alen;
79 struct server *hostp = 0;
80 struct vcache *tvc;
81 struct AFSStoreStatus InStatus;
82 struct AFSFetchStatus OutFidStatus, OutDirStatus;
83 struct AFSCallBack CallBack;
84 struct AFSVolSync tsync;
85 struct volume *volp = 0;
86 struct afs_fakestat_state fakestate;
87 struct rx_connection *rxconn;
88 XSTATS_DECLSstruct afs_stats_opTimingData *opP = ((void *)0); osi_timeval_t
opStartTime = { 0, 0}, opStopTime, elapsedTime
;
89 OSI_VC_CONVERT(adp);
90
91 AFS_STATCNT(afs_symlink)((afs_cmstats.callInfo.C_afs_symlink)++);
92 afs_Trace2(afs_iclSetp, CM_TRACE_SYMLINK, ICL_TYPE_POINTER, adp,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event2(afs_iclSetp, (701087831L), (1<<24)+((2)
<<18)+((4)<<12), (long)(adp), (long)(aname)) : 0)
93 ICL_TYPE_STRING, aname)(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event2(afs_iclSetp, (701087831L), (1<<24)+((2)
<<18)+((4)<<12), (long)(adp), (long)(aname)) : 0)
;
94
95 if ((code = afs_InitReq(&treq, acred)))
1
Taking false branch
96 goto done2;
97
98 afs_InitFakeStat(&fakestate);
99
100 AFS_DISCON_LOCK()do { ; if (!((&afs_discon_lock)->excl_locked & 2))
((&afs_discon_lock)->readers_reading)++; else Afs_Lock_Obtain
(&afs_discon_lock, 1); (&afs_discon_lock)->pid_last_reader
= (((__curthread())->td_proc)->p_pid ); } while (0)
;
101
102 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
103 if (code)
2
Taking false branch
104 goto done;
105
106 if (strlen(aname) > AFSNAMEMAX256 || strlen(atargetName) > AFSPATHMAX1024) {
3
Taking false branch
107 code = ENAMETOOLONG63;
108 goto done;
109 }
110
111 if (afs_IsDynroot(adp)) {
4
Taking false branch
112 code = afs_DynrootVOPSymlink(adp, acred, aname, atargetName);
113 goto done;
114 }
115 if (afs_IsDynrootMount(adp)) {
5
Taking false branch
116 code = EROFS30;
117 goto done;
118 }
119
120 code = afs_VerifyVCache(adp, &treq)(((adp)->f.states & 0x00000001) ? 0 : afs_VerifyVCache2
((adp),&treq))
;
121 if (code) {
6
Taking false branch
122 code = afs_CheckCode(code, &treq, 30);
123 goto done;
124 }
125
126 /** If the volume is read-only, return error without making an RPC to the
127 * fileserver
128 */
129 if (adp->f.states & CRO0x00000004) {
7
Taking false branch
130 code = EROFS30;
131 goto done;
132 }
133
134 if (AFS_IS_DISCONNECTED(afs_is_disconnected) && !AFS_IS_DISCON_RW(afs_is_discon_rw)) {
8
Taking false branch
135 code = ENETDOWN50;
136 goto done;
137 }
138
139 InStatus.Mask = AFS_SETMODTIME1 | AFS_SETMODE8;
140 InStatus.ClientModTime = osi_Time()time_second;
141 alen = strlen(atargetName); /* we want it to include the null */
142 if ( (*atargetName == '#' || *atargetName == '%') && alen > 1 && atargetName[alen-1] == '.') {
9
Taking false branch
143 InStatus.UnixModeBits = 0644; /* mt pt: null from "." at end */
144 if (alen == 1)
145 alen++; /* Empty string */
146 } else {
147 InStatus.UnixModeBits = 0755;
148 alen++; /* add in the null */
149 }
150 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1);
151 volp = afs_FindVolume(&adp->f.fid, READ_LOCK1); /*parent is also in same vol */
152 ObtainWriteLock(&adp->lock, 156)do { ; if (!(&adp->lock)->excl_locked && !(
&adp->lock)->readers_reading) (&adp->lock) ->
excl_locked = 2; else Afs_Lock_Obtain(&adp->lock, 2);
(&adp->lock)->pid_writer = (((__curthread())->td_proc
)->p_pid ); (&adp->lock)->src_indicator = 156; }
while (0)
;
153 if (tdc)
10
Taking false branch
154 ObtainWriteLock(&tdc->lock, 636)do { ; if (!(&tdc->lock)->excl_locked && !(
&tdc->lock)->readers_reading) (&tdc->lock) ->
excl_locked = 2; else Afs_Lock_Obtain(&tdc->lock, 2);
(&tdc->lock)->pid_writer = (((__curthread())->td_proc
)->p_pid ); (&tdc->lock)->src_indicator = 636; }
while (0)
;
155 /* No further locks: if the SymLink succeeds, it does not matter what happens
156 * to our local copy of the directory. If somebody tampers with it in the meantime,
157 * the copy will be invalidated */
158 if (!AFS_IS_DISCON_RW(afs_is_discon_rw)) {
11
Taking false branch
159 do {
160 tc = afs_Conn(&adp->f.fid, &treq, SHARED_LOCK4, &rxconn);
161 if (tc) {
162 hostp = tc->parent->srvr->server;
163 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SYMLINK)opP = &(afs_stats_cmfullperf.rpc.fsRPCTimes[9]); microtime
(&opStartTime);
;
164 if (adp->f.states & CForeign0x00002000) {
165 now = osi_Time()time_second;
166 RX_AFS_GUNLOCK()do { (void)0; _mtx_unlock_flags(((&afs_global_mtx)), (0),
"/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c", 166
); } while (0)
;
167 code =
168 RXAFS_DFSSymlink(rxconn,
169 (struct AFSFid *)&adp->f.fid.Fid,
170 aname, atargetName, &InStatus,
171 (struct AFSFid *)&newFid.Fid,
172 &OutFidStatus, &OutDirStatus,
173 &CallBack, &tsync);
174 RX_AFS_GLOCK()do { (void)0; _mtx_lock_flags(((&afs_global_mtx)), (0), "/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c"
, 174); (void)0; } while (0)
;
175 } else {
176 RX_AFS_GUNLOCK()do { (void)0; _mtx_unlock_flags(((&afs_global_mtx)), (0),
"/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c", 176
); } while (0)
;
177 code =
178 RXAFS_Symlink(rxconn, (struct AFSFid *)&adp->f.fid.Fid,
179 aname, atargetName, &InStatus,
180 (struct AFSFid *)&newFid.Fid,
181 &OutFidStatus, &OutDirStatus, &tsync);
182 RX_AFS_GLOCK()do { (void)0; _mtx_lock_flags(((&afs_global_mtx)), (0), "/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c"
, 182); (void)0; } while (0)
;
183 }
184 XSTATS_END_TIMEmicrotime(&opStopTime); (opP->numOps)++; if (!code) { (
opP->numSuccesses)++; { if (opStopTime.tv_usec < opStartTime
.tv_usec) { opStopTime.tv_usec += 1000000; opStopTime.tv_sec -=
1; } elapsedTime.tv_sec = opStopTime.tv_sec - opStartTime.tv_sec
; elapsedTime.tv_usec = opStopTime.tv_usec - opStartTime.tv_usec
; }; { (opP->sumTime).tv_sec += elapsedTime.tv_sec; (opP->
sumTime).tv_usec += elapsedTime.tv_usec; if ((opP->sumTime
).tv_usec > 1000000) { (opP->sumTime).tv_usec -= 1000000
; (opP->sumTime).tv_sec++; } }; { if(elapsedTime.tv_sec >
0 ) { (opP->sqrTime).tv_sec += elapsedTime.tv_sec * elapsedTime
.tv_sec + 2 * elapsedTime.tv_sec * elapsedTime.tv_usec /1000000
; (opP->sqrTime).tv_usec += (2 * elapsedTime.tv_sec * elapsedTime
.tv_usec) % 1000000 + (elapsedTime.tv_usec / 1000)*(elapsedTime
.tv_usec / 1000) + 2 * (elapsedTime.tv_usec / 1000) * (elapsedTime
.tv_usec % 1000) / 1000 + (((elapsedTime.tv_usec % 1000) >
707) ? 1 : 0); } else { (opP->sqrTime).tv_usec += (elapsedTime
.tv_usec / 1000)*(elapsedTime.tv_usec / 1000) + 2 * (elapsedTime
.tv_usec / 1000) * (elapsedTime.tv_usec % 1000) / 1000 + (((elapsedTime
.tv_usec % 1000) > 707) ? 1 : 0); } if ((opP->sqrTime).
tv_usec > 1000000) { (opP->sqrTime).tv_usec -= 1000000;
(opP->sqrTime).tv_sec++; } }; if (((elapsedTime.tv_sec <
(opP->minTime).tv_sec) ? 1 : (elapsedTime.tv_sec > (opP
->minTime).tv_sec) ? 0 : (elapsedTime.tv_usec < (opP->
minTime).tv_usec) ? 1 : 0)) { { (opP->minTime).tv_sec = elapsedTime
.tv_sec; (opP->minTime).tv_usec = elapsedTime.tv_usec; }; }
if (((elapsedTime.tv_sec > (opP->maxTime).tv_sec) ? 1 :
(elapsedTime.tv_sec < (opP->maxTime).tv_sec) ? 0 : (elapsedTime
.tv_usec > (opP->maxTime).tv_usec) ? 1 : 0)) { { (opP->
maxTime).tv_sec = elapsedTime.tv_sec; (opP->maxTime).tv_usec
= elapsedTime.tv_usec; }; } }
;
185 } else
186 code = -1;
187 } while (afs_Analyze
188 (tc, rxconn, code, &adp->f.fid, &treq, AFS_STATS_FS_RPCIDX_SYMLINK9,
189 SHARED_LOCK4, NULL((void *)0)));
190 } else {
191 newFid.Cell = adp->f.fid.Cell;
192 newFid.Fid.Volume = adp->f.fid.Fid.Volume;
193 afs_GenFakeFid(&newFid, VREG, 0);
194 }
195
196 ObtainWriteLock(&afs_xvcache, 40)do { ; if (!(&afs_xvcache)->excl_locked && !(&
afs_xvcache)->readers_reading) (&afs_xvcache) -> excl_locked
= 2; else Afs_Lock_Obtain(&afs_xvcache, 2); (&afs_xvcache
)->pid_writer = (((__curthread())->td_proc)->p_pid )
; (&afs_xvcache)->src_indicator = 40; } while (0)
;
197 if (code) {
12
Taking false branch
198 if (code < 0) {
199 ObtainWriteLock(&afs_xcbhash, 499)do { ; if (!(&afs_xcbhash)->excl_locked && !(&
afs_xcbhash)->readers_reading) (&afs_xcbhash) -> excl_locked
= 2; else Afs_Lock_Obtain(&afs_xcbhash, 2); (&afs_xcbhash
)->pid_writer = (((__curthread())->td_proc)->p_pid )
; (&afs_xcbhash)->src_indicator = 499; } while (0)
;
200 afs_DequeueCallback(adp);
201 adp->f.states &= ~CStatd0x00000001;
202 ReleaseWriteLock(&afs_xcbhash)do { ; (&afs_xcbhash)->excl_locked &= ~2; if ((&
afs_xcbhash)->wait_states) Afs_Lock_ReleaseR(&afs_xcbhash
); (&afs_xcbhash)->pid_writer=0; } while (0)
;
203 osi_dnlc_purgedp(adp);
204 }
205 ReleaseWriteLock(&adp->lock)do { ; (&adp->lock)->excl_locked &= ~2; if ((&
adp->lock)->wait_states) Afs_Lock_ReleaseR(&adp->
lock); (&adp->lock)->pid_writer=0; } while (0)
;
206 ReleaseWriteLock(&afs_xvcache)do { ; (&afs_xvcache)->excl_locked &= ~2; if ((&
afs_xvcache)->wait_states) Afs_Lock_ReleaseR(&afs_xvcache
); (&afs_xvcache)->pid_writer=0; } while (0)
;
207 if (tdc) {
208 ReleaseWriteLock(&tdc->lock)do { ; (&tdc->lock)->excl_locked &= ~2; if ((&
tdc->lock)->wait_states) Afs_Lock_ReleaseR(&tdc->
lock); (&tdc->lock)->pid_writer=0; } while (0)
;
209 afs_PutDCache(tdc);
210 }
211 goto done;
212 }
213 /* otherwise, we should see if we can make the change to the dir locally */
214 if (AFS_IS_DISCON_RW(afs_is_discon_rw) || afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
13
Taking false branch
215 /* we can do it locally */
216 ObtainWriteLock(&afs_xdcache, 293)do { ; if (!(&afs_xdcache)->excl_locked && !(&
afs_xdcache)->readers_reading) (&afs_xdcache) -> excl_locked
= 2; else Afs_Lock_Obtain(&afs_xdcache, 2); (&afs_xdcache
)->pid_writer = (((__curthread())->td_proc)->p_pid )
; (&afs_xdcache)->src_indicator = 293; } while (0)
;
217 /* If the following fails because the name has been created in the meantime, the
218 * directory is out-of-date - the file server knows best! */
219 code = afs_dir_Create(tdc, aname, &newFid.Fid);
220 ReleaseWriteLock(&afs_xdcache)do { ; (&afs_xdcache)->excl_locked &= ~2; if ((&
afs_xdcache)->wait_states) Afs_Lock_ReleaseR(&afs_xdcache
); (&afs_xdcache)->pid_writer=0; } while (0)
;
221 if (code && !AFS_IS_DISCON_RW(afs_is_discon_rw)) {
222 ZapDCE(tdc)do { (tdc)->f.fid.Fid.Unique = 0; afs_indexUnique[(tdc)->
index] = 0; (tdc)->dflags |= 0x02; } while(0)
; /* surprise error -- use invalid value */
223 DZap(tdc);
224 }
225 }
226 if (tdc) {
14
Taking false branch
227 ReleaseWriteLock(&tdc->lock)do { ; (&tdc->lock)->excl_locked &= ~2; if ((&
tdc->lock)->wait_states) Afs_Lock_ReleaseR(&tdc->
lock); (&tdc->lock)->pid_writer=0; } while (0)
;
228 afs_PutDCache(tdc);
229 }
230 newFid.Cell = adp->f.fid.Cell;
231 newFid.Fid.Volume = adp->f.fid.Fid.Volume;
232 ReleaseWriteLock(&adp->lock)do { ; (&adp->lock)->excl_locked &= ~2; if ((&
adp->lock)->wait_states) Afs_Lock_ReleaseR(&adp->
lock); (&adp->lock)->pid_writer=0; } while (0)
;
233
234 /* now we're done with parent dir, create the link's entry. Note that
235 * no one can get a pointer to the new cache entry until we release
236 * the xvcache lock. */
237 tvc = afs_NewVCache(&newFid, hostp);
238 if (!tvc)
15
Taking false branch
239 {
240 code = -2;
241 ReleaseWriteLock(&afs_xvcache)do { ; (&afs_xvcache)->excl_locked &= ~2; if ((&
afs_xvcache)->wait_states) Afs_Lock_ReleaseR(&afs_xvcache
); (&afs_xvcache)->pid_writer=0; } while (0)
;
242 goto done;
243 }
244 ObtainWriteLock(&tvc->lock, 157)do { ; if (!(&tvc->lock)->excl_locked && !(
&tvc->lock)->readers_reading) (&tvc->lock) ->
excl_locked = 2; else Afs_Lock_Obtain(&tvc->lock, 2);
(&tvc->lock)->pid_writer = (((__curthread())->td_proc
)->p_pid ); (&tvc->lock)->src_indicator = 157; }
while (0)
;
245 ObtainWriteLock(&afs_xcbhash, 500)do { ; if (!(&afs_xcbhash)->excl_locked && !(&
afs_xcbhash)->readers_reading) (&afs_xcbhash) -> excl_locked
= 2; else Afs_Lock_Obtain(&afs_xcbhash, 2); (&afs_xcbhash
)->pid_writer = (((__curthread())->td_proc)->p_pid )
; (&afs_xcbhash)->src_indicator = 500; } while (0)
;
246 tvc->f.states |= CStatd0x00000001; /* have valid info */
247 tvc->f.states &= ~CBulkFetching0x04000000;
248
249 if (adp->f.states & CForeign0x00002000) {
16
Taking true branch
250 tvc->f.states |= CForeign0x00002000;
251 /* We don't have to worry about losing the callback since we're doing it
252 * under the afs_xvcache lock actually, afs_NewVCache may drop the
253 * afs_xvcache lock, if it calls afs_FlushVCache */
254 tvc->cbExpires = CallBack.ExpirationTime + now;
17
The left operand of '+' is a garbage value
255 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime)((CallBack.ExpirationTime)>>7), volp);
256 } else {
257 tvc->cbExpires = 0x7fffffff; /* never expires, they can't change */
258 /* since it never expires, we don't have to queue the callback */
259 }
260 ReleaseWriteLock(&afs_xcbhash)do { ; (&afs_xcbhash)->excl_locked &= ~2; if ((&
afs_xcbhash)->wait_states) Afs_Lock_ReleaseR(&afs_xcbhash
); (&afs_xcbhash)->pid_writer=0; } while (0)
;
261
262 if (AFS_IS_DISCON_RW(afs_is_discon_rw)) {
263 attrs->va_mode = InStatus.UnixModeBits;
264 afs_GenDisconStatus(adp, tvc, &newFid, attrs, &treq, VLNK);
265 code = afs_DisconCreateSymlink(tvc, atargetName, &treq);
266 if (code) {
267 /* XXX - When this goes wrong, we need to tidy up the changes we made to
268 * the parent, and get rid of the vcache we just created */
269 ReleaseWriteLock(&tvc->lock)do { ; (&tvc->lock)->excl_locked &= ~2; if ((&
tvc->lock)->wait_states) Afs_Lock_ReleaseR(&tvc->
lock); (&tvc->lock)->pid_writer=0; } while (0)
;
270 ReleaseWriteLock(&afs_xvcache)do { ; (&afs_xvcache)->excl_locked &= ~2; if ((&
afs_xvcache)->wait_states) Afs_Lock_ReleaseR(&afs_xvcache
); (&afs_xvcache)->pid_writer=0; } while (0)
;
271 afs_PutVCache(tvc);
272 goto done;
273 }
274 afs_DisconAddDirty(tvc, VDisconCreate0x00004000, 0);
275 } else {
276 afs_ProcessFS(tvc, &OutFidStatus, &treq);
277 }
278
279 if (!tvc->linkData) {
280 tvc->linkData = afs_osi_Alloc(alen);
281 osi_Assert(tvc->linkData != NULL)(void)((tvc->linkData != ((void *)0)) || (osi_AssertFailK(
"tvc->linkData != NULL" , "/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c"
, 281), 0))
;
282 strncpy(tvc->linkData, atargetName, alen - 1);
283 tvc->linkData[alen - 1] = 0;
284 }
285 ReleaseWriteLock(&tvc->lock)do { ; (&tvc->lock)->excl_locked &= ~2; if ((&
tvc->lock)->wait_states) Afs_Lock_ReleaseR(&tvc->
lock); (&tvc->lock)->pid_writer=0; } while (0)
;
286 ReleaseWriteLock(&afs_xvcache)do { ; (&afs_xvcache)->excl_locked &= ~2; if ((&
afs_xvcache)->wait_states) Afs_Lock_ReleaseR(&afs_xvcache
); (&afs_xvcache)->pid_writer=0; } while (0)
;
287 afs_PutVCache(tvc);
288 code = 0;
289 done:
290 afs_PutFakeStat(&fakestate);
291 if (volp)
292 afs_PutVolume(volp, READ_LOCK)((volp)->refCount--);
293 AFS_DISCON_UNLOCK()do { ; if (!(--((&afs_discon_lock)->readers_reading)) &&
(&afs_discon_lock)->wait_states) Afs_Lock_ReleaseW(&
afs_discon_lock) ; if ( (&afs_discon_lock)->pid_last_reader
== (((__curthread())->td_proc)->p_pid ) ) (&afs_discon_lock
)->pid_last_reader =0; } while (0)
;
294 code = afs_CheckCode(code, &treq, 31);
295 done2:
296 return code;
297}
298
299int
300afs_MemHandleLink(struct vcache *avc, struct vrequest *areq)
301{
302 struct dcache *tdc;
303 char *tp, *rbuf;
304 afs_size_t offset, len;
305 afs_int32 tlen, alen;
306 afs_int32 code;
307
308 AFS_STATCNT(afs_MemHandleLink)((afs_cmstats.callInfo.C_afs_MemHandleLink)++);
309 /* two different formats, one for links protected 644, have a "." at
310 * the end of the file name, which we turn into a null. Others,
311 * protected 755, we add a null to the end of */
312 if (!avc->linkData) {
313 void *addr;
314 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 0);
315 if (!tdc) {
316 return EIO5;
317 }
318 /* otherwise we have the data loaded, go for it */
319 if (len > 1024) {
320 afs_PutDCache(tdc);
321 return EFAULT14;
322 }
323 if (avc->f.m.Mode & 0111)
324 alen = len + 1; /* regular link */
325 else
326 alen = len; /* mt point */
327 rbuf = (char *)osi_AllocLargeSpace(AFS_LRALLOCSIZ4096);
328 ObtainReadLock(&tdc->lock)do { ; if (!((&tdc->lock)->excl_locked & 2)) ((
&tdc->lock)->readers_reading)++; else Afs_Lock_Obtain
(&tdc->lock, 1); (&tdc->lock)->pid_last_reader
= (((__curthread())->td_proc)->p_pid ); } while (0)
;
329 addr = afs_MemCacheOpen(&tdc->f.inode);
330 tlen = len;
331 code = afs_MemReadBlk(addr, 0, rbuf, tlen);
332 afs_MemCacheClose(addr);
333 ReleaseReadLock(&tdc->lock)do { ; if (!(--((&tdc->lock)->readers_reading)) &&
(&tdc->lock)->wait_states) Afs_Lock_ReleaseW(&
tdc->lock) ; if ( (&tdc->lock)->pid_last_reader ==
(((__curthread())->td_proc)->p_pid ) ) (&tdc->lock
)->pid_last_reader =0; } while (0)
;
334 afs_PutDCache(tdc);
335 rbuf[alen - 1] = 0;
336 alen = strlen(rbuf) + 1;
337 tp = afs_osi_Alloc(alen); /* make room for terminating null */
338 osi_Assert(tp != NULL)(void)((tp != ((void *)0)) || (osi_AssertFailK( "tp != NULL" ,
"/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c", 338
), 0))
;
339 memcpy(tp, rbuf, alen);
340 osi_FreeLargeSpace(rbuf);
341 if (code != len) {
342 afs_osi_Free(tp, alen);
343 return EIO5;
344 }
345 avc->linkData = tp;
346 }
347 return 0;
348}
349
350int
351afs_UFSHandleLink(struct vcache *avc, struct vrequest *areq)
352{
353 struct dcache *tdc;
354 char *tp, *rbuf;
355 void *tfile;
356 afs_size_t offset, len;
357 afs_int32 tlen, alen;
358 afs_int32 code;
359
360 /* two different formats, one for links protected 644, have a "." at the
361 * end of the file name, which we turn into a null. Others, protected
362 * 755, we add a null to the end of */
363 AFS_STATCNT(afs_UFSHandleLink)((afs_cmstats.callInfo.C_afs_UFSHandleLink)++);
364 if (!avc->linkData) {
365 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 0);
366 afs_Trace3(afs_iclSetp, CM_TRACE_UFSLINK, ICL_TYPE_POINTER, avc,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event3(afs_iclSetp, (701087862L), (1<<24)+((2)
<<18)+((2)<<12)+((8)<<6), (long)(avc), (long
)(tdc), (long)((&avc->f.m.Length))) : 0)
367 ICL_TYPE_POINTER, tdc, ICL_TYPE_OFFSET,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event3(afs_iclSetp, (701087862L), (1<<24)+((2)
<<18)+((2)<<12)+((8)<<6), (long)(avc), (long
)(tdc), (long)((&avc->f.m.Length))) : 0)
368 ICL_HANDLE_OFFSET(avc->f.m.Length))(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event3(afs_iclSetp, (701087862L), (1<<24)+((2)
<<18)+((2)<<12)+((8)<<6), (long)(avc), (long
)(tdc), (long)((&avc->f.m.Length))) : 0)
;
369 if (!tdc) {
370 if (AFS_IS_DISCONNECTED(afs_is_disconnected))
371 return ENETDOWN50;
372 else
373 return EIO5;
374 }
375 /* otherwise we have the data loaded, go for it */
376 if (len > 1024) {
377 afs_PutDCache(tdc);
378 return EFAULT14;
379 }
380 if (avc->f.m.Mode & 0111)
381 alen = len + 1; /* regular link */
382 else
383 alen = len; /* mt point */
384 rbuf = (char *)osi_AllocLargeSpace(AFS_LRALLOCSIZ4096);
385 tlen = len;
386 ObtainReadLock(&tdc->lock)do { ; if (!((&tdc->lock)->excl_locked & 2)) ((
&tdc->lock)->readers_reading)++; else Afs_Lock_Obtain
(&tdc->lock, 1); (&tdc->lock)->pid_last_reader
= (((__curthread())->td_proc)->p_pid ); } while (0)
;
387 tfile = osi_UFSOpen(&tdc->f.inode);
388 code = afs_osi_Read(tfile, -1, rbuf, tlen);
389 osi_UFSClose(tfile);
390 ReleaseReadLock(&tdc->lock)do { ; if (!(--((&tdc->lock)->readers_reading)) &&
(&tdc->lock)->wait_states) Afs_Lock_ReleaseW(&
tdc->lock) ; if ( (&tdc->lock)->pid_last_reader ==
(((__curthread())->td_proc)->p_pid ) ) (&tdc->lock
)->pid_last_reader =0; } while (0)
;
391 afs_PutDCache(tdc);
392 rbuf[alen - 1] = '\0';
393 alen = strlen(rbuf) + 1;
394 tp = afs_osi_Alloc(alen); /* make room for terminating null */
395 osi_Assert(tp != NULL)(void)((tp != ((void *)0)) || (osi_AssertFailK( "tp != NULL" ,
"/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c", 395
), 0))
;
396 memcpy(tp, rbuf, alen);
397 osi_FreeLargeSpace(rbuf);
398 if (code != tlen) {
399 afs_osi_Free(tp, alen);
400 return EIO5;
401 }
402 avc->linkData = tp;
403 }
404 return 0;
405}
406
407int
408afs_readlink(OSI_VC_DECL(avc)struct vcache *avc, struct uio *auio, afs_ucred_t *acred)
409{
410 afs_int32 code;
411 struct vrequest treq;
412 char *tp;
413 struct afs_fakestat_state fakestat;
414 OSI_VC_CONVERT(avc);
415
416 AFS_STATCNT(afs_readlink)((afs_cmstats.callInfo.C_afs_readlink)++);
417 afs_Trace1(afs_iclSetp, CM_TRACE_READLINK, ICL_TYPE_POINTER, avc)(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event1(afs_iclSetp, (701087832L), (1<<24)+((2)
<<18), (long)(avc)) : 0)
;
418 if ((code = afs_InitReq(&treq, acred)))
419 return code;
420 afs_InitFakeStat(&fakestat);
421
422 AFS_DISCON_LOCK()do { ; if (!((&afs_discon_lock)->excl_locked & 2))
((&afs_discon_lock)->readers_reading)++; else Afs_Lock_Obtain
(&afs_discon_lock, 1); (&afs_discon_lock)->pid_last_reader
= (((__curthread())->td_proc)->p_pid ); } while (0)
;
423
424 code = afs_EvalFakeStat(&avc, &fakestat, &treq);
425 if (code)
426 goto done;
427 code = afs_VerifyVCache(avc, &treq)(((avc)->f.states & 0x00000001) ? 0 : afs_VerifyVCache2
((avc),&treq))
;
428 if (code)
429 goto done;
430 if (vType(avc)((avc)->v)->v_type != VLNK) {
431 code = EINVAL22;
432 goto done;
433 }
434 ObtainWriteLock(&avc->lock, 158)do { ; if (!(&avc->lock)->excl_locked && !(
&avc->lock)->readers_reading) (&avc->lock) ->
excl_locked = 2; else Afs_Lock_Obtain(&avc->lock, 2);
(&avc->lock)->pid_writer = (((__curthread())->td_proc
)->p_pid ); (&avc->lock)->src_indicator = 158; }
while (0)
;
435 code = afs_HandleLink(avc, &treq)(*(afs_cacheType->HandleLink))(avc, &treq);
436 /* finally uiomove it to user-land */
437 if (code == 0) {
438 tp = avc->linkData;
439 if (tp)
440 AFS_UIOMOVE(tp, strlen(tp), UIO_READ, auio, code)do { int haveGlock = ((((&afs_global_mtx)->mtx_lock &
~(0x00000001 | 0x00000002 | 0x00000004)) == (uintptr_t)(__curthread
()))); if (haveGlock) do { (void)0; _mtx_unlock_flags(((&
afs_global_mtx)), (0), "/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c"
, 440); } while (0); (auio)->uio_rw = (UIO_READ); code = uiomove
((tp),(strlen(tp)),(auio)); if (haveGlock) do { (void)0; _mtx_lock_flags
(((&afs_global_mtx)), (0), "/home/wollman/openafs/src/afs/VNOPS/afs_vnop_symlink.c"
, 440); (void)0; } while (0); } while(0)
;
441 else {
442 code = EIO5;
443 }
444 }
445 ReleaseWriteLock(&avc->lock)do { ; (&avc->lock)->excl_locked &= ~2; if ((&
avc->lock)->wait_states) Afs_Lock_ReleaseR(&avc->
lock); (&avc->lock)->pid_writer=0; } while (0)
;
446 done:
447 afs_PutFakeStat(&fakestat);
448 AFS_DISCON_UNLOCK()do { ; if (!(--((&afs_discon_lock)->readers_reading)) &&
(&afs_discon_lock)->wait_states) Afs_Lock_ReleaseW(&
afs_discon_lock) ; if ( (&afs_discon_lock)->pid_last_reader
== (((__curthread())->td_proc)->p_pid ) ) (&afs_discon_lock
)->pid_last_reader =0; } while (0)
;
449 code = afs_CheckCode(code, &treq, 32);
450 return code;
451}