From 18794c820f109e6de2e16af0f058b562b0492cbc Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Wed, 11 Nov 2015 16:22:45 -0600 Subject: Update dosfstools * Version 3.0.28 * Update filenames in source * Remove unnecessary symlink to fsck * Commit "Recode short filenames from DOS codepage (default 437)." has been reverted since we do not have access to iconv * Commits cherry-picked on top of 3.0.28: - mkfs.fat: fix incorrect int type - Prevent out of bound array read in date_dos2unix() Change-Id: I50310235c62ec2e6bc90afcd10f2814d3afb5113 --- dosfstools/src/fatlabel.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 dosfstools/src/fatlabel.c (limited to 'dosfstools/src/fatlabel.c') diff --git a/dosfstools/src/fatlabel.c b/dosfstools/src/fatlabel.c new file mode 100644 index 000000000..1484ba527 --- /dev/null +++ b/dosfstools/src/fatlabel.c @@ -0,0 +1,144 @@ +/* fatlabel.c - User interface + + Copyright (C) 1993 Werner Almesberger + Copyright (C) 1998 Roman Hodek + Copyright (C) 2007 Red Hat, Inc. + Copyright (C) 2008-2014 Daniel Baumann + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + The complete text of the GNU General Public License + can be found in /usr/share/common-licenses/GPL-3 file. +*/ + +#include "version.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "fsck.fat.h" +#include "io.h" +#include "boot.h" +#include "fat.h" +#include "file.h" +#include "check.h" + +int interactive = 0, rw = 0, list = 0, test = 0, verbose = 0, write_immed = 0; +int atari_format = 0; +unsigned n_files = 0; +void *mem_queue = NULL; + +static void usage(int error) +{ + FILE *f = error ? stderr : stdout; + int status = error ? 1 : 0; + + fprintf(f, "usage: fatlabel device [label]\n"); + exit(status); +} + +/* + * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant + * of MS-DOS filesystem by default. + */ +static void check_atari(void) +{ +#ifdef __mc68000__ + FILE *f; + char line[128], *p; + + if (!(f = fopen("/proc/hardware", "r"))) { + perror("/proc/hardware"); + return; + } + + while (fgets(line, sizeof(line), f)) { + if (strncmp(line, "Model:", 6) == 0) { + p = line + 6; + p += strspn(p, " \t"); + if (strncmp(p, "Atari ", 6) == 0) + atari_format = 1; + break; + } + } + fclose(f); +#endif +} + +int main(int argc, char *argv[]) +{ + DOS_FS fs = { 0 }; + rw = 0; + + int i; + + char *device = NULL; + char label[12] = { 0 }; + + loff_t offset; + DIR_ENT de; + + check_atari(); + + if (argc < 2 || argc > 3) + usage(1); + + if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) + usage(0); + else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { + printf("fatlabel " VERSION " (" VERSION_DATE ")\n"); + exit(0); + } + + device = argv[1]; + if (argc == 3) { + strncpy(label, argv[2], 11); + if (strlen(argv[2]) > 11) { + fprintf(stderr, + "fatlabel: labels can be no longer than 11 characters\n"); + exit(1); + } + for (i = 0; label[i] && i < 11; i++) + /* don't know if here should be more strict !uppercase(label[i]) */ + if (islower(label[i])) { + fprintf(stderr, + "fatlabel: warning - lowercase labels might not work properly with DOS or Windows\n"); + break; + } + rw = 1; + } + + fs_open(device, rw); + read_boot(&fs); + if (fs.fat_bits == 32) + read_fat(&fs); + if (!rw) { + offset = find_volume_de(&fs, &de); + if (offset == 0) + fprintf(stdout, "%s\n", fs.label); + else + fprintf(stdout, "%.8s%.3s\n", de.name, de.ext); + exit(0); + } + + write_label(&fs, label); + fs_close(rw); + return 0; +} -- cgit v1.2.3