mirror of
https://github.com/KarnerF/SMPlusGui.git
synced 2026-10-06 08:00:19 +02:00
USB detection via getmntinfo kernel mount table
This commit is contained in:
1 parent
864735027d
commit
b29f2b3357
1 file changed
+6
-6
@@ -12,6 +12,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/mount.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
@@ -2248,12 +2249,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
}
|
||||
else if(mg_match(hm->uri,mg_str("/api/config/usb-status"),NULL)){
|
||||
char usb[32]={0}; int found=0;
|
||||
struct stat mnt_st; stat("/mnt",&mnt_st);
|
||||
for(int i=0;i<=7&&!found;i++){
|
||||
char p[24]; snprintf(p,sizeof(p),"/mnt/usb%d",i);
|
||||
struct stat st;
|
||||
/* real mount: st_dev differs from parent /mnt */
|
||||
if(stat(p,&st)==0&&st.st_dev!=mnt_st.st_dev){strncpy(usb,p,31);found=1;}
|
||||
struct statfs *mntbuf; int n=getmntinfo(&mntbuf,MNT_NOWAIT);
|
||||
for(int i=0;i<n&&!found;i++){
|
||||
if(strncmp(mntbuf[i].f_mntonname,"/mnt/usb",8)==0){
|
||||
strncpy(usb,mntbuf[i].f_mntonname,31);found=1;
|
||||
}
|
||||
}
|
||||
mg_http_reply(c,200,"Content-Type: application/json\r\n",
|
||||
"{\"present\":%s,\"path\":\"%s\"}",found?"true":"false",found?usb:"");
|
||||
|
||||
Reference in new issue
Block a user