• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2016 Linux Test Project
4  */
5 
6 #include <stdlib.h>
7 #include <sys/mount.h>
8 #include <stdint.h>
9 
10 #include "tst_test.h"
11 
do_test(void)12 static void do_test(void)
13 {
14 	int fd;
15 	const char *dev;
16 	char block_dev[100];
17 	uint64_t ltp_dev_size;
18 
19 	dev = tst_device->dev;
20 	if (!dev)
21 		tst_brk(TCONF, "Failed to acquire test device");
22 
23 	SAFE_MKFS(dev, "ext2", NULL, NULL);
24 
25 	fd = SAFE_OPEN(dev, O_RDONLY);
26 	SAFE_IOCTL(fd, BLKGETSIZE64, &ltp_dev_size);
27 	SAFE_CLOSE(fd);
28 
29 	if (ltp_dev_size/1024/1024 == 300)
30 		tst_res(TPASS, "Got expected device size");
31 	else
32 		tst_res(TFAIL, "Got unexpected device size");
33 
34 	tst_find_backing_dev("/boot", block_dev);
35 	tst_res(TPASS, "/boot belongs to %s block dev", block_dev);
36 	tst_find_backing_dev("/", block_dev);
37 	tst_res(TPASS, "/ belongs to %s block dev", block_dev);
38 	tst_find_backing_dev("/tmp", block_dev);
39 	tst_find_backing_dev("/boot/xuyang", block_dev);
40 }
41 
42 static struct tst_test test = {
43 	.needs_root = 1,
44 	.needs_device = 1,
45 	.dev_min_size = 300,
46 	.test_all = do_test,
47 };
48