/* Prune the db file the first time this directory is opened in a session. */ void fsdb_clean_dir (a_inode *dir) { TCHAR buf[1 + 4 + 257 + 257 + 81]; TCHAR *n; FILE *f; off_t pos1 = 0, pos2; if (!dir->nname) return; n = build_nname (dir->nname, FSDB_FILE); f = _tfopen (n, _T("r+b")); if (f == 0) { xfree (n); return; } for (;;) { pos2 = ftell (f); if (fread (buf, 1, sizeof buf, f) < sizeof buf) break; fsdb_fixup (f, buf, sizeof buf, dir); if (buf[0] == 0) continue; if (pos1 != pos2) { fseek (f, pos1, SEEK_SET); fwrite (buf, 1, sizeof buf, f); fseek (f, pos2 + sizeof buf, SEEK_SET); } pos1 += sizeof buf; } fclose (f); my_truncate (n, pos1); xfree (n); }
/* Prune the db file the first time this directory is opened in a session. */ void fsdb_clean_dir (a_inode *dir) { char buf[1 + 4 + 257 + 257 + 81]; char *n = build_nname (dir->nname, FSDB_FILE); FILE *f = fopen (n, "r+b"); off_t pos1 = 0, pos2; if (f == 0) { free (n); return; } for (;;) { pos2 = ftell (f); if (fread (buf, 1, sizeof buf, f) < sizeof buf) break; fsdb_fixup (f, buf, sizeof buf, dir); if (buf[0] == 0) continue; if (pos1 != pos2) { fseek (f, pos1, SEEK_SET); fwrite (buf, 1, sizeof buf, f); fseek (f, pos2 + sizeof buf, SEEK_SET); } pos1 += sizeof buf; } fclose (f); truncate (n, pos1); free (n); }
/* Prune the db file the first time this directory is opened in a session. */ void fsdb_clean_dir (a_inode *dir) { uae_u8 buf[1 + 4 + 257 + 257 + 81]; TCHAR *n; FILE *f; off_t pos1 = 0, pos2; if (!dir->nname) return; n = build_nname (dir->nname, FSDB_FILE); f = _tfopen (n, _T("r+b")); if (f == 0) { xfree (n); return; } for (;;) { pos2 = ftell (f); if (fread (buf, 1, sizeof buf, f) < sizeof buf) break; fsdb_fixup (f, buf, sizeof buf, dir); if (buf[0] == 0) continue; if (pos1 != pos2) { fseek (f, pos1, SEEK_SET); size_t isWritten = fwrite (buf, 1, sizeof buf, f); if (isWritten < sizeof(buf)) write_log("%s:%d [%s] - Failed to write %ld bytes (%ld/%ld)", __FILE__, __LINE__, __FUNCTION__, sizeof(buf) - isWritten, isWritten, sizeof(buf)); fseek (f, pos2 + sizeof buf, SEEK_SET); } pos1 += sizeof buf; } fclose (f); if (pos1 == 0) { kill_fsdb (dir); } else { my_truncate (n, pos1); } xfree (n); }