kernels/linux-2.4.0/fs/jffs/intrep.c
/* Insert any kind of node into the file system.  Take care of data
   insertions and deletions.  Also remove redundant information. The
   memory allocated for the `name' is regarded as "given away" in the
   caller's perspective.  */
Insert any kind of node into the file system.  Take care of data
insertions and deletions.  Also remove redundant information. The
memory allocated for the `name' is regarded as "given away" in the
caller's perspective.
Insert any kind of node into the file system . Take care of data insertions and deletions . Also remove redundant information . The memory allocated for the ` name ' is regarded as " given away " in the caller ' s perspective .
int
jffs_insert_node(struct jffs_control *c, struct jffs_file *f,
		 const struct jffs_raw_inode *raw_inode,
		 const char *name, struct jffs_node *node)
{
	int update_name = 0;
	int insert_into_tree = 0;
	D2(printk("jffs_insert_node(): ino = %u, version = %u, "
		  "name = \"%s\", deleted = %d\n",
		  raw_inode->ino, raw_inode->version,
		  ((name && *name) ? name : ""), raw_inode->deleted));
	if (!f && !(f = jffs_find_file(c, raw_inode->ino))) {
		if (!(f = jffs_create_file(c, raw_inode))) {
			return -ENOMEM;
		}
		jffs_insert_file_into_hash(f);
		insert_into_tree = 1;
	}
	node->ino = raw_inode->ino;
	node->version = raw_inode->version;
	node->data_size = raw_inode->dsize;
	node->fm_offset = sizeof(struct jffs_raw_inode) + raw_inode->nsize
			  + JFFS_GET_PAD_BYTES(raw_inode->nsize);
	node->name_size = raw_inode->nsize;
	if (!f->version_head) {
		f->version_head = node;
		f->version_tail = node;
		node->version_prev = 0;
		node->version_next = 0;
		f->highest_version = node->version;
		update_name = 1;
		f->mode = raw_inode->mode;
		f->uid = raw_inode->uid;
		f->gid = raw_inode->gid;
		f->atime = raw_inode->atime;
		f->mtime = raw_inode->mtime;
		f->ctime = raw_inode->ctime;
		f->deleted = raw_inode->deleted;
	}
	else if ((f->highest_version < node->version)
		 || (node->version == 0)) {
		node->version_prev = f->version_tail;
		node->version_next = 0;
		f->version_tail->version_next = node;
		f->version_tail = node;
		f->highest_version = node->version;
		update_name = 1;
		f->pino = raw_inode->pino;
		f->mode = raw_inode->mode;
		f->uid = raw_inode->uid;
		f->gid = raw_inode->gid;
		f->atime = raw_inode->atime;
		f->mtime = raw_inode->mtime;
		f->ctime = raw_inode->ctime;
		f->deleted = raw_inode->deleted;
	}
	else if (f->version_head->version > node->version) {
		node->version_prev = 0;
		node->version_next = f->version_head;
		f->version_head->version_prev = node;
		f->version_head = node;
		if (!f->name) {
			update_name = 1;
		}
		if (raw_inode->deleted) {
			f->deleted = raw_inode->deleted;
		}
	}
	else {
		struct jffs_node *n;
		int newer_name = 0;
		for (n = f->version_tail; n; n = n->version_prev) {
			if (n->version < node->version) {
				node->version_prev = n;
				node->version_next = n->version_next;
				node->version_next->version_prev = node;
				n->version_next = node;
				if (!newer_name) {
					update_name = 1;
				}
				break;
			}
			if (n->name_size) {
				newer_name = 1;
			}
		}
	}
	if (raw_inode->nsize && update_name && name && *name && (name != f->name)) {
		if (f->name) {
			kfree(f->name);
			DJM(no_name--);
		}
		if (!(f->name = (char *) kmalloc(raw_inode->nsize + 1,
						 GFP_KERNEL))) {
			return -ENOMEM;
		}
		DJM(no_name++);
		memcpy(f->name, name, raw_inode->nsize);
		f->name[raw_inode->nsize] = '\0';
		f->nsize = raw_inode->nsize;
		D3(printk("jffs_insert_node(): Updated the name of "
			  "the file to \"%s\".\n", name));
	}
	if (!c->building_fs) {
		D3(printk("jffs_insert_node(): ---------------------------"
			  "------------------------------------------- 1\n"));
		if (insert_into_tree) {
			jffs_insert_file_into_tree(f);
		}
		if (f->deleted) {
			jffs_possibly_delete_file(f);
		}
		else {
			if (node->data_size || node->removed_size) {
				jffs_update_file(f, node);
			}
			jffs_remove_redundant_nodes(f);
		}
		jffs_garbage_collect_trigger(c);
		D3(printk("jffs_insert_node(): ---------------------------"
			  "------------------------------------------- 2\n"));
	}
	return 0;
}
int jffs_insert_node ( struct jffs_control * c , struct jffs_file * f , const struct jffs_raw_inode * raw_inode , const char * name , struct jffs_node * node ) { int update_name = 0 ; int insert_into_tree = 0 ; D2 ( printk ( " " " \" \" \n " , raw_inode -> ino , raw_inode -> version , ( ( name && * name ) ? name : " " ) , raw_inode -> deleted ) ) ; if ( ! f && ! ( f = jffs_find_file ( c , raw_inode -> ino ) ) ) { if ( ! ( f = jffs_create_file ( c , raw_inode ) ) ) { return - ENOMEM ; } jffs_insert_file_into_hash ( f ) ; insert_into_tree = 1 ; } node -> ino = raw_inode -> ino ; node -> version = raw_inode -> version ; node -> data_size = raw_inode -> dsize ; node -> fm_offset = sizeof ( struct jffs_raw_inode ) + raw_inode -> nsize + JFFS_GET_PAD_BYTES ( raw_inode -> nsize ) ; node -> name_size = raw_inode -> nsize ; if ( ! f -> version_head ) { f -> version_head = node ; f -> version_tail = node ; node -> version_prev = 0 ; node -> version_next = 0 ; f -> highest_version = node -> version ; update_name = 1 ; f -> mode = raw_inode -> mode ; f -> uid = raw_inode -> uid ; f -> gid = raw_inode -> gid ; f -> atime = raw_inode -> atime ; f -> mtime = raw_inode -> mtime ; f -> ctime = raw_inode -> ctime ; f -> deleted = raw_inode -> deleted ; } else if ( ( f -> highest_version < node -> version ) || ( node -> version == 0 ) ) { node -> version_prev = f -> version_tail ; node -> version_next = 0 ; f -> version_tail -> version_next = node ; f -> version_tail = node ; f -> highest_version = node -> version ; update_name = 1 ; f -> pino = raw_inode -> pino ; f -> mode = raw_inode -> mode ; f -> uid = raw_inode -> uid ; f -> gid = raw_inode -> gid ; f -> atime = raw_inode -> atime ; f -> mtime = raw_inode -> mtime ; f -> ctime = raw_inode -> ctime ; f -> deleted = raw_inode -> deleted ; } else if ( f -> version_head -> version > node -> version ) { node -> version_prev = 0 ; node -> version_next = f -> version_head ; f -> version_head -> version_prev = node ; f -> version_head = node ; if ( ! f -> name ) { update_name = 1 ; } if ( raw_inode -> deleted ) { f -> deleted = raw_inode -> deleted ; } } else { struct jffs_node * n ; int newer_name = 0 ; for ( n = f -> version_tail ; n ; n = n -> version_prev ) { if ( n -> version < node -> version ) { node -> version_prev = n ; node -> version_next = n -> version_next ; node -> version_next -> version_prev = node ; n -> version_next = node ; if ( ! newer_name ) { update_name = 1 ; } break ; } if ( n -> name_size ) { newer_name = 1 ; } } } if ( raw_inode -> nsize && update_name && name && * name && ( name != f -> name ) ) { if ( f -> name ) { kfree ( f -> name ) ; DJM ( no_name -- ) ; } if ( ! ( f -> name = ( char * ) kmalloc ( raw_inode -> nsize + 1 , GFP_KERNEL ) ) ) { return - ENOMEM ; } DJM ( no_name ++ ) ; memcpy ( f -> name , name , raw_inode -> nsize ) ; f -> name [ raw_inode -> nsize ] = ' \0 ' ; f -> nsize = raw_inode -> nsize ; D3 ( printk ( " " " \" \" \n " , name ) ) ; } if ( ! c -> building_fs ) { D3 ( printk ( " " " \n " ) ) ; if ( insert_into_tree ) { jffs_insert_file_into_tree ( f ) ; } if ( f -> deleted ) { jffs_possibly_delete_file ( f ) ; } else { if ( node -> data_size || node -> removed_size ) { jffs_update_file ( f , node ) ; } jffs_remove_redundant_nodes ( f ) ; } jffs_garbage_collect_trigger ( c ) ; D3 ( printk ( " " " \n " ) ) ; } return 0 ; }
Insert any kind of node into the file system.
Insert any kind of node into the file system .
/* If there doesn't exist an associated jffs_file, then
	   create, initialize and insert one into the file system.  */ /* Now insert the node at the correct position into the file's
	   version list.  */ /* This is the first node.  */ /* Insert at the end of the list.  I.e. this node is the
		   oldest one so far.  */ /* Insert at the bottom of the list.  */ /* Search for the insertion position starting from
		   the tail (newest node).  */ /* Perhaps update the name.  */ /* Mark all versions of the node as obsolete.  */