조회 수 2976 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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

 


List of Articles
번호 제목 글쓴이 날짜 조회 수
» libblkid - USB Storage의 정보 가져오기 makersweb 2018.10.18 2976
24 tslib 크로스 컴파일과 터치스크린 보정 makersweb 2018.08.02 4861
23 Ubuntu Linux에서 dbus-c++바인딩 D-Bus 테스트 file makersweb 2018.03.07 10214
22 NFS를 통해 파일시스템 공유 makersweb 2018.03.05 3172
21 Wayland에 대한 간단한 소개 file makersweb 2017.12.29 5957
20 Ubuntu16.04에서 weston구동 file makersweb 2017.12.28 3866
19 UVC 장치를 사용할때 v4l2: select timeout 에러 발생 makersweb 2017.12.27 5217
18 [IPC]D-Bus 소개 file makersweb 2015.02.28 32523
17 리눅스 데스크탑 환경 종류 pjk 2015.02.11 7008
16 디바이스 드라이버에 대해서 makersweb 2014.04.19 7103
15 리눅스 커널 소스코드 구성도 file makersweb 2014.03.04 8198
14 read() 함수, write() 함수 makersweb 2014.03.04 14432
13 리눅스 디렉터리 구조 makersweb 2014.02.28 5405
12 1. make pjk 2014.02.05 4393
11 2. 간단한 Makefile pjk 2014.02.05 5191
10 3. 매크로(Macro) 와 확장자(Suffix) 규칙 pjk 2014.02.05 4820
9 4. Makefile를 작성할 때 알면 좋은 것들 pjk 2014.02.05 6267
8 5. make 중요 옵션 정리 pjk 2014.02.05 5166
7 6. Makefile 작성의 가이드라인 pjk 2014.02.05 4292
6 mmap() 함수, munmap() 함수 pjk 2014.02.05 18927
Board Pagination Prev 1 2 3 Next
/ 3