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;
73 AFS_STATCNT(afs_mkdir);
74 afs_Trace2(afs_iclSetp, CM_TRACE_MKDIR, ICL_TYPE_POINTER, adp,
75 ICL_TYPE_STRING, aname);
77 if ((code = afs_InitReq(&treq, acred)))
79 afs_InitFakeStat(&fakestate);
81 if (strlen(aname) > AFSNAMEMAX) {
86 if (!afs_ENameOK(aname)) {
90 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
93 code = afs_VerifyVCache(adp, &treq);
97 /** If the volume is read-only, return error without making an RPC to the
100 if (adp->states & CRO) {
105 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
106 InStatus.ClientModTime = osi_Time();
107 InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */
108 InStatus.Group = (afs_int32) acred->cr_gid;
109 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1);
110 ObtainWriteLock(&adp->lock, 153);
112 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
114 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR);
118 RXAFS_MakeDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
119 &InStatus, (struct AFSFid *)&newFid.Fid,
120 &OutFidStatus, &OutDirStatus, &CallBack,
124 CallBack.ExpirationTime += now;
125 /* DON'T forget to Set the callback value... */
129 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_MAKEDIR,
134 ObtainWriteLock(&afs_xcbhash, 490);
135 afs_DequeueCallback(adp);
136 adp->states &= ~CStatd;
137 ReleaseWriteLock(&afs_xcbhash);
138 osi_dnlc_purgedp(adp);
140 ReleaseWriteLock(&adp->lock);
145 /* otherwise, we should see if we can make the change to the dir locally */
147 ObtainWriteLock(&tdc->lock, 632);
148 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
149 /* we can do it locally */
150 code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid);
152 ZapDCE(tdc); /* surprise error -- use invalid value */
157 ReleaseWriteLock(&tdc->lock);
160 adp->m.LinkCount = OutDirStatus.LinkCount;
161 newFid.Cell = adp->fid.Cell;
162 newFid.Fid.Volume = adp->fid.Fid.Volume;
163 ReleaseWriteLock(&adp->lock);
164 /* now we're done with parent dir, create the real dir's cache entry */
165 tvc = afs_GetVCache(&newFid, &treq, NULL, NULL);
172 afs_PutFakeStat(&fakestate);
173 code = afs_CheckCode(code, &treq, 26);
176 AFS_RELE(ndp->ni_dvp);
177 #endif /* AFS_OSF_ENV */
185 struct nameidata *ndp;
187 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
188 char *aname = ndp->ni_dent.d_name;
189 struct ucred *acred = ndp->ni_cred;
190 #else /* AFS_OSF_ENV */
191 /* don't set CDirty in here because RPC is called synchronously */
192 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
193 afs_rmdir(OSI_VC_ARG(adp), aname, cdirp, acred)
196 afs_rmdir(adp, aname, acred)
200 struct AFS_UCRED *acred;
203 struct vrequest treq;
204 register struct dcache *tdc;
205 register struct vcache *tvc = NULL;
206 register afs_int32 code;
207 register struct conn *tc;
208 afs_size_t offset, len;
209 struct AFSFetchStatus OutDirStatus;
210 struct AFSVolSync tsync;
211 struct afs_fakestat_state fakestate;
215 AFS_STATCNT(afs_rmdir);
217 afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp,
218 ICL_TYPE_STRING, aname);
220 if ((code = afs_InitReq(&treq, acred)))
222 afs_InitFakeStat(&fakestate);
224 if (strlen(aname) > AFSNAMEMAX) {
229 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
233 code = afs_VerifyVCache(adp, &treq);
237 /** If the volume is read-only, return error without making an RPC to the
240 if (adp->states & CRO) {
245 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
246 ObtainWriteLock(&adp->lock, 154);
248 ObtainSharedLock(&tdc->lock, 633);
249 if (tdc && (adp->states & CForeign)) {
250 struct VenusFid unlinkFid;
252 unlinkFid.Fid.Vnode = 0;
253 code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid);
255 afs_int32 cached = 0;
257 unlinkFid.Cell = adp->fid.Cell;
258 unlinkFid.Fid.Volume = adp->fid.Fid.Volume;
259 if (unlinkFid.Fid.Unique == 0) {
261 afs_LookupVCache(&unlinkFid, &treq, &cached, adp, aname);
263 ObtainReadLock(&afs_xvcache);
264 tvc = afs_FindVCache(&unlinkFid, 0, 1 /* do xstats */ );
265 ReleaseReadLock(&afs_xvcache);
271 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
273 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR);
276 RXAFS_RemoveDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
277 &OutDirStatus, &tsync);
283 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_REMOVEDIR,
288 ReleaseSharedLock(&tdc->lock);
292 ObtainWriteLock(&afs_xcbhash, 491);
293 afs_DequeueCallback(adp);
294 adp->states &= ~CStatd;
295 ReleaseWriteLock(&afs_xcbhash);
296 osi_dnlc_purgedp(adp);
298 ReleaseWriteLock(&adp->lock);
301 /* here if rpc worked; update the in-core link count */
302 adp->m.LinkCount = OutDirStatus.LinkCount;
304 UpgradeSToWLock(&tdc->lock, 634);
305 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
306 /* we can do it locally */
307 code = afs_dir_Delete(&tdc->f.inode, aname);
309 ZapDCE(tdc); /* surprise error -- invalid value */
314 ReleaseWriteLock(&tdc->lock);
315 afs_PutDCache(tdc); /* drop ref count */
320 osi_dnlc_purgedp(tvc); /* get rid of any entries for this directory */
321 afs_symhint_inval(tvc);
323 osi_dnlc_remove(adp, aname, 0);
326 ObtainWriteLock(&tvc->lock, 155);
327 tvc->states &= ~CUnique; /* For the dfs xlator */
328 ReleaseWriteLock(&tvc->lock);
331 ReleaseWriteLock(&adp->lock);
332 /* don't worry about link count since dirs can not be hardlinked */
336 afs_PutFakeStat(&fakestate);
337 code = afs_CheckCode(code, &treq, 27);
341 afs_PutVCache(ndp->ni_vp);
342 #endif /* AFS_OSF_ENV */