]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/udev/mtd_probe/mtd_probe.c
d5fb64f1948a31f16718c61b1227b3a3fbb474b6
[thirdparty/systemd.git] / src / udev / mtd_probe / mtd_probe.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright © 2010 - Maxim Levitsky
4 *
5 * mtd_probe is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * mtd_probe is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with mtd_probe; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
19 */
20
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <mtd/mtd-user.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <sys/ioctl.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30
31 #include "alloc-util.h"
32 #include "fd-util.h"
33 #include "mtd_probe.h"
34
35 int main(int argc, char** argv) {
36 _cleanup_close_ int mtd_fd = -1;
37 mtd_info_t mtd_info;
38
39 if (argc != 2) {
40 printf("usage: mtd_probe /dev/mtd[n]\n");
41 return EXIT_FAILURE;
42 }
43
44 mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
45 if (mtd_fd < 0) {
46 log_error_errno(errno, "Failed to open: %m");
47 return EXIT_FAILURE;
48 }
49
50 if (ioctl(mtd_fd, MEMGETINFO, &mtd_info) < 0) {
51 log_error_errno(errno, "Failed to issue MEMGETINFO ioctl: %m");
52 return EXIT_FAILURE;
53 }
54
55 if (probe_smart_media(mtd_fd, &mtd_info) < 0)
56 return EXIT_FAILURE;
57
58 return EXIT_SUCCESS;
59 }