Branch data Line data Source code
1 : : /* SPDX-License-Identifier: GPL-2.0+ */ 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 : 0 : int main(int argc, char** argv) { 36 : 0 : _cleanup_close_ int mtd_fd = -1; 37 : : mtd_info_t mtd_info; 38 : : 39 [ # # ]: 0 : if (argc != 2) { 40 : 0 : printf("usage: mtd_probe /dev/mtd[n]\n"); 41 : 0 : return EXIT_FAILURE; 42 : : } 43 : : 44 : 0 : mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC); 45 [ # # ]: 0 : if (mtd_fd < 0) { 46 [ # # ]: 0 : log_error_errno(errno, "Failed to open: %m"); 47 : 0 : return EXIT_FAILURE; 48 : : } 49 : : 50 [ # # ]: 0 : if (ioctl(mtd_fd, MEMGETINFO, &mtd_info) < 0) { 51 [ # # ]: 0 : log_error_errno(errno, "Failed to issue MEMGETINFO ioctl: %m"); 52 : 0 : return EXIT_FAILURE; 53 : : } 54 : : 55 [ # # ]: 0 : if (probe_smart_media(mtd_fd, &mtd_info) < 0) 56 : 0 : return EXIT_FAILURE; 57 : : 58 : 0 : return EXIT_SUCCESS; 59 : : }