2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * User space client specific interface glue
14 #include <afsconfig.h>
15 #include "afs/param.h"
23 #include "afs/sysincludes.h" /* Standard vendor system headers */
25 #include "afsincludes.h" /* Afs-based standard headers */
26 #include "afs_usrops.h"
27 #include "afs/afs_stats.h"
29 #include "afs/cellconfig.h"
31 #include "afs/kautils.h"
32 #include "afs/afsutil.h"
33 #include "rx/rx_globals.h"
39 #define CACHEINFOFILE "cacheinfo"
40 #define AFSLOGFILE "AFSLog"
41 #define DCACHEFILE "CacheItems"
42 #define VOLINFOFILE "VolumeItems"
43 #define CELLINFOFILE "CellItems"
47 #define MIN(A,B) ((A)<(B)?(A):(B))
50 #define MAX(A,B) ((A)>(B)?(A):(B))
53 extern int cacheDiskType;
55 char afs_LclCellName[64];
57 struct usr_vnode *afs_FileTable[MAX_OSI_FILES];
58 int afs_FileFlags[MAX_OSI_FILES];
59 int afs_FileOffsets[MAX_OSI_FILES];
61 #define MAX_CACHE_LOOPS 4
63 struct usr_vfs afs_RootVfs;
64 struct usr_vnode *afs_RootVnode = NULL;
65 struct usr_vnode *afs_CurrentDir = NULL;
67 afs_int32 cacheBlocks; /* Num blocks in cache */
68 afs_int32 cacheFiles = 1000; /* Num files in workstation cache */
69 afs_int32 cacheStatEntries = 300; /* Num of stat cache entries */
70 char cacheBaseDir[1024]; /* AFS cache directory */
71 char confDir[1024]; /* AFS configuration directory */
72 char afs_mountDir[1024]; /* AFS mount point */
73 int afs_mountDirLen; /* strlen of AFS mount point */
74 char fullpn_DCacheFile[1024]; /* Full pathname of DCACHEFILE */
75 char fullpn_VolInfoFile[1024]; /* Full pathname of VOLINFOFILE */
76 char fullpn_CellInfoFile[1024]; /* Full pathname of CELLINFOFILE */
77 char fullpn_AFSLogFile[1024]; /* Full pathname of AFSLOGFILE */
78 char fullpn_CacheInfo[1024]; /* Full pathname of CACHEINFO */
79 char fullpn_VFile[1024]; /* Full pathname of data cache files */
80 char *vFileNumber; /* Ptr to number in file pathname */
81 char rootVolume[64] = "root.afs"; /* AFS root volume name */
82 afs_int32 isHomeCell; /* Is current cell info for home cell */
83 int createAndTrunc = O_CREAT | O_TRUNC; /* Create & truncate on open */
84 int ownerRWmode = 0600; /* Read/write OK by owner */
85 static int nDaemons = 2; /* Number of background daemons */
86 static int chunkSize = 0; /* 2^chunkSize bytes per chunk */
87 static int dCacheSize = 300; /* # of dcache entries */
88 static int vCacheSize = 50; /* # of volume cache entries */
89 static int cacheFlags = 0; /* Flags to cache manager */
90 static int preallocs = 400; /* Def # of allocated memory blocks */
91 int afsd_verbose = 0; /* Are we being chatty? */
92 int afsd_debug = 0; /* Are we printing debugging info? */
93 int afsd_CloseSynch = 0; /* Are closes synchronous or not? */
95 #define AFSD_INO_T afs_uint32
96 char **pathname_for_V; /* Array of cache file pathnames */
97 int missing_DCacheFile = 1; /* Is the DCACHEFILE missing? */
98 int missing_VolInfoFile = 1; /* Is the VOLINFOFILE missing? */
99 int missing_CellInfoFile = 1;
100 struct afs_cacheParams cparams; /* params passed to cache manager */
101 struct afsconf_dir *afs_cdir; /* config dir */
103 static int HandleMTab();
105 int afs_bufferpages = 100;
106 int usr_udpcksum = 0;
108 usr_key_t afs_global_u_key;
110 struct usr_proc *afs_global_procp;
111 struct usr_ucred *afs_global_ucredp;
112 struct usr_sysent usr_sysent[200];
114 #ifdef AFS_USR_OSF_ENV
116 #else /* AFS_USR_OSF_ENV */
118 #endif /* AFS_USR_OSF_ENV */
120 struct usr_ucred afs_osi_cred, *afs_osi_credp;
121 usr_mutex_t afs_global_lock;
122 usr_thread_t afs_global_owner;
123 usr_mutex_t rx_global_lock;
124 usr_thread_t rx_global_owner;
125 usr_mutex_t osi_inode_lock;
126 usr_mutex_t osi_waitq_lock;
127 usr_mutex_t osi_authenticate_lock;
129 afs_lock_t osi_flplock;
130 afs_lock_t osi_fsplock;
133 #ifndef NETSCAPE_NSAPI
136 * Mutex and condition variable used to implement sleep
138 pthread_mutex_t usr_sleep_mutex;
139 pthread_cond_t usr_sleep_cond;
141 #endif /* !NETSCAPE_NSAPI */
143 int call_syscall(long, long, long, long, long, long);
147 * Hash table mapping addresses onto wait structures for
148 * osi_Sleep/osi_Wakeup and osi_Wait/osi_Wakeup
150 typedef struct osi_wait {
154 struct osi_wait *next;
155 struct osi_wait *prev;
157 struct osi_wait *timedNext;
158 struct osi_wait *timedPrev;
162 * Head of the linked list of available waitq structures.
164 osi_wait_t *osi_waithash_avail;
167 * List of timed waits, NSAPI does not provide a cond_timed
168 * wait, so we need to keep track of the timed waits ourselves and
169 * periodically check for expirations
171 osi_wait_t *osi_timedwait_head;
172 osi_wait_t *osi_timedwait_tail;
177 } osi_waithash_table[OSI_WAITHASH_SIZE];
180 * Never call afs_brelse
183 ufs_brelse(struct usr_vnode *vp, struct usr_buf *bp)
189 * I am not sure what to do with these, they assert for now
192 iodone(struct usr_buf *bp)
204 * Every user is a super user
207 afs_osi_suser(void *credp)
213 afs_suser(void *credp)
219 * These are no-ops in user space
223 afs_osi_SetTime(osi_timeval_t * atv)
229 * xflock should never fall through, the only files we know
230 * about are AFS files
239 * ioctl should never fall through, the only files we know
240 * about are AFS files
249 * We do not support the inode related system calls
252 afs_syscall_icreate(void)
258 afs_syscall_iincdec(void)
264 afs_syscall_iopen(void)
270 afs_syscall_ireadwrite(void)
276 * these routines are referenced in the vfsops structure, but
277 * should never get called
304 * uiomove copies data between kernel buffers and uio buffers
307 usr_uiomove(char *kbuf, int n, int rw, struct usr_uio *uio)
314 nio = uio->uio_iovcnt;
324 while (nio > 0 && n > 0) {
325 len = MIN(n, iovp->iov_len);
326 if (rw == UIO_READ) {
327 memcpy(iovp->iov_base, ptr, len);
329 memcpy(ptr, iovp->iov_base, len);
333 uio->uio_resid -= len;
334 uio->uio_offset += len;
335 iovp->iov_base = (char *)(iovp->iov_base) + len;
336 iovp->iov_len -= len;
347 * routines to manage user credentials
350 usr_crcopy(struct usr_ucred *credp)
352 struct usr_ucred *newcredp;
354 newcredp = (struct usr_ucred *)afs_osi_Alloc(sizeof(struct usr_ucred));
356 newcredp->cr_ref = 1;
363 struct usr_ucred *newcredp;
365 newcredp = (struct usr_ucred *)afs_osi_Alloc(sizeof(struct usr_ucred));
366 newcredp->cr_ref = 1;
371 usr_crfree(struct usr_ucred *credp)
374 if (credp->cr_ref == 0) {
375 afs_osi_Free((char *)credp, sizeof(struct usr_ucred));
380 usr_crhold(struct usr_ucred *credp)
386 usr_vattr_null(struct usr_vattr *vap)
391 n = sizeof(struct usr_vattr);
399 * Initialize the thread specific data used to simulate the
400 * kernel environment for each thread. The user structure
401 * is stored in the thread specific data.
404 uafs_InitThread(void)
407 struct usr_user *uptr;
410 * initialize the thread specific user structure. Use malloc to
411 * allocate the data block, so pthread_finish can free the buffer
412 * when this thread terminates.
415 (struct usr_user *)malloc(sizeof(struct usr_user) +
416 sizeof(struct usr_ucred));
417 usr_assert(uptr != NULL);
420 uptr->u_procp = afs_global_procp;
421 uptr->u_cred = (struct usr_ucred *)(uptr + 1);
422 *uptr->u_cred = *afs_global_ucredp;
423 st = usr_setspecific(afs_global_u_key, (void *)uptr);
428 * routine to get the user structure from the thread specific data.
429 * this routine is used to implement the global 'u' structure. Initializes
430 * the thread if needed.
433 get_user_struct(void)
435 struct usr_user *uptr;
437 st = usr_getspecific(afs_global_u_key, (void **)&uptr);
441 st = usr_getspecific(afs_global_u_key, (void **)&uptr);
443 usr_assert(uptr != NULL);
449 * Hash an address for the waithash table
451 #define WAITHASH(X) \
452 (((long)(X)^((long)(X)>>4)^((long)(X)<<4))&(OSI_WAITHASH_SIZE-1))
458 afs_osi_Sleep(void *x)
462 int rxGlockOwner = ISAFS_RXGLOCK();
463 int glockOwner = ISAFS_GLOCK();
465 usr_mutex_lock(&osi_waitq_lock);
473 if (osi_waithash_avail == NULL) {
474 waitp = (osi_wait_t *) afs_osi_Alloc(sizeof(osi_wait_t));
475 usr_cond_init(&waitp->cond);
477 waitp = osi_waithash_avail;
478 osi_waithash_avail = osi_waithash_avail->next;
482 DLL_INSERT_TAIL(waitp, osi_waithash_table[index].head,
483 osi_waithash_table[index].tail, next, prev);
484 waitp->expiration = 0;
485 waitp->timedNext = NULL;
486 waitp->timedPrev = NULL;
487 while (waitp->flag == 0) {
488 usr_cond_wait(&waitp->cond, &osi_waitq_lock);
490 DLL_DELETE(waitp, osi_waithash_table[index].head,
491 osi_waithash_table[index].tail, next, prev);
492 waitp->next = osi_waithash_avail;
493 osi_waithash_avail = waitp;
494 usr_mutex_unlock(&osi_waitq_lock);
504 afs_osi_SleepSig(void *x)
511 afs_osi_Wakeup(void *x)
517 usr_mutex_lock(&osi_waitq_lock);
518 waitp = osi_waithash_table[index].head;
520 if (waitp->addr == x && waitp->flag == 0) {
522 usr_cond_signal(&waitp->cond);
526 usr_mutex_unlock(&osi_waitq_lock);
530 afs_osi_Wait(afs_int32 msec, struct afs_osi_WaitHandle *handle, int intok)
536 int rxGlockOwner = ISAFS_RXGLOCK();
537 int glockOwner = ISAFS_GLOCK();
539 tv.tv_sec = msec / 1000;
540 tv.tv_nsec = (msec % 1000) * 1000000;
541 if (handle == NULL) {
548 usr_thread_sleep(&tv);
557 usr_mutex_lock(&osi_waitq_lock);
564 index = WAITHASH((caddr_t) handle);
565 if (osi_waithash_avail == NULL) {
566 waitp = (osi_wait_t *) afs_osi_Alloc(sizeof(osi_wait_t));
567 usr_cond_init(&waitp->cond);
569 waitp = osi_waithash_avail;
570 osi_waithash_avail = osi_waithash_avail->next;
572 waitp->addr = (caddr_t) handle;
574 DLL_INSERT_TAIL(waitp, osi_waithash_table[index].head,
575 osi_waithash_table[index].tail, next, prev);
576 tv.tv_sec += time(NULL);
577 waitp->expiration = tv.tv_sec + ((tv.tv_nsec == 0) ? 0 : 1);
578 DLL_INSERT_TAIL(waitp, osi_timedwait_head, osi_timedwait_tail,
579 timedNext, timedPrev);
580 usr_cond_wait(&waitp->cond, &osi_waitq_lock);
586 DLL_DELETE(waitp, osi_waithash_table[index].head,
587 osi_waithash_table[index].tail, next, prev);
588 DLL_DELETE(waitp, osi_timedwait_head, osi_timedwait_tail, timedNext,
590 waitp->next = osi_waithash_avail;
591 osi_waithash_avail = waitp;
592 usr_mutex_unlock(&osi_waitq_lock);
604 afs_osi_CancelWait(struct afs_osi_WaitHandle *handle)
606 afs_osi_Wakeup(handle);
610 * Netscape NSAPI doesn't have a cond_timed_wait, so we need
611 * to explicitly signal cond_timed_waits when their timers expire
614 afs_osi_CheckTimedWaits(void)
619 curTime = time(NULL);
620 usr_mutex_lock(&osi_waitq_lock);
621 waitp = osi_timedwait_head;
622 while (waitp != NULL) {
623 usr_assert(waitp->expiration != 0);
624 if (waitp->expiration <= curTime) {
626 usr_cond_signal(&waitp->cond);
628 waitp = waitp->timedNext;
630 usr_mutex_unlock(&osi_waitq_lock);
634 * I-node numbers are indeces into a table containing a filename
635 * i-node structure and a vnode structure. When we create an i-node,
636 * we copy the name into the array and initialize enough of the fields
637 * in the inode and vnode structures to get the client to work.
640 struct usr_inode i_node;
643 osi_file_table_t *osi_file_table;
645 int max_osi_files = 0;
648 * Allocate a slot in the file table if there is not one there already,
649 * copy in the file name and kludge up the vnode and inode structures
652 lookupname(char *fnamep, int segflg, int followlink,
653 struct usr_vnode **dirvpp, struct usr_vnode **compvpp)
657 struct usr_inode *ip;
658 struct usr_vnode *vp;
660 /*usr_assert(followlink == 0); */
661 usr_assert(dirvpp == NULL);
664 * Assume relative pathnames refer to files in AFS
666 if (*fnamep != '/' || uafs_afsPathName(fnamep) != NULL) {
668 code = uafs_LookupName(fnamep, afs_CurrentDir, compvpp, 0, 0);
673 usr_mutex_lock(&osi_inode_lock);
675 for (i = 0; i < n_osi_files; i++) {
676 if (strcmp(fnamep, osi_file_table[i].name) == 0) {
677 *compvpp = &osi_file_table[i].i_node.i_vnode;
678 (*compvpp)->v_count++;
679 usr_mutex_unlock(&osi_inode_lock);
684 if (n_osi_files == max_osi_files) {
685 usr_mutex_unlock(&osi_inode_lock);
689 osi_file_table[n_osi_files].name = afs_osi_Alloc(strlen(fnamep) + 1);
690 usr_assert(osi_file_table[n_osi_files].name != NULL);
691 strcpy(osi_file_table[n_osi_files].name, fnamep);
692 ip = &osi_file_table[i].i_node;
694 vp->v_data = (caddr_t) ip;
697 ip->i_number = n_osi_files;
699 usr_mutex_unlock(&osi_inode_lock);
705 * open a file given its i-node number
708 osi_UFSOpen(afs_int32 ino)
716 if (ino > n_osi_files) {
722 fp = (struct osi_file *)afs_osi_Alloc(sizeof(struct osi_file));
723 usr_assert(fp != NULL);
724 fp->fd = open(osi_file_table[ino - 1].name, O_RDWR | O_CREAT, 0);
727 afs_osi_Free((char *)fp, sizeof(struct osi_file));
731 rc = fstat(fp->fd, &st);
734 afs_osi_Free((void *)fp, sizeof(struct osi_file));
738 fp->size = st.st_size;
741 fp->vnode = (struct usr_vnode *)fp;
748 osi_UFSClose(struct osi_file *fp)
758 afs_osi_Free((void *)fp, sizeof(struct osi_file));
762 afs_osi_Free((void *)fp, sizeof(struct osi_file));
768 osi_UFSTruncate(struct osi_file *fp, afs_int32 len)
775 rc = ftruncate(fp->fd, len);
787 afs_osi_Read(struct osi_file *fp, int offset, void *buf, afs_int32 len)
797 rc = lseek(fp->fd, offset, SEEK_SET);
799 rc = lseek(fp->fd, fp->offset, SEEK_SET);
807 ret = read(fp->fd, buf, len);
814 rc = fstat(fp->fd, &st);
820 fp->size = st.st_size;
826 afs_osi_Write(struct osi_file *fp, afs_int32 offset, void *buf, afs_int32 len)
836 rc = lseek(fp->fd, offset, SEEK_SET);
838 rc = lseek(fp->fd, fp->offset, SEEK_SET);
846 ret = write(fp->fd, buf, len);
853 rc = fstat(fp->fd, &st);
859 fp->size = st.st_size;
865 afs_osi_Stat(struct osi_file *fp, struct osi_stat *stp)
871 rc = fstat(fp->fd, &st);
877 stp->size = st.st_size;
878 stp->blksize = st.st_blksize;
879 stp->mtime = st.st_mtime;
880 stp->atime = st.st_atime;
889 afs_osi_VOP_RDWR(struct usr_vnode *vnodeP, struct usr_uio *uioP, int rw,
890 int flags, struct usr_ucred *credP)
893 struct osi_file *fp = (struct osi_file *)vnodeP;
896 * We don't support readv/writev.
898 usr_assert(uioP->uio_iovcnt == 1);
899 usr_assert(uioP->uio_resid == uioP->uio_iov[0].iov_len);
901 if (rw == UIO_WRITE) {
902 usr_assert(uioP->uio_fmode == FWRITE);
903 rc = afs_osi_Write(fp, uioP->uio_offset, uioP->uio_iov[0].iov_base,
904 uioP->uio_iov[0].iov_len);
906 usr_assert(uioP->uio_fmode == FREAD);
907 rc = afs_osi_Read(fp, uioP->uio_offset, uioP->uio_iov[0].iov_base,
908 uioP->uio_iov[0].iov_len);
914 uioP->uio_resid -= rc;
915 uioP->uio_offset += rc;
916 uioP->uio_iov[0].iov_base = (char *)(uioP->uio_iov[0].iov_base) + rc;
917 uioP->uio_iov[0].iov_len -= rc;
922 * Use malloc/free routines with check patterns before and after each block
925 static char *afs_check_string1 = "UAFS";
926 static char *afs_check_string2 = "AFS_OSI_";
929 afs_osi_Alloc(size_t size)
935 afs_osi_Free(void *ptr, size_t size)
941 afs_osi_FreeStr(char *ptr)
947 osi_AllocLargeSpace(size_t size)
949 AFS_STATCNT(osi_AllocLargeSpace);
950 return afs_osi_Alloc(size);
954 osi_FreeLargeSpace(void *ptr)
956 AFS_STATCNT(osi_FreeLargeSpace);
957 afs_osi_Free(ptr, 0);
961 osi_AllocSmallSpace(size_t size)
963 AFS_STATCNT(osi_AllocSmallSpace);
964 return afs_osi_Alloc(size);
968 osi_FreeSmallSpace(void *ptr)
970 AFS_STATCNT(osi_FreeSmallSpace);
971 afs_osi_Free(ptr, 0);
977 AFS_STATCNT(shutdown_osi);
982 shutdown_osinet(void)
984 AFS_STATCNT(shutdown_osinet);
989 shutdown_osifile(void)
991 AFS_STATCNT(shutdown_osifile);
996 afs_nfsclient_init(void)
1002 shutdown_nfsclnt(void)
1008 afs_osi_Invisible(void)
1014 osi_GetTime(struct timeval *tv)
1016 gettimeofday(tv, NULL);
1021 osi_SetTime(struct timeval *tv)
1027 osi_Active(struct vcache *avc)
1029 AFS_STATCNT(osi_Active);
1036 afs_osi_MapStrategy(int (*aproc) (), struct usr_buf *bp)
1038 afs_int32 returnCode;
1039 returnCode = (*aproc) (bp);
1044 osi_FlushPages(register struct vcache *avc, struct AFS_UCRED *credp)
1046 ObtainSharedLock(&avc->lock, 555);
1047 if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0)
1048 || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) {
1049 ReleaseSharedLock(&avc->lock);
1052 UpgradeSToWLock(&avc->lock, 565);
1053 hset(avc->mapDV, avc->m.DataVersion);
1054 ReleaseWriteLock(&avc->lock);
1059 osi_FlushText_really(register struct vcache *vp)
1061 if (hcmp(vp->m.DataVersion, vp->flushDV) > 0) {
1062 hset(vp->flushDV, vp->m.DataVersion);
1068 osi_SyncVM(struct vcache *avc)
1074 osi_ReleaseVM(struct vcache *avc, int len, struct usr_ucred *credp)
1087 * Allocate the table used to implement psuedo-inodes.
1089 max_osi_files = cacheFiles + 100;
1090 osi_file_table = (osi_file_table_t *)
1091 afs_osi_Alloc(max_osi_files * sizeof(osi_file_table_t));
1092 usr_assert(osi_file_table != NULL);
1094 #ifndef NETSCAPE_NSAPI
1096 * Initialize the mutex and condition variable used to implement
1099 pthread_mutex_init(&usr_sleep_mutex, NULL);
1100 pthread_cond_init(&usr_sleep_cond, NULL);
1101 #endif /* !NETSCAPE_NSAPI */
1104 * Initialize the hash table used for sleep/wakeup
1106 for (i = 0; i < OSI_WAITHASH_SIZE; i++) {
1107 DLL_INIT_LIST(osi_waithash_table[i].head, osi_waithash_table[i].tail);
1109 DLL_INIT_LIST(osi_timedwait_head, osi_timedwait_tail);
1110 osi_waithash_avail = NULL;
1113 * Initialize the AFS file table
1115 for (i = 0; i < MAX_OSI_FILES; i++) {
1116 afs_FileTable[i] = NULL;
1120 * Initialize the global locks
1122 usr_mutex_init(&afs_global_lock);
1123 usr_mutex_init(&rx_global_lock);
1124 usr_mutex_init(&osi_inode_lock);
1125 usr_mutex_init(&osi_waitq_lock);
1126 usr_mutex_init(&osi_authenticate_lock);
1129 * Initialize the AFS OSI credentials
1131 afs_osi_cred = *afs_global_ucredp;
1132 afs_osi_credp = &afs_osi_cred;
1135 /* ParseArgs is now obsolete, being handled by cmd */
1137 /*---------------------------------------------------------------------
1141 * Given the final component of a filename expected to be a data cache file,
1142 * return the integer corresponding to the file. Note: we reject names that
1143 * are not a ``V'' followed by an integer. We also reject those names having
1144 * the right format but lying outside the range [0..cacheFiles-1].
1147 * fname : Char ptr to the filename to parse.
1150 * >= 0 iff the file is really a data cache file numbered from 0 to cacheFiles-1, or
1154 * Nothing interesting.
1158 *------------------------------------------------------------------------*/
1161 GetVFileNumber(char *fname)
1163 int computedVNumber; /*The computed file number we return */
1164 int filenameLen; /*Number of chars in filename */
1165 int currDigit; /*Current digit being processed */
1168 * The filename must have at least two characters, the first of which must be a ``V''
1169 * and the second of which cannot be a zero unless the file is exactly two chars long.
1171 filenameLen = strlen(fname);
1172 if (filenameLen < 2)
1174 if (fname[0] != 'V')
1176 if ((filenameLen > 2) && (fname[1] == '0'))
1180 * Scan through the characters in the given filename, failing immediately if a non-digit
1183 for (currDigit = 1; currDigit < filenameLen; currDigit++)
1184 if (isdigit(fname[currDigit]) == 0)
1188 * All relevant characters are digits. Pull out the decimal number they represent.
1189 * Reject it if it's out of range, otherwise return it.
1191 computedVNumber = atoi(++fname);
1192 if (computedVNumber < cacheFiles)
1193 return (computedVNumber);
1198 /*---------------------------------------------------------------------
1202 * Given a full pathname for a file we need to create for the workstation AFS
1203 * cache, go ahead and create the file.
1206 * fname : Full pathname of file to create.
1209 * 0 iff the file was created,
1213 * The given cache file has been found to be missing.
1217 *------------------------------------------------------------------------*/
1220 CreateCacheFile(char *fname)
1222 static char rn[] = "CreateCacheFile"; /*Routine name */
1223 int cfd; /*File descriptor to AFS cache file */
1224 int closeResult; /*Result of close() */
1227 printf("%s: Creating cache file '%s'\n", rn, fname);
1228 cfd = open(fname, createAndTrunc, ownerRWmode);
1230 printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
1234 closeResult = close(cfd);
1237 ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
1245 /*---------------------------------------------------------------------
1249 * Sweep through the AFS cache directory, recording the inode number for
1250 * each valid data cache file there. Also, delete any file that doesn't beint32
1251 * in the cache directory during this sweep, and remember which of the other
1252 * residents of this directory were seen. After the sweep, we create any data
1253 * cache files that were missing.
1256 * vFilesFound : Set to the number of data cache files found.
1259 * 0 if everything went well,
1263 * This routine may be called several times. If the number of data cache files
1264 * found is less than the global cacheFiles, then the caller will need to call it
1265 * again to record the inodes of the missing zero-length data cache files created
1266 * in the previous call.
1269 * Fills up the global pathname_for_V array, may create and/or
1270 * delete files as explained above.
1271 *------------------------------------------------------------------------*/
1274 SweepAFSCache(int *vFilesFound)
1276 static char rn[] = "SweepAFSCache"; /*Routine name */
1277 char fullpn_FileToDelete[1024]; /*File to be deleted from cache */
1278 char *fileToDelete; /*Ptr to last component of above */
1279 DIR *cdirp; /*Ptr to cache directory structure */
1281 struct dirent *currp; /*Current directory entry */
1282 int vFileNum; /*Data cache file's associated number */
1284 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1286 printf("%s: Memory Cache, no cache sweep done\n", rn);
1292 printf("%s: Opening cache directory '%s'\n", rn, cacheBaseDir);
1294 if (chmod(cacheBaseDir, 0700)) { /* force it to be 700 */
1295 printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
1299 cdirp = opendir(cacheBaseDir);
1300 if (cdirp == (DIR *) 0) {
1301 printf("%s: Can't open AFS cache directory, '%s'.\n", rn,
1307 * Scan the directory entries, remembering data cache file inodes and the existance
1308 * of other important residents. Delete all files that don't belong here.
1311 sprintf(fullpn_FileToDelete, "%s/", cacheBaseDir);
1312 fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
1314 for (currp = readdir(cdirp); currp; currp = readdir(cdirp)) {
1316 printf("%s: Current directory entry:\n", rn);
1317 printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino,
1318 currp->d_reclen, currp->d_name);
1322 * Guess current entry is for a data cache file.
1324 vFileNum = GetVFileNumber(currp->d_name);
1325 if (vFileNum >= 0) {
1327 * Found a valid data cache filename. Remember this file's name
1328 * and bump the number of files found.
1330 pathname_for_V[vFileNum] =
1331 afs_osi_Alloc(strlen(currp->d_name) + strlen(cacheBaseDir) +
1333 usr_assert(pathname_for_V[vFileNum] != NULL);
1334 sprintf(pathname_for_V[vFileNum], "%s/%s", cacheBaseDir,
1337 } else if (strcmp(currp->d_name, DCACHEFILE) == 0) {
1339 * Found the file holding the dcache entries.
1341 missing_DCacheFile = 0;
1342 } else if (strcmp(currp->d_name, VOLINFOFILE) == 0) {
1344 * Found the file holding the volume info.
1346 missing_VolInfoFile = 0;
1347 } else if (strcmp(currp->d_name, CELLINFOFILE) == 0) {
1348 missing_CellInfoFile = 0;
1349 } else if ((strcmp(currp->d_name, ".") == 0)
1350 || (strcmp(currp->d_name, "..") == 0)
1351 || (strcmp(currp->d_name, "lost+found") == 0)) {
1353 * Don't do anything - this file is legit, and is to be left alone.
1357 * This file doesn't belong in the cache. Nuke it.
1359 sprintf(fileToDelete, "%s", currp->d_name);
1361 printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
1362 if (unlink(fullpn_FileToDelete)) {
1363 printf("%s: Can't unlink '%s', errno is %d\n", rn,
1364 fullpn_FileToDelete, errno);
1370 * Create all the cache files that are missing.
1372 if (missing_DCacheFile) {
1374 printf("%s: Creating '%s'\n", rn, fullpn_DCacheFile);
1375 if (CreateCacheFile(fullpn_DCacheFile))
1376 printf("%s: Can't create '%s'\n", rn, fullpn_DCacheFile);
1378 if (missing_VolInfoFile) {
1380 printf("%s: Creating '%s'\n", rn, fullpn_VolInfoFile);
1381 if (CreateCacheFile(fullpn_VolInfoFile))
1382 printf("%s: Can't create '%s'\n", rn, fullpn_VolInfoFile);
1384 if (missing_CellInfoFile) {
1386 printf("%s: Creating '%s'\n", rn, fullpn_CellInfoFile);
1387 if (CreateCacheFile(fullpn_CellInfoFile))
1388 printf("%s: Can't create '%s'\n", rn, fullpn_CellInfoFile);
1391 if (*vFilesFound < cacheFiles) {
1393 * We came up short on the number of data cache files found. Scan through the inode
1394 * list and create all missing files.
1396 for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++)
1397 if (pathname_for_V[vFileNum] == (AFSD_INO_T) 0) {
1398 sprintf(vFileNumber, "%d", vFileNum);
1400 printf("%s: Creating '%s'\n", rn, fullpn_VFile);
1401 if (CreateCacheFile(fullpn_VFile))
1402 printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
1407 * Close the directory, return success.
1410 printf("%s: Closing cache directory.\n", rn);
1416 ConfigCell(register struct afsconf_cell *aci, char *arock,
1417 struct afsconf_dir *adir)
1419 register int isHomeCell;
1421 afs_int32 cellFlags = 0;
1422 afs_int32 hosts[MAXHOSTSPERCELL];
1424 /* figure out if this is the home cell */
1425 isHomeCell = (strcmp(aci->name, afs_LclCellName) == 0);
1427 cellFlags = 2; /* not home, suid is forbidden */
1429 /* build address list */
1430 for (i = 0; i < MAXHOSTSPERCELL; i++)
1431 memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
1433 if (aci->linkedCell)
1434 cellFlags |= 4; /* Flag that linkedCell arg exists,
1435 * for upwards compatibility */
1437 /* configure one cell */
1438 call_syscall(AFSCALL_CALL, AFSOP_ADDCELL2, (long)hosts, /* server addresses */
1439 (long)aci->name, /* cell name */
1440 (long)cellFlags, /* is this the home cell? */
1441 (long)aci->linkedCell); /* Linked cell, if any */
1446 ConfigCellAlias(aca, arock, adir)
1447 struct afsconf_cellalias *aca;
1449 struct afsconf_dir *adir;
1451 call_syscall(AFSOP_ADDCELLALIAS, (long)aca->aliasName,
1452 (long)aca->realName, 0, 0, 0);
1457 * Set the UDP port number RX uses for UDP datagrams
1460 uafs_SetRxPort(int port)
1462 usr_assert(usr_rx_port == 0);
1468 * Initialize the user space client.
1471 uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
1472 char *cacheBaseDirParam, int cacheBlocksParam, int cacheFilesParam,
1473 int cacheStatEntriesParam, int dCacheSizeParam, int vCacheSizeParam,
1474 int chunkSizeParam, int closeSynchParam, int debugParam,
1475 int nDaemonsParam, int cacheFlagsParam, char *logFile)
1478 struct usr_proc *procp;
1479 struct usr_ucred *ucredp;
1482 int currVFile; /* Current AFS cache file number */
1483 int lookupResult; /* Result of GetLocalCellName() */
1484 int cacheIteration; /* cache verification loop counter */
1485 int vFilesFound; /* Num data cache files found in sweep */
1487 afs_int32 vfs1_type = -1;
1488 struct afs_ioctl iob;
1492 afs_int32 buffer[MAXIPADDRS];
1493 afs_int32 maskbuffer[MAXIPADDRS];
1494 afs_int32 mtubuffer[MAXIPADDRS];
1497 * Use the thread specific data to implement the user structure
1499 usr_keycreate(&afs_global_u_key, free);
1502 * Initialize the global ucred structure
1504 afs_global_ucredp = (struct usr_ucred *)
1505 afs_osi_Alloc(sizeof(struct usr_ucred));
1506 usr_assert(afs_global_ucredp != NULL);
1507 afs_global_ucredp->cr_ref = 1;
1508 afs_global_ucredp->cr_uid = geteuid();
1509 afs_global_ucredp->cr_gid = getegid();
1510 afs_global_ucredp->cr_ruid = getuid();
1511 afs_global_ucredp->cr_rgid = getgid();
1512 afs_global_ucredp->cr_suid = afs_global_ucredp->cr_ruid;
1513 afs_global_ucredp->cr_sgid = afs_global_ucredp->cr_rgid;
1514 st = getgroups(NGROUPS, &afs_global_ucredp->cr_groups[0]);
1515 usr_assert(st >= 0);
1516 afs_global_ucredp->cr_ngroups = (unsigned long)st;
1517 for (i = st; i < NGROUPS; i++) {
1518 afs_global_ucredp->cr_groups[i] = NOGROUP;
1522 * Initialize the global process structure
1524 afs_global_procp = (struct usr_proc *)
1525 afs_osi_Alloc(sizeof(struct usr_proc));
1526 usr_assert(afs_global_procp != NULL);
1527 afs_global_procp->p_pid = getpid();
1528 afs_global_procp->p_ppid = (pid_t) 1;
1529 afs_global_procp->p_ucred = afs_global_ucredp;
1532 * Initialize the AFS mount point, default is '/afs'.
1533 * Strip duplicate/trailing slashes from mount point string.
1534 * afs_mountDirLen is set to strlen(afs_mountDir).
1536 if (mountDirParam) {
1537 sprintf(tbuffer, "%s", mountDirParam);
1539 sprintf(tbuffer, "afs");
1541 afs_mountDir[0] = '/';
1542 afs_mountDirLen = 1;
1543 for (lastchar = '/', p = &tbuffer[0]; *p != '\0'; p++) {
1544 if (lastchar != '/' || *p != '/') {
1545 afs_mountDir[afs_mountDirLen++] = lastchar = *p;
1548 if (lastchar == '/' && afs_mountDirLen > 1)
1550 afs_mountDir[afs_mountDirLen] = '\0';
1551 usr_assert(afs_mountDirLen > 1);
1554 * Initialize cache parameters using the input arguments
1557 cacheBlocks = cacheBlocksParam;
1558 if (cacheFilesParam != 0) {
1559 cacheFiles = cacheFilesParam;
1561 cacheFiles = cacheBlocks / 10;
1563 if (cacheStatEntriesParam != 0) {
1564 cacheStatEntries = cacheStatEntriesParam;
1566 strcpy(cacheBaseDir, cacheBaseDirParam);
1567 if (nDaemons != 0) {
1568 nDaemons = nDaemonsParam;
1572 afsd_verbose = debugParam;
1573 afsd_debug = debugParam;
1574 chunkSize = chunkSizeParam;
1575 if (dCacheSizeParam != 0) {
1576 dCacheSize = dCacheSizeParam;
1578 dCacheSize = cacheFiles / 2;
1580 if (vCacheSizeParam != 0) {
1581 vCacheSize = vCacheSizeParam;
1583 strcpy(confDir, confDirParam);
1584 afsd_CloseSynch = closeSynchParam;
1585 if (cacheFlagsParam >= 0) {
1586 cacheFlags = cacheFlagsParam;
1588 if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
1589 cacheFiles = dCacheSize;
1592 sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
1593 if (logFile == NULL) {
1594 sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE);
1596 strcpy(fullpn_AFSLogFile, logFile);
1599 printf("\n%s: Initializing user space AFS client\n\n", rn);
1600 printf(" mountDir: %s\n", afs_mountDir);
1601 printf(" confDir: %s\n", confDir);
1602 printf(" cacheBaseDir: %s\n", cacheBaseDir);
1603 printf(" cacheBlocks: %d\n", cacheBlocks);
1604 printf(" cacheFiles: %d\n", cacheFiles);
1605 printf(" cacheStatEntries: %d\n", cacheStatEntries);
1606 printf(" dCacheSize: %d\n", dCacheSize);
1607 printf(" vCacheSize: %d\n", vCacheSize);
1608 printf(" chunkSize: %d\n", chunkSize);
1609 printf(" afsd_CloseSynch: %d\n", afsd_CloseSynch);
1610 printf(" afsd_debug/verbose: %d/%d\n", afsd_debug, afsd_verbose);
1611 printf(" nDaemons: %d\n", nDaemons);
1612 printf(" cacheFlags: %d\n", cacheFlags);
1613 printf(" logFile: %s\n", fullpn_AFSLogFile);
1618 * Initialize the AFS client
1623 * Pull out all the configuration info for the workstation's AFS cache and
1624 * the cellular community we're willing to let our users see.
1626 afs_cdir = afsconf_Open(confDir);
1628 printf("afsd: some file missing or bad in %s\n", confDir);
1633 afsconf_GetLocalCell(afs_cdir, afs_LclCellName,
1634 sizeof(afs_LclCellName));
1636 printf("%s: Can't get my home cell name! [Error is %d]\n", rn,
1640 printf("%s: My home cell is '%s'\n", rn, afs_LclCellName);
1644 * Set the primary cell name.
1646 call_syscall(AFSOP_SET_THISCELL, (long)afs_LclCellName, 0, 0, 0, 0);
1648 if ((logfd = fopen(fullpn_AFSLogFile, "r+")) == 0) {
1650 printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile);
1651 if (CreateCacheFile(fullpn_AFSLogFile)) {
1653 ("%s: Can't create '%s' (You may want to use the -logfile option)\n",
1654 rn, fullpn_AFSLogFile);
1661 * Create and zero the pathname table for the desired cache files.
1663 pathname_for_V = (char **)afs_osi_Alloc(cacheFiles * sizeof(char *));
1664 if (pathname_for_V == NULL) {
1665 printf("%s: malloc() failed for cache file table with %d entries.\n",
1669 memset(pathname_for_V, 0, (cacheFiles * sizeof(char *)));
1671 printf("%s: %d pathname_for_V entries at 0x%x, %d bytes\n", rn,
1672 cacheFiles, pathname_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
1675 * Set up all the pathnames we'll need for later.
1677 sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
1678 sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
1679 sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
1680 sprintf(fullpn_VFile, "%s/V", cacheBaseDir);
1681 vFileNumber = fullpn_VFile + strlen(fullpn_VFile);
1684 * Start the RX listener.
1687 printf("%s: Calling AFSOP_RXLISTENER_DAEMON\n", rn);
1688 fork_syscall(AFSCALL_CALL, AFSOP_RXLISTENER_DAEMON, FALSE, FALSE, FALSE);
1691 * Start the RX event handler.
1694 printf("%s: Calling AFSOP_RXEVENT_DAEMON\n", rn);
1695 fork_syscall(AFSCALL_CALL, AFSOP_RXEVENT_DAEMON, FALSE);
1698 * Set up all the kernel processes needed for AFS.
1701 /* initialize AFS callback interface */
1703 /* parse multihomed address files */
1705 st = parseNetFiles(buffer, maskbuffer, mtubuffer, MAXIPADDRS, reason,
1706 AFSDIR_CLIENT_NETINFO_FILEPATH,
1707 AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
1709 call_syscall(AFSCALL_CALL, AFSOP_ADVISEADDR, st,
1710 (long)(&buffer[0]), (long)(&maskbuffer[0]),
1711 (long)(&mtubuffer[0]));
1713 printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
1720 printf("%s: Forking rx callback listener.\n", rn);
1722 if (preallocs < cacheStatEntries + 50)
1723 preallocs = cacheStatEntries + 50;
1724 fork_syscall(AFSCALL_CALL, AFSOP_START_RXCALLBACK, preallocs);
1727 printf("%s: Initializing AFS daemon.\n", rn);
1728 call_syscall(AFSCALL_CALL, AFSOP_BASIC_INIT, 1, 0, 0, 0);
1731 * Tell the kernel some basic information about the workstation's cache.
1734 printf("%s: Calling AFSOP_CACHEINIT: %d stat cache entries,"
1735 " %d optimum cache files, %d blocks in the cache,"
1736 " flags = 0x%x, dcache entries %d\n", rn, cacheStatEntries,
1737 cacheFiles, cacheBlocks, cacheFlags, dCacheSize);
1738 memset(&cparams, 0, sizeof(cparams));
1739 cparams.cacheScaches = cacheStatEntries;
1740 cparams.cacheFiles = cacheFiles;
1741 cparams.cacheBlocks = cacheBlocks;
1742 cparams.cacheDcaches = dCacheSize;
1743 cparams.cacheVolumes = vCacheSize;
1744 cparams.chunkSize = chunkSize;
1745 cparams.setTimeFlag = FALSE;
1746 cparams.memCacheFlag = cacheFlags;
1747 call_syscall(AFSCALL_CALL, AFSOP_CACHEINIT, (long)&cparams, 0, 0, 0);
1748 if (afsd_CloseSynch)
1749 call_syscall(AFSCALL_CALL, AFSOP_CLOSEWAIT, 0, 0, 0, 0);
1752 * Sweep the workstation AFS cache directory, remembering the inodes of
1753 * valid files and deleting extraneous files. Keep sweeping until we
1754 * have the right number of data cache files or we've swept too many
1758 printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
1760 /* Memory-cache based system doesn't need any of this */
1761 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
1764 if (SweepAFSCache(&vFilesFound)) {
1765 printf("%s: Error on sweep %d of workstation AFS cache \
1766 directory.\n", rn, cacheIteration);
1771 ("%s: %d out of %d data cache files found in sweep %d.\n",
1772 rn, vFilesFound, cacheFiles, cacheIteration);
1773 } while ((vFilesFound < cacheFiles)
1774 && (cacheIteration < MAX_CACHE_LOOPS));
1775 } else if (afsd_verbose)
1776 printf("%s: Using memory cache, not swept\n", rn);
1779 * Pass the kernel the name of the workstation cache file holding the
1783 printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
1785 /* once again, meaningless for a memory-based cache. */
1786 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
1787 call_syscall(AFSCALL_CALL, AFSOP_CACHEINFO, (long)fullpn_DCacheFile,
1790 call_syscall(AFSCALL_CALL, AFSOP_CELLINFO, (long)fullpn_CellInfoFile, 0,
1794 * Pass the kernel the name of the workstation cache file holding the
1795 * volume information.
1798 printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
1799 fullpn_VolInfoFile);
1800 call_syscall(AFSCALL_CALL, AFSOP_VOLUMEINFO, (long)fullpn_VolInfoFile, 0,
1804 * Pass the kernel the name of the afs logging file holding the volume
1808 printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n", rn,
1810 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
1811 call_syscall(AFSCALL_CALL, AFSOP_AFSLOG, (long)fullpn_AFSLogFile, 0,
1815 * Tell the kernel about each cell in the configuration.
1817 afsconf_CellApply(afs_cdir, ConfigCell, NULL);
1818 afsconf_CellAliasApply(afs_cdir, ConfigCellAlias, NULL);
1821 printf("%s: Forking AFS daemon.\n", rn);
1822 fork_syscall(AFSCALL_CALL, AFSOP_START_AFS);
1825 printf("%s: Forking check server daemon.\n", rn);
1826 fork_syscall(AFSCALL_CALL, AFSOP_START_CS);
1829 printf("%s: Forking %d background daemons.\n", rn, nDaemons);
1830 for (i = 0; i < nDaemons; i++) {
1831 fork_syscall(AFSCALL_CALL, AFSOP_START_BKG);
1835 printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn, rootVolume);
1836 call_syscall(AFSCALL_CALL, AFSOP_ROOTVOLUME, (long)rootVolume, 0, 0, 0);
1839 * Give the kernel the names of the AFS files cached on the workstation's
1844 ("%s: Calling AFSOP_CACHEFILES for each of the %d files in '%s'\n",
1845 rn, cacheFiles, cacheBaseDir);
1846 if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
1847 for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
1848 call_syscall(AFSCALL_CALL, AFSOP_CACHEFILE,
1849 (long)pathname_for_V[currVFile], 0, 0, 0);
1852 #ifndef NETSCAPE_NSAPI
1854 * Copy our tokens from the kernel to the user space client
1856 for (i = 0; i < 200; i++) {
1858 * Get the i'th token from the kernel
1860 memset((void *)&tbuffer[0], 0, sizeof(tbuffer));
1861 memcpy((void *)&tbuffer[0], (void *)&i, sizeof(int));
1863 iob.in_size = sizeof(int);
1865 iob.out_size = sizeof(tbuffer);
1867 #if defined(AFS_USR_SUN5_ENV) || defined(AFS_USR_OSF_ENV) || defined(AFS_USR_HPUX_ENV) || defined(AFS_USR_LINUX22_ENV) || defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
1868 rc = syscall(AFS_SYSCALL, AFSCALL_PIOCTL, 0, _VICEIOCTL(8), &iob, 0);
1869 #elif defined(AFS_USR_SGI_ENV)
1870 rc = syscall(AFS_PIOCTL, 0, _VICEIOCTL(8), &iob, 0);
1871 #else /* AFS_USR_AIX_ENV */
1872 rc = lpioctl(0, _VICEIOCTL(8), &iob, 0);
1875 usr_assert(errno == EDOM || errno == ENOSYS);
1880 * Now pass the token into the user space kernel
1882 rc = uafs_SetTokens(tbuffer, iob.out_size);
1883 usr_assert(rc == 0);
1885 #endif /* !NETSCAPE_NSAPI */
1888 * All the necessary info has been passed into the kernel to run an AFS
1889 * system. Give the kernel our go-ahead.
1892 printf("%s: Calling AFSOP_GO\n", rn);
1893 call_syscall(AFSCALL_CALL, AFSOP_GO, FALSE, 0, 0, 0);
1896 * At this point, we have finished passing the kernel all the info
1897 * it needs to set up the AFS. Mount the AFS root.
1899 printf("%s: All AFS daemons started.\n", rn);
1902 printf("%s: Forking trunc-cache daemon.\n", rn);
1903 fork_syscall(AFSCALL_CALL, AFSOP_START_TRUNCDAEMON);
1906 * Mount the AFS filesystem
1909 rc = afs_mount(&afs_RootVfs, NULL, NULL);
1910 usr_assert(rc == 0);
1911 rc = afs_root(&afs_RootVfs, &afs_RootVnode);
1912 usr_assert(rc == 0);
1916 * initialize the current directory to the AFS root
1918 afs_CurrentDir = afs_RootVnode;
1919 VN_HOLD(afs_CurrentDir);
1932 VN_RELE(afs_CurrentDir);
1933 rc = afs_unmount(&afs_RootVfs);
1934 usr_assert(rc == 0);
1941 * Donate the current thread to the RX server pool.
1944 uafs_RxServerProc(void)
1948 struct rx_call *newcall = NULL;
1950 rxi_MorePackets(2); /* alloc more packets */
1951 threadID = rxi_availProcs++;
1954 sock = OSI_NULLSOCKET;
1955 rxi_ServerProc(threadID, newcall, &sock);
1956 if (sock == OSI_NULLSOCKET) {
1961 rxi_ListenerProc(sock, &threadID, &newcall);
1962 /* assert(threadID != -1); */
1963 /* assert(newcall != NULL); */
1967 struct syscallThreadArgs {
1976 #ifdef NETSCAPE_NSAPI
1978 syscallThread(void *argp)
1979 #else /* NETSCAPE_NSAPI */
1981 syscallThread(void *argp)
1982 #endif /* NETSCAPE_NSAPI */
1985 struct usr_ucred *crp;
1986 struct syscallThreadArgs *sysArgsP = (struct syscallThreadArgs *)argp;
1989 * AFS daemons run authenticated
1991 u.u_viceid = getuid();
1993 crp->cr_uid = getuid();
1994 crp->cr_ruid = getuid();
1995 crp->cr_suid = getuid();
1996 crp->cr_groups[0] = getgid();
1997 crp->cr_ngroups = 1;
1998 for (i = 1; i < NGROUPS; i++) {
1999 crp->cr_groups[i] = NOGROUP;
2002 call_syscall(sysArgsP->syscall, sysArgsP->afscall, sysArgsP->param1,
2003 sysArgsP->param2, sysArgsP->param3, sysArgsP->param4);
2005 afs_osi_Free(argp, -1);
2008 fork_syscall(syscall, afscall, param1, param2, param3, param4)
2009 long syscall, afscall, param1, param2, param3, param4;
2012 struct syscallThreadArgs *sysArgsP;
2014 sysArgsP = (struct syscallThreadArgs *)
2015 afs_osi_Alloc(sizeof(struct syscallThreadArgs));
2016 usr_assert(sysArgsP != NULL);
2017 sysArgsP->syscall = syscall;
2018 sysArgsP->afscall = afscall;
2019 sysArgsP->param1 = param1;
2020 sysArgsP->param2 = param2;
2021 sysArgsP->param3 = param3;
2022 sysArgsP->param4 = param4;
2024 usr_thread_create(&tid, syscallThread, sysArgsP);
2025 usr_thread_detach(tid);
2028 call_syscall(syscall, afscall, param1, param2, param3, param4)
2029 long syscall, afscall, param1, param2, param3, param4;
2041 a.syscall = syscall;
2042 a.afscall = afscall;
2049 u.u_ap = (char *)&a;
2051 code = Afs_syscall();
2056 uafs_SetTokens(char *tbuffer, int tlen)
2059 struct afs_ioctl iob;
2064 iob.out = &outbuf[0];
2065 iob.out_size = sizeof(outbuf);
2066 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(3), (long)&iob, 0, 0);
2075 uafs_RPCStatsEnableProc(void)
2078 struct afs_ioctl iob;
2081 flag = AFSCALL_RXSTATS_ENABLE;
2082 iob.in = (char *)&flag;
2083 iob.in_size = sizeof(afs_int32);
2086 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(53), (long)&iob, 0, 0);
2095 uafs_RPCStatsDisableProc(void)
2098 struct afs_ioctl iob;
2101 flag = AFSCALL_RXSTATS_DISABLE;
2102 iob.in = (char *)&flag;
2103 iob.in_size = sizeof(afs_int32);
2106 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(53), (long)&iob, 0, 0);
2115 uafs_RPCStatsClearProc(void)
2118 struct afs_ioctl iob;
2121 flag = AFSCALL_RXSTATS_CLEAR;
2122 iob.in = (char *)&flag;
2123 iob.in_size = sizeof(afs_int32);
2126 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(53), (long)&iob, 0, 0);
2135 uafs_RPCStatsEnablePeer(void)
2138 struct afs_ioctl iob;
2141 flag = AFSCALL_RXSTATS_ENABLE;
2142 iob.in = (char *)&flag;
2143 iob.in_size = sizeof(afs_int32);
2146 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(54), (long)&iob, 0, 0);
2155 uafs_RPCStatsDisablePeer(void)
2158 struct afs_ioctl iob;
2161 flag = AFSCALL_RXSTATS_DISABLE;
2162 iob.in = (char *)&flag;
2163 iob.in_size = sizeof(afs_int32);
2166 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(54), (long)&iob, 0, 0);
2175 uafs_RPCStatsClearPeer(void)
2178 struct afs_ioctl iob;
2181 flag = AFSCALL_RXSTATS_CLEAR;
2182 iob.in = (char *)&flag;
2183 iob.in_size = sizeof(afs_int32);
2186 rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(54), (long)&iob, 0, 0);
2195 * Lookup a file or directory given its path.
2196 * Call VN_HOLD on the output vnode if successful.
2197 * Returns zero on success, error code on failure.
2199 * Note: Caller must hold the AFS global lock.
2202 uafs_LookupName(char *path, struct usr_vnode *parentVp,
2203 struct usr_vnode **vpp, int follow, int no_eval_mtpt)
2207 struct usr_vnode *vp;
2208 struct usr_vnode *nextVp;
2209 struct usr_vnode *linkVp;
2217 * Absolute paths must start with the AFS mount point.
2219 if (path[0] != '/') {
2222 path = uafs_afsPathName(path);
2230 * Loop through the path looking for the new directory
2232 tmpPath = afs_osi_Alloc(strlen(path) + 1);
2233 usr_assert(tmpPath != NULL);
2234 strcpy(tmpPath, path);
2237 while (pathP != NULL && *pathP != '\0') {
2238 usr_assert(*pathP != '/');
2241 * terminate the current component and skip over slashes
2243 nextPathP = afs_strchr(pathP, '/');
2244 if (nextPathP != NULL) {
2245 while (*nextPathP == '/') {
2246 *(nextPathP++) = '\0';
2251 * Don't call afs_lookup on non-directories
2253 if (vp->v_type != VDIR) {
2255 afs_osi_Free(tmpPath, strlen(path) + 1);
2259 if (vp == afs_RootVnode && strcmp(pathP, "..") == 0) {
2261 * The AFS root is its own parent
2263 nextVp = afs_RootVnode;
2266 * We need execute permission to search a directory
2268 code = afs_access(vp, VEXEC, u.u_cred);
2271 afs_osi_Free(tmpPath, strlen(path) + 1);
2276 * lookup the next component in the path, we can release the
2277 * subdirectory since we hold the global lock
2280 #ifdef AFS_WEB_ENHANCEMENTS
2281 if ((nextPathP != NULL && *nextPathP != '\0') || !no_eval_mtpt)
2282 code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0);
2285 afs_lookup(vp, pathP, &nextVp, u.u_cred,
2288 code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0);
2289 #endif /* AFS_WEB_ENHANCEMENTS */
2292 afs_osi_Free(tmpPath, strlen(path) + 1);
2298 * Follow symbolic links for parent directories and
2299 * for leaves when the follow flag is set.
2301 if ((nextPathP != NULL && *nextPathP != '\0') || follow) {
2303 while (nextVp->v_type == VLNK) {
2304 if (++linkCount > MAX_OSI_LINKS) {
2307 afs_osi_Free(tmpPath, strlen(path) + 1);
2310 code = uafs_LookupLink(nextVp, vp, &linkVp);
2314 afs_osi_Free(tmpPath, strlen(path) + 1);
2328 * Special case, nextPathP is non-null if pathname ends in slash
2330 if (nextPathP != NULL && vp->v_type != VDIR) {
2332 afs_osi_Free(tmpPath, strlen(path) + 1);
2336 afs_osi_Free(tmpPath, strlen(path) + 1);
2342 * Lookup the target of a symbolic link
2343 * Call VN_HOLD on the output vnode if successful.
2344 * Returns zero on success, error code on failure.
2346 * Note: Caller must hold the AFS global lock.
2349 uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp,
2350 struct usr_vnode **vpp)
2355 struct usr_vnode *linkVp;
2357 struct iovec iov[1];
2361 pathP = afs_osi_Alloc(MAX_OSI_PATH + 1);
2362 usr_assert(pathP != NULL);
2365 * set up the uio buffer
2367 iov[0].iov_base = pathP;
2368 iov[0].iov_len = MAX_OSI_PATH + 1;
2369 uio.uio_iov = &iov[0];
2373 uio.uio_fmode = FREAD;
2374 uio.uio_resid = MAX_OSI_PATH + 1;
2377 * Read the link data
2379 code = afs_readlink(vp, &uio, u.u_cred);
2381 afs_osi_Free(pathP, MAX_OSI_PATH + 1);
2384 len = MAX_OSI_PATH + 1 - uio.uio_resid;
2388 * Find the target of the symbolic link
2390 code = uafs_LookupName(pathP, parentVp, &linkVp, 1, 0);
2392 afs_osi_Free(pathP, MAX_OSI_PATH + 1);
2396 afs_osi_Free(pathP, MAX_OSI_PATH + 1);
2402 * Lookup the parent of a file or directory given its path
2403 * Call VN_HOLD on the output vnode if successful.
2404 * Returns zero on success, error code on failure.
2406 * Note: Caller must hold the AFS global lock.
2409 uafs_LookupParent(char *path, struct usr_vnode **vpp)
2414 struct usr_vnode *parentP;
2419 * Absolute path names must start with the AFS mount point.
2422 pathP = uafs_afsPathName(path);
2423 if (pathP == NULL) {
2429 * Find the length of the parent path
2432 while (len > 0 && path[len - 1] == '/') {
2438 while (len > 0 && path[len - 1] != '/') {
2445 pathP = afs_osi_Alloc(len);
2446 usr_assert(pathP != NULL);
2447 memcpy(pathP, path, len - 1);
2448 pathP[len - 1] = '\0';
2451 * look up the parent
2453 code = uafs_LookupName(pathP, afs_CurrentDir, &parentP, 1, 0);
2454 afs_osi_Free(pathP, len);
2458 if (parentP->v_type != VDIR) {
2468 * Return a pointer to the first character in the last component
2472 uafs_LastPath(char *path)
2477 while (len > 0 && path[len - 1] == '/') {
2480 while (len > 0 && path[len - 1] != '/') {
2490 * Set the working directory.
2493 uafs_chdir(char *path)
2497 retval = uafs_chdir_r(path);
2503 uafs_chdir_r(char *path)
2508 code = uafs_LookupName(path, afs_CurrentDir, &dirP, 1, 0);
2513 if (dirP->v_type != VDIR) {
2518 VN_RELE(afs_CurrentDir);
2519 afs_CurrentDir = dirP;
2524 * Create a directory.
2527 uafs_mkdir(char *path, int mode)
2531 retval = uafs_mkdir_r(path, mode);
2537 uafs_mkdir_r(char *path, int mode)
2541 struct vnode *parentP;
2543 struct usr_vattr attrs;
2545 if (uafs_IsRoot(path)) {
2550 * Look up the parent directory.
2552 nameP = uafs_LastPath(path);
2553 if (nameP != NULL) {
2554 code = uafs_LookupParent(path, &parentP);
2560 parentP = afs_CurrentDir;
2566 * Make sure the directory has at least one character
2568 if (*nameP == '\0') {
2575 * Create the directory
2577 usr_vattr_null(&attrs);
2578 attrs.va_type = VREG;
2579 attrs.va_mode = mode;
2580 attrs.va_uid = u.u_cred->cr_uid;
2581 attrs.va_gid = u.u_cred->cr_gid;
2583 code = afs_mkdir(parentP, nameP, &attrs, &dirP, u.u_cred);
2594 * Return 1 if path is the AFS root, otherwise return 0
2597 uafs_IsRoot(char *path)
2599 while (*path == '/' && *(path + 1) == '/') {
2602 if (strncmp(path, afs_mountDir, afs_mountDirLen) != 0) {
2605 path += afs_mountDirLen;
2606 while (*path == '/') {
2609 if (*path != '\0') {
2617 * Note: file name may not end in a slash.
2620 uafs_open(char *path, int flags, int mode)
2624 retval = uafs_open_r(path, flags, mode);
2630 uafs_open_r(char *path, int flags, int mode)
2636 struct usr_vnode *fileP;
2637 struct usr_vnode *dirP;
2638 struct usr_vattr attrs;
2641 if (uafs_IsRoot(path)) {
2642 fileP = afs_RootVnode;
2646 * Look up the parent directory.
2648 nameP = uafs_LastPath(path);
2649 if (nameP != NULL) {
2650 code = uafs_LookupParent(path, &dirP);
2656 dirP = afs_CurrentDir;
2662 * Make sure the filename has at least one character
2664 if (*nameP == '\0') {
2671 * Get the VNODE for this file
2673 if (flags & O_CREAT) {
2674 usr_vattr_null(&attrs);
2675 attrs.va_type = VREG;
2676 attrs.va_mode = mode;
2677 attrs.va_uid = u.u_cred->cr_uid;
2678 attrs.va_gid = u.u_cred->cr_gid;
2679 if (flags & O_TRUNC) {
2684 afs_create(dirP, nameP, &attrs,
2685 (flags & O_EXCL) ? usr_EXCL : usr_NONEXCL, mode,
2694 code = uafs_LookupName(nameP, dirP, &fileP, 1, 0);
2702 * Check whether we have access to this file
2705 if (flags & (O_RDONLY | O_RDWR)) {
2708 if (flags & (O_WRONLY | O_RDWR)) {
2712 fileMode = VREAD; /* since O_RDONLY is 0 */
2713 code = afs_access(fileP, fileMode, u.u_cred);
2721 * Get the file attributes, all we need is the size
2723 code = afs_getattr(fileP, &attrs, u.u_cred);
2733 * Setup the open flags
2736 if (flags & O_TRUNC) {
2737 openFlags |= FTRUNC;
2739 if (flags & O_APPEND) {
2740 openFlags |= FAPPEND;
2742 if (flags & O_SYNC) {
2745 if (flags & O_SYNC) {
2748 if (flags & (O_RDONLY | O_RDWR)) {
2751 if (flags & (O_WRONLY | O_RDWR)) {
2752 openFlags |= FWRITE;
2756 * Truncate if necessary
2758 if ((flags & O_TRUNC) && (attrs.va_size != 0)) {
2759 usr_vattr_null(&attrs);
2761 code = afs_setattr(fileP, &attrs, u.u_cred);
2772 code = afs_open(&fileP, openFlags, u.u_cred);
2780 * Put the vnode pointer into the file table
2782 for (fd = 0; fd < MAX_OSI_FILES; fd++) {
2783 if (afs_FileTable[fd] == NULL) {
2784 afs_FileTable[fd] = fileP;
2785 afs_FileFlags[fd] = openFlags;
2786 if (flags & O_APPEND) {
2787 afs_FileOffsets[fd] = attrs.va_size;
2789 afs_FileOffsets[fd] = 0;
2794 if (fd == MAX_OSI_FILES) {
2807 uafs_creat(char *path, int mode)
2810 rc = uafs_open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
2815 uafs_creat_r(char *path, int mode)
2818 rc = uafs_open_r(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
2826 uafs_write(int fd, char *buf, int len)
2830 retval = uafs_write_r(fd, buf, len);
2836 uafs_write_r(int fd, char *buf, int len)
2840 struct iovec iov[1];
2841 struct usr_vnode *fileP;
2844 * Make sure this is an open file
2846 fileP = afs_FileTable[fd];
2847 if (fileP == NULL) {
2853 * set up the uio buffer
2855 iov[0].iov_base = buf;
2856 iov[0].iov_len = len;
2857 uio.uio_iov = &iov[0];
2859 uio.uio_offset = afs_FileOffsets[fd];
2861 uio.uio_fmode = FWRITE;
2862 uio.uio_resid = len;
2868 code = afs_write(fileP, &uio, afs_FileFlags[fd], u.u_cred, 0);
2874 afs_FileOffsets[fd] = uio.uio_offset;
2875 return (len - uio.uio_resid);
2882 uafs_read(int fd, char *buf, int len)
2886 retval = uafs_read_r(fd, buf, len);
2892 uafs_read_r(int fd, char *buf, int len)
2896 struct iovec iov[1];
2897 struct usr_vnode *fileP;
2898 struct usr_buf *bufP;
2901 * Make sure this is an open file
2903 fileP = afs_FileTable[fd];
2904 if (fileP == NULL) {
2910 * set up the uio buffer
2912 iov[0].iov_base = buf;
2913 iov[0].iov_len = len;
2914 uio.uio_iov = &iov[0];
2916 uio.uio_offset = afs_FileOffsets[fd];
2918 uio.uio_fmode = FREAD;
2919 uio.uio_resid = len;
2924 code = afs_read(fileP, &uio, u.u_cred, 0, &bufP, 0);
2930 afs_FileOffsets[fd] = uio.uio_offset;
2931 return (len - uio.uio_resid);
2935 * Copy the attributes of a file into a stat structure.
2937 * NOTE: Caller must hold the global AFS lock.
2940 uafs_GetAttr(struct usr_vnode *vp, struct stat *stats)
2943 struct usr_vattr attrs;
2948 * Get the attributes
2950 code = afs_getattr(vp, &attrs, u.u_cred);
2956 * Copy the attributes, zero fields that aren't set
2958 memset((void *)stats, 0, sizeof(struct stat));
2960 stats->st_ino = attrs.va_nodeid;
2961 stats->st_mode = attrs.va_mode;
2962 stats->st_nlink = attrs.va_nlink;
2963 stats->st_uid = attrs.va_uid;
2964 stats->st_gid = attrs.va_gid;
2965 stats->st_rdev = attrs.va_rdev;
2966 stats->st_size = attrs.va_size;
2967 stats->st_atime = attrs.va_atime.tv_sec;
2968 stats->st_mtime = attrs.va_mtime.tv_sec;
2969 stats->st_ctime = attrs.va_ctime.tv_sec;
2970 stats->st_blksize = attrs.va_blocksize;
2971 stats->st_blocks = attrs.va_blocks;
2977 * Get the attributes of a file, do follow links
2980 uafs_stat(char *path, struct stat *buf)
2984 retval = uafs_stat_r(path, buf);
2990 uafs_stat_r(char *path, struct stat *buf)
2995 code = uafs_LookupName(path, afs_CurrentDir, &vp, 1, 0);
3000 code = uafs_GetAttr(vp, buf);
3010 * Get the attributes of a file, don't follow links
3013 uafs_lstat(char *path, struct stat *buf)
3017 retval = uafs_lstat_r(path, buf);
3023 uafs_lstat_r(char *path, struct stat *buf)
3028 code = uafs_LookupName(path, afs_CurrentDir, &vp, 0, 0);
3033 code = uafs_GetAttr(vp, buf);
3043 * Get the attributes of an open file
3046 uafs_fstat(int fd, struct stat *buf)
3050 retval = uafs_fstat_r(fd, buf);
3056 uafs_fstat_r(int fd, struct stat *buf)
3061 vp = afs_FileTable[fd];
3066 code = uafs_GetAttr(vp, buf);
3076 * change the permissions on a file
3079 uafs_chmod(char *path, int mode)
3083 retval = uafs_chmod_r(path, mode);
3089 uafs_chmod_r(char *path, int mode)
3093 struct usr_vattr attrs;
3095 code = uafs_LookupName(path, afs_CurrentDir, &vp, 1, 0);
3100 usr_vattr_null(&attrs);
3101 attrs.va_mode = mode;
3102 code = afs_setattr(vp, &attrs, u.u_cred);
3112 * change the permissions on an open file
3115 uafs_fchmod(int fd, int mode)
3119 retval = uafs_fchmod_r(fd, mode);
3125 uafs_fchmod_r(int fd, int mode)
3129 struct usr_vattr attrs;
3131 vp = afs_FileTable[fd];
3136 usr_vattr_null(&attrs);
3137 attrs.va_mode = mode;
3138 code = afs_setattr(vp, &attrs, u.u_cred);
3150 uafs_truncate(char *path, int length)
3154 retval = uafs_truncate_r(path, length);
3160 uafs_truncate_r(char *path, int length)
3164 struct usr_vattr attrs;
3166 code = uafs_LookupName(path, afs_CurrentDir, &vp, 1, 0);
3171 usr_vattr_null(&attrs);
3172 attrs.va_size = length;
3173 code = afs_setattr(vp, &attrs, u.u_cred);
3183 * truncate an open file
3186 uafs_ftruncate(int fd, int length)
3190 retval = uafs_ftruncate_r(fd, length);
3196 uafs_ftruncate_r(int fd, int length)
3200 struct usr_vattr attrs;
3202 vp = afs_FileTable[fd];
3207 usr_vattr_null(&attrs);
3208 attrs.va_size = length;
3209 code = afs_setattr(vp, &attrs, u.u_cred);
3218 * set the read/write file pointer of an open file
3221 uafs_lseek(int fd, int offset, int whence)
3225 retval = uafs_lseek_r(fd, offset, whence);
3231 uafs_lseek_r(int fd, int offset, int whence)
3235 struct usr_vattr attrs;
3236 struct usr_vnode *vp;
3238 vp = afs_FileTable[fd];
3245 newpos = afs_FileOffsets[fd] + offset;
3251 code = afs_getattr(vp, &attrs, u.u_cred);
3256 newpos = attrs.va_size + offset;
3266 afs_FileOffsets[fd] = newpos;
3278 retval = uafs_fsync_r(fd);
3284 uafs_fsync_r(int fd)
3287 struct usr_vnode *fileP;
3290 fileP = afs_FileTable[fd];
3291 if (fileP == NULL) {
3296 code = afs_fsync(fileP, u.u_cred);
3313 retval = uafs_close_r(fd);
3319 uafs_close_r(int fd)
3322 struct usr_vnode *fileP;
3324 fileP = afs_FileTable[fd];
3325 if (fileP == NULL) {
3329 afs_FileTable[fd] = NULL;
3331 code = afs_close(fileP, afs_FileFlags[fd], u.u_cred);
3342 * Create a hard link from the source to the target
3343 * Note: file names may not end in a slash.
3346 uafs_link(char *existing, char *new)
3350 retval = uafs_link_r(existing, new);
3356 uafs_link_r(char *existing, char *new)
3359 struct usr_vnode *existP;
3360 struct usr_vnode *dirP;
3363 if (uafs_IsRoot(new)) {
3368 * Look up the existing node.
3370 code = uafs_LookupName(existing, afs_CurrentDir, &existP, 1, 0);
3377 * Look up the parent directory.
3379 nameP = uafs_LastPath(new);
3380 if (nameP != NULL) {
3381 code = uafs_LookupParent(new, &dirP);
3388 dirP = afs_CurrentDir;
3394 * Make sure the filename has at least one character
3396 if (*nameP == '\0') {
3406 code = afs_link(existP, dirP, nameP, u.u_cred);
3417 * Create a symbolic link from the source to the target
3418 * Note: file names may not end in a slash.
3421 uafs_symlink(char *target, char *source)
3425 retval = uafs_symlink_r(target, source);
3431 uafs_symlink_r(char *target, char *source)
3434 struct usr_vnode *dirP;
3435 struct usr_vattr attrs;
3438 if (uafs_IsRoot(source)) {
3443 * Look up the parent directory.
3445 nameP = uafs_LastPath(source);
3446 if (nameP != NULL) {
3447 code = uafs_LookupParent(source, &dirP);
3453 dirP = afs_CurrentDir;
3459 * Make sure the filename has at least one character
3461 if (*nameP == '\0') {
3470 usr_vattr_null(&attrs);
3471 attrs.va_type = VLNK;
3472 attrs.va_mode = 0777;
3473 attrs.va_uid = u.u_cred->cr_uid;
3474 attrs.va_gid = u.u_cred->cr_gid;
3475 code = afs_symlink(dirP, nameP, &attrs, target, u.u_cred);
3485 * Read a symbolic link into the buffer
3488 uafs_readlink(char *path, char *buf, int len)
3492 retval = uafs_readlink_r(path, buf, len);
3498 uafs_readlink_r(char *path, char *buf, int len)
3501 struct usr_vnode *vp;
3503 struct iovec iov[1];
3505 code = uafs_LookupName(path, afs_CurrentDir, &vp, 0, 0);
3511 if (vp->v_type != VLNK) {
3518 * set up the uio buffer
3520 iov[0].iov_base = buf;
3521 iov[0].iov_len = len;
3522 uio.uio_iov = &iov[0];
3526 uio.uio_fmode = FREAD;
3527 uio.uio_resid = len;
3532 code = afs_readlink(vp, &uio, u.u_cred);
3540 * return the number of bytes read
3542 return (len - uio.uio_resid);
3546 * Remove a file (or directory)
3547 * Note: file name may not end in a slash.
3550 uafs_unlink(char *path)
3554 retval = uafs_unlink_r(path);
3560 uafs_unlink_r(char *path)
3564 struct usr_vnode *fileP;
3565 struct usr_vnode *dirP;
3568 if (uafs_IsRoot(path)) {
3573 * Look up the parent directory.
3575 nameP = uafs_LastPath(path);
3576 if (nameP != NULL) {
3577 code = uafs_LookupParent(path, &dirP);
3583 dirP = afs_CurrentDir;
3589 * Make sure the filename has at least one character
3591 if (*nameP == '\0') {
3600 code = afs_remove(dirP, nameP, u.u_cred);
3611 * Rename a file (or directory)
3614 uafs_rename(char *old, char *new)
3618 retval = uafs_rename_r(old, new);
3624 uafs_rename_r(char *old, char *new)
3629 struct usr_vnode *odirP;
3630 struct usr_vnode *ndirP;
3632 if (uafs_IsRoot(new)) {
3637 * Look up the parent directories.
3639 onameP = uafs_LastPath(old);
3640 if (onameP != NULL) {
3641 code = uafs_LookupParent(old, &odirP);
3647 odirP = afs_CurrentDir;
3651 nnameP = uafs_LastPath(new);
3652 if (nnameP != NULL) {
3653 code = uafs_LookupParent(new, &ndirP);
3659 ndirP = afs_CurrentDir;
3665 * Make sure the filename has at least one character
3667 if (*onameP == '\0' || *nnameP == '\0') {
3677 code = afs_rename(odirP, onameP, ndirP, nnameP, u.u_cred);
3689 * Remove a or directory
3690 * Note: file name may not end in a slash.
3693 uafs_rmdir(char *path)
3697 retval = uafs_rmdir_r(path);
3703 uafs_rmdir_r(char *path)
3707 struct usr_vnode *fileP;
3708 struct usr_vnode *dirP;
3711 if (uafs_IsRoot(path)) {
3716 * Look up the parent directory.
3718 nameP = uafs_LastPath(path);
3719 if (nameP != NULL) {
3720 code = uafs_LookupParent(path, &dirP);
3726 dirP = afs_CurrentDir;
3732 * Make sure the directory name has at least one character
3734 if (*nameP == '\0') {
3741 * Remove the directory
3743 code = afs_rmdir(dirP, nameP, u.u_cred);
3754 * Flush a file from the AFS cache
3757 uafs_FlushFile(char *path)
3760 struct afs_ioctl iob;
3768 call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(6), (long)&iob, 0,
3779 uafs_FlushFile_r(char *path)
3783 retval = uafs_FlushFile(path);
3792 uafs_opendir(char *path)
3796 retval = uafs_opendir_r(path);
3802 uafs_opendir_r(char *path)
3805 struct usr_vnode *fileP;
3809 * Open the directory for reading
3811 fd = uafs_open_r(path, O_RDONLY, 0);
3816 fileP = afs_FileTable[fd];
3817 if (fileP == NULL) {
3821 if (fileP->v_type != VDIR) {
3828 * Set up the directory structures
3831 (usr_DIR *) afs_osi_Alloc(sizeof(usr_DIR) + USR_DIRSIZE +
3832 sizeof(struct usr_dirent));
3833 usr_assert(dirp != NULL);
3834 dirp->dd_buf = (char *)(dirp + 1);
3844 * Read directory entries into a file system independent format.
3845 * This routine was developed to support AFS cache consistency testing.
3846 * You should use uafs_readdir instead.
3849 uafs_getdents(int fd, struct min_direct *buf, int len)
3853 retval = uafs_getdents_r(fd, buf, len);
3859 uafs_getdents_r(int fd, struct min_direct *buf, int len)
3863 struct usr_vnode *vp;
3864 struct iovec iov[1];
3867 * Make sure this is an open file
3869 vp = afs_FileTable[fd];
3877 * set up the uio buffer
3879 iov[0].iov_base = (char *)buf;
<