From: Lawrence S. <ljs...@us...> - 2019-08-17 20:21:48
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via fb6de0708d45fc1b6596bc4f5309e32a1481da09 (commit) via 5032bac3efb7aa1eb5f37550487115a4ab0588ae (commit) via e6e4877006f933af83e2401553351fc463539531 (commit) via c0fa8d521ebde8f39a03d62d512bc4aff40fda46 (commit) via 3cbaec9a513952e6d4d50d6aa1b3fe7e36f870f5 (commit) via 3b4584c7f0b25998873e8a8ac332641e932be009 (commit) via 68cc1711e02ab3e957b23299737bd5fa8e46ea59 (commit) via ff3f2c180ee3648decea48ea55dcee2d66462bdb (commit) via 14022525ff129b26bf25dd9c832bdf4c2a3dcdca (commit) via 5625983562f6bd8107c70204842f9f70c89499e5 (commit) from 5a91f9882c3252cae3af66768522791f8568363e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit fb6de0708d45fc1b6596bc4f5309e32a1481da09 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 16:19:31 2019 -0400 libkosfat: Enable read/write support. Please note that there are still a few restrictions on write support: 1. New files/directories can only be created with short (8.3) names. 2. Rename support isn't yet present. Other than that, I think everything should be (hopefully) working. Please test and report any issues that arise! commit 5032bac3efb7aa1eb5f37550487115a4ab0588ae Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 16:16:23 2019 -0400 libkosfat: Make mkdir return -1 properly on error, not some positive errno value. commit e6e4877006f933af83e2401553351fc463539531 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 16:12:57 2019 -0400 libkosfat: When searching for a child entry by short name, it helps if we pass the normalized short name, not the original string. This bug had the fun effect of allowing mkdir to make multiple of the same directory... commit c0fa8d521ebde8f39a03d62d512bc4aff40fda46 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 15:36:01 2019 -0400 libkosfat: Update the dentry on open if opened with O_TRUNC. commit 3cbaec9a513952e6d4d50d6aa1b3fe7e36f870f5 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 15:33:02 2019 -0400 libkosfat: Fix dentry cluster number for files in root directory and write dentries immediately on write. commit 3b4584c7f0b25998873e8a8ac332641e932be009 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 15:08:47 2019 -0400 libkosfat: Fix timestamps to they aren't 70 years in the future. commit 68cc1711e02ab3e957b23299737bd5fa8e46ea59 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 15:08:03 2019 -0400 libkosfat: It would help if we could actually create files/directories in the root of a FAT fs... commit ff3f2c180ee3648decea48ea55dcee2d66462bdb Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 14:24:34 2019 -0400 libkosfat: Make sure long file names completely match, not just mostly match. commit 14022525ff129b26bf25dd9c832bdf4c2a3dcdca Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 14:13:17 2019 -0400 libkosfat: Don't add a dot to short names that don't have an extension. commit 5625983562f6bd8107c70204842f9f70c89499e5 Author: Lawrence Sebald <ljs...@us...> Date: Sat Aug 17 14:02:33 2019 -0400 libkosfat: Fix a bug with reads failing after seeks. ----------------------------------------------------------------------- Summary of changes: addons/libkosfat/directory.c | 10 +++---- addons/libkosfat/fs_fat.c | 71 +++++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/addons/libkosfat/directory.c b/addons/libkosfat/directory.c index d45b2ea..d9fb7b7 100644 --- a/addons/libkosfat/directory.c +++ b/addons/libkosfat/directory.c @@ -257,7 +257,7 @@ static int fat_search_long(fat_fs_t *fs, const char *fn, uint32_t cluster, /* Now, is the filename length *actually* right? */ fnlen += fat_strlen_ucs2(longname_buf + fnlen); - if(l > fnlen) { + if(l != fnlen) { skip = (lent->order & 0x3F); continue; } @@ -450,7 +450,7 @@ int fat_find_child(fat_fs_t *fs, const char *fn, fat_dentry_t *parent, if(is_component_short(fnc)) { normalize_shortname(fnc, comp); - err = fat_search_dir(fs, fnc, cl, rv, rcl, roff); + err = fat_search_dir(fs, comp, cl, rv, rcl, roff); *rlcl = 0; *rloff = 0; } @@ -518,8 +518,6 @@ int fat_find_dentry(fat_fs_t *fs, const char *fn, fat_dentry_t *rv, } tok = strtok_r(NULL, "/", &tmp); - cl = cur.cluster_low | (cur.cluster_high << 16); - while(tok) { /* Make sure what we're looking at is a directory... */ @@ -528,6 +526,8 @@ int fat_find_dentry(fat_fs_t *fs, const char *fn, fat_dentry_t *rv, goto out; } + cl = cur.cluster_low | (cur.cluster_high << 16); + if(is_component_short(tok)) { normalize_shortname(tok, comp); lcl = loff = 0; @@ -863,7 +863,7 @@ static int fat_get_free_dentry(fat_fs_t *fs, uint32_t cluster, uint32_t *rcl, static inline void fill_timestamp(struct tm *now, uint16_t *date, uint16_t *ts, uint8_t *tenth) { /* The MS-DOS epoch is January 1, 1980, not January 1, 1970... */ - *date = ((now->tm_year - 10) & 0x7f) << 9; + *date = ((now->tm_year - 80) & 0x7f) << 9; *date |= (now->tm_mon + 1) << 5; *date |= now->tm_mday; diff --git a/addons/libkosfat/fs_fat.c b/addons/libkosfat/fs_fat.c index c1a05e2..f6815b9 100644 --- a/addons/libkosfat/fs_fat.c +++ b/addons/libkosfat/fs_fat.c @@ -7,6 +7,7 @@ #include <time.h> #include <errno.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> @@ -78,9 +79,7 @@ static int fat_create_entry(fat_fs_t *fs, const char *fn, uint8_t attr, /* Figure out where the new directory's name starts in the string... */ newdir_fn = strrchr(parent_fn, '/'); - if(newdir_fn == parent_fn || !newdir_fn) { - /* If it's at the beginning, or non-existent, then the user is trying - to mkdir the root directory, which obviously already exists. */ + if(!newdir_fn) { free(parent_fn); return -EEXIST; } @@ -151,6 +150,8 @@ static int advance_cluster(fat_fs_t *fs, int fd, uint32_t order, int write) { and advance forward. */ clo = 0; cl = fh[fd].dentry.cluster_low | (fh[fd].dentry.cluster_high << 16); + fh[fd].cluster = cl; + fh[fd].cluster_order = clo; } /* At this point, we're definitely moving forward, if at all... */ @@ -168,6 +169,7 @@ static int advance_cluster(fat_fs_t *fs, int fd, uint32_t order, int write) { if(!write) { fh[fd].cluster = cl2; fh[fd].cluster_order = clo; + fh[fd].mode &= ~0x80000000; return -EDOM; } else { @@ -194,10 +196,11 @@ static int advance_cluster(fat_fs_t *fs, int fd, uint32_t order, int write) { cl = cl2; ++clo; - fh[fd].cluster = cl; - fh[fd].cluster_order = clo; } + fh[fd].cluster = cl; + fh[fd].cluster_order = clo; + fh[fd].mode &= ~0x80000000; return 0; } @@ -320,6 +323,14 @@ static void *fs_fat_open(vfs_handler_t *vfs, const char *fn, int mode) { /* Set the size to 0. */ fat_cluster_clear(mnt->fs, cl, &rv); fh[fd].dentry.size = 0; + + if((rv = fat_update_dentry(mnt->fs, &fh[fd].dentry, + fh[fd].dentry_cluster, + fh[fd].dentry_offset)) < 0) { + errno = -rv; + mutex_unlock(&fat_mutex); + return NULL; + } } /* Fill in the rest of the handle */ @@ -338,26 +349,11 @@ created: static int fs_fat_close(void *h) { file_t fd = ((file_t)h) - 1; - int mode, rv; - fat_fs_t *fs; + int rv = 0; mutex_lock(&fat_mutex); if(fd < MAX_FAT_FILES && fh[fd].opened) { - /* If the file was open for writing, then we need to update the dentry - on the disk... */ - mode = fh[fd].mode & O_MODE_MASK; - if(mode == O_WRONLY && mode == O_RDWR) { - fs = fh[fd].fs->fs; - - if((mode = fat_update_dentry(fs, &fh[fd].dentry, - fh[fd].dentry_cluster, - fh[fd].dentry_offset)) < 0) { - rv = -1; - errno = -mode; - } - } - fh[fd].opened = 0; fh[fd].dentry_offset = fh[fd].dentry_cluster = 0; fh[fd].dentry_lcl = fh[fd].dentry_loff = 0; @@ -431,7 +427,7 @@ static ssize_t fs_fat_read(void *h, void *buf, size_t cnt) { mutex_unlock(&fat_mutex); return 0; } - else { + else if(mode < 0) { mutex_unlock(&fat_mutex); errno = -mode; return -1; @@ -636,6 +632,7 @@ static ssize_t fs_fat_write(void *h, const void *buf, size_t cnt) { /* Is there still more to write after this cluster? */ if(cnt > bs) { memcpy(block, bbuf, bs); + fat_cluster_mark_dirty(fs, fh[fd].cluster); fh[fd].ptr += bs; cnt -= bs; bbuf += bs; @@ -663,8 +660,15 @@ static ssize_t fs_fat_write(void *h, const void *buf, size_t cnt) { /* If the file pointer is past the end of the file as recorded in its directory entry, update the directory entry with the new size. */ - if(fh[fd].ptr > fh[fd].dentry.size) { + if(fh[fd].ptr > fh[fd].dentry.size || mode == O_WRONLY) { fh[fd].dentry.size = fh[fd].ptr; + + if((err = fat_update_dentry(fs, &fh[fd].dentry, + fh[fd].dentry_cluster, + fh[fd].dentry_offset)) < 0) { + rv = -1; + errno = -err; + } } /* Update the file's modification timestamp. */ @@ -757,7 +761,7 @@ static time_t fat_time_to_stat(uint16_t date, uint16_t time) { struct tm tmv; /* The MS-DOS epoch is January 1, 1980, not January 1, 1970... */ - tmv.tm_year = (date >> 9) + 10; + tmv.tm_year = (date >> 9) + 80; tmv.tm_mon = ((date >> 5) & 0x0F) - 1; tmv.tm_mday = date & 0x1F; @@ -787,16 +791,19 @@ static void fill_stat_timestamps(const fat_dentry_t *ent, struct stat *buf) { } static void copy_shortname(fat_dentry_t *dent, char *fn) { - int i, j; + int i, j = 0; for(i = 0; i < 8 && dent->name[i] != ' '; ++i) { fn[i] = dent->name[i]; } - fn[i++] = '.'; + /* Only add a dot if there's actually an extension. */ + if(dent->name[8] != ' ') { + fn[i++] = '.'; - for(j = 0; j < 3 && dent->name[8 + j] != ' '; ++j) { - fn[i + j] = dent->name[8 + j]; + for(; j < 3 && dent->name[8 + j] != ' '; ++j) { + fn[i + j] = dent->name[8 + j]; + } } fn[i + j] = '\0'; @@ -1111,7 +1118,8 @@ static int fs_fat_mkdir(vfs_handler_t *vfs, const char *fn) { if((err = fat_create_entry(fs->fs, fn, FAT_ATTR_DIRECTORY, &cl, &off, &lcl, &loff, &buf, &cl2)) < 0) { mutex_unlock(&fat_mutex); - return -err; + errno = -err; + return -1; } /* Add entries for "." and ".." */ @@ -1343,11 +1351,6 @@ int fs_fat_mount(const char *mp, kos_blockdev_t *dev, uint32_t flags) { return -1; } - if((flags & FS_FAT_MOUNT_READWRITE)) { - dbglog(DBG_DEBUG, "fs_fat: Read/write mode not yet supported.\n"); - return -1; - } - mutex_lock(&fat_mutex); /* Try to initialize the filesystem */ hooks/post-receive -- A pseudo Operating System for the Dreamcast. |