48 lines
1.6 KiB
C
48 lines
1.6 KiB
C
/* Calcite, src/kernel/drives.c
|
|
* Copyright 2025 Benji Dial
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "utility.h"
|
|
#include "drives.h"
|
|
#include "heap.h"
|
|
|
|
struct drive_info *drive_list;
|
|
int drive_list_buffer_length = 0;
|
|
int drive_list_count = 0;
|
|
|
|
#define DRIVE_LIST_INITIAL_LENGTH 16
|
|
|
|
struct drive_info *add_drive() {
|
|
|
|
if (drive_list_buffer_length == 0) {
|
|
drive_list = heap_alloc(DRIVE_LIST_INITIAL_LENGTH * sizeof(struct drive_info));
|
|
drive_list_buffer_length = DRIVE_LIST_INITIAL_LENGTH;
|
|
}
|
|
|
|
else if (drive_list_count == drive_list_buffer_length) {
|
|
struct drive_info *new_drive_list =
|
|
heap_alloc(2 * drive_list_buffer_length * sizeof(struct drive_info));
|
|
memcpy(new_drive_list, drive_list, drive_list_count * sizeof(struct drive_info));
|
|
heap_dealloc(drive_list, drive_list_count * sizeof(struct drive_info));
|
|
drive_list = new_drive_list;
|
|
drive_list_buffer_length *= 2;
|
|
}
|
|
|
|
struct drive_info *to_return = &drive_list[drive_list_count];
|
|
++drive_list_count;
|
|
return to_return;
|
|
|
|
}
|