获取磁盘标签在Linux下的C / C ++ [英] Getting disk label in Linux in C/C++

查看:412
本文介绍了获取磁盘标签在Linux下的C / C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/4112964/how-to-get-drive-label-in-linux-using-c-from-userspace\">How利用从用户空间C至获取驱动器标签在Linux下

我如何才能通过其文件名用C语言编写的程序获得光盘的标签(的/ dev / sda1的,例如)/ C ++?

How can I obtain label of a disk by its file name (/dev/sda1, e.g.) in a program written in C/C++?

推荐答案

您可以code此命令的C或C ++等效的:

You can code the C or C++ equivalent of this command:

find -L /dev/disk/by-label -inum $(stat -c %i /dev/sda1) -print

这就是 STAT()你关心,并记住它的索引节点号的设备文件。遍历所有的文件位于/ dev /磁盘/按标签和 STAT()他们每个人。当inode号相匹配,那么匹配的文件的名称是软盘的标签。

That is, stat() the device file you care about and remember its inode number. Iterate over all of the files in /dev/disk/by-label, and stat() each of them. When the inode number matches, then the name of the matched file is the label of that disk.

如果是我的话,我倒是code在C以上算法++,采用的 Boost.Filesystem的

If it were me, I'd code the above algorithm in C++, using Boost.Filesystem.

这篇关于获取磁盘标签在Linux下的C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