diff options
author | Freya Murphy <freya@freyacat.org> | 2025-05-06 16:37:53 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-05-06 16:37:53 -0400 |
commit | e26b031702d3f0ef63afcae814ebddd439d05274 (patch) | |
tree | 8a3952a3c56d5bcda7a8ae81e79547278f42bee7 | |
parent | more docs (diff) | |
download | comus-e26b031702d3f0ef63afcae814ebddd439d05274.tar.gz comus-e26b031702d3f0ef63afcae814ebddd439d05274.tar.bz2 comus-e26b031702d3f0ef63afcae814ebddd439d05274.zip |
fmt
-rw-r--r-- | kernel/drivers/ata.c | 20 | ||||
-rw-r--r-- | kernel/fs/tar.c | 377 | ||||
-rw-r--r-- | kernel/include/comus/procs.h | 8 | ||||
-rw-r--r-- | user/forkman.c | 2 |
4 files changed, 211 insertions, 196 deletions
diff --git a/kernel/drivers/ata.c b/kernel/drivers/ata.c index 2fc059f..b05e78d 100644 --- a/kernel/drivers/ata.c +++ b/kernel/drivers/ata.c @@ -252,7 +252,7 @@ static enum ide_error ide_channel_poll(struct ide_channel *channel, if (advanced_check) { uint8_t state = ide_channel_read(channel, ATA_REG_STATUS); - // check for errors or faults + // check for errors or faults if (state & ATA_SR_ERROR) { return IDE_ERROR_POLL_STATUS_REGISTER_ERROR; } @@ -261,7 +261,7 @@ static enum ide_error ide_channel_poll(struct ide_channel *channel, return IDE_ERROR_POLL_DEVICE_FAULT; } - // then check if drive is ready + // then check if drive is ready if ((state & ATA_SR_DRIVEREQUESTREADY) == 0) { return IDE_ERROR_POLL_DRIVE_REQUEST_NOT_READY; } @@ -335,13 +335,13 @@ static void ide_initialize(uint32_t BAR0, uint32_t BAR1, uint32_t BAR2, .bus_master_ide_base = (BAR4 & 0xFFFFFFFC) + 8, }; - // disable irqs + // disable irqs ide_channel_write(channel(ATA_PRIMARY), ATA_REG_CONTROL, 2); ide_channel_write(channel(ATA_SECONDARY), ATA_REG_CONTROL, 2); - // detect disks by writing CMD_IDENTIFY to each one and checking for err. - // if device exists, ask for its ID space and copy out info about the - // device into the ide_device struct + // detect disks by writing CMD_IDENTIFY to each one and checking for err. + // if device exists, ask for its ID space and copy out info about the + // device into the ide_device struct uint32_t device_count = 0; for (uint8_t channel_idx = 0; channel_idx < 2; channel_idx++) { // drive idx is like device_count but it starts at 0 per channel @@ -428,7 +428,7 @@ static void ide_initialize(uint32_t BAR0, uint32_t BAR1, uint32_t BAR2, // get size (depends on address mode): if (dev->supported_command_sets & (1 << 26)) { - // lba48 + // lba48 dev->size_in_sectors = *((uint32_t *)(id_space_buf + ATA_IDENT_MAX_LBA_EXT)); } else { @@ -463,7 +463,7 @@ enum access_mode { static uint8_t get_ata_cmd_for_access(enum lba_mode lba_mode, enum access_mode mode) { - // outline of the algorithm: + // outline of the algorithm: // If ( dma & lba48) DO_DMA_EXT; // If ( dma & lba28) DO_DMA_LBA; // If ( dma & lba28) DO_DMA_CHS; @@ -503,7 +503,7 @@ static uint8_t get_ata_cmd_for_access(enum lba_mode lba_mode, // if (lba_mode == 2 && dma == 1 && direction == 1) // cmd = ATA_CMD_WRITE_DMA_EXT; } - panic("unreachable"); + panic("unreachable"); return -1; } @@ -654,7 +654,7 @@ enum ide_error ide_device_read_sectors(ide_device_t dev_identifier, // err = ide_atapi_read(drive, lba + i, 1, es, edi + (i*2048)); //panic("atapi unimplemented- todo"); - // soft error instead of panic + // soft error instead of panic return IDE_ERROR_UNIMPLEMENTED; } diff --git a/kernel/fs/tar.c b/kernel/fs/tar.c index 4e66944..462200b 100644 --- a/kernel/fs/tar.c +++ b/kernel/fs/tar.c @@ -2,62 +2,61 @@ #include <lib.h> #include <comus/tar.h> - // the placements of these values mimics their placement in standard UStar struct tar_header { - char name[100]; // 0-99 - char mode[8]; // 100-107 - char ownerUID[8]; // 108-115 - char groupUID[8]; // 116-123 - char fileSize[12]; // 124-135 - char lastMod[12]; // 136-147 - char checksum[8]; // 148-155 - char type_flag; // 156 - char linked_name[100]; // 157-256 - char magic[6]; // 257-262 - char version[2]; // 263-264 - char username[32]; // 265-296 - char groupname[32]; // 297-328 - char majorNum[8]; // 329-336 - char minorNum[8]; // 337-344 - char prefix[155]; // 345-499 - char notUsed[12]; // 500-511 + char name[100]; // 0-99 + char mode[8]; // 100-107 + char ownerUID[8]; // 108-115 + char groupUID[8]; // 116-123 + char fileSize[12]; // 124-135 + char lastMod[12]; // 136-147 + char checksum[8]; // 148-155 + char type_flag; // 156 + char linked_name[100]; // 157-256 + char magic[6]; // 257-262 + char version[2]; // 263-264 + char username[32]; // 265-296 + char groupname[32]; // 297-328 + char majorNum[8]; // 329-336 + char minorNum[8]; // 337-344 + char prefix[155]; // 345-499 + char notUsed[12]; // 500-511 }; -#define TAR_SIZE 512 -#define TMAGIC "ustar" /* ustar and a null */ -#define TMAGLEN 6 -#define TVERSION "00" /* 00 and no null */ +#define TAR_SIZE 512 +#define TMAGIC "ustar" /* ustar and a null */ +#define TMAGLEN 6 +#define TVERSION "00" /* 00 and no null */ #define TVERSLEN 2 #define ERROR_TAR 1 #define NOERROR_TAR 0 -#define REGTYPE '0' /* regular file */ -#define DIRTYPE '5' /* directory */ - +#define REGTYPE '0' /* regular file */ +#define DIRTYPE '5' /* directory */ struct tar_file { - struct file file; - struct file_system *fs; - size_t len; - size_t offset; - size_t sect; + struct file file; + struct file_system *fs; + size_t len; + size_t offset; + size_t sect; }; /// @brief reads from the disk into tar_header /// @param disk the disk used with disk_read /// @param sect the sector to read (used for disk_read offset) /// @param hdr the tar_header to read into. read_tar_header is essentially used to output this. /// @return NOERROR_TAR or ERROR_TAR -int read_tar_header(struct disk *disk, uint32_t sect, struct tar_header *hdr) { - // makes sure it reads enough bytes. - if(disk_read(disk, sect * TAR_SIZE, TAR_SIZE, hdr) < TAR_SIZE) { - return ERROR_TAR; - } - // makes sure magic and version are correct for USTar. - if(memcmp(hdr->magic, TMAGIC, TMAGLEN) != 0 || memcmp(hdr->version, TVERSION, TVERSLEN) != 0) { - return ERROR_TAR; - } - return NOERROR_TAR; - +int read_tar_header(struct disk *disk, uint32_t sect, struct tar_header *hdr) +{ + // makes sure it reads enough bytes. + if (disk_read(disk, sect * TAR_SIZE, TAR_SIZE, hdr) < TAR_SIZE) { + return ERROR_TAR; + } + // makes sure magic and version are correct for USTar. + if (memcmp(hdr->magic, TMAGIC, TMAGLEN) != 0 || + memcmp(hdr->version, TVERSION, TVERSLEN) != 0) { + return ERROR_TAR; + } + return NOERROR_TAR; } /// @brief reads from the file, and puts it into buffer @@ -65,15 +64,17 @@ int read_tar_header(struct disk *disk, uint32_t sect, struct tar_header *hdr) { /// @param buffer the buffer that the content of the file is read into /// @param len length of the buffer, which caps what can be read if the file has more data. /// @return size of what was read. -int tar_read(struct file *f, void *buffer, size_t len) { - struct tar_file *tf = (struct tar_file*) f; - long size = MIN((tf->len - tf->offset), len); - if(tf->file.f_type != F_REG || size < 1) { - return ERROR_TAR; - } - size = disk_read(tf->fs->fs_disk, (tf->sect+1) * TAR_SIZE + tf->offset, size, buffer); - tf->offset += size; - return size; +int tar_read(struct file *f, void *buffer, size_t len) +{ + struct tar_file *tf = (struct tar_file *)f; + long size = MIN((tf->len - tf->offset), len); + if (tf->file.f_type != F_REG || size < 1) { + return ERROR_TAR; + } + size = disk_read(tf->fs->fs_disk, (tf->sect + 1) * TAR_SIZE + tf->offset, + size, buffer); + tf->offset += size; + return size; } /// @brief used to locate files /// @param fs the file system being used @@ -82,111 +83,121 @@ int tar_read(struct file *f, void *buffer, size_t len) { /// @param sect_return the sector to be outputted /// @param outHeader tar_header output for file found. /// @return NOERROR_TAR or ERROR_TAR -int find_file(struct file_system *fs, const char *filepath, size_t *sect, size_t *sect_return, struct tar_header *outHeader) { - struct tar_header hdr; - size_t curr_sect; - if(sect == NULL) { - curr_sect = 0; - } else { - curr_sect = *sect; - } - while (1 == 1) { - // if read_tar_header errors - if(read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { - return ERROR_TAR; - } - if(memcmp(hdr.name, filepath, strlen(filepath) + 1) != 0) { - // didn't find it. - curr_sect += ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1)/TAR_SIZE) + 1; - continue; - } else { - *outHeader = hdr; - *sect_return = curr_sect; - if(sect != NULL) { - sect += curr_sect; - } - return NOERROR_TAR; - } - - } - return ERROR_TAR; +int find_file(struct file_system *fs, const char *filepath, size_t *sect, + size_t *sect_return, struct tar_header *outHeader) +{ + struct tar_header hdr; + size_t curr_sect; + if (sect == NULL) { + curr_sect = 0; + } else { + curr_sect = *sect; + } + while (1 == 1) { + // if read_tar_header errors + if (read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { + return ERROR_TAR; + } + if (memcmp(hdr.name, filepath, strlen(filepath) + 1) != 0) { + // didn't find it. + curr_sect += + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1) / TAR_SIZE) + + 1; + continue; + } else { + *outHeader = hdr; + *sect_return = curr_sect; + if (sect != NULL) { + sect += curr_sect; + } + return NOERROR_TAR; + } + } + return ERROR_TAR; } // similar to find_file, but with a partition -int find_file_redux(struct file_system *fs, const char *filepath, size_t *sect, size_t *sect_return, struct tar_header *outHeader) { - struct tar_header hdr; - size_t curr_sect; - if(sect == NULL) { - curr_sect = 0; - } else { - curr_sect = *sect; - } - while (1 == 1) { - if(read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { - return ERROR_TAR; - } - if(memcmp(hdr.name, filepath, MIN(strlen(filepath), strlen(hdr.name))) != 0) { - // didn't find it. - - curr_sect += ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1)/TAR_SIZE) + 1; - continue; - } else { - *outHeader = hdr; - *sect_return = curr_sect; - if(sect != NULL) { - sect += curr_sect + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1)/TAR_SIZE) + 1; - } - return NOERROR_TAR; - - } - - } - return ERROR_TAR; // it should never actually reach here. +int find_file_redux(struct file_system *fs, const char *filepath, size_t *sect, + size_t *sect_return, struct tar_header *outHeader) +{ + struct tar_header hdr; + size_t curr_sect; + if (sect == NULL) { + curr_sect = 0; + } else { + curr_sect = *sect; + } + while (1 == 1) { + if (read_tar_header(fs->fs_disk, curr_sect, &hdr) != 0) { + return ERROR_TAR; + } + if (memcmp(hdr.name, filepath, + MIN(strlen(filepath), strlen(hdr.name))) != 0) { + // didn't find it. + curr_sect += + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1) / TAR_SIZE) + + 1; + continue; + } else { + *outHeader = hdr; + *sect_return = curr_sect; + if (sect != NULL) { + sect += curr_sect + + ((strtoull(hdr.fileSize, NULL, 8) + TAR_SIZE - 1) / + TAR_SIZE) + + 1; + } + return NOERROR_TAR; + } + } + return ERROR_TAR; // it should never actually reach here. } /// @brief closes the file /// @param f the file to close, and free memory from. -void tar_close(struct file *f) { - kfree(f); +void tar_close(struct file *f) +{ + kfree(f); } -/// @brief +/// @brief /// @param f the file to perform seek /// @param offsetAdd what to add/adjust to the offset /// @param theSeek what kind of seek we are doing /// @return the new offset, or -1 on error (we can't use 1 since that is a possible offset change). -int tar_seek(struct file *f, long int offsetAdd, int theSeek) { - struct tar_file *tf = (struct tar_file*) f; - if(theSeek == SEEK_SET) { - tf->offset = offsetAdd; - return tf->offset; - } else if(theSeek == SEEK_CUR) { - tf->offset = tf->offset + offsetAdd; - return tf->offset; - } else if(theSeek ==SEEK_END) { - tf->offset = tf->len + offsetAdd; - return tf->offset; - } else { - return -1; // if seek has a bad value for some reason. - } - +int tar_seek(struct file *f, long int offsetAdd, int theSeek) +{ + struct tar_file *tf = (struct tar_file *)f; + if (theSeek == SEEK_SET) { + tf->offset = offsetAdd; + return tf->offset; + } else if (theSeek == SEEK_CUR) { + tf->offset = tf->offset + offsetAdd; + return tf->offset; + } else if (theSeek == SEEK_END) { + tf->offset = tf->len + offsetAdd; + return tf->offset; + } else { + return -1; // if seek has a bad value for some reason. + } } -/// @brief +/// @brief /// @param f the file to write to (in theory) /// @param buffer the buffer to write from (in theory) /// @param len the length of the buffer to be written into (in theory) /// @return ERROR_TAR or NOERROR_TAR (in this case always ERROR_TAR). -int tar_write(struct file *f, const void *buffer, size_t len) { - // tar doesn't do write lol. This is just here so there is something to send to write - (void)f; - (void)buffer; - (void)len; - return ERROR_TAR; +int tar_write(struct file *f, const void *buffer, size_t len) +{ + // tar doesn't do write lol. This is just here so there is something to send to write + (void)f; + (void)buffer; + (void)len; + return ERROR_TAR; } /// @brief gets the directory entry for the given file -/// @param f the file +/// @param f the file /// @param ent the directory entry is put into here /// @param entry where idx needs to reach /// @return NOERROR_TAR or ERROR_TAR @@ -205,8 +216,8 @@ int tar_ents(struct file *f, struct dirent *ent, size_t entry) return ERROR_TAR; if (read_tar_header(tf->fs->fs_disk, sect, &dir)) { - return ERROR_TAR; - } + return ERROR_TAR; + } while (1) { if (find_file_redux(tf->fs, dir.name, §_off, §, &hdr)) @@ -232,29 +243,31 @@ int tar_ents(struct file *f, struct dirent *ent, size_t entry) /// @param flags in this case, just used to check whether the file is set to read only, to make sure it is correct /// @param out the file, ready to be acted upon, with the other functions loaded onto it. /// @return NOERROR_TAR or ERROR_TAR -int tar_open(struct file_system *fs, const char *fullpath, int flags, struct file **out) { - struct tar_header hdr; - struct tar_file *newFile; - size_t sect_result; - find_file(fs, fullpath, NULL, §_result, &hdr); - if(flags != O_RDONLY) { - return ERROR_TAR; - } - newFile = kalloc(sizeof(struct tar_file)); +int tar_open(struct file_system *fs, const char *fullpath, int flags, + struct file **out) +{ + struct tar_header hdr; + struct tar_file *newFile; + size_t sect_result; + find_file(fs, fullpath, NULL, §_result, &hdr); + if (flags != O_RDONLY) { + return ERROR_TAR; + } + newFile = kalloc(sizeof(struct tar_file)); - newFile->file.f_type = F_REG; - newFile->fs = fs; - newFile->file.read = tar_read; - newFile->file.close = tar_close; - newFile->file.write = tar_write; // doesn't actually work; - newFile->file.ents = tar_ents; - newFile->file.seek = tar_seek; - newFile->offset = 0; - newFile->len = strtoull(hdr.fileSize, NULL, 8); - newFile->sect = sect_result; + newFile->file.f_type = F_REG; + newFile->fs = fs; + newFile->file.read = tar_read; + newFile->file.close = tar_close; + newFile->file.write = tar_write; // doesn't actually work; + newFile->file.ents = tar_ents; + newFile->file.seek = tar_seek; + newFile->offset = 0; + newFile->len = strtoull(hdr.fileSize, NULL, 8); + newFile->sect = sect_result; - *out = (struct file *)newFile; - return NOERROR_TAR; + *out = (struct file *)newFile; + return NOERROR_TAR; } /// @brief gets the stats for the file found at fullpath, putting them in out @@ -262,34 +275,36 @@ int tar_open(struct file_system *fs, const char *fullpath, int flags, struct fil /// @param fullpath the full filepath of the file /// @param out the stats for the file found /// @return NOERROR_TAR OR ERROR_TAR -int tar_stat(struct file_system *fs, const char *fullpath, struct stat *out) { - struct tar_header hdr; - size_t sect_result; - find_file(fs, fullpath, NULL, §_result, &hdr); - out->s_length = strtoull(hdr.fileSize, NULL, 8); - if(hdr.type_flag == REGTYPE) { - out->s_type = F_REG; - } else if(hdr.type_flag == DIRTYPE) { - out->s_type = F_DIR; - } else { - // wth - return ERROR_TAR; - } - return NOERROR_TAR; +int tar_stat(struct file_system *fs, const char *fullpath, struct stat *out) +{ + struct tar_header hdr; + size_t sect_result; + find_file(fs, fullpath, NULL, §_result, &hdr); + out->s_length = strtoull(hdr.fileSize, NULL, 8); + if (hdr.type_flag == REGTYPE) { + out->s_type = F_REG; + } else if (hdr.type_flag == DIRTYPE) { + out->s_type = F_DIR; + } else { + // wth + return ERROR_TAR; + } + return NOERROR_TAR; } /// @brief use tar for the filesystem. /// @param fs the file system being used, and loading tar into it. /// @return NOERROR_TAR or ERROR_TAR -int tar_mount(struct file_system *fs) { - struct tar_header hdr; - // reads into hdr - if(read_tar_header(fs->fs_disk, 0, &hdr) == 0) { - fs->fs_name = "tar"; - fs->open = tar_open; - fs->stat = tar_stat; - fs->fs_present = true; - return NOERROR_TAR; - } - return ERROR_TAR; +int tar_mount(struct file_system *fs) +{ + struct tar_header hdr; + // reads into hdr + if (read_tar_header(fs->fs_disk, 0, &hdr) == 0) { + fs->fs_name = "tar"; + fs->open = tar_open; + fs->stat = tar_stat; + fs->fs_present = true; + return NOERROR_TAR; + } + return ERROR_TAR; }
\ No newline at end of file diff --git a/kernel/include/comus/procs.h b/kernel/include/comus/procs.h index ee723aa..0490c17 100644 --- a/kernel/include/comus/procs.h +++ b/kernel/include/comus/procs.h @@ -76,10 +76,10 @@ struct pcb { uint64_t wakeup; uint8_t exit_status; - // pipe to check for shared memory - void* shared_mem; - size_t shared_mem_pages; - pid_t shared_mem_source; + // pipe to check for shared memory + void *shared_mem; + size_t shared_mem_pages; + pid_t shared_mem_source; }; /// ordering of pcb queues diff --git a/user/forkman.c b/user/forkman.c index 538992b..2e0e0af 100644 --- a/user/forkman.c +++ b/user/forkman.c @@ -260,7 +260,7 @@ static int client_entry(sharedmem *shared) for (size_t i = 0; i < shared->player_vel.x; ++i) { size_t x = shared->player_pos.x + 1; size_t y = shared->player_pos.y + 1; - // boundscheck to consider outside tiles to be solid + // boundscheck to consider outside tiles to be solid if (is_inbounds(x, y) && tile_at(shared, x, y)->type != TILE_AIR) { break; } |