Changeset 33903 in vbox for trunk/src/VBox/Runtime/common/vfs
- Timestamp:
- Nov 9, 2010 2:44:55 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 67559
- Location:
- trunk/src/VBox/Runtime/common/vfs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r33867 r33903 914 914 RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead) 915 915 { 916 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); 917 if (pcbRead) 918 *pcbRead = 0; 916 919 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 917 920 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); … … 931 934 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten) 932 935 { 936 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); 937 if (pcbWritten) 938 *pcbWritten = 0; 933 939 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 934 940 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); … … 948 954 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 949 955 { 956 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); 957 if (pcbRead) 958 *pcbRead = 0; 950 959 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 951 960 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 952 961 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 953 962 AssertPtr(pSgBuf); 954 AssertReturn(fBlocking || VALID_PTR(pcbRead), VERR_INVALID_PARAMETER);963 AssertReturn(fBlocking || pcbRead, VERR_INVALID_PARAMETER); 955 964 956 965 RTVFS_WRITE_LOCK(pThis->hSemRW); … … 963 972 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 964 973 { 974 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); 975 if (pcbWritten) 976 *pcbWritten = 0; 965 977 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 966 978 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 967 979 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 968 980 AssertPtr(pSgBuf); 969 AssertReturn(fBlocking || VALID_PTR(pcbWritten), VERR_INVALID_PARAMETER);981 AssertReturn(fBlocking || pcbWritten, VERR_INVALID_PARAMETER); 970 982 971 983 RTVFS_WRITE_LOCK(pThis->hSemRW); -
trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp
r33860 r33903 84 84 85 85 /** 86 * RTFileRead and RTFileReadAt does not return VINF_EOF or VINF_TRY_AGAIN, this 87 * function tries to fix this as best as it can. 88 * 89 * This fixing can be subject to races if some other thread or process is 90 * modifying the file size between the read and our size query here. 91 * 92 * @returns VINF_SUCCESS, VINF_EOF or VINF_TRY_AGAIN. 93 * @param pThis The instance data. 94 * @param off The offset parameter. 95 * @param cbToRead The number of bytes attempted read . 96 * @param cbActuallyRead The number of bytes actually read. 97 */ 98 DECLINLINE(int) rtVfsStdFile_ReadFixRC(PRTVFSSTDFILE pThis, RTFOFF off, size_t cbToRead, size_t cbActuallyRead) 99 { 100 /* If the read returned less bytes than requested, it means the end of the 101 file has been reached. */ 102 if (cbToRead > cbActuallyRead) 103 return VINF_EOF; 104 105 /* The other case here is the very special zero byte read at the end of the 106 file, where we're supposed to indicate EOF. */ 107 if (cbToRead > 0) 108 return VINF_SUCCESS; 109 110 uint64_t cbFile; 111 int rc = RTFileGetSize(pThis->hFile, &cbFile); 112 if (RT_FAILURE(rc)) 113 return rc; 114 115 uint64_t off2; 116 if (off >= 0) 117 off2 = off; 118 else 119 { 120 rc = RTFileSeek(pThis->hFile, 0, RTFILE_SEEK_CURRENT, &off2); 121 if (RT_FAILURE(rc)) 122 return rc; 123 } 124 125 return off2 >= cbFile ? VINF_EOF : VINF_SUCCESS; 126 } 127 128 129 /** 86 130 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 87 131 */ … … 95 139 { 96 140 if (off < 0) 97 rc = RTFileRead( pThis->hFile,pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead);141 rc = RTFileRead( pThis->hFile, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead); 98 142 else 99 143 rc = RTFileReadAt(pThis->hFile, off, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead); 144 if (rc == VINF_SUCCESS && pcbRead) 145 rc = rtVfsStdFile_ReadFixRC(pThis, off, pSgBuf->paSegs[0].cbSeg, *pcbRead); 100 146 } 101 147 else 102 148 { 149 size_t cbSeg = 0; 103 150 size_t cbRead = 0; 104 size_t cbReadSeg; 105 size_t *pcbReadSeg = pcbRead ? &cbReadSeg : NULL; 151 size_t cbReadSeg = 0; 106 152 rc = VINF_SUCCESS; 107 153 108 154 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 109 155 { 110 void *pvSeg= pSgBuf->paSegs[iSeg].pvSeg;111 size_t cbSeg= pSgBuf->paSegs[iSeg].cbSeg;112 113 cbReadSeg = 0;156 void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg; 157 cbSeg = pSgBuf->paSegs[iSeg].cbSeg; 158 159 cbReadSeg = cbSeg; 114 160 if (off < 0) 115 rc = RTFileRead( pThis->hFile, pvSeg, cbSeg, pcbReadSeg);161 rc = RTFileRead( pThis->hFile, pvSeg, cbSeg, pcbRead ? &cbReadSeg : NULL); 116 162 else 117 { 118 rc = RTFileReadAt(pThis->hFile, off, pvSeg, cbSeg, pcbReadSeg); 119 off += cbSeg; 120 } 163 rc = RTFileReadAt(pThis->hFile, off, pvSeg, cbSeg, pcbRead ? &cbReadSeg : NULL); 121 164 if (RT_FAILURE(rc)) 122 165 break; 123 if (pcbRead) 124 { 125 cbRead += cbReadSeg; 126 if (cbReadSeg != cbSeg) 127 break; 128 } 166 if (off < 0) 167 off += cbReadSeg; 168 cbRead += cbReadSeg; 169 if ((pcbRead && cbReadSeg != cbSeg) || rc != VINF_SUCCESS) 170 break; 129 171 } 130 172 131 173 if (pcbRead) 174 { 132 175 *pcbRead = cbRead; 176 if (rc == VINF_SUCCESS) 177 rc = rtVfsStdFile_ReadFixRC(pThis, off, cbSeg, cbReadSeg); 178 } 133 179 } 134 180
Note:
See TracChangeset
for help on using the changeset viewer.