AnsweredAssumed Answered

how to umount a usb disk by native application

Question asked by thony Du on Nov 8, 2014

I usb i.mx6 board with android 4.2.2. it's usb disk auto mount to /mnt/udisk dir. I find a a trick question,  

this is code in native app

int main(void)

{

  int a = 0;

  FILE * fd = fopen("/data/test/out.txt", "a+");

  fprintf(fd,  "uid = %d, gid = %d, euid = %d, egid = %d\n", getuid(), getgid(), geteuid(), getegid());

  a = umount("/mnt/udisk");

  if(a != 0)

  fprintf(fd,"%s\n",strerror(errno));

  fprintf(fd,"umount = %d\n", a);

  fclose(fd);

  //sleep(60);

  return 0;

}

 

this is the java app

ProcessBuilder process = new ProcessBuilder("su", "-c", "/data/test/testumount");

              Process p = process.start();

              p.waitFor();

 

I got a out.txt from native app.

uid = 0, gid = 0, euid = 0, egid = 0

umount = 0

 

You see the umount return 0, but /mnt/udisk not umount. So , why? the native app's uid = 0, it is root.

Outcomes