remount issue on android 7.0

http://blog.chinaunix.net/uid-23141914-id-5754416.html

最近在新版本的android 7.0上,发现filesystem的remount老是报“ Device or resource busy”的错误。
最终发现,android 7.0上,从原来的toolbox切换到toybox。

  1. :/ $ ls -al /system/bin/mount
  2. lrwxr-xr-x 1 root shell 6 2016-09-02 16:23 /system/bin/mount -> toybox

然后仔细查看了一下toybox中关于mount的相关代码,果然是一个坑。

  1. // For remount we need _last_ match (in case of overmounts), so traverse
  2.   // in reverse order. (Yes I'm using remount as a boolean for a bit here,
  3.   // the double cast is to get gcc to shut up about it.)
  4.   remount = (void *)(long)comma_scan(opts, "remount", 1);
  5.   if (((toys.optflags & FLAG_a) && !access("/proc/mounts", R_OK)) || remount) {
  6.     mm = dlist_terminate(mtl = mtl2 = xgetmountlist(0));
  7.     if (remount) remount = mm;
  8.   }

关键就是这个comma_scan的最后一个参数clean

  1. // check all instances of opt and "no"opt in optlist, return true if opt
  2. // found and last instance wasn't no. If clean, remove each instance from list.
  3. int comma_scan(char *optlist, char *opt, int clean)
  4. {
  5.   int optlen = strlen(opt), len, no, got = 0;
  6.     
  7.   if (optlist) for (;;) {
  8.     char *s = comma_iterate(&optlist, &len);
  9.   
  10.     if (!s) break;
  11.     no = 2*(*s == 'n' && s[1] == 'o');
  12.     if (optlen == len-no && !strncmp(opt, s+no, optlen)) {
  13.       got = !no;
  14.       if (clean && optlist) memmove(s, optlist, strlen(optlist)+1);
  15.     }
  16.   }
  17.       
  18.   return got;
  19. }

如果remount不是-o的最后一个参数(_last_ match ),那么就会被清除掉。最终调用syscall mount的时候,这个remount的flag就没了。
把命令重新改为 mount -t vfat -o rw,remount /firmware 就好了。
关于remount的说明在help里面根本没有,真是坑!

posted @ 2017-10-11 18:04  mydddfly  阅读(379)  评论(0编辑  收藏  举报