109 ubifs_current_time(inode);
138 ui->
flags = inherit_flags(dir, mode);
156 ubifs_warn(
"running out of inode numbers (current %lu, max %d)",
173 static int dbg_check_name(
const struct ubifs_info *
c,
175 const struct qstr *nm)
177 if (!dbg_is_chk_gen(c))
195 dbg_gen(
"'%.*s' in dir ino %lu",
216 if (dbg_check_name(c, dent, &dentry->
d_name)) {
227 err = PTR_ERR(inode);
228 ubifs_err(
"dead directory entry '%.*s', error %d",
240 d_add(dentry, inode);
248 static int ubifs_create(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
263 dbg_gen(
"dent '%.*s', mode %#hx in dir ino %lu",
272 err = PTR_ERR(inode);
286 insert_inode_hash(inode);
298 ubifs_err(
"cannot create regular file, error %d", err);
355 struct inode *dir = file->
f_path.dentry->d_inode;
368 if (file->
f_pos == 0) {
370 over = filldir(dirent,
".", 1, 0, dir->
i_ino,
DT_DIR);
376 if (file->
f_pos == 1) {
378 over = filldir(dirent,
"..", 2, 1,
384 lowest_dent_key(c, &
key, dir->
i_ino);
392 file->
f_pos = key_hash_flash(c, &dent->
key);
410 file->
f_pos = key_hash_flash(c, &dent->
key);
415 dbg_gen(
"feed '%s', ino %llu, new f_pos %#x",
417 key_hash_flash(c, &dent->
key));
422 over = filldir(dirent, dent->
name, nm.len, file->
f_pos,
424 vfs_dent_type(dent->
type));
429 key_read(c, &dent->
key, &
key);
438 file->
f_pos = key_hash_flash(c, &dent->
key);
445 ubifs_err(
"cannot find next direntry, error %d", err);
456 static loff_t ubifs_dir_llseek(
struct file *file, loff_t
offset,
int origin)
464 static int ubifs_dir_release(
struct inode *dir,
struct file *file)
480 static void lock_2_inodes(
struct inode *inode1,
struct inode *inode2)
491 static void unlock_2_inodes(
struct inode *inode1,
struct inode *inode2)
497 static int ubifs_link(
struct dentry *old_dentry,
struct inode *dir,
498 struct dentry *dentry)
501 struct inode *inode = old_dentry->
d_inode;
513 dbg_gen(
"dent '%.*s' to ino %lu (nlink %d) in dir ino %lu",
527 lock_2_inodes(dir, inode);
530 inode->
i_ctime = ubifs_current_time(inode);
537 unlock_2_inodes(dir, inode);
547 unlock_2_inodes(dir, inode);
553 static int ubifs_unlink(
struct inode *dir,
struct dentry *dentry)
556 struct inode *inode = dentry->
d_inode;
559 int err, budgeted = 1;
561 unsigned int saved_nlink = inode->
i_nlink;
570 dbg_gen(
"dent '%.*s' from ino %lu (nlink %d) in dir ino %lu",
586 lock_2_inodes(dir, inode);
587 inode->
i_ctime = ubifs_current_time(dir);
595 unlock_2_inodes(dir, inode);
601 c->
bi.nospace = c->
bi.nospace_rp = 0;
610 unlock_2_inodes(dir, inode);
625 static int check_dir_empty(
struct ubifs_info *c,
struct inode *dir)
632 lowest_dent_key(c, &
key, dir->
i_ino);
645 static int ubifs_rmdir(
struct inode *dir,
struct dentry *dentry)
648 struct inode *inode = dentry->
d_inode;
650 int err, budgeted = 1;
660 dbg_gen(
"directory '%.*s', ino %lu in dir ino %lu", dentry->
d_name.len,
664 err = check_dir_empty(c, dentry->
d_inode);
675 lock_2_inodes(dir, inode);
676 inode->
i_ctime = ubifs_current_time(dir);
685 unlock_2_inodes(dir, inode);
691 c->
bi.nospace = c->
bi.nospace_rp = 0;
701 unlock_2_inodes(dir, inode);
707 static int ubifs_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
720 dbg_gen(
"dent '%.*s', mode %#hx in dir ino %lu",
729 err = PTR_ERR(inode);
734 insert_inode_hash(inode);
742 ubifs_err(
"cannot create directory, error %d", err);
763 static int ubifs_mknod(
struct inode *dir,
struct dentry *dentry,
774 .new_ino_d =
ALIGN(devlen, 8),
782 dbg_gen(
"dent '%.*s' in dir ino %lu",
785 if (!new_valid_dev(rdev))
792 devlen = ubifs_encode_dev(dev, rdev);
804 err = PTR_ERR(inode);
824 insert_inode_hash(inode);
839 static int ubifs_symlink(
struct inode *dir,
struct dentry *dentry,
849 .new_ino_d =
ALIGN(len, 8),
857 dbg_gen(
"dent '%.*s', target '%s' in dir ino %lu", dentry->
d_name.len,
869 err = PTR_ERR(inode);
881 ((
char *)ui->
data)[len] =
'\0';
900 insert_inode_hash(inode);
929 static void lock_3_inodes(
struct inode *inode1,
struct inode *inode2,
930 struct inode *inode3)
933 if (inode2 != inode1)
945 static void unlock_3_inodes(
struct inode *inode1,
struct inode *inode2,
946 struct inode *inode3)
950 if (inode1 != inode2)
955 static int ubifs_rename(
struct inode *old_dir,
struct dentry *old_dentry,
956 struct inode *new_dir,
struct dentry *new_dentry)
959 struct inode *old_inode = old_dentry->
d_inode;
983 dbg_gen(
"dent '%.*s' ino %lu in dir ino %lu to dent '%.*s' in dir ino %lu",
993 if (unlink && is_dir) {
994 err = check_dir_empty(c, new_inode);
1008 lock_3_inodes(old_dir, new_dir, new_inode);
1014 time = ubifs_current_time(old_dir);
1042 old_dir->
i_size -= old_sz;
1057 saved_nlink = new_inode->
i_nlink;
1064 new_dir->
i_size += new_sz;
1075 if (unlink &&
IS_SYNC(new_inode))
1083 unlock_3_inodes(old_dir, new_dir, new_inode);
1087 release = old_inode_ui->
dirty;
1088 mark_inode_dirty_sync(old_inode);
1094 err = old_inode->
i_sb->s_op->write_inode(old_inode,
NULL);
1101 new_dir->
i_size -= new_sz;
1104 old_dir->
i_size += old_sz;
1116 unlock_3_inodes(old_dir, new_dir, new_inode);
1126 struct inode *inode = dentry->
d_inode;
1154 stat->
blocks = size >> 9;
1162 .lookup = ubifs_lookup,
1163 .create = ubifs_create,
1165 .symlink = ubifs_symlink,
1166 .unlink = ubifs_unlink,
1167 .mkdir = ubifs_mkdir,
1168 .rmdir = ubifs_rmdir,
1169 .mknod = ubifs_mknod,
1170 .rename = ubifs_rename,
1180 .llseek = ubifs_dir_llseek,
1181 .release = ubifs_dir_release,
1183 .readdir = ubifs_readdir,
1186 #ifdef CONFIG_COMPAT
1187 .compat_ioctl = ubifs_compat_ioctl,