X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=blobdiff_plain;f=libatalk%2Fadouble%2Fad_lock.c;h=40ffd1407a2eb8a100bdb74269f194113aa604fd;hp=28b53b12edddc66842dfcf10e0fd79d2464b50e9;hb=d82952695132e6dc2de60655de1dccb805e2f26b;hpb=86fa17231b5daf7fb18ed30c201bfe15e0cb650d diff --git a/libatalk/adouble/ad_lock.c b/libatalk/adouble/ad_lock.c index 28b53b12..40ffd140 100644 --- a/libatalk/adouble/ad_lock.c +++ b/libatalk/adouble/ad_lock.c @@ -269,8 +269,8 @@ int start = off; } /* ------------------ */ -int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype, - const off_t off, const off_t len, const int fork) +static int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype, + const off_t off, const off_t len, const int fork) { #if 0 struct flock lock; @@ -457,6 +457,94 @@ static int testlock(struct ad_fd *adf, off_t off, off_t len) return 0; } + +/* ------------------------- +*/ +static int ad_fcntl_tmplock(struct adouble *ad, const u_int32_t eid, const int locktype, + const off_t off, const off_t len, const int fork) +{ + struct flock lock; + struct ad_fd *adf; + int err; + int type; + + lock.l_start = off; + type = locktype; + if (eid == ADEID_DFORK) { + adf = &ad->ad_data_fork; + } else { + /* FIXME META */ + adf = &ad->ad_resource_fork; + if (adf->adf_fd == -1) { + /* there's no resource fork. return success */ + return 0; + } + /* if ADLOCK_FILELOCK we want a lock from offset 0 + * it's used when deleting a file: + * in open we put read locks on meta datas + * in delete a write locks on the whole file + * so if the file is open by somebody else it fails + */ + if (!(type & ADLOCK_FILELOCK)) + lock.l_start += ad_getentryoff(ad, eid); + } + + if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) { + type = (type & ~ADLOCK_WR) | ADLOCK_RD; + } + + lock.l_type = XLATE_FCNTL_LOCK(type & ADLOCK_MASK); + lock.l_whence = SEEK_SET; + lock.l_len = len; + + /* see if it's locked by another fork. */ + if (fork && adf_findxlock(adf, fork, ADLOCK_WR | + ((type & ADLOCK_WR) ? ADLOCK_RD : 0), + lock.l_start, lock.l_len) > -1) { + errno = EACCES; + return -1; + } + + /* okay, we might have ranges byte-locked. we need to make sure that + * we restore the appropriate ranges once we're done. so, we check + * for overlap on an unlock and relock. + * XXX: in the future, all the byte locks will be sorted and contiguous. + * we just want to upgrade all the locks and then downgrade them + * here. */ + if (!adf->adf_excl) { + err = set_lock(adf->adf_fd, F_SETLK, &lock); + } + else { + err = 0; + } + if (!err && (lock.l_type == F_UNLCK)) + adf_relockrange(adf, adf->adf_fd, lock.l_start, len); + + return err; +} + +/* --------------------- */ +static void ad_fcntl_unlock(struct adouble *ad, const int fork) +{ + if (ad_data_fileno(ad) != -1) { + adf_unlock(&ad->ad_data_fork, fork); + } + if (ad_reso_fileno(ad) != -1) { + adf_unlock(&ad->ad_resource_fork, fork); + } + + if (ad->ad_flags != AD_VERSION_EA) { + return; + } + if (ad_meta_fileno(ad) != -1) { + adf_unlock(&ad->ad_metadata_fork, fork); + } +} + +/****************************************************************************** + * Public functions + ******************************************************************************/ + /* --------------- */ int ad_testlock(struct adouble *ad, int eid, const off_t off) { @@ -491,7 +579,7 @@ int ad_testlock(struct adouble *ad, int eid, const off_t off) - there's no locks held by another process (clients) - or we already know the answer and don't need to test. */ -u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits) +uint16_t ad_openforks(struct adouble *ad, u_int16_t attrbits) { return 0; #if 0 @@ -549,74 +637,6 @@ u_int16_t ad_openforks(struct adouble *ad, u_int16_t attrbits) #endif } -/* ------------------------- -*/ -int ad_fcntl_tmplock(struct adouble *ad, const u_int32_t eid, const int locktype, - const off_t off, const off_t len, const int fork) -{ - return 0; -#if 0 - struct flock lock; - struct ad_fd *adf; - int err; - int type; - - lock.l_start = off; - type = locktype; - if (eid == ADEID_DFORK) { - adf = &ad->ad_data_fork; - } else { - /* FIXME META */ - adf = &ad->ad_resource_fork; - if (adf->adf_fd == -1) { - /* there's no resource fork. return success */ - return 0; - } - /* if ADLOCK_FILELOCK we want a lock from offset 0 - * it's used when deleting a file: - * in open we put read locks on meta datas - * in delete a write locks on the whole file - * so if the file is open by somebody else it fails - */ - if (!(type & ADLOCK_FILELOCK)) - lock.l_start += ad_getentryoff(ad, eid); - } - - if (!(adf->adf_flags & O_RDWR) && (type & ADLOCK_WR)) { - type = (type & ~ADLOCK_WR) | ADLOCK_RD; - } - - lock.l_type = XLATE_FCNTL_LOCK(type & ADLOCK_MASK); - lock.l_whence = SEEK_SET; - lock.l_len = len; - - /* see if it's locked by another fork. */ - if (fork && adf_findxlock(adf, fork, ADLOCK_WR | - ((type & ADLOCK_WR) ? ADLOCK_RD : 0), - lock.l_start, lock.l_len) > -1) { - errno = EACCES; - return -1; - } - - /* okay, we might have ranges byte-locked. we need to make sure that - * we restore the appropriate ranges once we're done. so, we check - * for overlap on an unlock and relock. - * XXX: in the future, all the byte locks will be sorted and contiguous. - * we just want to upgrade all the locks and then downgrade them - * here. */ - if (!adf->adf_excl) { - err = set_lock(adf->adf_fd, F_SETLK, &lock); - } - else { - err = 0; - } - if (!err && (lock.l_type == F_UNLCK)) - adf_relockrange(adf, adf->adf_fd, lock.l_start, len); - - return err; -#endif -} - /* ------------------------- the fork is opened in Read Write, Deny Read, Deny Write mode lock the whole file once @@ -648,23 +668,17 @@ int ad_excl_lock(struct adouble *ad, const u_int32_t eid) #endif } -/* --------------------- */ -void ad_fcntl_unlock(struct adouble *ad, const int fork) +int ad_lock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user) { - return; -#if 0 - if (ad_data_fileno(ad) != -1) { - adf_unlock(&ad->ad_data_fork, fork); - } - if (ad_reso_fileno(ad) != -1) { - adf_unlock(&ad->ad_resource_fork, fork); - } + return 0; +} - if (ad->ad_flags != AD_VERSION_EA) { +void ad_unlock(struct adouble *ad, int user) +{ return; - } - if (ad_meta_fileno(ad) != -1) { - adf_unlock(&ad->ad_metadata_fork, fork); - } -#endif +} + +int ad_tmplock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user) +{ + return 0; }