~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r3/posix/path-posix.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:
462
462
 
463
463
RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
464
464
{
 
465
    return RTPathQueryInfoEx(pszPath, pObjInfo, enmAdditionalAttribs, RTPATH_F_ON_LINK);
 
466
}
 
467
 
 
468
 
 
469
RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
 
470
{
465
471
    /*
466
472
     * Validate input.
467
473
     */
468
 
    AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
 
474
    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
469
475
    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
470
 
    AssertMsgReturn(VALID_PTR(pObjInfo), ("%p\n", pszPath), VERR_INVALID_POINTER);
 
476
    AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER);
471
477
    AssertMsgReturn(    enmAdditionalAttribs >= RTFSOBJATTRADD_NOTHING
472
478
                    &&  enmAdditionalAttribs <= RTFSOBJATTRADD_LAST,
473
479
                    ("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs),
474
480
                    VERR_INVALID_PARAMETER);
 
481
    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
475
482
 
476
483
    /*
477
484
     * Convert the filename.
481
488
    if (RT_SUCCESS(rc))
482
489
    {
483
490
        struct stat Stat;
484
 
        if (!stat(pszNativePath, &Stat))
 
491
        if (fFlags & RTPATH_F_FOLLOW_LINK)
 
492
            rc = stat(pszNativePath, &Stat);
 
493
        else
 
494
            rc = lstat(pszNativePath, &Stat); /** @todo how doesn't have lstat again? */
 
495
        if (!rc)
485
496
        {
486
497
            rtFsConvertStatToObjInfo(pObjInfo, &Stat, pszPath, 0);
487
498
            switch (enmAdditionalAttribs)
516
527
RTR3DECL(int) RTPathSetTimes(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
517
528
                             PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
518
529
{
 
530
    return RTPathSetTimesEx(pszPath, pAccessTime, pModificationTime, pChangeTime, pBirthTime, RTPATH_F_ON_LINK);
 
531
}
 
532
 
 
533
 
 
534
RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
 
535
                               PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags)
 
536
{
519
537
    /*
520
538
     * Validate input.
521
539
     */
522
 
    AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
523
 
    AssertMsgReturn(*pszPath, ("%p\n", pszPath), VERR_INVALID_PARAMETER);
524
 
    AssertMsgReturn(!pAccessTime || VALID_PTR(pAccessTime), ("%p\n", pAccessTime), VERR_INVALID_POINTER);
525
 
    AssertMsgReturn(!pModificationTime || VALID_PTR(pModificationTime), ("%p\n", pModificationTime), VERR_INVALID_POINTER);
526
 
    AssertMsgReturn(!pChangeTime || VALID_PTR(pChangeTime), ("%p\n", pChangeTime), VERR_INVALID_POINTER);
527
 
    AssertMsgReturn(!pBirthTime || VALID_PTR(pBirthTime), ("%p\n", pBirthTime), VERR_INVALID_POINTER);
 
540
    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
 
541
    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
 
542
    AssertPtrNullReturn(pAccessTime, VERR_INVALID_POINTER);
 
543
    AssertPtrNullReturn(pModificationTime, VERR_INVALID_POINTER);
 
544
    AssertPtrNullReturn(pChangeTime, VERR_INVALID_POINTER);
 
545
    AssertPtrNullReturn(pBirthTime, VERR_INVALID_POINTER);
 
546
    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
528
547
 
529
548
    /*
530
549
     * Convert the paths.
533
552
    int rc = rtPathToNative(&pszNativePath, pszPath);
534
553
    if (RT_SUCCESS(rc))
535
554
    {
 
555
        RTFSOBJINFO ObjInfo;
 
556
 
536
557
        /*
537
558
         * If it's a no-op, we'll only verify the existance of the file.
538
559
         */
539
560
        if (!pAccessTime && !pModificationTime)
540
 
        {
541
 
            struct stat Stat;
542
 
            if (!stat(pszNativePath, &Stat))
543
 
                rc = VINF_SUCCESS;
544
 
            else
545
 
            {
546
 
                rc = RTErrConvertFromErrno(errno);
547
 
                Log(("RTPathSetTimes('%s',,,,): failed with %Rrc and errno=%d\n", pszPath, rc, errno));
548
 
            }
549
 
        }
 
561
            rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, fFlags);
550
562
        else
551
563
        {
552
564
            /*
561
573
            }
562
574
            else
563
575
            {
564
 
                RTFSOBJINFO ObjInfo;
565
 
                int rc = RTPathQueryInfo(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX);
 
576
                rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, fFlags);
566
577
                if (RT_SUCCESS(rc))
567
578
                {
568
579
                    RTTimeSpecGetTimeval(pAccessTime        ? pAccessTime       : &ObjInfo.AccessTime,       &aTimevals[0]);
574
585
            }
575
586
            if (RT_SUCCESS(rc))
576
587
            {
577
 
                if (utimes(pszNativePath, aTimevals))
578
 
                {
579
 
                    rc = RTErrConvertFromErrno(errno);
 
588
                if (fFlags & RTPATH_F_FOLLOW_LINK)
 
589
                {
 
590
                    if (utimes(pszNativePath, aTimevals))
 
591
                        rc = RTErrConvertFromErrno(errno);
 
592
                }
 
593
#if (defined(RT_OS_DARWIN) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050) \
 
594
 || defined(RT_OS_FREEBSD) \
 
595
 || defined(RT_OS_LINUX) \
 
596
 || defined(RT_OS_OS2) /** @todo who really has lutimes? */
 
597
                else
 
598
                {
 
599
                    if (lutimes(pszNativePath, aTimevals))
 
600
                        rc = RTErrConvertFromErrno(errno);
 
601
                }
 
602
#else
 
603
                else
 
604
                {
 
605
                    if (pAccessTime && pModificationTime)
 
606
                        rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, fFlags);
 
607
                    if (RT_SUCCESS(rc) && RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
 
608
                        rc = VERR_NS_SYMLINK_SET_TIME;
 
609
                    else if (RT_SUCCESS(rc))
 
610
                    {
 
611
                        if (utimes(pszNativePath, aTimevals))
 
612
                            rc = RTErrConvertFromErrno(errno);
 
613
                    }
 
614
                }
 
615
#endif
 
616
                if (RT_FAILURE(rc))
580
617
                    Log(("RTPathSetTimes('%s',%p,%p,,): failed with %Rrc and errno=%d\n",
581
618
                         pszPath, pAccessTime, pModificationTime, rc, errno));
582
 
                }
583
619
            }
584
620
        }
