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