한국어
Linux Programming
 

libblkid - USB Storage의 정보 가져오기

makersweb 2018.10.18 16:19 조회 수 : 646

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

 

번호 제목 글쓴이 날짜 조회 수
44 리눅스 Qt 응용프로그램 AppImage 로 구축 makersweb 2024.01.07 356
43 GRUB의 timeout 설정 makersweb 2023.11.07 340
42 lubuntu 22.04 LTS 설치 file makersweb 2023.01.23 1113
41 시스템에서 사용 가능한 D-Bus 서비스를 보려면? makersweb 2022.12.29 998
40 리눅스에서 네트워크 구성 makersweb 2022.06.11 2725
39 D-Bus ObjectManager file makersweb 2022.02.12 512
38 ifconfig 는 대부분 ip 명령으로 대체 makersweb 2022.02.12 1116
37 SocketCAN 유틸 사용방법 file makersweb 2022.02.05 6461
36 dbus-broker를 기본 DBus 구현으로 설정 makersweb 2021.01.20 965
35 리눅스 오디오 스택과 아키텍처 file makersweb 2020.09.02 2749
34 wayland-scanner 를 통해 Wayland 프로토콜 코드생성 makersweb 2020.06.08 819
33 Wayland 의 Client Application 프로그래밍 기본 루틴 makersweb 2020.06.04 1509
32 Wayland 의 주요 객체들 makersweb 2020.06.04 782
31 Weston 의 설명 및 관련 컴포넌트 makersweb 2020.06.03 2343
30 64비트 리눅스에서 32비트 응용프로그램을 실행하려면 makersweb 2020.02.29 1671
29 initramfs (initial ram file system: 초기 램 파일 시스템) makersweb 2020.02.25 1785
28 플랫폼 디바이스 드라이버 개발 시 많이 사용되는 커널 API 및 매크로 makersweb 2020.01.28 4566
27 PATH에 새로운 경로 추가 makersweb 2019.09.19 376
26 리눅스 컴파일러 최신으로 업데이트 linux 2018.12.26 1874
» libblkid - USB Storage의 정보 가져오기 makersweb 2018.10.18 646