Skip to content

Commit a1506df

Browse files
committed
implement real diskinfo functionality
1 parent 408406c commit a1506df

1 file changed

Lines changed: 14 additions & 27 deletions

File tree

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
#include "shared-bindings/hashlib/__init__.h"
5151
#include "shared-bindings/hashlib/Hash.h"
52+
#include "lib/oofatfs/diskio.h"
5253

5354
#if CIRCUITPY_MDNS
5455
#include "shared-bindings/mdns/RemoteService.h"
@@ -834,35 +835,21 @@ static void _reply_with_diskinfo_json(socketpool_socket_obj_t *socket, _request
834835
_send_str(socket, "\r\n");
835836
mp_print_t _socket_print = {socket, _print_chunk};
836837

837-
const char *hostname = "";
838-
#if CIRCUITPY_MDNS
839-
if (!common_hal_mdns_server_deinited(&mdns)) {
840-
hostname = common_hal_mdns_server_get_hostname(&mdns);
838+
DWORD free_clusters;
839+
FATFS *fs = filesystem_circuitpy();
840+
FRESULT blk_result = f_getfree(fs, &free_clusters);
841+
uint16_t block_size;
842+
if (blk_result == FR_OK) {
843+
disk_ioctl(fs, GET_SECTOR_SIZE, &block_size);
841844
}
842-
#endif
843-
_update_encoded_ip();
844-
// Note: this leverages the fact that C concats consecutive string literals together.
845+
846+
uint16_t total_size = fs->n_fatent - 2;
847+
845848
mp_printf(&_socket_print,
846-
"{\"web_api_version\": 1, "
847-
"\"version\": \"" MICROPY_GIT_TAG "\", "
848-
"\"build_date\": \"" MICROPY_BUILD_DATE "\", "
849-
"\"board_name\": \"" MICROPY_HW_BOARD_NAME "\", "
850-
"\"mcu_name\": \"" MICROPY_HW_MCU_NAME "\", "
851-
"\"board_id\": \"" CIRCUITPY_BOARD_ID "\", "
852-
"\"creator_id\": %u, "
853-
"\"creation_id\": %u, "
854-
"\"hostname\": \"%s\", "
855-
"\"port\": %d, ", CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded);
856-
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
857-
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
858-
common_hal_mcu_processor_get_uid(raw_id);
859-
mp_printf(&_socket_print, "\"UID\": \"");
860-
for (uint8_t i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
861-
mp_printf(&_socket_print, "%02X", raw_id[i]);
862-
}
863-
mp_printf(&_socket_print, "\", ");
864-
#endif
865-
mp_printf(&_socket_print, "\"ip\": \"%s\"}", _our_ip_encoded);
849+
"{\"free\": %d, "
850+
"\"block_size\": %d, "
851+
"\"total\": %d}", free_clusters * block_size, block_size, total_size * block_size);
852+
866853
// Empty chunk signals the end of the response.
867854
_send_chunk(socket, "");
868855
}

0 commit comments

Comments
 (0)