585
621
        rtPathFreeNative(pszNativePath);
787
823
 
788
824
RTDECL(bool) RTPathExists(const char *pszPath)
789
825
{
 
826
    return RTPathExistsEx(pszPath, RTPATH_F_FOLLOW_LINK);
 
827
}
 
828
 
 
829
 
 
830
RTDECL(bool) RTPathExistsEx(const char *pszPath, uint32_t fFlags)
 
831
{
790
832
    /*
791
833
     * Validate input.
792
834
     */
793
835
    AssertPtrReturn(pszPath, false);
794
836
    AssertReturn(*pszPath, false);
 
837
    Assert(RTPATH_F_IS_VALID(fFlags, 0));
795
838
 
796
839
    /*
797
840
     * Convert the path and check if it exists using stat().
801
844
    if (RT_SUCCESS(rc))
802
845
    {
803
846
        struct stat Stat;
804
 
        if (!stat(pszNativePath, &Stat))
 
847
        if (fFlags & RTPATH_F_FOLLOW_LINK)
 
848
            rc = stat(pszNativePath, &Stat);
 
849
        else
 
850
            rc = lstat(pszNativePath, &Stat);
 
851
        if (!rc)
805
852
            rc = VINF_SUCCESS;
806
853
        else
807
854
            rc = VERR_GENERAL_FAILURE;