TYPE command, fsys issues

Added TYPE command and fixed some fsys issues.
This commit is contained in:
Peter Weingartner 2021-09-24 12:05:45 -04:00
parent 1a3e3d79f5
commit 07a2a26a6b
8 changed files with 5565 additions and 5528 deletions

View file

@ -50,6 +50,7 @@ const t_cli_command g_cli_commands[] = {
{ "DIR", "DIR <path> -- print directory listing", cmd_dir },
{ "MBR", "MBR @S: | @F: | @H: -- fetch and display the MBR of the drive", cmd_dump_mbr},
{ "HELP", "HELP -- print this helpful message", cmd_help },
{ "TYPE", "TYPE <path> -- print the contents of a text file", cmd_type },
{ "?", "? -- print this helpful message", cmd_help },
{ 0, 0 }
};

View file

@ -3,8 +3,10 @@
#include "syscalls.h"
#include "log.h"
#include "simpleio.h"
#include "cli/dos_cmds.h"
#include "dev/block.h"
#include "dev/fsys.h"
#include "fatfs/ff.h"
void test_get_mbr(short screen, short device) {
@ -64,56 +66,59 @@ short cmd_dump_mbr(short screen, char * drive) {
return 0;
}
DIR my_dir;
FILINFO my_file;
FATFS my_fs;
short dos_cmd_dir(short screen, char * path) {
FRESULT fres;
char line[255];
t_file_info my_file;
print(screen, "Attempting to read directory for [");
print(screen, path);
print(screen, "]\n");
fres = f_mount(&my_fs, path, 0);
if (fres == FR_OK) {
fres = f_opendir(&my_dir, "/");
if (fres == FR_OK) {
do {
fres = f_readdir(&my_dir, &my_file);
if ((fres == FR_OK) && (my_file.fname[0] != 0)) {
if ((my_file.fattrib & AM_HID) == 0) {
sys_chan_write(screen, my_file.fname, strlen(my_file.fname));
if (my_file.fattrib & AM_DIR) {
sys_chan_write_b(screen, '/');
}
sys_chan_write(screen, "\n", 1);
log3(LOG_INFO, "Attempting to read directory for [", path, "]\n");
short dir = fsys_opendir(path);
if (dir >= 0) {
while (1) {
short result = fsys_readdir(dir, &my_file);
if ((result == 0) && (my_file.name[0] != 0)) {
if ((my_file.attributes & AM_HID) == 0) {
print(screen, my_file.name);
if (my_file.attributes & AM_DIR) {
print(screen, "/");
}
} else {
break;
print(screen, "\n");
}
} while(1);
f_closedir(&my_dir);
} else {
char * err = "Could not open directory: ";
sys_chan_write(screen, err, strlen(err));
//print_hex_16(screen, fres);
sys_chan_write_b(screen, '\n');
} else {
break;
}
}
f_mount(0, "", 0);
fsys_closedir(dir);
} else {
char * err = "Could not mount drive: ";
//sys_chan_write(screen, err, strlen(err));
print_hex_16(screen, fres);
log_num(LOG_ERROR, "Could not open directory: ", dir);
return dir;
}
return 0;
}
short cmd_type(short screen, char * path) {
unsigned char buffer[128];
log3(LOG_INFO, "Attempting to type [", path, "]");
short fd = fsys_open(path, FA_READ);
if (fd >= 0) {
log(LOG_INFO, "File open");
while (1) {
short n = chan_read(fd, buffer, 128);
log_num(LOG_INFO, "chan_read: " n);
if (n > 0) {
chan_write(screen, buffer, n);
} else {
break;
}
}
} else {
log_num(LOG_ERROR, "Could not open file for reading: ", fd);
return fd;
}
}
/*
* List the directory at the given path
*/

View file

@ -18,4 +18,6 @@ extern short cmd_dump_mbr(char * drive);
*/
extern short cmd_dir(char * path);
extern short cmd_type(short screen, char * path);
#endif

View file

@ -179,10 +179,14 @@ short chan_read(short channel, uint8_t * buffer, short size) {
p_dev_chan cdev;
short res;
log(LOG_TRACE, "chan_read");
res = chan_get_records(channel, &chan, &cdev);
if (res == 0) {
log2(LOG_DEBUG, "chan_read: ", cdev->name);
return cdev->read(chan, buffer, size);
} else {
log_num(LOG_DEBUG, "Couldn't get channel: ", res);
return res;
}
}

View file

@ -83,8 +83,8 @@ short fsys_open(const char * path, short mode) {
chan->dev = CDEV_FILE;
FRESULT result = f_open(&g_file[fd], path, mode);
if (result == 0) {
chan->data[0] = fd * 0xff; /* file handle in the channel data block */
return fd;
chan->data[0] = fd & 0xff; /* file handle in the channel data block */
return chan->number;
} else {
/* There was an error... deallocate the channel and file descriptor */
g_fil_state[fd] = 0;
@ -111,16 +111,15 @@ short fsys_open(const char * path, short mode) {
short fsys_close(short c) {
p_channel chan = 0;
short fd = 0;
FRESULT result;
chan = chan_get_record(c); /* Get the channel record */
fd = chan->data[0]; /* Get the file descriptor number */
result = f_close(&g_file[fd]); /* Close the file in FATFS */
f_close(&g_file[fd]); /* Close the file in FATFS */
chan_free(chan); /* Return the channel to the pool */
g_fil_state[fd] = 0; /* Return the file descriptor to the pool. */
return fatfs_to_foenix(result);
return 0;
}
/**
@ -349,6 +348,8 @@ short fchan_read(t_channel * chan, unsigned char * buffer, short size) {
FRESULT result;
int total_read;
log(LOG_TRACE, "fchan_read");
file = fchan_to_file(chan);
if (file) {
result = f_read(file, buffer, size, &total_read);

View file

@ -99,6 +99,8 @@ void initialize() {
text_init(); // Initialize the text channels
DEBUG("Foenix/MCP starting up...");
log_setlevel(LOG_ERROR);
/* Initialize the interrupt system */
int_init();

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff