📄 filesystemmain.c
字号:
// Improve the following processing so that MS-DOS may conform
fw = fatFopen((char *)arg[2], "wb");
if (fw == 0) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[2]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
do {
size = fatFread(buf, 1, BUF_COUNT * BUF_SIZE, fr);
fatFwrite(buf, 1, size, fw);
} while (fatFeof(fr) == 0);
fatFclose(fw);
}
fatFclose(fr);
}
// Make directory
} else if (strcmp((char *)arg[0], "md") == 0) {
if (fatMkdir((char *)arg[1]) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot make \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
// Delete directory
} else if (strcmp((char *)arg[0], "rd") == 0) {
if (fatRmdir((char *)arg[1], (unsigned long)NULL) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot delete \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
// Movement in current directory
} else if (strcmp((char *)arg[0], "cd") == 0) {
if (arg[1][0] == 0x00) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "%c:%s\n\r", fat_bCurDrv + 'C', fat_bCurDir);
FlowStrPrint(bmsgstr, FLOW_LV);
} else if (isalpha(arg[1][0]) && (arg[1][1] == ':') && (arg[1][2] == 0x00)) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "%c:\\\n\r", toupper(arg[1][0]));
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
if (fatChdir((char *)arg[1]) != 0) {
if ((fat_stFatErr.bErrCode == FAT_PATH_NOTFOUND) || (fat_stFatErr.bErrCode == FAT_INVALID_DRIVE)) {
;
} else {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot change current directory.\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
}
}
}
//
//(10)Rename
//According to specification of API command, if the first argument(source side) is specified as absolute path,
//the second argument(target side) shoule also be specified as absolute path
//Operation can be done even not doing as that for MS-DOS
//Improve the following processing so that MS-DOS may conform
//This API command is call "ren" by the DOS command, not "move".
//When the syntax of "move" is specified, it is judged as "Syntax error"
} else if (strcmp((char *)arg[0], "ren") == 0) {
if (fatRename((char *)arg[1], (char *)arg[2]) != TEST_SUCCESS) {
if (fat_stFatErr.bErrCode == FAT_INVALID_PARAMETER) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: syntax command.\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot rename \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
}
// (11)Get file attribute
} else if (strcmp((char *)arg[0], "getat") == 0) {
if (fatDosGetFileAttr((char *)arg[1], &iattr) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot get file attribute \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "<%s> 0x%X \n", arg[1], iattr);
FlowStrPrint(bmsgstr, FLOW_LV);
}
// (12)Set file attribute
} else if (strcmp((char *)arg[0], "setat") == 0) {
iattr = strtoul((char *)arg[2], NULL, 16);
if (fatDosSetFileAttr((char *)arg[1], iattr) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot set file attribute \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
// (13)Get serial number and volume label
} else if (strcmp((char *)arg[0], "getvol") == 0) {
ulSerNum = 0x00;
memset(bVolume, 0x00, FAT_FILE_LEN + 1);
if (fatGetVolume((char *)arg[1], &ulSerNum, bVolume) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot get Volume Label and Serial Number \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "<%s> Serial Number: %08X\n\r", arg[1], ulSerNum);
FlowStrPrint(bmsgstr, FLOW_LV);
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "<%s> Volume Label: %s\n\r", arg[1], bVolume);
FlowStrPrint(bmsgstr, FLOW_LV);
}
// (14)Set serial number and volume label
} else if (strcmp((char *)arg[0], "setvol") == 0) {
ulSerNum = strtoul((char *)arg[2], NULL, 16);
if (arg[3][0] != 0x00) {
if (fatSetVolume((char *)arg[1], ulSerNum, arg[3]) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot set Volume Label and Serial Number \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
} else {
if (fatSetVolume((char *)arg[1], ulSerNum, (unsigned char)NULL) != TEST_SUCCESS) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot set Volume Label and Serial Number \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
}
// (15)Get empty capacity of disk
// The execution of this API function will take some time for first execution, when the object device is HDD. Pay attention please.
} else if (strcmp((char *)arg[0], "disk") == 0) {
memset(&st_disk, 0x00, sizeof(st_disk));
if (fatDosGetDiskFree((char *)arg[1], &st_disk) != TEST_SUCCESS){
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot get Drive Information \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
Total_byte = st_disk.total_clusters * st_disk.sectors_per_cluster;
Total_byte *= st_disk.bytes_per_sector;
Avalable_byte = st_disk.avail_clusters * st_disk.sectors_per_cluster;
Avalable_byte *= st_disk.bytes_per_sector;
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Total disk size : %32.0lf\n\r", Total_byte);
FlowStrPrint(bmsgstr, FLOW_LV);
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Avalable byte : %32.0lf\n\r", Avalable_byte);
FlowStrPrint(bmsgstr, FLOW_LV);
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Total cluster : %32ld\n\r", st_disk.total_clusters);
FlowStrPrint(bmsgstr, FLOW_LV);
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Available cluster : %32ld\n\r", st_disk.avail_clusters);
FlowStrPrint(bmsgstr, FLOW_LV);
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Sector / Cluster : %32ld\n\r", st_disk.sectors_per_cluster);
FlowStrPrint(bmsgstr, FLOW_LV);
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Byte / Sector : %32ld\n\r", st_disk.bytes_per_sector);
FlowStrPrint(bmsgstr, FLOW_LV);
}
// (16)Change of drive letter
} else if (isalpha(arg[0][0]) && (arg[0][1] == ':') && (arg[0][2] == 0x00)) {
if (fatChdrv((char *)arg[0]) != TEST_SUCCESS) {
if ((fat_stFatErr.bErrCode == FAT_DRIVE_NOTFOUND) || (fat_stFatErr.bErrCode == FAT_INVALID_DRIVE)) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: \"%s\" drive(partition) letter is not found.\n\r", arg[0]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
}
// (17)Display directory list
} else if (strcmp((char *)arg[0], "dir") == 0) {
memset(&st_find, 0x00, sizeof(st_find));
if (arg[1][0] == 0x00) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
status = fatDosFindFirst("*.*", FAT_AT_ALL, &st_find);
while (status == TEST_SUCCESS) {
buf[0] = (st_find.attrib & FAT_AT_ARC) ? 'A' : '-';
buf[1] = (st_find.attrib & FAT_AT_SBD) ? 'D' : '-';
buf[2] = (st_find.attrib & FAT_AT_VOL) ? 'V' : '-';
buf[3] = (st_find.attrib & FAT_AT_SYS) ? 'S' : '-';
buf[4] = (st_find.attrib & FAT_AT_HID) ? 'H' : '-';
buf[5] = (st_find.attrib & FAT_AT_ROL) ? 'R' : '-';
sprintf((char *)bmsgstr, "0x%04X 0x%04X %s %10ul %s\n\r", st_find.wr_date, st_find.wr_time, buf, st_find.size, st_find.name);
FlowStrPrint(bmsgstr, FLOW_LV);
status = fatDosFindNext(&st_find);
}
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
if (fat_stFatErr.bErrCode == FAT_NOMORE_FILES) {
iFn = fatGetFn((char *)fat_bCurDir, (unsigned long *)&n);
sprintf((char *)bmsgstr, "All directory entry count : %d\n\r", n);
FlowStrPrint(bmsgstr, FLOW_LV);
sprintf((char *)bmsgstr, "File / Folder count : %d\n\r", iFn);
FlowStrPrint(bmsgstr, FLOW_LV);
}
} else {
if (!strrchr((char *)arg[1], '.')) {
strcpy((char *)arg[2], (char *)arg[1]);
strcat((char *)arg[1], "\\*.*");
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
status = fatDosFindFirst((char *)arg[1], FAT_AT_ALL, &st_find);
while (status == TEST_SUCCESS) {
buf[0] = (st_find.attrib & FAT_AT_ARC) ? 'A' : '-';
buf[1] = (st_find.attrib & FAT_AT_SBD) ? 'D' : '-';
buf[2] = (st_find.attrib & FAT_AT_VOL) ? 'V' : '-';
buf[3] = (st_find.attrib & FAT_AT_SYS) ? 'S' : '-';
buf[4] = (st_find.attrib & FAT_AT_HID) ? 'H' : '-';
buf[5] = (st_find.attrib & FAT_AT_ROL) ? 'R' : '-';
sprintf((char *)bmsgstr, "0x%04X 0x%04X %s %10ul %s\n\r", st_find.wr_date, st_find.wr_time, buf, st_find.size, st_find.name);
FlowStrPrint(bmsgstr, FLOW_LV);
status = fatDosFindNext(&st_find);
}
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
if (fat_stFatErr.bErrCode == FAT_NOMORE_FILES) {
iFn = fatGetFn((char *)arg[2], (unsigned long *)&n);
sprintf((char *)bmsgstr, "All directory entry count : %d\n\r", n);
FlowStrPrint(bmsgstr, FLOW_LV);
sprintf((char *)bmsgstr, "File / Folder count : %d\n\r", iFn);
FlowStrPrint(bmsgstr, FLOW_LV);
}
} else {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
status = fatDosFindFirst((char *)arg[1], FAT_AT_ALL, &st_find);
while (status == TEST_SUCCESS) {
buf[0] = (st_find.attrib & FAT_AT_ARC) ? 'A' : '-';
buf[1] = (st_find.attrib & FAT_AT_SBD) ? 'D' : '-';
buf[2] = (st_find.attrib & FAT_AT_VOL) ? 'V' : '-';
buf[3] = (st_find.attrib & FAT_AT_SYS) ? 'S' : '-';
buf[4] = (st_find.attrib & FAT_AT_HID) ? 'H' : '-';
buf[5] = (st_find.attrib & FAT_AT_ROL) ? 'R' : '-';
sprintf((char *)bmsgstr, "0x%04X 0x%04X %s %10ul %s\n\r", st_find.wr_date, st_find.wr_time, buf, st_find.size, st_find.name);
FlowStrPrint(bmsgstr, FLOW_LV);
status = fatDosFindNext(&st_find);
}
}
}
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
// (18)Display file data
} else if (strcmp((char *)arg[0], "dump") == 0) {
fr = fatFopen((char *)arg[1], "rb");
if (fr == 0) {
memset(bmsgstr, 0x00, sizeof(bmsgstr));
sprintf((char *)bmsgstr, "Error: Cannot open \"%s\".\n\r", arg[1]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
addr = 0;
i = (BUF_SIZE * BUF_COUNT) / 16; // loop number
do {
size_cnt = 0;
size = fatFread(buf, 1, BUF_SIZE * BUF_COUNT, fr);
if (size == 0)
break;
sprintf((char *)bmsgstr, "\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
sprintf((char *)bmsgstr, " Addr |+0 +1 +2 +3 +4 +5 +6 +7-+8 +9 +A +B +C +D +E +F|\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
sprintf((char *)bmsgstr, "--------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
for (row = 0; row < i; row++) {
sprintf((char *)bmsgstr, "%08X|", addr);
FlowStrPrint(bmsgstr, FLOW_LV);
for (col = 0; col < 16; col++) {
if (size_cnt < size) {
if (col == 7) {
sprintf((char *)bmsgstr, "%02X-", buf[size_cnt]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else if (col == 15) {
sprintf((char *)bmsgstr, "%02X|\n\r", buf[size_cnt]);
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
sprintf((char *)bmsgstr, "%02X ", buf[size_cnt]);
FlowStrPrint(bmsgstr, FLOW_LV);
}
} else {
if (col == 7) {
sprintf((char *)bmsgstr, " -" );
FlowStrPrint(bmsgstr, FLOW_LV);
} else if (col == 15) {
sprintf((char *)bmsgstr, " |\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
} else {
sprintf((char *)bmsgstr, " ");
FlowStrPrint(bmsgstr, FLOW_LV);
}
}
size_cnt++;
addr++;
}
if (size_cnt >= size)
break;
}
sprintf((char *)bmsgstr, "--------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\n\r");
FlowStrPrint(bmsgstr, FLOW_LV);
} while (fatFeof(fr) == 0);
}
fatFclose(fr);
// (19)File seek
} else if (strcmp((char *)arg[0], "seek") == 0) {
fr = fatFopen((char *)arg[1], "rb");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -