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