한국어
Linux Programming
 

libblkid - USB Storage의 정보 가져오기

makersweb 2018.10.18 16:19 조회 수 : 674

libblkid는 블록장치를 식별하고 정보를 제공하는 유틸리티이다. 이 라이브러리를 이용하여 USB 메모리의 파티션 파일시스템 타입이나 레이블정보를 얻을 수 있다. 아래 소스코드를 참고하자.

 

#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <blkid/blkid.h>

int main (int argc, char *argv[]) {
  blkid_probe pr;
  const char *uuid;
  const char *label;
  const char *type;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s devname\n", argv[0]);
    exit(1);
  }

  pr = blkid_new_probe_from_filename(argv[1]);
  if (!pr) {
    err(2, "Failed to open %s", argv[1]);
  }

  blkid_do_probe(pr);
  blkid_probe_lookup_value(pr, "UUID", &uuid, nullptr);
  blkid_probe_lookup_value(pr, "LABEL", &label, nullptr);
  blkid_probe_lookup_value(pr, "TYPE", &type, nullptr);

  printf("UUID=%s\n", uuid);
  printf("LABEL=%s\n", label);
  printf("TYPE=%s\n", type);

  blkid_free_probe(pr);

  return 0;
}

 

include 와 -lblkid 경로를 정의하고 컴파일하여 실행하면 아래와 같은 결과가 출력된다.

 

root@imx6qsabresd:~# ./blkidApp /dev/sda1
UUID=D6CA-3F90
LABEL=ESD-USB
TYPE=vfat

 

번호 제목 글쓴이 날짜 조회 수
24 Wayland에 대한 간단한 소개 file makersweb 2017.12.29 3371
23 NFS를 통해 파일시스템 공유 makersweb 2018.03.05 1135
22 Ubuntu Linux에서 dbus-c++바인딩 D-Bus 테스트 file makersweb 2018.03.07 7061
21 tslib 크로스 컴파일과 터치스크린 보정 makersweb 2018.08.02 2179
» libblkid - USB Storage의 정보 가져오기 makersweb 2018.10.18 674
19 리눅스 컴파일러 최신으로 업데이트 linux 2018.12.26 1899
18 PATH에 새로운 경로 추가 makersweb 2019.09.19 399
17 플랫폼 디바이스 드라이버 개발 시 많이 사용되는 커널 API 및 매크로 makersweb 2020.01.28 4718
16 initramfs (initial ram file system: 초기 램 파일 시스템) makersweb 2020.02.25 2060
15 64비트 리눅스에서 32비트 응용프로그램을 실행하려면 makersweb 2020.02.29 1788
14 Weston 의 설명 및 관련 컴포넌트 makersweb 2020.06.03 2494
13 Wayland 의 주요 객체들 makersweb 2020.06.04 908
12 Wayland 의 Client Application 프로그래밍 기본 루틴 makersweb 2020.06.04 1660
11 wayland-scanner 를 통해 Wayland 프로토콜 코드생성 makersweb 2020.06.08 938
10 리눅스 오디오 스택과 아키텍처 file makersweb 2020.09.02 2890
9 dbus-broker를 기본 DBus 구현으로 설정 makersweb 2021.01.20 1202
8 SocketCAN 유틸 사용방법 file makersweb 2022.02.05 7082
7 ifconfig 는 대부분 ip 명령으로 대체 makersweb 2022.02.12 1499
6 D-Bus ObjectManager file makersweb 2022.02.12 639
5 리눅스에서 네트워크 구성 makersweb 2022.06.11 2885