getfsent函数用法详解
getfsent函数简介
- 头文件包含
#include <fstab.h>
- 函数定义
void endfsent(void);
struct fstab *getfsent(void);
struct fstab *getfsfile(const char * mount_point );
struct fstab *getfsspec(const char * special_file );
int setfsent(void);
getfsent函数常见使用错误
- 编译错误
warning: implicit declaration of function ‘getfsent’ [-Wimplicit-function-declaration]
解决办法:包含头文件
#include <fstab.h>
getfsent函数详细描述
这些函数从文件/etc/fstab 中读取"struct fstab"的定义如下:
struct fstab {
char *fs_spec; /* block device name */
char *fs_file; /* mount point */
char *fs_vfstype; /* file-system type */
char *fs_mntops; /* mount options */
const char *fs_type; /* rw/rq/ro/sw/xx option */
int fs_freq; /* dump frequency, in days */
int fs_passno; /* pass number on parallel dump */
};
这里,字段fs_type包含(在*BSD系统上)五个字符串“rw”、“rq”、“ro”、“sw”、“xx”(读写、带配额的读写、只读、交换、忽略)中的一个。
函数setfsent ()在需要时打开文件,并将其放在第一行。
函数getfsent ()解析文件的下一行。(需要时打开后。)
函数endfsent ()在需要时关闭文件。
函数getfsspec ()从头开始搜索文件,并返回找到的fs_spec字段与special_file参数匹配的第一个条目。
函数getfsfile ()从头开始搜索文件,并返回找到的fs_file字段与mount_point参数匹配的第一个条目。
getfsent函数返回值
成功后,函数getfsent ()、getfsfile ()和getfsspec ()返回指向"struct fstab" 的指针,而setfsent ()返回1。在失败或文件结束时,这些函数分别返回NULL和0。
getfsent函数其他说明
这些函数不是线程安全的。
由于Linux允许在几个地方挂载一个块专用设备,并且由于几个设备可以有相同的挂载点,其中具有给定挂载点的最后一个设备是有趣的设备,而getfsfile ()和getfsspec ()只返回第一个出现的设备,所以这两个函数不适合在Linux下使用。
评论区