f = JFFS2_INODE_INFO(inode);
dir_f = JFFS2_INODE_INFO(dir_i);
/* jffs2_do_create() will want to lock it, _after_ reserving spaceandtakingc-alloc_sem.Ifwekeepitlockedhere, lockdepgetsunhappy(althoughit'safalsepositive; nothingelsewillbelookingatthisinodeyetsothere's
no chance of AB-BA deadlock involving its f->sem). */
mutex_unlock(&f->sem);
ret = jffs2_do_create(c, dir_f, f, ri, &dentry->d_name); if (ret) goto fail;
/* FIXME: If you care. We'd need to use frags for the target
if it grows much more than this */ if (targetlen > 254) return -ENAMETOOLONG;
ri = jffs2_alloc_raw_inode();
if (!ri) return -ENOMEM;
c = JFFS2_SB_INFO(dir_i->i_sb);
/* Try to reserve enough space for both node and dirent. *Justthenodewilldofornow,though
*/
namelen = dentry->d_name.len;
ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) {
jffs2_free_raw_inode(ri); return ret;
}
if (IS_ERR(fn)) { /* Eeek. Wave bye bye */
mutex_unlock(&f->sem);
jffs2_complete_reservation(c);
ret = PTR_ERR(fn); goto fail;
}
/* We use f->target field to store the target path. */
f->target = kmemdup(target, targetlen + 1, GFP_KERNEL); if (!f->target) {
pr_warn("Can't allocate %d bytes of memory\n", targetlen + 1);
mutex_unlock(&f->sem);
jffs2_complete_reservation(c);
ret = -ENOMEM; goto fail;
}
inode->i_link = f->target;
if (IS_ERR(fd)) { /* dirent failed to write. Delete the inode normally
as if it were the final unlink() */
jffs2_complete_reservation(c);
jffs2_free_raw_dirent(rd);
mutex_unlock(&dir_f->sem);
ret = PTR_ERR(fd); goto fail;
}
ri = jffs2_alloc_raw_inode(); if (!ri) return ERR_PTR(-ENOMEM);
c = JFFS2_SB_INFO(dir_i->i_sb);
/* Try to reserve enough space for both node and dirent. *Justthenodewilldofornow,though
*/
namelen = dentry->d_name.len;
ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
JFFS2_SUMMARY_INODE_SIZE);
if (ret) {
jffs2_free_raw_inode(ri); return ERR_PTR(ret);
}
inode = jffs2_new_inode(dir_i, mode, ri);
if (IS_ERR(inode)) {
jffs2_free_raw_inode(ri);
jffs2_complete_reservation(c); return ERR_CAST(inode);
}
if (IS_ERR(fn)) { /* Eeek. Wave bye bye */
mutex_unlock(&f->sem);
jffs2_complete_reservation(c);
ret = PTR_ERR(fn); goto fail;
} /* No data here. Only a metadata node, which will be obsoletedbythefirstdatawrite
*/
f->metadata = fn;
mutex_unlock(&f->sem);
jffs2_complete_reservation(c);
ret = jffs2_init_security(inode, dir_i, &dentry->d_name); if (ret) goto fail;
ret = jffs2_init_acl_post(inode); if (ret) goto fail;
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); if (ret) goto fail;
rd = jffs2_alloc_raw_dirent(); if (!rd) { /* Argh. Now we treat it like a normal delete */
jffs2_complete_reservation(c);
ret = -ENOMEM; goto fail;
}
if (IS_ERR(fd)) { /* dirent failed to write. Delete the inode normally
as if it were the final unlink() */
jffs2_complete_reservation(c);
jffs2_free_raw_dirent(rd);
mutex_unlock(&dir_f->sem);
ret = PTR_ERR(fd); goto fail;
}
ri = jffs2_alloc_raw_inode(); if (!ri) return -ENOMEM;
c = JFFS2_SB_INFO(dir_i->i_sb);
if (S_ISBLK(mode) || S_ISCHR(mode))
devlen = jffs2_encode_dev(&dev, rdev);
/* Try to reserve enough space for both node and dirent. *Justthenodewilldofornow,though
*/
namelen = dentry->d_name.len;
ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) {
jffs2_free_raw_inode(ri); return ret;
}
if (IS_ERR(fn)) { /* Eeek. Wave bye bye */
mutex_unlock(&f->sem);
jffs2_complete_reservation(c);
ret = PTR_ERR(fn); goto fail;
} /* No data here. Only a metadata node, which will be obsoletedbythefirstdatawrite
*/
f->metadata = fn;
mutex_unlock(&f->sem);
jffs2_complete_reservation(c);
ret = jffs2_init_security(inode, dir_i, &dentry->d_name); if (ret) goto fail;
ret = jffs2_init_acl_post(inode); if (ret) goto fail;
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); if (ret) goto fail;
rd = jffs2_alloc_raw_dirent(); if (!rd) { /* Argh. Now we treat it like a normal delete */
jffs2_complete_reservation(c);
ret = -ENOMEM; goto fail;
}
if (IS_ERR(fd)) { /* dirent failed to write. Delete the inode normally
as if it were the final unlink() */
jffs2_complete_reservation(c);
jffs2_free_raw_dirent(rd);
mutex_unlock(&dir_f->sem);
ret = PTR_ERR(fd); goto fail;
}
/* The VFS will check for us and prevent trying to rename a *fileoveradirectoryandviceversa,butifit'sadirectory, *theVFScan'tcheckwhetherthevictimisempty.Thefilesystem *needstodothatforitself.
*/ if (d_really_is_positive(new_dentry)) {
victim_f = JFFS2_INODE_INFO(d_inode(new_dentry)); if (d_is_dir(new_dentry)) { struct jffs2_full_dirent *fd;
/* XXX: We probably ought to alloc enough space for bothnodesatthesametime.Writingthenewlink, thengetting-ENOSPC,isquitebad:)
*/
/* Make a hard link */
/* XXX: This is ugly */
type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12; if (!type) type = DT_REG;
now = JFFS2_NOW();
ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
d_inode(old_dentry)->i_ino, type,
new_dentry->d_name.name, new_dentry->d_name.len, now);
if (ret) return ret;
if (victim_f) { /* There was a victim. Kill it off nicely */ if (d_is_dir(new_dentry))
clear_nlink(d_inode(new_dentry)); else
drop_nlink(d_inode(new_dentry)); /* Don't oops if the victim was a dirent pointing to an
inode which didn't exist. */ if (victim_f->inocache) {
mutex_lock(&victim_f->sem); if (d_is_dir(new_dentry))
victim_f->inocache->pino_nlink = 0; else
victim_f->inocache->pino_nlink--;
mutex_unlock(&victim_f->sem);
}
}
/* If it was a directory we moved, and there was no victim,
increase i_nlink on its new parent */ if (d_is_dir(old_dentry) && !victim_f)
inc_nlink(new_dir_i);
/* Unlink the original */
ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
/* We don't touch inode->i_nlink */
if (ret) { /* Oh shit. We really ought to make a single node which can do both atomically */ struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(old_dentry));
mutex_lock(&f->sem);
inc_nlink(d_inode(old_dentry)); if (f->inocache && !d_is_dir(old_dentry))
f->inocache->pino_nlink++;
mutex_unlock(&f->sem);
pr_notice("%s(): Link succeeded, unlink failed (err %d). You now have a hard link\n",
__func__, ret); /* *Wecan'tkeepthetargetindcacheafterthat. *Foronething,wecan'tafforddentryaliasesfordirectories. *Foranother,iftherewasavictim,we_can't_setnewinode *forthatsuckerandwehavetotriggermounteviction-the *callerwon'tdoitonitsownsincewearereturninganerror.
*/
d_invalidate(new_dentry);
inode_set_mtime_to_ts(new_dir_i,
inode_set_ctime_to_ts(new_dir_i, ITIME(now))); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.