LCOV - code coverage report
Current view: top level - udev/mtd_probe - probe_smartmedia.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 0 35 0.0 %
Date: 2019-08-23 13:36:53 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 29 0.0 %

           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 <stdint.h>
      25                 :            : #include <stdio.h>
      26                 :            : #include <stdlib.h>
      27                 :            : #include <string.h>
      28                 :            : #include <sys/stat.h>
      29                 :            : #include <sys/types.h>
      30                 :            : #include <unistd.h>
      31                 :            : 
      32                 :            : #include "alloc-util.h"
      33                 :            : #include "mtd_probe.h"
      34                 :            : 
      35                 :            : static const uint8_t cis_signature[] = {
      36                 :            :         0x01, 0x03, 0xD9, 0x01, 0xFF, 0x18, 0x02, 0xDF, 0x01, 0x20
      37                 :            : };
      38                 :            : 
      39                 :          0 : int probe_smart_media(int mtd_fd, mtd_info_t* info) {
      40                 :            :         int sector_size;
      41                 :            :         int block_size;
      42                 :            :         int size_in_megs;
      43                 :            :         int spare_count;
      44                 :          0 :         _cleanup_free_ uint8_t *cis_buffer = NULL;
      45                 :            :         int offset;
      46                 :          0 :         int cis_found = 0;
      47                 :            : 
      48                 :          0 :         cis_buffer = malloc(SM_SECTOR_SIZE);
      49         [ #  # ]:          0 :         if (!cis_buffer)
      50                 :          0 :                 return log_oom();
      51                 :            : 
      52         [ #  # ]:          0 :         if (info->type != MTD_NANDFLASH)
      53         [ #  # ]:          0 :                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
      54                 :            :                                        "Not marked MTD_NANDFLASH.");
      55                 :            : 
      56                 :          0 :         sector_size = info->writesize;
      57                 :          0 :         block_size = info->erasesize;
      58                 :          0 :         size_in_megs = info->size / (1024 * 1024);
      59                 :            : 
      60   [ #  #  #  # ]:          0 :         if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE))
      61         [ #  # ]:          0 :                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
      62                 :            :                                        "Unexpected sector size: %i", sector_size);
      63                 :            : 
      64      [ #  #  # ]:          0 :         switch(size_in_megs) {
      65                 :          0 :         case 1:
      66                 :            :         case 2:
      67                 :          0 :                 spare_count = 6;
      68                 :          0 :                 break;
      69                 :          0 :         case 4:
      70                 :          0 :                 spare_count = 12;
      71                 :          0 :                 break;
      72                 :          0 :         default:
      73                 :          0 :                 spare_count = 24;
      74                 :          0 :                 break;
      75                 :            :         }
      76                 :            : 
      77         [ #  # ]:          0 :         for (offset = 0; offset < block_size * spare_count; offset += sector_size) {
      78                 :          0 :                 (void) lseek(mtd_fd, SEEK_SET, offset);
      79                 :            : 
      80         [ #  # ]:          0 :                 if (read(mtd_fd, cis_buffer, SM_SECTOR_SIZE) == SM_SECTOR_SIZE) {
      81                 :          0 :                         cis_found = 1;
      82                 :          0 :                         break;
      83                 :            :                 }
      84                 :            :         }
      85                 :            : 
      86         [ #  # ]:          0 :         if (!cis_found)
      87         [ #  # ]:          0 :                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
      88                 :            :                                        "CIS not found");
      89                 :            : 
      90         [ #  # ]:          0 :         if (memcmp(cis_buffer, cis_signature, sizeof(cis_signature)) != 0 &&
      91         [ #  # ]:          0 :             memcmp(cis_buffer + SM_SMALL_PAGE, cis_signature, sizeof(cis_signature)) != 0)
      92         [ #  # ]:          0 :                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
      93                 :            :                                        "CIS signature didn't match");
      94                 :            : 
      95                 :          0 :         printf("MTD_FTL=smartmedia\n");
      96                 :          0 :         return 0;
      97                 :            : }

Generated by: LCOV version 1.14