/* Close out an extent. Must be called with valid cf values */ static void trunc_cf(CFILE *cf) { long pos = cf->pos; int lex; int rc; if (cf->dirp < 0) return; /* * cf->pos points one byte past the last byte written/copied. * If the file length is exactly on a 16 KiB logical-extent boundary, * the last valid extent is the previous one and its record count is * 0x80. The old calculation used pos/(16*1024) and masked the record * count with 0x7f; for 16/32/48 KiB files this changed the previous * directory entry to the next extent and wrote RC=0. */ if (pos > 0 && (pos & 0x3fff) == 0) { lex = (pos - 1) / (16*1024); rc = 0x80; } else { lex = pos / (16*1024); rc = ((pos & 0x3fff) + 127) >> 7; } { BYTE *entry = cf->dp->dir + cf->dirp*32; entry[12] = lex&0x1f; entry[14] = lex>>5; entry[15] = rc; } }