getmntent

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

getmntent, setmntent, addmntent, endmntent, hasmntopt, getmntent_r - ファイルシステム記述ファイルのエントリーを取得する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <stdio.h>
#include <mntent.h>

FILE *setmntent(const char *path, const char *type);

struct mntent *getmntent(FILE *stream);

int addmntent(FILE *restrict stream,
              const struct mntent *restrict mnt);

int endmntent(FILE *streamp);

char *hasmntopt(const struct mntent *mnt, const char *opt);

/* GNU による拡張 */
#include <mntent.h>

struct mntent *getmntent_r(int size;
              FILE *restrict streamp,
              struct mntent *restrict mntbuf,
              char buf[restrict size], int size);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

getmntent_r():

    Since glibc 2.19:
        _DEFAULT_SOURCE
    glibc 2.19 and earlier:
        _BSD_SOURCE || _SVID_SOURCE
 

説明

これらのルーチンは、ファイルシステムを記述したファイル /etc/fstab と、マウントされているファイルシステムを記述したファイル /etc/mtab にアクセスするために用いられる。

The setmntent() function opens the filesystem description file path and returns a file pointer which can be used by getmntent(). The argument type is the type of access required and can take the same values as the mode argument of fopen(3). The returned stream should be closed using endmntent() rather than fclose(3).

getmntent() 関数は stream からファイルシステムの記述ファイルの次の行を読み込み、 読み込んだ行をフィールドに分割した内容を収めた構造体へのポインターを返す。 ポインターはメモリーの静的な領域を指しており、この領域は getmntent() を次に呼び出したときに上書きされてしまう。

addmntent() 関数は mntent 構造体 mnt の内容を、オープンされている stream の最後に追加する。

endmntent() 関数はファイルシステムの記述ファイルに関連付けられている stream を閉じる。

hasmntopt() 関数は mntent 構造体 mnt の mnt_opts フィールド (下記 参照) をスキャンし、 opt に一致する部分文字列があるかを調べる。 有効なマウントオプションについては <mntent.h> と mount(8) を参照のこと。

The reentrant getmntent_r() function is similar to getmntent(), but stores the mntent structure in the provided *mntbuf, and stores the strings pointed to by the entries in that structure in the provided array buf of size size.

mntent 構造体は <mntent.h> で以下のように定義されている。

struct mntent {
    char *mnt_fsname;   /* name of mounted file system */
    char *mnt_dir;      /* file system path prefix */
    char *mnt_type;     /* mount type (see mntent.h) */
    char *mnt_opts;     /* mount options (see mntent.h) */
    int   mnt_freq;     /* dump frequency in days */
    int   mnt_passno;   /* pass number on parallel fsck */
};

Since fields in the mtab and fstab files are separated by whitespace, octal escapes are used to represent the characters space (\040), tab (\011), newline (\012), and backslash (\\) in those files when they occur in one of the four strings in a mntent structure. The routines addmntent() and getmntent() will convert from string representation to escaped representation and back. When converting from escaped representation, the sequence \134 is also converted to a backslash.  

返り値

getmntent() と getmntent_r() は mntent 構造体へのポインターを返す。 失敗した場合は NULL を返す。

addmntent() 関数は成功したら 0 を返し、失敗したら 1 を返す。

endmntent() 関数はつねに 1 を返す。

hasmntopt() 関数は、マッチした場合は部分文字列へのアドレスを返し、 マッチしなければ NULL を返す。  

ファイル

/etc/fstab
filesystem description file
/etc/mtab
mounted filesystem description file
 

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
setmntent(), endmntent(), hasmntopt() Thread safetyMT-Safe
getmntent() Thread safety MT-Unsafe race:mntentbuf locale
addmntent() Thread safety MT-Safe race:stream locale
getmntent_r() Thread safetyMT-Safe locale
 

標準規格

なし。  

歴史

リエントラントでない関数は SunOS 4.1.3 由来のものである。 getmntent_r() 関数は HPUX 10 で導入されたが、このバージョンでは int を返す。 上記に示したプロトタイプは glibc 独自のものである。

System V also has a getmntent() function but the calling sequence differs, and the returned structure is different. Under System V /etc/mnttab is used. 4.4BSD and Digital UNIX have a routine getmntinfo(), a wrapper around the system call getfsstat().  

関連項目

fopen(3), fstab(5), mount(8)


 

Index

名前
ライブラリ
書式
説明
返り値
ファイル
属性
標準規格
歴史
関連項目

This document was created by man2html, using the manual pages.