blkid_put_cache(cache);
return rc;
}
+
+int get_device_by_fd(int fd, char *partition, char *device)
+{
+ struct stat st;
+ int r = fstat(fd, &st);
+ if (r < 0) {
+ return -EINVAL; // hrm.
+ }
+ char *t = blkid_devno_to_devname(st.st_rdev);
+ if (!t) {
+ return -EINVAL;
+ }
+ strcpy(partition, t);
+ dev_t diskdev;
+ r = blkid_devno_to_wholedisk(st.st_rdev, device, PATH_MAX, &diskdev);
+ if (r < 0) {
+ return -EINVAL;
+ }
+ return 0;
+}
+
#elif defined(__APPLE__)
#include <sys/disk.h>
{
return -EOPNOTSUPP;
}
+int get_device_by_fd(int fd, char* partition, char* device)
+{
+ return -EOPNOTSUPP;
+}
#else
int get_block_device_size(int fd, int64_t *psize)
{
{
return -EOPNOTSUPP;
}
+
+int get_device_by_fd(int fd, char* partition, char* device)
+{
+ return -EOPNOTSUPP;
+}
#endif
extern int block_device_discard(int fd, int64_t offset, int64_t len);
extern int get_device_by_uuid(uuid_d dev_uuid, const char* label,
char* partition, char* device);
+extern int get_device_by_fd(int fd, char* partition, char* device);
#endif