41d093494c116736f3c2eae5722e1ce57175f959
[platform/upstream/cryptsetup.git] / lib / utils_device_locking.h
1 /*
2  * Metadata on-disk locking for processes serialization
3  *
4  * Copyright (C) 2016-2020 Red Hat, Inc. All rights reserved.
5  * Copyright (C) 2016-2020 Ondrej Kozina
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef _CRYPTSETUP_UTILS_LOCKING_H
23 #define _CRYPTSETUP_UTILS_LOCKING_H
24
25 struct crypt_device;
26 struct crypt_lock_handle;
27 struct device;
28
29 int device_locked_readonly(struct crypt_lock_handle *h);
30 int device_locked(struct crypt_lock_handle *h);
31
32 int device_read_lock_internal(struct crypt_device *cd, struct device *device);
33 int device_write_lock_internal(struct crypt_device *cd, struct device *device);
34 void device_unlock_internal(struct crypt_device *cd, struct device *device);
35
36 int device_locked_verify(struct crypt_device *cd, int fd, struct crypt_lock_handle *h);
37
38 int crypt_read_lock(struct crypt_device *cd, const char *name, bool blocking, struct crypt_lock_handle **lock);
39 int crypt_write_lock(struct crypt_device *cd, const char *name, bool blocking, struct crypt_lock_handle **lock);
40 void crypt_unlock_internal(struct crypt_device *cd, struct crypt_lock_handle *h);
41
42
43 /* Used only in device internal allocation */
44 void device_set_lock_handle(struct device *device, struct crypt_lock_handle *h);
45 struct crypt_lock_handle *device_get_lock_handle(struct device *device);
46
47 #endif