[JFFS2] Remove flash offset argument from various functions.

We don't need the upper layers to deal with the physical offset. It's
_always_ c->nextblock->offset + c->sector_size - c->nextblock->free_size
so we might as well just let the actual write functions deal with that.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
This commit is contained in:
David Woodhouse 2006-05-23 00:38:06 +01:00
parent 5fa433942b
commit 9fe4854cd1
9 changed files with 135 additions and 115 deletions

View File

@ -308,7 +308,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
struct jffs2_full_dnode *fn; struct jffs2_full_dnode *fn;
struct jffs2_full_dirent *fd; struct jffs2_full_dirent *fd;
int namelen; int namelen;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret, targetlen = strlen(target); int ret, targetlen = strlen(target);
/* FIXME: If you care. We'd need to use frags for the target /* FIXME: If you care. We'd need to use frags for the target
@ -327,7 +327,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
* Just the node will do for now, though * Just the node will do for now, though
*/ */
namelen = dentry->d_name.len; namelen = dentry->d_name.len;
ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
@ -356,7 +356,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
ri->data_crc = cpu_to_je32(crc32(0, target, targetlen)); ri->data_crc = cpu_to_je32(crc32(0, target, targetlen));
ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL); fn = jffs2_write_dnode(c, f, ri, target, targetlen, ALLOC_NORMAL);
jffs2_free_raw_inode(ri); jffs2_free_raw_inode(ri);
@ -400,7 +400,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
return ret; return ret;
} }
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
if (ret) { if (ret) {
/* Eep. */ /* Eep. */
@ -433,7 +433,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
if (IS_ERR(fd)) { if (IS_ERR(fd)) {
/* dirent failed to write. Delete the inode normally /* dirent failed to write. Delete the inode normally
@ -471,7 +471,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
struct jffs2_full_dnode *fn; struct jffs2_full_dnode *fn;
struct jffs2_full_dirent *fd; struct jffs2_full_dirent *fd;
int namelen; int namelen;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret; int ret;
mode |= S_IFDIR; mode |= S_IFDIR;
@ -486,7 +486,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
* Just the node will do for now, though * Just the node will do for now, though
*/ */
namelen = dentry->d_name.len; namelen = dentry->d_name.len;
ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
JFFS2_SUMMARY_INODE_SIZE); JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
@ -512,7 +512,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
ri->data_crc = cpu_to_je32(0); ri->data_crc = cpu_to_je32(0);
ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL);
jffs2_free_raw_inode(ri); jffs2_free_raw_inode(ri);
@ -542,7 +542,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
return ret; return ret;
} }
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
if (ret) { if (ret) {
/* Eep. */ /* Eep. */
@ -575,7 +575,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
if (IS_ERR(fd)) { if (IS_ERR(fd)) {
/* dirent failed to write. Delete the inode normally /* dirent failed to write. Delete the inode normally
@ -631,7 +631,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
int namelen; int namelen;
union jffs2_device_node dev; union jffs2_device_node dev;
int devlen = 0; int devlen = 0;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret; int ret;
if (!new_valid_dev(rdev)) if (!new_valid_dev(rdev))
@ -650,7 +650,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
* Just the node will do for now, though * Just the node will do for now, though
*/ */
namelen = dentry->d_name.len; namelen = dentry->d_name.len;
ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
@ -678,7 +678,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen)); ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL); fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, ALLOC_NORMAL);
jffs2_free_raw_inode(ri); jffs2_free_raw_inode(ri);
@ -708,7 +708,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
return ret; return ret;
} }
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
if (ret) { if (ret) {
/* Eep. */ /* Eep. */
@ -744,7 +744,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
if (IS_ERR(fd)) { if (IS_ERR(fd)) {
/* dirent failed to write. Delete the inode normally /* dirent failed to write. Delete the inode normally

View File

@ -134,12 +134,12 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
struct jffs2_raw_inode ri; struct jffs2_raw_inode ri;
struct jffs2_full_dnode *fn; struct jffs2_full_dnode *fn;
uint32_t phys_ofs, alloc_len; uint32_t alloc_len;
D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n", D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
(unsigned int)inode->i_size, pageofs)); (unsigned int)inode->i_size, pageofs));
ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len, ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) if (ret)
return ret; return ret;
@ -166,7 +166,7 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
ri.data_crc = cpu_to_je32(0); ri.data_crc = cpu_to_je32(0);
fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_NORMAL); fn = jffs2_write_dnode(c, f, &ri, NULL, 0, ALLOC_NORMAL);
if (IS_ERR(fn)) { if (IS_ERR(fn)) {
ret = PTR_ERR(fn); ret = PTR_ERR(fn);

View File

@ -37,7 +37,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
unsigned char *mdata = NULL; unsigned char *mdata = NULL;
int mdatalen = 0; int mdatalen = 0;
unsigned int ivalid; unsigned int ivalid;
uint32_t phys_ofs, alloclen; uint32_t alloclen;
int ret; int ret;
D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino)); D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino));
ret = inode_change_ok(inode, iattr); ret = inode_change_ok(inode, iattr);
@ -79,7 +79,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
return -ENOMEM; return -ENOMEM;
} }
ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
jffs2_free_raw_inode(ri); jffs2_free_raw_inode(ri);
@ -131,7 +131,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
else else
ri->data_crc = cpu_to_je32(0); ri->data_crc = cpu_to_je32(0);
new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, phys_ofs, ALLOC_NORMAL); new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, ALLOC_NORMAL);
if (S_ISLNK(inode->i_mode)) if (S_ISLNK(inode->i_mode))
kfree(mdata); kfree(mdata);

View File

@ -545,7 +545,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN) if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN; alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN;
ret = jffs2_reserve_space_gc(c, alloclen, &phys_ofs, &alloclen, rawlen); ret = jffs2_reserve_space_gc(c, alloclen, &alloclen, rawlen);
/* 'rawlen' is not the exact summary size; it is only an upper estimation */ /* 'rawlen' is not the exact summary size; it is only an upper estimation */
if (ret) if (ret)
@ -626,13 +626,13 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
/* OK, all the CRCs are good; this node can just be copied as-is. */ /* OK, all the CRCs are good; this node can just be copied as-is. */
retry: retry:
nraw->flash_offset = phys_ofs; nraw->flash_offset = phys_ofs = write_ofs(c);
ret = jffs2_flash_write(c, phys_ofs, rawlen, &retlen, (char *)node); ret = jffs2_flash_write(c, phys_ofs, rawlen, &retlen, (char *)node);
if (ret || (retlen != rawlen)) { if (ret || (retlen != rawlen)) {
printk(KERN_NOTICE "Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n", printk(KERN_NOTICE "Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n",
rawlen, phys_ofs, ret, retlen); rawlen, nraw->flash_offset, ret, retlen);
if (retlen) { if (retlen) {
nraw->flash_offset |= REF_OBSOLETE; nraw->flash_offset |= REF_OBSOLETE;
jffs2_add_physical_node_ref(c, nraw, rawlen, NULL); jffs2_add_physical_node_ref(c, nraw, rawlen, NULL);
@ -653,7 +653,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
jffs2_dbg_acct_sanity_check(c,jeb); jffs2_dbg_acct_sanity_check(c,jeb);
jffs2_dbg_acct_paranoia_check(c, jeb); jffs2_dbg_acct_paranoia_check(c, jeb);
ret = jffs2_reserve_space_gc(c, rawlen, &phys_ofs, &dummy, rawlen); ret = jffs2_reserve_space_gc(c, rawlen, &dummy, rawlen);
/* this is not the exact summary size of it, /* this is not the exact summary size of it,
it is only an upper estimation */ it is only an upper estimation */
@ -696,7 +696,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
struct jffs2_node_frag *last_frag; struct jffs2_node_frag *last_frag;
union jffs2_device_node dev; union jffs2_device_node dev;
char *mdata = NULL, mdatalen = 0; char *mdata = NULL, mdatalen = 0;
uint32_t alloclen, phys_ofs, ilen; uint32_t alloclen, ilen;
int ret; int ret;
if (S_ISBLK(JFFS2_F_I_MODE(f)) || if (S_ISBLK(JFFS2_F_I_MODE(f)) ||
@ -722,7 +722,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
} }
ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &phys_ofs, &alloclen, ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &alloclen,
JFFS2_SUMMARY_INODE_SIZE); JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n", printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n",
@ -760,7 +760,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen)); ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen));
new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, phys_ofs, ALLOC_GC); new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, ALLOC_GC);
if (IS_ERR(new_fn)) { if (IS_ERR(new_fn)) {
printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn)); printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn));
@ -781,7 +781,7 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
{ {
struct jffs2_full_dirent *new_fd; struct jffs2_full_dirent *new_fd;
struct jffs2_raw_dirent rd; struct jffs2_raw_dirent rd;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret; int ret;
rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@ -803,14 +803,14 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8)); rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8));
rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize)); rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize));
ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &phys_ofs, &alloclen, ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &alloclen,
JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize)); JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize));
if (ret) { if (ret) {
printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n", printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n",
sizeof(rd)+rd.nsize, ret); sizeof(rd)+rd.nsize, ret);
return ret; return ret;
} }
new_fd = jffs2_write_dirent(c, f, &rd, fd->name, rd.nsize, phys_ofs, ALLOC_GC); new_fd = jffs2_write_dirent(c, f, &rd, fd->name, rd.nsize, ALLOC_GC);
if (IS_ERR(new_fd)) { if (IS_ERR(new_fd)) {
printk(KERN_WARNING "jffs2_write_dirent in garbage_collect_dirent failed: %ld\n", PTR_ERR(new_fd)); printk(KERN_WARNING "jffs2_write_dirent in garbage_collect_dirent failed: %ld\n", PTR_ERR(new_fd));
@ -938,7 +938,7 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
struct jffs2_raw_inode ri; struct jffs2_raw_inode ri;
struct jffs2_node_frag *frag; struct jffs2_node_frag *frag;
struct jffs2_full_dnode *new_fn; struct jffs2_full_dnode *new_fn;
uint32_t alloclen, phys_ofs, ilen; uint32_t alloclen, ilen;
int ret; int ret;
D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n", D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n",
@ -1017,14 +1017,14 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
ri.data_crc = cpu_to_je32(0); ri.data_crc = cpu_to_je32(0);
ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
ret = jffs2_reserve_space_gc(c, sizeof(ri), &phys_ofs, &alloclen, ret = jffs2_reserve_space_gc(c, sizeof(ri), &alloclen,
JFFS2_SUMMARY_INODE_SIZE); JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n", printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n",
sizeof(ri), ret); sizeof(ri), ret);
return ret; return ret;
} }
new_fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_GC); new_fn = jffs2_write_dnode(c, f, &ri, NULL, 0, ALLOC_GC);
if (IS_ERR(new_fn)) { if (IS_ERR(new_fn)) {
printk(KERN_WARNING "Error writing new hole node: %ld\n", PTR_ERR(new_fn)); printk(KERN_WARNING "Error writing new hole node: %ld\n", PTR_ERR(new_fn));
@ -1086,7 +1086,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
{ {
struct jffs2_full_dnode *new_fn; struct jffs2_full_dnode *new_fn;
struct jffs2_raw_inode ri; struct jffs2_raw_inode ri;
uint32_t alloclen, phys_ofs, offset, orig_end, orig_start; uint32_t alloclen, offset, orig_end, orig_start;
int ret = 0; int ret = 0;
unsigned char *comprbuf = NULL, *writebuf; unsigned char *comprbuf = NULL, *writebuf;
unsigned long pg; unsigned long pg;
@ -1243,7 +1243,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
uint32_t cdatalen; uint32_t cdatalen;
uint16_t comprtype = JFFS2_COMPR_NONE; uint16_t comprtype = JFFS2_COMPR_NONE;
ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN,
&alloclen, JFFS2_SUMMARY_INODE_SIZE); &alloclen, JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
@ -1280,7 +1280,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, phys_ofs, ALLOC_GC); new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, ALLOC_GC);
jffs2_free_comprbuf(comprbuf, writebuf); jffs2_free_comprbuf(comprbuf, writebuf);

View File

@ -167,6 +167,8 @@ struct jffs2_inode_cache {
#define INOCACHE_HASHSIZE 128 #define INOCACHE_HASHSIZE 128
#define write_ofs(c) ((c)->nextblock->offset + (c)->sector_size - (c)->nextblock->free_size)
/* /*
Larger representation of a raw node, kept in-core only when the Larger representation of a raw node, kept in-core only when the
struct inode for this particular ino is instantiated. struct inode for this particular ino is instantiated.
@ -325,9 +327,9 @@ extern uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c,
/* nodemgmt.c */ /* nodemgmt.c */
int jffs2_thread_should_wake(struct jffs2_sb_info *c); int jffs2_thread_should_wake(struct jffs2_sb_info *c);
int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
uint32_t *len, int prio, uint32_t sumsize); uint32_t *len, int prio, uint32_t sumsize);
int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
uint32_t *len, uint32_t sumsize); uint32_t *len, uint32_t sumsize);
int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, int jffs2_add_physical_node_ref(struct jffs2_sb_info *c,
struct jffs2_raw_node_ref *new, struct jffs2_raw_node_ref *new,
@ -339,14 +341,21 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
/* write.c */ /* write.c */
int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri); int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri);
struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode); struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode); struct jffs2_raw_inode *ri, const unsigned char *data,
uint32_t datalen, int alloc_mode);
struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
struct jffs2_raw_dirent *rd, const unsigned char *name,
uint32_t namelen, int alloc_mode);
int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
struct jffs2_raw_inode *ri, unsigned char *buf, struct jffs2_raw_inode *ri, unsigned char *buf,
uint32_t offset, uint32_t writelen, uint32_t *retlen); uint32_t offset, uint32_t writelen, uint32_t *retlen);
int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen); int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f,
int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, int namelen, struct jffs2_inode_info *dead_f, uint32_t time); struct jffs2_raw_inode *ri, const char *name, int namelen);
int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time); int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name,
int namelen, struct jffs2_inode_info *dead_f, uint32_t time);
int jffs2_do_link(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino,
uint8_t type, const char *name, int namelen, uint32_t time);
/* readinode.c */ /* readinode.c */

