netatalk 4.5.0
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>`

## 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, struct ad_fd *adf, const int fork, int unlckbrl)
void | adf_lock_init (struct ad_fd *adf)
| Initialize lock tracking for an ad_fd structure.
void | adf_lock_free (struct ad_fd *adf)
| Free all locks in an ad_fd structure.
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)
| Test a lock.
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)
| Test for a share mode lock.
uint16_t | ad_openforks (struct adouble *ad, uint16_t attrbits)
| Return if a file is open by another process.

## 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

  [in,out] | ad | handle
  [in] | attrbits | 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

  [in,out] | ad | handle
  [in] | eid | datafork or resource fork
  [in] | off | 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

find a byte lock that overlaps off/len for a particular open fork

## ◆ adf_findxlock()

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

search other fork lock lists

## ◆ adf_freelock()

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

remove a lock and compact space if necessary

## ◆ adf_lock_free()

void adf_lock_free | ( | struct ad_fd * | adf | ) |

Free all locks in an ad_fd structure.

Iterates through all locks in the ad_fd lock array, releasing fcntl locks and freeing memory. Manages refcounted locks properly by only freeing refcount memory when the last reference is released.

This function is called when closing file descriptors to ensure all locks are properly released and memory is freed.

Parameters

  [in,out] | adf | File descriptor structure containing locks to free

## ◆ adf_lock_init()

void adf_lock_init | ( | struct ad_fd * | adf | ) |

Initialize lock tracking for an ad_fd structure.

Initializes the lock tracking fields in an ad_fd structure to their default empty state. This should be called when initializing a new ad_fd or after freeing all locks.

Parameters

  [in,out] | adf | File descriptor structure to initialize

## ◆ adf_relockrange()

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

relock any byte lock that overlaps off/len. unlock everything else.

## ◆ adf_unlock()

void adf_unlock | ( | struct adouble * | ad,
|  | 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

translate a resource fork lock to an offset

## ◆ 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

  [in] | adf | handle
  [in] | off | offset
  [in] | len | 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