-
Notifications
You must be signed in to change notification settings - Fork 26
WIP: Improve performance #32
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
Draft
ankon
wants to merge
1
commit into
abique:master
Choose a base branch
from
ankon:wip/improve-performance
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "tmfs.hh" | ||
|
||
typedef struct dirhandle { | ||
DIR * dir; | ||
fs::path real_path; | ||
} dirhandle; | ||
|
||
int tmfs_opendir(const char * path, struct fuse_file_info * fi) | ||
{ | ||
// get the real path | ||
fs::path real_path = get_real_path(path); | ||
|
||
// checks if it's really a directory | ||
if (!fs::is_directory(real_path)) | ||
return -ENOTDIR; | ||
|
||
dirhandle * dh = new dirhandle; | ||
dh->dir = opendir(real_path.c_str()); | ||
if (dh->dir == 0) | ||
return -errno; | ||
|
||
dh->real_path = real_path; | ||
fi->fh = (intptr_t)dh; | ||
|
||
return 0; | ||
} | ||
|
||
int tmfs_releasedir(const char * path, struct fuse_file_info * fi) | ||
{ | ||
dirhandle * dh = (dirhandle *)fi->fh; | ||
int res = closedir(dh->dir); | ||
delete dh; | ||
return res; | ||
} | ||
|
||
int tmfs_readdir(const char * path, void * buf, fuse_fill_dir_t filler_cb, off_t offset, | ||
struct fuse_file_info * fi) | ||
{ | ||
struct stat stbuf; | ||
|
||
dirhandle * dh = (dirhandle *)fi->fh; | ||
|
||
// XXX: Midnight Commander seems to be doing something weird, and calls readdir twice | ||
// on the same directory. As we report everything in one go this means the second call | ||
// produces an empty output. | ||
// See also https://github.com/littlefs-project/littlefs-fuse/issues/43 | ||
// This is a workaround for that, and it's obviously quite expensive for big directories ... | ||
rewinddir(((dirhandle *)fi->fh)->dir); | ||
|
||
// report ./ and ../ | ||
stbuf.st_mode = S_IFDIR | 0755; | ||
stbuf.st_nlink = 2; | ||
filler_cb(buf, ".", &stbuf, 0); | ||
filler_cb(buf, "..", &stbuf, 0); | ||
|
||
struct dirent * entry; | ||
while ((entry = readdir(dh->dir))) | ||
{ | ||
// Skip '.' and '..', we already reported those. | ||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) | ||
continue; | ||
|
||
// stat the file pointed by entry | ||
if (getattr_at(dh->real_path, entry->d_name, &stbuf)) | ||
continue; | ||
stbuf.st_mode |= 0755; | ||
// report the entry | ||
filler_cb(buf, entry->d_name, &stbuf, 0); | ||
} | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
#include "tmfs.hh" | ||
|
||
int tmfs_getattr(const char *path, struct stat *stbuf) | ||
{ | ||
return getattr_at("", path, stbuf); | ||
} | ||
|
||
int getattr_at(const fs::path & known_real_path, const std::string & relative_path, struct stat *stbuf) | ||
{ | ||
// get the real path | ||
std::string real_path = get_real_path(path); | ||
fs::path real_path = get_real_path_at(known_real_path, relative_path); | ||
|
||
// and now just stat the real path | ||
memset(stbuf, 0, sizeof(struct stat)); | ||
if (lstat(real_path.c_str(), stbuf)) | ||
if (lstat(real_path.string().c_str(), stbuf)) | ||
return -errno; | ||
return 0; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading through this, original code was better I think and more explicit: