dosfstools  4.2
About: dosfstools are utilities to create, check and label (MS-DOS) FAT filesystems.
  Fossies Dox: dosfstools-4.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

testdevinfo.c
Go to the documentation of this file.
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 }
int device_info_verbose
Definition: device_info.c:68
int get_device_info(int fd, struct device_info *info)
Definition: device_info.c:282
@ TYPE_REMOVABLE
Definition: device_info.h:9
@ TYPE_FILE
Definition: device_info.h:7
@ TYPE_BAD
Definition: device_info.h:6
@ TYPE_VIRTUAL
Definition: device_info.h:8
@ TYPE_UNKNOWN
Definition: device_info.h:5
@ TYPE_FIXED
Definition: device_info.h:10
static int fd
Definition: io.c:56
long long geom_start
Definition: device_info.h:37
enum device_type type
Definition: device_info.h:14
int geom_sectors
Definition: device_info.h:36
long long size
Definition: device_info.h:48
long long geom_size
Definition: device_info.h:38
int sector_size
Definition: device_info.h:43
int geom_heads
Definition: device_info.h:35
int has_children
Definition: device_info.h:30
int main(int argc, char **argv)
Definition: testdevinfo.c:25