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 */
74 #include <afs/afsint.h>
75 #include <afs/vldbint.h>
76 #include <afs/errors.h>
77 #include <afs/ihandle.h>
78 #include <afs/vnode.h>
79 #include <afs/volume.h>
80 #include <afs/ptclient.h>
81 #include <afs/ptuser.h>
82 #include <afs/prs_fs.h>
85 #include <rx/rx_globals.h>
87 #include <afs/cellconfig.h>
90 #include <afs/partition.h>
91 #include "viced_prototypes.h"
95 #include <afs/unified_afs.h>
96 #include <afs/audit.h>
97 #include <afs/afsutil.h>
100 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
101 extern void FidZap(DirHandle * file);
102 extern void FidZero(DirHandle * file);
104 #ifdef AFS_PTHREAD_ENV
105 pthread_mutex_t fileproc_glock_mutex;
106 #endif /* AFS_PTHREAD_ENV */
108 /* Useful local defines used by this module */
111 #define MustNOTBeDIR 1
115 #define TVS_SSTATUS 2
118 #define TVS_MKDIR 0x10
120 #define CHK_FETCH 0x10
121 #define CHK_FETCHDATA 0x10
122 #define CHK_FETCHACL 0x11
123 #define CHK_FETCHSTATUS 0x12
124 #define CHK_STOREDATA 0x00
125 #define CHK_STOREACL 0x01
126 #define CHK_STORESTATUS 0x02
128 #define OWNERREAD 0400
129 #define OWNERWRITE 0200
130 #define OWNEREXEC 0100
131 #ifdef USE_GROUP_PERMS
132 #define GROUPREAD 0040
133 #define GROUPWRITE 0020
134 #define GROUPREXEC 0010
137 /* The following errors were not defined in NT. They are given unique
138 * names here to avoid any potential collision.
140 #define FSERR_ELOOP 90
141 #define FSERR_EOPNOTSUPP 122
142 #define FSERR_ECONNREFUSED 130
144 #define NOTACTIVECALL 0
147 #define CREATE_SGUID_ADMIN_ONLY 1
149 extern struct afsconf_dir *confDir;
150 extern afs_int32 dataVersionHigh;
153 static struct AFSCallStatistics AFSCallStats;
154 #if FS_STATS_DETAILED
155 struct fs_stats_FullPerfStats afs_FullPerfStats;
156 extern int AnonymousID;
157 #endif /* FS_STATS_DETAILED */
158 #if OPENAFS_VOL_STATS
159 static const char nullString[] = "";
160 #endif /* OPENAFS_VOL_STATS */
163 afs_int32 NothingYet;
166 struct afs_FSStats afs_fsstats;
171 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
173 extern afs_int32 implicitAdminRights;
174 extern afs_int32 readonlyServer;
175 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
176 extern afs_fsize_t CopyOnWrite_maxsize;
179 * Externals used by the xstat code.
181 extern VolPkgStats VStats;
182 extern int CEs, CEBlocks;
184 extern int HTs, HTBlocks;
186 static afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
187 struct rx_call *Call, afs_sfsize_t Pos,
188 afs_sfsize_t Len, afs_int32 Int64Mode,
189 afs_sfsize_t * a_bytesToFetchP,
190 afs_sfsize_t * a_bytesFetchedP);
192 static afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
193 struct AFSFid *Fid, struct client *client,
194 struct rx_call *Call, afs_fsize_t Pos,
195 afs_fsize_t Length, afs_fsize_t FileLength,
197 afs_sfsize_t * a_bytesToStoreP,
198 afs_sfsize_t * a_bytesStoredP);
200 #ifdef AFS_SGI_XFS_IOPS_ENV
201 #include <afs/xfsattrs.h>
203 GetLinkCount(Volume * avp, struct stat *astat)
205 if (!strcmp("xfs", astat->st_fstype)) {
206 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
208 return astat->st_nlink;
211 #define GetLinkCount(V, S) (S)->st_nlink
215 SpareComp(Volume * avolp)
221 temp = V_maxquota(avolp);
223 /* no matter; doesn't check in this case */
227 temp = (temp * PctSpare) / 100;
238 * Set the volume synchronization parameter for this volume. If it changes,
239 * the Cache Manager knows that the volume must be purged from the stat cache.
242 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
245 /* date volume instance was created */
248 async->spare1 = avol->header->diskstuff.creationDate;
261 * Verify that the on-disk size for a vnode matches the length in the vnode
264 * @param[in] vp Volume pointer
265 * @param[in] vnp Vnode pointer
266 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
267 * and CheckLength itself will determine the on-disk size.
269 * @return operation status
270 * @retval 0 lengths match
271 * @retval nonzero Error; either the lengths do not match or there was an
272 * error determining the on-disk size. The volume should be
273 * taken offline and salvaged.
276 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
279 VN_GET_LEN(vlen, vnp);
284 fdP = IH_OPEN(vnp->handle);
286 ViceLog(0, ("CheckLength: cannot open inode for fid %lu.%lu.%lu\n",
287 afs_printable_uint32_lu(vp->hashid),
288 afs_printable_uint32_lu(Vn_id(vnp)),
289 afs_printable_uint32_lu(vnp->disk.uniquifier)));
292 alen = FDH_SIZE(fdP);
295 afs_int64 alen64 = alen;
296 ViceLog(0, ("CheckLength: cannot get size for inode for fid "
297 "%lu.%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
298 afs_printable_uint32_lu(vp->hashid),
299 afs_printable_uint32_lu(Vn_id(vnp)),
300 afs_printable_uint32_lu(vnp->disk.uniquifier),
307 afs_int64 alen64 = alen, vlen64 = vlen;
308 ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index "
309 "%lld inode %lld ); volume must be salvaged\n",
310 afs_printable_uint32_lu(vp->hashid),
311 afs_printable_uint32_lu(Vn_id(vnp)),
312 afs_printable_uint32_lu(vnp->disk.uniquifier),
320 * Note that this function always returns a held host, so
321 * that CallPostamble can block without the host's disappearing.
322 * Call returns rx connection in passed in *tconn
325 CallPreamble(struct rx_call *acall, int activecall,
326 struct rx_connection **tconn, struct host **ahostp)
329 struct client *tclient;
332 char hoststr[16], hoststr2[16];
333 #ifdef AFS_PTHREAD_ENV
334 struct ubik_client *uclient;
339 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
342 *tconn = rx_ConnectionOf(acall);
346 tclient = h_FindClient_r(*tconn);
348 ViceLog(0, ("CallPreamble: Couldn't get client.\n"));
352 thost = tclient->host;
353 if (tclient->prfail == 1) { /* couldn't get the CPS */
355 h_ReleaseClient_r(tclient);
357 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
361 retry_flag = 0; /* Retry once */
363 /* Take down the old connection and re-read the key file */
365 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
366 #ifdef AFS_PTHREAD_ENV
367 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
369 /* Is it still necessary to drop this? We hit the net, we should... */
375 code = hpr_Initialize(&uclient);
378 osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
381 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
384 h_ReleaseClient_r(tclient);
387 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
391 tclient->prfail = 2; /* Means re-eval client's cps */
392 h_ReleaseClient_r(tclient);
397 tclient->LastCall = thost->LastCall = FT_ApproxTime();
398 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
399 thost->ActiveCall = thost->LastCall;
402 if (thost->hostFlags & HOSTDELETED) {
404 ("Discarded a packet for deleted host %s:%d\n",
405 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
406 code = VBUSY; /* raced, so retry */
407 } else if ((thost->hostFlags & VENUSDOWN)
408 || (thost->hostFlags & HFE_LATER)) {
409 if (BreakDelayedCallBacks_r(thost)) {
411 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
412 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
413 ntohs(rxr_PortOf(*tconn))));
414 if (MultiProbeAlternateAddress_r(thost)) {
416 ("MultiProbe failed to find new address for host %s:%d\n",
417 afs_inet_ntoa_r(thost->host, hoststr),
418 ntohs(thost->port)));
422 ("MultiProbe found new address for host %s:%d\n",
423 afs_inet_ntoa_r(thost->host, hoststr),
424 ntohs(thost->port)));
425 if (BreakDelayedCallBacks_r(thost)) {
427 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
428 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
429 ntohs(rxr_PortOf(*tconn))));
438 h_ReleaseClient_r(tclient);
448 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
452 struct client *tclient;
456 tclient = h_FindClient_r(aconn);
459 thost = tclient->host;
460 if (thost->hostFlags & HERRORTRANS)
462 h_ReleaseClient_r(tclient);
465 if (ahost != thost) {
466 /* host/client recycle */
467 char hoststr[16], hoststr2[16];
468 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
470 afs_inet_ntoa_r(ahost->host, hoststr),
473 afs_inet_ntoa_r(thost->host, hoststr2),
477 /* return the reference taken in CallPreamble */
481 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
482 afs_inet_ntoa_r(thost->host, hoststr),
487 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
488 * does not decrement refcount on client->host */
493 return (translate ? sys_error_to_et(ret) : ret);
497 * Returns the volume and vnode pointers associated with file Fid; the lock
498 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
499 * are incremented and they must be eventualy released.
502 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
503 Vnode ** vptr, int lock)
506 Error local_errorCode, errorCode = -1;
507 static struct timeval restartedat = { 0, 0 };
509 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
511 if ((*volptr) == 0) {
516 #ifdef AFS_DEMAND_ATTACH_FS
522 #ifdef AFS_PTHREAD_ENV
523 static const struct timespec timeout_ts = { 0, 0 };
524 static const struct timespec * const ts = &timeout_ts;
526 static const struct timespec * const ts = NULL;
530 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
531 fid->Volume, ts, cbv);
536 if ((errorCode == VOFFLINE) && (VInit < 2)) {
537 /* The volume we want may not be attached yet because
538 * the volume initialization is not yet complete.
539 * We can do several things:
540 * 1. return -1, which will cause users to see
541 * "connection timed out". This is more or
542 * less the same as always, except that the servers
543 * may appear to bounce up and down while they
544 * are actually restarting.
545 * 2. return VBUSY which will cause clients to
546 * sleep and retry for 6.5 - 15 minutes, depending
547 * on what version of the CM they are running. If
548 * the file server takes longer than that interval
549 * to attach the desired volume, then the application
550 * will see an ENODEV or EIO. This approach has
551 * the advantage that volumes which have been attached
552 * are immediately available, it keeps the server's
553 * immediate backlog low, and the call is interruptible
554 * by the user. Users see "waiting for busy volume."
555 * 3. sleep here and retry. Some people like this approach
556 * because there is no danger of seeing errors. However,
557 * this approach only works with a bounded number of
558 * clients, since the pending queues will grow without
559 * stopping. It might be better to find a way to take
560 * this call and stick it back on a queue in order to
561 * recycle this thread for a different request.
562 * 4. Return a new error code, which new cache managers will
563 * know enough to interpret as "sleep and retry", without
564 * the upper bound of 6-15 minutes that is imposed by the
565 * VBUSY handling. Users will see "waiting for
566 * busy volume," so they know that something is
567 * happening. Old cache managers must be able to do
568 * something reasonable with this, for instance, mark the
569 * server down. Fortunately, any error code < 0
570 * will elicit that behavior. See #1.
571 * 5. Some combination of the above. I like doing #2 for 10
572 * minutes, followed by #4. 3.1b and 3.2 cache managers
573 * will be fine as long as the restart period is
574 * not longer than 6.5 minutes, otherwise they may
575 * return ENODEV to users. 3.3 cache managers will be
576 * fine for 10 minutes, then will return
577 * ETIMEDOUT. 3.4 cache managers will just wait
578 * until the call works or fails definitively.
579 * NB. The problem with 2,3,4,5 is that old clients won't
580 * fail over to an alternate read-only replica while this
581 * server is restarting. 3.4 clients will fail over right away.
583 if (restartedat.tv_sec == 0) {
584 /* I'm not really worried about when we restarted, I'm */
585 /* just worried about when the first VBUSY was returned. */
586 FT_GetTimeOfDay(&restartedat, 0);
589 afs_perfstats.fs_nBusies++;
592 return (busyonrst ? VBUSY : restarting);
595 FT_GetTimeOfDay(&now, 0);
596 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
599 afs_perfstats.fs_nBusies++;
602 return (busyonrst ? VBUSY : restarting);
608 /* allow read operations on busy volume.
609 * must check local_errorCode because demand attach fs
610 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
611 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
612 #ifdef AFS_DEMAND_ATTACH_FS
613 /* DAFS case is complicated by the fact that local_errorCode can
614 * be VBUSY in cases where the volume is truly offline */
616 /* volume is in VOL_STATE_UNATTACHED */
619 #endif /* AFS_DEMAND_ATTACH_FS */
622 } else if (errorCode)
629 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
632 if ((*vptr)->disk.uniquifier != fid->Unique) {
633 VPutVnode(&fileCode, *vptr);
634 osi_Assert(fileCode == 0);
636 return (VNOVNODE); /* return the right error code, at least */
641 static_inline afs_int32
642 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
644 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
648 * This routine returns the ACL associated with the targetptr. If the
649 * targetptr isn't a directory, we access its parent dir and get the ACL
650 * thru the parent; in such case the parent's vnode is returned in
654 SetAccessList(Vnode ** targetptr, Volume ** volume,
655 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
656 AFSFid * Fid, int Lock)
658 if ((*targetptr)->disk.type == vDirectory) {
660 *ACL = VVnodeACL(*targetptr);
661 *ACLSize = VAclSize(*targetptr);
664 osi_Assert(Fid != 0);
669 parentvnode = (*targetptr)->disk.parent;
670 VPutVnode(&errorCode, *targetptr);
674 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
677 *ACL = VVnodeACL(*parent);
678 *ACLSize = VAclSize(*parent);
679 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
681 if ((*targetptr)->disk.parent != parentvnode) {
682 VPutVnode(&errorCode, *parent);
693 /* Must not be called with H_LOCK held */
695 client_CheckRights(struct client *client, struct acl_accessList *ACL,
699 ObtainReadLock(&client->lock);
700 if (client->CPS.prlist_len > 0 && !client->deleted &&
701 client->host && !(client->host->hostFlags & HOSTDELETED))
702 acl_CheckRights(ACL, &client->CPS, rights);
703 ReleaseReadLock(&client->lock);
706 /* Must not be called with H_LOCK held */
708 client_HasAsMember(struct client *client, afs_int32 id)
712 ObtainReadLock(&client->lock);
713 if (client->CPS.prlist_len > 0 && !client->deleted &&
714 client->host && !(client->host->hostFlags & HOSTDELETED))
715 code = acl_IsAMember(id, &client->CPS);
716 ReleaseReadLock(&client->lock);
721 * Compare the directory's ACL with the user's access rights in the client
722 * connection and return the user's and everybody else's access permissions
723 * in rights and anyrights, respectively
726 GetRights(struct client *client, struct acl_accessList *ACL,
727 afs_int32 * rights, afs_int32 * anyrights)
729 extern prlist SystemAnyUserCPS;
730 afs_int32 hrights = 0;
731 #ifndef AFS_PTHREAD_ENV
735 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
736 ViceLog(0, ("CheckRights failed\n"));
741 client_CheckRights(client, ACL, rights);
743 /* wait if somebody else is already doing the getCPS call */
745 while (client->host->hostFlags & HCPS_INPROGRESS) {
746 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
747 #ifdef AFS_PTHREAD_ENV
748 CV_WAIT(&client->host->cond, &host_glock_mutex);
749 #else /* AFS_PTHREAD_ENV */
751 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
752 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
753 #endif /* AFS_PTHREAD_ENV */
756 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
759 ("CheckRights: len=%u, for host=%s:%d\n",
760 client->host->hcps.prlist_len,
761 afs_inet_ntoa_r(client->host->host, hoststr),
762 ntohs(client->host->port)));
764 acl_CheckRights(ACL, &client->host->hcps, &hrights);
766 /* Allow system:admin the rights given with the -implicit option */
767 if (client_HasAsMember(client, SystemId))
768 *rights |= implicitAdminRights;
771 *anyrights |= hrights;
778 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
779 * a System:Administrator)
782 VanillaUser(struct client *client)
784 if (client_HasAsMember(client, SystemId))
785 return (0); /* not a system administrator, then you're "vanilla" */
792 * This unusual afs_int32-parameter routine encapsulates all volume package related
793 * operations together in a single function; it's called by almost all AFS
797 GetVolumePackageWithCall(struct rx_connection *tcon, struct VCallByVol *cbv,
798 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
799 int chkforDir, Vnode ** parent, struct client **client,
800 int locktype, afs_int32 * rights, afs_int32 * anyrights)
802 struct acl_accessList *aCL; /* Internal access List */
803 int aCLSize; /* size of the access list */
804 Error errorCode = 0; /* return code to caller */
806 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
809 if (chkforDir == MustNOTBeDIR
810 && ((*targetptr)->disk.type == vDirectory))
812 else if (chkforDir == MustBeDIR
813 && ((*targetptr)->disk.type != vDirectory))
817 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
818 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
819 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
821 if (chkforDir == MustBeDIR)
822 osi_Assert((*parent) == 0);
824 if ((errorCode = GetClient(tcon, client)) != 0)
829 GetRights(*client, aCL, rights, anyrights);
830 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
831 if ((*targetptr)->disk.type != vDirectory) {
832 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
833 if ((*targetptr)->disk.owner == (*client)->ViceId)
834 (*rights) |= PRSFS_ADMINISTER;
836 (*rights) &= ~PRSFS_ADMINISTER;
838 #ifdef ADMIN_IMPLICIT_LOOKUP
839 /* admins get automatic lookup on everything */
840 if (!VanillaUser(*client))
841 (*rights) |= PRSFS_LOOKUP;
842 #endif /* ADMIN_IMPLICIT_LOOKUP */
845 } /*GetVolumePackage */
847 static_inline afs_int32
848 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
849 Vnode ** targetptr, int chkforDir, Vnode ** parent,
850 struct client **client, int locktype, afs_int32 * rights,
851 afs_int32 * anyrights)
853 return GetVolumePackageWithCall(tcon, NULL, Fid, volptr, targetptr,
854 chkforDir, parent, client, locktype,
860 * This is the opposite of GetVolumePackage(), and is always used at the end of
861 * AFS calls to put back all used vnodes and the volume in the proper order!
864 PutVolumePackageWithCall(Vnode * parentwhentargetnotdir, Vnode * targetptr,
865 Vnode * parentptr, Volume * volptr,
866 struct client **client, struct VCallByVol *cbv)
868 Error fileCode = 0; /* Error code returned by the volume package */
870 if (parentwhentargetnotdir) {
871 VPutVnode(&fileCode, parentwhentargetnotdir);
872 osi_Assert(!fileCode || (fileCode == VSALVAGE));
875 VPutVnode(&fileCode, targetptr);
876 osi_Assert(!fileCode || (fileCode == VSALVAGE));
879 VPutVnode(&fileCode, parentptr);
880 osi_Assert(!fileCode || (fileCode == VSALVAGE));
883 VPutVolumeWithCall(volptr, cbv);
888 } /*PutVolumePackage */
891 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
892 Vnode * parentptr, Volume * volptr, struct client **client)
894 PutVolumePackageWithCall(parentwhentargetnotdir, targetptr, parentptr,
895 volptr, client, NULL);
899 VolumeOwner(struct client *client, Vnode * targetptr)
901 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
904 return (client->ViceId == owner);
907 * We don't have to check for host's cps since only regular
908 * viceid are volume owners.
910 return (client_HasAsMember(client, owner));
916 VolumeRootVnode(Vnode * targetptr)
918 return ((targetptr->vnodeNumber == ROOTVNODE)
919 && (targetptr->disk.uniquifier == 1));
921 } /*VolumeRootVnode */
924 * Check if target file has the proper access permissions for the Fetch
925 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
926 * StoreStatus) related calls
928 /* this code should probably just set a "priv" flag where all the audit events
929 * are now, and only generate the audit event once at the end of the routine,
930 * thus only generating the event if all the checks succeed, but only because
931 * of the privilege XXX
934 Check_PermissionRights(Vnode * targetptr, struct client *client,
935 afs_int32 rights, int CallingRoutine,
936 AFSStoreStatus * InStatus)
939 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
940 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
941 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
943 if (CallingRoutine & CHK_FETCH) {
944 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
945 if (targetptr->disk.type == vDirectory
946 || targetptr->disk.type == vSymlink) {
947 if (!(rights & PRSFS_LOOKUP)
948 #ifdef ADMIN_IMPLICIT_LOOKUP
949 /* grant admins fetch on all directories */
950 && VanillaUser(client)
951 #endif /* ADMIN_IMPLICIT_LOOKUP */
952 && !VolumeOwner(client, targetptr))
955 /* must have read access, or be owner and have insert access */
956 if (!(rights & PRSFS_READ)
957 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
958 && (client->ViceId != AnonymousID))))
961 if (CallingRoutine == CHK_FETCHDATA
962 && targetptr->disk.type == vFile)
963 #ifdef USE_GROUP_PERMS
964 if (!OWNSp(client, targetptr)
965 && !client_HasAsMember(client, targetptr->disk.owner)) {
967 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
971 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
976 * The check with the ownership below is a kludge to allow
977 * reading of files created with no read permission. The owner
978 * of the file is always allowed to read it.
980 if ((client->ViceId != targetptr->disk.owner)
981 && VanillaUser(client))
983 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
984 modeBits) ? 0 : EACCES);
986 } else { /* !VanillaUser(client) && !FetchData */
988 osi_audit(PrivilegeEvent, 0, AUD_ID,
989 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
992 } else { /* a store operation */
993 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
994 && (CallingRoutine != CHK_STOREACL)
995 && (targetptr->disk.type == vFile)) {
996 /* bypass protection checks on first store after a create
997 * for the creator; also prevent chowns during this time
998 * unless you are a system administrator */
999 /****** InStatus->Owner && UnixModeBits better be SET!! */
1000 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1003 else if (VanillaUser(client))
1004 return (EPERM); /* Was EACCES */
1006 osi_audit(PrivilegeEvent, 0, AUD_ID,
1007 (client ? client->ViceId : 0), AUD_INT,
1008 CallingRoutine, AUD_END);
1011 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1012 osi_audit(PrivilegeEvent, 0, AUD_ID,
1013 (client ? client->ViceId : 0), AUD_INT,
1014 CallingRoutine, AUD_END);
1016 if (readonlyServer) {
1019 if (CallingRoutine == CHK_STOREACL) {
1020 if (!(rights & PRSFS_ADMINISTER)
1021 && !VolumeOwner(client, targetptr))
1023 } else { /* store data or status */
1024 /* watch for chowns and chgrps */
1025 if (CHOWN(InStatus, targetptr)
1026 || CHGRP(InStatus, targetptr)) {
1029 else if (VanillaUser(client))
1030 return (EPERM); /* Was EACCES */
1032 osi_audit(PrivilegeEvent, 0, AUD_ID,
1033 (client ? client->ViceId : 0), AUD_INT,
1034 CallingRoutine, AUD_END);
1036 /* must be sysadmin to set suid/sgid bits */
1037 if ((InStatus->Mask & AFS_SETMODE) &&
1039 (InStatus->UnixModeBits & 0xc00) != 0) {
1041 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1045 if (VanillaUser(client))
1048 osi_audit(PrivSetID, 0, AUD_ID,
1049 (client ? client->ViceId : 0), AUD_INT,
1050 CallingRoutine, AUD_END);
1052 if (CallingRoutine == CHK_STOREDATA) {
1055 if (!(rights & PRSFS_WRITE))
1057 /* Next thing is tricky. We want to prevent people
1058 * from writing files sans 0200 bit, but we want
1059 * creating new files with 0444 mode to work. We
1060 * don't check the 0200 bit in the "you are the owner"
1061 * path above, but here we check the bit. However, if
1062 * you're a system administrator, we ignore the 0200
1063 * bit anyway, since you may have fchowned the file,
1065 #ifdef USE_GROUP_PERMS
1066 if ((targetptr->disk.type == vFile)
1067 && VanillaUser(client)) {
1068 if (!OWNSp(client, targetptr)
1069 && !client_HasAsMember(client, targetptr->disk.owner)) {
1071 ((GROUPWRITE & targetptr->disk.modeBits)
1075 ((OWNERWRITE & targetptr->disk.modeBits)
1080 if ((targetptr->disk.type != vDirectory)
1081 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1084 if (VanillaUser(client))
1087 osi_audit(PrivilegeEvent, 0, AUD_ID,
1088 (client ? client->ViceId : 0),
1089 AUD_INT, CallingRoutine, AUD_END);
1091 } else { /* a status store */
1094 if (targetptr->disk.type == vDirectory) {
1095 if (!(rights & PRSFS_DELETE)
1096 && !(rights & PRSFS_INSERT))
1098 } else { /* a file or symlink */
1099 if (!(rights & PRSFS_WRITE))
1109 } /*Check_PermissionRights */
1113 * The Access List information is converted from its internal form in the
1114 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1115 * external form and returned back to the caller, via the AccessList
1119 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1120 struct AFSOpaque *AccessList)
1122 char *eACL; /* External access list placeholder */
1124 if (acl_Externalize_pr
1125 (hpr_IdToName, (targetptr->disk.type ==
1126 vDirectory ? VVnodeACL(targetptr) :
1127 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1130 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1131 acl_FreeExternalACL(&eACL);
1134 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1135 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1137 acl_FreeExternalACL(&eACL);
1140 } /*RXFetch_AccessList */
1144 * The Access List information is converted from its external form in the
1145 * input AccessList structure to the internal representation and copied into
1146 * the target dir's vnode storage.
1149 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1151 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1153 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1156 if ((newACL->size + 4) > VAclSize(targetptr))
1158 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1159 acl_FreeACL(&newACL);
1162 } /*RXStore_AccessList */
1165 /* In our current implementation, each successive data store (new file
1166 * data version) creates a new inode. This function creates the new
1167 * inode, copies the old inode's contents to the new one, remove the old
1168 * inode (i.e. decrement inode count -- if it's currently used the delete
1169 * will be delayed), and modify some fields (i.e. vnode's
1170 * disk.inodeNumber and cloned)
1172 #define COPYBUFFSIZE 8192
1173 #define MAXFSIZE (~(afs_fsize_t) 0)
1175 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1178 Inode nearInode AFS_UNUSED;
1185 int rc; /* return code */
1186 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1187 FdHandle_t *targFdP; /* Source Inode file handle */
1188 FdHandle_t *newFdP; /* Dest Inode file handle */
1190 if (targetptr->disk.type == vDirectory)
1191 DFlush(); /* just in case? */
1193 VN_GET_LEN(size, targetptr);
1201 buff = (char *)malloc(COPYBUFFSIZE);
1206 ino = VN_GET_INO(targetptr);
1207 if (!VALID_INO(ino)) {
1209 VTakeOffline(volptr);
1210 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1214 targFdP = IH_OPEN(targetptr->handle);
1215 if (targFdP == NULL) {
1218 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1219 targetptr->vnodeNumber, V_id(volptr), rc));
1221 VTakeOffline(volptr);
1225 nearInode = VN_GET_INO(targetptr);
1227 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1228 VPartitionPath(V_partition(volptr)), nearInode,
1229 V_id(volptr), targetptr->vnodeNumber,
1230 targetptr->disk.uniquifier,
1231 (int)targetptr->disk.dataVersion);
1232 if (!VALID_INO(ino)) {
1234 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1235 volptr->partition->name, V_id(volptr), errno));
1240 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1241 newFdP = IH_OPEN(newH);
1242 osi_Assert(newFdP != NULL);
1246 if (size > COPYBUFFSIZE) { /* more than a buffer */
1247 length = COPYBUFFSIZE;
1248 size -= COPYBUFFSIZE;
1253 rdlen = FDH_PREAD(targFdP, buff, length, done);
1254 if (rdlen == length) {
1255 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1259 /* Callers of this function are not prepared to recover
1260 * from error that put the filesystem in an inconsistent
1261 * state. Make sure that we force the volume off-line if
1262 * we some error other than ENOSPC - 4.29.99)
1264 * In case we are unable to write the required bytes, and the
1265 * error code indicates that the disk is full, we roll-back to
1266 * the initial state.
1268 if ((rdlen != length) || (wrlen != length)) {
1269 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1271 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1272 volptr->partition->name, V_id(volptr)));
1273 /* remove destination inode which was partially copied till now */
1274 FDH_REALLYCLOSE(newFdP);
1276 FDH_REALLYCLOSE(targFdP);
1277 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1280 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1281 rc, V_id(volptr), volptr->partition->name));
1282 VTakeOffline(volptr);
1287 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1288 * since we never do any I/O anywhere near 2^32 bytes at a
1289 * time, just case to an unsigned int for printing */
1292 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1293 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1294 (unsigned)wrlen, errno));
1295 #if defined(AFS_DEMAND_ATTACH_FS)
1296 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1298 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1300 /* Decrement this inode so salvager doesn't find it. */
1301 FDH_REALLYCLOSE(newFdP);
1303 FDH_REALLYCLOSE(targFdP);
1304 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1306 VTakeOffline(volptr);
1310 #ifndef AFS_PTHREAD_ENV
1312 #endif /* !AFS_PTHREAD_ENV */
1314 FDH_REALLYCLOSE(targFdP);
1315 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1316 V_parentId(volptr));
1318 IH_RELEASE(targetptr->handle);
1320 rc = FDH_SYNC(newFdP);
1321 osi_Assert(rc == 0);
1323 targetptr->handle = newH;
1324 VN_SET_INO(targetptr, ino);
1325 targetptr->disk.cloned = 0;
1326 /* Internal change to vnode, no user level change to volume - def 5445 */
1327 targetptr->changed_oldTime = 1;
1329 return 0; /* success */
1333 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1336 char *buff = malloc(COPYBUFFSIZE);
1341 afs_foff_t done = off;
1343 if (size > FDH_SIZE(targFdP) - off)
1344 size = FDH_SIZE(targFdP) - off;
1347 if (size > COPYBUFFSIZE) { /* more than a buffer */
1348 length = COPYBUFFSIZE;
1349 size -= COPYBUFFSIZE;
1354 rdlen = FDH_PREAD(targFdP, buff, length, done);
1355 if (rdlen == length) {
1356 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1362 if ((rdlen != length) || (wrlen != length)) {
1363 /* no error recovery, at the worst we'll have a "hole"
1375 * Common code to handle with removing the Name (file when it's called from
1376 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1377 * given directory, parentptr.
1379 int DT1 = 0, DT0 = 0;
1381 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1382 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1384 DirHandle childdir; /* Handle for dir package I/O */
1385 Error errorCode = 0;
1389 /* watch for invalid names */
1390 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1393 if (CheckLength(volptr, parentptr, -1)) {
1394 VTakeOffline(volptr);
1398 if (parentptr->disk.cloned) {
1399 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1400 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1402 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1408 /* check that the file is in the directory */
1409 SetDirHandle(dir, parentptr);
1410 if (afs_dir_Lookup(dir, Name, fileFid))
1412 fileFid->Volume = V_id(volptr);
1414 /* just-in-case check for something causing deadlock */
1415 if (fileFid->Vnode == parentptr->vnodeNumber)
1418 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1422 if (ChkForDir == MustBeDIR) {
1423 if ((*targetptr)->disk.type != vDirectory)
1425 } else if ((*targetptr)->disk.type == vDirectory)
1428 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1430 * If the uniquifiers dont match then instead of asserting
1431 * take the volume offline and return VSALVAGE
1433 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1434 VTakeOffline(volptr);
1436 ("Volume %u now offline, must be salvaged.\n",
1438 errorCode = VSALVAGE;
1442 if (ChkForDir == MustBeDIR) {
1443 SetDirHandle(&childdir, *targetptr);
1444 if (afs_dir_IsEmpty(&childdir) != 0)
1448 (*targetptr)->delete = 1;
1449 } else if ((--(*targetptr)->disk.linkCount) == 0)
1450 (*targetptr)->delete = 1;
1451 if ((*targetptr)->delete) {
1452 if (VN_GET_INO(*targetptr)) {
1454 IH_REALLYCLOSE((*targetptr)->handle);
1456 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1457 V_parentId(volptr));
1458 IH_RELEASE((*targetptr)->handle);
1459 if (errorCode == -1) {
1461 ("DT: inode=%s, name=%s, errno=%d\n",
1462 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1464 if (errno != ENOENT)
1466 VTakeOffline(volptr);
1468 ("Volume %u now offline, must be salvaged.\n",
1476 VN_SET_INO(*targetptr, (Inode) 0);
1478 afs_fsize_t adjLength;
1479 VN_GET_LEN(adjLength, *targetptr);
1480 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1484 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1486 code = afs_dir_Delete(dir, Name);
1489 ("Error %d deleting %s\n", code,
1490 (((*targetptr)->disk.type ==
1491 Directory) ? "directory" : "file")));
1492 VTakeOffline(volptr);
1494 ("Volume %u now offline, must be salvaged.\n",
1507 * This routine updates the parent directory's status block after the
1508 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1509 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1513 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1514 int author, int linkcount,
1515 #if FS_STATS_DETAILED
1516 char a_inSameNetwork
1517 #endif /* FS_STATS_DETAILED */
1520 afs_fsize_t newlength; /* Holds new directory length */
1521 afs_fsize_t parentLength;
1523 #if FS_STATS_DETAILED
1524 Date currDate; /*Current date */
1525 int writeIdx; /*Write index to bump */
1526 int timeIdx; /*Authorship time index to bump */
1527 #endif /* FS_STATS_DETAILED */
1529 parentptr->disk.dataVersion++;
1530 newlength = (afs_fsize_t) afs_dir_Length(dir);
1532 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1533 * (create, symlink, link, makedir) so we need to check if we have enough space
1534 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1535 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1537 VN_GET_LEN(parentLength, parentptr);
1538 if (nBlocks(newlength) != nBlocks(parentLength)) {
1539 VAdjustDiskUsage(&errorCode, volptr,
1540 (nBlocks(newlength) - nBlocks(parentLength)),
1541 (nBlocks(newlength) - nBlocks(parentLength)));
1543 VN_SET_LEN(parentptr, newlength);
1545 #if FS_STATS_DETAILED
1547 * Update directory write stats for this volume. Note that the auth
1548 * counter is located immediately after its associated ``distance''
1551 if (a_inSameNetwork)
1552 writeIdx = VOL_STATS_SAME_NET;
1554 writeIdx = VOL_STATS_DIFF_NET;
1555 V_stat_writes(volptr, writeIdx)++;
1556 if (author != AnonymousID) {
1557 V_stat_writes(volptr, writeIdx + 1)++;
1561 * Update the volume's authorship information in response to this
1562 * directory operation. Get the current time, decide to which time
1563 * slot this operation belongs, and bump the appropriate slot.
1565 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1567 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1568 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1569 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1570 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1571 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1572 if (parentptr->disk.author == author) {
1573 V_stat_dirSameAuthor(volptr, timeIdx)++;
1575 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1577 #endif /* FS_STATS_DETAILED */
1579 parentptr->disk.author = author;
1580 parentptr->disk.linkCount = linkcount;
1581 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1582 parentptr->disk.serverModifyTime = FT_ApproxTime();
1583 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1588 * Update the target file's (or dir's) status block after the specified
1589 * operation is complete. Note that some other fields maybe updated by
1590 * the individual module.
1593 /* XXX INCOMPLETE - More attention is needed here! */
1595 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1596 struct client *client, AFSStoreStatus * InStatus,
1597 Vnode * parentptr, Volume * volptr,
1600 #if FS_STATS_DETAILED
1601 Date currDate; /*Current date */
1602 int writeIdx; /*Write index to bump */
1603 int timeIdx; /*Authorship time index to bump */
1604 #endif /* FS_STATS_DETAILED */
1606 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1607 targetptr->disk.parent = parentptr->vnodeNumber;
1608 VN_SET_LEN(targetptr, length);
1609 /* targetptr->disk.group = 0; save some cycles */
1610 targetptr->disk.modeBits = 0777;
1611 targetptr->disk.owner = client->ViceId;
1612 targetptr->disk.dataVersion = 0; /* consistent with the client */
1613 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1614 /* the inode was created in Alloc_NewVnode() */
1616 #if FS_STATS_DETAILED
1618 * Update file write stats for this volume. Note that the auth
1619 * counter is located immediately after its associated ``distance''
1622 if (client->InSameNetwork)
1623 writeIdx = VOL_STATS_SAME_NET;
1625 writeIdx = VOL_STATS_DIFF_NET;
1626 V_stat_writes(volptr, writeIdx)++;
1627 if (client->ViceId != AnonymousID) {
1628 V_stat_writes(volptr, writeIdx + 1)++;
1632 * We only count operations that DON'T involve creating new objects
1633 * (files, symlinks, directories) or simply setting status as
1634 * authorship-change operations.
1636 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1638 * Update the volume's authorship information in response to this
1639 * file operation. Get the current time, decide to which time
1640 * slot this operation belongs, and bump the appropriate slot.
1642 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1645 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1646 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1647 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1648 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1649 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1650 VOL_STATS_TIME_IDX_5);
1651 if (targetptr->disk.author == client->ViceId) {
1652 V_stat_fileSameAuthor(volptr, timeIdx)++;
1654 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1657 #endif /* FS_STATS_DETAILED */
1659 if (!(Caller & TVS_SSTATUS))
1660 targetptr->disk.author = client->ViceId;
1661 if (Caller & TVS_SDATA) {
1662 targetptr->disk.dataVersion++;
1663 if (VanillaUser(client)) {
1664 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1665 #ifdef CREATE_SGUID_ADMIN_ONLY
1666 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1670 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1671 /* store status, must explicitly request to change the date */
1672 if (InStatus->Mask & AFS_SETMODTIME)
1673 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1674 } else { /* other: date always changes, but perhaps to what is specified by caller */
1675 targetptr->disk.unixModifyTime =
1676 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1677 ClientModTime : FT_ApproxTime());
1679 if (InStatus->Mask & AFS_SETOWNER) {
1680 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1681 if (VanillaUser(client)) {
1682 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1683 #ifdef CREATE_SGUID_ADMIN_ONLY
1684 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1687 targetptr->disk.owner = InStatus->Owner;
1688 if (VolumeRootVnode(targetptr)) {
1689 Error errorCode = 0; /* what should be done with this? */
1691 V_owner(targetptr->volumePtr) = InStatus->Owner;
1692 VUpdateVolume(&errorCode, targetptr->volumePtr);
1695 if (InStatus->Mask & AFS_SETMODE) {
1696 int modebits = InStatus->UnixModeBits;
1697 #define CREATE_SGUID_ADMIN_ONLY 1
1698 #ifdef CREATE_SGUID_ADMIN_ONLY
1699 if (VanillaUser(client))
1700 modebits = modebits & 0777;
1702 if (VanillaUser(client)) {
1703 targetptr->disk.modeBits = modebits;
1705 targetptr->disk.modeBits = modebits;
1708 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1709 CHK_STOREDATA, AUD_END);
1713 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1714 CHK_STORESTATUS, AUD_END);
1721 targetptr->disk.serverModifyTime = FT_ApproxTime();
1722 if (InStatus->Mask & AFS_SETGROUP)
1723 targetptr->disk.group = InStatus->Group;
1724 /* vnode changed : to be written back by VPutVnode */
1725 targetptr->changed_newTime = 1;
1727 } /*Update_TargetVnodeStatus */
1731 * Fills the CallBack structure with the expiration time and type of callback
1732 * structure. Warning: this function is currently incomplete.
1735 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1737 /* CallBackTime could not be 0 */
1738 if (CallBackTime == 0) {
1739 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1740 CallBack->ExpirationTime = 0;
1742 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1743 CallBack->CallBackVersion = CALLBACK_VERSION;
1744 CallBack->CallBackType = CB_SHARED; /* The default for now */
1746 } /*SetCallBackStruct */
1750 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1751 * allocation; if some error occured (exceeded volume quota or partition
1752 * was full, or whatever), it frees the space back and returns the code.
1753 * We usually pre-adjust the volume space to make sure that there's
1754 * enough space before consuming some.
1757 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1758 afs_sfsize_t checkLength)
1763 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1765 VAdjustDiskUsage(&nc, volptr, -length, 0);
1766 if (rc == VOVERQUOTA) {
1768 ("Volume %u (%s) is full\n", V_id(volptr),
1772 if (rc == VDISKFULL) {
1774 ("Partition %s that contains volume %u is full\n",
1775 volptr->partition->name, V_id(volptr)));
1778 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1783 } /*AdjustDiskUsage */
1786 * Common code that handles the creation of a new file (SAFS_CreateFile and
1787 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1790 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1791 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1792 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1794 Error errorCode = 0; /* Error code returned back */
1797 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1801 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1802 BlocksPreallocatedForVnode))) {
1804 ("Insufficient space to allocate %lld blocks\n",
1805 (afs_intmax_t) BlocksPreallocatedForVnode));
1809 if (CheckLength(volptr, parentptr, -1)) {
1810 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1811 VTakeOffline(volptr);
1815 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1816 if (errorCode != 0) {
1817 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1820 OutFid->Volume = V_id(volptr);
1821 OutFid->Vnode = (*targetptr)->vnodeNumber;
1822 OutFid->Unique = (*targetptr)->disk.uniquifier;
1824 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1826 /* create the inode now itself */
1828 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1829 VPartitionPath(V_partition(volptr)), nearInode,
1830 V_id(volptr), (*targetptr)->vnodeNumber,
1831 (*targetptr)->disk.uniquifier, 1);
1833 /* error in creating inode */
1834 if (!VALID_INO(inode)) {
1836 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1837 (*targetptr)->volumePtr->header->diskstuff.id,
1838 (*targetptr)->vnodeNumber, errno));
1839 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1840 (*targetptr)->delete = 1; /* delete vnode */
1843 VN_SET_INO(*targetptr, inode);
1844 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1846 /* copy group from parent dir */
1847 (*targetptr)->disk.group = parentptr->disk.group;
1849 if (parentptr->disk.cloned) {
1850 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1851 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1852 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1853 /* delete the vnode previously allocated */
1854 (*targetptr)->delete = 1;
1855 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1856 IH_REALLYCLOSE((*targetptr)->handle);
1857 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1859 ("Alloc_NewVnode: partition %s idec %s failed\n",
1860 volptr->partition->name, PrintInode(stmp, inode)));
1861 IH_RELEASE((*targetptr)->handle);
1867 /* add the name to the directory */
1868 SetDirHandle(dir, parentptr);
1869 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1870 (*targetptr)->delete = 1;
1871 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1872 IH_REALLYCLOSE((*targetptr)->handle);
1873 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1875 ("Alloc_NewVnode: partition %s idec %s failed\n",
1876 volptr->partition->name, PrintInode(stmp, inode)));
1877 IH_RELEASE((*targetptr)->handle);
1883 } /*Alloc_NewVnode */
1887 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1891 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1893 int Time; /* Used for time */
1894 int writeVnode = targetptr->changed_oldTime; /* save original status */
1896 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1897 Time = FT_ApproxTime();
1898 switch (LockingType) {
1901 if (Time > targetptr->disk.lock.lockTime)
1902 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1904 Time += AFS_LOCKWAIT;
1905 if (LockingType == LockRead) {
1906 if ( !(rights & PRSFS_LOCK) &&
1907 !(rights & PRSFS_WRITE) &&
1908 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1911 if (targetptr->disk.lock.lockCount >= 0) {
1912 ++(targetptr->disk.lock.lockCount);
1913 targetptr->disk.lock.lockTime = Time;
1916 } else if (LockingType == LockWrite) {
1917 if ( !(rights & PRSFS_WRITE) &&
1918 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1921 if (targetptr->disk.lock.lockCount == 0) {
1922 targetptr->disk.lock.lockCount = -1;
1923 targetptr->disk.lock.lockTime = Time;
1929 Time += AFS_LOCKWAIT;
1930 if (targetptr->disk.lock.lockCount != 0)
1931 targetptr->disk.lock.lockTime = Time;
1936 if ((--targetptr->disk.lock.lockCount) <= 0)
1937 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1941 targetptr->changed_oldTime = writeVnode; /* restore old status */
1942 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1945 } /*HandleLocking */
1947 /* 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. */
1950 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1954 if (!(rights & Prfs_Mode))
1956 if ((targetptr->disk.type != vDirectory)
1957 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1963 * If some flags (i.e. min or max quota) are set, the volume's in disk
1964 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1965 * update, if applicable.
1968 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1969 char *Name, char *OfflineMsg, char *Motd)
1971 Error errorCode = 0;
1973 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1974 V_minquota(volptr) = StoreVolStatus->MinQuota;
1975 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1976 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1977 if (strlen(OfflineMsg) > 0) {
1978 strcpy(V_offlineMessage(volptr), OfflineMsg);
1980 if (strlen(Name) > 0) {
1981 strcpy(V_name(volptr), Name);
1983 #if OPENAFS_VOL_STATS
1985 * We don't overwrite the motd field, since it's now being used
1989 if (strlen(Motd) > 0) {
1990 strcpy(V_motd(volptr), Motd);
1992 #endif /* FS_STATS_DETAILED */
1993 VUpdateVolume(&errorCode, volptr);
1996 } /*RXUpdate_VolumeStatus */
2000 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2001 char **motd, Volume * volptr)
2005 status->Vid = V_id(volptr);
2006 status->ParentId = V_parentId(volptr);
2007 status->Online = V_inUse(volptr);
2008 status->InService = V_inService(volptr);
2009 status->Blessed = V_blessed(volptr);
2010 status->NeedsSalvage = V_needsSalvaged(volptr);
2011 if (VolumeWriteable(volptr))
2012 status->Type = ReadWrite;
2014 status->Type = ReadOnly;
2015 status->MinQuota = V_minquota(volptr);
2016 status->MaxQuota = V_maxquota(volptr);
2017 status->BlocksInUse = V_diskused(volptr);
2018 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
2019 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
2021 /* now allocate and copy these things; they're freed by the RXGEN stub */
2022 temp = strlen(V_name(volptr)) + 1;
2023 *name = malloc(temp);
2025 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2027 strcpy(*name, V_name(volptr));
2028 temp = strlen(V_offlineMessage(volptr)) + 1;
2029 *offMsg = malloc(temp);
2031 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2033 strcpy(*offMsg, V_offlineMessage(volptr));
2034 #if OPENAFS_VOL_STATS
2037 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2039 strcpy(*motd, nullString);
2041 temp = strlen(V_motd(volptr)) + 1;
2042 *motd = malloc(temp);
2044 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2046 strcpy(*motd, V_motd(volptr));
2047 #endif /* OPENAFS_VOL_STATS */
2049 } /*RXGetVolumeStatus */
2053 FileNameOK(char *aname)
2058 /* watch for @sys on the right */
2059 if (strcmp(aname + i - 4, "@sys") == 0)
2062 while ((tc = *aname++)) {
2064 return 0; /* very bad character to encounter */
2066 return 1; /* file name is ok */
2072 * This variant of symlink is expressly to support the AFS/DFS translator
2073 * and is not supported by the AFS fileserver. We just return EINVAL.
2074 * The cache manager should not generate this call to an AFS cache manager.
2077 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2078 char *LinkContents, struct AFSStoreStatus *InStatus,
2079 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2080 struct AFSFetchStatus *OutDirStatus,
2081 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2087 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2088 struct FsCmdInputs * Inputs,
2089 struct FsCmdOutputs * Outputs)
2093 switch (Inputs->command) {
2097 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2098 Inputs->command, Outputs->code));
2103 static struct afs_buffer {
2104 struct afs_buffer *next;
2105 } *freeBufferList = 0;
2106 static int afs_buffersAlloced = 0;
2109 FreeSendBuffer(struct afs_buffer *adata)
2112 afs_buffersAlloced--;
2113 adata->next = freeBufferList;
2114 freeBufferList = adata;
2118 } /*FreeSendBuffer */
2120 /* allocate space for sender */
2122 AllocSendBuffer(void)
2124 struct afs_buffer *tp;
2127 afs_buffersAlloced++;
2128 if (!freeBufferList) {
2131 tmp = malloc(sendBufSize);
2133 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2137 tp = freeBufferList;
2138 freeBufferList = tp->next;
2142 } /*AllocSendBuffer */
2143 #endif /* HAVE_PIOV */
2146 * This routine returns the status info associated with the targetptr vnode
2147 * in the AFSFetchStatus structure. Some of the newer fields, such as
2148 * SegSize and Group are not yet implemented
2152 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2153 afs_int32 anyrights, Vnode * parentptr)
2155 /* initialize return status from a vnode */
2156 status->InterfaceVersion = 1;
2157 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2158 status->errorCode = 0;
2159 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2160 if (targetptr->disk.type == vFile)
2161 status->FileType = File;
2162 else if (targetptr->disk.type == vDirectory)
2163 status->FileType = Directory;
2164 else if (targetptr->disk.type == vSymlink)
2165 status->FileType = SymbolicLink;
2167 status->FileType = Invalid; /*invalid type field */
2168 status->LinkCount = targetptr->disk.linkCount;
2170 afs_fsize_t targetLen;
2171 VN_GET_LEN(targetLen, targetptr);
2172 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2174 status->DataVersion = targetptr->disk.dataVersion;
2175 status->Author = targetptr->disk.author;
2176 status->Owner = targetptr->disk.owner;
2177 status->CallerAccess = rights;
2178 status->AnonymousAccess = anyrights;
2179 status->UnixModeBits = targetptr->disk.modeBits;
2180 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2181 status->ParentVnode =
2182 (status->FileType ==
2183 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2184 status->ParentUnique =
2185 (status->FileType ==
2186 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2187 status->ServerModTime = targetptr->disk.serverModifyTime;
2188 status->Group = targetptr->disk.group;
2189 status->lockCount = targetptr->disk.lock.lockCount;
2190 status->errorCode = 0;
2196 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2197 afs_sfsize_t Pos, afs_sfsize_t Len,
2198 struct AFSFetchStatus *OutStatus,
2199 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2202 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2203 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2204 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2205 Error errorCode = 0; /* return code to caller */
2206 Error fileCode = 0; /* return code from vol package */
2207 Volume *volptr = 0; /* pointer to the volume */
2208 struct client *client = 0; /* pointer to the client data */
2209 struct rx_connection *tcon; /* the connection we're part of */
2211 afs_int32 rights, anyrights; /* rights for this and any user */
2212 struct client *t_client = NULL; /* tmp ptr to client data */
2213 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2214 struct VCallByVol tcbv, *cbv = NULL;
2215 static int remainder = 0; /* shared access protected by FS_LOCK */
2216 struct fsstats fsstats;
2217 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2218 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2220 #if FS_STATS_DETAILED
2221 int readIdx; /* Index of read stats array to bump */
2222 #endif /* FS_STATS_DETAILED */
2224 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2227 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2230 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2232 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2235 /* Get ptr to client data for user Id for logging */
2236 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2237 logHostAddr.s_addr = rxr_HostOf(tcon);
2239 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2240 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2241 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2243 queue_NodeInit(&tcbv);
2248 * Get volume/vnode for the fetched file; caller's access rights to
2249 * it are also returned
2252 GetVolumePackageWithCall(tcon, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2253 &parentwhentargetnotdir, &client, READ_LOCK,
2254 &rights, &anyrights)))
2257 SetVolumeSync(Sync, volptr);
2259 #if FS_STATS_DETAILED
2261 * Remember that another read operation was performed.
2264 if (client->InSameNetwork)
2265 readIdx = VOL_STATS_SAME_NET;
2267 readIdx = VOL_STATS_DIFF_NET;
2268 V_stat_reads(volptr, readIdx)++;
2269 if (client->ViceId != AnonymousID) {
2270 V_stat_reads(volptr, readIdx + 1)++;
2273 #endif /* FS_STATS_DETAILED */
2274 /* Check whether the caller has permission access to fetch the data */
2276 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2280 * Drop the read lock on the parent directory after saving the parent
2281 * vnode information we need to pass to GetStatus
2283 if (parentwhentargetnotdir != NULL) {
2284 tparentwhentargetnotdir = *parentwhentargetnotdir;
2285 VPutVnode(&fileCode, parentwhentargetnotdir);
2286 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2287 parentwhentargetnotdir = NULL;
2290 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2292 /* actually do the data transfer */
2294 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2295 &bytesToXfer, &bytesXferred);
2297 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2303 /* write back the OutStatus from the target vnode */
2304 GetStatus(targetptr, OutStatus, rights, anyrights,
2305 &tparentwhentargetnotdir);
2307 /* if a r/w volume, promise a callback to the caller */
2308 if (VolumeWriteable(volptr))
2309 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2311 struct AFSFid myFid;
2312 memset(&myFid, 0, sizeof(struct AFSFid));
2313 myFid.Volume = Fid->Volume;
2314 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2318 /* Update and store volume/vnode and parent vnodes back */
2319 (void)PutVolumePackageWithCall(parentwhentargetnotdir, targetptr,
2320 (Vnode *) 0, volptr, &client, cbv);
2321 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2322 errorCode = CallPostamble(tcon, errorCode, thost);
2324 fsstats_FinishOp(&fsstats, errorCode);
2326 osi_auditU(acall, FetchDataEvent, errorCode,
2327 AUD_ID, t_client ? t_client->ViceId : 0,
2328 AUD_FID, Fid, AUD_END);
2331 } /*SRXAFS_FetchData */
2334 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2335 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2336 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2338 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2343 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2344 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2345 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2348 afs_sfsize_t tPos, tLen;
2350 tPos = (afs_sfsize_t) Pos;
2351 tLen = (afs_sfsize_t) Len;
2354 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2360 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2361 struct AFSOpaque * AccessList,
2362 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2364 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2365 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2366 Error errorCode = 0; /* return error code to caller */
2367 Volume *volptr = 0; /* pointer to the volume */
2368 struct client *client = 0; /* pointer to the client data */
2369 afs_int32 rights, anyrights; /* rights for this and any user */
2370 struct rx_connection *tcon = rx_ConnectionOf(acall);
2372 struct client *t_client = NULL; /* tmp ptr to client data */
2373 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2374 struct fsstats fsstats;
2376 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2379 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2382 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2384 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2387 /* Get ptr to client data for user Id for logging */
2388 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2389 logHostAddr.s_addr = rxr_HostOf(tcon);
2391 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2392 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2393 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2395 AccessList->AFSOpaque_len = 0;
2396 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2397 if (!AccessList->AFSOpaque_val) {
2398 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2402 * Get volume/vnode for the fetched file; caller's access rights to it
2406 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2407 &parentwhentargetnotdir, &client, READ_LOCK,
2408 &rights, &anyrights)))
2411 SetVolumeSync(Sync, volptr);
2413 /* Check whether we have permission to fetch the ACL */
2415 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2418 /* Get the Access List from the dir's vnode */
2420 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2423 /* Get OutStatus back From the target Vnode */
2424 GetStatus(targetptr, OutStatus, rights, anyrights,
2425 parentwhentargetnotdir);
2428 /* Update and store volume/vnode and parent vnodes back */
2429 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2432 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2433 AccessList->AFSOpaque_val));
2434 errorCode = CallPostamble(tcon, errorCode, thost);
2436 fsstats_FinishOp(&fsstats, errorCode);
2438 osi_auditU(acall, FetchACLEvent, errorCode,
2439 AUD_ID, t_client ? t_client->ViceId : 0,
2441 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2443 } /*SRXAFS_FetchACL */
2447 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2448 * merged into it when possible.
2452 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2453 struct AFSFetchStatus *OutStatus,
2454 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2456 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2457 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2458 Error errorCode = 0; /* return code to caller */
2459 Volume *volptr = 0; /* pointer to the volume */
2460 struct client *client = 0; /* pointer to the client data */
2461 afs_int32 rights, anyrights; /* rights for this and any user */
2462 struct client *t_client = NULL; /* tmp ptr to client data */
2463 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2464 struct rx_connection *tcon = rx_ConnectionOf(acall);
2466 /* Get ptr to client data for user Id for logging */
2467 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2468 logHostAddr.s_addr = rxr_HostOf(tcon);
2470 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2471 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2472 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2474 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2477 * Get volume/vnode for the fetched file; caller's rights to it are
2481 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2482 &parentwhentargetnotdir, &client, READ_LOCK,
2483 &rights, &anyrights)))
2484 goto Bad_FetchStatus;
2486 /* set volume synchronization information */
2487 SetVolumeSync(Sync, volptr);
2489 /* Are we allowed to fetch Fid's status? */
2490 if (targetptr->disk.type != vDirectory) {
2492 Check_PermissionRights(targetptr, client, rights,
2493 CHK_FETCHSTATUS, 0))) {
2494 if (rx_GetCallAbortCode(acall) == errorCode)
2495 rx_SetCallAbortCode(acall, 0);
2496 goto Bad_FetchStatus;
2500 /* set OutStatus From the Fid */
2501 GetStatus(targetptr, OutStatus, rights, anyrights,
2502 parentwhentargetnotdir);
2504 /* If a r/w volume, also set the CallBack state */
2505 if (VolumeWriteable(volptr))
2506 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2508 struct AFSFid myFid;
2509 memset(&myFid, 0, sizeof(struct AFSFid));
2510 myFid.Volume = Fid->Volume;
2511 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2515 /* Update and store volume/vnode and parent vnodes back */
2516 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2518 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2521 } /*SAFSS_FetchStatus */
2525 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2526 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2527 struct AFSVolSync * Sync)
2531 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2532 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2533 Error errorCode = 0; /* return code to caller */
2534 Volume *volptr = 0; /* pointer to the volume */
2535 struct client *client = 0; /* pointer to the client data */
2536 afs_int32 rights, anyrights; /* rights for this and any user */
2537 struct AFSFid *tfid; /* file id we're dealing with now */
2538 struct rx_connection *tcon = rx_ConnectionOf(acall);
2540 struct client *t_client = NULL; /* tmp pointer to the client data */
2541 struct fsstats fsstats;
2543 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2545 ViceLog(1, ("SAFS_BulkStatus\n"));
2547 AFSCallStats.TotalCalls++;
2549 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2550 if (nfiles <= 0) { /* Sanity check */
2552 goto Audit_and_Return;
2555 /* allocate space for return output parameters */
2556 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2557 malloc(nfiles * sizeof(struct AFSFetchStatus));
2558 if (!OutStats->AFSBulkStats_val) {
2559 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2561 OutStats->AFSBulkStats_len = nfiles;
2562 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2563 malloc(nfiles * sizeof(struct AFSCallBack));
2564 if (!CallBacks->AFSCBs_val) {
2565 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2567 CallBacks->AFSCBs_len = nfiles;
2569 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2570 goto Bad_BulkStatus;
2572 tfid = Fids->AFSCBFids_val;
2573 for (i = 0; i < nfiles; i++, tfid++) {
2575 * Get volume/vnode for the fetched file; caller's rights to it
2579 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2580 &parentwhentargetnotdir, &client, READ_LOCK,
2581 &rights, &anyrights)))
2582 goto Bad_BulkStatus;
2583 /* set volume synchronization information, but only once per call */
2585 SetVolumeSync(Sync, volptr);
2587 /* Are we allowed to fetch Fid's status? */
2588 if (targetptr->disk.type != vDirectory) {
2590 Check_PermissionRights(targetptr, client, rights,
2591 CHK_FETCHSTATUS, 0))) {
2592 if (rx_GetCallAbortCode(acall) == errorCode)
2593 rx_SetCallAbortCode(acall, 0);
2594 goto Bad_BulkStatus;
2598 /* set OutStatus From the Fid */
2599 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2600 anyrights, parentwhentargetnotdir);
2602 /* If a r/w volume, also set the CallBack state */
2603 if (VolumeWriteable(volptr))
2604 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2605 &CallBacks->AFSCBs_val[i]);
2607 struct AFSFid myFid;
2608 memset(&myFid, 0, sizeof(struct AFSFid));
2609 myFid.Volume = tfid->Volume;
2610 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2611 &CallBacks->AFSCBs_val[i]);
2614 /* put back the file ID and volume */
2615 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2617 parentwhentargetnotdir = (Vnode *) 0;
2618 targetptr = (Vnode *) 0;
2619 volptr = (Volume *) 0;
2620 client = (struct client *)0;
2624 /* Update and store volume/vnode and parent vnodes back */
2625 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2627 errorCode = CallPostamble(tcon, errorCode, thost);
2629 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2631 fsstats_FinishOp(&fsstats, errorCode);
2634 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2635 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2636 AUD_ID, t_client ? t_client->ViceId : 0,
2637 AUD_FIDS, Fids, AUD_END);
2640 } /*SRXAFS_BulkStatus */
2644 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2645 struct AFSBulkStats * OutStats,
2646 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2650 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2651 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2652 Error errorCode = 0; /* return code to caller */
2653 Volume *volptr = 0; /* pointer to the volume */
2654 struct client *client = 0; /* pointer to the client data */
2655 afs_int32 rights, anyrights; /* rights for this and any user */
2656 struct AFSFid *tfid; /* file id we're dealing with now */
2657 struct rx_connection *tcon;
2659 struct client *t_client = NULL; /* tmp ptr to client data */
2660 AFSFetchStatus *tstatus;
2661 int VolSync_set = 0;
2662 struct fsstats fsstats;
2664 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2666 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2668 AFSCallStats.TotalCalls++;
2670 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2671 if (nfiles <= 0) { /* Sanity check */
2673 goto Audit_and_Return;
2676 /* allocate space for return output parameters */
2677 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2678 malloc(nfiles * sizeof(struct AFSFetchStatus));
2679 if (!OutStats->AFSBulkStats_val) {
2680 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2682 OutStats->AFSBulkStats_len = nfiles;
2683 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2684 malloc(nfiles * sizeof(struct AFSCallBack));
2685 if (!CallBacks->AFSCBs_val) {
2686 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2688 CallBacks->AFSCBs_len = nfiles;
2690 /* Zero out return values to avoid leaking information on partial succes */
2691 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2692 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2693 memset(Sync, 0, sizeof(*Sync));
2695 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2696 goto Bad_InlineBulkStatus;
2699 tfid = Fids->AFSCBFids_val;
2700 for (i = 0; i < nfiles; i++, tfid++) {
2702 * Get volume/vnode for the fetched file; caller's rights to it
2706 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2707 &parentwhentargetnotdir, &client, READ_LOCK,
2708 &rights, &anyrights))) {
2709 tstatus = &OutStats->AFSBulkStats_val[i];
2710 tstatus->errorCode = errorCode;
2711 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2713 parentwhentargetnotdir = (Vnode *) 0;
2714 targetptr = (Vnode *) 0;
2715 volptr = (Volume *) 0;
2716 client = (struct client *)0;
2720 /* set volume synchronization information, but only once per call */
2722 SetVolumeSync(Sync, volptr);
2726 /* Are we allowed to fetch Fid's status? */
2727 if (targetptr->disk.type != vDirectory) {
2729 Check_PermissionRights(targetptr, client, rights,
2730 CHK_FETCHSTATUS, 0))) {
2731 tstatus = &OutStats->AFSBulkStats_val[i];
2732 tstatus->errorCode = errorCode;
2733 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2734 (Vnode *) 0, volptr, &client);
2735 parentwhentargetnotdir = (Vnode *) 0;
2736 targetptr = (Vnode *) 0;
2737 volptr = (Volume *) 0;
2738 client = (struct client *)0;
2743 /* set OutStatus From the Fid */
2744 GetStatus(targetptr,
2745 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2746 rights, anyrights, parentwhentargetnotdir);
2748 /* If a r/w volume, also set the CallBack state */
2749 if (VolumeWriteable(volptr))
2750 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2751 &CallBacks->AFSCBs_val[i]);
2753 struct AFSFid myFid;
2754 memset(&myFid, 0, sizeof(struct AFSFid));
2755 myFid.Volume = tfid->Volume;
2756 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2757 &CallBacks->AFSCBs_val[i]);
2760 /* put back the file ID and volume */
2761 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2763 parentwhentargetnotdir = (Vnode *) 0;
2764 targetptr = (Vnode *) 0;
2765 volptr = (Volume *) 0;
2766 client = (struct client *)0;
2769 Bad_InlineBulkStatus:
2770 /* Update and store volume/vnode and parent vnodes back */
2771 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2773 errorCode = CallPostamble(tcon, errorCode, thost);
2775 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2777 fsstats_FinishOp(&fsstats, errorCode);
2780 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2781 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2782 AUD_ID, t_client ? t_client->ViceId : 0,
2783 AUD_FIDS, Fids, AUD_END);
2786 } /*SRXAFS_InlineBulkStatus */
2790 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2791 struct AFSFetchStatus * OutStatus,
2792 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2795 struct rx_connection *tcon;
2797 struct client *t_client = NULL; /* tmp ptr to client data */
2798 struct fsstats fsstats;
2800 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2802 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2803 goto Bad_FetchStatus;
2805 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2808 code = CallPostamble(tcon, code, thost);
2810 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2812 fsstats_FinishOp(&fsstats, code);
2814 osi_auditU(acall, FetchStatusEvent, code,
2815 AUD_ID, t_client ? t_client->ViceId : 0,
2816 AUD_FID, Fid, AUD_END);
2819 } /*SRXAFS_FetchStatus */
2823 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2824 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2825 afs_fsize_t Length, afs_fsize_t FileLength,
2826 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2828 Vnode *targetptr = 0; /* pointer to input fid */
2829 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2830 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2831 Error errorCode = 0; /* return code for caller */
2832 Error fileCode = 0; /* return code from vol package */
2833 Volume *volptr = 0; /* pointer to the volume header */
2834 struct client *client = 0; /* pointer to client structure */
2835 afs_int32 rights, anyrights; /* rights for this and any user */
2836 struct client *t_client = NULL; /* tmp ptr to client data */
2837 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2838 struct rx_connection *tcon;
2840 struct fsstats fsstats;
2841 afs_sfsize_t bytesToXfer;
2842 afs_sfsize_t bytesXferred;
2843 static int remainder = 0;
2846 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2849 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2852 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2854 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2857 /* Get ptr to client data for user Id for logging */
2858 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2859 logHostAddr.s_addr = rxr_HostOf(tcon);
2861 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2862 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2863 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2866 * Get associated volume/vnode for the stored file; caller's rights
2870 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2871 &parentwhentargetnotdir, &client, WRITE_LOCK,
2872 &rights, &anyrights))) {
2876 /* set volume synchronization information */
2877 SetVolumeSync(Sync, volptr);
2879 if ((targetptr->disk.type == vSymlink)) {
2880 /* Should we return a better error code here??? */
2885 /* Check if we're allowed to store the data */
2887 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2893 * Drop the read lock on the parent directory after saving the parent
2894 * vnode information we need to pass to GetStatus
2896 if (parentwhentargetnotdir != NULL) {
2897 tparentwhentargetnotdir = *parentwhentargetnotdir;
2898 VPutVnode(&fileCode, parentwhentargetnotdir);
2899 osi_Assert(!fileCode || (fileCode == VSALVAGE));
2900 parentwhentargetnotdir = NULL;
2903 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2906 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2907 FileLength, (InStatus->Mask & AFS_FSYNC),
2908 &bytesToXfer, &bytesXferred);
2910 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2913 if (errorCode && (!targetptr->changed_newTime))
2916 /* Update the status of the target's vnode */
2917 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2918 targetptr, volptr, 0);
2920 /* Get the updated File's status back to the caller */
2921 GetStatus(targetptr, OutStatus, rights, anyrights,
2922 &tparentwhentargetnotdir);
2925 /* Update and store volume/vnode and parent vnodes back */
2926 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2928 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2930 errorCode = CallPostamble(tcon, errorCode, thost);
2932 fsstats_FinishOp(&fsstats, errorCode);
2934 osi_auditU(acall, StoreDataEvent, errorCode,
2935 AUD_ID, t_client ? t_client->ViceId : 0,
2936 AUD_FID, Fid, AUD_END);
2938 } /*common_StoreData64 */
2941 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
2942 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
2943 afs_uint32 Length, afs_uint32 FileLength,
2944 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2946 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
2947 (0x7fffffff - Pos) < Length)
2950 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
2952 } /*SRXAFS_StoreData */
2955 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
2956 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
2957 afs_uint64 Length, afs_uint64 FileLength,
2958 struct AFSFetchStatus * OutStatus,
2959 struct AFSVolSync * Sync)
2963 afs_fsize_t tLength;
2964 afs_fsize_t tFileLength;
2966 tPos = (afs_fsize_t) Pos;
2967 tLength = (afs_fsize_t) Length;
2968 tFileLength = (afs_fsize_t) FileLength;
2971 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
2977 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
2978 struct AFSOpaque * AccessList,
2979 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2981 Vnode *targetptr = 0; /* pointer to input fid */
2982 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2983 Error errorCode = 0; /* return code for caller */
2984 struct AFSStoreStatus InStatus; /* Input status for fid */
2985 Volume *volptr = 0; /* pointer to the volume header */
2986 struct client *client = 0; /* pointer to client structure */
2987 afs_int32 rights, anyrights; /* rights for this and any user */
2988 struct rx_connection *tcon;
2990 struct client *t_client = NULL; /* tmp ptr to client data */
2991 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2992 struct fsstats fsstats;
2994 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
2996 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2999 /* Get ptr to client data for user Id for logging */
3000 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3001 logHostAddr.s_addr = rxr_HostOf(tcon);
3003 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3004 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3005 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3007 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3009 InStatus.Mask = 0; /* not storing any status */
3012 * Get associated volume/vnode for the target dir; caller's rights
3013 * are also returned.
3016 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3017 &parentwhentargetnotdir, &client, WRITE_LOCK,
3018 &rights, &anyrights))) {
3022 /* set volume synchronization information */
3023 SetVolumeSync(Sync, volptr);
3025 /* Check if we have permission to change the dir's ACL */
3027 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3032 /* Build and store the new Access List for the dir */
3033 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3037 targetptr->changed_newTime = 1; /* status change of directory */
3039 /* convert the write lock to a read lock before breaking callbacks */
3040 VVnodeWriteToRead(&errorCode, targetptr);
3041 osi_Assert(!errorCode || errorCode == VSALVAGE);
3043 /* break call backs on the directory */
3044 BreakCallBack(client->host, Fid, 0);
3046 /* Get the updated dir's status back to the caller */
3047 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3050 /* Update and store volume/vnode and parent vnodes back */
3051 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3053 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3054 errorCode = CallPostamble(tcon, errorCode, thost);
3056 fsstats_FinishOp(&fsstats, errorCode);
3058 osi_auditU(acall, StoreACLEvent, errorCode,
3059 AUD_ID, t_client ? t_client->ViceId : 0,
3060 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3063 } /*SRXAFS_StoreACL */
3067 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3068 * should be merged when possible.
3071 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3072 struct AFSStoreStatus *InStatus,
3073 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3075 Vnode *targetptr = 0; /* pointer to input fid */
3076 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3077 Error errorCode = 0; /* return code for caller */
3078 Volume *volptr = 0; /* pointer to the volume header */
3079 struct client *client = 0; /* pointer to client structure */
3080 afs_int32 rights, anyrights; /* rights for this and any user */
3081 struct client *t_client = NULL; /* tmp ptr to client data */
3082 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3083 struct rx_connection *tcon = rx_ConnectionOf(acall);
3085 /* Get ptr to client data for user Id for logging */
3086 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3087 logHostAddr.s_addr = rxr_HostOf(tcon);
3089 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3090 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3091 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3093 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3096 * Get volume/vnode for the target file; caller's rights to it are
3100 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3101 &parentwhentargetnotdir, &client, WRITE_LOCK,
3102 &rights, &anyrights))) {
3103 goto Bad_StoreStatus;
3106 /* set volume synchronization information */
3107 SetVolumeSync(Sync, volptr);
3109 /* Check if the caller has proper permissions to store status to Fid */
3111 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3113 goto Bad_StoreStatus;
3116 * Check for a symbolic link; we can't chmod these (otherwise could
3117 * change a symlink to a mt pt or vice versa)
3119 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3121 goto Bad_StoreStatus;
3124 /* Update the status of the target's vnode */
3125 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3126 (parentwhentargetnotdir ? parentwhentargetnotdir
3127 : targetptr), volptr, 0);
3129 /* convert the write lock to a read lock before breaking callbacks */
3130 VVnodeWriteToRead(&errorCode, targetptr);
3131 osi_Assert(!errorCode || errorCode == VSALVAGE);
3133 /* Break call backs on Fid */
3134 BreakCallBack(client->host, Fid, 0);
3136 /* Return the updated status back to caller */
3137 GetStatus(targetptr, OutStatus, rights, anyrights,
3138 parentwhentargetnotdir);
3141 /* Update and store volume/vnode and parent vnodes back */
3142 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3144 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3147 } /*SAFSS_StoreStatus */
3151 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3152 struct AFSStoreStatus * InStatus,
3153 struct AFSFetchStatus * OutStatus,
3154 struct AFSVolSync * Sync)
3157 struct rx_connection *tcon;
3159 struct client *t_client = NULL; /* tmp ptr to client data */
3160 struct fsstats fsstats;
3162 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3164 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3165 goto Bad_StoreStatus;
3167 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3170 code = CallPostamble(tcon, code, thost);
3172 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3174 fsstats_FinishOp(&fsstats, code);
3176 osi_auditU(acall, StoreStatusEvent, code,
3177 AUD_ID, t_client ? t_client->ViceId : 0,
3178 AUD_FID, Fid, AUD_END);
3181 } /*SRXAFS_StoreStatus */
3185 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3186 * merged in when possible.
3189 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3190 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3192 Vnode *parentptr = 0; /* vnode of input Directory */
3193 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3194 Vnode *targetptr = 0; /* file to be deleted */
3195 Volume *volptr = 0; /* pointer to the volume header */
3196 AFSFid fileFid; /* area for Fid from the directory */
3197 Error errorCode = 0; /* error code */
3198 DirHandle dir; /* Handle for dir package I/O */
3199 struct client *client = 0; /* pointer to client structure */
3200 afs_int32 rights, anyrights; /* rights for this and any user */
3201 struct client *t_client; /* tmp ptr to client data */
3202 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3203 struct rx_connection *tcon = rx_ConnectionOf(acall);
3206 /* Get ptr to client data for user Id for logging */
3207 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3208 logHostAddr.s_addr = rxr_HostOf(tcon);
3210 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3211 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3212 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3214 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3217 * Get volume/vnode for the parent dir; caller's access rights are
3221 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3222 &parentwhentargetnotdir, &client, WRITE_LOCK,
3223 &rights, &anyrights))) {
3224 goto Bad_RemoveFile;
3226 /* set volume synchronization information */
3227 SetVolumeSync(Sync, volptr);
3229 /* Does the caller has delete (& write) access to the parent directory? */
3230 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3231 goto Bad_RemoveFile;
3234 /* Actually delete the desired file */
3236 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3238 goto Bad_RemoveFile;
3241 /* Update the vnode status of the parent dir */
3242 #if FS_STATS_DETAILED
3243 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3244 parentptr->disk.linkCount,
3245 client->InSameNetwork);
3247 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3248 parentptr->disk.linkCount);
3249 #endif /* FS_STATS_DETAILED */
3251 /* Return the updated parent dir's status back to caller */
3252 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3254 /* Handle internal callback state for the parent and the deleted file */
3255 if (targetptr->disk.linkCount == 0) {
3256 /* no references left, discard entry */
3257 DeleteFileCallBacks(&fileFid);
3258 /* convert the parent lock to a read lock before breaking callbacks */
3259 VVnodeWriteToRead(&errorCode, parentptr);
3260 osi_Assert(!errorCode || errorCode == VSALVAGE);
3262 /* convert the parent lock to a read lock before breaking callbacks */
3263 VVnodeWriteToRead(&errorCode, parentptr);
3264 osi_Assert(!errorCode || errorCode == VSALVAGE);
3265 /* convert the target lock to a read lock before breaking callbacks */
3266 VVnodeWriteToRead(&errorCode, targetptr);
3267 osi_Assert(!errorCode || errorCode == VSALVAGE);
3268 /* tell all the file has changed */
3269 BreakCallBack(client->host, &fileFid, 1);
3272 /* break call back on the directory */
3273 BreakCallBack(client->host, DirFid, 0);
3276 /* Update and store volume/vnode and parent vnodes back */
3277 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3280 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3283 } /*SAFSS_RemoveFile */
3287 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3288 struct AFSFetchStatus * OutDirStatus,
3289 struct AFSVolSync * Sync)
3292 struct rx_connection *tcon;
3294 struct client *t_client = NULL; /* tmp ptr to client data */
3295 struct fsstats fsstats;
3297 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3299 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3300 goto Bad_RemoveFile;
3302 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3305 code = CallPostamble(tcon, code, thost);
3307 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3309 fsstats_FinishOp(&fsstats, code);
3311 osi_auditU(acall, RemoveFileEvent, code,
3312 AUD_ID, t_client ? t_client->ViceId : 0,
3313 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3316 } /*SRXAFS_RemoveFile */
3320 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3321 * be merged in when possible.
3324 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3325 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3326 struct AFSFetchStatus *OutFidStatus,
3327 struct AFSFetchStatus *OutDirStatus,
3328 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3330 Vnode *parentptr = 0; /* vnode of input Directory */
3331 Vnode *targetptr = 0; /* vnode of the new file */
3332 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3333 Volume *volptr = 0; /* pointer to the volume header */
3334 Error errorCode = 0; /* error code */
3335 DirHandle dir; /* Handle for dir package I/O */
3336 struct client *client = 0; /* pointer to client structure */
3337 afs_int32 rights, anyrights; /* rights for this and any user */
3338 struct client *t_client; /* tmp ptr to client data */
3339 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3340 struct rx_connection *tcon = rx_ConnectionOf(acall);
3344 /* Get ptr to client data for user Id for logging */
3345 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3346 logHostAddr.s_addr = rxr_HostOf(tcon);
3348 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3349 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3350 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3352 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3354 if (!FileNameOK(Name)) {
3356 goto Bad_CreateFile;
3360 * Get associated volume/vnode for the parent dir; caller long are
3364 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3365 &parentwhentargetnotdir, &client, WRITE_LOCK,
3366 &rights, &anyrights))) {
3367 goto Bad_CreateFile;
3370 /* set volume synchronization information */
3371 SetVolumeSync(Sync, volptr);
3373 /* Can we write (and insert) onto the parent directory? */
3374 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3375 goto Bad_CreateFile;
3377 /* get a new vnode for the file to be created and set it up */
3379 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3380 vFile, nBlocks(0)))) {
3381 goto Bad_CreateFile;
3384 /* update the status of the parent vnode */
3385 #if FS_STATS_DETAILED
3386 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3387 parentptr->disk.linkCount,
3388 client->InSameNetwork);
3390 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3391 parentptr->disk.linkCount);
3392 #endif /* FS_STATS_DETAILED */
3394 /* update the status of the new file's vnode */
3395 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3396 parentptr, volptr, 0);
3398 /* 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 */
3399 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3400 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3402 /* convert the write lock to a read lock before breaking callbacks */
3403 VVnodeWriteToRead(&errorCode, parentptr);
3404 osi_Assert(!errorCode || errorCode == VSALVAGE);
3406 /* break call back on parent dir */
3407 BreakCallBack(client->host, DirFid, 0);
3409 /* Return a callback promise for the newly created file to the caller */
3410 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3413 /* Update and store volume/vnode and parent vnodes back */
3414 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3417 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3420 } /*SAFSS_CreateFile */
3424 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3425 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3426 struct AFSFetchStatus * OutFidStatus,
3427 struct AFSFetchStatus * OutDirStatus,
3428 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3431 struct rx_connection *tcon;
3433 struct client *t_client = NULL; /* tmp ptr to client data */
3434 struct fsstats fsstats;
3436 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3438 memset(OutFid, 0, sizeof(struct AFSFid));
3440 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3441 goto Bad_CreateFile;
3444 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3445 OutDirStatus, CallBack, Sync);
3448 code = CallPostamble(tcon, code, thost);
3450 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3452 fsstats_FinishOp(&fsstats, code);