-
-
Notifications
You must be signed in to change notification settings - Fork 243
VFS: Initial procfs support #88
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
Conversation
This patch contains changes for procfs support, as well as fixing some bugs in the VFS system: - Fixed some more buffer overflow bugs. - Fixed traversing across mount boundaries. - Fixed `errno` when doing an unsupported operation on a device. (`EPERM`, not `EOPNOTSUPP`). Currently only a few static files (`filesystems`, `meminfo`, `mounts`, `self`, `uptime`), as well as the folder corresponding to the current process and its static contents (`cwd`, `exe`, `mounts`, `root`) are supported. For further support, `blink` must have some method to register, manage and query shared process information.
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.
Thank you!
struct HostfsDevice *hostfsdevice = (struct HostfsDevice *)device->data; | ||
*spec = strdup(hostfsdevice->source); | ||
if (*spec == NULL) { | ||
return enomem(); |
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.
You can just return -1 in cases like this, because strdup already set the errno.
@@ -128,6 +128,21 @@ int HostfsInit(const char *source, u64 flags, const void *data, | |||
return -1; | |||
} | |||
|
|||
int HostfsReadmountentry(struct VfsDevice *device, char **spec, char **type, char **mntops) { | |||
struct HostfsDevice *hostfsdevice = (struct HostfsDevice *)device->data; | |||
*spec = strdup(hostfsdevice->source); |
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.
One best practice for API design in C is that the output parameters should only be modified on success. There's very few exceptions to this rule. But it's mostly an issue for public APIs.
// TODO(trungnt): This should be dynamically allocated when we support | ||
// more processes. | ||
(*info)->ino = PROCFS_FIRST_PID_INO; | ||
sprintf((*info)->name, "%d", pid); |
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.
I recommend against using sprintf() because it's one of those functions that triggers security people and attracts attention from scanners.
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.
I used sprintf at that once instance as I wonder how a 32-bit int can take more than 16 chars to represent.
This patch contains changes for procfs support, as well as fixing some bugs in the VFS system:
errno
when doing an unsupported operation on a device. (EPERM
, notEOPNOTSUPP
).Currently only a few static files (
filesystems
,meminfo
,mounts
,self
,uptime
), as well as the folder corresponding to the current process and its static contents (cwd
,exe
,mounts
,root
) are supported. For further support,blink
must have some method to register, manage and query shared process information.