xref: /third_party/ltp/include/old/old_device.h (revision f08c3bdf)
1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2014-2016 Cyril Hrubis <chrubis@suse.cz>
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software: you can redistribute it and/or modify
5f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by
6f08c3bdfSopenharmony_ci * the Free Software Foundation, either version 2 of the License, or
7f08c3bdfSopenharmony_ci * (at your option) any later version.
8f08c3bdfSopenharmony_ci *
9f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful,
10f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
11f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12f08c3bdfSopenharmony_ci * GNU General Public License for more details.
13f08c3bdfSopenharmony_ci *
14f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License
15f08c3bdfSopenharmony_ci * along with this program. If not, see <http://www.gnu.org/licenses/>.
16f08c3bdfSopenharmony_ci */
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_ci#ifndef OLD_DEVICE_H__
19f08c3bdfSopenharmony_ci#define OLD_DEVICE_H__
20f08c3bdfSopenharmony_ci
21f08c3bdfSopenharmony_ci/*
22f08c3bdfSopenharmony_ci * Returns filesystem type to be used for the testing. Unless your test is
23f08c3bdfSopenharmony_ci * designed for specific filesystem you should use this function to the tested
24f08c3bdfSopenharmony_ci * filesystem.
25f08c3bdfSopenharmony_ci *
26f08c3bdfSopenharmony_ci * If TST_DEV_FS_TYPE is set the function returns it's content,
27f08c3bdfSopenharmony_ci * otherwise default fs type hardcoded in the library is returned.
28f08c3bdfSopenharmony_ci */
29f08c3bdfSopenharmony_ciconst char *tst_dev_fs_type(void);
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_ci/*
32f08c3bdfSopenharmony_ci * Acquires test device.
33f08c3bdfSopenharmony_ci *
34f08c3bdfSopenharmony_ci * Can be used only once, i.e. you cannot get two different devices.
35f08c3bdfSopenharmony_ci *
36f08c3bdfSopenharmony_ci * Looks for LTP_DEV env variable first (which may be passed by the test
37f08c3bdfSopenharmony_ci * driver or by a user) and returns just it's value if found.
38f08c3bdfSopenharmony_ci *
39f08c3bdfSopenharmony_ci * Otherwise creates a temp file and loop device.
40f08c3bdfSopenharmony_ci *
41f08c3bdfSopenharmony_ci * Note that you have to call tst_tmpdir() beforehand.
42f08c3bdfSopenharmony_ci *
43f08c3bdfSopenharmony_ci * Returns path to the device or NULL if it cannot be created.
44f08c3bdfSopenharmony_ci * Call tst_release_device() when you're done.
45f08c3bdfSopenharmony_ci */
46f08c3bdfSopenharmony_ciconst char *tst_acquire_device_(void (cleanup_fn)(void), unsigned int size);
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ciconst char *tst_acquire_device__(unsigned int size);
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_cistatic inline const char *tst_acquire_device(void (cleanup_fn)(void))
51f08c3bdfSopenharmony_ci{
52f08c3bdfSopenharmony_ci	return tst_acquire_device_(cleanup_fn, 0);
53f08c3bdfSopenharmony_ci}
54f08c3bdfSopenharmony_ci
55f08c3bdfSopenharmony_ci/*
56f08c3bdfSopenharmony_ci * Acquire a loop device with specified temp filename. This function allows
57f08c3bdfSopenharmony_ci * you to acquire multiple devices at the same time. LTP_DEV is ignored.
58f08c3bdfSopenharmony_ci * If you call this function directly, use tst_detach_device() to release
59f08c3bdfSopenharmony_ci * the devices. tst_release_device() will not work correctly.
60f08c3bdfSopenharmony_ci *
61f08c3bdfSopenharmony_ci * The return value points to a static buffer and additional calls of
62f08c3bdfSopenharmony_ci * tst_acquire_loop_device() or tst_acquire_device() will overwrite it.
63f08c3bdfSopenharmony_ci */
64f08c3bdfSopenharmony_ciconst char *tst_acquire_loop_device(unsigned int size, const char *filename);
65f08c3bdfSopenharmony_ci
66f08c3bdfSopenharmony_ci/*
67f08c3bdfSopenharmony_ci * @dev: device path returned by the tst_acquire_device()
68f08c3bdfSopenharmony_ci */
69f08c3bdfSopenharmony_ciint tst_release_device(const char *dev);
70f08c3bdfSopenharmony_ci
71f08c3bdfSopenharmony_ci/*
72f08c3bdfSopenharmony_ci * Cleanup function for tst_acquire_loop_device(). If you have acquired
73f08c3bdfSopenharmony_ci * a device using tst_acquire_device(), use tst_release_device() instead.
74f08c3bdfSopenharmony_ci * @dev: device path returned by the tst_acquire_loop_device()
75f08c3bdfSopenharmony_ci */
76f08c3bdfSopenharmony_ciint tst_detach_device(const char *dev);
77f08c3bdfSopenharmony_ci
78f08c3bdfSopenharmony_ci/*
79f08c3bdfSopenharmony_ci * Just like umount() but retries several times on failure.
80f08c3bdfSopenharmony_ci * @path: Path to umount
81f08c3bdfSopenharmony_ci */
82f08c3bdfSopenharmony_ciint tst_umount(const char *path);
83f08c3bdfSopenharmony_ci
84f08c3bdfSopenharmony_ci#endif	/* OLD_DEVICE_H__ */
85