libmount Reference Manual | ||||
---|---|---|---|---|
Top | Description |
struct libmnt_lock; void mnt_free_lock (struct libmnt_lock *ml
); int mnt_lock_file (struct libmnt_lock *ml
); struct libmnt_lock * mnt_new_lock (const char *datafile
,pid_t id
); void mnt_unlock_file (struct libmnt_lock *ml
); int mnt_lock_block_signals (struct libmnt_lock *ml
,int enable
);
The mtab lock is backwards compatible with the standard linux /etc/mtab locking. Note, it's necessary to use the same locking schema in all applications that access the file.
void mnt_free_lock (struct libmnt_lock *ml
);
Deallocates mnt_lock.
|
struct libmnt_lock handler |
int mnt_lock_file (struct libmnt_lock *ml
);
Creates a lock file (e.g. /etc/mtab~). Note that this function may
use alarm()
.
Your application always has to call mnt_unlock_file()
before exit.
Traditional mtab locking scheme:
1. create linkfile (e.g. /etc/mtab~.$PID)
2. link linkfile --> lockfile (e.g. /etc/mtab~.$PID --> /etc/mtab~)
3. a) link()
success: setups F_SETLK lock (see fcnlt(2))
b) link()
failed: wait (max 30s) on F_SETLKW lock, goto 2.
|
pointer to struct libmnt_lock instance |
Returns : |
0 on success or negative number in case of error (-ETIMEOUT is case of stale lock file). |
struct libmnt_lock * mnt_new_lock (const char *datafile
,pid_t id
);
|
the file that should be covered by the lock |
|
unique linkfile identifier or 0 (default is getpid() ) |
Returns : |
newly allocated lock handler or NULL on case of error. |
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)).
|
lock struct |