• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016-2019 Cyril Hrubis <chrubis@suse.cz>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TST_DEVICE_H__
19 #define TST_DEVICE_H__
20 
21 #include <unistd.h>
22 
23 struct tst_device {
24 	const char *dev;
25 	const char *fs_type;
26 };
27 
28 /*
29  * Automatically initialized if test.needs_device is set.
30  */
31 extern struct tst_device *tst_device;
32 
33 /*
34  * Just like umount() but retries several times on failure.
35  * @path: Path to umount
36  */
37 int tst_umount(const char *path);
38 
39 /*
40  * Clears a first few blocks of the device. This is needed when device has
41  * already been formatted with a filesystems, subset of mkfs.foo utils aborts
42  * the operation if it finds a filesystem signature there.
43  *
44  * Note that this is called from tst_mkfs() automatically, so you probably will
45  * not need to use this from the test yourself.
46  */
47 int tst_clear_device(const char *dev);
48 
49 /*
50  * Finds a free loop device for use and returns the free loopdev minor(-1 for no
51  * free loopdev). If path is non-NULL, it will be filled with free loopdev path.
52  *
53  */
54 int tst_find_free_loopdev(const char *path, size_t path_len);
55 
56 /*
57  * Attaches a file to a loop device.
58  *
59  * @dev_path Path to the loop device e.g. /dev/loop0
60  * @file_path Path to a file e.g. disk.img
61  * @return Zero on success, non-zero otherwise.
62  */
63 int tst_attach_device(const char *dev_path, const char *file_path);
64 
65 /*
66  * Detaches a file from a loop device.
67  *
68  * @dev_path Path to the loop device e.g. /dev/loop0
69  * @return Zero on succes, non-zero otherwise.
70  */
71 int tst_detach_device(const char *dev_path);
72 
73 /*
74  * To avoid FS deferred IO metadata/cache interference, so we do syncfs
75  * simply before the tst_dev_bytes_written invocation. For easy to use,
76  * we create this inline function tst_dev_sync.
77  */
78 int tst_dev_sync(int fd);
79 
80 /*
81  * Reads test block device stat file and returns the bytes written since the
82  * last call of this function.
83  * @dev: test block device
84  */
85 unsigned long tst_dev_bytes_written(const char *dev);
86 
87 #endif	/* TST_DEVICE_H__ */
88