Skip to content

Commit

Permalink
lxfs: allocate temporary block buffer when mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 29, 2024
1 parent a1b78e8 commit 74d0863
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 7 additions & 1 deletion fs/lxfs/src/include/lxfs/lxfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef struct Mountpoint {
char device[MAX_FILE_PATH];
int fd;
int sectorSize, blockSize, blockSizeBytes;

void *blockTableBuffer; // of size blockSizeBytes
} Mountpoint;

typedef struct {
Expand Down Expand Up @@ -110,5 +112,9 @@ typedef struct {
uint64_t refCount;
} __attribute__((packed)) LXFSFileHeader;


void lxfsMount(MountCommand *);
int lxfsReadBlock(Mountpoint *, uint64_t, void *);
int lxfsWriteBlock(Mountpoint *, uint64_t, const void *);
uint64_t lxfsNextBlock(Mountpoint *, uint64_t);
uint64_t lxfsReadNextBlock(Mountpoint *, uint64_t, void *);
uint64_t lxfsWriteNextBlock(Mountpoint *, uint64_t, const void *);
21 changes: 18 additions & 3 deletions fs/lxfs/src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,25 @@ void lxfsMount(MountCommand *cmd) {
return;
}

int sectorSize = 512 << ((id->parameters >> 1) & 3);
int blockSize = ((id->parameters >> 3) & 0x0F) + 1;
int blockSizeBytes = sectorSize * blockSize;

void *buffer = malloc(blockSizeBytes);
if(!buffer) {
cmd->header.header.status = -ENOMEM;
close(fd);
free(id);
luxSendDependency(cmd);
return;
}

Mountpoint *mp = allocateMP();
if(!mp) {
cmd->header.header.status = -ENOMEM;
close(fd);
free(id);
free(buffer);
luxSendDependency(cmd);
return;
}
Expand All @@ -80,9 +94,10 @@ void lxfsMount(MountCommand *cmd) {

strcpy(mp->device, cmd->source);
mp->fd = fd;
mp->sectorSize = 512 << ((id->parameters >> 1) & 3);
mp->blockSize = ((id->parameters >> 3) & 0x0F) + 1;
mp->blockSizeBytes = mp->sectorSize * mp->blockSize;
mp->sectorSize = sectorSize;
mp->blockSize = blockSize;
mp->blockSizeBytes = blockSizeBytes;
mp->blockTableBuffer = buffer;

luxLogf(KPRINT_LEVEL_DEBUG, "- %d bytes per sector, %d sectors per block\n", mp->sectorSize, mp->blockSize);

Expand Down

0 comments on commit 74d0863

Please sign in to comment.