slab: replace struct slab with slab_t

This type should never be modified by the user, and only passed into the
functions in slab.c. Using a typedef to notifies the user semantically
of this fact
This commit is contained in:
Michael Shaw 2023-05-19 16:49:34 -04:00
commit 29a0435cf6
13 changed files with 196 additions and 46 deletions

View file

@ -5,4 +5,75 @@
#include <kernel/common.h>
#include <kernel/block.h>
#define FAT32_SIGNATURE 0x29ull
struct fat32_bpb {
uint8_t jmp[3];
uint64_t oem_id;
uint16_t bytes_per_sector;
uint8_t sectors_per_cluster;
uint16_t reserved_sectors;
uint8_t fat_count;
uint16_t root_entries;
uint16_t total_sectors;
uint8_t media_type;
uint16_t fat_sectors;
uint16_t sectors_per_track;
uint16_t heads;
uint32_t hidden_sectors;
uint32_t total_sectors_large;
/* FAT32 */
uint32_t fat_sectors_large;
uint16_t flags;
uint16_t version;
uint32_t root_cluster;
uint16_t fsinfo_sector;
uint16_t backup_sector;
uint8_t reserved[12];
uint8_t drive_number;
uint8_t reserved2;
uint8_t signature;
uint32_t volume_id;
uint8_t volume_label[11];
uint8_t system_id[8];
uint8_t boot_code[420];
uint16_t boot_signature;
} PACKED;
struct fat32_fsinfo {
uint32_t signature1;
uint8_t reserved1[480];
uint32_t signature2;
uint32_t free_cluster_count;
uint32_t next_free_cluster;
uint8_t reserved2[12];
uint32_t signature3;
} PACKED;
struct fat32_dirent {
uint8_t name[8];
uint8_t ext[3];
uint8_t attr;
uint8_t reserved;
uint8_t ctime_ms;
uint16_t ctime_time;
uint16_t ctime_date;
uint16_t atime_date;
uint16_t cluster_high;
uint16_t mtime_time;
uint16_t mtime_date;
uint16_t cluster_low;
uint32_t size;
} PACKED;
struct fat32_fs {
struct block_device *dev;
struct block_part *part;
struct fat32_bpb bpb;
struct fat32_fsinfo fsinfo;
struct fat32_dirent root;
};
#endif /* _FAT32_H_ */

View file

@ -12,6 +12,13 @@ struct block_device_ops {
int (*write)(struct block_device *bdev, void *buf, size_t offset, size_t size);
};
struct block_part {
char *name;
struct block_device *bdev;
size_t lba_start;
size_t num_blocks;
};
struct block_device {
char *name;
struct block_device_ops ops;
@ -21,14 +28,15 @@ struct block_device {
size_t block_count;
size_t block_size;
struct gpt_header *gpt_header;
struct gpt_entry *gpt_entries;
size_t gpt_entries_count;
struct block_part *partitions;
size_t partition_count;
};
struct block_device *block_register(char *name, struct block_device_ops *ops, void *data, size_t block_count, size_t block_size);
int block_read(struct block_device *bdev, void *buf, size_t offset, size_t size);
int block_readp(struct block_part *part, void *buf, size_t offset, size_t size);
int block_write(struct block_device *bdev, void *buf, size_t offset, size_t size);
int block_writep(struct block_part *part, void *buf, size_t offset, size_t size);
extern struct block_device *block_devices[];
extern size_t block_devices_count;

View file

@ -38,12 +38,12 @@ struct gpt_header {
/* GPT LBA 2 */
struct gpt_entry {
uint8_t guid[16];
uint8_t guid_parent[16];
uint64_t type_guid[2];
uint64_t unique_guid[2];
uint64_t lba_first;
uint64_t lba_last;
uint8_t attr[8];
char name[72];
uint64_t flags;
uint8_t name[72];
} PACKED;
void block_gpt_init(struct block_device *dev);

View file

@ -11,7 +11,7 @@
#define ALLOC_KERN 0x01
#define ALLOC_DMA 0x02
struct slab {
typedef struct _slab {
size_t size; /* size of each object */
size_t tsize; /* total size of this slab */
size_t num; /* number of objects in this slab */
@ -19,20 +19,20 @@ struct slab {
uint64_t flags;
size_t align;
uintptr_t *nextfree;
struct slab *next;
struct slab *prev;
};
struct _slab *next;
struct _slab *prev;
} slab_t;
struct kmap_entry {
uintptr_t *ptr;
size_t size;
struct slab *slab;
slab_t *slab;
struct kmap_entry *next;
};
struct slab *slab_create(size_t size, size_t cache_size, uint64_t flags);
void *slab_alloc(struct slab *slab);
void slab_free(struct slab *slab, void *ptr);
slab_t *slab_create(size_t size, size_t cache_size, uint64_t flags);
void *slab_alloc(slab_t *slab);
void slab_free(slab_t *slab, void *ptr);
void kmalloc_init();
void *kmalloc(size_t size, uint64_t flags);