Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 使用mount()重新安装文件系统,而不知道文件系统类型或源设备_C_Linux_Filesystems_Mount - Fatal编程技术网

C 使用mount()重新安装文件系统,而不知道文件系统类型或源设备

C 使用mount()重新安装文件系统,而不知道文件系统类型或源设备,c,linux,filesystems,mount,C,Linux,Filesystems,Mount,我需要在Linux上运行C时以只读方式重新安装/。到目前为止,我已经找到了以下代码: mount("/dev/sda1", "/", "ext4", MS_REMOUNT | MS_RDONLY, NULL); 但是我想知道是否有一种方法可以在不指定源设备(/dev/sda1)或文件系统类型(ext4)的情况下实现这一点,比如命令mount-oremount,ro/。系统调用的这些部分是否可以简单地替换为NULL?使用: 名称 getmntent,setmntent,addmntent,end

我需要在Linux上运行C时以只读方式重新安装
/
。到目前为止,我已经找到了以下代码:

mount("/dev/sda1", "/", "ext4", MS_REMOUNT | MS_RDONLY, NULL);

但是我想知道是否有一种方法可以在不指定源设备(/dev/sda1)或文件系统类型(ext4)的情况下实现这一点,比如命令
mount-oremount,ro/
。系统调用的这些部分是否可以简单地替换为
NULL

使用:

名称

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 extension */
   #include <mntent.h>

   struct mntent *getmntent_r(FILE *streamp, struct mntent *mntbuf,
                              char *buf, int buflen);
#包括
#包括
文件*设置内容(常量字符*文件名,常量字符*类型);
结构mntent*getmntent(文件*流);
int addmntent(文件*stream,常量结构mntent*mnt);
int ENDMENT(文件*streamp);
char*hasmntopt(常量结构mntent*mnt,常量char*opt);
/*GNU扩展*/
#包括
结构mntent*getmntent_r(文件*streamp,结构mntent*mntbuf,
char*buf,int buflen);

找到安装在
/
上的文件系统,并从返回的
结构mntent获取其设备。

在测试系统上运行
strace mount-o remount,ro/
,查看它如何调用
mount
。它可能通过statvfs()信息计算设备和文件系统类型,通过/proc等进行挖掘。
mount-o remount,ro/
查找文件系统信息,如@AndrewHenle所述。