18 #ifdef AFS_FREELANCE_CLIENT
19 #include "cm_freelance.h"
22 extern void afsi_log(char *pattern, ...);
24 int cm_noLocalMountPoints;
26 int cm_fakeDirCallback=0;
27 int cm_fakeGettingCallback=0;
28 int cm_fakeDirVersion = 0x8;
29 cm_localMountPoint_t* cm_localMountPoints;
30 osi_mutex_t cm_Freelance_Lock;
31 int cm_localMountPointChangeFlag = 0;
32 int cm_freelanceEnabled = 0;
33 afs_uint32 FakeFreelanceModTime = 0x3b49f6e2;
35 void cm_InitFakeRootDir();
38 void cm_FreelanceChangeNotifier(void * parmp) {
39 HANDLE hFreelanceChangeEvent = 0;
42 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
43 "SOFTWARE\\OpenAFS\\Client\\Freelance",
46 &hkFreelance) == ERROR_SUCCESS) {
48 hFreelanceChangeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
49 if (hFreelanceChangeEvent == NULL) {
50 RegCloseKey(hkFreelance);
56 /* check hFreelanceChangeEvent to see if it is set.
57 * if so, call cm_noteLocalMountPointChange()
59 if (RegNotifyChangeKeyValue( hkFreelance, /* hKey */
60 FALSE, /* bWatchSubtree */
61 REG_NOTIFY_CHANGE_LAST_SET, /* dwNotifyFilter */
62 hFreelanceChangeEvent, /* hEvent */
63 TRUE /* fAsynchronous */
65 RegCloseKey(hkFreelance);
66 CloseHandle(hFreelanceChangeEvent);
70 if (WaitForSingleObject(hFreelanceChangeEvent, INFINITE) == WAIT_OBJECT_0)
72 cm_noteLocalMountPointChange();
78 void cm_InitFreelance() {
84 lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock");
86 // yj: first we make a call to cm_initLocalMountPoints
87 // to read all the local mount points from an ini file
88 cm_InitLocalMountPoints();
90 // then we make a call to InitFakeRootDir to create
91 // a fake root directory based on the local mount points
96 /* Start the registry monitor */
97 phandle = thrd_Create(NULL, 65536, (ThreadFunc) cm_FreelanceChangeNotifier,
98 NULL, 0, &lpid, "cm_FreelanceChangeNotifier");
99 osi_assert(phandle != NULL);
100 thrd_CloseHandle(phandle);
104 /* yj: Initialization of the fake root directory */
105 /* to be called while holding freelance lock unless during init. */
106 void cm_InitFakeRootDir() {
112 // allocate space for the fake info
113 cm_dirHeader_t fakeDirHeader;
114 cm_dirEntry_t fakeEntry;
115 cm_pageHeader_t fakePageHeader;
117 // i'm going to calculate how much space is needed for
118 // this fake root directory. we have these rules:
119 // 1. there are cm_noLocalMountPoints number of entries
120 // 2. each page is CM_DIR_PAGESIZE in size
121 // 3. the first 13 chunks of the first page are used for
123 // 4. the first chunk of all subsequent pages are used
124 // for page header stuff
125 // 5. a max of CM_DIR_EPP entries are allowed per page
126 // 6. each entry takes 1 or more chunks, depending on
127 // the size of the mount point string, as determined
129 // 7. each chunk is CM_DIR_CHUNKSIZE bytes
131 int CPP = CM_DIR_PAGESIZE / CM_DIR_CHUNKSIZE;
132 int curChunk = 13; // chunks 0 - 12 are used for header stuff
133 // of the first page in the directory
136 int curDirEntryInPage = 0;
140 /* Reserve 2 directory chunks for "." and ".." */
143 while (curDirEntry!=cm_noLocalMountPoints) {
144 sizeOfCurEntry = cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0);
145 if ((curChunk + sizeOfCurEntry >= CPP) ||
146 (curDirEntryInPage + 1 >= CM_DIR_EPP)) {
148 curDirEntryInPage = 0;
151 curChunk += sizeOfCurEntry;
156 dirSize = (curPage+1) * CM_DIR_PAGESIZE;
157 cm_FakeRootDir = malloc(dirSize);
158 cm_fakeDirSize = dirSize;
160 // yj: when we get here, we've figured out how much memory we need and
161 // allocated the appropriate space for it. we now prceed to fill
162 // it up with entries.
165 curDirEntryInPage = 0;
168 // fields in the directory entry that are unused.
170 fakeEntry.length = 0;
172 fakeEntry.fid.unique = htonl(1);
174 // the first page is special, it uses fakeDirHeader instead of fakePageHeader
175 // we fill up the page with dirEntries that belong there and we make changes
176 // to the fakeDirHeader.header.freeBitmap along the way. Then when we're done
177 // filling up the dirEntries in this page, we copy the fakeDirHeader into
178 // the top of the page.
180 // init the freeBitmap array
182 fakeDirHeader.header.freeBitmap[i]=0;
184 fakeDirHeader.header.freeBitmap[0] = 0xff;
185 fakeDirHeader.header.freeBitmap[1] = 0x7f;
188 // we start counting at 13 because the 0th to 12th chunks are used for header
191 // stick the first 2 entries "." and ".." in
192 fakeEntry.fid.unique = htonl(1);
193 fakeEntry.fid.vnode = htonl(1);
194 strcpy(fakeEntry.name, ".");
195 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
196 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
197 curChunk++; curDirEntryInPage++;
198 strcpy(fakeEntry.name, "..");
199 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
200 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
201 curChunk++; curDirEntryInPage++;
203 // keep putting stuff into page 0 if
204 // 1. we're not done with all entries
205 // 2. we have less than CM_DIR_EPP entries in page 0
206 // 3. we're not out of chunks in page 0
208 while( (curDirEntry!=cm_noLocalMountPoints) &&
209 (curDirEntryInPage < CM_DIR_EPP) &&
210 (curChunk + cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0) <= CPP))
213 noChunks = cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0);
214 fakeEntry.fid.vnode = htonl(curDirEntry + 2);
215 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
217 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
218 strcpy(currentPos + 12, (cm_localMountPoints+curDirEntry)->namep);
221 for (i=0; i<noChunks; i++) {
222 t1 = (curChunk + i) / 8;
223 t2 = curChunk + i - (t1*8);
224 fakeDirHeader.header.freeBitmap[t1] |= (1 << t2);
229 // when we get here, we're done with filling in the entries for page 0
230 // copy in the header info
232 memcpy(cm_FakeRootDir, &fakeDirHeader, 13 * CM_DIR_CHUNKSIZE);
236 // ok, page 0's done. Move on to the next page.
237 while (curDirEntry!=cm_noLocalMountPoints) {
239 curChunk = 1; // the zeroth chunk is reserved for page header
240 curDirEntryInPage = 0;
241 for (i=0; i<8; i++) {
242 fakePageHeader.freeBitmap[i]=0;
244 fakePageHeader.freeCount = 0;
245 fakePageHeader.pgcount = 0;
246 fakePageHeader.tag = htons(1234);
248 // while we're on the same page...
249 while ( (curDirEntry!=cm_noLocalMountPoints) &&
250 (curDirEntryInPage < CM_DIR_EPP) &&
251 (curChunk + cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0) <= CPP))
253 // add an entry to this page
255 noChunks = cm_NameEntries((cm_localMountPoints+curDirEntry)->namep, 0);
256 fakeEntry.fid.vnode=htonl(curDirEntry+2);
257 currentPos = cm_FakeRootDir + curPage * CM_DIR_PAGESIZE + curChunk * CM_DIR_CHUNKSIZE;
258 memcpy(currentPos, &fakeEntry, CM_DIR_CHUNKSIZE);
259 strcpy(currentPos + 12, (cm_localMountPoints+curDirEntry)->namep);
262 for (i=0; i<noChunks; i++) {
263 t1 = (curChunk + i) / 8;
264 t2 = curChunk + i - (t1*8);
265 fakePageHeader.freeBitmap[t1] |= (1 << t2);
269 memcpy(cm_FakeRootDir + curPage * CM_DIR_PAGESIZE, &fakePageHeader, sizeof(fakePageHeader));
274 // we know the fakeDir is setup properly, so we claim that we have callback
275 osi_Log0(afsd_logp,"cm_InitFakeRootDir fakeDirCallback=1");
276 cm_fakeDirCallback=1;
278 // when we get here, we've set up everything! done!
281 int cm_FakeRootFid(cm_fid_t *fidp)
283 fidp->cell = AFS_FAKE_ROOT_CELL_ID; /* root cell */
284 fidp->volume = AFS_FAKE_ROOT_VOL_ID; /* root.afs ? */
290 /* called directly from ioctl */
291 /* called while not holding freelance lock */
292 int cm_noteLocalMountPointChange() {
293 lock_ObtainMutex(&cm_Freelance_Lock);
295 cm_localMountPointChangeFlag = 1;
296 lock_ReleaseMutex(&cm_Freelance_Lock);
300 int cm_getLocalMountPointChange() {
301 return cm_localMountPointChangeFlag;
304 int cm_clearLocalMountPointChange() {
305 cm_localMountPointChangeFlag = 0;
309 int cm_reInitLocalMountPoints() {
312 cm_scache_t *scp, **lscpp, *tscp;
314 osi_Log0(afsd_logp,"----- freelance reinitialization starts ----- ");
316 // first we invalidate all the SCPs that were created
317 // for the local mount points
319 osi_Log0(afsd_logp,"Invalidating local mount point scp... ");
321 aFid.cell = AFS_FAKE_ROOT_CELL_ID;
322 aFid.volume=AFS_FAKE_ROOT_VOL_ID;
326 lock_ObtainWrite(&cm_scacheLock);
327 lock_ObtainMutex(&cm_Freelance_Lock); /* always scache then freelance lock */
328 for (i=0; i<cm_noLocalMountPoints; i++) {
329 hash = CM_SCACHE_HASH(&aFid);
330 for (scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
331 if (scp->fid.volume == aFid.volume &&
332 scp->fid.vnode == aFid.vnode &&
333 scp->fid.unique == aFid.unique
336 // mark the scp to be reused
337 lock_ReleaseWrite(&cm_scacheLock);
338 lock_ObtainMutex(&scp->mx);
339 cm_DiscardSCache(scp);
340 lock_ReleaseMutex(&scp->mx);
341 cm_CallbackNotifyChange(scp);
342 lock_ObtainWrite(&cm_scacheLock);
345 // take the scp out of the hash
346 lscpp = &cm_hashTablep[hash];
347 for (tscp=*lscpp; tscp; lscpp = &tscp->nextp, tscp = *lscpp) {
348 if (tscp == scp) break;
351 scp->flags &= ~CM_SCACHEFLAG_INHASH;
356 aFid.vnode = aFid.vnode + 1;
358 lock_ReleaseWrite(&cm_scacheLock);
359 osi_Log0(afsd_logp,"\tall old scp cleared!");
361 // we must free the memory that was allocated in the prev
362 // cm_InitLocalMountPoints call
363 osi_Log0(afsd_logp,"Removing old localmountpoints... ");
364 free(cm_localMountPoints);
365 osi_Log0(afsd_logp,"\tall old localmountpoints cleared!");
367 // now re-init the localmountpoints
368 osi_Log0(afsd_logp,"Creating new localmountpoints... ");
369 cm_InitLocalMountPoints();
370 osi_Log0(afsd_logp,"\tcreated new set of localmountpoints!");
373 // now we have to free the memory allocated in cm_initfakerootdir
374 osi_Log0(afsd_logp,"Removing old fakedir... ");
375 free(cm_FakeRootDir);
376 osi_Log0(afsd_logp,"\t\told fakedir removed!");
378 // then we re-create that dir
379 osi_Log0(afsd_logp,"Creating new fakedir... ");
380 cm_InitFakeRootDir();
381 osi_Log0(afsd_logp,"\t\tcreated new fakedir!");
383 lock_ReleaseMutex(&cm_Freelance_Lock);
385 osi_Log0(afsd_logp,"----- freelance reinit complete -----");
390 // yj: open up the ini file and read all the local mount
391 // points that are stored there. Part of the initialization
392 // process for the freelance client.
393 /* to be called while holding freelance lock unless during init. */
394 long cm_InitLocalMountPoints() {
399 cm_localMountPoint_t* aLocalMountPoint;
402 char rootCellName[256];
404 HKEY hkFreelance = 0;
405 DWORD dwType, dwSize;
408 FILETIME ftLastWriteTime;
413 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
414 "SOFTWARE\\OpenAFS\\Client\\Freelance",
416 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
417 &hkFreelance) == ERROR_SUCCESS) {
419 RegQueryInfoKey( hkFreelance,
422 NULL, /* lpReserved */
423 NULL, /* lpcSubKeys */
424 NULL, /* lpcMaxSubKeyLen */
425 NULL, /* lpcMaxClassLen */
426 &dwMountPoints, /* lpcValues */
427 NULL, /* lpcMaxValueNameLen */
428 NULL, /* lpcMaxValueLen */
429 NULL, /* lpcbSecurityDescriptor */
430 &ftLastWriteTime /* lpftLastWriteTime */
433 smb_UnixTimeFromLargeSearchTime(&FakeFreelanceModTime, &ftLastWriteTime);
435 if ( dwMountPoints == 0 ) {
436 sprintf(line,"%s#%s:root.cell.\n",rootCellName,rootCellName);
438 dwSize = strlen(line) + 1;
439 RegSetValueEx( hkFreelance, "0", 0, dwType, line, dwSize);
440 sprintf(line,".%s%%%s:root.cell.\n",rootCellName,rootCellName);
441 dwSize = strlen(line) + 1;
442 RegSetValueEx( hkFreelance, "1", 0, dwType, line, dwSize);
446 // get the number of entries there are from the first line
448 cm_noLocalMountPoints = dwMountPoints;
450 // create space to store the local mount points
451 cm_localMountPoints = malloc(sizeof(cm_localMountPoint_t) * cm_noLocalMountPoints);
452 aLocalMountPoint = cm_localMountPoints;
454 // now we read n lines and parse them into local mount points
455 // where n is the number of local mount points there are, as
457 // Each line in the ini file represents 1 local mount point and
458 // is in the format xxx#yyy:zzz, where xxx is the directory
459 // entry name, yyy is the cell name and zzz is the volume name.
460 // #yyy:zzz together make up the mount point.
461 for ( dwIndex = 0 ; dwIndex < dwMountPoints; dwIndex++ ) {
462 TCHAR szValueName[16];
463 DWORD dwValueSize = 16;
464 dwSize = sizeof(line);
465 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
466 &dwType, line, &dwSize);
468 // line is not empty, so let's parse it
469 t = strchr(line, '#');
471 t = strchr(line, '%');
472 // make sure that there is a '#' or '%' separator in the line
474 afsi_log("error occurred while parsing entry in %s: no # or %% separator in line %d", AFS_FREELANCE_INI, dwIndex);
475 fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: no # or %% separator in line %d", dwIndex);
476 cm_noLocalMountPoints--;
479 aLocalMountPoint->namep=malloc(t-line+1);
480 memcpy(aLocalMountPoint->namep, line, t-line);
481 *(aLocalMountPoint->namep + (t-line)) = 0;
483 aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1);
484 memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2);
485 *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0;
487 osi_Log2(afsd_logp,"found mount point: name %s, string %s",
488 osi_LogSaveString(afsd_logp,aLocalMountPoint->namep),
489 osi_LogSaveString(afsd_logp,aLocalMountPoint->mountPointStringp));
494 RegCloseKey(hkFreelance);
499 /* What follows is the old code to read freelance mount points
500 * out of a text file modified to copy the data into the registry
502 cm_GetConfigDir(hdir);
503 strcat(hdir, AFS_FREELANCE_INI);
504 // open the ini file for reading
505 fp = fopen(hdir, "r");
507 // if we fail to open the file, create an empty one
509 fp = fopen(hdir, "w");
510 code = cm_GetRootCellName(rootCellName);
513 fprintf(fp,"%s#%s:root.cell.\n",rootCellName,rootCellName);
514 fprintf(fp,".%s%%%s:root.cell.\n",rootCellName,rootCellName);
516 fp = fopen(hdir, "r");
520 return 0; /* success */
524 // we successfully opened the file
525 osi_Log0(afsd_logp,"opened afs_freelance.ini");
528 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
529 "SOFTWARE\\OpenAFS\\Client\\Freelance",
532 REG_OPTION_NON_VOLATILE,
540 // now we read the first line to see how many entries
542 fgets(line, sizeof(line), fp);
544 // if the line is empty at any point when we're reading
545 // we're screwed. report error and return.
547 afsi_log("error occurred while reading afs_freelance.ini");
548 fprintf(stderr, "error occurred while reading afs_freelance.ini");
552 // get the number of entries there are from the first line
554 cm_noLocalMountPoints = atoi(line);
556 // create space to store the local mount points
557 cm_localMountPoints = malloc(sizeof(cm_localMountPoint_t) * cm_noLocalMountPoints);
558 aLocalMountPoint = cm_localMountPoints;
560 // now we read n lines and parse them into local mount points
561 // where n is the number of local mount points there are, as
563 // Each line in the ini file represents 1 local mount point and
564 // is in the format xxx#yyy:zzz, where xxx is the directory
565 // entry name, yyy is the cell name and zzz is the volume name.
566 // #yyy:zzz together make up the mount point.
567 for (i=0; i<cm_noLocalMountPoints; i++) {
568 fgets(line, sizeof(line), fp);
569 // check that the line is not empty
571 afsi_log("error occurred while parsing entry in %s: empty line in line %d", AFS_FREELANCE_INI, i);
572 fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: empty line in line %d", i);
579 /* we are migrating to the registry */
580 sprintf(szIndex,"%d",dwIndex++);
582 dwSize = strlen(line) + 1;
583 RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
587 // line is not empty, so let's parse it
588 t = strchr(line, '#');
590 t = strchr(line, '%');
591 // make sure that there is a '#' or '%' separator in the line
593 afsi_log("error occurred while parsing entry in %s: no # or %% separator in line %d", AFS_FREELANCE_INI, i);
594 fprintf(stderr, "error occurred while parsing entry in afs_freelance.ini: no # or %% separator in line %d", i);
597 aLocalMountPoint->namep=malloc(t-line+1);
598 memcpy(aLocalMountPoint->namep, line, t-line);
599 *(aLocalMountPoint->namep + (t-line)) = 0;
601 aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1);
602 memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2);
603 *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0;
605 osi_Log2(afsd_logp,"found mount point: name %s, string %s",
606 aLocalMountPoint->namep,
607 aLocalMountPoint->mountPointStringp);
614 RegCloseKey(hkFreelance);
621 int cm_getNoLocalMountPoints() {
622 return cm_noLocalMountPoints;
625 cm_localMountPoint_t* cm_getLocalMountPoint(int vnode) {
629 long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp)
638 HKEY hkFreelance = 0;
639 DWORD dwType, dwSize;
644 /* before adding, verify the cell name; if it is not a valid cell,
645 don't add the mount point.
646 allow partial matches as a means of poor man's alias. */
647 /* major performance issue? */
648 osi_Log4(afsd_logp,"Freelance Add Mount request: filename=%s cellname=%s volume=%s %s",
649 osi_LogSaveString(afsd_logp,filename),
650 osi_LogSaveString(afsd_logp,cellname),
651 osi_LogSaveString(afsd_logp,volume),
653 if (cellname[0] == '.') {
654 if (!cm_GetCell_Gen(&cellname[1], fullname, CM_FLAG_CREATE))
657 if (!cm_GetCell_Gen(cellname, fullname, CM_FLAG_CREATE))
661 osi_Log1(afsd_logp,"Freelance Adding Mount for Cell: %s",
662 osi_LogSaveString(afsd_logp,cellname));
664 lock_ObtainMutex(&cm_Freelance_Lock);
667 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
668 "SOFTWARE\\OpenAFS\\Client\\Freelance",
670 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
671 &hkFreelance) == ERROR_SUCCESS) {
673 RegQueryInfoKey( hkFreelance,
676 NULL, /* lpReserved */
677 NULL, /* lpcSubKeys */
678 NULL, /* lpcMaxSubKeyLen */
679 NULL, /* lpcMaxClassLen */
680 &dwMountPoints, /* lpcValues */
681 NULL, /* lpcMaxValueNameLen */
682 NULL, /* lpcMaxValueLen */
683 NULL, /* lpcbSecurityDescriptor */
684 NULL /* lpftLastWriteTime */
688 sprintf(line, "%s%%%s:%s\n", filename, fullname, volume);
690 sprintf(line, "%s#%s:%s\n", filename, fullname, volume);
692 /* If we are adding a new value, there must be an unused name
693 * within the range 0 to dwMountPoints
695 for ( dwIndex = 0; dwIndex <= dwMountPoints; dwIndex++ ) {
697 sprintf(szIndex, "%d", dwIndex);
698 if (RegQueryValueEx( hkFreelance, szIndex, 0, &dwType, NULL, &dwSize) != ERROR_SUCCESS) {
699 /* found an unused value */
701 dwSize = strlen(line) + 1;
702 RegSetValueEx( hkFreelance, szIndex, 0, dwType, line, dwSize);
706 RegCloseKey(hkFreelance);
710 cm_GetConfigDir(hfile);
711 strcat(hfile, AFS_FREELANCE_INI);
712 fp = fopen(hfile, "r+");
714 return CM_ERROR_INVAL;
715 fgets(line, sizeof(line), fp);
718 fseek(fp, 0, SEEK_SET);
719 fprintf(fp, "%d", n);
720 fseek(fp, 0, SEEK_END);
722 fprintf(fp, "%s%%%s:%s\n", filename, fullname, volume);
724 fprintf(fp, "%s#%s:%s\n", filename, fullname, volume);
727 lock_ReleaseMutex(&cm_Freelance_Lock);
729 /* cm_reInitLocalMountPoints(); */
732 fidp->vnode = cm_noLocalMountPoints + 1; /* vnode value of last mt pt */
734 cm_noteLocalMountPointChange();
738 long cm_FreelanceRemoveMount(char *toremove)
744 char hfile[120], hfile2[120];
748 HKEY hkFreelance = 0;
749 DWORD dwType, dwSize;
754 lock_ObtainMutex(&cm_Freelance_Lock);
758 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
759 "SOFTWARE\\OpenAFS\\Client\\Freelance",
761 KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
762 &hkFreelance) == ERROR_SUCCESS) {
764 RegQueryInfoKey( hkFreelance,
767 NULL, /* lpReserved */
768 NULL, /* lpcSubKeys */
769 NULL, /* lpcMaxSubKeyLen */
770 NULL, /* lpcMaxClassLen */
771 &dwMountPoints, /* lpcValues */
772 NULL, /* lpcMaxValueNameLen */
773 NULL, /* lpcMaxValueLen */
774 NULL, /* lpcbSecurityDescriptor */
775 NULL /* lpftLastWriteTime */
778 for ( dwIndex = 0; dwIndex < dwMountPoints; dwIndex++ ) {
779 TCHAR szValueName[16];
780 DWORD dwValueSize = 16;
781 dwSize = sizeof(line);
782 RegEnumValue( hkFreelance, dwIndex, szValueName, &dwValueSize, NULL,
783 &dwType, line, &dwSize);
785 cp=strchr(line, '#');
787 cp=strchr(line, '%');
788 memcpy(shortname, line, cp-line);
789 shortname[cp-line]=0;
791 if (!strcmp(shortname, toremove)) {
792 RegDeleteValue( hkFreelance, szValueName );
796 RegCloseKey(hkFreelance);
800 cm_GetConfigDir(hfile);
801 strcat(hfile, AFS_FREELANCE_INI);
802 strcpy(hfile2, hfile);
804 fp1=fopen(hfile, "r+");
806 return CM_ERROR_INVAL;
807 fp2=fopen(hfile2, "w+");
810 return CM_ERROR_INVAL;
813 fgets(line, sizeof(line), fp1);
815 fprintf(fp2, "%d\n", n-1);
817 for (i=0; i<n; i++) {
818 fgets(line, sizeof(line), fp1);
819 cp=strchr(line, '#');
821 cp=strchr(line, '%');
822 memcpy(shortname, line, cp-line);
823 shortname[cp-line]=0;
825 if (strcmp(shortname, toremove)==0) {
836 return CM_ERROR_NOSUCHFILE;
839 rename(hfile2, hfile);
842 lock_ReleaseMutex(&cm_Freelance_Lock);
843 cm_noteLocalMountPointChange();
847 #endif /* AFS_FREELANCE_CLIENT */