netatalk  4.4.0dev
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
ad_lock.c File Reference
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atalk/adouble.h>
#include <atalk/compat.h>
#include <atalk/errchk.h>
#include <atalk/logger.h>
#include <atalk/util.h>
#include "ad_lock.h"

Macros

#define ARRAY_BLOCK_SIZE   10
#define ARRAY_FREE_DELTA   100
#define LTYPE2STRBUFSIZ   128

Functions

static const char * shmdstrfromoff (off_t off)
static int set_lock (int fd, int cmd, struct flock *lock)
static int XLATE_FCNTL_LOCK (int type)
static int OVERLAP (off_t a, off_t alen, off_t b, off_t blen)
static void adf_freelock (struct ad_fd *ad, const int i)
static void adf_unlock (struct adouble *ad _U_, struct ad_fd *adf, const int fork, int unlckbrl)
static void adf_relockrange (struct ad_fd *ad, int fd, off_t off, off_t len)
static int adf_findlock (struct ad_fd *ad, const int fork, const int type, const off_t off, const off_t len)
static int adf_findxlock (struct ad_fd *ad, const int fork, const int type, const off_t off, const off_t len)
static off_t rf2off (off_t off)
static int testlock (const struct ad_fd *adf, off_t off, off_t len)
static const char * locktypetostr (int type)
int ad_lock (struct adouble *ad, uint32_t eid, int locktype, off_t off, off_t len, int fork)
int ad_tmplock (struct adouble *ad, uint32_t eid, int locktype, off_t off, off_t len, int fork)
void ad_unlock (struct adouble *ad, const int fork, int unlckbrl)
int ad_testlock (struct adouble *ad, int eid, const off_t off)
uint16_t ad_openforks (struct adouble *ad, uint16_t attrbits)

Macro Definition Documentation

◆ ARRAY_BLOCK_SIZE

#define ARRAY_BLOCK_SIZE   10

◆ ARRAY_FREE_DELTA

#define ARRAY_FREE_DELTA   100

◆ LTYPE2STRBUFSIZ

#define LTYPE2STRBUFSIZ   128

Function Documentation

◆ ad_lock()

int ad_lock ( struct adouble * ad,
uint32_t eid,
int locktype,
off_t off,
off_t len,
int fork )

◆ ad_openforks()

uint16_t ad_openforks ( struct adouble * ad,
uint16_t attrbits )

Return if a file is open by another process.

Optimized for the common case:

  • there's no locks held by another process (clients)
  • or we already know the answer and don't need to test (attrbits)
Parameters
ad(rw) handle
attrbits(r) forks opened by us
Returns
bitflags ATTRBIT_DOPEN | ATTRBIT_ROPEN if other process has fork of file opened

◆ ad_testlock()

int ad_testlock ( struct adouble * ad,
int eid,
const off_t off )

Test for a share mode lock

Parameters
ad(rw) handle
eid(r) datafork or resource fork
off(r) sharemode lock to test
Returns
1 if there's an existing lock, 0 if there's no lock, -1 in case any error occured

◆ ad_tmplock()

int ad_tmplock ( struct adouble * ad,
uint32_t eid,
int locktype,
off_t off,
off_t len,
int fork )

◆ ad_unlock()

void ad_unlock ( struct adouble * ad,
const int fork,
int unlckbrl )

◆ adf_findlock()

int adf_findlock ( struct ad_fd * ad,
const int fork,
const int type,
const off_t off,
const off_t len )
static

◆ adf_findxlock()

int adf_findxlock ( struct ad_fd * ad,
const int fork,
const int type,
const off_t off,
const off_t len )
static

◆ adf_freelock()

void adf_freelock ( struct ad_fd * ad,
const int i )
static

◆ adf_relockrange()

void adf_relockrange ( struct ad_fd * ad,
int fd,
off_t off,
off_t len )
static

◆ adf_unlock()

void adf_unlock ( struct adouble *ad _U_,
struct ad_fd * adf,
const int fork,
int unlckbrl )
static

◆ locktypetostr()

const char * locktypetostr ( int type)
static

◆ OVERLAP()

int OVERLAP ( off_t a,
off_t alen,
off_t b,
off_t blen )
static

◆ rf2off()

off_t rf2off ( off_t off)
static

◆ set_lock()

int set_lock ( int fd,
int cmd,
struct flock * lock )
static

◆ shmdstrfromoff()

const char * shmdstrfromoff ( off_t off)
static

◆ testlock()

int testlock ( const struct ad_fd * adf,
off_t off,
off_t len )
static

Test a lock

(1) Test against our own locks array (2) Test fcntl lock, locks from other processes

Parameters
adf(r) handle
off(r) offset
len(r) length
Returns
1 if there's an existing lock, 0 if there's no lock, -1 in case any error occured

◆ XLATE_FCNTL_LOCK()

int XLATE_FCNTL_LOCK ( int type)
static