mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 18:58:40 +00:00
fix fat32 volume labels
This commit is contained in:
parent
0655dd8bae
commit
09a84a6af2
2 changed files with 41 additions and 3 deletions
|
|
@ -42,6 +42,32 @@ static int dm_strlen(const char *s) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dm_copy_fat_label(char *dst, const uint8_t *src) {
|
||||||
|
int end = 11;
|
||||||
|
while (end > 0 && src[end - 1] == ' ') end--;
|
||||||
|
for (int i = 0; i < end && i < 31; i++) dst[i] = (char)src[i];
|
||||||
|
dst[end < 31 ? end : 31] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void disk_load_fat32_label(Disk *disk) {
|
||||||
|
uint8_t *buffer;
|
||||||
|
FAT32_BootSector *bpb;
|
||||||
|
char label[32];
|
||||||
|
|
||||||
|
if (!disk || !disk->read_sector) return;
|
||||||
|
|
||||||
|
buffer = (uint8_t*)kmalloc(512);
|
||||||
|
if (!buffer) return;
|
||||||
|
|
||||||
|
if (disk->read_sector(disk, 0, buffer) == 0 && buffer[510] == 0x55 && buffer[511] == 0xAA) {
|
||||||
|
bpb = (FAT32_BootSector*)buffer;
|
||||||
|
dm_copy_fat_label(label, bpb->volume_label);
|
||||||
|
if (label[0]) dm_strcpy(disk->label, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
kfree(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
// === ATA Definitions (Legacy IDE PIO — kept as fallback) ===
|
// === ATA Definitions (Legacy IDE PIO — kept as fallback) ===
|
||||||
|
|
||||||
#define ATA_PRIMARY_IO 0x1F0
|
#define ATA_PRIMARY_IO 0x1F0
|
||||||
|
|
@ -387,6 +413,8 @@ void disk_register_partition(Disk *parent, uint32_t lba_offset, uint32_t sector_
|
||||||
part->is_partition = true;
|
part->is_partition = true;
|
||||||
part->registered = true;
|
part->registered = true;
|
||||||
|
|
||||||
|
if (is_fat32) disk_load_fat32_label(part);
|
||||||
|
|
||||||
disks[disk_count++] = part;
|
disks[disk_count++] = part;
|
||||||
|
|
||||||
serial_write("[DISK] Registered /dev/");
|
serial_write("[DISK] Registered /dev/");
|
||||||
|
|
@ -567,6 +595,7 @@ static void parse_mbr_partitions(Disk *disk) {
|
||||||
serial_write("\n");
|
serial_write("\n");
|
||||||
disk->is_fat32 = true;
|
disk->is_fat32 = true;
|
||||||
disk->partition_lba_offset = 0;
|
disk->partition_lba_offset = 0;
|
||||||
|
disk_load_fat32_label(disk);
|
||||||
} else if (part_count == 0) {
|
} else if (part_count == 0) {
|
||||||
serial_write("[DISK] No MBR partitions found on /dev/");
|
serial_write("[DISK] No MBR partitions found on /dev/");
|
||||||
serial_write(disk->devname);
|
serial_write(disk->devname);
|
||||||
|
|
@ -1040,4 +1069,4 @@ int disk_rescan(Disk *disk) {
|
||||||
|
|
||||||
parse_mbr_partitions(disk);
|
parse_mbr_partitions(disk);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,13 @@ static void mf_strncpy(char *dst, const char *src, int n) {
|
||||||
while (i < n) { dst[i++] = ' '; } /* FAT labels are space-padded */
|
while (i < n) { dst[i++] = ' '; } /* FAT labels are space-padded */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mf_set_disk_label(Disk *disk, const char *label) {
|
||||||
|
int end = 11;
|
||||||
|
while (end > 0 && label[end - 1] == ' ') end--;
|
||||||
|
for (int i = 0; i < end && i < 31; i++) disk->label[i] = label[i];
|
||||||
|
disk->label[end < 31 ? end : 31] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// On-disk BPB structures
|
// On-disk BPB structures
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) {
|
typedef struct __attribute__((packed)) {
|
||||||
|
|
@ -269,13 +276,15 @@ int mkfs_fat32_format(Disk *disk, uint32_t sector_count, const char *label) {
|
||||||
|
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
|
|
||||||
|
disk->is_fat32 = true;
|
||||||
|
mf_set_disk_label(disk, upper_label);
|
||||||
|
|
||||||
serial_write("[MKFS] FAT32 formatted: ");
|
serial_write("[MKFS] FAT32 formatted: ");
|
||||||
serial_write(disk->devname);
|
serial_write(disk->devname);
|
||||||
serial_write(" label=");
|
serial_write(" label=");
|
||||||
char lb[12];
|
char lb[12];
|
||||||
mf_memcpy(lb, vol_label, 11);
|
mf_memcpy(lb, upper_label, 11);
|
||||||
lb[11] = 0;
|
lb[11] = 0;
|
||||||
for (int i = 0; i < 11; i++) lb[i] = (lb[i] >= 'a' && lb[i] <= 'z') ? lb[i] - 32 : lb[i];
|
|
||||||
for (int i = 10; i >= 0 && lb[i] == ' '; i--) lb[i] = 0;
|
for (int i = 10; i >= 0 && lb[i] == ' '; i--) lb[i] = 0;
|
||||||
serial_write(lb);
|
serial_write(lb);
|
||||||
serial_write(" spc=");
|
serial_write(" spc=");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue