xref: /aosp_15_r20/external/ltp/testcases/lib/tst_fsfreeze.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (C) 2010 Hajime Taira <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker  *                    Masatake Yamato <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2023 Petr Vorel <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  *
7*49cdfc7eSAndroid Build Coastguard Worker  * Based on fsfreeze from util-linux.
8*49cdfc7eSAndroid Build Coastguard Worker  */
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker #include <linux/fs.h>
11*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
12*49cdfc7eSAndroid Build Coastguard Worker 
13*49cdfc7eSAndroid Build Coastguard Worker #define TST_NO_DEFAULT_MAIN
14*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
15*49cdfc7eSAndroid Build Coastguard Worker #include "tst_safe_macros.h"
16*49cdfc7eSAndroid Build Coastguard Worker 
help(void)17*49cdfc7eSAndroid Build Coastguard Worker static void help(void)
18*49cdfc7eSAndroid Build Coastguard Worker {
19*49cdfc7eSAndroid Build Coastguard Worker 	printf("Freeze and unfreeze the device.\n");
20*49cdfc7eSAndroid Build Coastguard Worker 	printf("Usage: tst_fsfreeze device\n");
21*49cdfc7eSAndroid Build Coastguard Worker }
22*49cdfc7eSAndroid Build Coastguard Worker 
main(int argc,char * argv[])23*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
24*49cdfc7eSAndroid Build Coastguard Worker {
25*49cdfc7eSAndroid Build Coastguard Worker 	int fd;
26*49cdfc7eSAndroid Build Coastguard Worker 
27*49cdfc7eSAndroid Build Coastguard Worker 	if (argc < 2) {
28*49cdfc7eSAndroid Build Coastguard Worker 		help();
29*49cdfc7eSAndroid Build Coastguard Worker 		return 1;
30*49cdfc7eSAndroid Build Coastguard Worker 	}
31*49cdfc7eSAndroid Build Coastguard Worker 
32*49cdfc7eSAndroid Build Coastguard Worker 	fd = SAFE_OPEN(argv[1], O_RDONLY);
33*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_IOCTL(fd, FIFREEZE, 0);
34*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_IOCTL(fd, FITHAW, 0);
35*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_CLOSE(fd);
36*49cdfc7eSAndroid Build Coastguard Worker 
37*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
38*49cdfc7eSAndroid Build Coastguard Worker }
39