mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 09:35:46 +01:00
write a function for deleting a specific chunk.
This commit is contained in:
@@ -3,10 +3,31 @@
|
|||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "../util/compat/endian.h"
|
#include "../util/compat/endian.h"
|
||||||
#include "../util/intdef.h"
|
#include "../util/intdef.h"
|
||||||
|
|
||||||
|
void mcx_delchunk(u8 *restrict buf, int chunk) {
|
||||||
|
// load the table data, and clear it
|
||||||
|
u32 *table = (u32 *)buf;
|
||||||
|
size_t bidx = (table[chunk] >> 8) * 0x1000; // compute the byte offset the chunk starts at
|
||||||
|
size_t blen = (table[chunk] & 0xFF) * 0x1000; // compute the byte length of the chunk
|
||||||
|
table[chunk] = 0;
|
||||||
|
table[chunk + 0x400] = time(NULL); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead
|
||||||
|
|
||||||
|
// store the head and tail end of the current chunk
|
||||||
|
u8 *head = buf + bidx;
|
||||||
|
u8 *tail = buf + bidx + blen;
|
||||||
|
|
||||||
|
// count the amount of bytes that we must move
|
||||||
|
blen = 0;
|
||||||
|
for (chunk++; chunk < 0x400; chunk++)
|
||||||
|
blen += table[chunk] & 0xFF * 0x1000;
|
||||||
|
memmove(head, tail, blen);
|
||||||
|
}
|
||||||
|
|
||||||
/* an `*.mcX` contains a `0x2000` byte long table, the first `0x1000` containing
|
/* an `*.mcX` contains a `0x2000` byte long table, the first `0x1000` containing
|
||||||
* `0x400` entries of chunk data.
|
* `0x400` entries of chunk data.
|
||||||
* This chunk data is big-endian, where bytes `0xFFFFFF00` represent the `0x1000` sector offset.
|
* This chunk data is big-endian, where bytes `0xFFFFFF00` represent the `0x1000` sector offset.
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
struct mcx_chunk {
|
struct mcx_chunk {
|
||||||
size_t idx; // byte offset for start of chunk data
|
size_t idx; // byte offset for start of chunk data
|
||||||
u32 len; // byte length of chunk (+ padding)
|
u32 len; // byte length of chunk (+ padding)
|
||||||
u32 time; // modification time in epoch seconds
|
u32 time; // modification time in epoch seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: should return some form of feedback about its success
|
||||||
|
/* Deletes chunk `idx` from `buf`, moving all chunks downwards in the process. */
|
||||||
|
void mcx_delchunk(u8 *restrict buf, int idx);
|
||||||
|
|
||||||
/* indexes the chunks in an `*.mcX` file, writing `0x400` of entries to `chunks` */
|
/* indexes the chunks in an `*.mcX` file, writing `0x400` of entries to `chunks` */
|
||||||
void mcx_index(const u8 *restrict buf, struct mcx_chunk *restrict chunks) NONNULL((1, 2));
|
void mcx_index(const u8 *restrict buf, struct mcx_chunk *restrict chunks) NONNULL((1, 2));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user