VirtualBox

Changeset 1390 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Mar 9, 2007 8:52:00 PM (18 years ago)
Author:
vboxsync
Message:

A Quick hack to support single locks on samba shares. (TODO: needs per file handle data for tracking multiple locks if we ever will be needing multiple locks per file.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/darwin/filelock-darwin.cpp

    r1388 r1390  
    2929#include <sys/types.h>
    3030#include <sys/ioctl.h>
    31 #include <sys/fcntl.hs>
     31#include <sys/fcntl.h>
    3232#include <fcntl.h>
    3333#include <unistd.h>
     
    8080    if (fcntl(File, (fLock & RTFILE_LOCK_WAIT) ? F_SETLKW : F_SETLK, &fl) >= 0)
    8181        return VINF_SUCCESS;
     82    int iErr = errno;
     83    if (iErr == ENOTSUP)
     84    {
     85        /*
     86         * This is really bad hack for getting VDIs to work somewhat
     87         * safely on SMB mounts.
     88         */
     89        /** @todo we need to keep track of these locks really. Anyone requiring to lock more
     90         * than one part of a file will have to fix this. */
     91        unsigned f = 0;
     92        Assert(RTFILE_LOCK_WAIT);
     93        if (fLock & RTFILE_LOCK_WAIT)
     94            f |= LOCK_NB;
     95        if (fLock & RTFILE_LOCK_WRITE)
     96            f |= LOCK_EX;
     97        else
     98            f |= LOCK_SH;
     99        if (!flock(File, f))
     100            return VINF_SUCCESS;
     101        iErr = errno;
     102        if (iErr == EWOULDBLOCK)
     103            return VERR_FILE_LOCK_VIOLATION;
     104    }
    82105
    83     int iErr = errno;
    84106    if (    iErr == EAGAIN
    85107        ||  iErr == EACCES)
     
    124146        return VINF_SUCCESS;
    125147
    126     /* @todo check error codes for non existing lock. */
    127148    int iErr = errno;
     149    if (iErr == ENOTSUP)
     150    {
     151        /* A SMB hack, see RTFileLock. */
     152        if (!flock(File, LOCK_UN))
     153            return VINF_SUCCESS;
     154    }
     155
     156    /** @todo check error codes for non existing lock. */
    128157    if (    iErr == EAGAIN
    129158        ||  iErr == EACCES)
     
    133162}
    134163
    135 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette