diff options
-rw-r--r-- | rootdev.c | 9 | ||||
-rw-r--r-- | rootdev.h | 10 |
2 files changed, 11 insertions, 8 deletions
@@ -357,10 +357,11 @@ int rootdev_get_path(char *path, size_t size, const char *device, if (path_len != strlen(dev_path) + 1 + strlen(device)) return -1; - // TODO(bsimonnet): We should check that |path| exists and is the right - // device. We don't do this currently as OEMs can add custom SELinux rules - // which may prevent us from accessing this. - // See b/24267261. + if (stat(path, &dev_statbuf) != 0) + return 1; + + if (dev && dev != dev_statbuf.st_rdev) + return 2; return 0; } @@ -79,12 +79,14 @@ void rootdev_get_device_slave(char *slave, size_t size, dev_t *dev, * @path is populated for all return codes. * Returns 0 on success and non-zero on error: * -1 on unexpected errors (@path may be invalid) + * 1 on no existing @path + * 2 @path exists but the dev_t value is mismatched. * * Nb, this function does NOT search /dev for a match. It performs a normal - * string concatenation. - * We can't check if the device actually exists as vendors may create an - * SELinux context we don't know about for it (in which case, this function - * would always fail). + * string concatenation and probes for the existence. If udev has moved, + * or otherwise renamed, the device, a positive value is returned. + * The caller may then use the dev_t and @path to create the node with + * mknod(2). */ int rootdev_get_path(char *path, size_t size, const char *device, dev_t dev, const char *dev_path); |