Locking

Locking — locking methods for utab or another libmount files

Functions

void mnt_free_lock ()
int mnt_lock_file ()
struct libmnt_lock * mnt_new_lock ()
void mnt_ref_lock ()
void mnt_unref_lock ()
void mnt_unlock_file ()
int mnt_lock_block_signals ()

Types and Values

struct libmnt_lock

Description

Since v2.39 libmount does nto support classic mtab locking. Now all is based on flock only.

Functions

mnt_free_lock ()

void
mnt_free_lock (struct libmnt_lock *ml);

Deallocates libmnt_lock. This function does not care about reference count. Don't use this function directly -- it's better to use mnt_unref_lock().

The reference counting is supported since util-linux v2.40.

Parameters

ml

struct libmnt_lock handler

 

mnt_lock_file ()

int
mnt_lock_file (struct libmnt_lock *ml);

Creates a lock file.

Note that when the lock is used by mnt_update_table() interface then libmount uses flock() for private library file /run/mount/utab.

Parameters

ml

pointer to struct libmnt_lock instance

 

Returns

0 on success or negative number in case of error (-ETIMEOUT is case of stale lock file).


mnt_new_lock ()

struct libmnt_lock *
mnt_new_lock (const char *datafile,
              pid_t id);

Parameters

datafile

the file that should be covered by the lock

 

id

ignored by library

 

Returns

newly allocated lock handler or NULL on case of error.


mnt_ref_lock ()

void
mnt_ref_lock (struct libmnt_lock *ml);

Increments reference counter.

Parameters

ml

lock pointer

 

Since: 2.40


mnt_unref_lock ()

void
mnt_unref_lock (struct libmnt_lock *ml);

De-increments reference counter, on zero the ml is automatically deallocated by mnt_free_lock).

Parameters

ml

lock pointer

 

mnt_unlock_file ()

void
mnt_unlock_file (struct libmnt_lock *ml);

Unlocks the file. The function could be called independently of the lock status (for example from exit(3)).

Parameters

ml

lock struct

 

mnt_lock_block_signals ()

int
mnt_lock_block_signals (struct libmnt_lock *ml,
                        int enable);

Block/unblock signals when the lock is locked, the signals are not blocked by default.

Parameters

ml

struct libmnt_lock handler

 

enable

TRUE/FALSE

 

Returns

<0 on error, 0 on success.

Types and Values

struct libmnt_lock

struct libmnt_lock;

Stores information about the locked file