From: Kees Jongenburger Date: Wed, 4 Jul 2012 12:00:28 +0000 (+0000) Subject: Allow to specify the rslabel to use for a file system. X-Git-Tag: v3.2.1~458 X-Git-Url: http://zhaoyanbai.com/repos/COPYRIGHT?a=commitdiff_plain;h=30b5c227e9d7e6dc000903b07913153dccea1e81;p=minix.git Allow to specify the rslabel to use for a file system. When a file system is mounted some heuristics are used to define a RS label for that system. This commit allows to specify the label to use in an optional mount argument using either mount -o rslabel=fs_myfs or as a mount option in fstab. This can be used to start services that later also need to be accessed directly. --- diff --git a/lib/libc/sys-minix/mount.c b/lib/libc/sys-minix/mount.c index 32d237f30..29f8b0b0a 100644 --- a/lib/libc/sys-minix/mount.c +++ b/lib/libc/sys-minix/mount.c @@ -32,6 +32,7 @@ static int rs_down(char *label) return system(cmd); } +char *find_rslabel(char *args_line); int mount(special, name, mountflags, type, args) char *name, *special, *type, *args; int mountflags; @@ -43,6 +44,7 @@ int mountflags; char path[PATH_MAX]; char cmd[200]; char *p; + char *rslabel; int reuse = 0; int use_existing = 0; @@ -80,8 +82,17 @@ int mountflags; } sprintf(label, "fs_%.12s", p); } else { - if (stat(name, &statbuf) < 0) return -1; - sprintf(label, "fs_%04x%llx", statbuf.st_dev, statbuf.st_ino); + /* check for a rslabel option in the arguments and try to use + * that. + */ + rslabel = find_rslabel(args); + if (rslabel != NULL){ + snprintf(label,16,rslabel); + free(rslabel); + } else { + if (stat(name, &statbuf) < 0) return -1; + sprintf(label, "fs_%04x%llx", statbuf.st_dev, statbuf.st_ino); + } } } else { /* label to long? */ @@ -192,3 +203,46 @@ int flags; return r; } + +char *find_rslabel(args_line) +char *args_line; +{ + /** + * Find and return the rslabel as given as optional + * agument to the mount command e.g. + * mount -o rslabel=bla + * or + * mount -o rw,rslabel=bla + * or as found in fstab + **/ + char *buf, *input,*saveptr; + buf = input = saveptr = NULL; + + if (args_line == NULL) return NULL; + + /* copy the input args_line we are going to modify it*/ + input = strndup(args_line,20); + if (input == NULL) /* EOM */ + return NULL; /* it is not that bad to not find a label */ + + /* locate rslabel= in the input */ + buf = strstr(input,"rslabel="); + if (buf == NULL) { + free(input); + return NULL; + } + + /* tokenise on "," starting from rslabel (e.g null terminate )*/ + buf = strtok_r(buf,",",&saveptr); + /* tokenise the result again using = and take the second entry */ + buf = strtok_r(buf,"=",&saveptr); + buf = strtok_r(NULL,"=",&saveptr); + /* buf is now either NULL if there was no second token or + * the value we are searchig for + */ + if (buf != NULL) + buf = strdup(buf); + free(input); + return buf; +} +