[PATCH] swswsup: return correct load_image error
[deliverable/linux.git] / fs / jffs2 / write.c
index 0a194759bbbdc9a34e0f50d1e1310c0a7c416630..1342f0158e9b0d0da2565c99c18eb5f088c501a5 100644 (file)
@@ -7,7 +7,7 @@
  *
  * For licensing information, see the file 'LICENCE' in this directory.
  *
- * $Id: write.c,v 1.95 2005/08/17 13:46:23 dedekind Exp $
+ * $Id: write.c,v 1.97 2005/11/07 11:14:42 gleixner Exp $
  *
  */
 
@@ -54,7 +54,7 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint
        return 0;
 }
 
-/* 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 */
 
 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)
@@ -86,7 +86,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
        raw = jffs2_alloc_raw_node_ref();
        if (!raw)
                return ERR_PTR(-ENOMEM);
-       
+
        fn = jffs2_alloc_full_dnode();
        if (!fn) {
                jffs2_free_raw_node_ref(raw);
@@ -110,7 +110,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
        if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) {
                BUG_ON(!retried);
                D1(printk(KERN_DEBUG "jffs2_write_dnode : dnode_version %d, "
-                               "highest version %d -> updating dnode\n", 
+                               "highest version %d -> updating dnode\n",
                                je32_to_cpu(ri->version), f->highest_version));
                ri->version = cpu_to_je32(++f->highest_version);
                ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
@@ -120,7 +120,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
                                 (alloc_mode==ALLOC_GC)?0:f->inocache->ino);
 
        if (ret || (retlen != sizeof(*ri) + datalen)) {
-               printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n", 
+               printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
                       sizeof(*ri)+datalen, flash_ofs, ret, retlen);
 
                /* Mark the space as dirtied */
@@ -128,10 +128,10 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
                        /* Doesn't belong to any inode */
                        raw->next_in_ino = NULL;
 
-                       /* Don't change raw->size to match retlen. We may have 
+                       /* Don't change raw->size to match retlen. We may have
                           written the node header already, and only the data will
                           seem corrupted, in which case the scan would skip over
-                          any node we write before the original intended end of 
+                          any node we write before the original intended end of
                           this node */
                        raw->flash_offset |= REF_OBSOLETE;
                        jffs2_add_physical_node_ref(c, raw);
@@ -148,18 +148,20 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
                        retried = 1;
 
                        D1(printk(KERN_DEBUG "Retrying failed write.\n"));
-                       
+
                        jffs2_dbg_acct_sanity_check(c,jeb);
                        jffs2_dbg_acct_paranoia_check(c, jeb);
 
                        if (alloc_mode == ALLOC_GC) {
-                               ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, &dummy);
+                               ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs,
+                                                       &dummy, JFFS2_SUMMARY_INODE_SIZE);
                        } else {
                                /* Locking pain */
                                up(&f->sem);
                                jffs2_complete_reservation(c);
-                       
-                               ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, &dummy, alloc_mode);
+
+                               ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs,
+                                                       &dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
                                down(&f->sem);
                        }
 
@@ -179,9 +181,9 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
                return ERR_PTR(ret?ret:-EIO);
        }
        /* Mark the space used */
-       /* If node covers at least a whole page, or if it starts at the 
-          beginning of a page and runs to the end of the file, or if 
-          it's a hole node, mark it REF_PRISTINE, else REF_NORMAL. 
+       /* If node covers at least a whole page, or if it starts at the
+          beginning of a page and runs to the end of the file, or if
+          it's a hole node, mark it REF_PRISTINE, else REF_NORMAL.
        */
        if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) ||
            ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) &&
@@ -199,7 +201,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
        spin_unlock(&c->erase_completion_lock);
 
        D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n",
-                 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize), 
+                 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize),
                  je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc),
                  je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen)));
 
@@ -219,7 +221,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
        int retried = 0;
        int ret;
 
-       D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n", 
+       D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n",
                  je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
                  je32_to_cpu(rd->name_crc)));
 
@@ -233,7 +235,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
        vecs[0].iov_len = sizeof(*rd);
        vecs[1].iov_base = (unsigned char *)name;
        vecs[1].iov_len = namelen;
-       
+
        jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
 
        raw = jffs2_alloc_raw_node_ref();
@@ -274,7 +276,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
        ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen,
                                 (alloc_mode==ALLOC_GC)?0:je32_to_cpu(rd->pino));
        if (ret || (retlen != sizeof(*rd) + namelen)) {
-               printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n", 
+               printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
                               sizeof(*rd)+namelen, flash_ofs, ret, retlen);
                /* Mark the space as dirtied */
                if (retlen) {
@@ -299,13 +301,15 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
                        jffs2_dbg_acct_paranoia_check(c, jeb);
 
                        if (alloc_mode == ALLOC_GC) {
-                               ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs, &dummy);
+                               ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs,
+                                                       &dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
                        } else {
                                /* Locking pain */
                                up(&f->sem);
                                jffs2_complete_reservation(c);
-                       
-                               ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, &dummy, alloc_mode);
+
+                               ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs,
+                                                       &dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
                                down(&f->sem);
                        }
 
