Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set or reset DIR_ATT_HIDDEN attribute for directory entry #22425

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Marlin/src/sd/SdBaseFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,28 @@ bool SdBaseFile::remove(SdBaseFile *dirFile, const char *path) {
return file.open(dirFile, path, O_WRITE) ? file.remove() : false;
}

bool SdBaseFile::hide(const bool hidden) {
if (ENABLED(SDCARD_READONLY)) return false;
// must be an open file or subdirectory
if (!(isFile() || isSubDir())) return false;
// sync() and cache directory entry
sync();
dir_t *d = cacheDirEntry(SdVolume::CACHE_FOR_WRITE);
if (!d) return false;
uint8_t a = d->attributes;
if (hidden)
a |= DIR_ATT_HIDDEN;
else
a &= ~DIR_ATT_HIDDEN;

if (a != d->attributes) {
d->attributes = a;
return vol_->cacheFlush();
}

return true;
}

/**
* Rename a file or subdirectory.
*
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/sd/SdBaseFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ class SdBaseFile {
bool rmdir();
bool rmRfStar();

/**
* Set or clear DIR_ATT_HIDDEN attribute for directory entry
*/
bool hide(const bool hidden);

/**
* Set the files position to current position + \a pos. See seekSet().
* \param[in] offset The new position in bytes from the current position.
Expand Down