meterfs: Implement mount, getAttr, setAttr, stat and readdir#119
meterfs: Implement mount, getAttr, setAttr, stat and readdir#119agkaminski wants to merge 1 commit intomasterfrom
Conversation
|
|
| if (name[i] == '/') | ||
| return -ENOENT; | ||
| char *end = strchrnul(name + len, '/'); | ||
| const size_t size = end - name + len; |
There was a problem hiding this comment.
Probably should be:
| const size_t size = end - name + len; | |
| const size_t size = end - (name + len); |
| } | ||
|
|
||
| /* Hack-ish - handle virtual "." and ".." */ | ||
| if (offs == 0) { /* "."" */ |
There was a problem hiding this comment.
| if (offs == 0) { /* "."" */ | |
| if (offs == 0) { /* "." */ |
same in line 1476
| dent->d_reclen = len; | ||
| dent->d_namlen = len; | ||
| dent->d_type = DT_REG; | ||
| strncpy(dent->d_name, f->header.name, len); |
There was a problem hiding this comment.
it should be faster
| strncpy(dent->d_name, f->header.name, len); | |
| memcpy(dent->d_name, f->header.name, len); |
| if (parent == NULL) { | ||
| return -ENOMEM; | ||
| } | ||
| memcpy(parent, ctx->mountpoint, mntlen + 1); |
There was a problem hiding this comment.
a little faster
| memcpy(parent, ctx->mountpoint, mntlen + 1); | |
| memcpy(parent, ctx->mountpoint, mntlen); |
| int meterfs_init(meterfs_ctx_t *ctx) | ||
| { | ||
| int err; | ||
| ctx->mountpoint = NULL; |
There was a problem hiding this comment.
Move it after checking the condition ctx == NULL
anglov
left a comment
There was a problem hiding this comment.
Not reviewied code, I just playing with it a little with adapted flashsrv for DEND project.
My findings below:
1.meterfs: Filesystem check done. Found 23 files.,but ls show 24 files. One file is doubled
2. echo "abc" > /meterfs_mount_point/mfs_file causes that psh destroys file in unexpected way.
|
/gemini |
|
It looks like you ran the |
|
/gemini review |
There was a problem hiding this comment.
Code Review
The pull request introduces several new features to the meterfs, including mount, getAttr, setAttr, stat, and readdir functionalities. The changes seem well-structured and address the stated goal of enabling meterfs to be mounted in a directory and making 'ls' work. However, there are a few areas that could benefit from further attention.
Summary of Findings
- Error Handling in
meterfs_mount: Themeterfs_mountfunction allocates memory forparentandmountPoint. Ifreallocfails, the originalctx->mountpointis leaked. This should be addressed to prevent memory leaks. - Inconsistent ID Handling: The code mixes
id_tandoid_ttypes, especially in themeterfs_lookupfunctions. This could lead to confusion and potential errors. Standardizing onoid_tand removing the deprecatedmeterfs_lookupwould improve clarity. - Magic Number in
meterfs_readdir: Themeterfs_readdirfunction uses the magic number3to adjust the offset. This could be made more explicit with a named constant. - TODO comment in
meterfs_stat: Themeterfs_statfunction has a TODO comment regarding the filesystem ID. This should be addressed to ensure proper filesystem identification.
Merge Readiness
The pull request introduces significant new functionality and is a step in the right direction. However, there are several issues that need to be addressed before merging, particularly the memory leak in meterfs_mount and the inconsistent ID handling. I am unable to directly approve this pull request, and recommend that it not be merged until the critical and high severity issues are addressed, and that others review and approve this code before merging.
| int ret = lookup(parent, &ctx->parent, NULL); | ||
| free(parent); | ||
| if (ret < 0) { | ||
| return -ENOENT; | ||
| } | ||
|
|
||
| void *mountPoint = realloc(ctx->mountpoint, mntlen + 1); | ||
| if (mountPoint == NULL) { | ||
| return -ENOMEM; | ||
| } | ||
| ctx->mountpoint = mountPoint; |
There was a problem hiding this comment.
If realloc fails, the original ctx->mountpoint is leaked. This should be addressed to prevent memory leaks. Also, lookup is undeclared, so it should be defined or replaced with a standard library function.
int ret = lookup(parent, &ctx->parent, NULL);
free(parent);
if (ret < 0) {
free(ctx->mountpoint); // Free previously allocated mountpoint
return -ENOENT;
}
void *mountPoint = realloc(ctx->mountpoint, mntlen + 1);
if (mountPoint == NULL) {
free(ctx->mountpoint); // Free previously allocated mountpoint
return -ENOMEM;
}
ctx->mountpoint = mountPoint;| *res = ctx->parent; | ||
| return len - 1; |
| /* Backward compatibility, remove after adapting all flashsrvs */ | ||
| int meterfs_lookup(const char *name, id_t *res, meterfs_ctx_t *ctx) | ||
| { | ||
| oid_t oid; | ||
| int ret = meterfs_lookupOid(name, &oid, ctx); | ||
| *res = oid.id; | ||
| return ret; | ||
| } |
There was a problem hiding this comment.
Since meterfs_lookup is deprecated, consider removing it entirely to avoid confusion and simplify the API. If it must be retained for backward compatibility, add a prominent comment indicating its deprecated status and suggesting the use of meterfs_lookupOid instead.
| /* Backward compatibility, remove after adapting all flashsrvs */ | |
| int meterfs_lookup(const char *name, id_t *res, meterfs_ctx_t *ctx) | |
| { | |
| oid_t oid; | |
| int ret = meterfs_lookupOid(name, &oid, ctx); | |
| *res = oid.id; | |
| return ret; | |
| } | |
| /* Deprecated: Use meterfs_lookupOid instead */ | |
| int meterfs_lookup(const char *name, id_t *res, meterfs_ctx_t *ctx) | |
| { | |
| oid_t oid; | |
| int ret = meterfs_lookupOid(name, &oid, ctx); | |
| *res = oid.id; | |
| return ret; | |
| } |
| /* TODO - remove redundant custom enums */ | ||
| *attr = (id == ROOTDIR_ID) ? otDir : otFile; |
There was a problem hiding this comment.
The comment "TODO - remove redundant custom enums" indicates that the custom enums otDir and otFile should be removed. Consider doing this as part of this PR, or creating a separate issue to track this work.
| /* TODO - remove redundant custom enums */ | |
| *attr = (id == ROOTDIR_ID) ? otDir : otFile; | |
| /* Handle fs rootdir, otherwise regular file */ | |
| *attr = (id == ROOTDIR_ID) ? S_IFDIR : S_IFREG; |
JIRA: RTOS-182
Description
Change is intended as non-breaking, old API should be still functional
Motivation and Context
Allow meterfs to be mounted in a directory and make 'ls' work
Types of changes
How Has This Been Tested?
Checklist:
Special treatment