static APIRET changeDir(ServerData * pServerData, struct chdir * pchdir) { int iExtent; if (VERIFYFIXED(pchdir->szDir) || verifyPathName(pchdir->szDir)) return ERROR_INVALID_PARAMETER; logMsg(L_DBG, "CD_EXPLICIT, curdir=%s, newdir=%s", pchdir->cdfsi.cdi_curdir, pchdir->szDir); /* Walk the directory tree to find the name in szDir. */ iExtent=isoQueryDirExtentFromPath( pchdir->pVolData, pchdir->pVolData->iRootExtent, pchdir->szDir + 2, NULL); if(!iExtent) { return ERROR_PATH_NOT_FOUND; } return NO_ERROR; }
APIRET fsMkDir(ServerData * pServerData, struct mkdir * pmkdir) { CoreResult cr; APIRET rc; VolData * pVolData; CryptedVolume * pVolume; CHAR szName[CCHMAXPATH]; CryptedFileID idDir, idFile, idNewDir; CryptedFileInfo info; pmkdir->oError = 0; if (VERIFYFIXED(pmkdir->szName) || verifyPathName(pmkdir->szName)) return ERROR_INVALID_PARAMETER; GET_VOLUME(pmkdir); pVolume = pVolData->pVolume; logMsg(L_DBG, "FS_MKDIR, szName=%s, fsFlags=%d", pmkdir->szName, pmkdir->fsFlags); cr = findFromCurDir(pVolData, pmkdir->szName, &pmkdir->cdfsi, &pmkdir->cdfsd, pmkdir->iCurDirEnd, &idDir, &idFile, 0, szName); if (!idDir) return coreResultToOS2(cr); if (cr == CORERC_OK) return ERROR_ACCESS_DENIED; if (cr != CORERC_FILE_NOT_FOUND) return coreResultToOS2(cr); /* No. Create a new directory. */ memset(&info, 0, sizeof(info)); info.flFlags = CFF_IFDIR | 0700; /* rwx for user */ info.cRefs = 1; info.cbFileSize = 0; info.timeWrite = info.timeAccess = info.timeCreation = curTime(); info.idParent = idDir; /* uid and gid are set to 0 */ cr = coreCreateBaseFile(pVolume, &info, &idNewDir); if (cr) return coreResultToOS2(cr); /* Set the extended attributes. */ if (pmkdir->fHasEAs) { rc = addEAs(pVolume, idNewDir, (PFEALIST) pServerData->pData); if (rc) { coreDeleteFile(pVolume, idNewDir); return rc; } } /* Add the directory to the parent directory. */ cr = coreAddEntryToDir(pVolume, idDir, szName, idNewDir, 0); if (cr) { coreDeleteFile(pVolume, idNewDir); return coreResultToOS2(cr); } return NO_ERROR; }
APIRET fsRmDir(ServerData * pServerData, struct rmdir * prmdir) { if (VERIFYFIXED(prmdir->szName) || verifyPathName(prmdir->szName)) return ERROR_INVALID_PARAMETER; logMsg(L_DBG, "FS_RMDIR, szName=%s", prmdir->szName); return ERROR_WRITE_PROTECT; }
APIRET fsMkDir(ServerData * pServerData, struct mkdir * pmkdir) { pmkdir->oError = 0; if (VERIFYFIXED(pmkdir->szName) || verifyPathName(pmkdir->szName)) return ERROR_INVALID_PARAMETER; logMsg(L_DBG, "FS_CHDIR, szName=%s, fsFlags=%d", pmkdir->szName, pmkdir->fsFlags); return ERROR_WRITE_PROTECT; }
APIRET fsRmDir(ServerData * pServerData, struct rmdir * prmdir) { CoreResult cr; VolData * pVolData; CryptedVolume * pVolume; CHAR szName[CCHMAXPATH]; CryptedFileID idDir; CryptedFileID idFile; CryptedDirEntry * pFirstEntry; if (VERIFYFIXED(prmdir->szName) || verifyPathName(prmdir->szName)) return ERROR_INVALID_PARAMETER; GET_VOLUME(prmdir); pVolume = pVolData->pVolume; logMsg(L_DBG, "FS_RMDIR, szName=%s", prmdir->szName); cr = findFromCurDir(pVolData, prmdir->szName, &prmdir->cdfsi, &prmdir->cdfsd, prmdir->iCurDirEnd, &idDir, &idFile, 0, szName); if (cr) return coreResultToOS2(cr); /* Yes. Read the directory contents. (This implicitly makes sure that pFile is a directory. */ cr = coreQueryDirEntries(pVolume, idFile, &pFirstEntry); if (cr || pFirstEntry) { coreFreeDirEntries(pFirstEntry); return cr ? coreResultToOS2(cr) : ERROR_CURRENT_DIRECTORY; } /* The directory is empty, so we can proceed with the deletion. */ /* Remove the directory from its parent directory. */ cr = coreMoveDirEntry(pVolume, szName, idDir, 0, 0); if (cr) return coreResultToOS2(cr); /* Delete the directory. */ cr = coreDeleteFile(pVolume, idFile); if (cr) return coreResultToOS2(cr); return NO_ERROR; }
APIRET fsPathInfo(ServerData * pServerData, struct pathinfo * ppathinfo) { CoreResult cr; VolData * pVolData; CryptedVolume * pVolume; CHAR szName[CCHMAXPATH]; CryptedFileID idDir; CryptedFileID idFile; CryptedDirEntry * pDirEntry; bool fHidden; if (VERIFYFIXED(ppathinfo->szName) || verifyPathName(ppathinfo->szName)) return ERROR_INVALID_PARAMETER; GET_VOLUME(ppathinfo); pVolume = pVolData->pVolume; logMsg(L_DBG, "FS_PATHINFO, szName=%s, usLevel=%hd, " "cbData=%hd, fsFlag=%04hx", ppathinfo->szName, ppathinfo->usLevel, ppathinfo->cbData, ppathinfo->fsFlag); cr = findFromCurDir(pVolData, ppathinfo->szName, &ppathinfo->cdfsi, &ppathinfo->cdfsd, ppathinfo->iCurDirEnd, &idDir, &idFile, &pDirEntry, szName); if (cr) return coreResultToOS2(cr); fHidden = pDirEntry->flFlags & CDF_HIDDEN; coreFreeDirEntries(pDirEntry); return doFileInfo( 0, ppathinfo->fsFlag, ppathinfo->usLevel, pVolData, idFile, idDir, fHidden, ppathinfo->cbData, (char *) pServerData->pData); }
static APIRET changeDir(ServerData * pServerData, struct chdir * pchdir) { CoreResult cr; VolData * pVolData; CryptedVolume * pVolume; CryptedFileID idDir; CryptedFileInfo info; if (VERIFYFIXED(pchdir->szDir) || verifyPathName(pchdir->szDir)) return ERROR_INVALID_PARAMETER; GET_VOLUME(pchdir); pVolume = pVolData->pVolume; logMsg(L_DBG, "CD_EXPLICIT, newdir=%s", pchdir->szDir); cr = findFromCurDir2(pVolData, pchdir->szDir, &pchdir->cdfsi, &pchdir->cdfsd, pchdir->iCurDirEnd, &idDir, 0); if (cr) return coreResultToOS2(cr); /* Get info */ cr = coreQueryFileInfo(pVolume, idDir, &info); if (cr) return coreResultToOS2(cr); /* Is this really a directory? */ if (!CFF_ISDIR(info.flFlags)) /* This error code is not entirely concise, but it's what OS/2 wants to see. */ return ERROR_PATH_NOT_FOUND; pchdir->cdfsd.data[0] = idDir; return NO_ERROR; }
APIRET fsFileAttribute(ServerData * pServerData, struct fileattribute * pfileattribute) { CoreResult cr; VolData * pVolData; CryptedVolume * pVolume; CHAR szName[CCHMAXPATH]; CryptedFileID idDir; CryptedFileID idFile; CryptedFileInfo info, info2; CryptedDirEntry * pDirEntry; bool fHidden; if (VERIFYFIXED(pfileattribute->szName) || verifyPathName(pfileattribute->szName)) return ERROR_INVALID_PARAMETER; GET_VOLUME(pfileattribute); pVolume = pVolData->pVolume; logMsg(L_DBG, "FS_FILEATTRIBUTE, szName=%s, fsFlag=%hd, fsAttr=%hd", pfileattribute->szName, pfileattribute->fsFlag, pfileattribute->fsAttr); cr = findFromCurDir(pVolData, pfileattribute->szName, &pfileattribute->cdfsi, &pfileattribute->cdfsd, pfileattribute->iCurDirEnd, &idDir, &idFile, &pDirEntry, szName); if (cr) return coreResultToOS2(cr); fHidden = pDirEntry->flFlags & CDF_HIDDEN; coreFreeDirEntries(pDirEntry); /* Access the file and get file info. */ cr = coreQueryFileInfo(pVolume, idFile, &info); if (cr) return coreResultToOS2(cr); if (pfileattribute->fsFlag & FA_SET) { /* Set the file attributes. */ /* Update the hidden flag in the directory, if necessary. */ if (!beq(fHidden, pfileattribute->fsAttr & FILE_HIDDEN)) { cr = setHiddenFlag(pVolume, idDir, idFile, pfileattribute->fsAttr & FILE_HIDDEN); if (cr) return coreResultToOS2(cr); } /* Update the flags in the info sector, if necessary. */ info2 = info; extractDOSAttr(pfileattribute->fsAttr, &info2); if (info2.flFlags != info.flFlags) { cr = coreSetFileInfo(pVolume, idFile, &info2); if (cr) return coreResultToOS2(cr); } return NO_ERROR; } else { /* Query the file attributes. */ pfileattribute->fsAttr = makeDOSAttr(fHidden, &info); return NO_ERROR; } }
APIRET fsFindFirst(ServerData * pServerData, struct findfirst * pfindfirst) { APIRET rc; CryptedVolume * pVolume = pfindfirst->pVolData->pVolume; CHAR szDir[CCHMAXPATH]; SearchData * pSearchData; PGEALIST pgeas = 0; struct iso_directory_record * idr; IsoDirEntry* pIsoDirEntry=NULL; int iSize; int iExtent; pfindfirst->pSearchData = 0; if (VERIFYFIXED(pfindfirst->szName) || verifyPathName(pfindfirst->szName)) return ERROR_INVALID_PARAMETER; logMsg(L_DBG, "FS_FINDFIRST, curdir=%s, name=%s, " "iCurDirEnd=%d, fsAttr=%04hx, cMatch=%d, " "usLevel=%d, fsFlags=%04hx, cbData=%d", pfindfirst->cdfsi.cdi_curdir, pfindfirst->szName, pfindfirst->iCurDirEnd, pfindfirst->fsAttr, pfindfirst->cMatch, pfindfirst->usLevel, pfindfirst->fsFlags, pfindfirst->cbData); /* FIL_STANDARD : 1 FIL_QUERYEASIZE : 2 FIL_QUERYEASFROMLIST : 3 */ if (pfindfirst->usLevel != FIL_STANDARD && pfindfirst->usLevel != FIL_QUERYEASIZE && pfindfirst->usLevel != FIL_QUERYEASFROMLIST ) { logMsg(L_EVIL, "unknown FS_FINDFIRST info level: %d", pfindfirst->usLevel); return ERROR_NOT_SUPPORTED; } /* Allocate the SearchData structure. */ pSearchData = malloc(sizeof(SearchData)); if (!pSearchData) return ERROR_NOT_ENOUGH_MEMORY; pSearchData->pFirstInIsoDir = 0; pSearchData->flAttr = pfindfirst->fsAttr; /* Split the search specification. */ splitPath(pfindfirst->szName + 2, szDir, pSearchData->szName); logMsg(L_DBG, "dir=%s, spec=%s", szDir, pSearchData->szName); if (!*pSearchData->szName) { freeSearchData(pSearchData); return ERROR_INVALID_PARAMETER; } if(strlen(szDir)) { /* Walk the directory tree to find the name in szDir. */ pIsoDirEntry=isoQueryIsoEntryFromPath( pfindfirst->pVolData, szDir); if(!pIsoDirEntry) { logMsg(L_DBG, "Entry for %s not found", szDir); freeSearchData(pSearchData); return ERROR_PATH_NOT_FOUND; } logMsg(L_DBG, "Entry for %s found.", szDir); iExtent=pIsoDirEntry->iExtent; iSize=pIsoDirEntry->iSize; if(!S_ISDIR(pIsoDirEntry->fstat_buf.st_mode)) { free(pIsoDirEntry); logMsg(L_DBG, "Entry is not an directory", szDir); freeSearchData(pSearchData); return ERROR_PATH_NOT_FOUND; } free(pIsoDirEntry); } else { iExtent=pfindfirst->pVolData->iRootExtent; /* Get the contents of the directory from ISO file. */ idr=(struct iso_directory_record *)pfindfirst->pVolData->ipd.root_directory_record; iSize=isonum_733((unsigned char *)idr->size); } pIsoDirEntry=getDirEntries(szDir, iExtent, iSize, pfindfirst->pVolData, 0); pSearchData->pFirstInIsoDir=pIsoDirEntry; pSearchData->pIsoNext=pIsoDirEntry; if(pIsoDirEntry) { #if 0 logMsg(L_DBG, "Found following entries:"); do { logMsg(L_DBG, "Name is: %s, extent: %d, parent extent: %d", pIsoDirEntry->chrName,pIsoDirEntry->iExtent,pIsoDirEntry->iParentExtent); pIsoDirEntry=pIsoDirEntry->pNext; }while(pIsoDirEntry); #endif } else { freeSearchData(pSearchData); return ERROR_FILE_NOT_FOUND; } /* The GEAs are stored in the exchange buffer which is about to be overwritten; so make a copy. */ if (pfindfirst->usLevel == FIL_QUERYEASFROMLIST) { pgeas = alloca(((PGEALIST) pServerData->pData)->cbList); memcpy(pgeas, pServerData->pData, ((PGEALIST) pServerData->pData)->cbList); } /* Store up to the requested number of items. */ rc = storeDirContents( pVolume, pSearchData, pgeas, (char *) pServerData->pData, pfindfirst->cbData, pfindfirst->usLevel, &pfindfirst->cMatch, pfindfirst->fsFlags); if (rc && (rc != ERROR_EAS_DIDNT_FIT)) { freeSearchData(pSearchData); return rc; } logMsg(L_DBG, "%d entries returned", pfindfirst->cMatch); #if 0 /*!! ???????????*/ if(!pfindfirst->cMatch) { freeSearchData(pSearchData); /*return ERROR_NO_MORE_FILES;*/ return ERROR_FILE_NOT_FOUND; } #endif pfindfirst->pSearchData = pSearchData; pfindfirst->pVolData->cSearches++; return rc; }