View File

@ -23,13 +23,12 @@
* jffs2_reserve_space - request physical space to write nodes to flash * jffs2_reserve_space - request physical space to write nodes to flash
* @c: superblock info * @c: superblock info
* @minsize: Minimum acceptable size of allocation * @minsize: Minimum acceptable size of allocation
* @ofs: Returned value of node offset
* @len: Returned value of allocation length * @len: Returned value of allocation length
* @prio: Allocation type - ALLOC_{NORMAL,DELETION} * @prio: Allocation type - ALLOC_{NORMAL,DELETION}
* *
* Requests a block of physical space on the flash. Returns zero for success * Requests a block of physical space on the flash. Returns zero for success
* and puts 'ofs' and 'len' into the appriopriate place, or returns -ENOSPC * and puts 'len' into the appropriate place, or returns -ENOSPC or other
* or other error if appropriate. * error if appropriate. Doesn't return len since that's
* *
* If it returns zero, jffs2_reserve_space() also downs the per-filesystem * If it returns zero, jffs2_reserve_space() also downs the per-filesystem
* allocation semaphore, to prevent more than one allocation from being * allocation semaphore, to prevent more than one allocation from being
@ -40,9 +39,9 @@
*/ */
static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
uint32_t *ofs, uint32_t *len, uint32_t sumsize); uint32_t *len, uint32_t sumsize);
int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
uint32_t *len, int prio, uint32_t sumsize) uint32_t *len, int prio, uint32_t sumsize)
{ {
int ret = -EAGAIN; int ret = -EAGAIN;
@ -132,7 +131,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
} }
ret = jffs2_do_reserve_space(c, minsize, ofs, len, sumsize); ret = jffs2_do_reserve_space(c, minsize, len, sumsize);
if (ret) { if (ret) {
D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret)); D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret));
} }
@ -143,7 +142,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
return ret; return ret;
} }
int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
uint32_t *len, uint32_t sumsize) uint32_t *len, uint32_t sumsize)
{ {
int ret = -EAGAIN; int ret = -EAGAIN;
@ -153,7 +152,7 @@ int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
while(ret == -EAGAIN) { while(ret == -EAGAIN) {
ret = jffs2_do_reserve_space(c, minsize, ofs, len, sumsize); ret = jffs2_do_reserve_space(c, minsize, len, sumsize);
if (ret) { if (ret) {
D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret)); D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret));
} }
@ -259,7 +258,8 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c)
} }
/* Called with alloc sem _and_ erase_completion_lock */ /* Called with alloc sem _and_ erase_completion_lock */
static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len, uint32_t sumsize) static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
uint32_t *len, uint32_t sumsize)
{ {
struct jffs2_eraseblock *jeb = c->nextblock; struct jffs2_eraseblock *jeb = c->nextblock;
uint32_t reserved_size; /* for summary information at the end of the jeb */ uint32_t reserved_size; /* for summary information at the end of the jeb */
@ -349,7 +349,6 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uin
} }
/* OK, jeb (==c->nextblock) is now pointing at a block which definitely has /* OK, jeb (==c->nextblock) is now pointing at a block which definitely has
enough space */ enough space */
*ofs = jeb->offset + (c->sector_size - jeb->free_size);
*len = jeb->free_size - reserved_size; *len = jeb->free_size - reserved_size;
if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size && if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size &&
@ -365,7 +364,8 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uin
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
} }
D1(printk(KERN_DEBUG "jffs2_do_reserve_space(): Giving 0x%x bytes at 0x%x\n", *len, *ofs)); D1(printk(KERN_DEBUG "jffs2_do_reserve_space(): Giving 0x%x bytes at 0x%x\n",
*len, jeb->offset + (c->sector_size - jeb->free_size)));
return 0; return 0;
} }

View File

@ -265,12 +265,14 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
/* ... and get an allocation of space from a shiny new block instead */ /* ... and get an allocation of space from a shiny new block instead */
ret = jffs2_reserve_space_gc(c, end-start, &ofs, &len, JFFS2_SUMMARY_NOSUM_SIZE); ret = jffs2_reserve_space_gc(c, end-start, &len, JFFS2_SUMMARY_NOSUM_SIZE);
if (ret) { if (ret) {
printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n"); printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n");
kfree(buf); kfree(buf);
return; return;
} }
ofs = write_ofs(c);
if (end-start >= c->wbuf_pagesize) { if (end-start >= c->wbuf_pagesize) {
/* Need to do another write immediately, but it's possible /* Need to do another write immediately, but it's possible
that this is just because the wbuf itself is completely that this is just because the wbuf itself is completely

View File

@ -56,12 +56,15 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint
/* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it, /* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it,
write it to the flash, link it into the existing inode/fragment list */ write it to the flash, link it into the existing inode/fragment list */
struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode) struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
struct jffs2_raw_inode *ri, const unsigned char *data,
uint32_t datalen, int alloc_mode)
{ {
struct jffs2_raw_node_ref *raw; struct jffs2_raw_node_ref *raw;
struct jffs2_full_dnode *fn; struct jffs2_full_dnode *fn;
size_t retlen; size_t retlen;
uint32_t flash_ofs;
struct kvec vecs[2]; struct kvec vecs[2];
int ret; int ret;
int retried = 0; int retried = 0;
@ -77,8 +80,6 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
vecs[1].iov_base = (unsigned char *)data; vecs[1].iov_base = (unsigned char *)data;
vecs[1].iov_len = datalen; vecs[1].iov_len = datalen;
jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) { if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) {
printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen); printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen);
} }
@ -102,7 +103,9 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
retry: retry:
fn->raw = raw; fn->raw = raw;
raw->flash_offset = flash_ofs; raw->flash_offset = flash_ofs = write_ofs(c);
jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) { if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) {
BUG_ON(!retried); BUG_ON(!retried);
@ -147,19 +150,20 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
jffs2_dbg_acct_paranoia_check(c, jeb); jffs2_dbg_acct_paranoia_check(c, jeb);
if (alloc_mode == ALLOC_GC) { if (alloc_mode == ALLOC_GC) {
ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &dummy,
&dummy, JFFS2_SUMMARY_INODE_SIZE); JFFS2_SUMMARY_INODE_SIZE);
} else { } else {
/* Locking pain */ /* Locking pain */
up(&f->sem); up(&f->sem);
jffs2_complete_reservation(c); jffs2_complete_reservation(c);
ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy,
&dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE); alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
down(&f->sem); down(&f->sem);
} }
if (!ret) { if (!ret) {
flash_ofs = write_ofs(c);
D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
jffs2_dbg_acct_sanity_check(c,jeb); jffs2_dbg_acct_sanity_check(c,jeb);
@ -200,12 +204,15 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
return fn; return fn;
} }
struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode) struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
struct jffs2_raw_dirent *rd, const unsigned char *name,
uint32_t namelen, int alloc_mode)
{ {
struct jffs2_raw_node_ref *raw; struct jffs2_raw_node_ref *raw;
struct jffs2_full_dirent *fd; struct jffs2_full_dirent *fd;
size_t retlen; size_t retlen;
struct kvec vecs[2]; struct kvec vecs[2];
uint32_t flash_ofs = write_ofs(c);
int retried = 0; int retried = 0;
int ret; int ret;
@ -286,19 +293,20 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
jffs2_dbg_acct_paranoia_check(c, jeb); jffs2_dbg_acct_paranoia_check(c, jeb);
if (alloc_mode == ALLOC_GC) { if (alloc_mode == ALLOC_GC) {
ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs, ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &dummy,
&dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); JFFS2_SUMMARY_DIRENT_SIZE(namelen));
} else { } else {
/* Locking pain */ /* Locking pain */
up(&f->sem); up(&f->sem);
jffs2_complete_reservation(c); jffs2_complete_reservation(c);
ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy,
&dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
down(&f->sem); down(&f->sem);
} }
if (!ret) { if (!ret) {
flash_ofs = write_ofs(c);
D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
jffs2_dbg_acct_sanity_check(c,jeb); jffs2_dbg_acct_sanity_check(c,jeb);
jffs2_dbg_acct_paranoia_check(c, jeb); jffs2_dbg_acct_paranoia_check(c, jeb);
@ -339,14 +347,14 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
struct jffs2_full_dnode *fn; struct jffs2_full_dnode *fn;
unsigned char *comprbuf = NULL; unsigned char *comprbuf = NULL;
uint16_t comprtype = JFFS2_COMPR_NONE; uint16_t comprtype = JFFS2_COMPR_NONE;
uint32_t phys_ofs, alloclen; uint32_t alloclen;
uint32_t datalen, cdatalen; uint32_t datalen, cdatalen;
int retried = 0; int retried = 0;
retry: retry:
D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset)); D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset));
ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN,
&alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
if (ret) { if (ret) {
D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
@ -374,7 +382,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, ALLOC_NORETRY); fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, ALLOC_NORETRY);
jffs2_free_comprbuf(comprbuf, buf); jffs2_free_comprbuf(comprbuf, buf);
@ -428,13 +436,13 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
struct jffs2_raw_dirent *rd; struct jffs2_raw_dirent *rd;
struct jffs2_full_dnode *fn; struct jffs2_full_dnode *fn;
struct jffs2_full_dirent *fd; struct jffs2_full_dirent *fd;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret; int ret;
/* Try to reserve enough space for both node and dirent. /* Try to reserve enough space for both node and dirent.
* Just the node will do for now, though * Just the node will do for now, though
*/ */
ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
JFFS2_SUMMARY_INODE_SIZE); JFFS2_SUMMARY_INODE_SIZE);
D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
if (ret) { if (ret) {
@ -445,7 +453,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
ri->data_crc = cpu_to_je32(0); ri->data_crc = cpu_to_je32(0);
ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL);
D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n", D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n",
jemode_to_cpu(ri->mode))); jemode_to_cpu(ri->mode)));
@ -464,7 +472,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
up(&f->sem); up(&f->sem);
jffs2_complete_reservation(c); jffs2_complete_reservation(c);
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
if (ret) { if (ret) {
@ -496,7 +504,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
jffs2_free_raw_dirent(rd); jffs2_free_raw_dirent(rd);
@ -525,7 +533,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
{ {
struct jffs2_raw_dirent *rd; struct jffs2_raw_dirent *rd;
struct jffs2_full_dirent *fd; struct jffs2_full_dirent *fd;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret; int ret;
if (1 /* alternative branch needs testing */ || if (1 /* alternative branch needs testing */ ||
@ -536,7 +544,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
if (!rd) if (!rd)
return -ENOMEM; return -ENOMEM;
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
if (ret) { if (ret) {
jffs2_free_raw_dirent(rd); jffs2_free_raw_dirent(rd);
@ -560,7 +568,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION); fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_DELETION);
jffs2_free_raw_dirent(rd); jffs2_free_raw_dirent(rd);
@ -639,14 +647,14 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
{ {
struct jffs2_raw_dirent *rd; struct jffs2_raw_dirent *rd;
struct jffs2_full_dirent *fd; struct jffs2_full_dirent *fd;
uint32_t alloclen, phys_ofs; uint32_t alloclen;
int ret; int ret;
rd = jffs2_alloc_raw_dirent(); rd = jffs2_alloc_raw_dirent();
if (!rd) if (!rd)
return -ENOMEM; return -ENOMEM;
ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
if (ret) { if (ret) {
jffs2_free_raw_dirent(rd); jffs2_free_raw_dirent(rd);
@ -672,7 +680,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
jffs2_free_raw_dirent(rd); jffs2_free_raw_dirent(rd);

View File

@ -49,9 +49,9 @@
* is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum(). * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
* If xd need to call do_verify_xattr_datum() at first, it's called before calling * If xd need to call do_verify_xattr_datum() at first, it's called before calling
* do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum(). * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
* save_xattr_datum(c, xd, phys_ofs) * save_xattr_datum(c, xd)
* is used to write xdatum to medium. xd->version will be incremented. * is used to write xdatum to medium. xd->version will be incremented.
* create_xattr_datum(c, xprefix, xname, xvalue, xsize, phys_ofs) * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
* is used to create new xdatum and write to medium. * is used to create new xdatum and write to medium.
* -------------------------------------------------- */ * -------------------------------------------------- */
@ -301,7 +301,7 @@ static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
return rc; return rc;
} }
static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, uint32_t phys_ofs) static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{ {
/* must be called under down_write(xattr_sem) */ /* must be called under down_write(xattr_sem) */
struct jffs2_raw_xattr rx; struct jffs2_raw_xattr rx;
@ -309,6 +309,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
struct kvec vecs[2]; struct kvec vecs[2];
uint32_t length; uint32_t length;
int rc, totlen; int rc, totlen;
uint32_t phys_ofs = write_ofs(c);
BUG_ON(!xd->xname); BUG_ON(!xd->xname);
@ -369,8 +370,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
int xprefix, const char *xname, int xprefix, const char *xname,
const char *xvalue, int xsize, const char *xvalue, int xsize)
uint32_t phys_ofs)
{ {
/* must be called under down_write(xattr_sem) */ /* must be called under down_write(xattr_sem) */
struct jffs2_xattr_datum *xd; struct jffs2_xattr_datum *xd;
@ -419,7 +419,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
xd->value_len = xsize; xd->value_len = xsize;
xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len); xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
rc = save_xattr_datum(c, xd, phys_ofs); rc = save_xattr_datum(c, xd);
if (rc) { if (rc) {
kfree(xd->xname); kfree(xd->xname);
jffs2_free_xattr_datum(xd); jffs2_free_xattr_datum(xd);
@ -446,9 +446,9 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
* delete_xattr_ref(c, ref) * delete_xattr_ref(c, ref)
* is used to delete jffs2_xattr_ref object. If the reference counter of xdatum * is used to delete jffs2_xattr_ref object. If the reference counter of xdatum
* is refered by this xref become 0, delete_xattr_datum() is called later. * is refered by this xref become 0, delete_xattr_datum() is called later.
* save_xattr_ref(c, ref, phys_ofs) * save_xattr_ref(c, ref)
* is used to write xref to medium. * is used to write xref to medium.
* create_xattr_ref(c, ic, xd, phys_ofs) * create_xattr_ref(c, ic, xd)
* is used to create a new xref and write to medium. * is used to create a new xref and write to medium.
* jffs2_xattr_delete_inode(c, ic) * jffs2_xattr_delete_inode(c, ic)
* is called to remove xrefs related to obsolete inode when inode is unlinked. * is called to remove xrefs related to obsolete inode when inode is unlinked.
@ -554,12 +554,13 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re
jffs2_free_xattr_ref(ref); jffs2_free_xattr_ref(ref);
} }
static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, uint32_t phys_ofs) static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{ {
/* must be called under down_write(xattr_sem) */ /* must be called under down_write(xattr_sem) */
struct jffs2_raw_node_ref *raw; struct jffs2_raw_node_ref *raw;
struct jffs2_raw_xref rr; struct jffs2_raw_xref rr;
uint32_t length; uint32_t length;
uint32_t phys_ofs = write_ofs(c);
int ret; int ret;
raw = jffs2_alloc_raw_node_ref(); raw = jffs2_alloc_raw_node_ref();
@ -604,7 +605,7 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
} }
static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic,
struct jffs2_xattr_datum *xd, uint32_t phys_ofs) struct jffs2_xattr_datum *xd)
{ {
/* must be called under down_write(xattr_sem) */ /* must be called under down_write(xattr_sem) */
struct jffs2_xattr_ref *ref; struct jffs2_xattr_ref *ref;
@ -616,7 +617,7 @@ static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct
ref->ic = ic; ref->ic = ic;
ref->xd = xd; ref->xd = xd;
ret = save_xattr_ref(c, ref, phys_ofs); ret = save_xattr_ref(c, ref);
if (ret) { if (ret) {
jffs2_free_xattr_ref(ref); jffs2_free_xattr_ref(ref);
return ERR_PTR(ret); return ERR_PTR(ret);
@ -1062,7 +1063,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
struct jffs2_inode_cache *ic = f->inocache; struct jffs2_inode_cache *ic = f->inocache;
struct jffs2_xattr_datum *xd; struct jffs2_xattr_datum *xd;
struct jffs2_xattr_ref *ref, *newref, **pref; struct jffs2_xattr_ref *ref, *newref, **pref;
uint32_t phys_ofs, length, request; uint32_t length, request;
int rc; int rc;
rc = check_xattr_ref_inode(c, ic); rc = check_xattr_ref_inode(c, ic);
@ -1070,7 +1071,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
return rc; return rc;
request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size); request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
rc = jffs2_reserve_space(c, request, &phys_ofs, &length, rc = jffs2_reserve_space(c, request, &length,
ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE); ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
if (rc) { if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@ -1117,7 +1118,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
goto out; goto out;
} }
found: found:
xd = create_xattr_datum(c, xprefix, xname, buffer, size, phys_ofs); xd = create_xattr_datum(c, xprefix, xname, buffer, size);
if (IS_ERR(xd)) { if (IS_ERR(xd)) {
rc = PTR_ERR(xd); rc = PTR_ERR(xd);
goto out; goto out;
@ -1127,7 +1128,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
/* create xattr_ref */ /* create xattr_ref */
request = PAD(sizeof(struct jffs2_raw_xref)); request = PAD(sizeof(struct jffs2_raw_xref));
rc = jffs2_reserve_space(c, request, &phys_ofs, &length, rc = jffs2_reserve_space(c, request, &length,
ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
if (rc) { if (rc) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@ -1141,7 +1142,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
down_write(&c->xattr_sem); down_write(&c->xattr_sem);
if (ref) if (ref)
*pref = ref->next; *pref = ref->next;
newref = create_xattr_ref(c, ic, xd, phys_ofs); newref = create_xattr_ref(c, ic, xd);
if (IS_ERR(newref)) { if (IS_ERR(newref)) {
if (ref) { if (ref) {
ref->next = ic->xref; ref->next = ic->xref;
@ -1170,7 +1171,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
* -------------------------------------------------- */ * -------------------------------------------------- */
int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
{ {
uint32_t phys_ofs, totlen, length, old_ofs; uint32_t totlen, length, old_ofs;
int rc = -EINVAL; int rc = -EINVAL;
down_write(&c->xattr_sem); down_write(&c->xattr_sem);
@ -1190,13 +1191,13 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
} else if (unlikely(rc < 0)) } else if (unlikely(rc < 0))
goto out; goto out;
} }
rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XATTR_SIZE); rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
if (rc || length < totlen) { if (rc || length < totlen) {
JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen); JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen);
rc = rc ? rc : -EBADFD; rc = rc ? rc : -EBADFD;
goto out; goto out;
} }
rc = save_xattr_datum(c, xd, phys_ofs); rc = save_xattr_datum(c, xd);
if (!rc) if (!rc)
dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n", dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
xd->xid, xd->version, old_ofs, ref_offset(xd->node)); xd->xid, xd->version, old_ofs, ref_offset(xd->node));
@ -1208,7 +1209,7 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
{ {
uint32_t phys_ofs, totlen, length, old_ofs; uint32_t totlen, length, old_ofs;
int rc = -EINVAL; int rc = -EINVAL;
down_write(&c->xattr_sem); down_write(&c->xattr_sem);
@ -1219,14 +1220,14 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
if (totlen != sizeof(struct jffs2_raw_xref)) if (totlen != sizeof(struct jffs2_raw_xref))
goto out; goto out;
rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XREF_SIZE); rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
if (rc || length < totlen) { if (rc || length < totlen) {
JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n", JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n",
__FUNCTION__, rc, totlen); __FUNCTION__, rc, totlen);
rc = rc ? rc : -EBADFD; rc = rc ? rc : -EBADFD;
goto out; goto out;
} }
rc = save_xattr_ref(c, ref, phys_ofs); rc = save_xattr_ref(c, ref);
if (!rc) if (!rc)
dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n", dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));