]> git.proxmox.com Git - systemd.git/blob - src/shared/loop-util.h
New upstream version 249~rc1
[systemd.git] / src / shared / loop-util.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "macro.h"
5 #include "time-util.h"
6
7 typedef struct LoopDevice LoopDevice;
8
9 /* Some helpers for setting up loopback block devices */
10
11 struct LoopDevice {
12 int fd;
13 int nr;
14 dev_t devno;
15 char *node;
16 bool relinquished;
17 uint64_t uevent_seqnum_not_before; /* uevent sequm right before we attached the loopback device, or UINT64_MAX if we don't know */
18 usec_t timestamp_not_before; /* CLOCK_MONOTONIC timestamp taken immediately before attaching the loopback device, or USEC_INFINITY if we don't know */
19 };
20
21 int loop_device_make(int fd, int open_flags, uint64_t offset, uint64_t size, uint32_t loop_flags, LoopDevice **ret);
22 int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, LoopDevice **ret);
23 int loop_device_open(const char *loop_path, int open_flags, LoopDevice **ret);
24
25 LoopDevice* loop_device_unref(LoopDevice *d);
26 DEFINE_TRIVIAL_CLEANUP_FUNC(LoopDevice*, loop_device_unref);
27
28 void loop_device_relinquish(LoopDevice *d);
29
30 int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size);
31
32 int loop_device_flock(LoopDevice *d, int operation);
33 int loop_device_sync(LoopDevice *d);