Mount + proper init + sys/proc/tmp
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <node.h>
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
|
||||
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
|
||||
|
||||
namespace ioctlNode {
|
||||
void nodeIoctl(const nodeparam& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
|
||||
|
||||
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument 1& 2 must be a number").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::String::Utf8Value str(isolate, args[0]);
|
||||
std::string cppStr(*str);
|
||||
|
||||
int fd = open(cppStr.c_str(), 'r');
|
||||
unsigned long request = args[1].As<v8::Number>()->Value();
|
||||
int params[args.Length() - 2];
|
||||
for(int i = 1 ; i < args.Length(); i++ ) {
|
||||
if (!args[i]->IsNumber()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
params[i - 1] = args[i].As<v8::Number>()->Value();
|
||||
}
|
||||
|
||||
args.GetReturnValue().Set(ioctl(fd, request, ¶ms));
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports) {
|
||||
NODE_SET_METHOD(exports, "ioctl", nodeIoctl);
|
||||
}
|
||||
|
||||
NODE_MODULE(ioctl_api, Initialize)
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
#include <node.h>
|
||||
|
||||
namespace mountNode {
|
||||
void nodemount(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
if (!args[0]->IsString()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "First argument must be a string pointing to a device").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args[1]->IsString()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument must be a string pointing to a folder").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args[2]->IsString()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument must be a filesystem name").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args[3]->IsNumber()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument must be a number made from the mount flags").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args[4]->IsString()) {
|
||||
isolate->ThrowException(v8::Exception::TypeError(
|
||||
v8::String::NewFromUtf8(isolate, "Argument must be a string").ToLocalChecked()));
|
||||
return;
|
||||
}
|
||||
|
||||
v8::String::Utf8Value devpathV8(isolate, args[0]);
|
||||
std::string devpath(*devpathV8);
|
||||
|
||||
v8::String::Utf8Value mountPointV8(isolate, args[1]);
|
||||
std::string mountPoint(*mountPointV8);
|
||||
|
||||
v8::String::Utf8Value fsTypeV8(isolate, args[2]);
|
||||
std::string fsType(*fsTypeV8);
|
||||
|
||||
unsigned long rwFlags = args[3].As<v8::Number>()->Value();
|
||||
|
||||
//comma separated parameters passed directly into the fs driver
|
||||
v8::String::Utf8Value fsFlagsV8(isolate, args[4]);
|
||||
std::string fsFlags(*fsFlagsV8);
|
||||
|
||||
const int returnValue = mount(devpath.c_str(), mountPoint.c_str(), fsType.c_str(), rwFlags, fsFlags.c_str());
|
||||
args.GetReturnValue().Set(returnValue);
|
||||
}
|
||||
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports) {
|
||||
NODE_SET_METHOD(exports, "mount", nodemount);
|
||||
}
|
||||
|
||||
NODE_MODULE(mount_api, Initialize)
|
||||
}
|
||||
Reference in New Issue
Block a user