~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r3/win/path-win.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
 
188
188
RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
189
189
{
 
190
    return RTPathQueryInfoEx(pszPath, pObjInfo, enmAdditionalAttribs, RTPATH_F_ON_LINK);
 
191
}
 
192
 
 
193
 
 
194
RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
 
195
{
190
196
    /*
191
197
     * Validate input.
192
198
     */
193
 
    if (!pszPath)
194
 
    {
195
 
        AssertMsgFailed(("Invalid pszPath=%p\n", pszPath));
196
 
        return VERR_INVALID_PARAMETER;
197
 
    }
198
 
    if (!pObjInfo)
199
 
    {
200
 
        AssertMsgFailed(("Invalid pObjInfo=%p\n", pObjInfo));
201
 
        return VERR_INVALID_PARAMETER;
202
 
    }
203
 
    if (    enmAdditionalAttribs < RTFSOBJATTRADD_NOTHING
204
 
        ||  enmAdditionalAttribs > RTFSOBJATTRADD_LAST)
205
 
    {
206
 
        AssertMsgFailed(("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs));
207
 
        return VERR_INVALID_PARAMETER;
208
 
    }
 
199
    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
 
200
    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
 
201
    AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER);
 
202
    AssertMsgReturn(    enmAdditionalAttribs >= RTFSOBJATTRADD_NOTHING
 
203
                    &&  enmAdditionalAttribs <= RTFSOBJATTRADD_LAST,
 
204
                    ("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs),
 
205
                    VERR_INVALID_PARAMETER);
 
206
    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
209
207
 
210
208
    /*
211
209
     * Query file info.
218
216
        return rc;
219
217
    if (!GetFileAttributesExW(pwszPath, GetFileExInfoStandard, &Data))
220
218
    {
221
 
        rc = RTErrConvertFromWin32(GetLastError());
222
 
        RTUtf16Free(pwszPath);
223
 
        return rc;
 
219
        /* Fallback to FindFileFirst in case of sharing violation. */
 
220
        if (GetLastError() == ERROR_SHARING_VIOLATION)
 
221
        {
 
222
            WIN32_FIND_DATAW FindData;
 
223
            HANDLE hDir = FindFirstFileW(pwszPath, &FindData);
 
224
            if (hDir == INVALID_HANDLE_VALUE)
 
225
            {
 
226
                rc = RTErrConvertFromWin32(GetLastError());
 
227
                RTUtf16Free(pwszPath);
 
228
                return rc;
 
229
            }
 
230
            FindClose(hDir);
 
231
            Data.dwFileAttributes = FindData.dwFileAttributes;
 
232
            Data.ftCreationTime = FindData.ftCreationTime;
 
233
            Data.ftLastAccessTime = FindData.ftLastAccessTime;
 
234
            Data.ftLastWriteTime = FindData.ftLastWriteTime;
 
235
            Data.nFileSizeHigh = FindData.nFileSizeHigh;
 
236
            Data.nFileSizeLow = FindData.nFileSizeLow;
 
237
        }
 
238
        else
 
239
        {
 
240
            rc = RTErrConvertFromWin32(GetLastError());
 
241
            RTUtf16Free(pwszPath);
 
242
            return rc;
 
243
        }
224
244
    }
225
245
    RTUtf16Free(pwszPath);
226
246
#else
227
247
    if (!GetFileAttributesExA(pszPath, GetFileExInfoStandard, &Data))
228
 
        return RTErrConvertFromWin32(GetLastError());
229
 
#endif
 
248
    {
 
249
        /* Fallback to FindFileFirst in case of sharing violation. */
 
250
        if (GetLastError() != ERROR_SHARING_VIOLATION)
 
251
            return RTErrConvertFromWin32(GetLastError());
 
252
        WIN32_FIND_DATAA FindData;
 
253
        HANDLE hDir = FindFirstFileA(pszPath, &FindData);
 
254
        if (hDir == INVALID_HANDLE_VALUE)
 
255
            return RTErrConvertFromWin32(GetLastError());
 
256
        FindClose(hDir);
 
257
        Data.dwFileAttributes = FindData.dwFileAttributes;
 
258
        Data.ftCreationTime = FindData.ftCreationTime;
 
259
        Data.ftLastAccessTime = FindData.ftLastAccessTime;
 
260
        Data.ftLastWriteTime = FindData.ftLastWriteTime;
 
261
        Data.nFileSizeHigh = FindData.nFileSizeHigh;
 
262
        Data.nFileSizeLow = FindData.nFileSizeLow;
 
263
    }
 
264
#endif
 
265
    if (   (fFlags & RTPATH_F_FOLLOW_LINK)
 
266
        && (Data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
 
267
    {
 
268
#ifndef DEBUG_sandervl
 
269
        AssertFailed();
 
270
#endif
 
271
        /** @todo Symlinks: RTPathQueryInfoEx is not handling symbolic links
 
272
         *        correctly on Windows.  (Both GetFileAttributesEx and FileFindFirst
 
273
         *        will return info about the symlink.) */
 
274
    }
230
275
 
231
276
    /*
232
277
     * Setup the returned data.
282
327
RTR3DECL(int) RTPathSetTimes(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
283
328
                             PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
284
329
{
 
330
    return RTPathSetTimesEx(pszPath, pAccessTime, pModificationTime, pChangeTime, pBirthTime, RTPATH_F_ON_LINK);
 
331
}
 
332
 
 
333
 
 
334
RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
 
335
                               PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags)
 
336
{
285
337
    /*
286
338
     * Validate input.
287
339
     */
288
 
    AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
289
 
    AssertMsgReturn(*pszPath, ("%p\n", pszPath), VERR_INVALID_PARAMETER);
290
 
    AssertMsgReturn(!pAccessTime || VALID_PTR(pAccessTime), ("%p\n", pAccessTime), VERR_INVALID_POINTER);
291
 
    AssertMsgReturn(!pModificationTime || VALID_PTR(pModificationTime), ("%p\n", pModificationTime), VERR_INVALID_POINTER);
292
 
    AssertMsgReturn(!pChangeTime || VALID_PTR(pChangeTime), ("%p\n", pChangeTime), VERR_INVALID_POINTER);
293
 
    AssertMsgReturn(!pBirthTime || VALID_PTR(pBirthTime), ("%p\n", pBirthTime), VERR_INVALID_POINTER);
 
340
    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
 
341
    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
 
342
    AssertPtrNullReturn(pAccessTime, VERR_INVALID_POINTER);
 
343
    AssertPtrNullReturn(pModificationTime, VERR_INVALID_POINTER);
 
344
    AssertPtrNullReturn(pChangeTime, VERR_INVALID_POINTER);
 
345
    AssertPtrNullReturn(pBirthTime, VERR_INVALID_POINTER);
 
346
    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
294
347
 
295
348
    /*
296
349
     * Convert the path.
299
352
    int rc = RTStrToUtf16(pszPath, &pwszPath);
300
353
    if (RT_SUCCESS(rc))
301
354
    {
302
 
        HANDLE hFile = CreateFileW(pwszPath,
303
 
                                   FILE_WRITE_ATTRIBUTES,   /* dwDesiredAccess */
304
 
                                   FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
305
 
                                   NULL,                    /* security attribs */
306
 
                                   OPEN_EXISTING,           /* dwCreationDisposition */
307
 
                                   FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
308
 
                                   NULL);
 
355
        HANDLE hFile;
 
356
        if (fFlags & RTPATH_F_FOLLOW_LINK)
 
357
            hFile = CreateFileW(pwszPath,
 
358
                                FILE_WRITE_ATTRIBUTES,   /* dwDesiredAccess */
 
359
                                FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
 
360
                                NULL,                    /* security attribs */
 
361
                                OPEN_EXISTING,           /* dwCreationDisposition */
 
362
                                FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
 
363
                                NULL);
 
364
        else
 
365
        {
 
366
/** @todo Symlink: Test RTPathSetTimesEx on Windows. (The code is disabled
 
367
 *        because it's not tested yet.) */
 
368
#if 0 //def FILE_FLAG_OPEN_REPARSE_POINT
 
369
            hFile = CreateFileW(pwszPath,
 
370
                                FILE_WRITE_ATTRIBUTES,   /* dwDesiredAccess */
 
371
                                FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
 
372
                                NULL,                    /* security attribs */
 
373
                                OPEN_EXISTING,           /* dwCreationDisposition */
 
374
                                FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT,
 
375
                                NULL);
 
376
 
 
377
            if (hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_INVALID_PARAMETER)
 
378
#endif
 
379
                hFile = CreateFileW(pwszPath,
 
380
                                    FILE_WRITE_ATTRIBUTES,   /* dwDesiredAccess */
 
381
                                    FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, /* dwShareMode */
 
382
                                    NULL,                    /* security attribs */
 
383
                                    OPEN_EXISTING,           /* dwCreationDisposition */
 
384
                                    FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
 
385
                                    NULL);
 
386
        }
309
387
        if (hFile != INVALID_HANDLE_VALUE)
310
388
        {
311
389
            /*
444
522
}
445
523
 
446
524
 
447
 
/**
448
 
 * Checks if the path exists.
449
 
 *
450
 
 * Symbolic links will all be attempted resolved.
451
 
 *
452
 
 * @returns true if it exists and false if it doesn't
453
 
 * @param   pszPath     The path to check.
454
 
 */
455
525
RTDECL(bool) RTPathExists(const char *pszPath)
456
526
{
 
527
    return RTPathExistsEx(pszPath, RTPATH_F_FOLLOW_LINK);
 
528
}
 
529
 
 
530
 
 
531
RTDECL(bool) RTPathExistsEx(const char *pszPath, uint32_t fFlags)
 
532
{
457
533
    /*
458
534
     * Validate input.
459
535
     */
460
536
    AssertPtrReturn(pszPath, false);
461
537
    AssertReturn(*pszPath, false);
 
538
    Assert(RTPATH_F_IS_VALID(fFlags, 0));
462
539
 
463
540
    /*
464
541
     * Try query file info.
465
542
     */
 
543
    DWORD dwAttr;
466
544
#ifndef RT_DONT_CONVERT_FILENAMES
467
545
    PRTUTF16 pwszPath;
468
546
    int rc = RTStrToUtf16(pszPath, &pwszPath);
469
547
    if (RT_SUCCESS(rc))
470
548
    {
471
 
        if (GetFileAttributesW(pwszPath) == INVALID_FILE_ATTRIBUTES)
472
 
            rc = VERR_GENERAL_FAILURE;
 
549
        dwAttr = GetFileAttributesW(pwszPath);
473
550
        RTUtf16Free(pwszPath);
474
551
    }
 
552
    else
 
553
        dwAttr = INVALID_FILE_ATTRIBUTES;
475
554
#else
476
 
    int rc = VINF_SUCCESS;
477
 
    if (GetFileAttributesExA(pszPath) == INVALID_FILE_ATTRIBUTES)
478
 
        rc = VERR_GENERAL_FAILURE;
479
 
#endif
480
 
 
481
 
    return RT_SUCCESS(rc);
 
555
    dwAttr = GetFileAttributesA(pszPath);
 
556
#endif
 
557
 
 
558
    if (dwAttr == INVALID_FILE_ATTRIBUTES)
 
559
        return false;
 
560
 
 
561
#ifdef FILE_ATTRIBUTE_REPARSE_POINT
 
562
    if (   (fFlags & RTPATH_F_FOLLOW_LINK)
 
563
        && (dwAttr & FILE_ATTRIBUTE_REPARSE_POINT))
 
564
    {
 
565
        AssertFailed();
 
566
        /** @todo Symlinks: RTPathExists+RTPathExistsEx is misbehaving on symbolic
 
567
         *        links on Windows. */
 
568
    }
 
569
#endif
 
570
 
 
571
    return true;
482
572
}
483
573
 
484
574