+typedef struct {
+ char *p_end; /* pointer to NULL at end of path */
+ char p_path[MAX_PATHLEN + 1]; /* pointer to the start of a path */
+} PATH_T;
+
+static inline void strip_trailing_slash(PATH_T *p)
+{
+ while (p->p_end > p->p_path && p->p_end[-1] == '/')
+ *--p->p_end = 0;
+}
+
+/*
+ * Move specified string into path. Convert "" to "." to handle BSD
+ * semantics for a null path. Strip trailing slashes.
+ */
+int
+path_set(PATH_T *p, char *string)
+{
+ if (strlen(string) > MAX_PATHLEN) {
+ //err("%s: name too long", string);
+ return(0);
+ }
+
+ (void)strcpy(p->p_path, string);
+ p->p_end = p->p_path + strlen(p->p_path);
+
+ if (p->p_path == p->p_end) {
+ *p->p_end++ = '.';
+ *p->p_end = 0;
+ }
+
+ strip_trailing_slash(p);
+ return(1);
+}
+
+#define R_FLAG (1<<0)
+#define I_FLAG (1<<1)
+#define N_FLAG (1<<2)
+#define F_FLAG (1<<3)
+#define P_FLAG (1<<4)
+#define V_FLAG (1<<5)
+
+command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
+
+ FRESULT fr; /* Return value */
+ DIR dj; /* Directory search object */
+ FILINFO fno; /* File information */
+
+ uint8_t flags = 0;
+
+
+ /* reset getopt() */
+ optind = 0;
+
+ int opt;
+ while ((opt = getopt(argc, argv, PSTR("Rrfip"))) != -1) {
+ switch (opt) {
+ case 'f':
+ flags &= I_FLAG;
+ break;
+ case 'i':
+ flags |= I_FLAG;
+ flags &= F_FLAG;
+ break;
+ case 'p':
+ flags |= P_FLAG;
+ break;
+ case 'R':
+ case 'r':
+ flags |= R_FLAG;
+ break;
+ case 'v':
+ flags |= V_FLAG;
+ break;
+ default:
+ return CMD_RET_USAGE;
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+#if 0
+ /* consume last argument first. */
+ if (!path_set(&to, argv[--argc]))
+ exit(1);
+
+
+ if (flags & V_FLAG)
+ printf_P((PSTR("%s %s -> %s\n", badcp ? : "ERR:" : " ",
+ curr->fts_path, to.p_path);
+#endif
+
+/* Search a directory for objects and display it */
+
+
+ fr = f_findfirst(&dj, &fno, argv[1], argv[2]); /* Start to search for files */
+
+ while (fr == FR_OK && fno.fname[0]) { /* Repeat while an item is found */
+ printf_P(PSTR("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n"),
+ (fno.fattrib & AM_DIR) ? 'D' : '-',
+ (fno.fattrib & AM_RDO) ? 'R' : '-',
+ (fno.fattrib & AM_HID) ? 'H' : '-',
+ (fno.fattrib & AM_SYS) ? 'S' : '-',
+ (fno.fattrib & AM_ARC) ? 'A' : '-',
+ (fno.fdate >> 9) + 1980, (fno.fdate >> 5) & 15, fno.fdate & 31,
+ (fno.ftime >> 11), (fno.ftime >> 5) & 63,
+ fno.fsize, fno.fname);
+ fr = f_findnext(&dj, &fno); /* Search for next item */
+ }
+
+ f_closedir(&dj);
+
+ return CMD_RET_SUCCESS;
+}
+
+
+cmd_tbl_t cmd_tbl_fat[] = {