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
11 * afs_vnop_symlink.c - symlink and readlink vnodeops.
21 #include <afsconfig.h>
22 #include "../afs/param.h"
26 #include "../afs/sysincludes.h" /* Standard vendor system headers */
27 #include "../afs/afsincludes.h" /* Afs-based standard headers */
28 #include "../afs/afs_stats.h" /* statistics */
29 #include "../afs/afs_cbqueue.h"
30 #include "../afs/nfsclient.h"
31 #include "../afs/afs_osidnlc.h"
33 extern afs_rwlock_t afs_xvcache;
34 extern afs_rwlock_t afs_xcbhash;
36 /* Note: There is the bare bones beginning of symlink hints in the now
37 * defunct afs/afs_lookup.c file. Since they are not in use, making the call
38 * is just a performance hit.
42 /* don't set CDirty in here because RPC is called synchronously */
45 (ndp, attrs, atargetName)
46 struct nameidata *ndp;
48 register char *atargetName; {
49 register struct vcache *adp = (struct vcache *)ndp->ni_dvp;
50 char *aname = ndp->ni_dent.d_name;
51 struct ucred *acred = ndp->ni_cred;
52 #else /* AFS_OSF_ENV */
53 (OSI_VC_ARG(adp), aname, attrs, atargetName, acred)
58 struct AFS_UCRED *acred; {
64 struct VenusFid newFid;
66 afs_int32 offset, len, alen;
67 struct server *hostp=0;
69 struct AFSStoreStatus InStatus;
70 struct AFSFetchStatus OutFidStatus, OutDirStatus;
71 struct AFSCallBack CallBack;
72 struct AFSVolSync tsync;
73 struct volume* volp=0;
77 AFS_STATCNT(afs_symlink);
78 afs_Trace2(afs_iclSetp, CM_TRACE_SYMLINK, ICL_TYPE_POINTER, adp,
79 ICL_TYPE_STRING, aname);
80 if (code = afs_InitReq(&treq, acred))
83 code = afs_VerifyVCache(adp, &treq);
85 code = afs_CheckCode(code, &treq, 30);
89 /** If the volume is read-only, return error without making an RPC to the
92 if ( adp->states & CRO ) {
97 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE;
98 InStatus.ClientModTime = osi_Time();
99 alen = strlen(atargetName); /* we want it to include the null */
100 if (*atargetName == '#' || *atargetName == '%') {
101 InStatus.UnixModeBits = 0644; /* mt pt: null from "." at end */
102 if (alen == 1) alen++; /* Empty string */
104 InStatus.UnixModeBits = 0755;
105 alen++; /* add in the null */
107 tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1);
108 volp = afs_FindVolume(&adp->fid, READ_LOCK); /*parent is also in same vol*/
109 ObtainWriteLock(&adp->lock,156);
110 ObtainSharedLock(&afs_xvcache,17); /* prevent others from creating this entry */
111 /* XXX Pay attention to afs_xvcache around the whole thing!! XXX */
113 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
115 hostp = tc->srvr->server;
116 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SYMLINK);
117 if (adp->states & CForeign) {
119 #ifdef RX_ENABLE_LOCKS
121 #endif /* RX_ENABLE_LOCKS */
122 code = RXAFS_DFSSymlink(tc->id, (struct AFSFid *) &adp->fid.Fid, aname,
123 atargetName, &InStatus, (struct AFSFid *) &newFid.Fid,
124 &OutFidStatus, &OutDirStatus, &CallBack, &tsync);
125 #ifdef RX_ENABLE_LOCKS
127 #endif /* RX_ENABLE_LOCKS */
129 #ifdef RX_ENABLE_LOCKS
131 #endif /* RX_ENABLE_LOCKS */
132 code = RXAFS_Symlink(tc->id, (struct AFSFid *) &adp->fid.Fid, aname,
133 atargetName, &InStatus, (struct AFSFid *) &newFid.Fid,
134 &OutFidStatus, &OutDirStatus, &tsync);
135 #ifdef RX_ENABLE_LOCKS
137 #endif /* RX_ENABLE_LOCKS */
143 (afs_Analyze(tc, code, &adp->fid, &treq,
144 AFS_STATS_FS_RPCIDX_SYMLINK, SHARED_LOCK, (struct cell *)0));
146 UpgradeSToWLock(&afs_xvcache,40);
149 ObtainWriteLock(&afs_xcbhash, 499);
150 afs_DequeueCallback(adp);
151 adp->states &= ~CStatd;
152 ReleaseWriteLock(&afs_xcbhash);
153 osi_dnlc_purgedp(adp);
155 ReleaseWriteLock(&adp->lock);
156 ReleaseWriteLock(&afs_xvcache);
157 if (tdc) afs_PutDCache(tdc);
160 /* otherwise, we should see if we can make the change to the dir locally */
161 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
162 /* we can do it locally */
163 code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid);
165 ZapDCE(tdc); /* surprise error -- use invalid value */
172 newFid.Cell = adp->fid.Cell;
173 newFid.Fid.Volume = adp->fid.Fid.Volume;
174 ReleaseWriteLock(&adp->lock);
176 /* now we're done with parent dir, create the link's entry. Note that
177 * no one can get a pointer to the new cache entry until we release
178 * the xvcache lock. */
179 tvc = afs_NewVCache(&newFid, hostp, 1, WRITE_LOCK);
180 ObtainWriteLock(&tvc->lock,157);
181 ObtainWriteLock(&afs_xcbhash, 500);
182 tvc->states |= CStatd; /* have valid info */
183 tvc->states &= ~CBulkFetching;
185 if (adp->states & CForeign) {
186 tvc->states |= CForeign;
187 /* We don't have to worry about losing the callback since we're doing it
188 * under the afs_xvcache lock actually, afs_NewVCache may drop the
189 * afs_xvcache lock, if it calls afs_FlushVCache */
190 tvc->cbExpires = CallBack.ExpirationTime + now;
191 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), volp);
193 tvc->cbExpires = 0x7fffffff; /* never expires, they can't change */
194 /* since it never expires, we don't have to queue the callback */
196 ReleaseWriteLock(&afs_xcbhash);
197 afs_ProcessFS(tvc, &OutFidStatus, &treq);
199 if (!tvc->linkData) {
200 tvc->linkData = (char *) afs_osi_Alloc(alen);
201 strncpy(tvc->linkData, atargetName, alen-1);
202 tvc->linkData[alen-1] = 0;
204 ReleaseWriteLock(&tvc->lock);
205 ReleaseWriteLock(&afs_xvcache);
206 afs_PutVCache(tvc, WRITE_LOCK);
210 AFS_RELE(ndp->ni_dvp);
211 #endif /* AFS_OSF_ENV */
213 afs_PutVolume(volp, READ_LOCK);
214 code = afs_CheckCode(code, &treq, 31);
218 afs_MemHandleLink(avc, areq)
219 register struct vcache *avc;
220 struct vrequest *areq;
222 register struct dcache *tdc;
224 afs_int32 offset, len, alen;
225 register afs_int32 code;
227 AFS_STATCNT(afs_MemHandleLink);
228 /* two different formats, one for links protected 644, have a "." at
229 the end of the file name, which we turn into a null. Others,
230 protected 755, we add a null to the end of */
231 if (!avc->linkData) {
233 tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0);
237 /* otherwise we have the data loaded, go for it */
242 if (avc->m.Mode & 0111) alen = len+1; /* regular link */
243 else alen = len; /* mt point */
244 tp = afs_osi_Alloc(alen); /* make room for terminating null */
245 addr = afs_MemCacheOpen(tdc->f.inode);
246 code = afs_MemReadBlk(addr, 0, tp, len);
250 afs_osi_Free(tp, alen);
258 afs_UFSHandleLink(avc, areq)
259 register struct vcache *avc;
260 struct vrequest *areq; {
261 register struct dcache *tdc;
264 afs_int32 offset, len, alen;
265 register afs_int32 code;
267 /* two different formats, one for links protected 644, have a "." at the end
268 of the file name, which we turn into a null. Others, protected 755,
269 we add a null to the end of */
270 AFS_STATCNT(afs_UFSHandleLink);
271 if (!avc->linkData) {
272 tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0);
276 /* otherwise we have the data loaded, go for it */
281 tfile = osi_UFSOpen (tdc->f.inode);
282 if (avc->m.Mode & 0111) alen = len+1; /* regular link */
283 else alen = len; /* mt point */
284 tp = afs_osi_Alloc(alen); /* make room for terminating null */
285 code = afs_osi_Read(tfile, -1, tp, len);
290 afs_osi_Free(tp, alen);
298 afs_readlink(OSI_VC_ARG(avc), auio, acred)
301 struct AFS_UCRED *acred; {
302 register afs_int32 code;
303 struct vrequest treq;
307 AFS_STATCNT(afs_readlink);
308 afs_Trace1(afs_iclSetp, CM_TRACE_READLINK, ICL_TYPE_POINTER, avc);
309 if (code = afs_InitReq(&treq, acred)) return code;
310 code = afs_VerifyVCache(avc, &treq);
312 if (vType(avc) != VLNK) {
316 ObtainWriteLock(&avc->lock,158);
317 code = afs_HandleLink(avc, &treq);
318 /* finally uiomove it to user-land */
321 if (tp) AFS_UIOMOVE(tp, strlen(tp), UIO_READ, auio, code);
326 ReleaseWriteLock(&avc->lock);
328 code = afs_CheckCode(code, &treq, 32);