"Fossies" - the Fresh Open Source Software Archive

Member "dosfstools-4.2/src/testdevinfo.c" (31 Jan 2021, 2807 Bytes) of package /linux/misc/dosfstools-4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "testdevinfo.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1_vs_4.2.

    1 /* testdevinfo - Display device info findings for debugging
    2 
    3    Copyright (C) 2015 Andreas Bombe <aeb@debian.org>
    4 
    5    This program 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 3 of the License, or
    8    (at your option) any later version.
    9 
   10    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
   17 */
   18 
   19 #include <fcntl.h>
   20 #include <unistd.h>
   21 #include <stdio.h>
   22 #include "device_info.h"
   23 
   24 
   25 int main(int argc, char **argv)
   26 {
   27     struct device_info info;
   28     int fd;
   29 
   30     if (argc != 2) {
   31     printf("Usage: testdevinfo FILENAME\n");
   32     return 1;
   33     }
   34 
   35     fd = open(argv[1], O_RDONLY | O_NONBLOCK);
   36     if (fd < 0) {
   37     perror("open device");
   38     return 1;
   39     }
   40 
   41     device_info_verbose = 100;
   42     get_device_info(fd, &info);
   43     close(fd);
   44 
   45     printf("found information:\n");
   46 
   47     printf("device type: ");
   48     switch (info.type) {
   49     case TYPE_UNKNOWN:
   50         printf("unknown\n");
   51         break;
   52 
   53     case TYPE_BAD:
   54         printf("unusable\n");
   55         break;
   56 
   57     case TYPE_FILE:
   58         printf("image file\n");
   59         break;
   60 
   61     case TYPE_VIRTUAL:
   62         printf("virtual\n");
   63         break;
   64 
   65     case TYPE_REMOVABLE:
   66         printf("removable\n");
   67         break;
   68 
   69     case TYPE_FIXED:
   70         printf("fixed\n");
   71         break;
   72 
   73     default:
   74         printf("internal error! invalid value\n");
   75         break;
   76     }
   77 
   78     printf("is partition: ");
   79     if (info.partition < 0)
   80     printf("unknown\n");
   81     else if (info.partition == 0)
   82     printf("no, full disk\n");
   83     else
   84     printf("number %d\n", info.partition);
   85 
   86     printf("has children: ");
   87     if (info.has_children < 0)
   88     printf("unknown\n");
   89     else if (info.has_children == 0)
   90     printf("no\n");
   91     else
   92     printf("yes\n");
   93 
   94     printf("heads: ");
   95     if (info.geom_heads < 0)
   96     printf("unknown\n");
   97     else
   98     printf("%d\n", info.geom_heads);
   99 
  100     printf("sectors: ");
  101     if (info.geom_sectors < 0)
  102     printf("unknown\n");
  103     else
  104     printf("%d\n", info.geom_sectors);
  105 
  106     printf("start: ");
  107     if (info.geom_start < 0)
  108     printf("unknown\n");
  109     else
  110     printf("%lld\n", info.geom_start);
  111 
  112     printf("total disk sectors: ");
  113     if (info.geom_size < 0)
  114     printf("unknown\n");
  115     else
  116     printf("%lld\n", info.geom_size);
  117 
  118     printf("sector size: ");
  119     if (info.sector_size < 0)
  120     printf("unknown\n");
  121     else
  122     printf("%d\n", info.sector_size);
  123 
  124     printf("size: ");
  125     if (info.size < 0)
  126     printf("unknown\n");
  127     else
  128     printf("%lld\n", info.size);
  129 
  130     return 0;
  131 }