dosfstools/dosfstools-label.patch

190 lines
5.7 KiB
Diff

Index: dosfstools-3.0.10/src/dosfslabel.c
===================================================================
--- dosfstools-3.0.10.orig/src/dosfslabel.c
+++ dosfstools-3.0.10/src/dosfslabel.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
+#include <ctype.h>
#include "common.h"
#include "dosfsck.h"
@@ -89,7 +90,14 @@ int main(int argc, char *argv[])
rw = 0;
char *device = NULL;
- char *label = NULL;
+ char label[11];
+
+ int i;
+
+ loff_t offset;
+ DIR_ENT de;
+
+ memset(&fs, 0, sizeof(fs));
check_atari();
@@ -105,19 +113,31 @@ int main(int argc, char *argv[])
device = argv[1];
if (argc == 3) {
- label = argv[2];
- if (strlen(label) > 11) {
+ if (strlen(argv[2]) > 11) {
fprintf(stderr,
"dosfslabel: labels can be no longer than 11 characters\n");
exit(1);
}
+ strncpy(label, argv[2], 11);
+ for (i = 0; i < 11; i++)
+ if (islower(label[i]))
+ {
+ fprintf(stderr,
+ "dosfslabel: labels cannot contain lower case characters\n");
+ exit(1);
+ }
rw = 1;
}
fs_open(device, rw);
read_boot(&fs);
+ read_fat(&fs);
if (!rw) {
- fprintf(stdout, "%s\n", fs.label);
+ 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);
}
Index: dosfstools-3.0.10/src/mkdosfs.c
===================================================================
--- dosfstools-3.0.10.orig/src/mkdosfs.c
+++ dosfstools-3.0.10/src/mkdosfs.c
@@ -105,6 +105,7 @@
#define HARD_SECTOR_SIZE 512
#define SECTORS_PER_BLOCK ( BLOCK_SIZE / HARD_SECTOR_SIZE )
+#define NO_NAME "NO NAME "
/* Macro definitions */
@@ -285,7 +286,7 @@ static int verbose = 0; /* Default to v
static long volume_id; /* Volume ID number */
static time_t create_time; /* Creation time */
static struct timeval create_timeval; /* Creation time */
-static char volume_name[] = " "; /* Volume name */
+static char volume_name[] = NO_NAME; /* Volume name */
static unsigned long long blocks; /* Number of blocks in filesystem */
static int sector_size = 512; /* Size of a logical sector */
static int sector_size_set = 0; /* User selected sector size */
@@ -1248,7 +1249,7 @@ setup_tables (void)
}
printf ("Volume ID is %08lx, ", volume_id &
(atari_format ? 0x00ffffff : 0xffffffff));
- if ( strcmp(volume_name, " ") )
+ if ( strcmp(volume_name, NO_NAME) )
printf("volume label %s.\n", volume_name);
else
printf("no volume label.\n");
@@ -1287,7 +1288,7 @@ setup_tables (void)
}
memset(root_dir, 0, size_root_dir);
- if ( memcmp(volume_name, " ", 11) )
+ if ( memcmp(volume_name, NO_NAME, 11) )
{
struct msdos_dir_entry *de = &root_dir[0];
memcpy(de->name, volume_name, 8);
@@ -1630,6 +1631,8 @@ main (int argc, char **argv)
case 'n': /* n : Volume name */
sprintf(volume_name, "%-11.11s", optarg);
+ for (i = 0; i < 11; i++)
+ volume_name[i] = toupper(volume_name[i]);
break;
case 'r': /* r : Root directory entries */
Index: dosfstools-3.0.10/src/boot.c
===================================================================
--- dosfstools-3.0.10.orig/src/boot.c
+++ dosfstools-3.0.10/src/boot.c
@@ -34,6 +34,7 @@
#include "fat.h"
#include "io.h"
#include "boot.h"
+#include "check.h"
#define ROUND_TO_MULTIPLE(n,m) ((n) && (m) ? (n)+(m)-1-((n)-1)%(m) : 0)
@@ -453,7 +454,7 @@ static void write_boot_label(DOS_FS *fs,
fs_write(fs->backupboot_start, sizeof(b), &b);
}
-static loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de)
+loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de)
{
unsigned long cluster;
loff_t offset;
@@ -492,7 +493,10 @@ static void write_volume_label(DOS_FS *f
offset = find_volume_de(fs, &de);
if (offset == 0)
- return;
+ {
+ offset = alloc_rootdir_entry(fs, &de, label);
+ /*return 0;*/
+ }
memcpy(de.name, label, 11);
de.time = CT_LE_W((unsigned short)((mtime->tm_sec >> 1) +
@@ -501,7 +505,16 @@ static void write_volume_label(DOS_FS *f
de.date = CT_LE_W((unsigned short)(mtime->tm_mday +
((mtime->tm_mon+1) << 5) +
((mtime->tm_year-80) << 9)));
- fs_write(offset, sizeof(DIR_ENT), &de);
+ de.attr = ATTR_VOLUME;
+ de.ctime_ms = 0;
+ de.ctime = de.time;
+ de.cdate = de.date;
+ de.adate = de.date;
+ de.starthi = CT_LE_W(0);
+ de.start = CT_LE_W(0);
+ de.size = CT_LE_L(0);
+
+ fs_write(offset, sizeof(DIR_ENT), &de);
}
void write_label(DOS_FS *fs, char *label)
Index: dosfstools-3.0.10/src/check.c
===================================================================
--- dosfstools-3.0.10.orig/src/check.c
+++ dosfstools-3.0.10/src/check.c
@@ -133,8 +133,8 @@ loff_t alloc_rootdir_entry(DOS_FS *fs, D
while (1) {
char expanded[12];
sprintf(expanded, pattern, curr_num);
- memcpy(de->name+4, expanded, 4);
- memcpy(de->ext, expanded+4, 3);
+ memcpy(de->name, expanded, 8);
+ memcpy(de->ext, expanded+8, 3);
clu_num = fs->root_cluster;
i = 0;
offset2 = cluster_start(fs,clu_num);
Index: dosfstools-3.0.10/src/boot.h
===================================================================
--- dosfstools-3.0.10.orig/src/boot.h
+++ dosfstools-3.0.10/src/boot.h
@@ -25,6 +25,7 @@
void read_boot(DOS_FS *fs);
void write_label(DOS_FS *fs, char *label);
+loff_t find_volume_de(DOS_FS *fs, DIR_ENT *de);
/* Reads the boot sector from the currently open device and initializes *FS */