기본 콘텐츠로 건너뛰기

마운트 정보 읽어오기

Linux에서 마운트 정보를 읽어보자. getmntent()가 바로 그것이다. 아쉽게도 POSIX, ANSI, IEEE 표준이 아니며, 리눅스SunOS, HP-UX 등에서 사용할 수 있으며, FreeBSD에서는 getmntinfo()로부터 알아낼 수 있다. 이 함수는 내부 버퍼를 사용하기 때문에 쓰레드에 안전하지 않으며, getmntent_r()으로 쓰레드에 대응할 수 있다.

자, 먼저 getmntent()를 하기 앞서, 마운트 정보를 읽고 쓸 수 있도록 핸들을 얻어와야하는데 그것을 하는 것이 setmntent()이고, 다 쓴 핸들을 닫을 때 쓰는 것이 endmntent()이다. 만약 중간에 마운트 정보를 바꿨으면, endmntent()할 때 비로소 적용된다. 자세한 것은 man페이지를 참조하고, 간단하게 C++로 마운트 목록을 보여주는 프로그램을 짜보았다.
#include <iostream>
#include <list>
#include <string>
#include <cstdio>
#include <errno.h>
using namespace std;
#include <mntent.h>

typedef struct me_type
{
    string fsname;
    string dir;
    string type;
    string opts;
    int freq;
    int passno;
} me_type;

typedef list<me_type> me_list;

bool
getMountList(me_list& ml)
{
    ml.clear();
    struct mntent* mnt;
    const char* table = "/etc/mtab"; // 부팅할 때 정보를 읽으려면 /etc/fstab로 수정한다.
    FILE* fp;

    fp = setmntent(table, "r");
    if ( !fp )
    {
        return false;
    }

    me_type me;

    while ( (mnt=getmntent(fp) ) )
    {
        me.fsname = mnt->mnt_fsname;
        me.dir = mnt->mnt_dir;
        me.type = mnt->mnt_type;
        me.opts = mnt->mnt_opts;
        me.freq = mnt->mnt_freq;
        me.passno = mnt->mnt_passno;
        ml.push_back(me);
    }// while

    endmntent(fp);

    return true;
}

int
main(int argc, char* argv[])
{
    me_list mel;
    if ( !getMountList(mel) )
    {
        cout << strerror(errno) << endl;
    }

    me_list::const_iterator ib(mel.begin());
    me_list::const_iterator ie(mel.end());

    while ( ib != ie )
    {
        cout << "ib->fsname: " << ib->fsname << endl;
        cout << "ib->dir: " << ib->dir << endl;
        cout << "ib->opts: " << ib->opts << endl;
        cout << "ib->freq: " << ib->freq << endl;
        cout << "ib->passno: " << ib->passno << endl;
        ++ ib;
    }

    return 0;
}

댓글

이 블로그의 인기 게시물

버즈 라이브 배터리 교체

나는 버즈 라이브(SM-R180)가 좋은데, 평가가 별루였는지, 해당 스타일로 버즈를 더 이상 만들지 않고 있다. 아무튼, 오래 쓴 버즈 라이브 배터리가 슬슬 맛이 가기 시작해서, 블로그 를 참조하면서 분해 및 교체를 하였다. (진짜 쉬움) 요로코롬 위아래를 살짝 눌러주면 뚜껑이 벌어진다. 안쪽 플라스틱은 오른쪽은 분홍색, 왼쪽은 회색이다. 리본 케이블 살짝 들어내고, 기판을 떼어내면, 작은 나사가 있다. 나사를 풀고, 플라스틱을 걷어내면, 검은 양면 테이프로 고정된 CR1254 배터리가 보인다. 잘 쑤셔서(?) 꺼낸다. 새로운 CR1254 배터리를 넣는다. 음극이 아래로 가도록 하고, 분해의 역순으로 조립하면 된다. 조립할 때, 아까 풀었던 나사는 잊지 말고 꼭 조여준다. (까먹고 조립해서 다시 뜯고 조립함) 충전도 잘 되고, 소리도 잘 나는거 보면, 조립도 잘 된 것 같다. 이렇게 버즈 라이브의 수명을 강제로 늘렸다. 나중에 본체 배터리도 갈아야겠다.

Windows 에서 절전을 깨우는 장치 찾기

참조:  https://www.reddit.com/r/computer/comments/wquswv/windows_11_pc_wakes_up_every_time_i_move_usb/ powercfg /devicequery wake_armed powercfg /deviceenablewake "[DEVICE]" # $PROFILE function Get-WakeArmedDevices { $devices = powercfg -devicequery wake_armed if ($devices) { $devices | ForEach-Object { $_.Trim() } } else { Write-Host "No devices are currently armed for wake events." } } function Set-EnableWakeOnDevice { param( [string]$deviceName ) sudo powercfg -deviceenablewake $deviceName } function Set-DisableWakeOnDevice { param( [string]$deviceName ) sudo powercfg -devicedisablewake $deviceName }