From 5fed7548cd23cecab198b84de7f64d9f55445e33 Mon Sep 17 00:00:00 2001 From: neil Date: Sun, 12 Jul 2015 16:53:22 +0000 Subject: [PATCH] Use the FAT_MAX_SHORT_NAME macro instead of hard-coded 11. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@50943 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/filesys/fat/direntry.c | 11 +++++++---- rom/filesys/fat/disk.c | 4 ++-- rom/filesys/fat/fat.c | 8 +++----- rom/filesys/fat/fat_fs.h | 2 +- rom/filesys/fat/names.c | 35 +++++++++++++++++++---------------- rom/filesys/fat/ops.c | 4 ++-- 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/rom/filesys/fat/direntry.c b/rom/filesys/fat/direntry.c index 4af8909041..0bb8a7d109 100644 --- a/rom/filesys/fat/direntry.c +++ b/rom/filesys/fat/direntry.c @@ -153,9 +153,11 @@ LONG GetNextDirEntry(struct DirHandle *dh, struct DirEntry *de) /* ignore the . and .. entries */ if (de->e.entry.name[0] == '.' && ((de->index == 0 - && strncmp((char *)de->e.entry.name, ". ", 11) == 0) + && strncmp((char *)de->e.entry.name, ". ", + FAT_MAX_SHORT_NAME) == 0) || (de->index == 1 - && strncmp((char *)de->e.entry.name, ".. ", 11) == 0))) + && strncmp((char *)de->e.entry.name, ".. ", + FAT_MAX_SHORT_NAME) == 0))) { D(bug("[fat] skipping . or .. entry\n")); continue; @@ -190,10 +192,11 @@ LONG GetParentDir(struct DirHandle *dh, struct DirEntry *de) /* make sure it's actually the parent dir entry */ if (((de->e.entry.attr & ATTR_DIRECTORY) == 0) || - strncmp((char *)de->e.entry.name, ".. ", 11) != 0) + strncmp((char *)de->e.entry.name, ".. ", FAT_MAX_SHORT_NAME) + != 0) { D(bug("[fat] entry index 1 does not have name '..', can't go up\n")); - D(bug("[fat] actual name: '%.*s', attrs: 0x%x\n", 11, + D(bug("[fat] actual name: '%.*s', attrs: 0x%x\n", FAT_MAX_SHORT_NAME, de->e.entry.name, de->e.entry.attr)); return ERROR_OBJECT_NOT_FOUND; } diff --git a/rom/filesys/fat/disk.c b/rom/filesys/fat/disk.c index 1b7dd4ea1b..c5bc7f2d3d 100644 --- a/rom/filesys/fat/disk.c +++ b/rom/filesys/fat/disk.c @@ -239,8 +239,8 @@ void DoDiskInsert(struct Globals *glob) (sb->type == 32) ? ID_FAT32_DISK : ID_FAT12_DISK; - if ((newvol->dol_Name = - MKBADDR(AllocVecPooled(pool, 13)))) + if ((newvol->dol_Name = MKBADDR( + AllocVecPooled(pool, FAT_MAX_SHORT_NAME + 2)))) { #ifdef AROS_FAST_BPTR /* ReadFATSuper() sets a null byte after the diff --git a/rom/filesys/fat/fat.c b/rom/filesys/fat/fat.c index 2a51040893..b2679d17ad 100644 --- a/rom/filesys/fat/fat.c +++ b/rom/filesys/fat/fat.c @@ -529,7 +529,7 @@ LONG ReadFATSuper(struct FSSuper *sb) UpdateDirEntry(&dir_entry); } - SetVolumeName(sb, ebpb->bs_vollab, 11); + SetVolumeName(sb, ebpb->bs_vollab, FAT_MAX_SHORT_NAME); ReleaseDirHandle(&dh); glob->formatting = FALSE; @@ -643,10 +643,8 @@ static LONG GetVolumeIdentity(struct FSSuper *sb, D(bug("[fat] found volume id entry %ld\n", dh.cur_index)); /* copy the name in. volume->name is a BSTR */ - volume->name[1] = de.e.entry.name[0]; - - for (i = 1; i < 11; i++) + for (i = 1; i < FAT_MAX_SHORT_NAME; i++) { if (volume->name[i] == ' ') volume->name[i + 1] = de.e.entry.name[i]; @@ -809,7 +807,7 @@ LONG FormatFATVolume(const UBYTE *name, UWORD len, struct Globals *glob) ebpb->bs_volid = FastRand(eclock.ev_lo ^ eclock.ev_hi); /* copy volume name in */ - for (i = 0; i < 11; i++) + for (i = 0; i < FAT_MAX_SHORT_NAME; i++) if (i < len) ebpb->bs_vollab[i] = toupper(name[i]); else diff --git a/rom/filesys/fat/fat_fs.h b/rom/filesys/fat/fat_fs.h index 70b59e527d..4c6cc2450e 100644 --- a/rom/filesys/fat/fat_fs.h +++ b/rom/filesys/fat/fat_fs.h @@ -326,7 +326,7 @@ struct Globals { \ ULONG i; \ checksum = 0; \ - for (i = 0; i < 11; i++) \ + for (i = 0; i < FAT_MAX_SHORT_NAME; i++) \ checksum = \ ((checksum & 1) ? 0x80 : 0) + (checksum >> 1) + name[i]; \ } \ diff --git a/rom/filesys/fat/names.c b/rom/filesys/fat/names.c index 72230c835e..a82eb65809 100644 --- a/rom/filesys/fat/names.c +++ b/rom/filesys/fat/names.c @@ -69,13 +69,13 @@ LONG GetDirEntryShortName(struct DirEntry *de, STRPTR name, ULONG *len) D( bug("[fat] extracting short name for name '"); - RawPutChars(raw, 11); + RawPutChars(raw, FAT_MAX_SHORT_NAME); bug("' (index %ld)\n", de->index); ) /* copy the chars into the return string */ c = name; - for (i = 0; i < 11; i++) + for (i = 0; i < FAT_MAX_SHORT_NAME; i++) { *c = tolower(raw[i]); @@ -154,8 +154,8 @@ LONG GetDirEntryLongName(struct DirEntry *short_de, STRPTR name, return 0; } - D(bug("[fat] looking for long name for name '%.11s' (index %ld)\n", raw, - short_de->index)); + D(bug("[fat] looking for long name for name '%.*s' (index %ld)\n", + FAT_MAX_SHORT_NAME, raw, short_de->index)); /* compute the short name checksum. this value is held in every associated * long name entry to help us identify it. see FATdoc 1.03 p28 */ @@ -248,7 +248,7 @@ LONG GetDirEntryLongName(struct DirEntry *short_de, STRPTR name, LONG SetDirEntryName(struct DirEntry *short_de, STRPTR name, ULONG len) { struct Globals *glob = short_de->sb->glob; - UBYTE basis[11]; + UBYTE basis[FAT_MAX_SHORT_NAME]; ULONG nlong; LONG src, dst, i, left, root_end; ULONG seq = 0, cur = 0; @@ -349,7 +349,7 @@ LONG SetDirEntryName(struct DirEntry *short_de, STRPTR name, ULONG len) src = i + 1; /* copy it in */ - while (src < len && dst < 11) + while (src < len && dst < FAT_MAX_SHORT_NAME) { if (name[src] != ' ') { @@ -371,10 +371,10 @@ LONG SetDirEntryName(struct DirEntry *short_de, STRPTR name, ULONG len) } /* pad the rest of the right side with spaces */ - for (; dst < 11; dst++) + for (; dst < FAT_MAX_SHORT_NAME; dst++) basis[dst] = ' '; - D(bug("[fat] basis name is '%.11s'\n", basis)); + D(bug("[fat] basis name is '%.*s'\n", FAT_MAX_SHORT_NAME, basis)); /* get a fresh handle on the current directory */ InitDirHandle(short_de->sb, short_de->cluster, &dh, FALSE); @@ -400,7 +400,8 @@ LONG SetDirEntryName(struct DirEntry *short_de, STRPTR name, ULONG len) CopyMem(tail, &basis[left], strlen(tail)); cur = seq; - D(bug("[fat] new basis name is '%.11s'\n", basis)); + D(bug("[fat] new basis name is '%.*s'\n", + FAT_MAX_SHORT_NAME, basis)); } /* get the next entry, and bail if we hit the end of the dir */ @@ -415,27 +416,29 @@ LONG SetDirEntryName(struct DirEntry *short_de, STRPTR name, ULONG len) } /* compare the two names */ - D(bug("[fat] comparing '%.11s' with '%.11s'\n", basis, - de.e.entry.name)); - for (i = 0; i < 11; i++) + D(bug("[fat] comparing '%.*s' with '%.*s'\n", + FAT_MAX_SHORT_NAME, basis, + FAT_MAX_SHORT_NAME, de.e.entry.name)); + for (i = 0; i < FAT_MAX_SHORT_NAME; i++) if (de.e.entry.name[i] != basis[i]) break; /* if we reached the end, then our current basis is in use and we * need to generate a new one and start again */ - if (i == 11) + if (i == FAT_MAX_SHORT_NAME) { seq++; RESET_DIRHANDLE(&dh); } } - D(bug("[fat] basis name '%.11s' not in use, using it\n", basis)); + D(bug("[fat] basis name '%.*s' not in use, using it\n", + FAT_MAX_SHORT_NAME, basis)); } /* copy the new name into the original entry. we don't write it out - * we'll leave that for the caller to do, it's his entry */ - CopyMem(basis, short_de->e.entry.name, 11); + CopyMem(basis, short_de->e.entry.name, FAT_MAX_SHORT_NAME); /* we can stop here if no long name is required */ if (nlong == 0) @@ -554,7 +557,7 @@ ULONG NumLongNameEntries(STRPTR name, ULONG len) /* if the name is standard 8.3 (or less) then we don't need any long name * entries - the name can be contained within the standard entry */ - if (len <= 12) + if (len <= FAT_MAX_SHORT_NAME + 1) { left = 0; diff --git a/rom/filesys/fat/ops.c b/rom/filesys/fat/ops.c index ca9d5ca2c4..b4b710650a 100644 --- a/rom/filesys/fat/ops.c +++ b/rom/filesys/fat/ops.c @@ -723,14 +723,14 @@ LONG OpCreateDir(struct ExtFileLock *dirlock, UBYTE *name, ULONG namelen, * with a different name */ GetDirEntry(&sdh, 0, &sde); CopyMem(&de.e.entry, &sde.e.entry, sizeof(struct FATDirEntry)); - CopyMem(". ", &sde.e.entry.name, 11); + CopyMem(". ", &sde.e.entry.name, FAT_MAX_SHORT_NAME); UpdateDirEntry(&sde); /* create the dot-dot entry. again, a copy, with the cluster pointer setup * to point to the parent */ GetDirEntry(&sdh, 1, &sde); CopyMem(&de.e.entry, &sde.e.entry, sizeof(struct FATDirEntry)); - CopyMem(".. ", &sde.e.entry.name, 11); + CopyMem(".. ", &sde.e.entry.name, FAT_MAX_SHORT_NAME); cluster = dh.ioh.first_cluster; if (cluster == dh.ioh.sb->rootdir_cluster) cluster = 0; -- 2.11.4.GIT