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_dirops.c - make and remove directories
20 #include <afsconfig.h>
21 #include "afs/param.h"
26 #include "afs/sysincludes.h" /* Standard vendor system headers */
27 #include "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 /* don't set CDirty in here because RPC is called synchronously */
41 struct nameidata *ndp;
44 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
45 char *aname = ndp->ni_dent.d_name;
46 register struct vcache **avcp = (struct vcache **)&(ndp->ni_vp);
47 struct ucred *acred = ndp->ni_cred;
48 #else /* AFS_OSF_ENV */
49 afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred)
51 register struct vcache **avcp;
54 struct AFS_UCRED *acred;
58 register afs_int32 code;
59 register struct conn *tc;
60 struct VenusFid newFid;
61 register struct dcache *tdc;
62 afs_size_t offset, len;
63 register struct vcache *tvc;
64 struct AFSStoreStatus InStatus;
65 struct AFSFetchStatus OutFidStatus, OutDirStatus;
66 struct AFSCallBack CallBack;
67 struct AFSVolSync tsync;
69 struct afs_fakestat_state fakestate;
70 XSTATS_DECLS OSI_VC_CONVERT(adp)
72 AFS_STATCNT(afs_mkdir);
73 afs_Trace2(afs_iclSetp, CM_TRACE_MKDIR, ICL_TYPE_POINTER, adp,
74 ICL_TYPE_STRING, aname);
76 if ((code = afs_InitReq(&treq, acred)))
78 afs_InitFakeStat(&fakestate);
80 if (strlen(aname) > AFSNAMEMAX) {
85 if (!afs_ENameOK(aname)) {
89 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
92 code = afs_VerifyVCache(adp, &treq);
96 /** If the volume is read-only, return error without making an RPC to the
99 if (adp->states & CRO) {
104 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
105 InStatus.ClientModTime = osi_Time();
106 InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */
107 InStatus.Group = (afs_int32) acred->cr_gid;
108 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1);
109 ObtainWriteLock(&adp->lock, 153);
111 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
113 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR);
117 RXAFS_MakeDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
118 &InStatus, (struct AFSFid *)&newFid.Fid,
119 &OutFidStatus, &OutDirStatus, &CallBack,
123 CallBack.ExpirationTime += now;
124 /* DON'T forget to Set the callback value... */
128 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_MAKEDIR,
133 ObtainWriteLock(&afs_xcbhash, 490);
134 afs_DequeueCallback(adp);
135 adp->states &= ~CStatd;
136 ReleaseWriteLock(&afs_xcbhash);
137 osi_dnlc_purgedp(adp);
139 ReleaseWriteLock(&adp->lock);
144 /* otherwise, we should see if we can make the change to the dir locally */
146 ObtainWriteLock(&tdc->lock, 632);
147 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
148 /* we can do it locally */
149 code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid);
151 ZapDCE(tdc); /* surprise error -- use invalid value */
156 ReleaseWriteLock(&tdc->lock);
159 adp->m.LinkCount = OutDirStatus.LinkCount;
160 newFid.Cell = adp->fid.Cell;
161 newFid.Fid.Volume = adp->fid.Fid.Volume;
162 ReleaseWriteLock(&adp->lock);
163 /* now we're done with parent dir, create the real dir's cache entry */
164 tvc = afs_GetVCache(&newFid, &treq, NULL, NULL);
171 afs_PutFakeStat(&fakestate);
172 code = afs_CheckCode(code, &treq, 26);
175 AFS_RELE(ndp->ni_dvp);
176 #endif /* AFS_OSF_ENV */
184 struct nameidata *ndp;
186 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
187 char *aname = ndp->ni_dent.d_name;
188 struct ucred *acred = ndp->ni_cred;
189 #else /* AFS_OSF_ENV */
190 /* don't set CDirty in here because RPC is called synchronously */
191 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
192 afs_rmdir(OSI_VC_ARG(adp), aname, cdirp, acred)
195 afs_rmdir(adp, aname, acred)
199 struct AFS_UCRED *acred;
202 struct vrequest treq;
203 register struct dcache *tdc;
204 register struct vcache *tvc = NULL;
205 register afs_int32 code;
206 register struct conn *tc;
207 afs_size_t offset, len;
208 struct AFSFetchStatus OutDirStatus;
209 struct AFSVolSync tsync;
210 struct afs_fakestat_state fakestate;
211 XSTATS_DECLS OSI_VC_CONVERT(adp)
213 AFS_STATCNT(afs_rmdir);
215 afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp,
216 ICL_TYPE_STRING, aname);
218 if ((code = afs_InitReq(&treq, acred)))
220 afs_InitFakeStat(&fakestate);
222 if (strlen(aname) > AFSNAMEMAX) {
227 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
231 code = afs_VerifyVCache(adp, &treq);
235 /** If the volume is read-only, return error without making an RPC to the
238 if (adp->states & CRO) {
243 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
244 ObtainWriteLock(&adp->lock, 154);
246 ObtainSharedLock(&tdc->lock, 633);
247 if (tdc && (adp->states & CForeign)) {
248 struct VenusFid unlinkFid;
250 unlinkFid.Fid.Vnode = 0;
251 code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid);
253 afs_int32 cached = 0;
255 unlinkFid.Cell = adp->fid.Cell;
256 unlinkFid.Fid.Volume = adp->fid.Fid.Volume;
257 if (unlinkFid.Fid.Unique == 0) {
259 afs_LookupVCache(&unlinkFid, &treq, &cached, adp, aname);
261 ObtainReadLock(&afs_xvcache);
262 tvc = afs_FindVCache(&unlinkFid, 0, 1 /* do xstats */ );
263 ReleaseReadLock(&afs_xvcache);
269 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
271 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR);
274 RXAFS_RemoveDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
275 &OutDirStatus, &tsync);
281 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_REMOVEDIR,
286 ReleaseSharedLock(&tdc->lock);
290 ObtainWriteLock(&afs_xcbhash, 491);
291 afs_DequeueCallback(adp);
292 adp->states &= ~CStatd;
293 ReleaseWriteLock(&afs_xcbhash);
294 osi_dnlc_purgedp(adp);
296 ReleaseWriteLock(&adp->lock);
299 /* here if rpc worked; update the in-core link count */
300 adp->m.LinkCount = OutDirStatus.LinkCount;
302 UpgradeSToWLock(&tdc->lock, 634);
303 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
304 /* we can do it locally */
305 code = afs_dir_Delete(&tdc->f.inode, aname);
307 ZapDCE(tdc); /* surprise error -- invalid value */
312 ReleaseWriteLock(&tdc->lock);
313 afs_PutDCache(tdc); /* drop ref count */
318 osi_dnlc_purgedp(tvc); /* get rid of any entries for this directory */
319 afs_symhint_inval(tvc);
321 osi_dnlc_remove(adp, aname, 0);
324 ObtainWriteLock(&tvc->lock, 155);
325 tvc->states &= ~CUnique; /* For the dfs xlator */
326 ReleaseWriteLock(&tvc->lock);
329 ReleaseWriteLock(&adp->lock);
330 /* don't worry about link count since dirs can not be hardlinked */
334 afs_PutFakeStat(&fakestate);
335 code = afs_CheckCode(code, &treq, 27);
339 afs_PutVCache(ndp->ni_vp);
340 #endif /* AFS_OSF_ENV */