-- if (root && in_path(root, output))
-+ if (root && same_device(root, output) && in_path(root, output))
- return err_msg("output file cannot be in the UBIFS root "
- "directory");
- if (!is_power_of_2(c->min_io_size))
+- if (root) {
++ if (root && same_device(root, output)) {
+ tmp = is_contained(output, root);
+ if (tmp < 0)
+ return err_msg("failed to perform output file root check");