Bug Summary

File:afs/VNOPS/afs_vnop_attrs.c
Location:line 270, column 3
Description:Value stored to 'inited' is never read

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 * Portions Copyright (c) 2003 Apple Computer, Inc.
10 */
11
12/*
13 * afs_vnop_attrs.c - setattr and getattr vnodeops
14 *
15 * Implements:
16 * afs_CopyOutAttrs
17 * afs_getattr
18 * afs_VAttrToAS
19 * afs_setattr
20 *
21 */
22
23#include <afsconfig.h>
24#include "afs/param.h"
25
26
27#include "afs/sysincludes.h" /* Standard vendor system headers */
28#include "afsincludes.h" /* Afs-based standard headers */
29#include "afs/afs_stats.h" /* statistics */
30#include "afs/afs_cbqueue.h"
31#include "afs/nfsclient.h"
32#include "afs/afs_osidnlc.h"
33
34extern afs_rwlock_t afs_xcbhash;
35struct afs_exporter *afs_nfsexporter;
36extern struct vcache *afs_globalVp;
37#if defined(AFS_HPUX110_ENV)
38extern struct vfs *afs_globalVFS;
39#endif
40
41
42/* copy out attributes from cache entry */
43int
44afs_CopyOutAttrs(struct vcache *avc, struct vattr *attrs)
45{
46 struct volume *tvp;
47 struct cell *tcell;
48#if defined(AFS_FBSD_ENV1) || defined(AFS_DFBSD_ENV)
49 struct vnode *vp = AFSTOV(avc)((avc)->v);
50#endif
51 int fakedir = 0;
52
53 AFS_STATCNT(afs_CopyOutAttrs)((afs_cmstats.callInfo.C_afs_CopyOutAttrs)++);
54 if (afs_fakestat_enable && avc->mvstat == 1)
55 fakedir = 1;
56 attrs->va_type = fakedir ? VDIR : vType(avc)((avc)->v)->v_type;
57#if defined(AFS_SGI_ENV) || defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
58 attrs->va_mode = fakedir ? 0755 : (mode_t) (avc->f.m.Mode & 0xffff);
59#else
60 attrs->va_mode = fakedir ? VDIR | 0755 : avc->f.m.Mode;
61#endif
62
63 if (avc->f.m.Mode & (VSUID0004000 | VSGID0002000)) {
64 /* setuid or setgid, make sure we're allowed to run them from this cell */
65 tcell = afs_GetCell(avc->f.fid.Cell, 0);
66 if (tcell && (tcell->states & CNoSUID0x02))
67 attrs->va_mode &= ~(VSUID0004000 | VSGID0002000);
68 }
69#if defined(AFS_DARWIN_ENV)
70 {
71 if (!afs_darwin_realmodes) {
72 /* Mac OS X uses the mode bits to determine whether a file or
73 * directory is accessible, and believes them, even though under
74 * AFS they're almost assuredly wrong, especially if the local uid
75 * does not match the AFS ID. So we set the mode bits
76 * conservatively.
77 */
78 if (S_ISDIR(attrs->va_mode)(((attrs->va_mode) & 0170000) == 0040000)) {
79 /* all access bits need to be set for directories, since even
80 * a mode 0 directory can still be used normally.
81 */
82 attrs->va_mode |= ACCESSPERMS(0000700|0000070|0000007);
83 } else {
84 /* for other files, replicate the user bits to group and other */
85 mode_t ubits = (attrs->va_mode & S_IRWXU0000700) >> 6;
86 attrs->va_mode |= ubits | (ubits << 3);
87 }
88 }
89 }
90#endif /* AFS_DARWIN_ENV */
91 attrs->va_uid = fakedir ? 0 : avc->f.m.Owner;
92 attrs->va_gid = fakedir ? 0 : avc->f.m.Group; /* yeah! */
93#if defined(AFS_SUN5_ENV)
94 attrs->va_fsid = avc->v.v_vfspv_mount->vfs_fsidmnt_stat.f_fsid.val[0];
95#elif defined(AFS_DARWIN80_ENV)
96 VATTR_RETURN(attrs, va_fsid, vfs_statfs(vnode_mount(AFSTOV(avc)((avc)->v)))->f_fsid.val[0]);
97#elif defined(AFS_DARWIN_ENV)
98 attrs->va_fsid = avc->v->v_mount->mnt_stat.f_fsid.val[0];
99#else /* ! AFS_DARWIN_ENV */
100 attrs->va_fsid = 1;
101#endif
102 if (avc->mvstat == 2) {
103 tvp = afs_GetVolume(&avc->f.fid, 0, READ_LOCK1);
104 /* The mount point's vnode. */
105 if (tvp) {
106 attrs->va_nodeidva_fileid =
107 afs_calc_inum(tvp->mtpoint.Cell,
108 tvp->mtpoint.Fid.Volume,
109 tvp->mtpoint.Fid.Vnode);
110 if (FidCmp(&afs_rootFid, &avc->f.fid)((&afs_rootFid)->Fid.Unique != (&avc->f.fid)->
Fid.Unique || (&afs_rootFid)->Fid.Vnode != (&avc->
f.fid)->Fid.Vnode || (&afs_rootFid)->Fid.Volume != (
&avc->f.fid)->Fid.Volume || (&afs_rootFid)->
Cell != (&avc->f.fid)->Cell)
&& !attrs->va_nodeidva_fileid)
111 attrs->va_nodeidva_fileid = 2;
112 afs_PutVolume(tvp, READ_LOCK)((tvp)->refCount--);
113 } else
114 attrs->va_nodeidva_fileid = 2;
115 } else
116 attrs->va_nodeidva_fileid =
117 afs_calc_inum(avc->f.fid.Cell,
118 avc->f.fid.Fid.Volume,
119 avc->f.fid.Fid.Vnode);
120 attrs->va_nodeidva_fileid &= 0x7fffffff; /* Saber C hates negative inode #s! */
121 attrs->va_nlink = fakedir ? 100 : avc->f.m.LinkCount;
122 attrs->va_size = fakedir ? 4096 : avc->f.m.Length;
123#if defined(AFS_FBSD_ENV1) || defined(AFS_DFBSD_ENV)
124 vnode_pager_setsize(vp, (u_long) attrs->va_size);
125#endif
126 attrs->va_atime.tv_sec = attrs->va_mtime.tv_sec = attrs->va_ctime.tv_sec =
127 fakedir ? 0 : (int)avc->f.m.Date;
128 /* set microseconds to be dataversion # so that we approximate NFS-style
129 * use of mtime as a dataversion #. We take it mod 512K because
130 * microseconds *must* be less than a million, and 512K is the biggest
131 * power of 2 less than such. DataVersions are typically pretty small
132 * anyway, so the difference between 512K and 1000000 shouldn't matter
133 * much, and "&" is a lot faster than "%".
134 */
135#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV1)
136 /* nfs on these systems puts an 0 in nsec and stores the nfs usec (aka
137 * dataversion) in va_gen */
138
139 attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec =
140 attrs->va_ctime.tv_nsec = 0;
141 attrs->va_gen = hgetlo(avc->f.m.DataVersion)((avc->f.m.DataVersion).low);
142#elif defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_OBSD_ENV) || defined(AFS_NBSD_ENV)
143 attrs->va_atime.tv_nsec = attrs->va_mtime.tv_nsec =
144 attrs->va_ctime.tv_nsec =
145 (hgetlo(avc->f.m.DataVersion)((avc->f.m.DataVersion).low) & 0x7ffff) * 1000;
146#else
147 attrs->va_atime.tv_usec = attrs->va_mtime.tv_usec =
148 attrs->va_ctime.tv_usec = (hgetlo(avc->f.m.DataVersion)((avc->f.m.DataVersion).low) & 0x7ffff);
149#endif
150#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV1)
151 attrs->va_flags = 0;
152#endif
153#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
154 attrs->va_blksize = AFS_BLKSIZE(1 << 12); /* XXX Was 8192 XXX */
155#else
156 attrs->va_blocksize = AFS_BLKSIZE(1 << 12); /* XXX Was 8192 XXX */
157#endif
158 attrs->va_rdev = 1;
159#if defined(AFS_HPUX110_ENV)
160 if (afs_globalVFS)
161 attrs->va_fstype = afs_globalVFS->vfs_mtype;
162#endif
163
164 /*
165 * Below return 0 (and not 1) blocks if the file is zero length. This conforms
166 * better with the other filesystems that do return 0.
167 */
168#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV1)
169 attrs->va_bytes = (attrs->va_size ? (attrs->va_size + 1023) : 1024);
170#ifdef va_bytes_rsv
171 attrs->va_bytes_rsv = -1;
172#endif
173#elif defined(AFS_HPUX_ENV)
174 attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10) : 0);
175#elif defined(AFS_SGI_ENV)
176 attrs->va_blocks = BTOBB(attrs->va_size);
177#elif defined(AFS_SUN5_ENV)
178 attrs->va_nblocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10)<<1:0);
179#else /* everything else */
180 attrs->va_blocks = (attrs->va_size ? ((attrs->va_size + 1023)>>10)<<1:0);
181#endif
182 return 0;
183}
184
185
186
187#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
188int
189afs_getattr(OSI_VC_DECL(avc)struct vcache *avc, struct vattr *attrs, int flags,
190 afs_ucred_t *acred)
191#else
192int
193afs_getattr(OSI_VC_DECL(avc)struct vcache *avc, struct vattr *attrs, afs_ucred_t *acred)
194#endif
195{
196 afs_int32 code;
197 struct vrequest treq;
198 struct unixuser *au;
199 int inited = 0;
200 OSI_VC_CONVERT(avc);
201
202 AFS_STATCNT(afs_getattr)((afs_cmstats.callInfo.C_afs_getattr)++);
203 afs_Trace2(afs_iclSetp, CM_TRACE_GETATTR, ICL_TYPE_POINTER, avc,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event2(afs_iclSetp, (701087820L), (1<<24)+((2)
<<18)+((8)<<12), (long)(avc), (long)((&avc->
f.m.Length))) : 0)
204 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length))(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event2(afs_iclSetp, (701087820L), (1<<24)+((2)
<<18)+((8)<<12), (long)(avc), (long)((&avc->
f.m.Length))) : 0)
;
205
206 if (afs_fakestat_enable && avc->mvstat == 1) {
207 struct afs_fakestat_state fakestat;
208
209 code = afs_InitReq(&treq, acred);
210 if (code)
211 return code;
212 afs_InitFakeStat(&fakestat);
213 code = afs_TryEvalFakeStat(&avc, &fakestat, &treq);
214 if (code) {
215 afs_PutFakeStat(&fakestat);
216 return code;
217 }
218
219 code = afs_CopyOutAttrs(avc, attrs);
220 afs_PutFakeStat(&fakestat);
221 return code;
222 }
223#if defined(AFS_SUN5_ENV)
224 if (flags & ATTR_HINT) {
225 code = afs_CopyOutAttrs(avc, attrs);
226 return code;
227 }
228#endif
229#if defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
230 if (avc->f.states & CUBCinit) {
231 code = afs_CopyOutAttrs(avc, attrs);
232 return code;
233 }
234#endif
235
236 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)
;
237
238#ifdef AFS_BOZONLOCK_ENV
239 afs_BozonLock(&avc->pvnLock, avc);
240#endif
241
242 if (afs_shuttingdown)
243 return EIO5;
244
245 if (!(avc->f.states & CStatd0x00000001)) {
246 if (!(code = afs_InitReq(&treq, acred))) {
247 code = afs_VerifyVCache2(avc, &treq);
248 inited = 1;
249 }
250 } else
251 code = 0;
252
253#if defined(AFS_SUN5_ENV) || defined(AFS_BOZONLOCK_ENV)
254 if (code == 0)
255 osi_FlushPages(avc, acred);
256#endif
257#ifdef AFS_BOZONLOCK_ENV
258 afs_BozonUnlock(&avc->pvnLock, avc);
259#endif
260
261
262 if (code == 0) {
263 osi_FlushText(avc); /* only needed to flush text if text locked last time */
264 code = afs_CopyOutAttrs(avc, attrs);
265
266 if (afs_nfsexporter) {
267 if (!inited) {
268 if ((code = afs_InitReq(&treq, acred)))
269 return code;
270 inited = 1;
Value stored to 'inited' is never read
271 }
272 if (AFS_NFSXLATORREQ(acred)0) {
273 if ((vType(avc)((avc)->v)->v_type != VDIR)
274 && !afs_AccessOK(avc, PRSFS_READ1, &treq,
275 CHECK_MODE_BITS1 |
276 CMB_ALLOW_EXEC_AS_READ2)) {
277 return EACCES13;
278 }
279 }
280 if ((au = afs_FindUser(treq.uid, -1, READ_LOCK1))) {
281 struct afs_exporter *exporter = au->exporter;
282
283 if (exporter && !(afs_nfsexporter->exp_states & EXP_UNIXMODE2)) {
284 unsigned int ubits;
285 /*
286 * If the remote user wishes to enforce default Unix mode semantics,
287 * like in the nfs exporter case, we OR in the user bits
288 * into the group and other bits. We need to do this
289 * because there is no RFS_ACCESS call and thus nfs
290 * clients implement nfs_access by interpreting the
291 * mode bits in the traditional way, which of course
292 * loses with afs.
293 */
294 ubits = (attrs->va_mode & 0700) >> 6;
295 attrs->va_mode = attrs->va_mode | ubits | (ubits << 3);
296 /* If it's the root of AFS, replace the inode number with the
297 * inode number of the mounted on directory; otherwise this
298 * confuses getwd()... */
299#ifdef AFS_LINUX22_ENV
300 if (avc == afs_globalVp) {
301 struct inode *ip = AFSTOV(avc)((avc)->v)->i_sb->s_root->d_inode;
302 attrs->va_nodeidva_fileid = ip->i_ino; /* VTOI()? */
303 }
304#else
305 if (
306#if defined(AFS_DARWIN_ENV)
307 vnode_isvroot(AFSTOV(avc)((avc)->v))
308#elif defined(AFS_NBSD50_ENV)
309 AFSTOV(avc)((avc)->v)->v_vflag & VV_ROOT0x0001
310#else
311 AFSTOV(avc)((avc)->v)->v_flagv_vflag & VROOT0x0001
312#endif
313 ) {
314 struct vnode *vp = AFSTOV(avc)((avc)->v);
315
316#ifdef AFS_DARWIN80_ENV
317 /* XXX vp = vnode_mount(vp)->mnt_vnodecovered; */
318 vp = 0;
319#else
320 vp = vp->v_vfspv_mount->vfs_vnodecoveredmnt_vnodecovered;
321 if (vp) { /* Ignore weird failures */
322#ifdef AFS_SGI62_ENV
323 attrs->va_nodeidva_fileid = VnodeToIno(vp);
324#else
325 struct inode *ip;
326
327 ip = (struct inode *)VTOI(vp)((struct inode *)(vp)->v_data);
328 if (ip) /* Ignore weird failures */
329 attrs->va_nodeidva_fileid = ip->i_number;
330#endif
331 }
332#endif
333 }
334#endif /* AFS_LINUX22_ENV */
335 }
336 afs_PutUser(au, READ_LOCK1);
337 }
338 }
339 }
340
341 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)
;
342
343 if (!code)
344 return 0;
345 code = afs_CheckCode(code, &treq, 14);
346 return code;
347}
348
349/* convert a Unix request into a status store request */
350int
351afs_VAttrToAS(struct vcache *avc, struct vattr *av,
352 struct AFSStoreStatus *as)
353{
354 int mask;
355 mask = 0;
356 AFS_STATCNT(afs_VAttrToAS)((afs_cmstats.callInfo.C_afs_VAttrToAS)++);
357#if defined(AFS_DARWIN80_ENV)
358 if (VATTR_IS_ACTIVE(av, va_mode)) {
359#elif defined(AFS_AIX_ENV)
360/* Boy, was this machine dependent bogosity hard to swallow????.... */
361 if (av->va_mode != -1) {
362#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
363 if (av->va_mask & ATTR_MODE) {
364#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
365 if (av->va_mask & AT_MODE) {
366#elif defined(AFS_XBSD_ENV1)
367 if (av->va_mode != (mode_t)VNOVAL(-1)) {
368#else
369 if (av->va_mode != ((unsigned short)-1)) {
370#endif
371 mask |= AFS_SETMODE8;
372 as->UnixModeBits = av->va_mode & 0xffff;
373 if (avc->f.states & CForeign0x00002000) {
374 ObtainWriteLock(&avc->lock, 127)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 = 127; }
while (0)
;
375 afs_FreeAllAxs(&(avc->Access));
376 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)
;
377 }
378 }
379#if defined(AFS_DARWIN80_ENV)
380 if (VATTR_IS_ACTIVE(av, va_gid)) {
381#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
382 if (av->va_mask & ATTR_GID) {
383#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
384 if (av->va_mask & AT_GID) {
385#elif defined(AFS_HPUX_ENV)
386#if defined(AFS_HPUX102_ENV)
387 if (av->va_gid != GID_NO_CHANGE) {
388#else
389 if (av->va_gid != ((unsigned short)-1)) {
390#endif
391#elif defined(AFS_XBSD_ENV1)
392 if (av->va_gid != (gid_t)VNOVAL(-1)) {
393#else
394 if (av->va_gid != -1) {
395#endif /* AFS_LINUX22_ENV */
396 mask |= AFS_SETGROUP4;
397 as->Group = av->va_gid;
398 }
399#if defined(AFS_DARWIN80_ENV)
400 if (VATTR_IS_ACTIVE(av, va_uid)) {
401#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
402 if (av->va_mask & ATTR_UID) {
403#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
404 if (av->va_mask & AT_UID) {
405#elif defined(AFS_HPUX_ENV)
406#if defined(AFS_HPUX102_ENV)
407 if (av->va_uid != UID_NO_CHANGE) {
408#elif defined(AFS_XBSD_ENV1)
409 if (av->va_uid != (uid_t)VNOVAL(-1)) {
410#else
411 if (av->va_uid != ((unsigned short)-1)) {
412#endif
413#else
414 if (av->va_uid != -1) {
415#endif /* AFS_LINUX22_ENV */
416 mask |= AFS_SETOWNER2;
417 as->Owner = av->va_uid;
418 }
419#if defined(AFS_DARWIN80_ENV)
420 if (VATTR_IS_ACTIVE(av, va_modify_time)) {
421#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
422 if (av->va_mask & ATTR_MTIME) {
423#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
424 if (av->va_mask & AT_MTIME) {
425#else
426 if (av->va_mtime.tv_sec != -1) {
427#endif
428 mask |= AFS_SETMODTIME1;
429#ifndef AFS_SGI_ENV
430#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV1)
431 if (av->va_mtime.tv_nsec == -1)
432#else
433 if (av->va_mtime.tv_usec == -1)
434#endif
435 as->ClientModTime = osi_Time()time_second; /* special Sys V compat hack for Suns */
436 else
437#endif
438 as->ClientModTime = av->va_mtime.tv_sec;
439 }
440 as->Mask = mask;
441 return 0;
442}
443
444/* We don't set CDirty bit in avc->f.states because setattr calls WriteVCache
445 * synchronously, therefore, it's not needed.
446 */
447#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
448int
449afs_setattr(OSI_VC_DECL(avc)struct vcache *avc, struct vattr *attrs, int flags,
450 afs_ucred_t *acred)
451#else
452int
453afs_setattr(OSI_VC_DECL(avc)struct vcache *avc, struct vattr *attrs,
454 afs_ucred_t *acred)
455#endif
456{
457 struct vrequest treq;
458 struct AFSStoreStatus astat;
459 afs_int32 code;
460#if defined(AFS_FBSD_ENV1) || defined(AFS_DFBSD_ENV)
461 struct vnode *vp = AFSTOV(avc)((avc)->v);
462#endif
463 struct afs_fakestat_state fakestate;
464 OSI_VC_CONVERT(avc);
465
466 AFS_STATCNT(afs_setattr)((afs_cmstats.callInfo.C_afs_setattr)++);
467#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX22_ENV)
468 afs_Trace4(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mask), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
469 ICL_TYPE_INT32, attrs->va_mask, ICL_TYPE_OFFSET,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mask), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
470 ICL_HANDLE_OFFSET(attrs->va_size), ICL_TYPE_OFFSET,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mask), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
471 ICL_HANDLE_OFFSET(avc->f.m.Length))(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mask), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
;
472#else
473 afs_Trace4(afs_iclSetp, CM_TRACE_SETATTR, ICL_TYPE_POINTER, avc,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mode), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
474 ICL_TYPE_INT32, attrs->va_mode, ICL_TYPE_OFFSET,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mode), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
475 ICL_HANDLE_OFFSET(attrs->va_size), ICL_TYPE_OFFSET,(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mode), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
476 ICL_HANDLE_OFFSET(avc->f.m.Length))(((afs_iclSetp) && (afs_iclSetp->states & 2)) ?
afs_icl_Event4(afs_iclSetp, (701087821L), (1<<24)+((2)
<<18)+((7)<<12)+((8)<<6)+(8), (long)(avc), (
long)(attrs->va_mode), (long)((&attrs->va_size)), (
long)((&avc->f.m.Length))) : 0)
;
477#endif
478 if ((code = afs_InitReq(&treq, acred)))
479 return code;
480
481 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)
;
482
483 afs_InitFakeStat(&fakestate);
484 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
485 if (code)
486 goto done;
487
488 if (avc->f.states & CRO0x00000004) {
489 code = EROFS30;
490 goto done;
491 }
492#if defined(AFS_SGI_ENV)
493 /* ignore ATTR_LAZY calls - they are really only for keeping
494 * the access/mtime of mmaped files up to date
495 */
496 if (flags & ATTR_LAZY)
497 goto done;
498#endif
499 /* if file size has changed, we need write access, otherwise (e.g.
500 * chmod) give it a shot; if it fails, we'll discard the status
501 * info.
502 */
503#if defined(AFS_DARWIN80_ENV)
504 if (VATTR_IS_ACTIVE(attrs, va_data_size)) {
505#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
506 if (attrs->va_mask & ATTR_SIZE) {
507#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
508 if (attrs->va_mask & AT_SIZE) {
509#elif defined(AFS_XBSD_ENV1)
510 if (attrs->va_size != VNOVAL(-1)) {
511#elif defined(AFS_AIX41_ENV)
512 if (attrs->va_size != -1) {
513#else
514 if (attrs->va_size != ~0) {
515#endif
516 if (!afs_AccessOK(avc, PRSFS_WRITE2, &treq, DONT_CHECK_MODE_BITS0)) {
517 code = EACCES13;
518 goto done;
519 }
520 }
521
522 if (AFS_IS_DISCONNECTED(afs_is_disconnected) && !AFS_IS_DISCON_RW(afs_is_discon_rw)) {
523 code = ENETDOWN50;
524 goto done;
525 }
526
527 afs_VAttrToAS(avc, attrs, &astat); /* interpret request */
528 code = 0;
529#ifdef AFS_BOZONLOCK_ENV
530 afs_BozonLock(&avc->pvnLock, avc);
531#endif
532#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
533 if (AFS_NFSXLATORREQ(acred)0) {
534 avc->execsOrWriters++;
535 }
536#endif
537
538#if defined(AFS_SGI_ENV)
539 AFS_RWLOCK((vnode_tstruct vnode *) avc, VRWLOCK_WRITE);
540#endif
541#if defined(AFS_DARWIN80_ENV)
542 if (VATTR_IS_ACTIVE(attrs, va_data_size)) {
543#elif defined(AFS_LINUX22_ENV) || defined(UKERNEL)
544 if (attrs->va_mask & ATTR_SIZE) {
545#elif defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
546 if (attrs->va_mask & AT_SIZE) {
547#elif defined(AFS_XBSD_ENV1)
548 if (attrs->va_size != VNOVAL(-1)) {
549#elif defined(AFS_AIX41_ENV)
550 if (attrs->va_size != -1) {
551#else
552 if (attrs->va_size != ~0) {
553#endif
554 afs_size_t tsize = attrs->va_size;
555 ObtainWriteLock(&avc->lock, 128)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 = 128; }
while (0)
;
556 avc->f.states |= CDirty0x00000020;
557
558 if (AFS_IS_DISCONNECTED(afs_is_disconnected) && tsize >=avc->f.m.Length) {
559 /* If we're growing the file, and we're disconnected, we need
560 * to make the relevant dcache chunks appear ourselves. */
561 code = afs_ExtendSegments(avc, tsize, &treq);
562 } else {
563 code = afs_TruncateAllSegments(avc, tsize, &treq, acred);
564 }
565#ifdef AFS_LINUX26_ENV
566 /* We must update the Linux kernel's idea of file size as soon as
567 * possible, to avoid racing with delayed writepages delivered by
568 * pdflush */
569 if (code == 0)
570 i_size_write(AFSTOV(avc)((avc)->v), tsize);
571#endif
572#if defined(AFS_FBSD_ENV1) || defined(AFS_DFBSD_ENV)
573 vnode_pager_setsize(vp, (u_long) tsize);
574#endif
575 /* if date not explicitly set by this call, set it ourselves, since we
576 * changed the data */
577 if (!(astat.Mask & AFS_SETMODTIME1)) {
578 astat.Mask |= AFS_SETMODTIME1;
579 astat.ClientModTime = osi_Time()time_second;
580 }
581
582 if (code == 0) {
583 if (((avc->execsOrWriters <= 0) && (avc->f.states & CCreating0x00400000) == 0)
584 || (avc->execsOrWriters == 1 && AFS_NFSXLATORREQ(acred)0)) {
585
586 /* Store files now if not disconnected. */
587 /* XXX: AFS_IS_DISCON_RW handled. */
588 if (!AFS_IS_DISCONNECTED(afs_is_disconnected)) {
589 code = afs_StoreAllSegments(avc, &treq, AFS_ASYNC0);
590 if (!code)
591 avc->f.states &= ~CDirty0x00000020;
592 }
593 }
594 } else
595 avc->f.states &= ~CDirty0x00000020;
596
597 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)
;
598 hzero(avc->flushDV)((avc->flushDV).low = 0, (avc->flushDV).high = 0);
599 osi_FlushText(avc); /* do this after releasing all locks */
600 }
601
602 if (!AFS_IS_DISCONNECTED(afs_is_disconnected)) {
603 if (code == 0) {
604 ObtainSharedLock(&avc->lock, 16)do { ; if (!(&avc->lock)->excl_locked) (&avc->
lock) -> excl_locked = 4; else Afs_Lock_Obtain(&avc->
lock, 4); (&avc->lock)->pid_writer = (((__curthread
())->td_proc)->p_pid ); (&avc->lock)->src_indicator
= 16; } while (0)
; /* lock entry */
605 code = afs_WriteVCache(avc, &astat, &treq); /* send request */
606 ReleaseSharedLock(&avc->lock)do { ; (&avc->lock)->excl_locked &= ~(4 | 2); if
((&avc->lock)->wait_states) Afs_Lock_ReleaseR(&
avc->lock); (&avc->lock)->pid_writer=0; } while (
0)
; /* release lock */
607 }
608 if (code) {
609 ObtainWriteLock(&afs_xcbhash, 487)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 = 487; } while (0)
;
610 afs_DequeueCallback(avc);
611 avc->f.states &= ~CStatd0x00000001;
612 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)
;
613 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc)((avc)->v)->v_type == VDIR))
614 osi_dnlc_purgedp(avc);
615 /* error? erase any changes we made to vcache entry */
616 }
617 } else {
618 ObtainSharedLock(&avc->lock, 712)do { ; if (!(&avc->lock)->excl_locked) (&avc->
lock) -> excl_locked = 4; else Afs_Lock_Obtain(&avc->
lock, 4); (&avc->lock)->pid_writer = (((__curthread
())->td_proc)->p_pid ); (&avc->lock)->src_indicator
= 712; } while (0)
;
619 /* Write changes locally. */
620 code = afs_WriteVCacheDiscon(avc, &astat, attrs);
621 ReleaseSharedLock(&avc->lock)do { ; (&avc->lock)->excl_locked &= ~(4 | 2); if
((&avc->lock)->wait_states) Afs_Lock_ReleaseR(&
avc->lock); (&avc->lock)->pid_writer=0; } while (
0)
;
622 } /* if (!AFS_IS_DISCONNECTED) */
623
624#if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
625 if (AFS_NFSXLATORREQ(acred)0) {
626 avc->execsOrWriters--;
627 }
628#endif
629#ifdef AFS_BOZONLOCK_ENV
630 afs_BozonUnlock(&avc->pvnLock, avc);
631#endif
632#if defined(AFS_SGI_ENV)
633 AFS_RWUNLOCK((vnode_tstruct vnode *) avc, VRWLOCK_WRITE);
634#endif
635 done:
636 afs_PutFakeStat(&fakestate);
637
638 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)
;
639 code = afs_CheckCode(code, &treq, 15);
640 return code;
641}