summaryrefslogtreecommitdiffstats
path: root/src/kernel/tests/lib/tst_ioctl.c
blob: 364220bcded5297787038168f4d35e26c1e61f51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-2.0-or-later

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/fs.h>

#define TST_NO_DEFAULT_MAIN

#include "tst_test.h"

int tst_fibmap(const char *filename)
{
	/* test if FIBMAP ioctl is supported */
	int fd, block = 0;

	fd = open(filename, O_RDWR | O_CREAT, 0666);
	if (fd < 0) {
		tst_res(TWARN | TERRNO,
			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
		return -1;
	}

	if (ioctl(fd, FIBMAP, &block)) {
		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
		close(fd);
		return 1;
	}
	tst_res(TINFO, "FIBMAP ioctl is supported");

	if (close(fd)) {
		tst_res(TWARN | TERRNO, "close(fd) failed");
		return -1;
	}
	return 0;
}