From 7083b0a4fa657bdce8cfaad25c13488b3a46de28 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Fri, 22 May 2009 00:25:11 +0000 Subject: [PATCH] On close or commit, only update those directory entry fields that have an SFT equivalent. The rest stays unmodified on disk. git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@1392 6ac86273-5f31-0410-b378-82cca8765d1b --- hdr/fat.h | 1 + kernel/fatdir.c | 26 ++++++++++++++++++++++---- kernel/fatfs.c | 2 +- kernel/proto.h | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/hdr/fat.h b/hdr/fat.h index 8670bbc..bf4b6ca 100644 --- a/hdr/fat.h +++ b/hdr/fat.h @@ -145,6 +145,7 @@ BOOL checkdstart(struct dpb FAR *dpbp, struct dirent *dentry, CLUSTER value); #define DIR_EXT FNAME_SIZE #define DIR_ATTRIB (FNAME_SIZE+FEXT_SIZE) #define DIR_RESERVED (FNAME_SIZE+FEXT_SIZE+1) +#define DIR_START_HIGH (FNAME_SIZE+FEXT_SIZE+9) #define DIR_TIME (FNAME_SIZE+FEXT_SIZE+11) #define DIR_DATE (FNAME_SIZE+FEXT_SIZE+13) #define DIR_START (FNAME_SIZE+FEXT_SIZE+15) diff --git a/kernel/fatdir.c b/kernel/fatdir.c index 832b506..f4ce395 100644 --- a/kernel/fatdir.c +++ b/kernel/fatdir.c @@ -245,10 +245,10 @@ COUNT dir_read(REG f_node_ptr fnp) * TRUE - all OK. * FALSE - error occured (fnode is released). */ -#ifndef IPL -BOOL dir_write(REG f_node_ptr fnp) +BOOL dir_write_update(REG f_node_ptr fnp, BOOL update) { struct buffer FAR *bp; + UBYTE FAR *vp; if (!(fnp->f_flags & F_DDIR)) return FALSE; @@ -272,7 +272,26 @@ BOOL dir_write(REG f_node_ptr fnp) swap_deleted(fnp->f_dir.dir_name); - putdirent(&fnp->f_dir, &bp->b_buffer[fnp->f_diridx * DIRENT_SIZE]); + vp = &bp->b_buffer[fnp->f_diridx * DIRENT_SIZE]; + + if (update) + { + /* only update fields that are also in the SFT, for dos_close/commit */ + fmemcpy(&vp[DIR_NAME], fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE); + fputbyte(&vp[DIR_ATTRIB], fnp->f_dir.dir_attrib); + fputword(&vp[DIR_TIME], fnp->f_dir.dir_time); + fputword(&vp[DIR_DATE], fnp->f_dir.dir_date); + fputword(&vp[DIR_START], fnp->f_dir.dir_start); +#ifdef WITHFAT32 + if (ISFAT32(fnp->f_dpb)) + fputword(&vp[DIR_START_HIGH], fnp->f_dir.dir_start_high); +#endif + fputlong(&vp[DIR_SIZE], fnp->f_dir.dir_size); + } + else + { + putdirent(&fnp->f_dir, vp); + } swap_deleted(fnp->f_dir.dir_name); @@ -281,7 +300,6 @@ BOOL dir_write(REG f_node_ptr fnp) } return TRUE; } -#endif VOID dir_close(REG f_node_ptr fnp) { diff --git a/kernel/fatfs.c b/kernel/fatfs.c index 8ce34f1..d6c01ac 100644 --- a/kernel/fatfs.c +++ b/kernel/fatfs.c @@ -279,7 +279,7 @@ COUNT dos_close(COUNT fd) } fnp->f_flags |= F_DDIR; - dir_write(fnp); + dir_write_update(fnp, TRUE); dir_close(fnp); return SUCCESS; } diff --git a/kernel/proto.h b/kernel/proto.h index b685fd9..e455dd5 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -140,7 +140,8 @@ VOID fatal(BYTE * err_msg); VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart); f_node_ptr dir_open(const char *dirname, f_node_ptr fnp); COUNT dir_read(REG f_node_ptr fnp); -BOOL dir_write(REG f_node_ptr fnp); +BOOL dir_write_update(REG f_node_ptr fnp, BOOL update); +#define dir_write(fnp) dir_write_update(fnp, FALSE) VOID dir_close(REG f_node_ptr fnp); COUNT dos_findfirst(UCOUNT attr, BYTE * name); COUNT dos_findnext(void);