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
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
35 #undef SHARED /* XXX */
42 #ifdef HAVE_NETINET_IF_ETHER_H
43 #include <netinet/if_ether.h>
46 #if !defined(AFS_SGI_ENV) && defined(HAVE_SYS_MAP_H)
50 #ifdef HAVE_SYS_STATFS_H
51 #include <sys/statfs.h>
54 #ifdef HAVE_SYS_LOCKF_H
55 #include <sys/lockf.h>
63 /* included early because of name conflict on IOPEN */
64 #include <sys/inode.h>
68 #endif /* AFS_HPUX_ENV */
72 #include <afs/afs_assert.h>
75 #include <afs/afsint.h>
76 #include <afs/vldbint.h>
77 #include <afs/errors.h>
78 #include <afs/ihandle.h>
79 #include <afs/vnode.h>
80 #include <afs/volume.h>
81 #include <afs/ptclient.h>
82 #include <afs/ptuser.h>
83 #include <afs/prs_fs.h>
86 #include <rx/rx_globals.h>
88 #include <afs/cellconfig.h>
91 #include <afs/partition.h>
92 #include "viced_prototypes.h"
96 #include <afs/unified_afs.h>
97 #include <afs/audit.h>
98 #include <afs/afsutil.h>
101 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
102 extern void FidZap(DirHandle * file);
103 extern void FidZero(DirHandle * file);
105 #ifdef AFS_PTHREAD_ENV
106 pthread_mutex_t fileproc_glock_mutex;
107 #endif /* AFS_PTHREAD_ENV */
109 /* Useful local defines used by this module */
112 #define MustNOTBeDIR 1
116 #define TVS_SSTATUS 2
119 #define TVS_MKDIR 0x10
121 #define CHK_FETCH 0x10
122 #define CHK_FETCHDATA 0x10
123 #define CHK_FETCHACL 0x11
124 #define CHK_FETCHSTATUS 0x12
125 #define CHK_STOREDATA 0x00
126 #define CHK_STOREACL 0x01
127 #define CHK_STORESTATUS 0x02
129 #define OWNERREAD 0400
130 #define OWNERWRITE 0200
131 #define OWNEREXEC 0100
132 #ifdef USE_GROUP_PERMS
133 #define GROUPREAD 0040
134 #define GROUPWRITE 0020
135 #define GROUPREXEC 0010
138 /* The following errors were not defined in NT. They are given unique
139 * names here to avoid any potential collision.
141 #define FSERR_ELOOP 90
142 #define FSERR_EOPNOTSUPP 122
143 #define FSERR_ECONNREFUSED 130
145 #define NOTACTIVECALL 0
148 #define CREATE_SGUID_ADMIN_ONLY 1
150 extern struct afsconf_dir *confDir;
151 extern afs_int32 dataVersionHigh;
154 static struct AFSCallStatistics AFSCallStats;
155 #if FS_STATS_DETAILED
156 struct fs_stats_FullPerfStats afs_FullPerfStats;
157 extern int AnonymousID;
158 #endif /* FS_STATS_DETAILED */
159 #if OPENAFS_VOL_STATS
160 static const char nullString[] = "";
161 #endif /* OPENAFS_VOL_STATS */
164 afs_int32 NothingYet;
167 struct afs_FSStats afs_fsstats;
172 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
174 extern afs_int32 implicitAdminRights;
175 extern afs_int32 readonlyServer;
176 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
177 extern afs_fsize_t CopyOnWrite_maxsize;
180 * Externals used by the xstat code.
182 extern VolPkgStats VStats;
183 extern int CEs, CEBlocks;
185 extern int HTs, HTBlocks;
187 static afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
188 struct rx_call *Call, afs_sfsize_t Pos,
189 afs_sfsize_t Len, afs_int32 Int64Mode,
190 afs_sfsize_t * a_bytesToFetchP,
191 afs_sfsize_t * a_bytesFetchedP);
193 static afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
194 struct AFSFid *Fid, struct client *client,
195 struct rx_call *Call, afs_fsize_t Pos,
196 afs_fsize_t Length, afs_fsize_t FileLength,
198 afs_sfsize_t * a_bytesToStoreP,
199 afs_sfsize_t * a_bytesStoredP);
201 #ifdef AFS_SGI_XFS_IOPS_ENV
202 #include <afs/xfsattrs.h>
204 GetLinkCount(Volume * avp, struct stat *astat)
206 if (!strcmp("xfs", astat->st_fstype)) {
207 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
209 return astat->st_nlink;
212 #define GetLinkCount(V, S) (S)->st_nlink
216 SpareComp(Volume * avolp)
222 temp = V_maxquota(avolp);
224 /* no matter; doesn't check in this case */
228 temp = (temp * PctSpare) / 100;
239 * Set the volume synchronization parameter for this volume. If it changes,
240 * the Cache Manager knows that the volume must be purged from the stat cache.
243 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
246 /* date volume instance was created */
249 async->spare1 = avol->header->diskstuff.creationDate;
262 * Verify that the on-disk size for a vnode matches the length in the vnode
265 * @param[in] vp Volume pointer
266 * @param[in] vnp Vnode pointer
267 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
268 * and CheckLength itself will determine the on-disk size.
270 * @return operation status
271 * @retval 0 lengths match
272 * @retval nonzero Error; either the lengths do not match or there was an
273 * error determining the on-disk size. The volume should be
274 * taken offline and salvaged.
277 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
280 VN_GET_LEN(vlen, vnp);
285 fdP = IH_OPEN(vnp->handle);
287 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
288 afs_printable_uint32_lu(vp->hashid),
289 afs_printable_uint32_lu(Vn_id(vnp)),
290 afs_printable_uint32_lu(vnp->disk.uniquifier)));
293 alen = FDH_SIZE(fdP);
296 afs_int64 alen64 = alen;
297 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
298 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
299 afs_printable_uint32_lu(vp->hashid),
300 afs_printable_uint32_lu(Vn_id(vnp)),
301 afs_printable_uint32_lu(vnp->disk.uniquifier),
308 afs_int64 alen64 = alen, vlen64 = vlen;
309 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
310 "%lld inode %lld ); volume must be salvaged\n",
311 afs_printable_uint32_lu(vp->hashid),
312 afs_printable_uint32_lu(Vn_id(vnp)),
313 afs_printable_uint32_lu(vnp->disk.uniquifier),
321 * Note that this function always returns a held host, so
322 * that CallPostamble can block without the host's disappearing.
323 * Call returns rx connection in passed in *tconn
326 CallPreamble(struct rx_call *acall, int activecall,
327 struct rx_connection **tconn, struct host **ahostp)
330 struct client *tclient;
333 char hoststr[16], hoststr2[16];
334 #ifdef AFS_PTHREAD_ENV
335 struct ubik_client *uclient;
340 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
343 *tconn = rx_ConnectionOf(acall);
347 tclient = h_FindClient_r(*tconn);
349 ViceLog(0, ("CallPreamble: Couldn't get client.\n"));
353 thost = tclient->host;
354 if (tclient->prfail == 1) { /* couldn't get the CPS */
356 h_ReleaseClient_r(tclient);
358 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
362 retry_flag = 0; /* Retry once */
364 /* Take down the old connection and re-read the key file */
366 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
367 #ifdef AFS_PTHREAD_ENV
368 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
370 /* Is it still necessary to drop this? We hit the net, we should... */
376 code = hpr_Initialize(&uclient);
379 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
382 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
385 h_ReleaseClient_r(tclient);
388 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
392 tclient->prfail = 2; /* Means re-eval client's cps */
393 h_ReleaseClient_r(tclient);
398 tclient->LastCall = thost->LastCall = FT_ApproxTime();
399 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
400 thost->ActiveCall = thost->LastCall;
403 if (thost->hostFlags & HOSTDELETED) {
405 ("Discarded a packet for deleted host %s:%d\n",
406 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
407 code = VBUSY; /* raced, so retry */
408 } else if ((thost->hostFlags & VENUSDOWN)
409 || (thost->hostFlags & HFE_LATER)) {
410 if (BreakDelayedCallBacks_r(thost)) {
412 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
413 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
414 ntohs(rxr_PortOf(*tconn))));
415 if (MultiProbeAlternateAddress_r(thost)) {
417 ("MultiProbe failed to find new address for host %s:%d\n",
418 afs_inet_ntoa_r(thost->host, hoststr),
419 ntohs(thost->port)));
423 ("MultiProbe found new address for host %s:%d\n",
424 afs_inet_ntoa_r(thost->host, hoststr),
425 ntohs(thost->port)));
426 if (BreakDelayedCallBacks_r(thost)) {
428 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
429 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
430 ntohs(rxr_PortOf(*tconn))));
439 h_ReleaseClient_r(tclient);
449 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
453 struct client *tclient;
457 tclient = h_FindClient_r(aconn);
460 thost = tclient->host;
461 if (thost->hostFlags & HERRORTRANS)
463 h_ReleaseClient_r(tclient);
466 if (ahost != thost) {
467 /* host/client recycle */
468 char hoststr[16], hoststr2[16];
469 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
471 afs_inet_ntoa_r(ahost->host, hoststr),
474 afs_inet_ntoa_r(thost->host, hoststr2),
478 /* return the reference taken in CallPreamble */
482 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
483 afs_inet_ntoa_r(thost->host, hoststr),
488 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
489 * does not decrement refcount on client->host */
494 return (translate ? sys_error_to_et(ret) : ret);
498 * Returns the volume and vnode pointers associated with file Fid; the lock
499 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
500 * are incremented and they must be eventualy released.
503 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
504 Vnode ** vptr, int lock)
507 Error local_errorCode, errorCode = -1;
508 static struct timeval restartedat = { 0, 0 };
510 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
512 if ((*volptr) == 0) {
517 #ifdef AFS_DEMAND_ATTACH_FS
523 #ifdef AFS_PTHREAD_ENV
524 static const struct timespec timeout_ts = { 0, 0 };
525 static const struct timespec * const ts = &timeout_ts;
527 static const struct timespec * const ts = NULL;
531 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
532 fid->Volume, ts, cbv);
537 if ((errorCode == VOFFLINE) && (VInit < 2)) {
538 /* The volume we want may not be attached yet because
539 * the volume initialization is not yet complete.
540 * We can do several things:
541 * 1. return -1, which will cause users to see
542 * "connection timed out". This is more or
543 * less the same as always, except that the servers
544 * may appear to bounce up and down while they
545 * are actually restarting.
546 * 2. return VBUSY which will cause clients to
547 * sleep and retry for 6.5 - 15 minutes, depending
548 * on what version of the CM they are running. If
549 * the file server takes longer than that interval
550 * to attach the desired volume, then the application
551 * will see an ENODEV or EIO. This approach has
552 * the advantage that volumes which have been attached
553 * are immediately available, it keeps the server's
554 * immediate backlog low, and the call is interruptible
555 * by the user. Users see "waiting for busy volume."
556 * 3. sleep here and retry. Some people like this approach
557 * because there is no danger of seeing errors. However,
558 * this approach only works with a bounded number of
559 * clients, since the pending queues will grow without
560 * stopping. It might be better to find a way to take
561 * this call and stick it back on a queue in order to
562 * recycle this thread for a different request.
563 * 4. Return a new error code, which new cache managers will
564 * know enough to interpret as "sleep and retry", without
565 * the upper bound of 6-15 minutes that is imposed by the
566 * VBUSY handling. Users will see "waiting for
567 * busy volume," so they know that something is
568 * happening. Old cache managers must be able to do
569 * something reasonable with this, for instance, mark the
570 * server down. Fortunately, any error code < 0
571 * will elicit that behavior. See #1.
572 * 5. Some combination of the above. I like doing #2 for 10
573 * minutes, followed by #4. 3.1b and 3.2 cache managers
574 * will be fine as long as the restart period is
575 * not longer than 6.5 minutes, otherwise they may
576 * return ENODEV to users. 3.3 cache managers will be
577 * fine for 10 minutes, then will return
578 * ETIMEDOUT. 3.4 cache managers will just wait
579 * until the call works or fails definitively.
580 * NB. The problem with 2,3,4,5 is that old clients won't
581 * fail over to an alternate read-only replica while this
582 * server is restarting. 3.4 clients will fail over right away.
584 if (restartedat.tv_sec == 0) {
585 /* I'm not really worried about when we restarted, I'm */
586 /* just worried about when the first VBUSY was returned. */
587 FT_GetTimeOfDay(&restartedat, 0);
590 afs_perfstats.fs_nBusies++;
593 return (busyonrst ? VBUSY : restarting);
596 FT_GetTimeOfDay(&now, 0);
597 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
600 afs_perfstats.fs_nBusies++;
603 return (busyonrst ? VBUSY : restarting);
609 /* allow read operations on busy volume.
610 * must check local_errorCode because demand attach fs
611 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
612 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
613 #ifdef AFS_DEMAND_ATTACH_FS
614 /* DAFS case is complicated by the fact that local_errorCode can
615 * be VBUSY in cases where the volume is truly offline */
617 /* volume is in VOL_STATE_UNATTACHED */
620 #endif /* AFS_DEMAND_ATTACH_FS */
623 } else if (errorCode)
630 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
633 if ((*vptr)->disk.uniquifier != fid->Unique) {
634 VPutVnode(&fileCode, *vptr);
635 osi_Assert(fileCode == 0);
637 return (VNOVNODE); /* return the right error code, at least */
642 static_inline afs_int32
643 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
645 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
649 * This routine returns the ACL associated with the targetptr. If the
650 * targetptr isn't a directory, we access its parent dir and get the ACL
651 * thru the parent; in such case the parent's vnode is returned in
655 SetAccessList(Vnode ** targetptr, Volume ** volume,
656 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
657 AFSFid * Fid, int Lock)
659 if ((*targetptr)->disk.type == vDirectory) {
661 *ACL = VVnodeACL(*targetptr);
662 *ACLSize = VAclSize(*targetptr);
665 osi_Assert(Fid != 0);
670 parentvnode = (*targetptr)->disk.parent;
671 VPutVnode(&errorCode, *targetptr);
675 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
678 *ACL = VVnodeACL(*parent);
679 *ACLSize = VAclSize(*parent);
680 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
682 if ((*targetptr)->disk.parent != parentvnode) {
683 VPutVnode(&errorCode, *parent);
694 /* Must not be called with H_LOCK held */
696 client_CheckRights(struct client *client, struct acl_accessList *ACL,
700 ObtainReadLock(&client->lock);
701 if (client->CPS.prlist_len > 0 && !client->deleted &&
702 client->host && !(client->host->hostFlags & HOSTDELETED))
703 acl_CheckRights(ACL, &client->CPS, rights);
704 ReleaseReadLock(&client->lock);
707 /* Must not be called with H_LOCK held */
709 client_HasAsMember(struct client *client, afs_int32 id)
713 ObtainReadLock(&client->lock);
714 if (client->CPS.prlist_len > 0 && !client->deleted &&
715 client->host && !(client->host->hostFlags & HOSTDELETED))
716 code = acl_IsAMember(id, &client->CPS);
717 ReleaseReadLock(&client->lock);
722 * Compare the directory's ACL with the user's access rights in the client
723 * connection and return the user's and everybody else's access permissions
724 * in rights and anyrights, respectively
727 GetRights(struct client *client, struct acl_accessList *ACL,
728 afs_int32 * rights, afs_int32 * anyrights)
730 extern prlist SystemAnyUserCPS;
731 afs_int32 hrights = 0;
732 #ifndef AFS_PTHREAD_ENV
736 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
737 ViceLog(0, ("CheckRights failed\n"));
742 client_CheckRights(client, ACL, rights);
744 /* wait if somebody else is already doing the getCPS call */
746 while (client->host->hostFlags & HCPS_INPROGRESS) {
747 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
748 #ifdef AFS_PTHREAD_ENV
749 CV_WAIT(&client->host->cond, &host_glock_mutex);
750 #else /* AFS_PTHREAD_ENV */
752 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
753 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
754 #endif /* AFS_PTHREAD_ENV */
757 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
760 ("CheckRights: len=%u, for host=%s:%d\n",
761 client->host->hcps.prlist_len,
762 afs_inet_ntoa_r(client->host->host, hoststr),
763 ntohs(client->host->port)));
765 acl_CheckRights(ACL, &client->host->hcps, &hrights);
767 /* Allow system:admin the rights given with the -implicit option */
768 if (client_HasAsMember(client, SystemId))
769 *rights |= implicitAdminRights;
772 *anyrights |= hrights;
779 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
780 * a System:Administrator)
783 VanillaUser(struct client *client)
785 if (client_HasAsMember(client, SystemId))
786 return (0); /* not a system administrator, then you're "vanilla" */
793 * This unusual afs_int32-parameter routine encapsulates all volume package related
794 * operations together in a single function; it's called by almost all AFS
798 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
799 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
800 int chkforDir, Vnode ** parent, struct client **client,
801 int locktype, afs_int32 * rights, afs_int32 * anyrights)
803 struct acl_accessList *aCL; /* Internal access List */
804 int aCLSize; /* size of the access list */
805 Error errorCode = 0; /* return code to caller */
807 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
810 if (chkforDir == MustNOTBeDIR
811 && ((*targetptr)->disk.type == vDirectory))
813 else if (chkforDir == MustBeDIR
814 && ((*targetptr)->disk.type != vDirectory))
818 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
819 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
820 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
822 if (chkforDir == MustBeDIR)
823 osi_Assert((*parent) == 0);
825 if ((errorCode = GetClient(tcon, client)) != 0)
830 GetRights(*client, aCL, rights, anyrights);
831 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
832 if ((*targetptr)->disk.type != vDirectory) {
833 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
834 if ((*targetptr)->disk.owner == (*client)->ViceId)
835 (*rights) |= PRSFS_ADMINISTER;
837 (*rights) &= ~PRSFS_ADMINISTER;
839 #ifdef ADMIN_IMPLICIT_LOOKUP
840 /* admins get automatic lookup on everything */
841 if (!VanillaUser(*client))
842 (*rights) |= PRSFS_LOOKUP;
843 #endif /* ADMIN_IMPLICIT_LOOKUP */
846 } /*GetVolumePackage */
848 static_inline afs_int32
849 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
850 Vnode ** targetptr, int chkforDir, Vnode ** parent,
851 struct client **client, int locktype, afs_int32 * rights,
852 afs_int32 * anyrights)
854 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
855 chkforDir, parent, client, locktype,
861 * This is the opposite of GetVolumePackage(), and is always used at the end of
862 * AFS calls to put back all used vnodes and the volume in the proper order!
865 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
866 Vnode * parentptr, Volume * volptr,
867 struct client **client, struct VCallByVol *cbv)
869 Error fileCode = 0; /* Error code returned by the volume package */
871 if (parentwhentargetnotdir) {
872 VPutVnode(&fileCode, parentwhentargetnotdir);
873 osi_Assert(!fileCode || (fileCode == VSALVAGE));
876 VPutVnode(&fileCode, targetptr);
877 osi_Assert(!fileCode || (fileCode == VSALVAGE));
880 VPutVnode(&fileCode, parentptr);
881 osi_Assert(!fileCode || (fileCode == VSALVAGE));
884 VPutVolumeWithCall(volptr, cbv);
889 } /*PutVolumePackage */
892 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
893 Vnode * parentptr, Volume * volptr, struct client **client)
895 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
896 volptr, client, NULL);
900 VolumeOwner(struct client *client, Vnode * targetptr)
902 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
905 return (client->ViceId == owner);
908 * We don't have to check for host's cps since only regular
909 * viceid are volume owners.
911 return (client_HasAsMember(client, owner));
917 VolumeRootVnode(Vnode * targetptr)
919 return ((targetptr->vnodeNumber == ROOTVNODE)
920 && (targetptr->disk.uniquifier == 1));
922 } /*VolumeRootVnode */
925 * Check if target file has the proper access permissions for the Fetch
926 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
927 * StoreStatus) related calls
929 /* this code should probably just set a "priv" flag where all the audit events
930 * are now, and only generate the audit event once at the end of the routine,
931 * thus only generating the event if all the checks succeed, but only because
932 * of the privilege XXX
935 Check_PermissionRights(Vnode * targetptr, struct client *client,
936 afs_int32 rights, int CallingRoutine,
937 AFSStoreStatus * InStatus)
940 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
941 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
942 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
944 if (CallingRoutine & CHK_FETCH) {
945 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
946 if (targetptr->disk.type == vDirectory
947 || targetptr->disk.type == vSymlink) {
948 if (!(rights & PRSFS_LOOKUP)
949 #ifdef ADMIN_IMPLICIT_LOOKUP
950 /* grant admins fetch on all directories */
951 && VanillaUser(client)
952 #endif /* ADMIN_IMPLICIT_LOOKUP */
953 && !VolumeOwner(client, targetptr))
956 /* must have read access, or be owner and have insert access */
957 if (!(rights & PRSFS_READ)
958 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
959 && (client->ViceId != AnonymousID))))
962 if (CallingRoutine == CHK_FETCHDATA
963 && targetptr->disk.type == vFile)
964 #ifdef USE_GROUP_PERMS
965 if (!OWNSp(client, targetptr)
966 && !client_HasAsMember(client, targetptr->disk.owner)) {
968 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
972 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
977 * The check with the ownership below is a kludge to allow
978 * reading of files created with no read permission. The owner
979 * of the file is always allowed to read it.
981 if ((client->ViceId != targetptr->disk.owner)
982 && VanillaUser(client))
984 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
985 modeBits) ? 0 : EACCES);
987 } else { /* !VanillaUser(client) && !FetchData */
989 osi_audit(PrivilegeEvent, 0, AUD_ID,
990 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
993 } else { /* a store operation */
994 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
995 && (CallingRoutine != CHK_STOREACL)
996 && (targetptr->disk.type == vFile)) {
997 /* bypass protection checks on first store after a create
998 * for the creator; also prevent chowns during this time
999 * unless you are a system administrator */
1000 /****** InStatus->Owner && UnixModeBits better be SET!! */
1001 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1004 else if (VanillaUser(client))
1005 return (EPERM); /* Was EACCES */
1007 osi_audit(PrivilegeEvent, 0, AUD_ID,
1008 (client ? client->ViceId : 0), AUD_INT,
1009 CallingRoutine, AUD_END);
1012 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1013 osi_audit(PrivilegeEvent, 0, AUD_ID,
1014 (client ? client->ViceId : 0), AUD_INT,
1015 CallingRoutine, AUD_END);
1017 if (readonlyServer) {
1020 if (CallingRoutine == CHK_STOREACL) {
1021 if (!(rights & PRSFS_ADMINISTER)
1022 && !VolumeOwner(client, targetptr))
1024 } else { /* store data or status */
1025 /* watch for chowns and chgrps */
1026 if (CHOWN(InStatus, targetptr)
1027 || CHGRP(InStatus, targetptr)) {
1030 else if (VanillaUser(client))
1031 return (EPERM); /* Was EACCES */
1033 osi_audit(PrivilegeEvent, 0, AUD_ID,
1034 (client ? client->ViceId : 0), AUD_INT,
1035 CallingRoutine, AUD_END);
1037 /* must be sysadmin to set suid/sgid bits */
1038 if ((InStatus->Mask & AFS_SETMODE) &&
1040 (InStatus->UnixModeBits & 0xc00) != 0) {
1042 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1046 if (VanillaUser(client))
1049 osi_audit(PrivSetID, 0, AUD_ID,
1050 (client ? client->ViceId : 0), AUD_INT,
1051 CallingRoutine, AUD_END);
1053 if (CallingRoutine == CHK_STOREDATA) {
1056 if (!(rights & PRSFS_WRITE))
1058 /* Next thing is tricky. We want to prevent people
1059 * from writing files sans 0200 bit, but we want
1060 * creating new files with 0444 mode to work. We
1061 * don't check the 0200 bit in the "you are the owner"
1062 * path above, but here we check the bit. However, if
1063 * you're a system administrator, we ignore the 0200
1064 * bit anyway, since you may have fchowned the file,
1066 #ifdef USE_GROUP_PERMS
1067 if ((targetptr->disk.type == vFile)
1068 && VanillaUser(client)) {
1069 if (!OWNSp(client, targetptr)
1070 && !client_HasAsMember(client, targetptr->disk.owner)) {
1072 ((GROUPWRITE & targetptr->disk.modeBits)
1076 ((OWNERWRITE & targetptr->disk.modeBits)
1081 if ((targetptr->disk.type != vDirectory)
1082 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1085 if (VanillaUser(client))
1088 osi_audit(PrivilegeEvent, 0, AUD_ID,
1089 (client ? client->ViceId : 0),
1090 AUD_INT, CallingRoutine, AUD_END);
1092 } else { /* a status store */
1095 if (targetptr->disk.type == vDirectory) {
1096 if (!(rights & PRSFS_DELETE)
1097 && !(rights & PRSFS_INSERT))
1099 } else { /* a file or symlink */
1100 if (!(rights & PRSFS_WRITE))
1110 } /*Check_PermissionRights */
1114 * The Access List information is converted from its internal form in the
1115 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1116 * external form and returned back to the caller, via the AccessList
1120 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1121 struct AFSOpaque *AccessList)
1123 char *eACL; /* External access list placeholder */
1125 if (acl_Externalize_pr
1126 (hpr_IdToName, (targetptr->disk.type ==
1127 vDirectory ? VVnodeACL(targetptr) :
1128 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1131 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1132 acl_FreeExternalACL(&eACL);
1135 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1136 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1138 acl_FreeExternalACL(&eACL);
1141 } /*RXFetch_AccessList */
1145 * The Access List information is converted from its external form in the
1146 * input AccessList structure to the internal representation and copied into
1147 * the target dir's vnode storage.
1150 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1152 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1154 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1157 if ((newACL->size + 4) > VAclSize(targetptr))
1159 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1160 acl_FreeACL(&newACL);
1163 } /*RXStore_AccessList */
1166 /* In our current implementation, each successive data store (new file
1167 * data version) creates a new inode. This function creates the new
1168 * inode, copies the old inode's contents to the new one, remove the old
1169 * inode (i.e. decrement inode count -- if it's currently used the delete
1170 * will be delayed), and modify some fields (i.e. vnode's
1171 * disk.inodeNumber and cloned)
1173 #define COPYBUFFSIZE 8192
1174 #define MAXFSIZE (~(afs_fsize_t) 0)
1176 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1179 Inode nearInode AFS_UNUSED;
1186 int rc; /* return code */
1187 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1188 FdHandle_t *targFdP; /* Source Inode file handle */
1189 FdHandle_t *newFdP; /* Dest Inode file handle */
1191 if (targetptr->disk.type == vDirectory)
1192 DFlush(); /* just in case? */
1194 VN_GET_LEN(size, targetptr);
1202 buff = (char *)malloc(COPYBUFFSIZE);
1207 ino = VN_GET_INO(targetptr);
1208 if (!VALID_INO(ino)) {
1210 VTakeOffline(volptr);
1211 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1215 targFdP = IH_OPEN(targetptr->handle);
1216 if (targFdP == NULL) {
1219 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1220 targetptr->vnodeNumber, V_id(volptr), rc));
1222 VTakeOffline(volptr);
1226 nearInode = VN_GET_INO(targetptr);
1228 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1229 VPartitionPath(V_partition(volptr)), nearInode,
1230 V_id(volptr), targetptr->vnodeNumber,
1231 targetptr->disk.uniquifier,
1232 (int)targetptr->disk.dataVersion);
1233 if (!VALID_INO(ino)) {
1235 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1236 volptr->partition->name, V_id(volptr), errno));
1241 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1242 newFdP = IH_OPEN(newH);
1243 osi_Assert(newFdP != NULL);
1247 if (size > COPYBUFFSIZE) { /* more than a buffer */
1248 length = COPYBUFFSIZE;
1249 size -= COPYBUFFSIZE;
1254 rdlen = FDH_PREAD(targFdP, buff, length, done);
1255 if (rdlen == length) {
1256 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1260 /* Callers of this function are not prepared to recover
1261 * from error that put the filesystem in an inconsistent
1262 * state. Make sure that we force the volume off-line if
1263 * we some error other than ENOSPC - 4.29.99)
1265 * In case we are unable to write the required bytes, and the
1266 * error code indicates that the disk is full, we roll-back to
1267 * the initial state.
1269 if ((rdlen != length) || (wrlen != length)) {
1270 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1272 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1273 volptr->partition->name, V_id(volptr)));
1274 /* remove destination inode which was partially copied till now */
1275 FDH_REALLYCLOSE(newFdP);
1277 FDH_REALLYCLOSE(targFdP);
1278 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1281 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1282 rc, V_id(volptr), volptr->partition->name));
1283 VTakeOffline(volptr);
1288 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1289 * since we never do any I/O anywhere near 2^32 bytes at a
1290 * time, just case to an unsigned int for printing */
1293 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1294 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1295 (unsigned)wrlen, errno));
1296 #if defined(AFS_DEMAND_ATTACH_FS)
1297 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1299 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1301 /* Decrement this inode so salvager doesn't find it. */
1302 FDH_REALLYCLOSE(newFdP);
1304 FDH_REALLYCLOSE(targFdP);
1305 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1307 VTakeOffline(volptr);
1311 #ifndef AFS_PTHREAD_ENV
1313 #endif /* !AFS_PTHREAD_ENV */
1315 FDH_REALLYCLOSE(targFdP);
1316 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1317 V_parentId(volptr));
1319 IH_RELEASE(targetptr->handle);
1321 rc = FDH_SYNC(newFdP);
1322 osi_Assert(rc == 0);
1324 targetptr->handle = newH;
1325 VN_SET_INO(targetptr, ino);
1326 targetptr->disk.cloned = 0;
1327 /* Internal change to vnode, no user level change to volume - def 5445 */
1328 targetptr->changed_oldTime = 1;
1330 return 0; /* success */
1334 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1337 char *buff = malloc(COPYBUFFSIZE);
1342 afs_foff_t done = off;
1344 if (size > FDH_SIZE(targFdP) - off)
1345 size = FDH_SIZE(targFdP) - off;
1348 if (size > COPYBUFFSIZE) { /* more than a buffer */
1349 length = COPYBUFFSIZE;
1350 size -= COPYBUFFSIZE;
1355 rdlen = FDH_PREAD(targFdP, buff, length, done);
1356 if (rdlen == length) {
1357 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1363 if ((rdlen != length) || (wrlen != length)) {
1364 /* no error recovery, at the worst we'll have a "hole"
1376 * Common code to handle with removing the Name (file when it's called from
1377 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1378 * given directory, parentptr.
1380 int DT1 = 0, DT0 = 0;
1382 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1383 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1385 DirHandle childdir; /* Handle for dir package I/O */
1386 Error errorCode = 0;
1390 /* watch for invalid names */
1391 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1394 if (CheckLength(volptr, parentptr, -1)) {
1395 VTakeOffline(volptr);
1399 if (parentptr->disk.cloned) {
1400 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1401 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1403 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1409 /* check that the file is in the directory */
1410 SetDirHandle(dir, parentptr);
1411 if (afs_dir_Lookup(dir, Name, fileFid))
1413 fileFid->Volume = V_id(volptr);
1415 /* just-in-case check for something causing deadlock */
1416 if (fileFid->Vnode == parentptr->vnodeNumber)
1419 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1423 if (ChkForDir == MustBeDIR) {
1424 if ((*targetptr)->disk.type != vDirectory)
1426 } else if ((*targetptr)->disk.type == vDirectory)
1429 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1431 * If the uniquifiers dont match then instead of asserting
1432 * take the volume offline and return VSALVAGE
1434 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1435 VTakeOffline(volptr);
1437 ("Volume %u now offline, must be salvaged.\n",
1439 errorCode = VSALVAGE;
1443 if (ChkForDir == MustBeDIR) {
1444 SetDirHandle(&childdir, *targetptr);
1445 if (afs_dir_IsEmpty(&childdir) != 0)
1449 (*targetptr)->delete = 1;
1450 } else if ((--(*targetptr)->disk.linkCount) == 0)
1451 (*targetptr)->delete = 1;
1452 if ((*targetptr)->delete) {
1453 if (VN_GET_INO(*targetptr)) {
1455 IH_REALLYCLOSE((*targetptr)->handle);
1457 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1458 V_parentId(volptr));
1459 IH_RELEASE((*targetptr)->handle);
1460 if (errorCode == -1) {
1462 ("DT: inode=%s, name=%s, errno=%d\n",
1463 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1465 if (errno != ENOENT)
1467 VTakeOffline(volptr);
1469 ("Volume %u now offline, must be salvaged.\n",
1477 VN_SET_INO(*targetptr, (Inode) 0);
1479 afs_fsize_t adjLength;
1480 VN_GET_LEN(adjLength, *targetptr);
1481 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1485 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1487 code = afs_dir_Delete(dir, Name);
1490 ("Error %d deleting %s\n", code,
1491 (((*targetptr)->disk.type ==
1492 Directory) ? "directory" : "file")));
1493 VTakeOffline(volptr);
1495 ("Volume %u now offline, must be salvaged.\n",
1508 * This routine updates the parent directory's status block after the
1509 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1510 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1514 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1515 int author, int linkcount,
1516 #if FS_STATS_DETAILED
1517 char a_inSameNetwork
1518 #endif /* FS_STATS_DETAILED */
1521 afs_fsize_t newlength; /* Holds new directory length */
1522 afs_fsize_t parentLength;
1524 #if FS_STATS_DETAILED
1525 Date currDate; /*Current date */
1526 int writeIdx; /*Write index to bump */
1527 int timeIdx; /*Authorship time index to bump */
1528 #endif /* FS_STATS_DETAILED */
1530 parentptr->disk.dataVersion++;
1531 newlength = (afs_fsize_t) afs_dir_Length(dir);
1533 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1534 * (create, symlink, link, makedir) so we need to check if we have enough space
1535 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1536 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1538 VN_GET_LEN(parentLength, parentptr);
1539 if (nBlocks(newlength) != nBlocks(parentLength)) {
1540 VAdjustDiskUsage(&errorCode, volptr,
1541 (nBlocks(newlength) - nBlocks(parentLength)),
1542 (nBlocks(newlength) - nBlocks(parentLength)));
1544 VN_SET_LEN(parentptr, newlength);
1546 #if FS_STATS_DETAILED
1548 * Update directory write stats for this volume. Note that the auth
1549 * counter is located immediately after its associated ``distance''
1552 if (a_inSameNetwork)
1553 writeIdx = VOL_STATS_SAME_NET;
1555 writeIdx = VOL_STATS_DIFF_NET;
1556 V_stat_writes(volptr, writeIdx)++;
1557 if (author != AnonymousID) {
1558 V_stat_writes(volptr, writeIdx + 1)++;
1562 * Update the volume's authorship information in response to this
1563 * directory operation. Get the current time, decide to which time
1564 * slot this operation belongs, and bump the appropriate slot.
1566 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1568 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1569 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1570 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1571 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1572 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1573 if (parentptr->disk.author == author) {
1574 V_stat_dirSameAuthor(volptr, timeIdx)++;
1576 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1578 #endif /* FS_STATS_DETAILED */
1580 parentptr->disk.author = author;
1581 parentptr->disk.linkCount = linkcount;
1582 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1583 parentptr->disk.serverModifyTime = FT_ApproxTime();
1584 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1589 * Update the target file's (or dir's) status block after the specified
1590 * operation is complete. Note that some other fields maybe updated by
1591 * the individual module.
1594 /* XXX INCOMPLETE - More attention is needed here! */
1596 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1597 struct client *client, AFSStoreStatus * InStatus,
1598 Vnode * parentptr, Volume * volptr,
1601 #if FS_STATS_DETAILED
1602 Date currDate; /*Current date */
1603 int writeIdx; /*Write index to bump */
1604 int timeIdx; /*Authorship time index to bump */
1605 #endif /* FS_STATS_DETAILED */
1607 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1608 targetptr->disk.parent = parentptr->vnodeNumber;
1609 VN_SET_LEN(targetptr, length);
1610 /* targetptr->disk.group = 0; save some cycles */
1611 targetptr->disk.modeBits = 0777;
1612 targetptr->disk.owner = client->ViceId;
1613 targetptr->disk.dataVersion = 0; /* consistent with the client */
1614 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1615 /* the inode was created in Alloc_NewVnode() */
1617 #if FS_STATS_DETAILED
1619 * Update file write stats for this volume. Note that the auth
1620 * counter is located immediately after its associated ``distance''
1623 if (client->InSameNetwork)
1624 writeIdx = VOL_STATS_SAME_NET;
1626 writeIdx = VOL_STATS_DIFF_NET;
1627 V_stat_writes(volptr, writeIdx)++;
1628 if (client->ViceId != AnonymousID) {
1629 V_stat_writes(volptr, writeIdx + 1)++;
1633 * We only count operations that DON'T involve creating new objects
1634 * (files, symlinks, directories) or simply setting status as
1635 * authorship-change operations.
1637 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1639 * Update the volume's authorship information in response to this
1640 * file operation. Get the current time, decide to which time
1641 * slot this operation belongs, and bump the appropriate slot.
1643 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1646 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1647 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1648 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1649 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1650 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1651 VOL_STATS_TIME_IDX_5);
1652 if (targetptr->disk.author == client->ViceId) {
1653 V_stat_fileSameAuthor(volptr, timeIdx)++;
1655 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1658 #endif /* FS_STATS_DETAILED */
1660 if (!(Caller & TVS_SSTATUS))
1661 targetptr->disk.author = client->ViceId;
1662 if (Caller & TVS_SDATA) {
1663 targetptr->disk.dataVersion++;
1664 if (VanillaUser(client)) {
1665 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1666 #ifdef CREATE_SGUID_ADMIN_ONLY
1667 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1671 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1672 /* store status, must explicitly request to change the date */
1673 if (InStatus->Mask & AFS_SETMODTIME)
1674 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1675 } else { /* other: date always changes, but perhaps to what is specified by caller */
1676 targetptr->disk.unixModifyTime =
1677 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1678 ClientModTime : FT_ApproxTime());
1680 if (InStatus->Mask & AFS_SETOWNER) {
1681 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1682 if (VanillaUser(client)) {
1683 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1684 #ifdef CREATE_SGUID_ADMIN_ONLY
1685 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1688 targetptr->disk.owner = InStatus->Owner;
1689 if (VolumeRootVnode(targetptr)) {
1690 Error errorCode = 0; /* what should be done with this? */
1692 V_owner(targetptr->volumePtr) = InStatus->Owner;
1693 VUpdateVolume(&errorCode, targetptr->volumePtr);
1696 if (InStatus->Mask & AFS_SETMODE) {
1697 int modebits = InStatus->UnixModeBits;
1698 #define CREATE_SGUID_ADMIN_ONLY 1
1699 #ifdef CREATE_SGUID_ADMIN_ONLY
1700 if (VanillaUser(client))
1701 modebits = modebits & 0777;
1703 if (VanillaUser(client)) {
1704 targetptr->disk.modeBits = modebits;
1706 targetptr->disk.modeBits = modebits;
1709 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1710 CHK_STOREDATA, AUD_END);
1714 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1715 CHK_STORESTATUS, AUD_END);
1722 targetptr->disk.serverModifyTime = FT_ApproxTime();
1723 if (InStatus->Mask & AFS_SETGROUP)
1724 targetptr->disk.group = InStatus->Group;
1725 /* vnode changed : to be written back by VPutVnode */
1726 targetptr->changed_newTime = 1;
1728 } /*Update_TargetVnodeStatus */
1732 * Fills the CallBack structure with the expiration time and type of callback
1733 * structure. Warning: this function is currently incomplete.
1736 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1738 /* CallBackTime could not be 0 */
1739 if (CallBackTime == 0) {
1740 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1741 CallBack->ExpirationTime = 0;
1743 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1744 CallBack->CallBackVersion = CALLBACK_VERSION;
1745 CallBack->CallBackType = CB_SHARED; /* The default for now */
1747 } /*SetCallBackStruct */
1751 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1752 * allocation; if some error occured (exceeded volume quota or partition
1753 * was full, or whatever), it frees the space back and returns the code.
1754 * We usually pre-adjust the volume space to make sure that there's
1755 * enough space before consuming some.
1758 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1759 afs_sfsize_t checkLength)
1764 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1766 VAdjustDiskUsage(&nc, volptr, -length, 0);
1767 if (rc == VOVERQUOTA) {
1769 ("Volume %u (%s) is full\n", V_id(volptr),
1773 if (rc == VDISKFULL) {
1775 ("Partition %s that contains volume %u is full\n",
1776 volptr->partition->name, V_id(volptr)));
1779 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1784 } /*AdjustDiskUsage */
1787 * Common code that handles the creation of a new file (SAFS_CreateFile and
1788 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1791 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1792 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1793 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1795 Error errorCode = 0; /* Error code returned back */
1798 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1802 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1803 BlocksPreallocatedForVnode))) {
1805 ("Insufficient space to allocate %lld blocks\n",
1806 (afs_intmax_t) BlocksPreallocatedForVnode));
1810 if (CheckLength(volptr, parentptr, -1)) {
1811 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1812 VTakeOffline(volptr);
1816 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1817 if (errorCode != 0) {
1818 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1821 OutFid->Volume = V_id(volptr);
1822 OutFid->Vnode = (*targetptr)->vnodeNumber;
1823 OutFid->Unique = (*targetptr)->disk.uniquifier;
1825 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1827 /* create the inode now itself */
1829 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1830 VPartitionPath(V_partition(volptr)), nearInode,
1831 V_id(volptr), (*targetptr)->vnodeNumber,
1832 (*targetptr)->disk.uniquifier, 1);
1834 /* error in creating inode */
1835 if (!VALID_INO(inode)) {
1837 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1838 (*targetptr)->volumePtr->header->diskstuff.id,
1839 (*targetptr)->vnodeNumber, errno));
1840 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1841 (*targetptr)->delete = 1; /* delete vnode */
1844 VN_SET_INO(*targetptr, inode);
1845 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1847 /* copy group from parent dir */
1848 (*targetptr)->disk.group = parentptr->disk.group;
1850 if (parentptr->disk.cloned) {
1851 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1852 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1853 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1854 /* delete the vnode previously allocated */
1855 (*targetptr)->delete = 1;
1856 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1857 IH_REALLYCLOSE((*targetptr)->handle);
1858 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1860 ("Alloc_NewVnode: partition %s idec %s failed\n",
1861 volptr->partition->name, PrintInode(stmp, inode)));
1862 IH_RELEASE((*targetptr)->handle);
1868 /* add the name to the directory */
1869 SetDirHandle(dir, parentptr);
1870 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1871 (*targetptr)->delete = 1;
1872 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1873 IH_REALLYCLOSE((*targetptr)->handle);
1874 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1876 ("Alloc_NewVnode: partition %s idec %s failed\n",
1877 volptr->partition->name, PrintInode(stmp, inode)));
1878 IH_RELEASE((*targetptr)->handle);
1884 } /*Alloc_NewVnode */
1888 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1892 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1894 int Time; /* Used for time */
1895 int writeVnode = targetptr->changed_oldTime; /* save original status */
1897 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1898 Time = FT_ApproxTime();
1899 switch (LockingType) {
1902 if (Time > targetptr->disk.lock.lockTime)
1903 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1905 Time += AFS_LOCKWAIT;
1906 if (LockingType == LockRead) {
1907 if ( !(rights & PRSFS_LOCK) &&
1908 !(rights & PRSFS_WRITE) &&
1909 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1912 if (targetptr->disk.lock.lockCount >= 0) {
1913 ++(targetptr->disk.lock.lockCount);
1914 targetptr->disk.lock.lockTime = Time;
1917 } else if (LockingType == LockWrite) {
1918 if ( !(rights & PRSFS_WRITE) &&
1919 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1922 if (targetptr->disk.lock.lockCount == 0) {
1923 targetptr->disk.lock.lockCount = -1;
1924 targetptr->disk.lock.lockTime = Time;
1930 Time += AFS_LOCKWAIT;
1931 if (targetptr->disk.lock.lockCount != 0)
1932 targetptr->disk.lock.lockTime = Time;
1937 if ((--targetptr->disk.lock.lockCount) <= 0)
1938 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1942 targetptr->changed_oldTime = writeVnode; /* restore old status */
1943 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1946 } /*HandleLocking */
1948 /* Checks if caller has the proper AFS and Unix (WRITE) access permission to the target directory; Prfs_Mode refers to the AFS Mode operation while rights contains the caller's access permissions to the directory. */
1951 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1955 if (!(rights & Prfs_Mode))
1957 if ((targetptr->disk.type != vDirectory)
1958 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1964 * If some flags (i.e. min or max quota) are set, the volume's in disk
1965 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1966 * update, if applicable.
1969 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1970 char *Name, char *OfflineMsg, char *Motd)
1972 Error errorCode = 0;
1974 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1975 V_minquota(volptr) = StoreVolStatus->MinQuota;
1976 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1977 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1978 if (strlen(OfflineMsg) > 0) {
1979 strcpy(V_offlineMessage(volptr), OfflineMsg);
1981 if (strlen(Name) > 0) {
1982 strcpy(V_name(volptr), Name);
1984 #if OPENAFS_VOL_STATS
1986 * We don't overwrite the motd field, since it's now being used
1990 if (strlen(Motd) > 0) {
1991 strcpy(V_motd(volptr), Motd);
1993 #endif /* FS_STATS_DETAILED */
1994 VUpdateVolume(&errorCode, volptr);
1997 } /*RXUpdate_VolumeStatus */
2001 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2002 char **motd, Volume * volptr)
2006 status->Vid = V_id(volptr);
2007 status->ParentId = V_parentId(volptr);
2008 status->Online = V_inUse(volptr);
2009 status->InService = V_inService(volptr);
2010 status->Blessed = V_blessed(volptr);
2011 status->NeedsSalvage = V_needsSalvaged(volptr);
2012 if (VolumeWriteable(volptr))
2013 status->Type = ReadWrite;
2015 status->Type = ReadOnly;
2016 status->MinQuota = V_minquota(volptr);
2017 status->MaxQuota = V_maxquota(volptr);
2018 status->BlocksInUse = V_diskused(volptr);
2019 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
2020 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
2022 /* now allocate and copy these things; they're freed by the RXGEN stub */
2023 temp = strlen(V_name(volptr)) + 1;
2024 *name = malloc(temp);
2026 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2028 strcpy(*name, V_name(volptr));
2029 temp = strlen(V_offlineMessage(volptr)) + 1;
2030 *offMsg = malloc(temp);
2032 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2034 strcpy(*offMsg, V_offlineMessage(volptr));
2035 #if OPENAFS_VOL_STATS
2038 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2040 strcpy(*motd, nullString);
2042 temp = strlen(V_motd(volptr)) + 1;
2043 *motd = malloc(temp);
2045 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2047 strcpy(*motd, V_motd(volptr));
2048 #endif /* OPENAFS_VOL_STATS */
2050 } /*RXGetVolumeStatus */
2054 FileNameOK(char *aname)
2059 /* watch for @sys on the right */
2060 if (strcmp(aname + i - 4, "@sys") == 0)
2063 while ((tc = *aname++)) {
2065 return 0; /* very bad character to encounter */
2067 return 1; /* file name is ok */
2073 * This variant of symlink is expressly to support the AFS/DFS translator
2074 * and is not supported by the AFS fileserver. We just return EINVAL.
2075 * The cache manager should not generate this call to an AFS cache manager.
2078 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2079 char *LinkContents, struct AFSStoreStatus *InStatus,
2080 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2081 struct AFSFetchStatus *OutDirStatus,
2082 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2088 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2089 struct FsCmdInputs * Inputs,
2090 struct FsCmdOutputs * Outputs)
2094 switch (Inputs->command) {
2098 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2099 Inputs->command, Outputs->code));
2104 static struct afs_buffer {
2105 struct afs_buffer *next;
2106 } *freeBufferList = 0;
2107 static int afs_buffersAlloced = 0;
2110 FreeSendBuffer(struct afs_buffer *adata)
2113 afs_buffersAlloced--;
2114 adata->next = freeBufferList;
2115 freeBufferList = adata;
2119 } /*FreeSendBuffer */
2121 /* allocate space for sender */
2123 AllocSendBuffer(void)
2125 struct afs_buffer *tp;
2128 afs_buffersAlloced++;
2129 if (!freeBufferList) {
2132 tmp = malloc(sendBufSize);
2134 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2138 tp = freeBufferList;
2139 freeBufferList = tp->next;
2143 } /*AllocSendBuffer */
2144 #endif /* HAVE_PIOV */
2147 * This routine returns the status info associated with the targetptr vnode
2148 * in the AFSFetchStatus structure. Some of the newer fields, such as
2149 * SegSize and Group are not yet implemented
2153 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2154 afs_int32 anyrights, Vnode * parentptr)
2156 /* initialize return status from a vnode */
2157 status->InterfaceVersion = 1;
2158 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2159 status->errorCode = 0;
2160 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2161 if (targetptr->disk.type == vFile)
2162 status->FileType = File;
2163 else if (targetptr->disk.type == vDirectory)
2164 status->FileType = Directory;
2165 else if (targetptr->disk.type == vSymlink)
2166 status->FileType = SymbolicLink;
2168 status->FileType = Invalid; /*invalid type field */
2169 status->LinkCount = targetptr->disk.linkCount;
2171 afs_fsize_t targetLen;
2172 VN_GET_LEN(targetLen, targetptr);
2173 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2175 status->DataVersion = targetptr->disk.dataVersion;
2176 status->Author = targetptr->disk.author;
2177 status->Owner = targetptr->disk.owner;
2178 status->CallerAccess = rights;
2179 status->AnonymousAccess = anyrights;
2180 status->UnixModeBits = targetptr->disk.modeBits;
2181 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2182 status->ParentVnode =
2183 (status->FileType ==
2184 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2185 status->ParentUnique =
2186 (status->FileType ==
2187 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2188 status->ServerModTime = targetptr->disk.serverModifyTime;
2189 status->Group = targetptr->disk.group;
2190 status->lockCount = targetptr->disk.lock.lockCount;
2191 status->errorCode = 0;
2197 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2198 afs_sfsize_t Pos, afs_sfsize_t Len,
2199 struct AFSFetchStatus *OutStatus,
2200 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2203 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2204 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2205 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2206 Error errorCode = 0; /* return code to caller */
2207 Error fileCode = 0; /* return code from vol package */
2208 Volume *volptr = 0; /* pointer to the volume */
2209 struct client *client = 0; /* pointer to the client data */
2210 struct rx_connection *tcon; /* the connection we're part of */
2212 afs_int32 rights, anyrights; /* rights for this and any user */
2213 struct client *t_client = NULL; /* tmp ptr to client data */
2214 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2215 struct VCallByVol tcbv, *cbv = NULL;
2216 static int remainder = 0; /* shared access protected by FS_LOCK */
2217 struct fsstats fsstats;
2218 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2219 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2221 #if FS_STATS_DETAILED
2222 int readIdx; /* Index of read stats array to bump */
2223 #endif /* FS_STATS_DETAILED */
2225 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2228 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2231 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2233 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2236 /* Get ptr to client data for user Id for logging */
2237 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2238 logHostAddr.s_addr = rxr_HostOf(tcon);
2240 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2241 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2242 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2244 queue_NodeInit(&tcbv);
2249 * Get volume/vnode for the fetched file; caller's access rights to
2250 * it are also returned
2253 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2254 &parentwhentargetnotdir, &client, READ_LOCK,
2255 &rights, &anyrights)))
2258 SetVolumeSync(Sync, volptr);
2260 #if FS_STATS_DETAILED
2262 * Remember that another read operation was performed.
2265 if (client->InSameNetwork)
2266 readIdx = VOL_STATS_SAME_NET;
2268 readIdx = VOL_STATS_DIFF_NET;
2269 V_stat_reads(volptr, readIdx)++;
2270 if (client->ViceId != AnonymousID) {
2271 V_stat_reads(volptr, readIdx + 1)++;
2274 #endif /* FS_STATS_DETAILED */
2275 /* Check whether the caller has permission access to fetch the data */
2277 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2281 * Drop the read lock on the parent directory after saving the parent
2282 * vnode information we need to pass to GetStatus
2284 if (parentwhentargetnotdir != NULL) {
2285 tparentwhentargetnotdir = *parentwhentargetnotdir;
2286 VPutVnode(&fileCode, parentwhentargetnotdir);
2287 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2288 parentwhentargetnotdir = NULL;
2291 fsstats_StartXfer(&fsstats);
2293 /* actually do the data transfer */
2295 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2296 &bytesToXfer, &bytesXferred);
2298 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2304 /* write back the OutStatus from the target vnode */
2305 GetStatus(targetptr, OutStatus, rights, anyrights,
2306 &tparentwhentargetnotdir);
2308 /* if a r/w volume, promise a callback to the caller */
2309 if (VolumeWriteable(volptr))
2310 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2312 struct AFSFid myFid;
2313 memset(&myFid, 0, sizeof(struct AFSFid));
2314 myFid.Volume = Fid->Volume;
2315 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2319 /* Update and store volume/vnode and parent vnodes back */
2320 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2321 (Vnode *) 0, volptr, &client, cbv);
2322 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2323 errorCode = CallPostamble(tcon, errorCode, thost);
2325 fsstats_FinishOp(&fsstats, errorCode);
2327 osi_auditU(acall, FetchDataEvent, errorCode,
2328 AUD_ID, t_client ? t_client->ViceId : 0,
2329 AUD_FID, Fid, AUD_END);
2332 } /*SRXAFS_FetchData */
2335 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2336 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2337 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2339 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2344 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2345 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2346 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2349 afs_sfsize_t tPos, tLen;
2351 tPos = (afs_sfsize_t) Pos;
2352 tLen = (afs_sfsize_t) Len;
2355 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2361 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2362 struct AFSOpaque * AccessList,
2363 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2365 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2366 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2367 Error errorCode = 0; /* return error code to caller */
2368 Volume *volptr = 0; /* pointer to the volume */
2369 struct client *client = 0; /* pointer to the client data */
2370 afs_int32 rights, anyrights; /* rights for this and any user */
2371 struct rx_connection *tcon = rx_ConnectionOf(acall);
2373 struct client *t_client = NULL; /* tmp ptr to client data */
2374 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2375 struct fsstats fsstats;
2377 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2380 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2383 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2385 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2388 /* Get ptr to client data for user Id for logging */
2389 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2390 logHostAddr.s_addr = rxr_HostOf(tcon);
2392 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2393 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2394 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2396 AccessList->AFSOpaque_len = 0;
2397 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2398 if (!AccessList->AFSOpaque_val) {
2399 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2403 * Get volume/vnode for the fetched file; caller's access rights to it
2407 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2408 &parentwhentargetnotdir, &client, READ_LOCK,
2409 &rights, &anyrights)))
2412 SetVolumeSync(Sync, volptr);
2414 /* Check whether we have permission to fetch the ACL */
2416 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2419 /* Get the Access List from the dir's vnode */
2421 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2424 /* Get OutStatus back From the target Vnode */
2425 GetStatus(targetptr, OutStatus, rights, anyrights,
2426 parentwhentargetnotdir);
2429 /* Update and store volume/vnode and parent vnodes back */
2430 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2433 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2434 AccessList->AFSOpaque_val));
2435 errorCode = CallPostamble(tcon, errorCode, thost);
2437 fsstats_FinishOp(&fsstats, errorCode);
2439 osi_auditU(acall, FetchACLEvent, errorCode,
2440 AUD_ID, t_client ? t_client->ViceId : 0,
2442 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2444 } /*SRXAFS_FetchACL */
2448 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2449 * merged into it when possible.
2453 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2454 struct AFSFetchStatus *OutStatus,
2455 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2457 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2458 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2459 Error errorCode = 0; /* return code to caller */
2460 Volume *volptr = 0; /* pointer to the volume */
2461 struct client *client = 0; /* pointer to the client data */
2462 afs_int32 rights, anyrights; /* rights for this and any user */
2463 struct client *t_client = NULL; /* tmp ptr to client data */
2464 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2465 struct rx_connection *tcon = rx_ConnectionOf(acall);
2467 /* Get ptr to client data for user Id for logging */
2468 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2469 logHostAddr.s_addr = rxr_HostOf(tcon);
2471 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2472 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2473 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2475 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2478 * Get volume/vnode for the fetched file; caller's rights to it are
2482 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2483 &parentwhentargetnotdir, &client, READ_LOCK,
2484 &rights, &anyrights)))
2485 goto Bad_FetchStatus;
2487 /* set volume synchronization information */
2488 SetVolumeSync(Sync, volptr);
2490 /* Are we allowed to fetch Fid's status? */
2491 if (targetptr->disk.type != vDirectory) {
2493 Check_PermissionRights(targetptr, client, rights,
2494 CHK_FETCHSTATUS, 0))) {
2495 if (rx_GetCallAbortCode(acall) == errorCode)
2496 rx_SetCallAbortCode(acall, 0);
2497 goto Bad_FetchStatus;
2501 /* set OutStatus From the Fid */
2502 GetStatus(targetptr, OutStatus, rights, anyrights,
2503 parentwhentargetnotdir);
2505 /* If a r/w volume, also set the CallBack state */
2506 if (VolumeWriteable(volptr))
2507 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2509 struct AFSFid myFid;
2510 memset(&myFid, 0, sizeof(struct AFSFid));
2511 myFid.Volume = Fid->Volume;
2512 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2516 /* Update and store volume/vnode and parent vnodes back */
2517 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2519 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2522 } /*SAFSS_FetchStatus */
2526 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2527 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2528 struct AFSVolSync * Sync)
2532 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2533 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2534 Error errorCode = 0; /* return code to caller */
2535 Volume *volptr = 0; /* pointer to the volume */
2536 struct client *client = 0; /* pointer to the client data */
2537 afs_int32 rights, anyrights; /* rights for this and any user */
2538 struct AFSFid *tfid; /* file id we're dealing with now */
2539 struct rx_connection *tcon = rx_ConnectionOf(acall);
2541 struct client *t_client = NULL; /* tmp pointer to the client data */
2542 struct fsstats fsstats;
2544 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2546 ViceLog(1, ("SAFS_BulkStatus\n"));
2548 AFSCallStats.TotalCalls++;
2550 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2551 if (nfiles <= 0) { /* Sanity check */
2553 goto Audit_and_Return;
2556 /* allocate space for return output parameters */
2557 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2558 malloc(nfiles * sizeof(struct AFSFetchStatus));
2559 if (!OutStats->AFSBulkStats_val) {
2560 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2562 OutStats->AFSBulkStats_len = nfiles;
2563 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2564 malloc(nfiles * sizeof(struct AFSCallBack));
2565 if (!CallBacks->AFSCBs_val) {
2566 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2568 CallBacks->AFSCBs_len = nfiles;
2570 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2571 goto Bad_BulkStatus;
2573 tfid = Fids->AFSCBFids_val;
2574 for (i = 0; i < nfiles; i++, tfid++) {
2576 * Get volume/vnode for the fetched file; caller's rights to it
2580 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2581 &parentwhentargetnotdir, &client, READ_LOCK,
2582 &rights, &anyrights)))
2583 goto Bad_BulkStatus;
2584 /* set volume synchronization information, but only once per call */
2586 SetVolumeSync(Sync, volptr);
2588 /* Are we allowed to fetch Fid's status? */
2589 if (targetptr->disk.type != vDirectory) {
2591 Check_PermissionRights(targetptr, client, rights,
2592 CHK_FETCHSTATUS, 0))) {
2593 if (rx_GetCallAbortCode(acall) == errorCode)
2594 rx_SetCallAbortCode(acall, 0);
2595 goto Bad_BulkStatus;
2599 /* set OutStatus From the Fid */
2600 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2601 anyrights, parentwhentargetnotdir);
2603 /* If a r/w volume, also set the CallBack state */
2604 if (VolumeWriteable(volptr))
2605 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2606 &CallBacks->AFSCBs_val[i]);
2608 struct AFSFid myFid;
2609 memset(&myFid, 0, sizeof(struct AFSFid));
2610 myFid.Volume = tfid->Volume;
2611 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2612 &CallBacks->AFSCBs_val[i]);
2615 /* put back the file ID and volume */
2616 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2618 parentwhentargetnotdir = (Vnode *) 0;
2619 targetptr = (Vnode *) 0;
2620 volptr = (Volume *) 0;
2621 client = (struct client *)0;
2625 /* Update and store volume/vnode and parent vnodes back */
2626 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2628 errorCode = CallPostamble(tcon, errorCode, thost);
2630 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2632 fsstats_FinishOp(&fsstats, errorCode);
2635 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2636 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2637 AUD_ID, t_client ? t_client->ViceId : 0,
2638 AUD_FIDS, Fids, AUD_END);
2641 } /*SRXAFS_BulkStatus */
2645 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2646 struct AFSBulkStats * OutStats,
2647 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2651 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2652 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2653 Error errorCode = 0; /* return code to caller */
2654 Volume *volptr = 0; /* pointer to the volume */
2655 struct client *client = 0; /* pointer to the client data */
2656 afs_int32 rights, anyrights; /* rights for this and any user */
2657 struct AFSFid *tfid; /* file id we're dealing with now */
2658 struct rx_connection *tcon;
2660 struct client *t_client = NULL; /* tmp ptr to client data */
2661 AFSFetchStatus *tstatus;
2662 int VolSync_set = 0;
2663 struct fsstats fsstats;
2665 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2667 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2669 AFSCallStats.TotalCalls++;
2671 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2672 if (nfiles <= 0) { /* Sanity check */
2674 goto Audit_and_Return;
2677 /* allocate space for return output parameters */
2678 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2679 malloc(nfiles * sizeof(struct AFSFetchStatus));
2680 if (!OutStats->AFSBulkStats_val) {
2681 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2683 OutStats->AFSBulkStats_len = nfiles;
2684 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2685 malloc(nfiles * sizeof(struct AFSCallBack));
2686 if (!CallBacks->AFSCBs_val) {
2687 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2689 CallBacks->AFSCBs_len = nfiles;
2691 /* Zero out return values to avoid leaking information on partial succes */
2692 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2693 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2694 memset(Sync, 0, sizeof(*Sync));
2696 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2697 goto Bad_InlineBulkStatus;
2700 tfid = Fids->AFSCBFids_val;
2701 for (i = 0; i < nfiles; i++, tfid++) {
2703 * Get volume/vnode for the fetched file; caller's rights to it
2707 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2708 &parentwhentargetnotdir, &client, READ_LOCK,
2709 &rights, &anyrights))) {
2710 tstatus = &OutStats->AFSBulkStats_val[i];
2711 tstatus->errorCode = errorCode;
2712 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2714 parentwhentargetnotdir = (Vnode *) 0;
2715 targetptr = (Vnode *) 0;
2716 volptr = (Volume *) 0;
2717 client = (struct client *)0;
2721 /* set volume synchronization information, but only once per call */
2723 SetVolumeSync(Sync, volptr);
2727 /* Are we allowed to fetch Fid's status? */
2728 if (targetptr->disk.type != vDirectory) {
2730 Check_PermissionRights(targetptr, client, rights,
2731 CHK_FETCHSTATUS, 0))) {
2732 tstatus = &OutStats->AFSBulkStats_val[i];
2733 tstatus->errorCode = errorCode;
2734 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2735 (Vnode *) 0, volptr, &client);
2736 parentwhentargetnotdir = (Vnode *) 0;
2737 targetptr = (Vnode *) 0;
2738 volptr = (Volume *) 0;
2739 client = (struct client *)0;
2744 /* set OutStatus From the Fid */
2745 GetStatus(targetptr,
2746 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2747 rights, anyrights, parentwhentargetnotdir);
2749 /* If a r/w volume, also set the CallBack state */
2750 if (VolumeWriteable(volptr))
2751 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2752 &CallBacks->AFSCBs_val[i]);
2754 struct AFSFid myFid;
2755 memset(&myFid, 0, sizeof(struct AFSFid));
2756 myFid.Volume = tfid->Volume;
2757 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2758 &CallBacks->AFSCBs_val[i]);
2761 /* put back the file ID and volume */
2762 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2764 parentwhentargetnotdir = (Vnode *) 0;
2765 targetptr = (Vnode *) 0;
2766 volptr = (Volume *) 0;
2767 client = (struct client *)0;
2770 Bad_InlineBulkStatus:
2771 /* Update and store volume/vnode and parent vnodes back */
2772 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2774 errorCode = CallPostamble(tcon, errorCode, thost);
2776 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2778 fsstats_FinishOp(&fsstats, errorCode);
2781 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2782 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2783 AUD_ID, t_client ? t_client->ViceId : 0,
2784 AUD_FIDS, Fids, AUD_END);
2787 } /*SRXAFS_InlineBulkStatus */
2791 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2792 struct AFSFetchStatus * OutStatus,
2793 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2796 struct rx_connection *tcon;
2798 struct client *t_client = NULL; /* tmp ptr to client data */
2799 struct fsstats fsstats;
2801 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2803 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2804 goto Bad_FetchStatus;
2806 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2809 code = CallPostamble(tcon, code, thost);
2811 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2813 fsstats_FinishOp(&fsstats, code);
2815 osi_auditU(acall, FetchStatusEvent, code,
2816 AUD_ID, t_client ? t_client->ViceId : 0,
2817 AUD_FID, Fid, AUD_END);
2820 } /*SRXAFS_FetchStatus */
2824 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2825 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2826 afs_fsize_t Length, afs_fsize_t FileLength,
2827 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2829 Vnode *targetptr = 0; /* pointer to input fid */
2830 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2831 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2832 Error errorCode = 0; /* return code for caller */
2833 Error fileCode = 0; /* return code from vol package */
2834 Volume *volptr = 0; /* pointer to the volume header */
2835 struct client *client = 0; /* pointer to client structure */
2836 afs_int32 rights, anyrights; /* rights for this and any user */
2837 struct client *t_client = NULL; /* tmp ptr to client data */
2838 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2839 struct rx_connection *tcon;
2841 struct fsstats fsstats;
2842 afs_sfsize_t bytesToXfer;
2843 afs_sfsize_t bytesXferred;
2844 static int remainder = 0;
2847 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2850 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2853 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2855 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2858 /* Get ptr to client data for user Id for logging */
2859 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2860 logHostAddr.s_addr = rxr_HostOf(tcon);
2862 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2863 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2864 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2867 * Get associated volume/vnode for the stored file; caller's rights
2871 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2872 &parentwhentargetnotdir, &client, WRITE_LOCK,
2873 &rights, &anyrights))) {
2877 /* set volume synchronization information */
2878 SetVolumeSync(Sync, volptr);
2880 if ((targetptr->disk.type == vSymlink)) {
2881 /* Should we return a better error code here??? */
2886 /* Check if we're allowed to store the data */
2888 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2894 * Drop the read lock on the parent directory after saving the parent
2895 * vnode information we need to pass to GetStatus
2897 if (parentwhentargetnotdir != NULL) {
2898 tparentwhentargetnotdir = *parentwhentargetnotdir;
2899 VPutVnode(&fileCode, parentwhentargetnotdir);
2900 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2901 parentwhentargetnotdir = NULL;
2904 fsstats_StartXfer(&fsstats);
2907 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2908 FileLength, (InStatus->Mask & AFS_FSYNC),
2909 &bytesToXfer, &bytesXferred);
2911 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2914 if (errorCode && (!targetptr->changed_newTime))
2917 /* Update the status of the target's vnode */
2918 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2919 targetptr, volptr, 0);
2921 /* Get the updated File's status back to the caller */
2922 GetStatus(targetptr, OutStatus, rights, anyrights,
2923 &tparentwhentargetnotdir);
2926 /* Update and store volume/vnode and parent vnodes back */
2927 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2929 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2931 errorCode = CallPostamble(tcon, errorCode, thost);
2933 fsstats_FinishOp(&fsstats, errorCode);
2935 osi_auditU(acall, StoreDataEvent, errorCode,
2936 AUD_ID, t_client ? t_client->ViceId : 0,
2937 AUD_FID, Fid, AUD_END);
2939 } /*common_StoreData64 */
2942 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
2943 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
2944 afs_uint32 Length, afs_uint32 FileLength,
2945 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2947 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
2948 (0x7fffffff - Pos) < Length)
2951 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
2953 } /*SRXAFS_StoreData */
2956 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
2957 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
2958 afs_uint64 Length, afs_uint64 FileLength,
2959 struct AFSFetchStatus * OutStatus,
2960 struct AFSVolSync * Sync)
2964 afs_fsize_t tLength;
2965 afs_fsize_t tFileLength;
2967 tPos = (afs_fsize_t) Pos;
2968 tLength = (afs_fsize_t) Length;
2969 tFileLength = (afs_fsize_t) FileLength;
2972 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
2978 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
2979 struct AFSOpaque * AccessList,
2980 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2982 Vnode *targetptr = 0; /* pointer to input fid */
2983 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2984 Error errorCode = 0; /* return code for caller */
2985 struct AFSStoreStatus InStatus; /* Input status for fid */
2986 Volume *volptr = 0; /* pointer to the volume header */
2987 struct client *client = 0; /* pointer to client structure */
2988 afs_int32 rights, anyrights; /* rights for this and any user */
2989 struct rx_connection *tcon;
2991 struct client *t_client = NULL; /* tmp ptr to client data */
2992 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2993 struct fsstats fsstats;
2995 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
2997 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3000 /* Get ptr to client data for user Id for logging */
3001 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3002 logHostAddr.s_addr = rxr_HostOf(tcon);
3004 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3005 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3006 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3008 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3010 InStatus.Mask = 0; /* not storing any status */
3013 * Get associated volume/vnode for the target dir; caller's rights
3014 * are also returned.
3017 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3018 &parentwhentargetnotdir, &client, WRITE_LOCK,
3019 &rights, &anyrights))) {
3023 /* set volume synchronization information */
3024 SetVolumeSync(Sync, volptr);
3026 /* Check if we have permission to change the dir's ACL */
3028 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3033 /* Build and store the new Access List for the dir */
3034 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3038 targetptr->changed_newTime = 1; /* status change of directory */
3040 /* convert the write lock to a read lock before breaking callbacks */
3041 VVnodeWriteToRead(&errorCode, targetptr);
3042 osi_Assert(!errorCode || errorCode == VSALVAGE);
3044 /* break call backs on the directory */
3045 BreakCallBack(client->host, Fid, 0);
3047 /* Get the updated dir's status back to the caller */
3048 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3051 /* Update and store volume/vnode and parent vnodes back */
3052 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3054 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3055 errorCode = CallPostamble(tcon, errorCode, thost);
3057 fsstats_FinishOp(&fsstats, errorCode);
3059 osi_auditU(acall, StoreACLEvent, errorCode,
3060 AUD_ID, t_client ? t_client->ViceId : 0,
3061 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3064 } /*SRXAFS_StoreACL */
3068 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3069 * should be merged when possible.
3072 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3073 struct AFSStoreStatus *InStatus,
3074 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3076 Vnode *targetptr = 0; /* pointer to input fid */
3077 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3078 Error errorCode = 0; /* return code for caller */
3079 Volume *volptr = 0; /* pointer to the volume header */
3080 struct client *client = 0; /* pointer to client structure */
3081 afs_int32 rights, anyrights; /* rights for this and any user */
3082 struct client *t_client = NULL; /* tmp ptr to client data */
3083 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3084 struct rx_connection *tcon = rx_ConnectionOf(acall);
3086 /* Get ptr to client data for user Id for logging */
3087 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3088 logHostAddr.s_addr = rxr_HostOf(tcon);
3090 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3091 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3092 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3094 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3097 * Get volume/vnode for the target file; caller's rights to it are
3101 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3102 &parentwhentargetnotdir, &client, WRITE_LOCK,
3103 &rights, &anyrights))) {
3104 goto Bad_StoreStatus;
3107 /* set volume synchronization information */
3108 SetVolumeSync(Sync, volptr);
3110 /* Check if the caller has proper permissions to store status to Fid */
3112 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3114 goto Bad_StoreStatus;
3117 * Check for a symbolic link; we can't chmod these (otherwise could
3118 * change a symlink to a mt pt or vice versa)
3120 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3122 goto Bad_StoreStatus;
3125 /* Update the status of the target's vnode */
3126 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3127 (parentwhentargetnotdir ? parentwhentargetnotdir
3128 : targetptr), volptr, 0);
3130 /* convert the write lock to a read lock before breaking callbacks */
3131 VVnodeWriteToRead(&errorCode, targetptr);
3132 osi_Assert(!errorCode || errorCode == VSALVAGE);
3134 /* Break call backs on Fid */
3135 BreakCallBack(client->host, Fid, 0);
3137 /* Return the updated status back to caller */
3138 GetStatus(targetptr, OutStatus, rights, anyrights,
3139 parentwhentargetnotdir);
3142 /* Update and store volume/vnode and parent vnodes back */
3143 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3145 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3148 } /*SAFSS_StoreStatus */
3152 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3153 struct AFSStoreStatus * InStatus,
3154 struct AFSFetchStatus * OutStatus,
3155 struct AFSVolSync * Sync)
3158 struct rx_connection *tcon;
3160 struct client *t_client = NULL; /* tmp ptr to client data */
3161 struct fsstats fsstats;
3163 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3165 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3166 goto Bad_StoreStatus;
3168 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3171 code = CallPostamble(tcon, code, thost);
3173 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3175 fsstats_FinishOp(&fsstats, code);
3177 osi_auditU(acall, StoreStatusEvent, code,
3178 AUD_ID, t_client ? t_client->ViceId : 0,
3179 AUD_FID, Fid, AUD_END);
3182 } /*SRXAFS_StoreStatus */
3186 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3187 * merged in when possible.
3190 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3191 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3193 Vnode *parentptr = 0; /* vnode of input Directory */
3194 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3195 Vnode *targetptr = 0; /* file to be deleted */
3196 Volume *volptr = 0; /* pointer to the volume header */
3197 AFSFid fileFid; /* area for Fid from the directory */
3198 Error errorCode = 0; /* error code */
3199 DirHandle dir; /* Handle for dir package I/O */
3200 struct client *client = 0; /* pointer to client structure */
3201 afs_int32 rights, anyrights; /* rights for this and any user */
3202 struct client *t_client; /* tmp ptr to client data */
3203 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3204 struct rx_connection *tcon = rx_ConnectionOf(acall);
3207 /* Get ptr to client data for user Id for logging */
3208 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3209 logHostAddr.s_addr = rxr_HostOf(tcon);
3211 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3212 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3213 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3215 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3218 * Get volume/vnode for the parent dir; caller's access rights are
3222 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3223 &parentwhentargetnotdir, &client, WRITE_LOCK,
3224 &rights, &anyrights))) {
3225 goto Bad_RemoveFile;
3227 /* set volume synchronization information */
3228 SetVolumeSync(Sync, volptr);
3230 /* Does the caller has delete (& write) access to the parent directory? */
3231 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3232 goto Bad_RemoveFile;
3235 /* Actually delete the desired file */
3237 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3239 goto Bad_RemoveFile;
3242 /* Update the vnode status of the parent dir */
3243 #if FS_STATS_DETAILED
3244 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3245 parentptr->disk.linkCount,
3246 client->InSameNetwork);
3248 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3249 parentptr->disk.linkCount);
3250 #endif /* FS_STATS_DETAILED */
3252 /* Return the updated parent dir's status back to caller */
3253 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3255 /* Handle internal callback state for the parent and the deleted file */
3256 if (targetptr->disk.linkCount == 0) {
3257 /* no references left, discard entry */
3258 DeleteFileCallBacks(&fileFid);
3259 /* convert the parent lock to a read lock before breaking callbacks */
3260 VVnodeWriteToRead(&errorCode, parentptr);
3261 osi_Assert(!errorCode || errorCode == VSALVAGE);
3263 /* convert the parent lock to a read lock before breaking callbacks */
3264 VVnodeWriteToRead(&errorCode, parentptr);
3265 osi_Assert(!errorCode || errorCode == VSALVAGE);
3266 /* convert the target lock to a read lock before breaking callbacks */
3267 VVnodeWriteToRead(&errorCode, targetptr);
3268 osi_Assert(!errorCode || errorCode == VSALVAGE);
3269 /* tell all the file has changed */
3270 BreakCallBack(client->host, &fileFid, 1);
3273 /* break call back on the directory */
3274 BreakCallBack(client->host, DirFid, 0);
3277 /* Update and store volume/vnode and parent vnodes back */
3278 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3281 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3284 } /*SAFSS_RemoveFile */
3288 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3289 struct AFSFetchStatus * OutDirStatus,
3290 struct AFSVolSync * Sync)
3293 struct rx_connection *tcon;
3295 struct client *t_client = NULL; /* tmp ptr to client data */
3296 struct fsstats fsstats;
3298 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3300 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3301 goto Bad_RemoveFile;
3303 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3306 code = CallPostamble(tcon, code, thost);
3308 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3310 fsstats_FinishOp(&fsstats, code);
3312 osi_auditU(acall, RemoveFileEvent, code,
3313 AUD_ID, t_client ? t_client->ViceId : 0,
3314 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3317 } /*SRXAFS_RemoveFile */
3321 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3322 * be merged in when possible.
3325 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3326 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3327 struct AFSFetchStatus *OutFidStatus,
3328 struct AFSFetchStatus *OutDirStatus,
3329 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3331 Vnode *parentptr = 0; /* vnode of input Directory */
3332 Vnode *targetptr = 0; /* vnode of the new file */
3333 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3334 Volume *volptr = 0; /* pointer to the volume header */
3335 Error errorCode = 0; /* error code */
3336 DirHandle dir; /* Handle for dir package I/O */
3337 struct client *client = 0; /* pointer to client structure */
3338 afs_int32 rights, anyrights; /* rights for this and any user */
3339 struct client *t_client; /* tmp ptr to client data */
3340 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3341 struct rx_connection *tcon = rx_ConnectionOf(acall);
3345 /* Get ptr to client data for user Id for logging */
3346 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3347 logHostAddr.s_addr = rxr_HostOf(tcon);
3349 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3350 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3351 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3353 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3355 if (!FileNameOK(Name)) {
3357 goto Bad_CreateFile;
3361 * Get associated volume/vnode for the parent dir; caller long are
3365 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3366 &parentwhentargetnotdir, &client, WRITE_LOCK,
3367 &rights, &anyrights))) {
3368 goto Bad_CreateFile;
3371 /* set volume synchronization information */
3372 SetVolumeSync(Sync, volptr);
3374 /* Can we write (and insert) onto the parent directory? */
3375 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3376 goto Bad_CreateFile;
3378 /* get a new vnode for the file to be created and set it up */
3380 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3381 vFile, nBlocks(0)))) {
3382 goto Bad_CreateFile;
3385 /* update the status of the parent vnode */
3386 #if FS_STATS_DETAILED
3387 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3388 parentptr->disk.linkCount,
3389 client->InSameNetwork);
3391 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3392 parentptr->disk.linkCount);
3393 #endif /* FS_STATS_DETAILED */
3395 /* update the status of the new file's vnode */
3396 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3397 parentptr, volptr, 0);
3399 /* set up the return status for the parent dir and the newly created file, and since the newly created file is owned by the creator, give it PRSFS_ADMINISTER to tell the client its the owner of the file */
3400 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3401 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3403 /* convert the write lock to a read lock before breaking callbacks */
3404 VVnodeWriteToRead(&errorCode, parentptr);
3405 osi_Assert(!errorCode || errorCode == VSALVAGE);
3407 /* break call back on parent dir */
3408 BreakCallBack(client->host, DirFid, 0);
3410 /* Return a callback promise for the newly created file to the caller */
3411 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3414 /* Update and store volume/vnode and parent vnodes back */
3415 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3418 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3421 } /*SAFSS_CreateFile */
3425 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3426 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3427 struct AFSFetchStatus * OutFidStatus,
3428 struct AFSFetchStatus * OutDirStatus,
3429 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3432 struct rx_connection *tcon;
3434 struct client *t_client = NULL; /* tmp ptr to client data */
3435 struct fsstats fsstats;
3437 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3439 memset(OutFid, 0, sizeof(struct AFSFid));
3441 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3442 goto Bad_CreateFile;
3445 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3446 OutDirStatus, CallBack, Sync);
3449 code = CallPostamble(tcon, code, thost);
3451 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);