Permalink
Browse files

small tweaks and fixes

  • Loading branch information...
1 parent 9215960 commit b8ce61b4a40125ac846406bff9d8df6e374eea1c tz committed Feb 5, 2010
Showing with 49 additions and 19 deletions.
  1. +2 −2 fat32lib/Makefile
  2. +2 −2 fat32lib/Makefile.linux
  3. +1 −1 fat32lib/TODO
  4. +31 −3 fat32lib/creat.c
  5. +3 −0 fat32lib/fat32.h
  6. +1 −1 fat32lib/fat32private.h
  7. +9 −9 fat32lib/mount.c
  8. +0 −1 fat32lib/write.c
View
@@ -1,4 +1,4 @@
-all: libfat32.a sdhc.o setforavr
+all: setforavr libfat32.a sdhc.o
.SUFFIXES: .elf .hex .eep .lss .sym .upload .dsm .c .s .S .o .l
@@ -32,7 +32,7 @@ setforavr:
rm -f setforlinux
clean:
- rm -f *.hex *.eep *.elf *.lss *.sym *.dsm *.o *.a *.d
+ rm -f *.hex *.eep *.elf *.lss *.sym *.dsm *.o *.d
mount.o fat32data.o opendir.o creat.o deltrunc.o write.o read.o seek.o: fat32.h fat32private.h
View
@@ -1,4 +1,4 @@
-all: setforlinux liblinfat32.a sdhcemu.o
+all: setforlinux liblinfat32.a
CFLAGS=-g -O2 -Wall $(DFLAGS)
CC=gcc
@@ -14,7 +14,7 @@ setforlinux:
rm -f setforavr
clean:
- rm -f *.hex *.eep *.elf *.lss *.sym *.dsm *.o *.a *.d
+ rm -f *.hex *.eep *.elf *.lss *.sym *.dsm *.o *.d
mount.o fat32data.o opendir.o creat.o deltrunc.o write.o read.o seek.o: fat32.h fat32private.h
View
@@ -1,5 +1,5 @@
-(TESTING) New cluster and link cluster should only do one read then write instead of r w r w.
dirty buffer flag for RMW - write only when needed, validate RMW fully/properly
+Incrementing time (find latest, keep adding 2 seconds for sort order).
Double buffer for sector (fill one while pulling from other).
typedef int to something?
max file size - if using auto-create log, auto create next log
View
@@ -5,6 +5,19 @@ static u32 nextlog = 0;
unsigned char newextension[4] = "LOG";
+void setname(u8 *newname, u8 *newext)
+{
+ if (!direntsect || readsec(direntsect))
+ return;
+ u8 *c;
+ c = &filesectbuf[direntnum << 5];
+ if( newname )
+ tzmemcpy(c, newname, 8 );
+ if( newext )
+ tzmemcpy(c, newname, 3 );
+ writesec(direntsect);
+}
+
static void clearclus(u32 clus)
{
u16 sect;
@@ -48,7 +61,10 @@ static int findemptydirent(u8 * dosname)
if (c[11] == 0x0f) // long name ent
continue;
if (!dosname) {
- if (c[8] == newextension[0] && c[9] == newextension[1] && c[10] == newextension[2]) {
+ if (
+ 1 //ignore extension for now - rename TMP to LOG or JPG?
+ // c[8] == newextension[0] && c[9] == newextension[1] && c[10] == newextension[2]
+ ) {
u32 thislog = 0;
u16 j, k;
for (j = 0; j < 8; j++) {
@@ -80,8 +96,20 @@ static void setdirent(u8 * c, u8 attr, u32 clus)
{
c[11] = attr;
// date - jan 2010
- c[16] = c[18] = c[24] = 0x21;
- c[17] = c[19] = c[25] = 0x3c;
+//0x0d create time ms, 0-199
+//0x0e-f create time
+//0x10-11 create date
+//0x12-3 last access date
+//0x16-7 last mod time
+//0x18-9 last mod date
+ unsigned crdate = todosdate(2010,1,26);
+ unsigned crtime = todostime(0,5,0);
+ c[16] = c[18] = c[24] = crdate;
+ c[17] = c[19] = c[25] = crdate >> 8;
+ c[13] = 100;
+ c[14] = c[22] = crtime;
+ c[15] = c[23] = crtime >> 8;
+
c[26] = clus;
c[27] = clus >> 8;
c[20] = clus >> 16;
View
@@ -62,6 +62,9 @@ void flushbuf(void);
// Maxout extends to end of cluster for crash recovery - won't miss anything
void syncdirent(u8 maxout);
+// For current file - change name entry - FLUSH before, SEEK after just like syncdirent.
+void setname(u8 *newname, u8 *newext);
+
// reset next free clus and avail clus to unknown
void zaphint(void);
View
@@ -65,6 +65,6 @@ u32 nextclus(u32 clus);
// ATTR X X ARCH DIR VOLID SYS HID RO
// DATE Y-1980, 7 bits : Month 1-12 J=1, 4 bits, Day, 5 bits, 1-31
-#define todosdate(y,m,d) (y-1980<<9|m<<5|d)
+#define todosdate(y,m,d) ((y-1980)<<9|m<<5|d)
// TIME Hour, 5bits, 0-23 ; Minute 6bits, 0-59 ; Secs/2, 5 bits, 0-29 for 0-58.
#define todostime(h,m,s) (h<<11|m<<5|s>>1)
View
@@ -36,7 +36,6 @@ int rawmount(u32 addr, u32 partlen)
// 3-a OEM name
u8 *c;
- u16 flg; // FAT flag - mirroring disable (0x80), ls4b which FAT is master
u16 rsv; // reserved sectors - first fat starts just after
u16 fsi; // sector of filesystem info (hints)
@@ -46,21 +45,23 @@ int rawmount(u32 addr, u32 partlen)
fpm.nft = *c++;
c = &filesectbuf[0x20];
get4todw(fpm.mxcl); // get total
+
if (fpm.mxcl > partlen)
- return -2; // more sectors than partition table says
+ return -3; // more sectors than partition table says
get4todw(fpm.spf);
// this is the only divide
fpm.mxcl = (fpm.mxcl - rsv - (fpm.nft * fpm.spf)) / fpm.spc;
- get2tow(flg);
- if (flg)
- return -2; // assume first cluster is master, mirror - 99.9% case
+ get2tow(fsi); // FAT flag - mirroring disable (0x80), ls4b which FAT is master
+ if (fsi)
+ return -4; // assume first cluster is master, mirror - 99.9% case
c += 2;
get4todw(fpm.d0c);
get2tow(fsi);
+
if (fsi != 1)
- return -1; //assume fsinfo is at sector 1, 99% case
+ return -5; //assume fsinfo is at sector 1, 99% case
fpm.hint = addr + fsi;
fpm.fat0 = addr + rsv;
fpm.data0 = fpm.fat0 + fpm.nft * fpm.spf - (fpm.spc << 1);
@@ -74,7 +75,7 @@ int rawmount(u32 addr, u32 partlen)
get4todw(s1);
if (s0 != 0x41615252 || s1 != 0x61417272)
- return -2;
+ return -6;
resetrootdir();
return 0;
@@ -125,8 +126,8 @@ static int decodeebr(u32 addr, u32 extpartlen)
return 1;
}
#endif
+
// index not used, but for Nth FAT32 partition
-//#include <stdio.h>
int mount(int index)
{
u32 secaddr, partlen;
@@ -144,7 +145,6 @@ int mount(int index)
c += 4;
get4todw(secaddr);
get4todw(partlen);
- // printf( "%lu, %lu, %d\n", secaddr, partlen, ptype );
switch (ptype) {
case 0xb:
case 0xc:
View
@@ -1,5 +1,4 @@
#include "fat32private.h"
-#include <stdio.h>
void syncdirent(u8 maxout)
{

0 comments on commit b8ce61b

Please sign in to comment.