From cab65acc464ca5876bd3682587ee2670268b13d2 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 21 Nov 2022 11:52:51 +0700 Subject: [PATCH] add pwd --- examples/host/msc_file_explorer/src/main.c | 8 ++-- examples/host/msc_file_explorer/src/msc_app.c | 43 +++++++++++++++++-- lib/fatfs/source/ffconf.h | 2 +- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/examples/host/msc_file_explorer/src/main.c b/examples/host/msc_file_explorer/src/main.c index f46e5092..652986b7 100644 --- a/examples/host/msc_file_explorer/src/main.c +++ b/examples/host/msc_file_explorer/src/main.c @@ -43,7 +43,7 @@ int main(void) { board_init(); - printf("TinyUSB Host MSC Explorer Example\r\n"); + printf("TinyUSB Host MassStorage Explorer Example\r\n"); // init host stack on configured roothub port tuh_init(BOARD_TUH_RHPORT); @@ -67,14 +67,12 @@ int main(void) void tuh_mount_cb(uint8_t dev_addr) { - // application set-up - printf("A device with address %d is mounted\r\n", dev_addr); + (void) dev_addr; } void tuh_umount_cb(uint8_t dev_addr) { - // application tear-down - printf("A device with address %d is unmounted \r\n", dev_addr); + (void) dev_addr; } diff --git a/examples/host/msc_file_explorer/src/msc_app.c b/examples/host/msc_file_explorer/src/msc_app.c index 4500aedd..6e5cb672 100644 --- a/examples/host/msc_file_explorer/src/msc_app.c +++ b/examples/host/msc_file_explorer/src/msc_app.c @@ -108,7 +108,7 @@ bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun); printf("Disk Size: %lu MB\r\n", block_count / ((1024*1024)/block_size)); - printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size); + // printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size); // For simplicity: we only mount 1 LUN per device uint8_t const drive_num = dev_addr-1; @@ -120,8 +120,15 @@ bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const puts("mount failed"); } - f_chdrive(drive_path); // change to newly mounted drive - f_chdir("/"); // root as current dir + // change to newly mounted drive + f_chdir(drive_path); + + // print the drive label +// char label[34]; +// if ( FR_OK == f_getlabel(drive_path, label, NULL) ) +// { +// puts(label); +// } return true; } @@ -137,7 +144,6 @@ void tuh_msc_mount_cb(uint8_t dev_addr) void tuh_msc_umount_cb(uint8_t dev_addr) { - (void) dev_addr; printf("A MassStorage device is unmounted\r\n"); uint8_t const drive_num = dev_addr-1; @@ -273,6 +279,7 @@ void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context); void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context); void cli_cmd_cp(EmbeddedCli *cli, char *args, void *context); void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context); +void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context); void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context); void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context); void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context); @@ -338,6 +345,14 @@ bool cli_init(void) cli_cmd_ls }); + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "pwd", + "Usage: pwd\r\n\tPrint the name of the current working directory.", + true, + NULL, + cli_cmd_pwd + }); + embeddedCliAddBinding(_cli, (CliCommandBinding) { "mkdir", "Usage: mkdir DIR...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..", @@ -531,6 +546,26 @@ void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context) f_closedir(&dir); } +void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + uint16_t argc = embeddedCliGetTokenCount(args); + + if (argc != 0) + { + printf("invalid arguments\r\n"); + return; + } + + char path[256]; + if (FR_OK != f_getcwd(path, sizeof(path))) + { + printf("cannot get current working directory\r\n"); + } + + puts(path); +} + void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context) { (void) cli; (void) context; diff --git a/lib/fatfs/source/ffconf.h b/lib/fatfs/source/ffconf.h index 9298ef89..96ff7715 100644 --- a/lib/fatfs/source/ffconf.h +++ b/lib/fatfs/source/ffconf.h @@ -153,7 +153,7 @@ / on character encoding. When LFN is not enabled, these options have no effect. */ -#define FF_FS_RPATH 1 +#define FF_FS_RPATH 2 /* This option configures support for relative path. / / 0: Disable relative path and remove related functions.