static unsigned long ubifs_findfile(struct super_block *sb, char *filename) { int ret; char *next; char fpath[128]; char *name = fpath; unsigned long root_inum = 1; unsigned long inum; strcpy(fpath, filename); /* Remove all leading slashes */ while (*name == '/') name++; /* * Handle root-direcoty ('/') */ inum = root_inum; if (!name || *name == '\0') return inum; for (;;) { /* Extract the actual part from the pathname. */ next = strchr(name, '/'); if (next) { /* Remove all leading slashes. */ while (*next == '/') *(next++) = '\0'; } ret = ubifs_finddir(sb, name, root_inum, &inum); /* * Check if directory with this name exists */ /* Found the node! */ if (!next || *next == '\0') { if (ret) return inum; break; } root_inum = inum; name = next; } return 0; }
static unsigned long ubifs_findfile(struct super_block *sb, char *filename) { int ret; char *next; char fpath[128]; char symlinkpath[128]; char *name = fpath; unsigned long root_inum = 1; unsigned long inum; int symlink_count = 0; /* Don't allow symlink recursion */ char link_name[64]; strcpy(fpath, filename); /* Remove all leading slashes */ while (*name == '/') name++; /* * Handle root-direcoty ('/') */ inum = root_inum; if (!name || *name == '\0') return inum; for (;;) { struct inode *inode; struct ubifs_inode *ui; /* Extract the actual part from the pathname. */ next = strchr(name, '/'); if (next) { /* Remove all leading slashes. */ while (*next == '/') *(next++) = '\0'; } ret = ubifs_finddir(sb, name, root_inum, &inum); if (!ret) return 0; inode = ubifs_iget(sb, inum); if (!inode) return 0; ui = ubifs_inode(inode); if ((inode->i_mode & S_IFMT) == S_IFLNK) { char buf[128]; /* We have some sort of symlink recursion, bail out */ if (symlink_count++ > 8) { printf("Symlink recursion, aborting\n"); return 0; } memcpy(link_name, ui->data, ui->data_len); link_name[ui->data_len] = '\0'; if (link_name[0] == '/') { /* Absolute path, redo everything without * the leading slash */ next = name = link_name + 1; root_inum = 1; continue; } /* Relative to cur dir */ sprintf(buf, "%s/%s", link_name, next == NULL ? "" : next); memcpy(symlinkpath, buf, sizeof(buf)); next = name = symlinkpath; continue; } /* * Check if directory with this name exists */ /* Found the node! */ if (!next || *next == '\0') return inum; root_inum = inum; name = next; } return 0; }