I am working on implementing a log based file system for a file as a class project. I have a lot of work on my OS X 64-bit laptop, but when I try to run code on 32-bit Linux machines in the CS department, I get a seg error.
The API provided allows you to write DISK_SECTOR_SIZE (512) bytes at a time. Our log entry consists of 512 bytes that the user wants to write, as well as some metadata (in which sector he wants to write, such as operation, etc.).
In total, the size of the โrecordโ object is 528 bytes, which means that each journal entry covers 2 sectors on the disk.
The first record records 0-512 in sector 0 and 0-15 in sector 1. The second record records 16-512 in sector 1 and 0-31 in sector 2. The third record records 32-512 in sector 2 and 0-47 in sector 3 . ETC.
So, what I'm doing is reading two sectors, which I will change in 2 freshly defined buffers, copying from the write to buf1 + the calculated offset for bytes with 512 offsets. This works correctly on both machines.
However, the second memcpy fails. In particular, "record + DISK_SECTOR_SIZE-offset" in the segfaults scripts below, but only on the linux machine. Performing some random tests, becomes more curious. The linux machine reports sizeof (Record) as 528. Therefore, if I tried memcpy from writing + 500 to buf for 1 byte, it should not have a problem.
In fact, the largest offset that I can get from the record is 254. That is, memcpy (buf1, record + 254, 1) works, but memcpy (buf1, record + 255, 1) segfaults.
Does anyone know what I am missing?
Record *record = malloc(sizeof(Record)); record->tid = tid; record->opType = OP_WRITE; record->opArg = sector; int i; for (i = 0; i < DISK_SECTOR_SIZE; i++) { record->data[i] = buf[i];