| 108 | |
| 109 | |
| 110 | Try<string> getDeviceForPath(const string& path) |
| 111 | { |
| 112 | struct stat statbuf; |
| 113 | |
| 114 | if (::lstat(path.c_str(), &statbuf) == -1) { |
| 115 | return ErrnoError("Unable to access '" + path + "'"); |
| 116 | } |
| 117 | |
| 118 | if (S_ISBLK(statbuf.st_mode)) { |
| 119 | return path; |
| 120 | } |
| 121 | |
| 122 | char* name = blkid_devno_to_devname(statbuf.st_dev); |
| 123 | if (name == nullptr) { |
| 124 | return ErrnoError("Unable to get device for '" + path + "'"); |
| 125 | } |
| 126 | |
| 127 | string devname(name); |
| 128 | free(name); |
| 129 | |
| 130 | return devname; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | namespace internal { |