summaryrefslogtreecommitdiff
path: root/fs/udf/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/namei.c')
-rw-r--r--fs/udf/namei.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 78bc4bbb7c54..145883d15c0f 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -141,6 +141,73 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
}
/**
+ * udf_fiiter_find_entry - find entry in given directory.
+ *
+ * @dir: directory inode to search in
+ * @child: qstr of the name
+ * @iter: iter to use for searching
+ *
+ * This function searches in the directory @dir for a file name @child. When
+ * found, @iter points to the position in the directory with given entry.
+ *
+ * Returns 0 on success, < 0 on error (including -ENOENT).
+ */
+static int udf_fiiter_find_entry(struct inode *dir, const struct qstr *child,
+ struct udf_fileident_iter *iter)
+{
+ int flen;
+ unsigned char *fname = NULL;
+ struct super_block *sb = dir->i_sb;
+ int isdotdot = child->len == 2 &&
+ child->name[0] == '.' && child->name[1] == '.';
+ int ret;
+
+ fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
+ if (!fname)
+ return -ENOMEM;
+
+ for (ret = udf_fiiter_init(iter, dir, 0);
+ !ret && iter->pos < dir->i_size;
+ ret = udf_fiiter_advance(iter)) {
+ if (iter->fi.fileCharacteristics & FID_FILE_CHAR_DELETED) {
+ if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
+ continue;
+ }
+
+ if (iter->fi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) {
+ if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
+ continue;
+ }
+
+ if ((iter->fi.fileCharacteristics & FID_FILE_CHAR_PARENT) &&
+ isdotdot)
+ goto out_ok;
+
+ if (!iter->fi.lengthFileIdent)
+ continue;
+
+ flen = udf_get_filename(sb, iter->name,
+ iter->fi.lengthFileIdent, fname, UDF_NAME_LEN);
+ if (flen < 0) {
+ ret = flen;
+ goto out_err;
+ }
+
+ if (udf_match(flen, fname, child->len, child->name))
+ goto out_ok;
+ }
+ if (!ret)
+ ret = -ENOENT;
+
+out_err:
+ udf_fiiter_release(iter);
+out_ok:
+ kfree(fname);
+
+ return ret;
+}
+
+/**
* udf_find_entry - find entry in given directory.
*
* @dir: directory inode to search in