blob: 5e2d2824fe1414b5f3af946ded3b7c093f3bf52d [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/* dosfslabel.c - User interface
2
3 Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
4 Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 Copyright (C) 2007 Red Hat, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 On Debian systems, the complete text of the GNU General Public License
21 can be found in /usr/share/common-licenses/GPL-3 file.
22*/
23
24#include "version.h"
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <stdlib.h>
30#include <unistd.h>
31#include <getopt.h>
32
33#ifdef _USING_BIONIC_
34#include <linux/fs.h>
35#endif
36
37#include "common.h"
38#include "dosfsck.h"
39#include "io.h"
40#include "boot.h"
41#include "fat.h"
42#include "file.h"
43#include "check.h"
44
45int interactive = 0, rw = 0, list = 0, test = 0, verbose = 0, write_immed = 0;
46int atari_format = 0;
47unsigned n_files = 0;
48void *mem_queue = NULL;
49
50static void usage(int error)
51{
52 FILE *f = error ? stderr : stdout;
53 int status = error ? 1 : 0;
54
55 fprintf(f, "usage: dosfslabel device [label]\n");
56 exit(status);
57}
58
59/*
60 * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
61 * of MS-DOS filesystem by default.
62 */
63static void check_atari(void)
64{
65#ifdef __mc68000__
66 FILE *f;
67 char line[128], *p;
68
69 if (!(f = fopen("/proc/hardware", "r"))) {
70 perror("/proc/hardware");
71 return;
72 }
73
74 while (fgets(line, sizeof(line), f)) {
75 if (strncmp(line, "Model:", 6) == 0) {
76 p = line + 6;
77 p += strspn(p, " \t");
78 if (strncmp(p, "Atari ", 6) == 0)
79 atari_format = 1;
80 break;
81 }
82 }
83 fclose(f);
84#endif
85}
86
87int main(int argc, char *argv[])
88{
89 DOS_FS fs;
90 rw = 0;
91
92 char *device = NULL;
93 char *label = NULL;
94
95 check_atari();
96
97 if (argc < 2 || argc > 3)
98 usage(1);
99
100 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
101 usage(0);
102 else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
103 printf("dosfslabel " VERSION ", " VERSION_DATE ", FAT32, LFN\n");
104 exit(0);
105 }
106
107 device = argv[1];
108 if (argc == 3) {
109 label = argv[2];
110 if (strlen(label) > 11) {
111 fprintf(stderr,
112 "dosfslabel: labels can be no longer than 11 characters\n");
113 exit(1);
114 }
115 rw = 1;
116 }
117
118 fs_open(device, rw);
119 read_boot(&fs);
120 if (!rw) {
121 fprintf(stdout, "%s\n", fs.label);
122 exit(0);
123 }
124
125 write_label(&fs, label);
126 fs_close(rw);
127 return 0;
128}