1 /* * This file is part of UBIFS.
3 * Copyright (C) 2006-2008 Nokia Corporation.
4 * Copyright (C) 2006, 2007 University of Szeged, Hungary
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Artem Bityutskiy (Битюцкий Артём)
25 * This file implements directory operations.
27 * All FS operations in this file allocate budget before writing anything to the
28 * media. If they fail to allocate it, the error is returned. The only
29 * exceptions are 'ubifs_unlink()' and 'ubifs_rmdir()' which keep working even
30 * if they unable to allocate the budget, because deletion %-ENOSPC failure is
31 * not what users are usually ready to get. UBIFS budgeting subsystem has some
32 * space reserved for these purposes.
34 * All operations in this file write all inodes which they change straight
35 * away, instead of marking them dirty. For example, 'ubifs_link()' changes
36 * @i_size of the parent inode and writes the parent inode together with the
37 * target inode. This was done to simplify file-system recovery which would
38 * otherwise be very difficult to do. The only exception is rename which marks
39 * the re-named inode dirty (because its @i_ctime is updated) but does not
40 * write it, but just marks it as dirty.
46 * inherit_flags - inherit flags of the parent inode.
48 * @mode: new inode mode flags
50 * This is a helper function for 'ubifs_new_inode()' which inherits flag of the
51 * parent directory inode @dir. UBIFS inodes inherit the following flags:
52 * o %UBIFS_COMPR_FL, which is useful to switch compression on/of on
53 * sub-directory basis;
54 * o %UBIFS_SYNC_FL - useful for the same reasons;
55 * o %UBIFS_DIRSYNC_FL - similar, but relevant only to directories.
57 * This function returns the inherited flags.
59 static int inherit_flags(const struct inode *dir, umode_t mode)
62 const struct ubifs_inode *ui = ubifs_inode(dir);
64 if (!S_ISDIR(dir->i_mode))
66 * The parent is not a directory, which means that an extended
67 * attribute inode is being created. No flags.
71 flags = ui->flags & (UBIFS_COMPR_FL | UBIFS_SYNC_FL | UBIFS_DIRSYNC_FL);
73 /* The "DIRSYNC" flag only applies to directories */
74 flags &= ~UBIFS_DIRSYNC_FL;
79 * ubifs_new_inode - allocate new UBIFS inode object.
80 * @c: UBIFS file-system description object
81 * @dir: parent directory inode
82 * @mode: inode mode flags
84 * This function finds an unused inode number, allocates new inode and
85 * initializes it. Returns new inode in case of success and an error code in
88 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
93 struct ubifs_inode *ui;
94 bool encrypted = false;
96 if (ubifs_crypt_is_encrypted(dir)) {
97 err = fscrypt_get_encryption_info(dir);
99 ubifs_err(c, "fscrypt_get_encryption_info failed: %i", err);
103 if (!fscrypt_has_encryption_key(dir))
104 return ERR_PTR(-EPERM);
109 inode = new_inode(c->vfs_sb);
110 ui = ubifs_inode(inode);
112 return ERR_PTR(-ENOMEM);
115 * Set 'S_NOCMTIME' to prevent VFS form updating [mc]time of inodes and
116 * marking them dirty in file write path (see 'file_update_time()').
117 * UBIFS has to fully control "clean <-> dirty" transitions of inodes
118 * to make budgeting work.
120 inode->i_flags |= S_NOCMTIME;
122 inode_init_owner(inode, dir, mode);
123 inode->i_mtime = inode->i_atime = inode->i_ctime =
125 inode->i_mapping->nrpages = 0;
127 switch (mode & S_IFMT) {
129 inode->i_mapping->a_ops = &ubifs_file_address_operations;
130 inode->i_op = &ubifs_file_inode_operations;
131 inode->i_fop = &ubifs_file_operations;
134 inode->i_op = &ubifs_dir_inode_operations;
135 inode->i_fop = &ubifs_dir_operations;
136 inode->i_size = ui->ui_size = UBIFS_INO_NODE_SZ;
139 inode->i_op = &ubifs_symlink_inode_operations;
145 inode->i_op = &ubifs_file_inode_operations;
152 ui->flags = inherit_flags(dir, mode);
153 ubifs_set_inode_flags(inode);
155 ui->compr_type = c->default_compr;
157 ui->compr_type = UBIFS_COMPR_NONE;
158 ui->synced_i_size = 0;
160 spin_lock(&c->cnt_lock);
161 /* Inode number overflow is currently not supported */
162 if (c->highest_inum >= INUM_WARN_WATERMARK) {
163 if (c->highest_inum >= INUM_WATERMARK) {
164 spin_unlock(&c->cnt_lock);
165 ubifs_err(c, "out of inode numbers");
166 make_bad_inode(inode);
168 return ERR_PTR(-EINVAL);
170 ubifs_warn(c, "running out of inode numbers (current %lu, max %u)",
171 (unsigned long)c->highest_inum, INUM_WATERMARK);
174 inode->i_ino = ++c->highest_inum;
176 * The creation sequence number remains with this inode for its
177 * lifetime. All nodes for this inode have a greater sequence number,
178 * and so it is possible to distinguish obsolete nodes belonging to a
179 * previous incarnation of the same inode number - for example, for the
180 * purpose of rebuilding the index.
182 ui->creat_sqnum = ++c->max_sqnum;
183 spin_unlock(&c->cnt_lock);
186 err = fscrypt_inherit_context(dir, inode, &encrypted, true);
188 ubifs_err(c, "fscrypt_inherit_context failed: %i", err);
189 make_bad_inode(inode);
198 static int dbg_check_name(const struct ubifs_info *c,
199 const struct ubifs_dent_node *dent,
200 const struct fscrypt_name *nm)
202 if (!dbg_is_chk_gen(c))
204 if (le16_to_cpu(dent->nlen) != fname_len(nm))
206 if (memcmp(dent->name, fname_name(nm), fname_len(nm)))
211 static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
216 struct inode *inode = NULL;
217 struct ubifs_dent_node *dent = NULL;
218 struct ubifs_info *c = dir->i_sb->s_fs_info;
219 struct fscrypt_name nm;
221 dbg_gen("'%pd' in dir ino %lu", dentry, dir->i_ino);
223 err = fscrypt_prepare_lookup(dir, dentry, &nm);
225 return d_splice_alias(NULL, dentry);
229 if (fname_len(&nm) > UBIFS_MAX_NLEN) {
230 inode = ERR_PTR(-ENAMETOOLONG);
234 dent = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
236 inode = ERR_PTR(-ENOMEM);
241 ubifs_assert(c, fname_len(&nm) == 0);
242 ubifs_assert(c, fname_name(&nm) == NULL);
243 if (nm.hash & ~UBIFS_S_KEY_HASH_MASK)
244 goto done; /* ENOENT */
245 dent_key_init_hash(c, &key, dir->i_ino, nm.hash);
246 err = ubifs_tnc_lookup_dh(c, &key, dent, nm.minor_hash);
248 dent_key_init(c, &key, dir->i_ino, &nm);
249 err = ubifs_tnc_lookup_nm(c, &key, dent, &nm);
254 dbg_gen("not found");
256 inode = ERR_PTR(err);
260 if (dbg_check_name(c, dent, &nm)) {
261 inode = ERR_PTR(-EINVAL);
265 inode = ubifs_iget(dir->i_sb, le64_to_cpu(dent->inum));
268 * This should not happen. Probably the file-system needs
271 err = PTR_ERR(inode);
272 ubifs_err(c, "dead directory entry '%pd', error %d",
274 ubifs_ro_mode(c, err);
278 if (ubifs_crypt_is_encrypted(dir) &&
279 (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
280 !fscrypt_has_permitted_context(dir, inode)) {
281 ubifs_warn(c, "Inconsistent encryption contexts: %lu/%lu",
282 dir->i_ino, inode->i_ino);
284 inode = ERR_PTR(-EPERM);
289 fscrypt_free_filename(&nm);
290 return d_splice_alias(inode, dentry);
293 static int ubifs_prepare_create(struct inode *dir, struct dentry *dentry,
294 struct fscrypt_name *nm)
296 if (fscrypt_is_nokey_name(dentry))
299 return fscrypt_setup_filename(dir, &dentry->d_name, 0, nm);
302 static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
306 struct ubifs_info *c = dir->i_sb->s_fs_info;
307 struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
309 struct ubifs_inode *dir_ui = ubifs_inode(dir);
310 struct fscrypt_name nm;
314 * Budget request settings: new inode, new direntry, changing the
315 * parent directory inode.
318 dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
319 dentry, mode, dir->i_ino);
321 err = ubifs_budget_space(c, &req);
325 err = ubifs_prepare_create(dir, dentry, &nm);
329 sz_change = CALC_DENT_SIZE(fname_len(&nm));
331 inode = ubifs_new_inode(c, dir, mode);
333 err = PTR_ERR(inode);
337 err = ubifs_init_security(dir, inode, &dentry->d_name);
341 mutex_lock(&dir_ui->ui_mutex);
342 dir->i_size += sz_change;
343 dir_ui->ui_size = dir->i_size;
344 dir->i_mtime = dir->i_ctime = inode->i_ctime;
345 err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0);
348 mutex_unlock(&dir_ui->ui_mutex);
350 ubifs_release_budget(c, &req);
351 fscrypt_free_filename(&nm);
352 insert_inode_hash(inode);
353 d_instantiate(dentry, inode);
357 dir->i_size -= sz_change;
358 dir_ui->ui_size = dir->i_size;
359 mutex_unlock(&dir_ui->ui_mutex);
361 make_bad_inode(inode);
364 fscrypt_free_filename(&nm);
366 ubifs_release_budget(c, &req);
367 ubifs_err(c, "cannot create regular file, error %d", err);
371 static int do_tmpfile(struct inode *dir, struct dentry *dentry,
372 umode_t mode, struct inode **whiteout)
375 struct ubifs_info *c = dir->i_sb->s_fs_info;
376 struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
378 struct ubifs_budget_req ino_req = { .dirtied_ino = 1 };
379 struct ubifs_inode *ui, *dir_ui = ubifs_inode(dir);
380 int err, instantiated = 0;
381 struct fscrypt_name nm;
384 * Budget request settings: new inode, new direntry, changing the
385 * parent directory inode.
386 * Allocate budget separately for new dirtied inode, the budget will
387 * be released via writeback.
390 dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
391 dentry, mode, dir->i_ino);
393 err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm);
397 err = ubifs_budget_space(c, &req);
399 fscrypt_free_filename(&nm);
403 err = ubifs_budget_space(c, &ino_req);
405 ubifs_release_budget(c, &req);
406 fscrypt_free_filename(&nm);
410 inode = ubifs_new_inode(c, dir, mode);
412 err = PTR_ERR(inode);
415 ui = ubifs_inode(inode);
418 init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
419 ubifs_assert(c, inode->i_op == &ubifs_file_inode_operations);
422 err = ubifs_init_security(dir, inode, &dentry->d_name);
426 mutex_lock(&ui->ui_mutex);
427 insert_inode_hash(inode);
430 mark_inode_dirty(inode);
434 d_tmpfile(dentry, inode);
436 ubifs_assert(c, ui->dirty);
439 mutex_unlock(&ui->ui_mutex);
441 mutex_lock(&dir_ui->ui_mutex);
442 err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0);
445 mutex_unlock(&dir_ui->ui_mutex);
447 ubifs_release_budget(c, &req);
452 mutex_unlock(&dir_ui->ui_mutex);
454 make_bad_inode(inode);
460 ubifs_release_budget(c, &req);
462 ubifs_release_budget(c, &ino_req);
463 fscrypt_free_filename(&nm);
464 ubifs_err(c, "cannot create temporary file, error %d", err);
468 static int ubifs_tmpfile(struct inode *dir, struct dentry *dentry,
471 return do_tmpfile(dir, dentry, mode, NULL);
475 * vfs_dent_type - get VFS directory entry type.
476 * @type: UBIFS directory entry type
478 * This function converts UBIFS directory entry type into VFS directory entry
481 static unsigned int vfs_dent_type(uint8_t type)
484 case UBIFS_ITYPE_REG:
486 case UBIFS_ITYPE_DIR:
488 case UBIFS_ITYPE_LNK:
490 case UBIFS_ITYPE_BLK:
492 case UBIFS_ITYPE_CHR:
494 case UBIFS_ITYPE_FIFO:
496 case UBIFS_ITYPE_SOCK:
505 * The classical Unix view for directory is that it is a linear array of
506 * (name, inode number) entries. Linux/VFS assumes this model as well.
507 * Particularly, 'readdir()' call wants us to return a directory entry offset
508 * which later may be used to continue 'readdir()'ing the directory or to
509 * 'seek()' to that specific direntry. Obviously UBIFS does not really fit this
510 * model because directory entries are identified by keys, which may collide.
512 * UBIFS uses directory entry hash value for directory offsets, so
513 * 'seekdir()'/'telldir()' may not always work because of possible key
514 * collisions. But UBIFS guarantees that consecutive 'readdir()' calls work
515 * properly by means of saving full directory entry name in the private field
516 * of the file description object.
518 * This means that UBIFS cannot support NFS which requires full
519 * 'seekdir()'/'telldir()' support.
521 static int ubifs_readdir(struct file *file, struct dir_context *ctx)
523 int fstr_real_len = 0, err = 0;
524 struct fscrypt_name nm;
525 struct fscrypt_str fstr = {0};
527 struct ubifs_dent_node *dent;
528 struct inode *dir = file_inode(file);
529 struct ubifs_info *c = dir->i_sb->s_fs_info;
530 bool encrypted = ubifs_crypt_is_encrypted(dir);
532 dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, ctx->pos);
534 if (ctx->pos > UBIFS_S_KEY_HASH_MASK || ctx->pos == 2)
536 * The directory was seek'ed to a senseless position or there
537 * are no more entries.
542 err = fscrypt_get_encryption_info(dir);
543 if (err && err != -ENOKEY)
546 err = fscrypt_fname_alloc_buffer(dir, UBIFS_MAX_NLEN, &fstr);
550 fstr_real_len = fstr.len;
553 if (file->f_version == 0) {
555 * The file was seek'ed, which means that @file->private_data
556 * is now invalid. This may also be just the first
557 * 'ubifs_readdir()' invocation, in which case
558 * @file->private_data is NULL, and the below code is
561 kfree(file->private_data);
562 file->private_data = NULL;
566 * 'generic_file_llseek()' unconditionally sets @file->f_version to
567 * zero, and we use this for detecting whether the file was seek'ed.
571 /* File positions 0 and 1 correspond to "." and ".." */
573 ubifs_assert(c, !file->private_data);
574 if (!dir_emit_dots(file, ctx)) {
576 fscrypt_fname_free_buffer(&fstr);
580 /* Find the first entry in TNC and save it */
581 lowest_dent_key(c, &key, dir->i_ino);
583 dent = ubifs_tnc_next_ent(c, &key, &nm);
589 ctx->pos = key_hash_flash(c, &dent->key);
590 file->private_data = dent;
593 dent = file->private_data;
596 * The directory was seek'ed to and is now readdir'ed.
597 * Find the entry corresponding to @ctx->pos or the closest one.
599 dent_key_init_hash(c, &key, dir->i_ino, ctx->pos);
601 dent = ubifs_tnc_next_ent(c, &key, &nm);
606 ctx->pos = key_hash_flash(c, &dent->key);
607 file->private_data = dent;
611 dbg_gen("ino %llu, new f_pos %#x",
612 (unsigned long long)le64_to_cpu(dent->inum),
613 key_hash_flash(c, &dent->key));
614 ubifs_assert(c, le64_to_cpu(dent->ch.sqnum) >
615 ubifs_inode(dir)->creat_sqnum);
617 fname_len(&nm) = le16_to_cpu(dent->nlen);
618 fname_name(&nm) = dent->name;
621 fstr.len = fstr_real_len;
623 err = fscrypt_fname_disk_to_usr(dir, key_hash_flash(c,
625 le32_to_cpu(dent->cookie),
626 &nm.disk_name, &fstr);
630 fstr.len = fname_len(&nm);
631 fstr.name = fname_name(&nm);
634 if (!dir_emit(ctx, fstr.name, fstr.len,
635 le64_to_cpu(dent->inum),
636 vfs_dent_type(dent->type))) {
638 fscrypt_fname_free_buffer(&fstr);
642 /* Switch to the next entry */
643 key_read(c, &dent->key, &key);
644 dent = ubifs_tnc_next_ent(c, &key, &nm);
650 kfree(file->private_data);
651 ctx->pos = key_hash_flash(c, &dent->key);
652 file->private_data = dent;
657 kfree(file->private_data);
658 file->private_data = NULL;
661 fscrypt_fname_free_buffer(&fstr);
664 ubifs_err(c, "cannot find next direntry, error %d", err);
667 * -ENOENT is a non-fatal error in this context, the TNC uses
668 * it to indicate that the cursor moved past the current directory
669 * and readdir() has to stop.
674 /* 2 is a special value indicating that there are no more direntries */
679 /* Free saved readdir() state when the directory is closed */
680 static int ubifs_dir_release(struct inode *dir, struct file *file)
682 kfree(file->private_data);
683 file->private_data = NULL;
688 * lock_2_inodes - a wrapper for locking two UBIFS inodes.
689 * @inode1: first inode
690 * @inode2: second inode
692 * We do not implement any tricks to guarantee strict lock ordering, because
693 * VFS has already done it for us on the @i_mutex. So this is just a simple
696 static void lock_2_inodes(struct inode *inode1, struct inode *inode2)
698 mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
699 mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
703 * unlock_2_inodes - a wrapper for unlocking two UBIFS inodes.
704 * @inode1: first inode
705 * @inode2: second inode
707 static void unlock_2_inodes(struct inode *inode1, struct inode *inode2)
709 mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
710 mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
713 static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
714 struct dentry *dentry)
716 struct ubifs_info *c = dir->i_sb->s_fs_info;
717 struct inode *inode = d_inode(old_dentry);
718 struct ubifs_inode *ui = ubifs_inode(inode);
719 struct ubifs_inode *dir_ui = ubifs_inode(dir);
720 int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
721 struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
722 .dirtied_ino_d = ALIGN(ui->data_len, 8) };
723 struct fscrypt_name nm;
726 * Budget request settings: new direntry, changing the target inode,
727 * changing the parent inode.
730 dbg_gen("dent '%pd' to ino %lu (nlink %d) in dir ino %lu",
731 dentry, inode->i_ino,
732 inode->i_nlink, dir->i_ino);
733 ubifs_assert(c, inode_is_locked(dir));
734 ubifs_assert(c, inode_is_locked(inode));
736 err = fscrypt_prepare_link(old_dentry, dir, dentry);
740 err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm);
744 err = dbg_check_synced_i_size(c, inode);
748 err = ubifs_budget_space(c, &req);
752 lock_2_inodes(dir, inode);
754 /* Handle O_TMPFILE corner case, it is allowed to link a O_TMPFILE. */
755 if (inode->i_nlink == 0)
756 ubifs_delete_orphan(c, inode->i_ino);
760 inode->i_ctime = current_time(inode);
761 dir->i_size += sz_change;
762 dir_ui->ui_size = dir->i_size;
763 dir->i_mtime = dir->i_ctime = inode->i_ctime;
764 err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0);
767 unlock_2_inodes(dir, inode);
769 ubifs_release_budget(c, &req);
770 d_instantiate(dentry, inode);
771 fscrypt_free_filename(&nm);
775 dir->i_size -= sz_change;
776 dir_ui->ui_size = dir->i_size;
778 if (inode->i_nlink == 0)
779 ubifs_add_orphan(c, inode->i_ino);
780 unlock_2_inodes(dir, inode);
781 ubifs_release_budget(c, &req);
784 fscrypt_free_filename(&nm);
788 static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
790 struct ubifs_info *c = dir->i_sb->s_fs_info;
791 struct inode *inode = d_inode(dentry);
792 struct ubifs_inode *dir_ui = ubifs_inode(dir);
793 int err, sz_change, budgeted = 1;
794 struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
795 unsigned int saved_nlink = inode->i_nlink;
796 struct fscrypt_name nm;
799 * Budget request settings: deletion direntry, deletion inode (+1 for
800 * @dirtied_ino), changing the parent directory inode. If budgeting
801 * fails, go ahead anyway because we have extra space reserved for
805 dbg_gen("dent '%pd' from ino %lu (nlink %d) in dir ino %lu",
806 dentry, inode->i_ino,
807 inode->i_nlink, dir->i_ino);
809 if (ubifs_crypt_is_encrypted(dir)) {
810 err = fscrypt_get_encryption_info(dir);
811 if (err && err != -ENOKEY)
815 err = fscrypt_setup_filename(dir, &dentry->d_name, 1, &nm);
819 sz_change = CALC_DENT_SIZE(fname_len(&nm));
821 ubifs_assert(c, inode_is_locked(dir));
822 ubifs_assert(c, inode_is_locked(inode));
823 err = dbg_check_synced_i_size(c, inode);
827 err = ubifs_budget_space(c, &req);
834 lock_2_inodes(dir, inode);
835 inode->i_ctime = current_time(dir);
837 dir->i_size -= sz_change;
838 dir_ui->ui_size = dir->i_size;
839 dir->i_mtime = dir->i_ctime = inode->i_ctime;
840 err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0);
843 unlock_2_inodes(dir, inode);
846 ubifs_release_budget(c, &req);
848 /* We've deleted something - clean the "no space" flags */
849 c->bi.nospace = c->bi.nospace_rp = 0;
852 fscrypt_free_filename(&nm);
856 dir->i_size += sz_change;
857 dir_ui->ui_size = dir->i_size;
858 set_nlink(inode, saved_nlink);
859 unlock_2_inodes(dir, inode);
861 ubifs_release_budget(c, &req);
863 fscrypt_free_filename(&nm);
868 * check_dir_empty - check if a directory is empty or not.
869 * @dir: VFS inode object of the directory to check
871 * This function checks if directory @dir is empty. Returns zero if the
872 * directory is empty, %-ENOTEMPTY if it is not, and other negative error codes
873 * in case of of errors.
875 int ubifs_check_dir_empty(struct inode *dir)
877 struct ubifs_info *c = dir->i_sb->s_fs_info;
878 struct fscrypt_name nm = { 0 };
879 struct ubifs_dent_node *dent;
883 lowest_dent_key(c, &key, dir->i_ino);
884 dent = ubifs_tnc_next_ent(c, &key, &nm);
896 static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
898 struct ubifs_info *c = dir->i_sb->s_fs_info;
899 struct inode *inode = d_inode(dentry);
900 int err, sz_change, budgeted = 1;
901 struct ubifs_inode *dir_ui = ubifs_inode(dir);
902 struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
903 struct fscrypt_name nm;
906 * Budget request settings: deletion direntry, deletion inode and
907 * changing the parent inode. If budgeting fails, go ahead anyway
908 * because we have extra space reserved for deletions.
911 dbg_gen("directory '%pd', ino %lu in dir ino %lu", dentry,
912 inode->i_ino, dir->i_ino);
913 ubifs_assert(c, inode_is_locked(dir));
914 ubifs_assert(c, inode_is_locked(inode));
915 err = ubifs_check_dir_empty(d_inode(dentry));
919 if (ubifs_crypt_is_encrypted(dir)) {
920 err = fscrypt_get_encryption_info(dir);
921 if (err && err != -ENOKEY)
925 err = fscrypt_setup_filename(dir, &dentry->d_name, 1, &nm);
929 sz_change = CALC_DENT_SIZE(fname_len(&nm));
931 err = ubifs_budget_space(c, &req);
938 lock_2_inodes(dir, inode);
939 inode->i_ctime = current_time(dir);
942 dir->i_size -= sz_change;
943 dir_ui->ui_size = dir->i_size;
944 dir->i_mtime = dir->i_ctime = inode->i_ctime;
945 err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0);
948 unlock_2_inodes(dir, inode);
951 ubifs_release_budget(c, &req);
953 /* We've deleted something - clean the "no space" flags */
954 c->bi.nospace = c->bi.nospace_rp = 0;
957 fscrypt_free_filename(&nm);
961 dir->i_size += sz_change;
962 dir_ui->ui_size = dir->i_size;
965 unlock_2_inodes(dir, inode);
967 ubifs_release_budget(c, &req);
969 fscrypt_free_filename(&nm);
973 static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
976 struct ubifs_inode *dir_ui = ubifs_inode(dir);
977 struct ubifs_info *c = dir->i_sb->s_fs_info;
979 struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
981 struct fscrypt_name nm;
984 * Budget request settings: new inode, new direntry and changing parent
988 dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
989 dentry, mode, dir->i_ino);
991 err = ubifs_budget_space(c, &req);
995 err = ubifs_prepare_create(dir, dentry, &nm);
999 sz_change = CALC_DENT_SIZE(fname_len(&nm));
1001 inode = ubifs_new_inode(c, dir, S_IFDIR | mode);
1002 if (IS_ERR(inode)) {
1003 err = PTR_ERR(inode);
1007 err = ubifs_init_security(dir, inode, &dentry->d_name);
1011 mutex_lock(&dir_ui->ui_mutex);
1012 insert_inode_hash(inode);
1015 dir->i_size += sz_change;
1016 dir_ui->ui_size = dir->i_size;
1017 dir->i_mtime = dir->i_ctime = inode->i_ctime;
1018 err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0);
1020 ubifs_err(c, "cannot create directory, error %d", err);
1023 mutex_unlock(&dir_ui->ui_mutex);
1025 ubifs_release_budget(c, &req);
1026 d_instantiate(dentry, inode);
1027 fscrypt_free_filename(&nm);
1031 dir->i_size -= sz_change;
1032 dir_ui->ui_size = dir->i_size;
1034 mutex_unlock(&dir_ui->ui_mutex);
1036 make_bad_inode(inode);
1039 fscrypt_free_filename(&nm);
1041 ubifs_release_budget(c, &req);
1045 static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
1046 umode_t mode, dev_t rdev)
1048 struct inode *inode;
1049 struct ubifs_inode *ui;
1050 struct ubifs_inode *dir_ui = ubifs_inode(dir);
1051 struct ubifs_info *c = dir->i_sb->s_fs_info;
1052 union ubifs_dev_desc *dev = NULL;
1054 int err, devlen = 0;
1055 struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
1057 struct fscrypt_name nm;
1060 * Budget request settings: new inode, new direntry and changing parent
1064 dbg_gen("dent '%pd' in dir ino %lu", dentry, dir->i_ino);
1066 if (S_ISBLK(mode) || S_ISCHR(mode)) {
1067 dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
1070 devlen = ubifs_encode_dev(dev, rdev);
1073 req.new_ino_d = ALIGN(devlen, 8);
1074 err = ubifs_budget_space(c, &req);
1080 err = ubifs_prepare_create(dir, dentry, &nm);
1086 sz_change = CALC_DENT_SIZE(fname_len(&nm));
1088 inode = ubifs_new_inode(c, dir, mode);
1089 if (IS_ERR(inode)) {
1091 err = PTR_ERR(inode);
1095 init_special_inode(inode, inode->i_mode, rdev);
1096 inode->i_size = ubifs_inode(inode)->ui_size = devlen;
1097 ui = ubifs_inode(inode);
1099 ui->data_len = devlen;
1101 err = ubifs_init_security(dir, inode, &dentry->d_name);
1105 mutex_lock(&dir_ui->ui_mutex);
1106 dir->i_size += sz_change;
1107 dir_ui->ui_size = dir->i_size;
1108 dir->i_mtime = dir->i_ctime = inode->i_ctime;
1109 err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0);
1112 mutex_unlock(&dir_ui->ui_mutex);
1114 ubifs_release_budget(c, &req);
1115 insert_inode_hash(inode);
1116 d_instantiate(dentry, inode);
1117 fscrypt_free_filename(&nm);
1121 dir->i_size -= sz_change;
1122 dir_ui->ui_size = dir->i_size;
1123 mutex_unlock(&dir_ui->ui_mutex);
1125 make_bad_inode(inode);
1128 fscrypt_free_filename(&nm);
1130 ubifs_release_budget(c, &req);
1134 static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
1135 const char *symname)
1137 struct inode *inode;
1138 struct ubifs_inode *ui;
1139 struct ubifs_inode *dir_ui = ubifs_inode(dir);
1140 struct ubifs_info *c = dir->i_sb->s_fs_info;
1141 int err, sz_change, len = strlen(symname);
1142 struct fscrypt_str disk_link;
1143 struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
1144 .new_ino_d = ALIGN(len, 8),
1146 struct fscrypt_name nm;
1148 dbg_gen("dent '%pd', target '%s' in dir ino %lu", dentry,
1149 symname, dir->i_ino);
1151 err = fscrypt_prepare_symlink(dir, symname, len, UBIFS_MAX_INO_DATA,
1157 * Budget request settings: new inode, new direntry and changing parent
1160 err = ubifs_budget_space(c, &req);
1164 err = ubifs_prepare_create(dir, dentry, &nm);
1168 sz_change = CALC_DENT_SIZE(fname_len(&nm));
1170 inode = ubifs_new_inode(c, dir, S_IFLNK | S_IRWXUGO);
1171 if (IS_ERR(inode)) {
1172 err = PTR_ERR(inode);
1176 ui = ubifs_inode(inode);
1177 ui->data = kmalloc(disk_link.len, GFP_NOFS);
1183 if (IS_ENCRYPTED(inode)) {
1184 disk_link.name = ui->data; /* encrypt directly into ui->data */
1185 err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link);
1189 memcpy(ui->data, disk_link.name, disk_link.len);
1190 inode->i_link = ui->data;
1194 * The terminating zero byte is not written to the flash media and it
1195 * is put just to make later in-memory string processing simpler. Thus,
1196 * data length is @disk_link.len - 1, not @disk_link.len.
1198 ui->data_len = disk_link.len - 1;
1199 inode->i_size = ubifs_inode(inode)->ui_size = disk_link.len - 1;
1201 err = ubifs_init_security(dir, inode, &dentry->d_name);
1205 mutex_lock(&dir_ui->ui_mutex);
1206 dir->i_size += sz_change;
1207 dir_ui->ui_size = dir->i_size;
1208 dir->i_mtime = dir->i_ctime = inode->i_ctime;
1209 err = ubifs_jnl_update(c, dir, &nm, inode, 0, 0);
1212 mutex_unlock(&dir_ui->ui_mutex);
1214 insert_inode_hash(inode);
1215 d_instantiate(dentry, inode);
1220 dir->i_size -= sz_change;
1221 dir_ui->ui_size = dir->i_size;
1222 mutex_unlock(&dir_ui->ui_mutex);
1224 make_bad_inode(inode);
1227 fscrypt_free_filename(&nm);
1229 ubifs_release_budget(c, &req);
1234 * lock_4_inodes - a wrapper for locking three UBIFS inodes.
1235 * @inode1: first inode
1236 * @inode2: second inode
1237 * @inode3: third inode
1238 * @inode4: fouth inode
1240 * This function is used for 'ubifs_rename()' and @inode1 may be the same as
1241 * @inode2 whereas @inode3 and @inode4 may be %NULL.
1243 * We do not implement any tricks to guarantee strict lock ordering, because
1244 * VFS has already done it for us on the @i_mutex. So this is just a simple
1247 static void lock_4_inodes(struct inode *inode1, struct inode *inode2,
1248 struct inode *inode3, struct inode *inode4)
1250 mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
1251 if (inode2 != inode1)
1252 mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
1254 mutex_lock_nested(&ubifs_inode(inode3)->ui_mutex, WB_MUTEX_3);
1256 mutex_lock_nested(&ubifs_inode(inode4)->ui_mutex, WB_MUTEX_4);
1260 * unlock_4_inodes - a wrapper for unlocking three UBIFS inodes for rename.
1261 * @inode1: first inode
1262 * @inode2: second inode
1263 * @inode3: third inode
1264 * @inode4: fouth inode
1266 static void unlock_4_inodes(struct inode *inode1, struct inode *inode2,
1267 struct inode *inode3, struct inode *inode4)
1270 mutex_unlock(&ubifs_inode(inode4)->ui_mutex);
1272 mutex_unlock(&ubifs_inode(inode3)->ui_mutex);
1273 if (inode1 != inode2)
1274 mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
1275 mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
1278 static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
1279 struct inode *new_dir, struct dentry *new_dentry,
1282 struct ubifs_info *c = old_dir->i_sb->s_fs_info;
1283 struct inode *old_inode = d_inode(old_dentry);
1284 struct inode *new_inode = d_inode(new_dentry);
1285 struct inode *whiteout = NULL;
1286 struct ubifs_inode *old_inode_ui = ubifs_inode(old_inode);
1287 struct ubifs_inode *whiteout_ui = NULL;
1288 int err, release, sync = 0, move = (new_dir != old_dir);
1289 int is_dir = S_ISDIR(old_inode->i_mode);
1290 int unlink = !!new_inode, new_sz, old_sz;
1291 struct ubifs_budget_req req = { .new_dent = 1, .mod_dent = 1,
1293 struct ubifs_budget_req ino_req = { .dirtied_ino = 1,
1294 .dirtied_ino_d = ALIGN(old_inode_ui->data_len, 8) };
1295 struct timespec64 time;
1296 unsigned int uninitialized_var(saved_nlink);
1297 struct fscrypt_name old_nm, new_nm;
1300 * Budget request settings: deletion direntry, new direntry, removing
1301 * the old inode, and changing old and new parent directory inodes.
1303 * However, this operation also marks the target inode as dirty and
1304 * does not write it, so we allocate budget for the target inode
1308 dbg_gen("dent '%pd' ino %lu in dir ino %lu to dent '%pd' in dir ino %lu flags 0x%x",
1309 old_dentry, old_inode->i_ino, old_dir->i_ino,
1310 new_dentry, new_dir->i_ino, flags);
1313 ubifs_assert(c, inode_is_locked(new_inode));
1315 if (unlink && is_dir) {
1316 err = ubifs_check_dir_empty(new_inode);
1321 err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &old_nm);
1325 err = fscrypt_setup_filename(new_dir, &new_dentry->d_name, 0, &new_nm);
1327 fscrypt_free_filename(&old_nm);
1331 new_sz = CALC_DENT_SIZE(fname_len(&new_nm));
1332 old_sz = CALC_DENT_SIZE(fname_len(&old_nm));
1334 err = ubifs_budget_space(c, &req);
1336 fscrypt_free_filename(&old_nm);
1337 fscrypt_free_filename(&new_nm);
1340 err = ubifs_budget_space(c, &ino_req);
1342 fscrypt_free_filename(&old_nm);
1343 fscrypt_free_filename(&new_nm);
1344 ubifs_release_budget(c, &req);
1348 if (flags & RENAME_WHITEOUT) {
1349 union ubifs_dev_desc *dev = NULL;
1350 struct ubifs_budget_req wht_req;
1352 dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
1358 err = do_tmpfile(old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE, &whiteout);
1364 spin_lock(&whiteout->i_lock);
1365 whiteout->i_state |= I_LINKABLE;
1366 spin_unlock(&whiteout->i_lock);
1368 whiteout_ui = ubifs_inode(whiteout);
1369 whiteout_ui->data = dev;
1370 whiteout_ui->data_len = ubifs_encode_dev(dev, MKDEV(0, 0));
1371 ubifs_assert(c, !whiteout_ui->dirty);
1373 memset(&wht_req, 0, sizeof(struct ubifs_budget_req));
1374 wht_req.dirtied_ino = 1;
1375 wht_req.dirtied_ino_d = ALIGN(whiteout_ui->data_len, 8);
1377 * To avoid deadlock between space budget (holds ui_mutex and
1378 * waits wb work) and writeback work(waits ui_mutex), do space
1379 * budget before ubifs inodes locked.
1381 err = ubifs_budget_space(c, &wht_req);
1387 /* Add the old_dentry size to the old_dir size. */
1388 old_sz -= CALC_DENT_SIZE(fname_len(&old_nm));
1391 lock_4_inodes(old_dir, new_dir, new_inode, whiteout);
1394 * Like most other Unix systems, set the @i_ctime for inodes on a
1397 time = current_time(old_dir);
1398 old_inode->i_ctime = time;
1400 /* We must adjust parent link count when renaming directories */
1404 * @old_dir loses a link because we are moving
1405 * @old_inode to a different directory.
1407 drop_nlink(old_dir);
1409 * @new_dir only gains a link if we are not also
1410 * overwriting an existing directory.
1416 * @old_inode is not moving to a different directory,
1417 * but @old_dir still loses a link if we are
1418 * overwriting an existing directory.
1421 drop_nlink(old_dir);
1425 old_dir->i_size -= old_sz;
1426 ubifs_inode(old_dir)->ui_size = old_dir->i_size;
1427 old_dir->i_mtime = old_dir->i_ctime = time;
1428 new_dir->i_mtime = new_dir->i_ctime = time;
1431 * And finally, if we unlinked a direntry which happened to have the
1432 * same name as the moved direntry, we have to decrement @i_nlink of
1433 * the unlinked inode and change its ctime.
1437 * Directories cannot have hard-links, so if this is a
1438 * directory, just clear @i_nlink.
1440 saved_nlink = new_inode->i_nlink;
1442 clear_nlink(new_inode);
1444 drop_nlink(new_inode);
1445 new_inode->i_ctime = time;
1447 new_dir->i_size += new_sz;
1448 ubifs_inode(new_dir)->ui_size = new_dir->i_size;
1452 * Do not ask 'ubifs_jnl_rename()' to flush write-buffer if @old_inode
1453 * is dirty, because this will be done later on at the end of
1456 if (IS_SYNC(old_inode)) {
1457 sync = IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir);
1458 if (unlink && IS_SYNC(new_inode))
1463 inc_nlink(whiteout);
1464 mark_inode_dirty(whiteout);
1466 spin_lock(&whiteout->i_lock);
1467 whiteout->i_state &= ~I_LINKABLE;
1468 spin_unlock(&whiteout->i_lock);
1473 err = ubifs_jnl_rename(c, old_dir, old_inode, &old_nm, new_dir,
1474 new_inode, &new_nm, whiteout, sync);
1478 unlock_4_inodes(old_dir, new_dir, new_inode, whiteout);
1479 ubifs_release_budget(c, &req);
1481 mutex_lock(&old_inode_ui->ui_mutex);
1482 release = old_inode_ui->dirty;
1483 mark_inode_dirty_sync(old_inode);
1484 mutex_unlock(&old_inode_ui->ui_mutex);
1487 ubifs_release_budget(c, &ino_req);
1488 if (IS_SYNC(old_inode))
1489 err = old_inode->i_sb->s_op->write_inode(old_inode, NULL);
1491 fscrypt_free_filename(&old_nm);
1492 fscrypt_free_filename(&new_nm);
1497 set_nlink(new_inode, saved_nlink);
1499 new_dir->i_size -= new_sz;
1500 ubifs_inode(new_dir)->ui_size = new_dir->i_size;
1502 old_dir->i_size += old_sz;
1503 ubifs_inode(old_dir)->ui_size = old_dir->i_size;
1508 drop_nlink(new_dir);
1515 drop_nlink(whiteout);
1518 unlock_4_inodes(old_dir, new_dir, new_inode, whiteout);
1520 ubifs_release_budget(c, &ino_req);
1521 ubifs_release_budget(c, &req);
1522 fscrypt_free_filename(&old_nm);
1523 fscrypt_free_filename(&new_nm);
1527 static int ubifs_xrename(struct inode *old_dir, struct dentry *old_dentry,
1528 struct inode *new_dir, struct dentry *new_dentry)
1530 struct ubifs_info *c = old_dir->i_sb->s_fs_info;
1531 struct ubifs_budget_req req = { .new_dent = 1, .mod_dent = 1,
1533 int sync = IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir);
1534 struct inode *fst_inode = d_inode(old_dentry);
1535 struct inode *snd_inode = d_inode(new_dentry);
1536 struct timespec64 time;
1538 struct fscrypt_name fst_nm, snd_nm;
1540 ubifs_assert(c, fst_inode && snd_inode);
1542 err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &fst_nm);
1546 err = fscrypt_setup_filename(new_dir, &new_dentry->d_name, 0, &snd_nm);
1548 fscrypt_free_filename(&fst_nm);
1552 lock_4_inodes(old_dir, new_dir, NULL, NULL);
1554 time = current_time(old_dir);
1555 fst_inode->i_ctime = time;
1556 snd_inode->i_ctime = time;
1557 old_dir->i_mtime = old_dir->i_ctime = time;
1558 new_dir->i_mtime = new_dir->i_ctime = time;
1560 if (old_dir != new_dir) {
1561 if (S_ISDIR(fst_inode->i_mode) && !S_ISDIR(snd_inode->i_mode)) {
1563 drop_nlink(old_dir);
1565 else if (!S_ISDIR(fst_inode->i_mode) && S_ISDIR(snd_inode->i_mode)) {
1566 drop_nlink(new_dir);
1571 err = ubifs_jnl_xrename(c, old_dir, fst_inode, &fst_nm, new_dir,
1572 snd_inode, &snd_nm, sync);
1574 unlock_4_inodes(old_dir, new_dir, NULL, NULL);
1575 ubifs_release_budget(c, &req);
1577 fscrypt_free_filename(&fst_nm);
1578 fscrypt_free_filename(&snd_nm);
1582 static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
1583 struct inode *new_dir, struct dentry *new_dentry,
1587 struct ubifs_info *c = old_dir->i_sb->s_fs_info;
1589 if (flags & ~(RENAME_NOREPLACE | RENAME_WHITEOUT | RENAME_EXCHANGE))
1592 ubifs_assert(c, inode_is_locked(old_dir));
1593 ubifs_assert(c, inode_is_locked(new_dir));
1595 err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
1600 if (flags & RENAME_EXCHANGE)
1601 return ubifs_xrename(old_dir, old_dentry, new_dir, new_dentry);
1603 return do_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
1606 int ubifs_getattr(const struct path *path, struct kstat *stat,
1607 u32 request_mask, unsigned int flags)
1610 struct inode *inode = d_inode(path->dentry);
1611 struct ubifs_inode *ui = ubifs_inode(inode);
1613 mutex_lock(&ui->ui_mutex);
1615 if (ui->flags & UBIFS_APPEND_FL)
1616 stat->attributes |= STATX_ATTR_APPEND;
1617 if (ui->flags & UBIFS_COMPR_FL)
1618 stat->attributes |= STATX_ATTR_COMPRESSED;
1619 if (ui->flags & UBIFS_CRYPT_FL)
1620 stat->attributes |= STATX_ATTR_ENCRYPTED;
1621 if (ui->flags & UBIFS_IMMUTABLE_FL)
1622 stat->attributes |= STATX_ATTR_IMMUTABLE;
1624 stat->attributes_mask |= (STATX_ATTR_APPEND |
1625 STATX_ATTR_COMPRESSED |
1626 STATX_ATTR_ENCRYPTED |
1627 STATX_ATTR_IMMUTABLE);
1629 generic_fillattr(inode, stat);
1630 stat->blksize = UBIFS_BLOCK_SIZE;
1631 stat->size = ui->ui_size;
1634 * Unfortunately, the 'stat()' system call was designed for block
1635 * device based file systems, and it is not appropriate for UBIFS,
1636 * because UBIFS does not have notion of "block". For example, it is
1637 * difficult to tell how many block a directory takes - it actually
1638 * takes less than 300 bytes, but we have to round it to block size,
1639 * which introduces large mistake. This makes utilities like 'du' to
1640 * report completely senseless numbers. This is the reason why UBIFS
1641 * goes the same way as JFFS2 - it reports zero blocks for everything
1642 * but regular files, which makes more sense than reporting completely
1645 if (S_ISREG(inode->i_mode)) {
1646 size = ui->xattr_size;
1648 size = ALIGN(size, UBIFS_BLOCK_SIZE);
1650 * Note, user-space expects 512-byte blocks count irrespectively
1651 * of what was reported in @stat->size.
1653 stat->blocks = size >> 9;
1656 mutex_unlock(&ui->ui_mutex);
1660 static int ubifs_dir_open(struct inode *dir, struct file *file)
1662 if (ubifs_crypt_is_encrypted(dir))
1663 return fscrypt_get_encryption_info(dir) ? -EACCES : 0;
1668 const struct inode_operations ubifs_dir_inode_operations = {
1669 .lookup = ubifs_lookup,
1670 .create = ubifs_create,
1672 .symlink = ubifs_symlink,
1673 .unlink = ubifs_unlink,
1674 .mkdir = ubifs_mkdir,
1675 .rmdir = ubifs_rmdir,
1676 .mknod = ubifs_mknod,
1677 .rename = ubifs_rename,
1678 .setattr = ubifs_setattr,
1679 .getattr = ubifs_getattr,
1680 #ifdef CONFIG_UBIFS_FS_XATTR
1681 .listxattr = ubifs_listxattr,
1683 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
1684 .update_time = ubifs_update_time,
1686 .tmpfile = ubifs_tmpfile,
1689 const struct file_operations ubifs_dir_operations = {
1690 .llseek = generic_file_llseek,
1691 .release = ubifs_dir_release,
1692 .read = generic_read_dir,
1693 .iterate_shared = ubifs_readdir,
1694 .fsync = ubifs_fsync,
1695 .unlocked_ioctl = ubifs_ioctl,
1696 .open = ubifs_dir_open,
1697 #ifdef CONFIG_COMPAT
1698 .compat_ioctl = ubifs_compat_ioctl,