@ohos-ports/drivelist 12.0.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +732 -0
- package/LICENSE +177 -0
- package/README.md +215 -0
- package/build/Release/drivelist.node +0 -0
- package/js/index.d.ts +39 -0
- package/js/index.js +84 -0
- package/js/index.js.map +1 -0
- package/js/lsblk/index.d.ts +3 -0
- package/js/lsblk/index.js +104 -0
- package/js/lsblk/index.js.map +1 -0
- package/js/lsblk/json.d.ts +31 -0
- package/js/lsblk/json.js +114 -0
- package/js/lsblk/json.js.map +1 -0
- package/js/lsblk/pairs.d.ts +2 -0
- package/js/lsblk/pairs.js +158 -0
- package/js/lsblk/pairs.js.map +1 -0
- package/lib/index.ts +113 -0
- package/lib/lsblk/index.ts +126 -0
- package/lib/lsblk/json.ts +155 -0
- package/lib/lsblk/pairs.ts +188 -0
- package/package.json +84 -0
- package/src/darwin/REDiskList.h +41 -0
- package/src/darwin/REDiskList.m +61 -0
- package/src/darwin/list.mm +185 -0
- package/src/device-descriptor.cpp +125 -0
- package/src/drivelist.cpp +69 -0
- package/src/drivelist.hpp +65 -0
- package/src/linux/list.cpp +29 -0
- package/src/windows/list.cpp +741 -0
- package/src/windows/list.hpp +108 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017 balena.io
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "drivelist.hpp"
|
|
18
|
+
|
|
19
|
+
#include <napi.h>
|
|
20
|
+
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
class DriveListWorker : public Napi::AsyncWorker {
|
|
24
|
+
public:
|
|
25
|
+
explicit DriveListWorker(Napi::Function& callback)
|
|
26
|
+
: Napi::AsyncWorker(callback), devices() {}
|
|
27
|
+
|
|
28
|
+
virtual ~DriveListWorker() {}
|
|
29
|
+
|
|
30
|
+
void Execute() { devices = Drivelist::ListStorageDevices(); }
|
|
31
|
+
|
|
32
|
+
void OnOK() {
|
|
33
|
+
Napi::HandleScope scope(Env());
|
|
34
|
+
Napi::Object drives = Napi::Array::New(Env());
|
|
35
|
+
|
|
36
|
+
uint32_t i;
|
|
37
|
+
uint32_t size = (uint32_t)devices.size();
|
|
38
|
+
|
|
39
|
+
for (i = 0; i < size; i++) {
|
|
40
|
+
drives.Set(i, Drivelist::PackDriveDescriptor(Env(), &devices[i]));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Callback().Call({Env().Undefined(), drives});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
std::vector<Drivelist::DeviceDescriptor> devices;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Napi::Value List(const Napi::CallbackInfo& info) {
|
|
51
|
+
if (!info[0].IsFunction()) {
|
|
52
|
+
Napi::TypeError::New(info.Env(), "Callback must be a function")
|
|
53
|
+
.ThrowAsJavaScriptException();
|
|
54
|
+
return info.Env().Null();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Napi::Function callback = info[0].As<Napi::Function>();
|
|
58
|
+
DriveListWorker* dlWorker = new DriveListWorker(callback);
|
|
59
|
+
dlWorker->Queue();
|
|
60
|
+
|
|
61
|
+
return info.Env().Undefined();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
65
|
+
exports.Set(Napi::String::New(env, "list"), Napi::Function::New(env, List));
|
|
66
|
+
return exports;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
NODE_API_MODULE(DriveList, Init)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017 balena.io
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef SRC_DRIVELIST_HPP_
|
|
18
|
+
#define SRC_DRIVELIST_HPP_
|
|
19
|
+
|
|
20
|
+
#include <napi.h>
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <vector>
|
|
23
|
+
|
|
24
|
+
namespace Drivelist {
|
|
25
|
+
|
|
26
|
+
struct MountPoint {
|
|
27
|
+
std::string path;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
struct DeviceDescriptor {
|
|
31
|
+
std::string enumerator;
|
|
32
|
+
std::string busType;
|
|
33
|
+
std::string busVersion;
|
|
34
|
+
bool busVersionNull;
|
|
35
|
+
std::string device;
|
|
36
|
+
std::string devicePath;
|
|
37
|
+
bool devicePathNull;
|
|
38
|
+
std::string raw;
|
|
39
|
+
std::string description;
|
|
40
|
+
std::string error;
|
|
41
|
+
std::string partitionTableType;
|
|
42
|
+
uint64_t size;
|
|
43
|
+
uint32_t blockSize = 512;
|
|
44
|
+
uint32_t logicalBlockSize = 512;
|
|
45
|
+
std::vector<std::string> mountpoints;
|
|
46
|
+
std::vector<std::string> mountpointLabels;
|
|
47
|
+
bool isReadOnly; // Device is read-only
|
|
48
|
+
bool isSystem; // Device is a system drive
|
|
49
|
+
bool isVirtual; // Device is a virtual storage device
|
|
50
|
+
bool isRemovable; // Device is removable from the running system
|
|
51
|
+
bool isCard; // Device is an SD-card
|
|
52
|
+
bool isSCSI; // Connected via the Small Computer System Interface (SCSI)
|
|
53
|
+
bool isUSB; // Connected via Universal Serial Bus (USB)
|
|
54
|
+
bool isUAS; // Connected via the USB Attached SCSI (UAS)
|
|
55
|
+
bool isUASNull;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
std::vector<DeviceDescriptor> ListStorageDevices();
|
|
59
|
+
Napi::Object PackDriveDescriptor(Napi::Env env, const DeviceDescriptor *instance);
|
|
60
|
+
|
|
61
|
+
} // namespace Drivelist
|
|
62
|
+
|
|
63
|
+
Napi::Value List(const Napi::CallbackInfo& info);
|
|
64
|
+
|
|
65
|
+
#endif // SRC_DRIVELIST_HPP_
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017 balena.io
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include <napi.h>
|
|
18
|
+
#include <uv.h>
|
|
19
|
+
#include "../drivelist.hpp"
|
|
20
|
+
|
|
21
|
+
namespace Drivelist {
|
|
22
|
+
|
|
23
|
+
// TODO(jhermsmeier): Implement
|
|
24
|
+
std::vector<DeviceDescriptor> ListStorageDevices() {
|
|
25
|
+
std::vector<DeviceDescriptor> drivelist;
|
|
26
|
+
return drivelist;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace Drivelist
|