xref: /third_party/ltp/lib/tst_ioctl.c (revision f08c3bdf)
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include <errno.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <sys/ioctl.h>
7#include <linux/fs.h>
8
9#define TST_NO_DEFAULT_MAIN
10
11#include "tst_test.h"
12
13int tst_fibmap(const char *filename)
14{
15	/* test if FIBMAP ioctl is supported */
16	int fd, block = 0;
17
18	fd = open(filename, O_RDWR | O_CREAT, 0666);
19	if (fd < 0) {
20		tst_res(TWARN | TERRNO,
21			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
22		return -1;
23	}
24
25	if (ioctl(fd, FIBMAP, &block)) {
26		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
27		close(fd);
28		return 1;
29	}
30	tst_res(TINFO, "FIBMAP ioctl is supported");
31
32	if (close(fd)) {
33		tst_res(TWARN | TERRNO, "close(fd) failed");
34		return -1;
35	}
36	return 0;
37}
38