Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

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

書式

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

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

       struct mntent *getmntent(FILE *stream);

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

       int endmntent(FILE *streamp);

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

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

       struct mntent *getmntent_r(FILE *streamp, struct mntent *mntbuf,
                                  char *buf, int buflen);

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

       リエントラントな関数  getmntent_r()   は  getmntent()   と同じだが、 ユーザーが用意した *mntbufstruct
       mount を格納し、その構造体の各エントリーが指し示す文字列を ユーザーが用意した大きさ buflen の配列 buf  に
       書き込む。

       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(),     │ Thread safety │ MT-Safe                         │
       │endmntent(),     │               │                                 │
       │hasmntopt()      │               │                                 │
       ├─────────────────┼───────────────┼─────────────────────────────────┤
       │getmntent()      │ Thread safety │ MT-Unsafe race:mntentbuf locale │
       ├─────────────────┼───────────────┼─────────────────────────────────┤
       │addmntent()      │ Thread safety │ MT-Safe race:stream locale      │
       ├─────────────────┼───────────────┼─────────────────────────────────┤
       │getmntent_r()    │ Thread safety │ MT-Safe locale                  │
       └─────────────────┴───────────────┴─────────────────────────────────┘

準拠

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

注意

       System V にも getmntent()  関数はあるが、 呼び出し手順が異なり、返される構造体も異なる。  System  V  では
       /etc/mnttab   が用いられる。   4.4BSD  と  Digital  UNIX  には  getmntinfo()   があるが、  システムコール
       getfsstat()  のラッパー関数である。

関連項目

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

この文書について

       この man ページは Linux man-pages プロジェクトのリリース 5.10  の一部である。プロジェクトの説明とバグ報告
       に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

                                                   2019-03-06                                       GETMNTENT(3)