blob: 30d175b6d290698fad6a38f6bbafba755eee90b4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
David Woodhousec00c3102007-04-25 14:16:47 +01004 * Copyright © 2001-2007 Red Hat, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
12#include <linux/kernel.h>
13#include <linux/fs.h>
14#include <linux/crc32.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/pagemap.h>
16#include <linux/mtd/mtd.h>
17#include "nodelist.h"
18#include "compr.h"
19
20
David Woodhouse27c72b02008-05-01 18:47:17 +010021int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
22 uint32_t mode, struct jffs2_raw_inode *ri)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
24 struct jffs2_inode_cache *ic;
25
26 ic = jffs2_alloc_inode_cache();
27 if (!ic) {
28 return -ENOMEM;
29 }
30
31 memset(ic, 0, sizeof(*ic));
32
33 f->inocache = ic;
David Woodhouse27c72b02008-05-01 18:47:17 +010034 f->inocache->pino_nlink = 1; /* Will be overwritten shortly for directories */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 f->inocache->state = INO_STATE_PRESENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 jffs2_add_ino_cache(c, f->inocache);
David Woodhouse7d200962005-04-13 14:22:38 +010039 D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino));
40 ri->ino = cpu_to_je32(f->inocache->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
43 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
44 ri->totlen = cpu_to_je32(PAD(sizeof(*ri)));
45 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
46 ri->mode = cpu_to_jemode(mode);
47
48 f->highest_version = 1;
49 ri->version = cpu_to_je32(f->highest_version);
50
51 return 0;
52}
53
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000054/* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 write it to the flash, link it into the existing inode/fragment list */
56
David Woodhouse9fe48542006-05-23 00:38:06 +010057struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
58 struct jffs2_raw_inode *ri, const unsigned char *data,
59 uint32_t datalen, int alloc_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61{
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 struct jffs2_full_dnode *fn;
63 size_t retlen;
David Woodhouse9fe48542006-05-23 00:38:06 +010064 uint32_t flash_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 struct kvec vecs[2];
66 int ret;
67 int retried = 0;
68 unsigned long cnt = 2;
69
70 D1(if(je32_to_cpu(ri->hdr_crc) != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
71 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dnode()\n");
72 BUG();
73 }
74 );
75 vecs[0].iov_base = ri;
76 vecs[0].iov_len = sizeof(*ri);
77 vecs[1].iov_base = (unsigned char *)data;
78 vecs[1].iov_len = datalen;
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) {
81 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);
82 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 fn = jffs2_alloc_full_dnode();
David Woodhouse2f785402006-05-24 02:04:45 +010085 if (!fn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 /* check number of valid vecs */
89 if (!datalen || !data)
90 cnt = 1;
91 retry:
David Woodhouse2f785402006-05-24 02:04:45 +010092 flash_ofs = write_ofs(c);
David Woodhouse9fe48542006-05-23 00:38:06 +010093
94 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Estelle Hammache9b88f472005-01-28 18:53:05 +000096 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) {
97 BUG_ON(!retried);
98 D1(printk(KERN_DEBUG "jffs2_write_dnode : dnode_version %d, "
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000099 "highest version %d -> updating dnode\n",
Estelle Hammache9b88f472005-01-28 18:53:05 +0000100 je32_to_cpu(ri->version), f->highest_version));
101 ri->version = cpu_to_je32(++f->highest_version);
102 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
Estelle Hammachee4803c32005-01-24 21:13:42 +0000103 }
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen,
106 (alloc_mode==ALLOC_GC)?0:f->inocache->ino);
107
108 if (ret || (retlen != sizeof(*ri) + datalen)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000109 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 sizeof(*ri)+datalen, flash_ofs, ret, retlen);
111
112 /* Mark the space as dirtied */
113 if (retlen) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000114 /* Don't change raw->size to match retlen. We may have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 written the node header already, and only the data will
116 seem corrupted, in which case the scan would skip over
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000117 any node we write before the original intended end of
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 this node */
David Woodhouse2f785402006-05-24 02:04:45 +0100119 jffs2_add_physical_node_ref(c, flash_ofs | REF_OBSOLETE, PAD(sizeof(*ri)+datalen), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100121 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", flash_ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
David Woodhouse2f785402006-05-24 02:04:45 +0100123 if (!retried && alloc_mode != ALLOC_NORETRY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* Try to reallocate space and retry */
125 uint32_t dummy;
126 struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size];
127
128 retried = 1;
129
130 D1(printk(KERN_DEBUG "Retrying failed write.\n"));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000131
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100132 jffs2_dbg_acct_sanity_check(c,jeb);
133 jffs2_dbg_acct_paranoia_check(c, jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 if (alloc_mode == ALLOC_GC) {
David Woodhouse9fe48542006-05-23 00:38:06 +0100136 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &dummy,
137 JFFS2_SUMMARY_INODE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 } else {
139 /* Locking pain */
David Woodhouseced22072008-04-22 15:13:40 +0100140 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 jffs2_complete_reservation(c);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000142
David Woodhouse9fe48542006-05-23 00:38:06 +0100143 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy,
144 alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
David Woodhouseced22072008-04-22 15:13:40 +0100145 mutex_lock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
148 if (!ret) {
David Woodhouse9fe48542006-05-23 00:38:06 +0100149 flash_ofs = write_ofs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
151
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100152 jffs2_dbg_acct_sanity_check(c,jeb);
153 jffs2_dbg_acct_paranoia_check(c, jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 goto retry;
156 }
157 D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159 /* Release the full_dnode which is now useless, and return */
160 jffs2_free_full_dnode(fn);
161 return ERR_PTR(ret?ret:-EIO);
162 }
163 /* Mark the space used */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000164 /* If node covers at least a whole page, or if it starts at the
165 beginning of a page and runs to the end of the file, or if
166 it's a hole node, mark it REF_PRISTINE, else REF_NORMAL.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 */
168 if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) ||
169 ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) &&
170 (je32_to_cpu(ri->dsize)+je32_to_cpu(ri->offset) == je32_to_cpu(ri->isize)))) {
David Woodhouse2f785402006-05-24 02:04:45 +0100171 flash_ofs |= REF_PRISTINE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100173 flash_ofs |= REF_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
David Woodhouse2f785402006-05-24 02:04:45 +0100175 fn->raw = jffs2_add_physical_node_ref(c, flash_ofs, PAD(sizeof(*ri)+datalen), f->inocache);
Joakim Tjernlund5bd5c032007-06-24 19:22:29 +0200176 if (IS_ERR(fn->raw)) {
177 void *hold_err = fn->raw;
178 /* Release the full_dnode which is now useless, and return */
179 jffs2_free_full_dnode(fn);
David Howellse231c2e2008-02-07 00:15:26 -0800180 return ERR_CAST(hold_err);
Joakim Tjernlund5bd5c032007-06-24 19:22:29 +0200181 }
David Woodhouse2f785402006-05-24 02:04:45 +0100182 fn->ofs = je32_to_cpu(ri->offset);
183 fn->size = je32_to_cpu(ri->dsize);
184 fn->frags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 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",
David Woodhouse2f785402006-05-24 02:04:45 +0100187 flash_ofs & ~3, flash_ofs & 3, je32_to_cpu(ri->dsize),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc),
189 je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen)));
190
191 if (retried) {
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100192 jffs2_dbg_acct_sanity_check(c,NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
195 return fn;
196}
197
David Woodhouse9fe48542006-05-23 00:38:06 +0100198struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
199 struct jffs2_raw_dirent *rd, const unsigned char *name,
200 uint32_t namelen, int alloc_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 struct jffs2_full_dirent *fd;
203 size_t retlen;
204 struct kvec vecs[2];
David Woodhouse2f785402006-05-24 02:04:45 +0100205 uint32_t flash_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 int retried = 0;
207 int ret;
208
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000209 D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
211 je32_to_cpu(rd->name_crc)));
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
214 printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n");
215 BUG();
David Woodhouse2f785402006-05-24 02:04:45 +0100216 });
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
David Woodhouse69ca4372007-10-13 11:33:50 +0100218 if (strnlen(name, namelen) != namelen) {
219 /* This should never happen, but seems to have done on at least one
220 occasion: https://dev.laptop.org/ticket/4184 */
221 printk(KERN_CRIT "Error in jffs2_write_dirent() -- name contains zero bytes!\n");
222 printk(KERN_CRIT "Directory inode #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x\n",
223 je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
224 je32_to_cpu(rd->name_crc));
225 WARN_ON(1);
226 return ERR_PTR(-EIO);
227 }
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 vecs[0].iov_base = rd;
230 vecs[0].iov_len = sizeof(*rd);
231 vecs[1].iov_base = (unsigned char *)name;
232 vecs[1].iov_len = namelen;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 fd = jffs2_alloc_full_dirent(namelen+1);
David Woodhouse2f785402006-05-24 02:04:45 +0100235 if (!fd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 fd->version = je32_to_cpu(rd->version);
239 fd->ino = je32_to_cpu(rd->ino);
David Woodhouse69ca4372007-10-13 11:33:50 +0100240 fd->nhash = full_name_hash(name, namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 fd->type = rd->type;
242 memcpy(fd->name, name, namelen);
243 fd->name[namelen]=0;
244
245 retry:
David Woodhouse2f785402006-05-24 02:04:45 +0100246 flash_ofs = write_ofs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
David Woodhouse2f785402006-05-24 02:04:45 +0100248 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Estelle Hammache9b88f472005-01-28 18:53:05 +0000250 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(rd->version) < f->highest_version)) {
251 BUG_ON(!retried);
252 D1(printk(KERN_DEBUG "jffs2_write_dirent : dirent_version %d, "
253 "highest version %d -> updating dirent\n",
254 je32_to_cpu(rd->version), f->highest_version));
255 rd->version = cpu_to_je32(++f->highest_version);
256 fd->version = je32_to_cpu(rd->version);
257 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
Estelle Hammachee4803c32005-01-24 21:13:42 +0000258 }
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen,
261 (alloc_mode==ALLOC_GC)?0:je32_to_cpu(rd->pino));
262 if (ret || (retlen != sizeof(*rd) + namelen)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000263 printk(KERN_NOTICE "Write of %zd bytes at 0x%08x failed. returned %d, retlen %zd\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 sizeof(*rd)+namelen, flash_ofs, ret, retlen);
265 /* Mark the space as dirtied */
266 if (retlen) {
David Woodhouse2f785402006-05-24 02:04:45 +0100267 jffs2_add_physical_node_ref(c, flash_ofs | REF_OBSOLETE, PAD(sizeof(*rd)+namelen), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100269 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", flash_ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
David Woodhouse2f785402006-05-24 02:04:45 +0100271 if (!retried) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 /* Try to reallocate space and retry */
273 uint32_t dummy;
274 struct jffs2_eraseblock *jeb = &c->blocks[flash_ofs / c->sector_size];
275
276 retried = 1;
277
278 D1(printk(KERN_DEBUG "Retrying failed write.\n"));
279
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100280 jffs2_dbg_acct_sanity_check(c,jeb);
281 jffs2_dbg_acct_paranoia_check(c, jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 if (alloc_mode == ALLOC_GC) {
David Woodhouse9fe48542006-05-23 00:38:06 +0100284 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &dummy,
285 JFFS2_SUMMARY_DIRENT_SIZE(namelen));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 } else {
287 /* Locking pain */
David Woodhouseced22072008-04-22 15:13:40 +0100288 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 jffs2_complete_reservation(c);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000290
David Woodhouse9fe48542006-05-23 00:38:06 +0100291 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy,
292 alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
David Woodhouseced22072008-04-22 15:13:40 +0100293 mutex_lock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295
296 if (!ret) {
David Woodhouse9fe48542006-05-23 00:38:06 +0100297 flash_ofs = write_ofs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100299 jffs2_dbg_acct_sanity_check(c,jeb);
300 jffs2_dbg_acct_paranoia_check(c, jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 goto retry;
302 }
303 D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
305 /* Release the full_dnode which is now useless, and return */
306 jffs2_free_full_dirent(fd);
307 return ERR_PTR(ret?ret:-EIO);
308 }
309 /* Mark the space used */
David Woodhouse71c23392007-06-29 13:39:57 +0100310 fd->raw = jffs2_add_physical_node_ref(c, flash_ofs | dirent_node_state(rd),
311 PAD(sizeof(*rd)+namelen), f->inocache);
Joakim Tjernlund5bd5c032007-06-24 19:22:29 +0200312 if (IS_ERR(fd->raw)) {
313 void *hold_err = fd->raw;
314 /* Release the full_dirent which is now useless, and return */
315 jffs2_free_full_dirent(fd);
David Howellse231c2e2008-02-07 00:15:26 -0800316 return ERR_CAST(hold_err);
Joakim Tjernlund5bd5c032007-06-24 19:22:29 +0200317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 if (retried) {
Artem B. Bityutskiy730554d2005-07-17 07:56:26 +0100320 jffs2_dbg_acct_sanity_check(c,NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322
323 return fd;
324}
325
326/* The OS-specific code fills in the metadata in the jffs2_raw_inode for us, so that
327 we don't have to go digging in struct inode or its equivalent. It should set:
328 mode, uid, gid, (starting)isize, atime, ctime, mtime */
329int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000330 struct jffs2_raw_inode *ri, unsigned char *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 uint32_t offset, uint32_t writelen, uint32_t *retlen)
332{
333 int ret = 0;
334 uint32_t writtenlen = 0;
335
336 D1(printk(KERN_DEBUG "jffs2_write_inode_range(): Ino #%u, ofs 0x%x, len 0x%x\n",
337 f->inocache->ino, offset, writelen));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 while(writelen) {
340 struct jffs2_full_dnode *fn;
341 unsigned char *comprbuf = NULL;
342 uint16_t comprtype = JFFS2_COMPR_NONE;
David Woodhouse9fe48542006-05-23 00:38:06 +0100343 uint32_t alloclen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 uint32_t datalen, cdatalen;
345 int retried = 0;
346
347 retry:
348 D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset));
349
David Woodhouse9fe48542006-05-23 00:38:06 +0100350 ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN,
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100351 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 if (ret) {
353 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
354 break;
355 }
David Woodhouseced22072008-04-22 15:13:40 +0100356 mutex_lock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 datalen = min_t(uint32_t, writelen, PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1)));
358 cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen);
359
360 comprtype = jffs2_compress(c, f, buf, &comprbuf, &datalen, &cdatalen);
361
362 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
363 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
364 ri->totlen = cpu_to_je32(sizeof(*ri) + cdatalen);
365 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
366
367 ri->ino = cpu_to_je32(f->inocache->ino);
368 ri->version = cpu_to_je32(++f->highest_version);
369 ri->isize = cpu_to_je32(max(je32_to_cpu(ri->isize), offset + datalen));
370 ri->offset = cpu_to_je32(offset);
371 ri->csize = cpu_to_je32(cdatalen);
372 ri->dsize = cpu_to_je32(datalen);
373 ri->compr = comprtype & 0xff;
374 ri->usercompr = (comprtype >> 8 ) & 0xff;
375 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
376 ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
377
David Woodhouse9fe48542006-05-23 00:38:06 +0100378 fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, ALLOC_NORETRY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 jffs2_free_comprbuf(comprbuf, buf);
381
382 if (IS_ERR(fn)) {
383 ret = PTR_ERR(fn);
David Woodhouseced22072008-04-22 15:13:40 +0100384 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 jffs2_complete_reservation(c);
386 if (!retried) {
387 /* Write error to be retried */
388 retried = 1;
389 D1(printk(KERN_DEBUG "Retrying node write in jffs2_write_inode_range()\n"));
390 goto retry;
391 }
392 break;
393 }
394 ret = jffs2_add_full_dnode_to_inode(c, f, fn);
395 if (f->metadata) {
396 jffs2_mark_node_obsolete(c, f->metadata->raw);
397 jffs2_free_full_dnode(f->metadata);
398 f->metadata = NULL;
399 }
400 if (ret) {
401 /* Eep */
402 D1(printk(KERN_DEBUG "Eep. add_full_dnode_to_inode() failed in commit_write, returned %d\n", ret));
403 jffs2_mark_node_obsolete(c, fn->raw);
404 jffs2_free_full_dnode(fn);
405
David Woodhouseced22072008-04-22 15:13:40 +0100406 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 jffs2_complete_reservation(c);
408 break;
409 }
David Woodhouseced22072008-04-22 15:13:40 +0100410 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 jffs2_complete_reservation(c);
412 if (!datalen) {
413 printk(KERN_WARNING "Eep. We didn't actually write any data in jffs2_write_inode_range()\n");
414 ret = -EIO;
415 break;
416 }
417 D1(printk(KERN_DEBUG "increasing writtenlen by %d\n", datalen));
418 writtenlen += datalen;
419 offset += datalen;
420 writelen -= datalen;
421 buf += datalen;
422 }
423 *retlen = writtenlen;
424 return ret;
425}
426
Eric Paris2a7dba32011-02-01 11:05:39 -0500427int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
428 struct jffs2_inode_info *f, struct jffs2_raw_inode *ri,
429 const struct qstr *qstr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 struct jffs2_raw_dirent *rd;
432 struct jffs2_full_dnode *fn;
433 struct jffs2_full_dirent *fd;
David Woodhouse9fe48542006-05-23 00:38:06 +0100434 uint32_t alloclen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 int ret;
436
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000437 /* Try to reserve enough space for both node and dirent.
438 * Just the node will do for now, though
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 */
David Woodhouse9fe48542006-05-23 00:38:06 +0100440 ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100441 JFFS2_SUMMARY_INODE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
David Woodhouse590fe342008-05-01 15:53:28 +0100443 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return ret;
David Woodhouse590fe342008-05-01 15:53:28 +0100445
446 mutex_lock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 ri->data_crc = cpu_to_je32(0);
449 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
450
David Woodhouse9fe48542006-05-23 00:38:06 +0100451 fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n",
454 jemode_to_cpu(ri->mode)));
455
456 if (IS_ERR(fn)) {
457 D1(printk(KERN_DEBUG "jffs2_write_dnode() failed\n"));
458 /* Eeek. Wave bye bye */
David Woodhouseced22072008-04-22 15:13:40 +0100459 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 jffs2_complete_reservation(c);
461 return PTR_ERR(fn);
462 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000463 /* No data here. Only a metadata node, which will be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 obsoleted by the first data write
465 */
466 f->metadata = fn;
467
David Woodhouseced22072008-04-22 15:13:40 +0100468 mutex_unlock(&f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 jffs2_complete_reservation(c);
KaiGai Koheicfc8dc62007-09-14 15:16:35 +0900470
Eric Paris2a7dba32011-02-01 11:05:39 -0500471 ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode, qstr);
KaiGai Koheicfc8dc62007-09-14 15:16:35 +0900472 if (ret)
473 return ret;
474 ret = jffs2_init_acl_post(&f->vfs_inode);
475 if (ret)
476 return ret;
477
Eric Paris2a7dba32011-02-01 11:05:39 -0500478 ret = jffs2_reserve_space(c, sizeof(*rd)+qstr->len, &alloclen,
479 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(qstr->len));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (ret) {
482 /* Eep. */
483 D1(printk(KERN_DEBUG "jffs2_reserve_space() for dirent failed\n"));
484 return ret;
485 }
486
487 rd = jffs2_alloc_raw_dirent();
488 if (!rd) {
489 /* Argh. Now we treat it like a normal delete */
490 jffs2_complete_reservation(c);
491 return -ENOMEM;
492 }
493
David Woodhouseced22072008-04-22 15:13:40 +0100494 mutex_lock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
497 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
Eric Paris2a7dba32011-02-01 11:05:39 -0500498 rd->totlen = cpu_to_je32(sizeof(*rd) + qstr->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
500
501 rd->pino = cpu_to_je32(dir_f->inocache->ino);
502 rd->version = cpu_to_je32(++dir_f->highest_version);
503 rd->ino = ri->ino;
504 rd->mctime = ri->ctime;
Eric Paris2a7dba32011-02-01 11:05:39 -0500505 rd->nsize = qstr->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 rd->type = DT_REG;
507 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
Eric Paris2a7dba32011-02-01 11:05:39 -0500508 rd->name_crc = cpu_to_je32(crc32(0, qstr->name, qstr->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Eric Paris2a7dba32011-02-01 11:05:39 -0500510 fd = jffs2_write_dirent(c, dir_f, rd, qstr->name, qstr->len, ALLOC_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 jffs2_free_raw_dirent(rd);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if (IS_ERR(fd)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000515 /* dirent failed to write. Delete the inode normally
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 as if it were the final unlink() */
517 jffs2_complete_reservation(c);
David Woodhouseced22072008-04-22 15:13:40 +0100518 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return PTR_ERR(fd);
520 }
521
522 /* Link the fd into the inode's list, obsoleting an old
523 one if necessary. */
524 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
525
526 jffs2_complete_reservation(c);
David Woodhouseced22072008-04-22 15:13:40 +0100527 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 return 0;
530}
531
532
533int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
Artem B. Bityutskiy3a69e0c2005-08-17 14:46:26 +0100534 const char *name, int namelen, struct jffs2_inode_info *dead_f,
535 uint32_t time)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
537 struct jffs2_raw_dirent *rd;
538 struct jffs2_full_dirent *fd;
David Woodhouse9fe48542006-05-23 00:38:06 +0100539 uint32_t alloclen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 int ret;
541
Joakim Tjernlunda4914862007-03-16 16:15:45 +0100542 if (!jffs2_can_mark_obsolete(c)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /* We can't mark stuff obsolete on the medium. We need to write a deletion dirent */
544
545 rd = jffs2_alloc_raw_dirent();
546 if (!rd)
547 return -ENOMEM;
548
David Woodhouse9fe48542006-05-23 00:38:06 +0100549 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100550 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (ret) {
552 jffs2_free_raw_dirent(rd);
553 return ret;
554 }
555
David Woodhouseced22072008-04-22 15:13:40 +0100556 mutex_lock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 /* Build a deletion node */
559 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
560 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
561 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
562 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 rd->pino = cpu_to_je32(dir_f->inocache->ino);
565 rd->version = cpu_to_je32(++dir_f->highest_version);
566 rd->ino = cpu_to_je32(0);
Artem B. Bityutskiy3a69e0c2005-08-17 14:46:26 +0100567 rd->mctime = cpu_to_je32(time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 rd->nsize = namelen;
569 rd->type = DT_UNKNOWN;
570 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
571 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
572
David Woodhouse9fe48542006-05-23 00:38:06 +0100573 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_DELETION);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 jffs2_free_raw_dirent(rd);
576
577 if (IS_ERR(fd)) {
578 jffs2_complete_reservation(c);
David Woodhouseced22072008-04-22 15:13:40 +0100579 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return PTR_ERR(fd);
581 }
582
583 /* File it. This will mark the old one obsolete. */
584 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
David Woodhouseced22072008-04-22 15:13:40 +0100585 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 uint32_t nhash = full_name_hash(name, namelen);
588
Harvey Harrisonbf667372008-04-18 13:44:14 -0700589 fd = dir_f->dents;
David Woodhouseb5748642007-08-20 11:05:29 +0100590 /* We don't actually want to reserve any space, but we do
591 want to be holding the alloc_sem when we write to flash */
David Woodhouseced22072008-04-22 15:13:40 +0100592 mutex_lock(&c->alloc_sem);
593 mutex_lock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
David Woodhouse15953582007-11-01 16:25:56 -0400595 for (fd = dir_f->dents; fd; fd = fd->next) {
596 if (fd->nhash == nhash &&
597 !memcmp(fd->name, name, namelen) &&
598 !fd->name[namelen]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) @%08x obsolete\n",
David Woodhouse15953582007-11-01 16:25:56 -0400601 fd->ino, ref_offset(fd->raw)));
602 jffs2_mark_node_obsolete(c, fd->raw);
603 /* We don't want to remove it from the list immediately,
604 because that screws up getdents()/seek() semantics even
605 more than they're screwed already. Turn it into a
606 node-less deletion dirent instead -- a placeholder */
607 fd->raw = NULL;
608 fd->ino = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 break;
610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
David Woodhouseced22072008-04-22 15:13:40 +0100612 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
615 /* dead_f is NULL if this was a rename not a real unlink */
616 /* Also catch the !f->inocache case, where there was a dirent
617 pointing to an inode which didn't exist. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000618 if (dead_f && dead_f->inocache) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
David Woodhouseced22072008-04-22 15:13:40 +0100620 mutex_lock(&dead_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +0000622 if (S_ISDIR(OFNI_EDONI_2SFFJ(dead_f)->i_mode)) {
623 while (dead_f->dents) {
624 /* There can be only deleted ones */
625 fd = dead_f->dents;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000626
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +0000627 dead_f->dents = fd->next;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000628
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +0000629 if (fd->ino) {
630 printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n",
631 dead_f->inocache->ino, fd->name, fd->ino);
632 } else {
633 D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n",
634 fd->name, dead_f->inocache->ino));
635 }
David Woodhouse15953582007-11-01 16:25:56 -0400636 if (fd->raw)
637 jffs2_mark_node_obsolete(c, fd->raw);
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +0000638 jffs2_free_full_dirent(fd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
David Woodhouse27c72b02008-05-01 18:47:17 +0100640 dead_f->inocache->pino_nlink = 0;
641 } else
642 dead_f->inocache->pino_nlink--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /* NB: Caller must set inode nlink if appropriate */
David Woodhouseced22072008-04-22 15:13:40 +0100644 mutex_unlock(&dead_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646
647 jffs2_complete_reservation(c);
648
649 return 0;
650}
651
652
Artem B. Bityutskiy3a69e0c2005-08-17 14:46:26 +0100653int 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
655 struct jffs2_raw_dirent *rd;
656 struct jffs2_full_dirent *fd;
David Woodhouse9fe48542006-05-23 00:38:06 +0100657 uint32_t alloclen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 int ret;
659
660 rd = jffs2_alloc_raw_dirent();
661 if (!rd)
662 return -ENOMEM;
663
David Woodhouse9fe48542006-05-23 00:38:06 +0100664 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100665 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 if (ret) {
667 jffs2_free_raw_dirent(rd);
668 return ret;
669 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000670
David Woodhouseced22072008-04-22 15:13:40 +0100671 mutex_lock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 /* Build a deletion node */
674 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
675 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
676 rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
677 rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
678
679 rd->pino = cpu_to_je32(dir_f->inocache->ino);
680 rd->version = cpu_to_je32(++dir_f->highest_version);
681 rd->ino = cpu_to_je32(ino);
Artem B. Bityutskiy3a69e0c2005-08-17 14:46:26 +0100682 rd->mctime = cpu_to_je32(time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 rd->nsize = namelen;
684
685 rd->type = type;
686
687 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
688 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
689
David Woodhouse9fe48542006-05-23 00:38:06 +0100690 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 jffs2_free_raw_dirent(rd);
693
694 if (IS_ERR(fd)) {
695 jffs2_complete_reservation(c);
David Woodhouseced22072008-04-22 15:13:40 +0100696 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 return PTR_ERR(fd);
698 }
699
700 /* File it. This will mark the old one obsolete. */
701 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
702
703 jffs2_complete_reservation(c);
David Woodhouseced22072008-04-22 15:13:40 +0100704 mutex_unlock(&dir_f->sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 return 0;
707}