12 #include <WINNT/afsreg.h>
16 #ifdef AFS_FREELANCE_CLIENT
17 #include "cm_freelance.h"
19 #define STRSAFE_NO_DEPRECATE
22 extern void afsi_log(char *pattern, ...);
24 static unsigned int cm_noLocalMountPoints = 0;
25 char * cm_FakeRootDir = NULL;
26 int cm_fakeDirSize = 0;
27 int cm_fakeDirCallback=0;
28 int cm_fakeGettingCallback=0;
29 static cm_localMountPoint_t* cm_localMountPoints;
30 osi_mutex_t cm_Freelance_Lock;
31 static int cm_localMountPointChangeFlag = 0;
32 int cm_freelanceEnabled = 1;
33 int cm_freelanceImportCellServDB = 0;
34 time_t FakeFreelanceModTime = 0x3b49f6e2;
36 static int freelance_ShutdownFlag = 0;
37 static HANDLE hFreelanceChangeEvent = 0;
38 static HANDLE hFreelanceSymlinkChangeEvent = 0;
40 void cm_InitFakeRootDir();
42 void cm_FreelanceChangeNotifier(void * parmp) {
45 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
46 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance",
49 &hkFreelance) == ERROR_SUCCESS) {
51 hFreelanceChangeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
52 if (hFreelanceChangeEvent == NULL) {
53 RegCloseKey(hkFreelance);
59 /* check hFreelanceChangeEvent to see if it is set.
60 * if so, call cm_noteLocalMountPointChange()
62 if (RegNotifyChangeKeyValue( hkFreelance, /* hKey */
63 FALSE, /* bWatchSubtree */
64 REG_NOTIFY_CHANGE_LAST_SET, /* dwNotifyFilter */
65 hFreelanceChangeEvent, /* hEvent */
66 TRUE /* fAsynchronous */
68 RegCloseKey(hkFreelance);
69 CloseHandle(hFreelanceChangeEvent);
70 hFreelanceChangeEvent = 0;
74 if (WaitForSingleObject(hFreelanceChangeEvent, INFINITE) == WAIT_OBJECT_0)
76 if (freelance_ShutdownFlag == 1) {
77 RegCloseKey(hkFreelance);
78 CloseHandle(hFreelanceChangeEvent);
79 hFreelanceChangeEvent = 0;
82 cm_noteLocalMountPointChange(FALSE);
87 void cm_FreelanceSymlinkChangeNotifier(void * parmp) {
90 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
91 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance\\Symlinks",
94 &hkFreelance) == ERROR_SUCCESS) {
96 hFreelanceSymlinkChangeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
97 if (hFreelanceSymlinkChangeEvent == NULL) {
98 RegCloseKey(hkFreelance);
104 /* check hFreelanceSymlinkChangeEvent to see if it is set.
105 * if so, call cm_noteLocalMountPointSymlinkChange()
107 if (RegNotifyChangeKeyValue( hkFreelance, /* hKey */
108 FALSE, /* bWatchSubtree */
109 REG_NOTIFY_CHANGE_LAST_SET, /* dwNotifyFilter */
110 hFreelanceSymlinkChangeEvent, /* hEvent */
111 TRUE /* fAsynchronous */
112 ) != ERROR_SUCCESS) {
113 RegCloseKey(hkFreelance);
114 CloseHandle(hFreelanceSymlinkChangeEvent);
115 hFreelanceSymlinkChangeEvent = 0;
119 if (WaitForSingleObject(hFreelanceSymlinkChangeEvent, INFINITE) == WAIT_OBJECT_0)
121 if (freelance_ShutdownFlag == 1) {
122 RegCloseKey(hkFreelance);
123 CloseHandle(hFreelanceSymlinkChangeEvent);
124 hFreelanceSymlinkChangeEvent = 0;
127 cm_noteLocalMountPointChange(FALSE);
133 cm_FreelanceShutdown(void)
135 freelance_ShutdownFlag = 1;
136 if (hFreelanceChangeEvent != 0)
137 thrd_SetEvent(hFreelanceChangeEvent);
138 if (hFreelanceSymlinkChangeEvent != 0)
139 thrd_SetEvent(hFreelanceSymlinkChangeEvent);
143 cm_FreelanceAddCSDBMountPoints(void *rockp, char *cellNamep)
145 char szCellName[CELL_MAXNAMELEN+1] = ".";
147 cm_FsStrCpy( &szCellName[1], CELL_MAXNAMELEN, cellNamep);
148 /* create readonly mount point */
149 cm_FreelanceAddMount( cellNamep, cellNamep, "root.cell", 0, NULL);
151 /* create read/write mount point */
152 cm_FreelanceAddMount( szCellName, szCellName, "root.cell", 1, NULL);
158 cm_FreelanceImportCellServDB(void)
160 cm_EnumerateCellRegistry( TRUE, cm_FreelanceAddCSDBMountPoints, NULL);
161 cm_EnumerateCellFile( TRUE, cm_FreelanceAddCSDBMountPoints, NULL);
164 void cm_InitFreelance() {
168 lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock", LOCK_HIERARCHY_FREELANCE_GLOBAL);
170 lock_ObtainMutex(&cm_Freelance_Lock);
172 // yj: first we make a call to cm_initLocalMountPoints
173 // to read all the local mount points from the registry
174 cm_InitLocalMountPoints();
176 // then we make a call to InitFakeRootDir to create
177 // a fake root directory based on the local mount points
178 cm_InitFakeRootDir();
179 // --- end of yj code
180 lock_ReleaseMutex(&cm_Freelance_Lock);
182 /* Start the registry monitor */
183 phandle = thrd_Create(NULL, 65536, (ThreadFunc) cm_FreelanceChangeNotifier,
184 NULL, 0, &lpid, "cm_FreelanceChangeNotifier");
185 osi_assertx(phandle != NULL, "cm_FreelanceChangeNotifier thread create failure");
186 thrd_CloseHandle(phandle);
188 phandle = thrd_Create(NULL, 65536, (ThreadFunc) cm_FreelanceSymlinkChangeNotifier,
189 NULL, 0, &lpid, "cm_FreelanceSymlinkChangeNotifier");
190 osi_assertx(phandle != NULL, "cm_FreelanceSymlinkChangeNotifier thread create failure");
191 thrd_CloseHandle(phandle);
194 /* yj: Initialization of the fake root directory */
195 /* to be called while holding freelance lock. */
196 void cm_InitFakeRootDir() {
201 // allocate space for the fake info
202 cm_dirHeader_t fakeDirHeader;
203 cm_dirEntry_t fakeEntry;
204 cm_pageHeader_t fakePageHeader;
206 // i'm going to calculate how much space is needed for
207 // this fake root directory. we have these rules:
208 // 1. there are cm_noLocalMountPoints number of entries
209 // 2. each page is CM_DIR_PAGESIZE in size
210 // 3. the first 13 chunks of the first page are used for
212 // 4. the first chunk of all subsequent pages are used
213 // for page header stuff
214 // 5. a max of CM_DIR_EPP entries are allowed per page
215 // 6. each entry takes 1 or more chunks, depending on
216 // the size of the mount point string, as determined
218 // 7. each chunk is CM_DIR_CHUNKSIZE bytes
220 int CPP = CM_DIR_PAGESIZE / CM_DIR_CHUNKSIZE;
221 int curChunk = 13; // chunks 0 - 12 are used for header stuff
222 // of the first page in the directory
224 unsigned int curDirEntry = 0;
225 int curDirEntryInPage = 0;
229 /* Reserve 2 directory chunks for "." and ".." */
232 while (curDirEntry<cm_noLocalMountPoints) {
233 sizeOfCurEntry = cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0);
234 if ((curChunk + sizeOfCurEntry >= CPP) ||
235 (curDirEntryInPage + 1 >= CM_DIR_EPP)) {
237 curDirEntryInPage = 0;
240 curChunk += sizeOfCurEntry;
245 dirSize = (curPage+1) * CM_DIR_PAGESIZE;
246 if (cm_fakeDirSize != dirSize) {
248 free(cm_FakeRootDir);
249 cm_FakeRootDir = calloc(dirSize, 1);
250 cm_fakeDirSize = dirSize;
253 // yj: when we get here, we've figured out how much memory we need and
254 // allocated the appropriate space for it. we now prceed to fill
255 // it up with entries.
258 curDirEntryInPage = 0;
261 // fields in the directory entry that are unused.
263 fakeEntry.length = 0;
265 fakeEntry.fid.unique = htonl(1);
267 // the first page is special, it uses fakeDirHeader instead of fakePageHeader
268 // we fill up the page with dirEntries that belong there and we make changes
269 // to the fakeDirHeader.header.freeBitmap along the way. Then when we're done
270 // filling up the dirEntries in this page, we copy the fakeDirHeader into
271 // the top of the page.
273 // init the freeBitmap array
275 fakeDirHeader.header.freeBitmap[i]=0;
277 fakeDirHeader.header.freeBitmap[0] = 0xff;
278 fakeDirHeader.header.freeBitmap[1] = 0x7f;
281 // we start counting at 13 because the 0th to 12th chunks are used for header
284 // stick the first 2 entries "." and ".." in
285 fakeEntry.fid.vnode = htonl(1);
286 strcpy(fakeEntry.name, ".");
287 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
288 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
289 curChunk++; curDirEntryInPage++;
290 strcpy(fakeEntry.name, "..");
291 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
292 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
293 curChunk++; curDirEntryInPage++;
295 // keep putting stuff into page 0 if
296 // 1. we're not done with all entries
297 // 2. we have less than CM_DIR_EPP entries in page 0
298 // 3. we're not out of chunks in page 0
300 while( (curDirEntry<cm_noLocalMountPoints) &&
301 (curDirEntryInPage < CM_DIR_EPP) &&
302 (curChunk + cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0) <= CPP))
305 noChunks = cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0);
306 /* enforce the rule that only directories have odd vnode values */
307 fakeEntry.fid.vnode = htonl((curDirEntry + 1) * 2);
308 fakeEntry.fid.unique = htonl(curDirEntry + 1);
309 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
311 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
312 strcpy(currentPos + 12, (cm_localMountPoints+curDirEntry)->namep);
315 for (i=0; i<noChunks; i++) {
316 t1 = (curChunk + i) / 8;
317 t2 = curChunk + i - (t1*8);
318 fakeDirHeader.header.freeBitmap[t1] |= (1 << t2);
323 // when we get here, we're done with filling in the entries for page 0
324 // copy in the header info
326 memcpy(cm_FakeRootDir, &fakeDirHeader, 13 * CM_DIR_CHUNKSIZE);
330 // ok, page 0's done. Move on to the next page.
331 while (curDirEntry<cm_noLocalMountPoints) {
333 curChunk = 1; // the zeroth chunk is reserved for page header
334 curDirEntryInPage = 0;
335 for (i=0; i<8; i++) {
336 fakePageHeader.freeBitmap[i]=0;
338 fakePageHeader.freeCount = 0;
339 fakePageHeader.pgcount = 0;
340 fakePageHeader.tag = htons(1234);
342 // while we're on the same page...
343 while ( (curDirEntry<cm_noLocalMountPoints) &&
344 (curDirEntryInPage < CM_DIR_EPP) &&
345 (curChunk + cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0) <= CPP))
347 // add an entry to this page
349 noChunks = cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0);
350 /* enforce the rule that only directories have odd vnode values */
351 fakeEntry.fid.vnode = htonl((curDirEntry + 1) * 2);
352 fakeEntry.fid.unique = htonl(curDirEntry + 1);
353 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
354 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
355 strcpy(currentPos + 12, (cm_localMountPoints+curDirEntry)->namep);
358 for (i=0; i<noChunks; i++) {
359 t1 = (curChunk + i) / 8;
360 t2 = curChunk + i - (t1*8);
361 fakePageHeader.freeBitmap[t1] |= (1 << t2);
365 memcpy(cm_FakeRootDir + curPage * CM_DIR_PAGESIZE, &fakePageHeader, sizeof(fakePageHeader));
370 // we know the fakeDir is setup properly, so we claim that we have callback
371 osi_Log0(afsd_logp,"cm_InitFakeRootDir fakeDirCallback=1");
372 cm_fakeDirCallback=1;
374 // when we get here, we've set up everything! done!
377 int cm_FakeRootFid(cm_fid_t *fidp)
380 AFS_FAKE_ROOT_CELL_ID, /* root cell */
381 AFS_FAKE_ROOT_VOL_ID, /* root.afs ? */
386 /* called directly from ioctl */
387 /* called while not holding freelance lock */
388 int cm_noteLocalMountPointChange(afs_int32 locked) {
390 lock_ObtainMutex(&cm_Freelance_Lock);
391 cm_data.fakeDirVersion++;
392 cm_localMountPointChangeFlag = 1;
394 lock_ReleaseMutex(&cm_Freelance_Lock);
398 int cm_getLocalMountPointChange() {
399 return cm_localMountPointChangeFlag;
402 int cm_clearLocalMountPointChange() {
403 cm_localMountPointChangeFlag = 0;
407 int cm_reInitLocalMountPoints() {
409 unsigned int i, hash;
410 cm_scache_t *scp, **lscpp, *tscp;
412 osi_Log0(afsd_logp,"----- freelance reinitialization starts ----- ");
414 // first we invalidate all the SCPs that were created
415 // for the local mount points
417 osi_Log0(afsd_logp,"Invalidating local mount point scp... ");
419 lock_ObtainWrite(&cm_scacheLock);
420 lock_ObtainMutex(&cm_Freelance_Lock); /* always scache then freelance lock */
421 for (i=0; i<=cm_noLocalMountPoints; i++) {
423 cm_SetFid(&aFid, AFS_FAKE_ROOT_CELL_ID, AFS_FAKE_ROOT_VOL_ID, 1, 1);
425 cm_SetFid(&aFid, AFS_FAKE_ROOT_CELL_ID, AFS_FAKE_ROOT_VOL_ID, i*2, i);
426 hash = CM_SCACHE_HASH(&aFid);
427 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
428 if (scp != cm_data.rootSCachep && cm_FidCmp(&scp->fid, &aFid) == 0) {
429 // mark the scp to be reused
430 cm_HoldSCacheNoLock(scp);
431 lock_ReleaseMutex(&cm_Freelance_Lock);
432 lock_ReleaseWrite(&cm_scacheLock);
433 lock_ObtainWrite(&scp->rw);
434 cm_DiscardSCache(scp);
436 // take the scp out of the hash
437 lock_ObtainWrite(&cm_scacheLock);
438 for (lscpp = &cm_data.scacheHashTablep[hash], tscp = cm_data.scacheHashTablep[hash];
440 lscpp = &tscp->nextp, tscp = tscp->nextp) {
444 scp->flags &= ~CM_SCACHEFLAG_INHASH;
449 lock_ReleaseWrite(&scp->rw);
450 lock_ReleaseWrite(&cm_scacheLock);
451 cm_CallbackNotifyChange(scp);
452 lock_ObtainWrite(&cm_scacheLock);
453 cm_ReleaseSCacheNoLock(scp);
454 lock_ObtainMutex(&cm_Freelance_Lock);
458 lock_ReleaseWrite(&cm_scacheLock);
459 osi_Log0(afsd_logp,"\tall old scp cleared!");
461 // we must free the memory that was allocated in the prev
462 // cm_InitLocalMountPoints call
463 osi_Log0(afsd_logp,"Removing old localmountpoints... ");
464 free(cm_localMountPoints);
465 cm_localMountPoints = NULL;
466 cm_noLocalMountPoints = 0;
467 osi_Log0(afsd_logp,"\tall old localmountpoints cleared!");
469 // now re-init the localmountpoints
470 osi_Log0(afsd_logp,"Creating new localmountpoints... ");
471 cm_InitLocalMountPoints();
472 osi_Log0(afsd_logp,"\tcreated new set of localmountpoints!");
474 // then we re-create that dir
475 osi_Log0(afsd_logp,"Creating new fakedir... ");
476 cm_InitFakeRootDir();
477 osi_Log0(afsd_logp,"\t\tcreated new fakedir!");
479 lock_ReleaseMutex(&cm_Freelance_Lock);
481 osi_Log0(afsd_logp,"----- freelance reinit complete -----");
486 // yj: open up the registry and read all the local mount
487 // points that are stored there. Part of the initialization
488 // process for the freelance client.
489 /* to be called while holding freelance lock. */
490 long cm_InitLocalMountPoints() {
495 cm_localMountPoint_t* aLocalMountPoint;
498 char rootCellName[256];
499 HKEY hkFreelance = 0, hkFreelanceSymlinks = 0;
500 DWORD dwType, dwSize;
501 DWORD dwMountPoints = 0;
503 DWORD dwSymlinks = 0;
504 FILETIME ftLastWriteTime;
506 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
507 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance",
509 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
510 &hkFreelance) == ERROR_SUCCESS) {
512 RegQueryInfoKey( hkFreelance,
515 NULL, /* lpReserved */
516 NULL, /* lpcSubKeys */
517 NULL, /* lpcMaxSubKeyLen */
518 NULL, /* lpcMaxClassLen */
519 &dwMountPoints, /* lpcValues */
520 NULL, /* lpcMaxValueNameLen */
521 NULL, /* lpcMaxValueLen */
522 NULL, /* lpcbSecurityDescriptor */
523 &ftLastWriteTime /* lpftLastWriteTime */
526 cm_UnixTimeFromLargeSearchTime(&FakeFreelanceModTime, &ftLastWriteTime);
528 if ( dwMountPoints == 0 ) {
529 rootCellName[0] = '.';
530 code = cm_GetRootCellName(&rootCellName[1]);
532 lock_ReleaseMutex(&cm_Freelance_Lock);
533 cm_FreelanceAddMount(&rootCellName[1], &rootCellName[1], "root.cell.", 0, NULL);
534 cm_FreelanceAddMount(rootCellName, &rootCellName[1], "root.cell.", 1, NULL);
535 cm_FreelanceAddMount(".root", &rootCellName[1], "root.afs.", 1, NULL);
536 lock_ObtainMutex(&cm_Freelance_Lock);
541 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
542 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance\\Symlinks",
545 REG_OPTION_NON_VOLATILE,
546 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
548 &hkFreelanceSymlinks,
549 NULL) == ERROR_SUCCESS) {
551 RegQueryInfoKey( hkFreelanceSymlinks,
554 NULL, /* lpReserved */
555 NULL, /* lpcSubKeys */
556 NULL, /* lpcMaxSubKeyLen */
557 NULL, /* lpcMaxClassLen */
558 &dwSymlinks, /* lpcValues */
559 NULL, /* lpcMaxValueNameLen */
560 NULL, /* lpcMaxValueLen */
561 NULL, /* lpcbSecurityDescriptor */
562 NULL /* lpftLastWriteTime */
566 // get the number of entries there are from the first line
568 cm_noLocalMountPoints = dwMountPoints + dwSymlinks;
570 // create space to store the local mount points
571 cm_localMountPoints = malloc(sizeof(cm_localMountPoint_t) * cm_noLocalMountPoints);
572 aLocalMountPoint = cm_localMountPoints;
574 // now we read n lines and parse them into local mount points
575 // where n is the number of local mount points there are, as
577 // Each line in the ini file represents 1 local mount point and
578 // is in the format xxx#yyy:zzz, where xxx is the directory
579 // entry name, yyy is the cell name and zzz is the volume name.
580 // #yyy:zzz together make up the mount point.
581 for ( dwIndex = 0 ; dwIndex < dwMountPoints; dwIndex++ ) {
582 TCHAR szValueName[16];
583 DWORD dwValueSize = 16;
584 dwSize = sizeof(line);
585 if (RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
586 &dwType, line, &dwSize))
588 afsi_log("RegEnumValue(hkFreelance) failed");
589 cm_noLocalMountPoints--;
593 afsi_log("Mountpoint[%d] = %s",dwIndex, line);
595 /* find the trailing dot; null terminate after it */
596 t2 = strrchr(line, '.');
600 for ( t=line;*t;t++ ) {
601 if ( !isprint(*t) ) {
602 afsi_log("error occurred while parsing mountpoint entry [%d]: non-printable character", dwIndex);
603 fprintf(stderr, "error occurred while parsing mountpoint entry [%d]: non-printable character", dwIndex);
604 cm_noLocalMountPoints--;
609 // line is not empty, so let's parse it
610 t = strchr(line, '#');
612 t = strchr(line, '%');
613 // make sure that there is a '#' or '%' separator in the line
615 afsi_log("error occurred while parsing mountpoint entry [%d]: no # or %% separator", dwIndex);
616 fprintf(stderr, "error occurred while parsing mountpoint entry [%d]: no # or %% separator", dwIndex);
617 cm_noLocalMountPoints--;
621 aLocalMountPoint->fileType = CM_SCACHETYPE_MOUNTPOINT;
622 aLocalMountPoint->namep=malloc(t-line+1);
623 strncpy(aLocalMountPoint->namep, line, t-line);
624 aLocalMountPoint->namep[t-line] = '\0';
626 /* copy the mount point string */
627 aLocalMountPoint->mountPointStringp=malloc(strlen(t));
628 strncpy(aLocalMountPoint->mountPointStringp, t, strlen(t)-1);
629 aLocalMountPoint->mountPointStringp[strlen(t)-1] = '\0';
631 osi_Log2(afsd_logp,"found mount point: name %s, string %s",
632 osi_LogSaveString(afsd_logp,aLocalMountPoint->namep),
633 osi_LogSaveString(afsd_logp,aLocalMountPoint->mountPointStringp));
638 for ( dwIndex = 0 ; dwIndex < dwSymlinks; dwIndex++ ) {
639 TCHAR szValueName[16];
640 DWORD dwValueSize = 16;
641 dwSize = sizeof(line);
642 if (RegEnumValue( hkFreelanceSymlinks, dwIndex, szValueName, &dwValueSize, NULL,
643 &dwType, line, &dwSize))
645 afsi_log("RegEnumValue(hkFreelanceSymlinks) failed");
646 cm_noLocalMountPoints--;
650 afsi_log("Symlink[%d] = %s",dwIndex, line);
652 /* find the trailing dot; null terminate after it */
653 t2 = strrchr(line, '.');
657 for ( t=line;*t;t++ ) {
658 if ( !isprint(*t) ) {
659 afsi_log("error occurred while parsing symlink entry [%d]: non-printable character", dwIndex);
660 fprintf(stderr, "error occurred while parsing symlink entry [%d]: non-printable character", dwIndex);
661 cm_noLocalMountPoints--;
666 // line is not empty, so let's parse it
667 t = strchr(line, ':');
669 // make sure that there is a ':' separator in the line
671 afsi_log("error occurred while parsing symlink entry [%d]: no ':' separator", dwIndex);
672 fprintf(stderr, "error occurred while parsing symlink entry [%d]: no ':' separator", dwIndex);
673 cm_noLocalMountPoints--;
677 aLocalMountPoint->fileType = CM_SCACHETYPE_SYMLINK;
678 aLocalMountPoint->namep=malloc(t-line+1);
679 strncpy(aLocalMountPoint->namep, line, t-line);
680 aLocalMountPoint->namep[t-line] = '\0';
682 /* copy the symlink string */
683 aLocalMountPoint->mountPointStringp=malloc(strlen(t)-1);
684 strncpy(aLocalMountPoint->mountPointStringp, t+1, strlen(t)-2);
685 aLocalMountPoint->mountPointStringp[strlen(t)-2] = '\0';
687 osi_Log2(afsd_logp,"found symlink: name %s, string %s",
688 osi_LogSaveString(afsd_logp,aLocalMountPoint->namep),
689 osi_LogSaveString(afsd_logp,aLocalMountPoint->mountPointStringp));
694 if ( hkFreelanceSymlinks )
695 RegCloseKey( hkFreelanceSymlinks );
696 RegCloseKey(hkFreelance);
700 /* What follows is the old code to read freelance mount points
701 * out of a text file modified to copy the data into the registry
703 cm_GetConfigDir(hdir, sizeof(hdir));
704 strcat(hdir, AFS_FREELANCE_INI);
705 // open the ini file for reading
706 fp = fopen(hdir, "r");
708 /* look in the Windows directory where we used to store the file */
709 GetWindowsDirectory(hdir, sizeof(hdir));
711 strcat(hdir, AFS_FREELANCE_INI);
712 fp = fopen(hdir, "r");
715 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
716 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance",
719 REG_OPTION_NON_VOLATILE,
727 RegCloseKey(hkFreelance);
728 rootCellName[0] = '.';
729 code = cm_GetRootCellName(&rootCellName[1]);
731 lock_ReleaseMutex(&cm_Freelance_Lock);
732 cm_FreelanceAddMount(&rootCellName[1], &rootCellName[1], "root.cell.", 0, NULL);
733 cm_FreelanceAddMount(rootCellName, &rootCellName[1], "root.cell.", 1, NULL);
734 cm_FreelanceAddMount(".root", &rootCellName[1], "root.afs.", 1, NULL);
735 lock_ObtainMutex(&cm_Freelance_Lock);
740 // we successfully opened the file
741 osi_Log0(afsd_logp,"opened afs_freelance.ini");
743 // now we read the first line to see how many entries
745 fgets(line, sizeof(line), fp);
747 // if the line is empty at any point when we're reading
748 // we're screwed. report error and return.
750 afsi_log("error occurred while reading afs_freelance.ini");
751 fprintf(stderr, "error occurred while reading afs_freelance.ini");
755 // get the number of entries there are from the first line
757 cm_noLocalMountPoints = atoi(line);
759 if (cm_noLocalMountPoints > 0) {
760 // create space to store the local mount points
761 cm_localMountPoints = malloc(sizeof(cm_localMountPoint_t) * cm_noLocalMountPoints);
762 aLocalMountPoint = cm_localMountPoints;
765 // now we read n lines and parse them into local mount points
766 // where n is the number of local mount points there are, as
768 // Each line in the ini file represents 1 local mount point and
769 // is in the format xxx#yyy:zzz, where xxx is the directory
770 // entry name, yyy is the cell name and zzz is the volume name.
771 // #yyy:zzz together make up the mount point.
772 for (i=0; i<cm_noLocalMountPoints; i++) {
773 fgets(line, sizeof(line), fp);
774 // check that the line is not empty
776 afsi_log("error occurred while parsing entry in %s: empty line in line %d", AFS_FREELANCE_INI, i);
777 fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: empty line in line %d", i);
781 /* find the trailing dot; null terminate after it */
782 t2 = strrchr(line, '.');
788 /* we are migrating to the registry */
789 sprintf(szIndex,"%d",dwIndex++);
791 dwSize = (DWORD)strlen(line) + 1;
792 RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
795 // line is not empty, so let's parse it
796 t = strchr(line, '#');
798 t = strchr(line, '%');
799 // make sure that there is a '#' or '%' separator in the line
801 afsi_log("error occurred while parsing entry in %s: no # or %% separator in line %d", AFS_FREELANCE_INI, i);
802 fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: no # or %% separator in line %d", i);
805 aLocalMountPoint->namep=malloc(t-line+1);
806 memcpy(aLocalMountPoint->namep, line, t-line);
807 *(aLocalMountPoint->namep + (t-line)) = 0;
809 aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1);
810 memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-1);
811 *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-1)) = 0;
813 osi_Log2(afsd_logp,"found mount point: name %s, string %s",
814 aLocalMountPoint->namep,
815 aLocalMountPoint->mountPointStringp);
821 RegCloseKey(hkFreelance);
827 int cm_getNoLocalMountPoints() {
828 return cm_noLocalMountPoints;
831 long cm_FreelanceMountPointExists(char * filename, int prefix_ok)
837 HKEY hkFreelance = 0;
838 DWORD dwType, dwSize;
842 lock_ObtainMutex(&cm_Freelance_Lock);
844 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
845 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance",
847 KEY_READ|KEY_QUERY_VALUE,
848 &hkFreelance) == ERROR_SUCCESS)
850 RegQueryInfoKey( hkFreelance,
853 NULL, /* lpReserved */
854 NULL, /* lpcSubKeys */
855 NULL, /* lpcMaxSubKeyLen */
856 NULL, /* lpcMaxClassLen */
857 &dwMountPoints, /* lpcValues */
858 NULL, /* lpcMaxValueNameLen */
859 NULL, /* lpcMaxValueLen */
860 NULL, /* lpcbSecurityDescriptor */
861 NULL /* lpftLastWriteTime */
864 for ( dwIndex = 0; dwIndex < dwMountPoints; dwIndex++ ) {
865 TCHAR szValueName[16];
866 DWORD dwValueSize = 16;
867 dwSize = sizeof(line);
868 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
869 &dwType, line, &dwSize);
871 cp=strchr(line, '#');
873 cp=strchr(line, '%');
874 memcpy(shortname, line, cp-line);
875 shortname[cp-line]=0;
877 if (!strcmp(shortname, filename)) {
882 for ( dwIndex = 0; dwIndex < dwMountPoints; dwIndex++ ) {
883 TCHAR szValueName[16];
884 DWORD dwValueSize = 16;
885 dwSize = sizeof(line);
886 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
887 &dwType, line, &dwSize);
889 cp=strchr(line, '#');
891 cp=strchr(line, '%');
892 memcpy(shortname, line, cp-line);
893 shortname[cp-line]=0;
895 if (!cm_stricmp_utf8(shortname, filename)) {
900 if (prefix_ok && strlen(shortname) - strlen(filename) == 1 && !strncmp(shortname, filename, strlen(filename))) {
905 RegCloseKey(hkFreelance);
908 lock_ReleaseMutex(&cm_Freelance_Lock);
913 long cm_FreelanceSymlinkExists(char * filename, int prefix_ok)
919 HKEY hkFreelance = 0;
920 DWORD dwType, dwSize;
924 lock_ObtainMutex(&cm_Freelance_Lock);
926 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
927 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance\\Symlinks",
929 KEY_READ|KEY_QUERY_VALUE,
930 &hkFreelance) == ERROR_SUCCESS)
932 RegQueryInfoKey( hkFreelance,
935 NULL, /* lpReserved */
936 NULL, /* lpcSubKeys */
937 NULL, /* lpcMaxSubKeyLen */
938 NULL, /* lpcMaxClassLen */
939 &dwSymlinks, /* lpcValues */
940 NULL, /* lpcMaxValueNameLen */
941 NULL, /* lpcMaxValueLen */
942 NULL, /* lpcbSecurityDescriptor */
943 NULL /* lpftLastWriteTime */
946 for ( dwIndex = 0; dwIndex < dwSymlinks; dwIndex++ ) {
947 TCHAR szValueName[16];
948 DWORD dwValueSize = 16;
949 dwSize = sizeof(line);
950 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
951 &dwType, line, &dwSize);
953 cp=strchr(line, ':');
954 memcpy(shortname, line, cp-line);
955 shortname[cp-line]=0;
957 if (!strcmp(shortname, filename)) {
962 if (prefix_ok && strlen(shortname) - strlen(filename) == 1 && !strncmp(shortname, filename, strlen(filename))) {
967 for ( dwIndex = 0; dwIndex < dwSymlinks; dwIndex++ ) {
968 TCHAR szValueName[16];
969 DWORD dwValueSize = 16;
970 dwSize = sizeof(line);
971 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
972 &dwType, line, &dwSize);
974 cp=strchr(line, ':');
975 memcpy(shortname, line, cp-line);
976 shortname[cp-line]=0;
978 if (!cm_stricmp_utf8(shortname, filename)) {
983 RegCloseKey(hkFreelance);
986 lock_ReleaseMutex(&cm_Freelance_Lock);
991 long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp)
996 char fullname[CELL_MAXNAMELEN];
999 HKEY hkFreelance = 0;
1000 DWORD dwType, dwSize;
1001 DWORD dwMountPoints;
1003 afs_uint32 code = 0;
1005 /* before adding, verify the cell name; if it is not a valid cell,
1006 don't add the mount point.
1007 allow partial matches as a means of poor man's alias. */
1008 /* major performance issue? */
1009 osi_Log4(afsd_logp,"Freelance Add Mount request: filename=%s cellname=%s volume=%s %s",
1010 osi_LogSaveString(afsd_logp,filename),
1011 osi_LogSaveString(afsd_logp,cellname),
1012 osi_LogSaveString(afsd_logp,volume),
1015 if ( filename[0] == '\0' || cellname[0] == '\0' || volume[0] == '\0' )
1016 return CM_ERROR_INVAL;
1018 if ( cm_FreelanceMountPointExists(filename, 0) ||
1019 cm_FreelanceSymlinkExists(filename, 0) ) {
1020 code = CM_ERROR_EXISTS;
1024 if (cellname[0] == '.') {
1025 if (!cm_GetCell_Gen(&cellname[1], fullname, CM_FLAG_CREATE))
1026 return CM_ERROR_INVAL;
1028 if (!cm_GetCell_Gen(cellname, fullname, CM_FLAG_CREATE))
1029 return CM_ERROR_INVAL;
1032 osi_Log1(afsd_logp,"Freelance Adding Mount for Cell: %s",
1033 osi_LogSaveString(afsd_logp,cellname));
1035 lock_ObtainMutex(&cm_Freelance_Lock);
1037 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
1038 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance",
1040 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
1041 &hkFreelance) == ERROR_SUCCESS) {
1043 RegQueryInfoKey( hkFreelance,
1045 NULL, /* lpcClass */
1046 NULL, /* lpReserved */
1047 NULL, /* lpcSubKeys */
1048 NULL, /* lpcMaxSubKeyLen */
1049 NULL, /* lpcMaxClassLen */
1050 &dwMountPoints, /* lpcValues */
1051 NULL, /* lpcMaxValueNameLen */
1052 NULL, /* lpcMaxValueLen */
1053 NULL, /* lpcbSecurityDescriptor */
1054 NULL /* lpftLastWriteTime */
1058 sprintf(line, "%s%%%s:%s", filename, fullname, volume);
1060 sprintf(line, "%s#%s:%s", filename, fullname, volume);
1062 /* If we are adding a new value, there must be an unused name
1063 * within the range 0 to dwMountPoints
1065 for ( dwIndex = 0; dwIndex <= dwMountPoints; dwIndex++ ) {
1069 dwSize = sizeof(szMount);
1070 sprintf(szIndex, "%d", dwIndex);
1071 if (RegQueryValueEx( hkFreelance, szIndex, 0, &dwType, szMount, &dwSize) != ERROR_SUCCESS) {
1072 /* found an unused value */
1074 dwSize = (DWORD)strlen(line) + 1;
1075 RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
1078 int len = (int)strlen(filename);
1079 if ( dwType == REG_SZ && !strncmp(filename, szMount, len) &&
1080 (szMount[len] == '%' || szMount[len] == '#')) {
1081 /* Replace the existing value */
1083 dwSize = (DWORD)strlen(line) + 1;
1084 RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
1089 RegCloseKey(hkFreelance);
1092 cm_GetConfigDir(hfile, sizeof(hfile));
1093 strcat(hfile, AFS_FREELANCE_INI);
1094 fp = fopen(hfile, "r+");
1096 return CM_ERROR_INVAL;
1097 fgets(line, sizeof(line), fp);
1100 fseek(fp, 0, SEEK_SET);
1101 fprintf(fp, "%d", n);
1102 fseek(fp, 0, SEEK_END);
1104 fprintf(fp, "%s%%%s:%s\n", filename, fullname, volume);
1106 fprintf(fp, "%s#%s:%s\n", filename, fullname, volume);
1110 /* Do this while we are holding the lock */
1111 cm_noteLocalMountPointChange(TRUE);
1112 lock_ReleaseMutex(&cm_Freelance_Lock);
1118 clientchar_t *cpath;
1122 cpath = cm_FsStringToClientStringAlloc(filename, -1, NULL);
1124 return CM_ERROR_NOSUCHPATH;
1126 if (cm_getLocalMountPointChange()) { // check for changes
1127 cm_clearLocalMountPointChange(); // clear the changefile
1128 cm_reInitLocalMountPoints(); // start reinit
1131 code = cm_NameI(cm_data.rootSCachep, cpath,
1132 CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD | CM_FLAG_DFS_REFERRAL,
1133 cm_rootUserp, NULL, &req, &scp);
1138 cm_ReleaseSCache(scp);
1144 long cm_FreelanceRemoveMount(char *toremove)
1149 char shortname[200];
1150 char hfile[260], hfile2[260];
1153 HKEY hkFreelance = 0;
1154 DWORD dwType, dwSize;
1155 DWORD dwMountPoints;
1158 lock_ObtainMutex(&cm_Freelance_Lock);
1160 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
1161 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance",
1163 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
1164 &hkFreelance) == ERROR_SUCCESS) {
1166 RegQueryInfoKey( hkFreelance,
1168 NULL, /* lpcClass */
1169 NULL, /* lpReserved */
1170 NULL, /* lpcSubKeys */
1171 NULL, /* lpcMaxSubKeyLen */
1172 NULL, /* lpcMaxClassLen */
1173 &dwMountPoints, /* lpcValues */
1174 NULL, /* lpcMaxValueNameLen */
1175 NULL, /* lpcMaxValueLen */
1176 NULL, /* lpcbSecurityDescriptor */
1177 NULL /* lpftLastWriteTime */
1180 for ( dwIndex = 0; dwIndex < dwMountPoints; dwIndex++ ) {
1181 TCHAR szValueName[16];
1182 DWORD dwValueSize = 16;
1183 dwSize = sizeof(line);
1184 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
1185 &dwType, line, &dwSize);
1187 cp=strchr(line, '#');
1189 cp=strchr(line, '%');
1190 memcpy(shortname, line, cp-line);
1191 shortname[cp-line]=0;
1193 if (!strcmp(shortname, toremove)) {
1194 RegDeleteValue( hkFreelance, szValueName );
1199 RegCloseKey(hkFreelance);
1202 cm_GetConfigDir(hfile, sizeof(hfile));
1203 strcat(hfile, AFS_FREELANCE_INI);
1204 strcpy(hfile2, hfile);
1205 strcat(hfile2, "2");
1206 fp1=fopen(hfile, "r+");
1208 return CM_ERROR_INVAL;
1209 fp2=fopen(hfile2, "w+");
1212 return CM_ERROR_INVAL;
1215 fgets(line, sizeof(line), fp1);
1217 fprintf(fp2, "%d\n", n-1);
1219 for (i=0; i<n; i++) {
1220 fgets(line, sizeof(line), fp1);
1221 cp=strchr(line, '#');
1223 cp=strchr(line, '%');
1224 memcpy(shortname, line, cp-line);
1225 shortname[cp-line]=0;
1227 if (strcmp(shortname, toremove)==0) {
1239 rename(hfile2, hfile);
1244 /* Do this while we are holding the lock */
1245 cm_noteLocalMountPointChange(TRUE);
1247 lock_ReleaseMutex(&cm_Freelance_Lock);
1248 return (found ? 0 : CM_ERROR_NOSUCHFILE);
1251 long cm_FreelanceAddSymlink(char *filename, char *destination, cm_fid_t *fidp)
1254 char fullname[CELL_MAXNAMELEN] = "";
1256 HKEY hkFreelanceSymlinks = 0;
1257 DWORD dwType, dwSize;
1260 afs_uint32 code = 0;
1263 * before adding, verify the filename. If it is already in use, either as
1264 * as mount point or a cellname, do not permit the creation of the symlink.
1266 osi_Log2(afsd_logp,"Freelance Add Symlink request: filename=%s destination=%s",
1267 osi_LogSaveString(afsd_logp,filename),
1268 osi_LogSaveString(afsd_logp,destination));
1270 if ( filename[0] == '\0' || destination[0] == '\0' )
1271 return CM_ERROR_INVAL;
1273 /* Do not create the symlink if the name ends in a dot */
1274 if ( filename[strlen(filename)-1] == '.')
1275 return CM_ERROR_INVAL;
1277 if ( cm_FreelanceMountPointExists(filename, 0) ||
1278 cm_FreelanceSymlinkExists(filename, 0) ) {
1279 code = CM_ERROR_EXISTS;
1283 if (filename[0] == '.') {
1284 cm_GetCell_Gen(&filename[1], fullname, CM_FLAG_CREATE);
1285 if (cm_stricmp_utf8(&filename[1],fullname) == 0) {
1286 code = CM_ERROR_EXISTS;
1290 cm_GetCell_Gen(filename, fullname, CM_FLAG_CREATE);
1291 if (cm_stricmp_utf8(filename,fullname) == 0) {
1292 code = CM_ERROR_EXISTS;
1297 lock_ObtainMutex(&cm_Freelance_Lock);
1299 if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
1300 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance\\Symlinks",
1303 REG_OPTION_NON_VOLATILE,
1304 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
1306 &hkFreelanceSymlinks,
1307 NULL) == ERROR_SUCCESS) {
1309 RegQueryInfoKey( hkFreelanceSymlinks,
1311 NULL, /* lpcClass */
1312 NULL, /* lpReserved */
1313 NULL, /* lpcSubKeys */
1314 NULL, /* lpcMaxSubKeyLen */
1315 NULL, /* lpcMaxClassLen */
1316 &dwSymlinks, /* lpcValues */
1317 NULL, /* lpcMaxValueNameLen */
1318 NULL, /* lpcMaxValueLen */
1319 NULL, /* lpcbSecurityDescriptor */
1320 NULL /* lpftLastWriteTime */
1323 sprintf(line, "%s:%s.", filename, destination);
1325 /* If we are adding a new value, there must be an unused name
1326 * within the range 0 to dwSymlinks
1328 for ( dwIndex = 0; dwIndex <= dwSymlinks; dwIndex++ ) {
1332 dwSize = sizeof(szLink);
1333 sprintf(szIndex, "%d", dwIndex);
1334 if (RegQueryValueEx( hkFreelanceSymlinks, szIndex, 0, &dwType, szLink, &dwSize) != ERROR_SUCCESS) {
1335 /* found an unused value */
1337 dwSize = (DWORD)strlen(line) + 1;
1338 RegSetValueEx( hkFreelanceSymlinks, szIndex, 0, dwType, line, dwSize);
1341 int len = (int)strlen(filename);
1342 if ( dwType == REG_SZ && !strncmp(filename, szLink, len) && szLink[len] == ':') {
1343 /* Replace the existing value */
1345 dwSize = (DWORD)strlen(line) + 1;
1346 RegSetValueEx( hkFreelanceSymlinks, szIndex, 0, dwType, line, dwSize);
1351 RegCloseKey(hkFreelanceSymlinks);
1354 /* Do this while we are holding the lock */
1355 cm_noteLocalMountPointChange(TRUE);
1356 lock_ReleaseMutex(&cm_Freelance_Lock);
1362 clientchar_t *cpath;
1366 cpath = cm_FsStringToClientStringAlloc(filename, -1, NULL);
1368 code = CM_ERROR_NOSUCHPATH;
1370 if (cm_getLocalMountPointChange()) { // check for changes
1371 cm_clearLocalMountPointChange(); // clear the changefile
1372 cm_reInitLocalMountPoints(); // start reinit
1375 code = cm_NameI(cm_data.rootSCachep, cpath,
1376 CM_FLAG_FOLLOW | CM_FLAG_CASEFOLD | CM_FLAG_DFS_REFERRAL,
1377 cm_rootUserp, NULL, &req, &scp);
1381 cm_ReleaseSCache(scp);
1389 long cm_FreelanceRemoveSymlink(char *toremove)
1393 char shortname[200];
1395 HKEY hkFreelanceSymlinks = 0;
1396 DWORD dwType, dwSize;
1400 lock_ObtainMutex(&cm_Freelance_Lock);
1402 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
1403 AFSREG_CLT_OPENAFS_SUBKEY "\\Freelance\\Symlinks",
1405 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
1406 &hkFreelanceSymlinks) == ERROR_SUCCESS) {
1408 RegQueryInfoKey( hkFreelanceSymlinks,
1410 NULL, /* lpcClass */
1411 NULL, /* lpReserved */
1412 NULL, /* lpcSubKeys */
1413 NULL, /* lpcMaxSubKeyLen */
1414 NULL, /* lpcMaxClassLen */
1415 &dwSymlinks, /* lpcValues */
1416 NULL, /* lpcMaxValueNameLen */
1417 NULL, /* lpcMaxValueLen */
1418 NULL, /* lpcbSecurityDescriptor */
1419 NULL /* lpftLastWriteTime */
1422 for ( dwIndex = 0; dwIndex < dwSymlinks; dwIndex++ ) {
1423 TCHAR szValueName[16];
1424 DWORD dwValueSize = 16;
1425 dwSize = sizeof(line);
1426 RegEnumValue( hkFreelanceSymlinks, dwIndex, szValueName, &dwValueSize, NULL,
1427 &dwType, line, &dwSize);
1429 cp=strchr(line, ':');
1430 memcpy(shortname, line, cp-line);
1431 shortname[cp-line]=0;
1433 if (!strcmp(shortname, toremove)) {
1434 RegDeleteValue( hkFreelanceSymlinks, szValueName );
1439 RegCloseKey(hkFreelanceSymlinks);
1443 /* Do this while we are holding the lock */
1444 cm_noteLocalMountPointChange(TRUE);
1446 lock_ReleaseMutex(&cm_Freelance_Lock);
1447 return (found ? 0 : CM_ERROR_NOSUCHFILE);
1451 cm_FreelanceFetchMountPointString(cm_scache_t *scp)
1453 lock_ObtainMutex(&cm_Freelance_Lock);
1454 if (!scp->mountPointStringp[0] &&
1455 scp->fid.cell == AFS_FAKE_ROOT_CELL_ID &&
1456 scp->fid.volume == AFS_FAKE_ROOT_VOL_ID &&
1457 scp->fid.unique <= cm_noLocalMountPoints) {
1458 strncpy(scp->mountPointStringp, cm_localMountPoints[scp->fid.unique-1].mountPointStringp, MOUNTPOINTLEN);
1459 scp->mountPointStringp[MOUNTPOINTLEN-1] = 0; /* null terminate */
1461 lock_ReleaseMutex(&cm_Freelance_Lock);
1467 cm_FreelanceFetchFileType(cm_scache_t *scp)
1469 lock_ObtainMutex(&cm_Freelance_Lock);
1470 if (scp->fid.cell == AFS_FAKE_ROOT_CELL_ID &&
1471 scp->fid.volume == AFS_FAKE_ROOT_VOL_ID &&
1472 scp->fid.unique <= cm_noLocalMountPoints)
1474 scp->fileType = cm_localMountPoints[scp->fid.unique-1].fileType;
1476 if ( scp->fileType == CM_SCACHETYPE_SYMLINK &&
1477 !strnicmp(cm_localMountPoints[scp->fid.unique-1].mountPointStringp, "msdfs:", strlen("msdfs:")) )
1479 scp->fileType = CM_SCACHETYPE_DFSLINK;
1482 scp->fileType = CM_SCACHETYPE_INVALID;
1484 lock_ReleaseMutex(&cm_Freelance_Lock);
1488 #endif /* AFS_FREELANCE_CLIENT */