* Make a new directory. * * \param[in] parent An open SdFat instance for the directory that will contain * the new directory. * * \param[in] path A path with a valid 8.3 DOS name for the new directory. * * \param[in] pFlag Create missing parent directories if true. * * \return true for success, false for failure. * Reasons for failure include this file is already open, \a parent is not a
| 438 | * directory, \a path is invalid or already exists in \a parent. |
| 439 | */ |
| 440 | bool SdBaseFile::mkdir(SdBaseFile *parent, const char *path, const bool pFlag/*=true*/) { |
| 441 | if (ENABLED(SDCARD_READONLY)) return false; |
| 442 | |
| 443 | SdBaseFile dir1, dir2, *sub = &dir1; |
| 444 | SdBaseFile * const start = parent; |
| 445 | |
| 446 | #if ENABLED(LONG_FILENAME_WRITE_SUPPORT) |
| 447 | uint8_t dlname[LONG_FILENAME_LENGTH]; |
| 448 | #endif |
| 449 | |
| 450 | if (!parent || isOpen()) return false; |
| 451 | |
| 452 | if (*path == '/') { |
| 453 | while (*path == '/') path++; |
| 454 | if (!parent->isRoot()) { |
| 455 | if (!dir2.openRoot(parent->vol_)) return false; |
| 456 | parent = &dir2; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | uint8_t dname[11]; |
| 461 | for (;;) { |
| 462 | if (!TERN(LONG_FILENAME_WRITE_SUPPORT, parsePath(path, dname, dlname, &path), make83Name(path, dname, &path))) return false; |
| 463 | while (*path == '/') path++; |
| 464 | if (!*path) break; |
| 465 | if (!sub->open(parent, dname OPTARG(LONG_FILENAME_WRITE_SUPPORT, dlname), O_READ)) { |
| 466 | if (!pFlag || !sub->mkdir(parent, dname OPTARG(LONG_FILENAME_WRITE_SUPPORT, dlname))) |
| 467 | return false; |
| 468 | } |
| 469 | if (parent != start) parent->close(); |
| 470 | parent = sub; |
| 471 | sub = parent != &dir1 ? &dir1 : &dir2; |
| 472 | } |
| 473 | return mkdir(parent, dname OPTARG(LONG_FILENAME_WRITE_SUPPORT, dlname)); |
| 474 | } |
| 475 | |
| 476 | bool SdBaseFile::mkdir(SdBaseFile * const parent, const uint8_t dname[11] |
| 477 | OPTARG(LONG_FILENAME_WRITE_SUPPORT, const uint8_t dlname[LONG_FILENAME_LENGTH]) |
no test coverage detected