diff options
author | Bertrand Simonnet <bsimonnet@google.com> | 2015-09-22 18:22:35 +0000 |
---|---|---|
committer | Bertrand Simonnet <bsimonnet@google.com> | 2015-09-22 18:22:35 +0000 |
commit | 134aa097b9106e63e1622389fbb0d5543bd3d558 (patch) | |
tree | 867565ee7f5d305761408f7effcfe49fd3ac4681 | |
parent | 4a2bdd8006a5ddf166bcc8973c135799da453e09 (diff) | |
download | rootdev-134aa097b9106e63e1622389fbb0d5543bd3d558.tar.gz |
Revert "rootdev: Don't try to access /dev/block."
This breaks when built with clang
This reverts commit 4a2bdd8006a5ddf166bcc8973c135799da453e09.
Change-Id: I2f89a9c19de91d4c46dce110e36a32551134e5d5
-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); |