Skip to content

Instantly share code, notes, and snippets.

@Bot-wxt1221
Last active February 5, 2024 07:12
Show Gist options
  • Save Bot-wxt1221/ed834d4f0a1c6b5ec85a28cc106cb94f to your computer and use it in GitHub Desktop.
Save Bot-wxt1221/ed834d4f0a1c6b5ec85a28cc106cb94f to your computer and use it in GitHub Desktop.
example
#include <sys/syscall.h>
#include <linux/mount.h>
#include <sys/types.h>
#include <linux/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
typedef unsigned long long u64;
u64 buf[100005];
long statmount(const struct mnt_id_req *req,struct statmount *buf, size_t bufsize,unsigned int flags){
return syscall(__NR_statmount,req,buf,bufsize,flags);
}
long listmount(const struct mnt_id_req *req,u64 *mnt_ids, size_t nr_mnt_ids,unsigned int flags){
return syscall(__NR_listmount,req,mnt_ids,nr_mnt_ids,flags);
}
unsigned char buf3[100005];
int main(){
struct statx statxbuf={0};
unsigned long long rootmntid=statxbuf.stx_mnt_id;
struct mnt_id_req req={0};
req.size=sizeof(struct mnt_id_req);
int ret=statx(0,"/",0,STATX_MNT_ID_UNIQUE,&statxbuf);
if(ret<0){
printf("statx error:%d",ret);
return -1;
}
rootmntid=statxbuf.stx_mnt_id;
req.param=0;
req.mnt_id=rootmntid;
ret=listmount(&req,buf,sizeof(buf)/sizeof(u64),0);
if(ret<=0){
printf("listmount error:%d",ret);
return -2;
}
int n=ret;
struct statmount *buf2=buf3;
for(int i=0;i<n;i++){
req.mnt_id=buf[i];
req.param=STATMOUNT_MNT_ROOT|STATMOUNT_MNT_POINT|STATMOUNT_FS_TYPE|STATMOUNT_MNT_BASIC;
ret=statmount(&req,buf2,sizeof(buf),0);
if(ret<0){
printf("statmount error :%d",ret);
return -3;
}
printf("mnt_root:%s mnt_point:%s fs_type:%s mnt_parent_id:%lld\n",buf2->str+buf2->mnt_root,buf2->str+buf2->mnt_point,buf2->str+buf2->fs_type,buf2->mnt_parent_id);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment