Changeset 82843 in vbox for trunk/src/VBox
- Timestamp:
- Jan 23, 2020 10:40:42 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/tools/RTFTPServer.cpp
r82842 r82843 73 73 /** The relative current working directory (CWD) to szRootDir. */ 74 74 char szCWD[RTPATH_MAX]; 75 RTFILE hFile;76 75 } FTPSERVERDATA; 77 76 typedef FTPSERVERDATA *PFTPSERVERDATA; 78 77 79 typedef struct FTPDIRHANDLE 80 { 81 /** The VFS (chain) handle to use for this directory. */ 82 RTVFSDIR hVfsDir; 83 } FTPDIRHANDLE; 84 typedef FTPDIRHANDLE *PFTPDIRHANDLE; 78 /** 79 * Enumeration specifying the VFS handle type of the FTP server. 80 */ 81 typedef enum FTPSERVERVFSHANDLETYPE 82 { 83 FTPSERVERVFSHANDLETYPE_INVALID = 0, 84 FTPSERVERVFSHANDLETYPE_FILE, 85 FTPSERVERVFSHANDLETYPE_DIR, 86 /** The usual 32-bit hack. */ 87 FTPSERVERVFSHANDLETYPE_32BIT_HACK = 0x7fffffff 88 } FTPSERVERVFSHANDLETYPE; 89 90 /** 91 * Structure for keeping a VFS handle of the FTP server. 92 */ 93 typedef struct FTPSERVERVFSHANDLE 94 { 95 /** The type of the handle, stored in the union below. */ 96 FTPSERVERVFSHANDLETYPE enmType; 97 union 98 { 99 /** The VFS (chain) handle to use for this file. */ 100 RTVFSFILE hVfsFile; 101 /** The VFS (chain) handle to use for this directory. */ 102 RTVFSDIR hVfsDir; 103 } u; 104 } FTPSERVERVFSHANDLE; 105 typedef FTPSERVERVFSHANDLE *PFTPSERVERVFSHANDLE; 85 106 86 107 … … 207 228 static DECLCALLBACK(int) onFileOpen(PRTFTPCALLBACKDATA pData, const char *pcszPath, uint32_t fMode, void **ppvHandle) 208 229 { 209 RT_NOREF(ppvHandle);210 211 230 PFTPSERVERDATA pThis = (PFTPSERVERDATA)pData->pvUser; 212 231 Assert(pData->cbUser == sizeof(FTPSERVERDATA)); 232 233 PFTPSERVERVFSHANDLE pHandle = (PFTPSERVERVFSHANDLE)RTMemAllocZ(sizeof(FTPSERVERVFSHANDLE)); 234 if (!pHandle) 235 return VERR_NO_MEMORY; 213 236 214 237 char *pszPathAbs = NULL; … … 216 239 return VERR_NO_MEMORY; 217 240 218 int rc = RTFileOpen(&pThis->hFile, pszPathAbs, fMode); 241 int rc = RTVfsChainOpenFile(pszPathAbs, fMode, &pHandle->u.hVfsFile, NULL /*poffError */, NULL /* pErrInfo */); 242 if (RT_SUCCESS(rc)) 243 { 244 pHandle->enmType = FTPSERVERVFSHANDLETYPE_FILE; 245 246 *ppvHandle = pHandle; 247 } 248 else 249 RTMemFree(pHandle); 219 250 220 251 RTStrFree(pszPathAbs); … … 225 256 static DECLCALLBACK(int) onFileRead(PRTFTPCALLBACKDATA pData, void *pvHandle, void *pvBuf, size_t cbToRead, size_t *pcbRead) 226 257 { 227 RT_NOREF(pvHandle); 228 229 PFTPSERVERDATA pThis = (PFTPSERVERDATA)pData->pvUser; 230 Assert(pData->cbUser == sizeof(FTPSERVERDATA)); 231 232 return RTFileRead(pThis->hFile, pvBuf, cbToRead, pcbRead); 258 RT_NOREF(pData); 259 260 PFTPSERVERVFSHANDLE pHandle = (PFTPSERVERVFSHANDLE)pvHandle; 261 AssertPtrReturn(pHandle, VERR_INVALID_POINTER); 262 AssertReturn(pHandle->enmType == FTPSERVERVFSHANDLETYPE_FILE, VERR_INVALID_PARAMETER); 263 264 return RTVfsFileRead(pHandle->u.hVfsFile, pvBuf, cbToRead, pcbRead); 233 265 } 234 266 235 267 static DECLCALLBACK(int) onFileClose(PRTFTPCALLBACKDATA pData, void *pvHandle) 236 268 { 237 RT_NOREF(pvHandle); 238 239 PFTPSERVERDATA pThis = (PFTPSERVERDATA)pData->pvUser; 240 Assert(pData->cbUser == sizeof(FTPSERVERDATA)); 241 242 int rc = RTFileClose(pThis->hFile); 269 RT_NOREF(pData); 270 271 PFTPSERVERVFSHANDLE pHandle = (PFTPSERVERVFSHANDLE)pvHandle; 272 AssertPtrReturn(pHandle, VERR_INVALID_POINTER); 273 AssertReturn(pHandle->enmType == FTPSERVERVFSHANDLETYPE_FILE, VERR_INVALID_PARAMETER); 274 275 int rc = RTVfsFileRelease(pHandle->u.hVfsFile); 243 276 if (RT_SUCCESS(rc)) 244 277 { 245 pThis->hFile = NIL_RTFILE; 278 RTMemFree(pvHandle); 279 pvHandle = NULL; 246 280 } 247 281 … … 342 376 Assert(pData->cbUser == sizeof(FTPSERVERDATA)); 343 377 344 PFTP DIRHANDLE pHandle = (PFTPDIRHANDLE)RTMemAllocZ(sizeof(FTPDIRHANDLE));378 PFTPSERVERVFSHANDLE pHandle = (PFTPSERVERVFSHANDLE)RTMemAllocZ(sizeof(FTPSERVERVFSHANDLE)); 345 379 if (!pHandle) 346 380 return VERR_NO_MEMORY; … … 353 387 RTPrintf("Opening directory '%s'\n", pszPathAbs); 354 388 355 int rc = RTVfsChainOpenDir(pszPathAbs, 0 /*fFlags*/, &pHandle-> hVfsDir, NULL /* poffError */, NULL /* pErrInfo */);389 int rc = RTVfsChainOpenDir(pszPathAbs, 0 /*fFlags*/, &pHandle->u.hVfsDir, NULL /* poffError */, NULL /* pErrInfo */); 356 390 if (RT_SUCCESS(rc)) 357 391 { 392 pHandle->enmType = FTPSERVERVFSHANDLETYPE_DIR; 393 358 394 *ppvHandle = pHandle; 359 395 } … … 372 408 RT_NOREF(pData); 373 409 374 PFTP DIRHANDLE pHandle = (PFTPDIRHANDLE)pvHandle;410 PFTPSERVERVFSHANDLE pHandle = (PFTPSERVERVFSHANDLE)pvHandle; 375 411 AssertPtrReturn(pHandle, VERR_INVALID_POINTER); 376 377 RTVfsDirRelease(pHandle->hVfsDir); 412 AssertReturn(pHandle->enmType == FTPSERVERVFSHANDLETYPE_DIR, VERR_INVALID_PARAMETER); 413 414 RTVfsDirRelease(pHandle->u.hVfsDir); 378 415 379 416 RTMemFree(pHandle); … … 389 426 RT_NOREF(ppszTarget); /* No symlinks yet */ 390 427 391 PFTP DIRHANDLE pHandle = (PFTPDIRHANDLE)pvHandle;428 PFTPSERVERVFSHANDLE pHandle = (PFTPSERVERVFSHANDLE)pvHandle; 392 429 AssertPtrReturn(pHandle, VERR_INVALID_POINTER); 430 AssertReturn(pHandle->enmType == FTPSERVERVFSHANDLETYPE_DIR, VERR_INVALID_PARAMETER); 393 431 394 432 size_t cbDirEntryAlloced = sizeof(RTDIRENTRYEX); … … 402 440 { 403 441 size_t cbDirEntry = cbDirEntryAlloced; 404 rc = RTVfsDirReadEx(pHandle-> hVfsDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX);442 rc = RTVfsDirReadEx(pHandle->u.hVfsDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX); 405 443 if (RT_FAILURE(rc)) 406 444 { … … 422 460 { 423 461 RTFSOBJINFO OwnerInfo; 424 rc = RTVfsDirQueryPathInfo(pHandle-> hVfsDir,462 rc = RTVfsDirQueryPathInfo(pHandle->u.hVfsDir, 425 463 pDirEntry->szName, &OwnerInfo, RTFSOBJATTRADD_UNIX_OWNER, RTPATH_F_ON_LINK); 426 464 if ( RT_SUCCESS(rc) … … 437 475 { 438 476 RTFSOBJINFO GroupInfo; 439 rc = RTVfsDirQueryPathInfo(pHandle-> hVfsDir,477 rc = RTVfsDirQueryPathInfo(pHandle->u.hVfsDir, 440 478 pDirEntry->szName, &GroupInfo, RTFSOBJATTRADD_UNIX_GROUP, RTPATH_F_ON_LINK); 441 479 if ( RT_SUCCESS(rc)
Note:
See TracChangeset
for help on using the changeset viewer.