1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*******************************************************************************
* Copyright (c) 2013 Linaro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Linaro <linaro-dev@lists.linaro.org>
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/msdos_fs.h>
#ifndef VFAT_IOCTL_GET_VOLUME_ID
#warning The IOCTL code has not been defined in public headers...
#define VFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x13, __u32)
#endif
int main(int argc, char *argv[])
{
struct option lopt[] = {
{ "path", required_argument, NULL, 'p' },
{ "ignore-error", no_argument, NULL, 'i' },
{ "use-bad-addr", no_argument, NULL, 'e' },
{ NULL, 0, NULL, 0 },
};
char * shopt = "p:ise";
char *device = NULL;
long res;
int h;
int c, opti,
ignore_ioctl_error = 0,
use_bad_addr = 0;
__u32 id;
while ((c = getopt_long(argc, argv, shopt, lopt, &opti)) != -1 ) {
switch (c) {
case 'p':
device = strdup(optarg);
break;
case 'i':
ignore_ioctl_error = 1;
break;
case 'e':
use_bad_addr = 1;
break;
default:
printf("Warning, unknown option!\n");
break;
}
}
if (!device) {
printf("Missing parameter, please use --path=<mounted fat partition> option\n");
return ENODEV;
}
h = open(device, O_RDONLY);
if (h < 0) {
perror("Error on open");
free(device);
return -h;
}
res = ioctl(h, VFAT_IOCTL_GET_VOLUME_ID, &id);
if (res != 0 && !ignore_ioctl_error) {
perror("Error on ioctl");
free(device);
return -res;
}
printf("0x%08X", id);
free(device);
return 0;
}
|