Skip to content

Commit f835d80

Browse files
uppercase fat filenames
1 parent ece00f4 commit f835d80

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/fatdrvce/fatdrvce.asm

+71-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
include '../include/library.inc'
33
;-------------------------------------------------------------------------------
44

5-
library FATDRVCE, 2
5+
library FATDRVCE, 3
66

77
;-------------------------------------------------------------------------------
88
; v1 functions
@@ -54,6 +54,7 @@ virtual at 0
5454
FAT_ERROR_INVALID_MAGIC rb 1
5555
FAT_ERROR_INVALID_SIGNATURE rb 1
5656
FAT_ERROR_NO_MORE_ENTRIES rb 1
57+
FAT_ERROR_INVALID_NAME rb 1
5758
end virtual
5859
virtual at 0
5960
FAT_LIST_FILEONLY rb 1
@@ -1060,6 +1061,10 @@ fat_Create:
10601061
; FAT_SUCCESS on success
10611062
ld iy,0
10621063
add iy,sp
1064+
ld hl,(iy + 9)
1065+
call util_validate_fat_name
1066+
ld hl,FAT_ERROR_INVALID_NAME
1067+
ret z
10631068
ld hl,-512
10641069
add hl,sp
10651070
ld sp,hl ; temporary space for concat
@@ -1788,6 +1793,7 @@ util_get_fat_name:
17881793
jr z,.done1
17891794
or a,a
17901795
jr z,.done1
1796+
call util_toupper
17911797
ld (hl),a
17921798
inc de
17931799
inc hl
@@ -1823,6 +1829,7 @@ util_get_fat_name:
18231829
jr z,.other
18241830
inc de
18251831
.store:
1832+
call util_toupper
18261833
ld (hl),a
18271834
inc hl
18281835
inc b
@@ -1851,6 +1858,69 @@ util_get_fat_name:
18511858
pop de
18521859
ret
18531860

1861+
;-------------------------------------------------------------------------------
1862+
util_validate_fat_name:
1863+
; ensure none of the following characters: * ? . , ; : / \ | + = < > [ ] " \t
1864+
; inputs:
1865+
; hl: pointer to null terminated string
1866+
; outputs:
1867+
; z set if invalid name
1868+
.loop:
1869+
ld a,(hl)
1870+
or a,a
1871+
jr z,.done
1872+
cp a,'*'
1873+
ret z
1874+
cp a,'?'
1875+
ret z
1876+
cp a,'.'
1877+
ret z
1878+
cp a,','
1879+
ret z
1880+
cp a,';'
1881+
ret z
1882+
cp a,':'
1883+
ret z
1884+
cp a,'/'
1885+
ret z
1886+
cp a,'\'
1887+
ret z
1888+
cp a,'|'
1889+
ret z
1890+
cp a,'+'
1891+
ret z
1892+
cp a,'='
1893+
ret z
1894+
cp a,'<'
1895+
ret z
1896+
cp a,'>'
1897+
ret z
1898+
cp a,'['
1899+
ret z
1900+
cp a,']'
1901+
ret z
1902+
cp a,'"'
1903+
ret z
1904+
cp a,' '
1905+
ret z
1906+
inc hl
1907+
jr .loop
1908+
.done:
1909+
inc a
1910+
ret
1911+
1912+
;-------------------------------------------------------------------------------
1913+
util_toupper:
1914+
sub a,'a'
1915+
cp a,1+'z'-'a'
1916+
jr nc,.nochange
1917+
add a,'a'
1918+
res 5,a
1919+
ret
1920+
.nochange:
1921+
add a,'a'
1922+
ret
1923+
18541924
;-------------------------------------------------------------------------------
18551925
util_get_component_start:
18561926
ld a,(de)

src/fatdrvce/fatdrvce.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef enum {
5252
FAT_ERROR_INVALID_MAGIC, /**< Some invalid magic bytes were detected */
5353
FAT_ERROR_INVALID_SIGNATURE, /**< Some invalid signature was detected */
5454
FAT_ERROR_NO_MORE_ENTRIES, /**< No more entries in the directory */
55+
FAT_ERROR_INVALID_NAME, /**< An invalid filename was provided */
5556
} fat_error_t;
5657

5758
/**

0 commit comments

Comments
 (0)