* adfCreateEntry * * if 'thisSect'==-1, allocate a sector, and insert its pointer into the hashTable of 'dir', using the * name 'name'. if 'thisSect'!=-1, insert this sector pointer into the hashTable * (here 'thisSect' must be allocated before in the bitmap). */
| 703 | * (here 'thisSect' must be allocated before in the bitmap). |
| 704 | */ |
| 705 | SECTNUM adfCreateEntry(struct Volume *vol, struct bEntryBlock *dir, char *name, |
| 706 | SECTNUM thisSect ) |
| 707 | { |
| 708 | BOOL intl; |
| 709 | struct bEntryBlock updEntry; |
| 710 | int len, hashValue; |
| 711 | RETCODE rc; |
| 712 | char name2[MAXNAMELEN+1], name3[MAXNAMELEN+1]; |
| 713 | SECTNUM nSect, newSect, newSect2; |
| 714 | struct bRootBlock* root; |
| 715 | |
| 716 | /*puts("adfCreateEntry in");*/ |
| 717 | |
| 718 | intl = isINTL(vol->dosType) || isDIRCACHE(vol->dosType); |
| 719 | len = min(strlen(name), MAXNAMELEN) ; |
| 720 | myToUpper((uint8_t*)name2, (uint8_t*)name, len, intl); |
| 721 | hashValue = adfGetHashValue((uint8_t*)name, intl); |
| 722 | nSect = dir->hashTable[ hashValue ]; |
| 723 | |
| 724 | if ( nSect==0 ) { |
| 725 | if (thisSect!=-1) |
| 726 | newSect = thisSect; |
| 727 | else { |
| 728 | newSect = adfGet1FreeBlock(vol); |
| 729 | if (newSect==-1) { |
| 730 | (*adfEnv.wFct)("adfCreateEntry : nSect==-1"); |
| 731 | return -1; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | dir->hashTable[ hashValue ] = newSect; |
| 736 | if (dir->secType==ST_ROOT) { |
| 737 | root = (struct bRootBlock*)dir; |
| 738 | adfTime2AmigaTime(adfGiveCurrentTime(), |
| 739 | &(root->cDays),&(root->cMins),&(root->cTicks)); |
| 740 | rc=adfWriteRootBlock(vol, vol->rootBlock, root); |
| 741 | } |
| 742 | else { |
| 743 | adfTime2AmigaTime(adfGiveCurrentTime(),&(dir->days),&(dir->mins),&(dir->ticks)); |
| 744 | rc=adfWriteDirBlock(vol, dir->headerKey, (struct bDirBlock*)dir); |
| 745 | } |
| 746 | /*puts("adfCreateEntry out, dir");*/ |
| 747 | if (rc!=RC_OK) { |
| 748 | adfSetBlockFree(vol, newSect); |
| 749 | return -1; |
| 750 | } |
| 751 | else |
| 752 | return( newSect ); |
| 753 | } |
| 754 | |
| 755 | do { |
| 756 | if (adfReadEntryBlock(vol, nSect, &updEntry)!=RC_OK) |
| 757 | return -1; |
| 758 | if (updEntry.nameLen==len) { |
| 759 | myToUpper((uint8_t*)name3,(uint8_t*)updEntry.name,updEntry.nameLen,intl); |
| 760 | if (strncmp(name3,name2,len)==0) { |
| 761 | (*adfEnv.wFct)("adfCreateEntry : entry already exists"); |
| 762 | return -1; |
no test coverage detected