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