- int prevChunkId;
- yaffs_ext_tags prevTags;
-
- int newChunkId;
- yaffs_ext_tags newTags;
-
- yaffs_dev_t *dev = in->my_dev;
-
- yaffs_check_gc(dev,0);
-
- /* Get the previous chunk at this location in the file if it exists.
- * If it does not exist then put a zero into the tree. This creates
- * the tnode now, rather than later when it is harder to clean up.
- */
- prevChunkId = yaffs_find_chunk_in_file(in, inode_chunk, &prevTags);
- if(prevChunkId < 1 &&
- !yaffs_put_chunk_in_file(in, inode_chunk, 0, 0))
- return 0;
-
- /* Set up new tags */
- yaffs_init_tags(&newTags);
-
- newTags.chunk_id = inode_chunk;
- newTags.obj_id = in->obj_id;
- newTags.serial_number =
- (prevChunkId > 0) ? prevTags.serial_number + 1 : 1;
- newTags.n_bytes = n_bytes;
-
- if (n_bytes < 1 || n_bytes > dev->param.total_bytes_per_chunk) {
- T(YAFFS_TRACE_ERROR,
- (TSTR("Writing %d bytes to chunk!!!!!!!!!" TENDSTR), n_bytes));
- YBUG();
- }
-
-
- newChunkId =
- yaffs_write_new_chunk(dev, buffer, &newTags,
- useReserve);
-
- if (newChunkId > 0) {
- yaffs_put_chunk_in_file(in, inode_chunk, newChunkId, 0);
-
- if (prevChunkId > 0)
- yaffs_chunk_del(dev, prevChunkId, 1, __LINE__);
-
- yaffs_verify_file_sane(in);
- }
- return newChunkId;
-
-}
-
-/* UpdateObjectHeader updates the header on NAND for an object.
- * If name is not NULL, then that new name is used.
- */
-int yaffs_update_oh(yaffs_obj_t *in, const YCHAR *name, int force,
- int is_shrink, int shadows, yaffs_xattr_mod *xmod)
-{
-
- yaffs_block_info_t *bi;
-
- yaffs_dev_t *dev = in->my_dev;
-
- int prevChunkId;
- int retVal = 0;
- int result = 0;
-
- int newChunkId;
- yaffs_ext_tags newTags;
- yaffs_ext_tags oldTags;
- const YCHAR *alias = NULL;
-
- __u8 *buffer = NULL;
- YCHAR old_name[YAFFS_MAX_NAME_LENGTH + 1];
-
- yaffs_obj_header *oh = NULL;
-
- yaffs_strcpy(old_name, _Y("silly old name"));
-
-
- if (!in->fake ||
- in == dev->root_dir || /* The root_dir should also be saved */
- force || xmod) {
-
- yaffs_check_gc(dev,0);
- yaffs_check_obj_details_loaded(in);
-
- buffer = yaffs_get_temp_buffer(in->my_dev, __LINE__);
- oh = (yaffs_obj_header *) buffer;
-
- prevChunkId = in->hdr_chunk;
-
- if (prevChunkId > 0) {
- result = yaffs_rd_chunk_tags_nand(dev, prevChunkId,
- buffer, &oldTags);
-
- yaffs_verify_oh(in, oh, &oldTags, 0);
-
- memcpy(old_name, oh->name, sizeof(oh->name));
- memset(buffer, 0xFF, sizeof(yaffs_obj_header));
- } else
- memset(buffer, 0xFF, dev->data_bytes_per_chunk);
-
- oh->type = in->variant_type;
- oh->yst_mode = in->yst_mode;
- oh->shadows_obj = oh->inband_shadowed_obj_id = shadows;
-
-#ifdef CONFIG_YAFFS_WINCE
- oh->win_atime[0] = in->win_atime[0];
- oh->win_ctime[0] = in->win_ctime[0];
- oh->win_mtime[0] = in->win_mtime[0];
- oh->win_atime[1] = in->win_atime[1];
- oh->win_ctime[1] = in->win_ctime[1];
- oh->win_mtime[1] = in->win_mtime[1];
-#else
- oh->yst_uid = in->yst_uid;
- oh->yst_gid = in->yst_gid;
- oh->yst_atime = in->yst_atime;
- oh->yst_mtime = in->yst_mtime;
- oh->yst_ctime = in->yst_ctime;
- oh->yst_rdev = in->yst_rdev;
-#endif
- if (in->parent)
- oh->parent_obj_id = in->parent->obj_id;
- else
- oh->parent_obj_id = 0;
-
- if (name && *name) {
- memset(oh->name, 0, sizeof(oh->name));
- yaffs_load_oh_from_name(dev,oh->name,name);
- } else if (prevChunkId > 0)
- memcpy(oh->name, old_name, sizeof(oh->name));
- else
- memset(oh->name, 0, sizeof(oh->name));
-
- oh->is_shrink = is_shrink;
-
- switch (in->variant_type) {
- case YAFFS_OBJECT_TYPE_UNKNOWN:
- /* Should not happen */
- break;
- case YAFFS_OBJECT_TYPE_FILE:
- oh->file_size =
- (oh->parent_obj_id == YAFFS_OBJECTID_DELETED
- || oh->parent_obj_id ==
- YAFFS_OBJECTID_UNLINKED) ? 0 : in->variant.
- file_variant.file_size;
- break;
- case YAFFS_OBJECT_TYPE_HARDLINK:
- oh->equiv_id =
- in->variant.hardlink_variant.equiv_id;
- break;
- case YAFFS_OBJECT_TYPE_SPECIAL:
- /* Do nothing */
- break;
- case YAFFS_OBJECT_TYPE_DIRECTORY:
- /* Do nothing */
- break;
- case YAFFS_OBJECT_TYPE_SYMLINK:
- alias = in->variant.symlink_variant.alias;
- if(!alias)
- alias = _Y("no alias");
- yaffs_strncpy(oh->alias,
- alias,
- YAFFS_MAX_ALIAS_LENGTH);
- oh->alias[YAFFS_MAX_ALIAS_LENGTH] = 0;
- break;
- }
-
- /* process any xattrib modifications */
- if(xmod)
- yaffs_apply_xattrib_mod(in, (char *)buffer, xmod);