|
@@ -136,17 +136,16 @@ static inline int token_len(const char* str, const char** next_str) {
|
|
return t - str;
|
|
return t - str;
|
|
}
|
|
}
|
|
|
|
|
|
-static int proc_match_name(const char* trim_name, const struct proc_ent** ent) {
|
|
|
|
|
|
+static int proc_match_name(const char* trim_name, const struct proc_ent** found_ent) {
|
|
if (!trim_name || !trim_name[0]) {
|
|
if (!trim_name || !trim_name[0]) {
|
|
- *ent = &proc_root_ent;
|
|
|
|
|
|
+ *found_ent = &proc_root_ent;
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- const char* token = trim_name;
|
|
|
|
- const char* next_token;
|
|
|
|
- const struct proc_ent* tmp = proc_root.ent;
|
|
|
|
- const struct proc_ent* end = tmp + proc_root.size;
|
|
|
|
- const struct proc_ent* last = NULL;
|
|
|
|
|
|
+ const char* token = trim_name;
|
|
|
|
+ const char* next_token = NULL;
|
|
|
|
+ const struct proc_dir* dir = &proc_root;
|
|
|
|
+ const struct proc_ent* ent = NULL;
|
|
|
|
|
|
if (*token == '/')
|
|
if (*token == '/')
|
|
token++;
|
|
token++;
|
|
@@ -154,33 +153,34 @@ static int proc_match_name(const char* trim_name, const struct proc_ent** ent) {
|
|
while (token) {
|
|
while (token) {
|
|
int tlen = token_len(token, &next_token);
|
|
int tlen = token_len(token, &next_token);
|
|
|
|
|
|
- for (; tmp < end; tmp++) {
|
|
|
|
- if (tmp->name && !memcmp(tmp->name, token, tlen))
|
|
|
|
- goto found;
|
|
|
|
|
|
+ for (ent = dir->ent; ent < dir->ent + dir->size; ent++) {
|
|
|
|
+ if (ent->name && !memcmp(ent->name, token, tlen))
|
|
|
|
+ break;
|
|
|
|
|
|
- if (tmp->nm_ops && tmp->nm_ops->match_name && tmp->nm_ops->match_name(trim_name))
|
|
|
|
- goto found;
|
|
|
|
|
|
+ if (ent->nm_ops && ent->nm_ops->match_name && ent->nm_ops->match_name(trim_name))
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
- return -ENOENT;
|
|
|
|
|
|
+ if (ent == dir->ent + dir->size) {
|
|
|
|
+ /* couldn't find any entry corresponding to token */
|
|
|
|
+ return -ENOENT;
|
|
|
|
+ }
|
|
|
|
|
|
- found:
|
|
|
|
if (!next_token) {
|
|
if (!next_token) {
|
|
/* found the entry, break out of the while loop */
|
|
/* found the entry, break out of the while loop */
|
|
- last = tmp;
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!tmp->dir)
|
|
|
|
|
|
+ if (!ent->dir) {
|
|
|
|
+ /* still have tokens left, but current entry doesn't have subdirs/files */
|
|
return -ENOENT;
|
|
return -ENOENT;
|
|
|
|
+ }
|
|
|
|
|
|
- last = tmp;
|
|
|
|
- end = tmp->dir->ent + tmp->dir->size;
|
|
|
|
- tmp = tmp->dir->ent;
|
|
|
|
|
|
+ dir = ent->dir;
|
|
token = next_token;
|
|
token = next_token;
|
|
}
|
|
}
|
|
|
|
|
|
- *ent = last;
|
|
|
|
|
|
+ *found_ent = ent;
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -271,8 +271,7 @@ static int proc_readdir(struct shim_dentry* dent, struct shim_dirent** dirent) {
|
|
if (!ent->dir)
|
|
if (!ent->dir)
|
|
return -ENOTDIR;
|
|
return -ENOTDIR;
|
|
|
|
|
|
- const struct proc_ent* tmp = ent->dir->ent;
|
|
|
|
- const struct proc_ent* end = tmp + ent->dir->size;
|
|
|
|
|
|
+ const struct proc_dir* dir = ent->dir;
|
|
|
|
|
|
HASHTYPE self_hash = hash_path(rel_path, dent->rel_path.len);
|
|
HASHTYPE self_hash = hash_path(rel_path, dent->rel_path.len);
|
|
HASHTYPE new_hash;
|
|
HASHTYPE new_hash;
|
|
@@ -285,7 +284,7 @@ retry:
|
|
*dirent = ptr = buf;
|
|
*dirent = ptr = buf;
|
|
struct shim_dirent** last = dirent;
|
|
struct shim_dirent** last = dirent;
|
|
|
|
|
|
- for (; tmp < end; tmp++) {
|
|
|
|
|
|
+ for (const struct proc_ent* tmp = dir->ent; tmp < dir->ent + dir->size; tmp++) {
|
|
if (tmp->name) {
|
|
if (tmp->name) {
|
|
int name_len = strlen(tmp->name);
|
|
int name_len = strlen(tmp->name);
|
|
|
|
|