• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2016-2019 Cyril Hrubis <chrubis@suse.cz>
4  */
5 
6 #ifndef TST_DEVICE_H__
7 #define TST_DEVICE_H__
8 
9 #include <unistd.h>
10 
11 struct tst_device {
12 	const char *dev;
13 	const char *fs_type;
14 };
15 
16 /*
17  * Automatically initialized if test.needs_device is set.
18  */
19 extern struct tst_device *tst_device;
20 
21 /*
22  * Just like umount() but retries several times on failure.
23  * @path: Path to umount
24  */
25 int tst_umount(const char *path);
26 
27 /*
28  * Verifies if an earlier mount is successful or not.
29  * @path: Mount path to verify
30  */
31 int tst_is_mounted(const char *path);
32 int tst_is_mounted_at_tmpdir(const char *path);
33 
34 /*
35  * Clears a first few blocks of the device. This is needed when device has
36  * already been formatted with a filesystems, subset of mkfs.foo utils aborts
37  * the operation if it finds a filesystem signature there.
38  *
39  * Note that this is called from tst_mkfs() automatically, so you probably will
40  * not need to use this from the test yourself.
41  */
42 int tst_clear_device(const char *dev);
43 
44 /*
45  * Finds a free loop device for use and returns the free loopdev minor(-1 for no
46  * free loopdev). If path is non-NULL, it will be filled with free loopdev path.
47  *
48  */
49 int tst_find_free_loopdev(const char *path, size_t path_len);
50 
51 /*
52  * Attaches a file to a loop device.
53  *
54  * @dev_path Path to the loop device e.g. /dev/loop0
55  * @file_path Path to a file e.g. disk.img
56  * @return Zero on success, non-zero otherwise.
57  */
58 int tst_attach_device(const char *dev_path, const char *file_path);
59 
60 /*
61  * Detaches a file from a loop device.
62  *
63  * @dev_path Path to the loop device e.g. /dev/loop0
64  * @return Zero on succes, non-zero otherwise.
65  */
66 int tst_detach_device(const char *dev_path);
67 
68 /*
69  * To avoid FS deferred IO metadata/cache interference, so we do syncfs
70  * simply before the tst_dev_bytes_written invocation. For easy to use,
71  * we create this inline function tst_dev_sync.
72  */
73 int tst_dev_sync(int fd);
74 
75 /*
76  * Reads test block device stat file and returns the bytes written since the
77  * last call of this function.
78  * @dev: test block device
79  */
80 unsigned long tst_dev_bytes_written(const char *dev);
81 
82 /*
83  * Wipe the contents of given directory but keep the directory itself
84  */
85 void tst_purge_dir(const char *path);
86 
87 #endif	/* TST_DEVICE_H__ */
88