@@ -342,7 +346,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
    we don't have to go digging in struct inode or its equivalent. It should set:
    mode, uid, gid, (starting)isize, atime, ctime, mtime */
 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)
 {
        int ret = 0;
@@ -350,7 +354,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
 
                D1(printk(KERN_DEBUG "jffs2_write_inode_range(): Ino #%u, ofs 0x%x, len 0x%x\n",
                  f->inocache->ino, offset, writelen));
-               
+
        while(writelen) {
                struct jffs2_full_dnode *fn;
                unsigned char *comprbuf = NULL;
@@ -362,7 +366,8 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
        retry:
                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, &alloclen, ALLOC_NORMAL);
+               ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs,
+                                       &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
                if (ret) {
                        D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
                        break;
@@ -446,10 +451,11 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
        uint32_t alloclen, phys_ofs;
        int ret;
 
-       /* Try to reserve enough space for both node and dirent. 
-        * Just the node will do for now, though 
+       /* Try to reserve enough space for both node and dirent.
+        * 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), &phys_ofs, &alloclen, ALLOC_NORMAL,
+                               JFFS2_SUMMARY_INODE_SIZE);
        D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
        if (ret) {
                up(&f->sem);
@@ -471,15 +477,16 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
                jffs2_complete_reservation(c);
                return PTR_ERR(fn);
        }
-       /* No data here. Only a metadata node, which will be 
+       /* No data here. Only a metadata node, which will be
           obsoleted by the first data write
        */
        f->metadata = fn;
 
        up(&f->sem);
        jffs2_complete_reservation(c);
-       ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
-               
+       ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
+                               ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
+
        if (ret) {
                /* Eep. */
                D1(printk(KERN_DEBUG "jffs2_reserve_space() for dirent failed\n"));
@@ -512,9 +519,9 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
        fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL);
 
        jffs2_free_raw_dirent(rd);
-       
+
        if (IS_ERR(fd)) {
-               /* dirent failed to write. Delete the inode normally 
+               /* dirent failed to write. Delete the inode normally
                   as if it were the final unlink() */
                jffs2_complete_reservation(c);
                up(&dir_f->sem);
@@ -541,7 +548,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
        uint32_t alloclen, phys_ofs;
        int ret;
 
-       if (1 /* alternative branch needs testing */ || 
+       if (1 /* alternative branch needs testing */ ||
            !jffs2_can_mark_obsolete(c)) {
                /* We can't mark stuff obsolete on the medium. We need to write a deletion dirent */
 
@@ -549,7 +556,8 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
                if (!rd)
                        return -ENOMEM;
 
-               ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_DELETION);
+               ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
+                                       ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
                if (ret) {
                        jffs2_free_raw_dirent(rd);
                        return ret;
@@ -562,7 +570,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
                rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
                rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
                rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
-               
+
                rd->pino = cpu_to_je32(dir_f->inocache->ino);
                rd->version = cpu_to_je32(++dir_f->highest_version);
                rd->ino = cpu_to_je32(0);
@@ -573,7 +581,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
                rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
                fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION);
-               
+
                jffs2_free_raw_dirent(rd);
 
                if (IS_ERR(fd)) {
@@ -592,7 +600,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
                down(&dir_f->sem);
 
                while ((*prev) && (*prev)->nhash <= nhash) {
-                       if ((*prev)->nhash == nhash && 
+                       if ((*prev)->nhash == nhash &&
                            !memcmp((*prev)->name, name, namelen) &&
                            !(*prev)->name[namelen]) {
                                struct jffs2_full_dirent *this = *prev;
@@ -613,7 +621,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
        /* dead_f is NULL if this was a rename not a real unlink */
        /* Also catch the !f->inocache case, where there was a dirent
           pointing to an inode which didn't exist. */
-       if (dead_f && dead_f->inocache) { 
+       if (dead_f && dead_f->inocache) {
 
                down(&dead_f->sem);
 
@@ -621,9 +629,9 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
                        while (dead_f->dents) {
                                /* There can be only deleted ones */
                                fd = dead_f->dents;
-                               
+
                                dead_f->dents = fd->next;
-                               
+
                                if (fd->ino) {
                                        printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n",
                                               dead_f->inocache->ino, fd->name, fd->ino);
@@ -658,12 +666,13 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
        if (!rd)
                return -ENOMEM;
 
-       ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, ALLOC_NORMAL);
+       ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen,
+                               ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
        if (ret) {
                jffs2_free_raw_dirent(rd);
                return ret;
        }
-       
+
        down(&dir_f->sem);
 
        /* Build a deletion node */
@@ -684,7 +693,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
        rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
        fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL);
-       
+
        jffs2_free_raw_dirent(rd);
 
        if (IS_ERR(fd)) {
This page took 0.031602 seconds and 5 git commands to generate.