@ohos-ports/mountutils 0.0.0-stage → 2.0.8-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/OHOS-PORTS.md ADDED
@@ -0,0 +1,24 @@
1
+ # @ohos-ports/mountutils
2
+
3
+ OpenHarmony port of [mountutils](https://github.com/balena-io-modules/mountutils) 2.0.8.
4
+
5
+ ## What changed vs upstream
6
+
7
+ - `nan` runtime dependency replaced with `@ohos-ports/nan@^2.22.0-gk.1-beta.1` (upstream `nan` cannot build on OpenHarmony); `binding.gyp` include_dirs updated to `require('@ohos-ports/nan')` accordingly.
8
+ - Native addon compiled from source on OpenHarmony arm64 (`src/linux/functions.cpp` — the linux sources are the correct ones for OpenHarmony; gyp routes `openharmony` to the `OS=="linux"` condition via `sys.platform`).
9
+ - Ships `prebuilds/openharmony-arm64/MountUtils.node` (built with Node.js 26.x headers; the addon uses nan/V8 API and is ABI-specific — other Node ABI versions fall back to source compilation via `node-gyp-build`/`node-gyp`, which requires the OpenHarmony native toolchain).
10
+ - Upstream `prebuilds/linux-x64/` prebuild dropped (wrong platform for OpenHarmony).
11
+
12
+ ## ⚠️ Known system-side limitation (not a porting defect)
13
+
14
+ `mount(2)` and `umount2(2)` are **SIGSYS-killed by the app-sandbox seccomp filter** in third-party app contexts on HarmonyOS (verified: standalone C probe exit 159 "Bad system call"). Consequence:
15
+
16
+ - The addon **installs, loads and exports** `eject`/`unmountDisk` correctly; 21/21 executable tests pass, `/proc/mounts` is readable, error paths propagate.
17
+ - **Calling `unmountDisk`/`eject` on a real device inside a third-party app kills the Node.js process** (SIGSYS, no errno return). No public HarmonyOS API maps to unmount/eject (`@ohos.file.volumeManager` is a system API). Usage from system/root contexts is expected to work but is unverified.
18
+ - Full evidence and attribution: see the `issue-system-side-mountutils@2.0.8.pptx` / migration report in the ohos-ports archives.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install @ohos-ports/mountutils
24
+ ```
package/README.md CHANGED
@@ -1,3 +1,118 @@
1
- # Temporary Holding Version
1
+ # mountutils
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/mountutils.svg?style=flat-square)](https://npmjs.com/package/mountutils)
4
+ [![npm license](https://img.shields.io/npm/l/mountutils.svg?style=flat-square)](https://npmjs.com/package/mountutils)
5
+ [![npm downloads](https://img.shields.io/npm/dm/mountutils.svg?style=flat-square)](https://npmjs.com/package/mountutils)
6
+
7
+ > Cross platform mount related utilities
8
+
9
+ ## Installation
10
+
11
+ Install `mountutils` by running:
12
+
13
+ ```sh
14
+ $ npm install --save mountutils
15
+ ```
16
+
17
+ ## Prebuild
18
+
19
+ This project contains cross-platform prebuild
20
+
21
+ ## Debug mode
22
+
23
+ You can enable debug mode by setting the `MOUNTUTILS_DEBUG` environment
24
+ variable.
25
+
26
+ ## Documentation
27
+
28
+ <a name="module_mountutils.unmountDisk"></a>
29
+
30
+ ### mountutils.unmountDisk(device, callback)
31
+
32
+ **Kind**: static method of <code>[mountutils](#module_mountutils)</code>
33
+ **Summary**: Unmount a whole disk
34
+ **Access**: public
35
+
36
+ | Param | Type | Description |
37
+ | -------- | --------------------- | ---------------- |
38
+ | device | <code>String</code> | device |
39
+ | callback | <code>function</code> | callback (error) |
40
+
41
+ **Example**
42
+
43
+ ```js
44
+ // macOS
45
+ const drive = "/dev/disk2";
46
+
47
+ // GNU/Linux
48
+ const drive = "/dev/sdb";
49
+
50
+ // Windows
51
+ const drive = "\\\\.\\PHYSICALDRIVE2";
52
+
53
+ mountutils.unmountDisk(drive, (error) => {
54
+ if (error) {
55
+ throw error;
56
+ }
57
+
58
+ console.log("Done!");
59
+ });
60
+ ```
61
+
62
+ ## Support
63
+
64
+ If you're having any problem, please [raise an issue][newissue] on GitHub and
65
+ the balena.io team will be happy to help.
66
+
67
+ ## Tests
68
+
69
+ Run the test suite by doing:
70
+
71
+ ```sh
72
+ $ npm test
73
+ ```
74
+
75
+ ## Troubleshooting
76
+
77
+ ### `error C2373: '__pfnDliNotifyHook2': redefinition`
78
+
79
+ This error indicates that the version of npm you're running is too old. Upgrade
80
+ by running:
81
+
82
+ ```sh
83
+ npm install -g npm@latest
84
+ ```
85
+
86
+ See the [following `node-gyp` issue](https://github.com/nodejs/node-gyp/issues/972) for more details.
87
+
88
+
89
+
90
+ ### ```ModuleNotFoundError: No module named 'distutils'`
91
+
92
+ Your version of python is too recent for node-gyp to work;
93
+ Use a version <= 3.11 and it should work.
94
+
95
+ ## Contribute
96
+
97
+ - Issue Tracker: [github.com/balena-io-modules/mountutils/issues][issues]
98
+ - Source Code: [github.com/balena-io-modules/mountutils][source]
99
+
100
+ ### Dependencies
101
+
102
+ - [cpplint][cpplint]
103
+
104
+ Before submitting a PR, please make sure that you include tests, and that
105
+ linters run without any warning:
106
+
107
+ ```sh
108
+ $ npm run lint
109
+ ```
110
+
111
+ ## License
112
+
113
+ The project is licensed under the Apache 2.0 license.
114
+
115
+ [issues]: https://github.com/balena-io-modules/mountutils/issues
116
+ [newissue]: https://github.com/balena-io-modules/mountutils/issues/new
117
+ [source]: https://github.com/balena-io-modules/mountutils
118
+ [cpplint]: https://github.com/cpplint/cpplint
package/binding.gyp ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "MountUtils",
5
+ "include_dirs" : [
6
+ "<!(node -e \"require('@ohos-ports/nan')\")"
7
+ ],
8
+ "sources": [
9
+ "src/mountutils.cpp",
10
+ "src/worker-unmount.cpp",
11
+ "src/worker-eject.cpp"
12
+ ],
13
+ "msvs_settings": {
14
+ "VCLinkerTool": {
15
+ "SetChecksum": "true"
16
+ },
17
+ "VCCLCompilerTool": {
18
+ "ExceptionHandling": 1,
19
+ "AdditionalOptions": [
20
+ "/EHsc"
21
+ ]
22
+ }
23
+ },
24
+ 'conditions': [
25
+
26
+ [ 'OS=="linux"', {
27
+ "sources": [
28
+ "src/linux/functions.cpp"
29
+ ],
30
+ } ],
31
+
32
+ [ 'OS=="win"', {
33
+ "sources": [
34
+ "src/windows/functions.cpp"
35
+ ],
36
+ "libraries": [
37
+ "-lKernel32.lib",
38
+ "-lSetupAPI.lib",
39
+ "-lCfgmgr32.lib"
40
+ ],
41
+ } ],
42
+
43
+ [ 'OS=="mac"', {
44
+ "xcode_settings": {
45
+ "OTHER_CPLUSPLUSFLAGS": [
46
+ "-stdlib=libc++"
47
+ ],
48
+ "OTHER_LDFLAGS": [
49
+ "-stdlib=libc++"
50
+ ]
51
+ },
52
+ "sources": [
53
+ "src/darwin/functions.cpp"
54
+ ],
55
+ "link_settings": {
56
+ "libraries": [
57
+ "DiskArbitration.framework",
58
+ "Foundation.framework",
59
+ ],
60
+ },
61
+ } ],
62
+
63
+ ],
64
+ }
65
+ ],
66
+ 'variables' : {
67
+ 'openssl_fips': '',
68
+ },
69
+ }
@@ -0,0 +1,91 @@
1
+ mountutils
2
+ ==========
3
+
4
+ [![npm](https://img.shields.io/npm/v/mountutils.svg?style=flat-square)](https://npmjs.com/package/mountutils)
5
+ [![npm license](https://img.shields.io/npm/l/mountutils.svg?style=flat-square)](https://npmjs.com/package/mountutils)
6
+ [![npm downloads](https://img.shields.io/npm/dm/mountutils.svg?style=flat-square)](https://npmjs.com/package/mountutils)
7
+ [![Travis CI status](https://img.shields.io/travis/resin-io-modules/mountutils/master.svg?style=flat-square&label=linux%20|%20mac)](https://travis-ci.org/resin-io-modules/mountutils/branches)
8
+ [![AppVeyor status](https://img.shields.io/appveyor/ci/resin-io/mountutils/master.svg?style=flat-square&label=windows)](https://ci.appveyor.com/project/resin-io/mountutils/branch/master)
9
+
10
+ > Cross platform mount related utilities
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Install `mountutils` by running:
16
+
17
+ ```sh
18
+ $ npm install --save mountutils
19
+ ```
20
+
21
+ Debug mode
22
+ ----------
23
+
24
+ You can enable debug mode by setting the `MOUNTUTILS_DEBUG` environment
25
+ variable.
26
+
27
+ Documentation
28
+ -------------
29
+
30
+ {{#module name="mountutils"}}
31
+ {{>body~}}
32
+ {{>member-index~}}
33
+ {{>separator~}}
34
+ {{>members~}}
35
+ {{/module}}
36
+
37
+ Support
38
+ -------
39
+
40
+ If you're having any problem, please [raise an issue][newissue] on GitHub and
41
+ the Resin.io team will be happy to help.
42
+
43
+ Tests
44
+ -----
45
+
46
+ Run the test suite by doing:
47
+
48
+ ```sh
49
+ $ npm test
50
+ ```
51
+
52
+ Troubleshooting
53
+ ---------------
54
+
55
+ ### `error C2373: '__pfnDliNotifyHook2': redefinition`
56
+
57
+ This error indicates that the version of npm you're running is too old. Upgrade
58
+ by running:
59
+
60
+ ```sh
61
+ npm install -g npm@latest
62
+ ```
63
+
64
+ See the [following `node-gyp` issue](https://github.com/nodejs/node-gyp/issues/972) for more details.
65
+
66
+ Contribute
67
+ ----------
68
+
69
+ - Issue Tracker: [github.com/resin-io-modules/mountutils/issues][issues]
70
+ - Source Code: [github.com/resin-io-modules/mountutils][source]
71
+
72
+ ### Dependencies
73
+
74
+ - [cpplint][cpplint]
75
+
76
+ Before submitting a PR, please make sure that you include tests, and that
77
+ linters run without any warning:
78
+
79
+ ```sh
80
+ $ npm run lint
81
+ ```
82
+
83
+ License
84
+ -------
85
+
86
+ The project is licensed under the Apache 2.0 license.
87
+
88
+ [issues]: https://github.com/resin-io-modules/mountutils/issues
89
+ [newissue]: https://github.com/resin-io-modules/mountutils/issues/new
90
+ [source]: https://github.com/resin-io-modules/mountutils
91
+ [cpplint]: https://github.com/cpplint/cpplint
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Copyright 2017 resin.io
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const mountUtils = require('..');
21
+
22
+ let argv = process.argv.slice(2);
23
+ let disk = argv.shift();
24
+
25
+ if (!disk) {
26
+ console.error(`Usage: node example/eject <disk>`);
27
+ process.exit(1);
28
+ }
29
+
30
+ process.env.MOUNTUTILS_DEBUG = true;
31
+
32
+ console.log('Ejecting', disk, '...');
33
+
34
+ mountUtils.eject(disk, function(error) {
35
+ console.log(error || 'OK');
36
+ });
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Copyright 2017 resin.io
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const mountUtils = require('..');
21
+
22
+ let argv = process.argv.slice(2);
23
+ let disk = argv.shift();
24
+
25
+ if (!disk) {
26
+ console.error(`Usage: node example/unmount <disk>`);
27
+ process.exit(1);
28
+ }
29
+
30
+ process.env.MOUNTUTILS_DEBUG = true;
31
+
32
+ console.log('Unmounting', disk, '...');
33
+
34
+ mountUtils.unmountDisk(disk, function(error) {
35
+ console.log(error || 'OK');
36
+ });
package/index.js ADDED
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2017 resin.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
+ /**
18
+ * @module mountutils
19
+ */
20
+
21
+ "use strict";
22
+
23
+ /**
24
+ * @summary Unmount a whole disk
25
+ * @function
26
+ * @public
27
+ * @static
28
+ * @name unmountDisk
29
+ *
30
+ * @param {String} device - device
31
+ * @param {Function} callback - callback (error)
32
+ *
33
+ * @example
34
+ * // macOS
35
+ * const drive = '/dev/disk2';
36
+ *
37
+ * // GNU/Linux
38
+ * const drive = '/dev/sdb';
39
+ *
40
+ * // Windows
41
+ * const drive = '\\\\.\\PHYSICALDRIVE2';
42
+ *
43
+ * mountutils.unmountDisk(drive, (error) => {
44
+ * if (error) {
45
+ * throw error;
46
+ * }
47
+ *
48
+ * console.log('Done!');
49
+ * });
50
+ */
51
+
52
+ // Will load a compiled build if present or a prebuild.
53
+ // If no build if found it will throw an exception
54
+ const binding = require('node-gyp-build')(__dirname);
55
+
56
+ module.exports = binding;
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@ohos-ports/mountutils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.8-beta.1",
4
+ "main": "index.js",
5
+ "description": "Cross platform mount related utilities",
6
+ "homepage": "https://github.com/balena-io-modules/mountutils",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
10
+ "directory": "ports/mountutils/2.0.8"
11
+ },
12
+ "keywords": [
13
+ "mount",
14
+ "utils",
15
+ "unmount",
16
+ "unmounDisk",
17
+ "cross",
18
+ "platform"
19
+ ],
20
+ "engines": {
21
+ "node": ">18 <=24"
22
+ },
23
+ "files": [
24
+ "index.js",
25
+ "src",
26
+ "docs",
27
+ "example",
28
+ "binding.gyp",
29
+ "README.md",
30
+ "requirements.txt",
31
+ "prebuilds",
32
+ "OHOS-PORTS.md"
33
+ ],
34
+ "directories": {
35
+ "test": "tests"
36
+ },
37
+ "scripts": {
38
+ "configure": "node-gyp configure",
39
+ "build": "node-gyp-build && npm run prebuildify",
40
+ "prebuildify": "prebuildify -t 20.18.1 -t 22.13.0 --strip",
41
+ "rebuild": "node-gyp rebuild",
42
+ "readme": "jsdoc2md --template docs/README.hbs index.js > README.md",
43
+ "lint-js": "eslint *.js",
44
+ "lint-cpp": "cpplint --recursive src",
45
+ "lint": "npm run lint-js && npm run lint-cpp",
46
+ "test": "npm rebuild && mocha tests -R spec",
47
+ "install": "node-gyp-build"
48
+ },
49
+ "author": "Juan Cruz Viotti <juan@resin.io>",
50
+ "license": "Apache-2.0",
51
+ "devDependencies": {
52
+ "chai": "6.2.2",
53
+ "eslint": "9.39.5",
54
+ "jsdoc-to-markdown": "9.1.3",
55
+ "mocha": "11.8.0"
56
+ },
57
+ "dependencies": {
58
+ "bindings": "^1.3.0",
59
+ "@ohos-ports/nan": "^2.22.0-gk.1-beta.1",
60
+ "node-gyp-build": "^4.8.4",
61
+ "prebuildify": "^6.0.1"
62
+ },
63
+ "gypfile": true,
64
+ "bugs": {
65
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
66
+ }
67
+ }
@@ -0,0 +1 @@
1
+ cpplint==1.6.1
@@ -0,0 +1,177 @@
1
+ /*
2
+ * Copyright 2017 resin.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 <DiskArbitration/DiskArbitration.h>
18
+ #include "../mountutils.hpp"
19
+
20
+ struct RunLoopContext {
21
+ MOUNTUTILS_RESULT code = MOUNTUTILS_SUCCESS;
22
+ };
23
+
24
+ MOUNTUTILS_RESULT translate_dissenter(DADissenterRef dissenter) {
25
+ if (dissenter) {
26
+ DAReturn status = DADissenterGetStatus(dissenter);
27
+ if (status == kDAReturnBadArgument ||
28
+ status == kDAReturnNotFound) {
29
+ return MOUNTUTILS_ERROR_INVALID_DRIVE;
30
+ } else if (status == kDAReturnNotPermitted ||
31
+ status == kDAReturnNotPrivileged) {
32
+ return MOUNTUTILS_ERROR_ACCESS_DENIED;
33
+ } else {
34
+ MountUtilsLog("Unknown dissenter status");
35
+ return MOUNTUTILS_ERROR_GENERAL;
36
+ }
37
+ } else {
38
+ return MOUNTUTILS_SUCCESS;
39
+ }
40
+ }
41
+
42
+ MOUNTUTILS_RESULT
43
+ run_cb(const char* device, DADiskUnmountCallback callback, size_t times) {
44
+ RunLoopContext context;
45
+ void *ctx = &context;
46
+
47
+ // Create a session object
48
+ MountUtilsLog("Creating DA session");
49
+ DASessionRef session = DASessionCreate(kCFAllocatorDefault);
50
+
51
+ if (session == NULL) {
52
+ MountUtilsLog("Session couldn't be created");
53
+ return MOUNTUTILS_ERROR_GENERAL;
54
+ }
55
+
56
+ // Get a disk object from the disk path
57
+ MountUtilsLog("Getting disk object");
58
+ DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault,
59
+ session, device);
60
+
61
+ // Unmount, and then eject from the unmount callback
62
+ MountUtilsLog("Unmounting");
63
+ DADiskUnmount(disk,
64
+ kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce,
65
+ callback,
66
+ ctx);
67
+
68
+ // Schedule a disk arbitration session
69
+ MountUtilsLog("Schedule session on run loop");
70
+ DASessionScheduleWithRunLoop(session,
71
+ CFRunLoopGetCurrent(),
72
+ kCFRunLoopDefaultMode);
73
+
74
+ // Start the run loop: Run with a timeout of 500ms (0.5s),
75
+ // and don't terminate after only handling one resource.
76
+ // NOTE: As the unmount callback gets called *before* the runloop can
77
+ // be started here when there's no device to be unmounted or
78
+ // the device has already been unmounted, the loop would
79
+ // hang indefinitely until stopped manually otherwise.
80
+ // Here we repeatedly run the loop for a given time, and stop
81
+ // it at some point if it hasn't gotten anywhere, or if there's
82
+ // nothing to be unmounted, or a dissent has been caught before the run.
83
+ // This way we don't have to manage state across callbacks.
84
+ MountUtilsLog("Starting run loop");
85
+
86
+ bool done = false;
87
+ unsigned int loop_count = 0;
88
+
89
+ while (!done) {
90
+ loop_count++;
91
+ // See https://developer.apple.com/reference/corefoundation/1541988-cfrunloopruninmode
92
+ SInt32 status = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, false);
93
+ // Stop starting the runloop once it's been manually stopped
94
+ if ((status == kCFRunLoopRunStopped) || (status == kCFRunLoopRunFinished)) {
95
+ done = true;
96
+ }
97
+ // Bail out if DADiskUnmount caught a dissent and
98
+ // thus returned before the runloop even started
99
+ if (context.code != MOUNTUTILS_SUCCESS) {
100
+ MountUtilsLog("Runloop dry");
101
+ done = true;
102
+ }
103
+ // Bail out if the runloop is timing out, but not getting anywhere
104
+ if (loop_count > 10) {
105
+ MountUtilsLog("Runloop stall");
106
+ context.code = MOUNTUTILS_ERROR_AGAIN;
107
+ done = true;
108
+ }
109
+ }
110
+
111
+ // Clean up the session
112
+ MountUtilsLog("Releasing session & disk object");
113
+ DASessionUnscheduleFromRunLoop(session,
114
+ CFRunLoopGetCurrent(),
115
+ kCFRunLoopDefaultMode);
116
+ CFRelease(session);
117
+
118
+ if (context.code == MOUNTUTILS_ERROR_AGAIN && times < 5) {
119
+ MountUtilsLog("Retrying...");
120
+ return run_cb(device, callback, times + 1);
121
+ }
122
+
123
+ MOUNTUTILS_RESULT result = context.code;
124
+ return result;
125
+ }
126
+
127
+ void _unmount_cb(DADiskRef disk, DADissenterRef dissenter, void *ctx) {
128
+ MountUtilsLog("[unmount]: Unmount callback");
129
+ RunLoopContext *context = reinterpret_cast<RunLoopContext*>(ctx);
130
+ if (dissenter) {
131
+ MountUtilsLog("[unmount]: Unmount dissenter");
132
+ context->code = translate_dissenter(dissenter);
133
+ } else {
134
+ MountUtilsLog("[unmount]: Unmount success");
135
+ context->code = MOUNTUTILS_SUCCESS;
136
+ }
137
+ CFRunLoopStop(CFRunLoopGetCurrent());
138
+ }
139
+
140
+ void _eject_cb(DADiskRef disk, DADissenterRef dissenter, void *ctx) {
141
+ MountUtilsLog("[eject]: Eject callback");
142
+ RunLoopContext *context = reinterpret_cast<RunLoopContext*>(ctx);
143
+ if (dissenter) {
144
+ MountUtilsLog("[eject]: Eject dissenter");
145
+ context->code = translate_dissenter(dissenter);
146
+ } else {
147
+ MountUtilsLog("[eject]: Eject success");
148
+ context->code = MOUNTUTILS_SUCCESS;
149
+ }
150
+ CFRunLoopStop(CFRunLoopGetCurrent());
151
+ }
152
+
153
+ void _eject_unmount_cb(DADiskRef disk, DADissenterRef dissenter, void *ctx) {
154
+ MountUtilsLog("[eject]: Unmount callback");
155
+ RunLoopContext *context = reinterpret_cast<RunLoopContext*>(ctx);
156
+ if (dissenter) {
157
+ MountUtilsLog("[eject]: Unmount dissenter");
158
+ context->code = translate_dissenter(dissenter);
159
+ CFRunLoopStop(CFRunLoopGetCurrent());
160
+ } else {
161
+ MountUtilsLog("[eject]: Unmount success");
162
+ MountUtilsLog("[eject]: Ejecting...");
163
+ context->code = MOUNTUTILS_SUCCESS;
164
+ DADiskEject(disk,
165
+ kDADiskEjectOptionDefault,
166
+ _eject_cb,
167
+ ctx);
168
+ }
169
+ }
170
+
171
+ MOUNTUTILS_RESULT unmount_disk(const char* device) {
172
+ return run_cb(device, _unmount_cb, 0);
173
+ }
174
+
175
+ MOUNTUTILS_RESULT eject_disk(const char* device) {
176
+ return run_cb(device, _eject_unmount_cb, 0);
177
+ }