]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/f2fs/dir.c
Merge tag 'kgdb-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux
[linux.git] / fs / f2fs / dir.c
index d9ad842945df5dac94c64b46975800791fcad7bf..27d0dd7a16d6dbbbb59e33f8fd7a032a470b0ba0 100644 (file)
@@ -578,6 +578,20 @@ int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots)
        goto next;
 }
 
+bool f2fs_has_enough_room(struct inode *dir, struct page *ipage,
+                                       struct fscrypt_name *fname)
+{
+       struct f2fs_dentry_ptr d;
+       unsigned int bit_pos;
+       int slots = GET_DENTRY_SLOTS(fname_len(fname));
+
+       make_dentry_ptr_inline(dir, &d, inline_data_addr(dir, ipage));
+
+       bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
+
+       return bit_pos < d.max;
+}
+
 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
                                const struct qstr *name, f2fs_hash_t name_hash,
                                unsigned int bit_pos)
@@ -1069,24 +1083,27 @@ static int f2fs_d_compare(const struct dentry *dentry, unsigned int len,
                          const char *str, const struct qstr *name)
 {
        struct qstr qstr = {.name = str, .len = len };
+       const struct dentry *parent = READ_ONCE(dentry->d_parent);
+       const struct inode *inode = READ_ONCE(parent->d_inode);
 
-       if (!IS_CASEFOLDED(dentry->d_parent->d_inode)) {
+       if (!inode || !IS_CASEFOLDED(inode)) {
                if (len != name->len)
                        return -1;
-               return memcmp(str, name, len);
+               return memcmp(str, name->name, len);
        }
 
-       return f2fs_ci_compare(dentry->d_parent->d_inode, name, &qstr, false);
+       return f2fs_ci_compare(inode, name, &qstr, false);
 }
 
 static int f2fs_d_hash(const struct dentry *dentry, struct qstr *str)
 {
        struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
        const struct unicode_map *um = sbi->s_encoding;
+       const struct inode *inode = READ_ONCE(dentry->d_inode);
        unsigned char *norm;
        int len, ret = 0;
 
-       if (!IS_CASEFOLDED(dentry->d_inode))
+       if (!inode || !IS_CASEFOLDED(inode))
                return 0;
 
        norm = f2fs_kmalloc(sbi, PATH_MAX, GFP_ATOMIC);