0

そのような単純な。開いているファイルのファイル記述子があり、それを含むデバイスのノード名を知りたいです。

4

1 に答える 1

0

これは、 libudevfstatを使用して簡単に作成できます。

#include <libudev.h>   // udev headers.
#include <sys/stat.h>  // for fstat function and stat struct.
#include <iostream>    // for printing ouput.
#include <fcntl>       // for open function.

using namespace std;

int main(int argc, char *argv[])
{
    int fd = open(argv[1], O_RDONLY);  // The file can be opened using any other mode, Eg. O_RDWR, O_APPEND, etc...
    struct udev *udev = udev_new();
    struct stat tb;
    fstat(fd, &tb);
    struct udev_device* dev = udev_device_new_from_devnum(udev, 'b', tb.st_dev);
    cout << "The opened file is located in the device: " << udev_device_get_devnode(dev) << endl;
    return 0;
}
于 2014-06-12T14:46:33.393 に答える