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
17 #include <afsconfig.h>
18 #include "../afs/param.h"
22 #include "../afs/sysincludes.h" /* Standard vendor system headers */
23 #include "../afs/afsincludes.h" /* Afs-based standard headers */
24 #include "../afs/afs_stats.h" /* statistics */
25 #include "../afs/afs_cbqueue.h"
26 #include "../afs/nfsclient.h"
27 #include "../afs/afs_osidnlc.h"
31 /* given a vnode ptr, open flags and credentials, open the file. No access
32 * checks are done here, instead they're done by afs_create or afs_access,
33 * both called by the vn_open call.
36 afs_open(bhv, avcp, aflags, acred)
39 afs_open(avcp, aflags, acred)
41 register struct vcache **avcp;
43 struct AFS_UCRED *acred;
45 register afs_int32 code;
47 register struct vcache *tvc;
50 AFS_STATCNT(afs_open);
51 if (code = afs_InitReq(&treq, acred)) return code;
53 /* avcpp can be, but is not necesarily, bhp's vnode. */
54 tvc = VTOAFS(BHV_TO_VNODE(bhv));
58 afs_Trace2(afs_iclSetp, CM_TRACE_OPEN, ICL_TYPE_POINTER, tvc,
59 ICL_TYPE_INT32, aflags);
60 code = afs_VerifyVCache(tvc, &treq);
62 if (aflags & (FWRITE | FTRUNC)) writing = 1;
64 if (vType(tvc) == VDIR) {
71 if (!afs_AccessOK(tvc,
72 ((tvc->states & CForeign) ? PRSFS_READ: PRSFS_LOOKUP),
73 &treq, CHECK_MODE_BITS)) {
81 if (AFS_NFSXLATORREQ(acred) && (aflags & FREAD)) {
82 if (!afs_AccessOK(tvc, PRSFS_READ, &treq,
83 CHECK_MODE_BITS|CMB_ALLOW_EXEC_AS_READ)) {
90 if (aflags & FRSHARE) {
93 * Apparently it is possible for a file to get mapped without
94 * either VNOP_MAP or VNOP_RDWR being called, if (1) it is a
95 * sharable library, and (2) it has already been loaded. We must
96 * ensure that the credp is up to date. We detect the situation
97 * by checking for O_RSHARE at open time.
100 * We keep the caller's credentials since an async daemon will
101 * handle the request at some point. We assume that the same
102 * credentials will be used.
104 ObtainWriteLock(&tvc->lock,140);
105 if (!tvc->credp || (tvc->credp != acred)) {
108 struct ucred *crp = tvc->credp;
109 tvc->credp = (struct ucred *)0;
114 ReleaseWriteLock(&tvc->lock);
117 /* normal file or symlink */
118 osi_FlushText(tvc); /* only needed to flush text if text locked last time */
119 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
120 afs_BozonLock(&tvc->pvnLock, tvc);
122 osi_FlushPages(tvc, acred);
123 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
124 afs_BozonUnlock(&tvc->pvnLock, tvc);
127 /* set date on file if open in O_TRUNC mode */
128 if (aflags & FTRUNC) {
129 /* this fixes touch */
130 ObtainWriteLock(&tvc->lock,123);
131 tvc->m.Date = osi_Time();
132 tvc->states |= CDirty;
133 ReleaseWriteLock(&tvc->lock);
135 ObtainReadLock(&tvc->lock);
136 if (writing) tvc->execsOrWriters++;
138 #if defined(AFS_SGI_ENV)
139 if (writing && tvc->cred == NULL) {
144 ReleaseReadLock(&tvc->lock);
146 code = afs_CheckCode(code, &treq, 4); /* avoid AIX -O bug */
148 afs_Trace2(afs_iclSetp, CM_TRACE_OPEN, ICL_TYPE_POINTER, tvc,
149 ICL_TYPE_INT32, 999999);