Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * JFFS2 -- Journalling Flash File System, Version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright © 2001-2007 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Created by David Woodhouse <dwmw2@infradead.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * For licensing information, see the file 'LICENCE' in this directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/jffs2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "nodelist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /* These are initialised to NULL in the kernel startup code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)    If you're porting to other operating systems, beware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct kmem_cache *full_dnode_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static struct kmem_cache *raw_dirent_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct kmem_cache *raw_inode_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct kmem_cache *tmp_dnode_info_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static struct kmem_cache *raw_node_ref_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static struct kmem_cache *node_frag_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct kmem_cache *inode_cache_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef CONFIG_JFFS2_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static struct kmem_cache *xattr_datum_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct kmem_cache *xattr_ref_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) int __init jffs2_create_slab_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	full_dnode_slab = kmem_cache_create("jffs2_full_dnode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 					    sizeof(struct jffs2_full_dnode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 					    0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!full_dnode_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 					    sizeof(struct jffs2_raw_dirent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 					    0, SLAB_HWCACHE_ALIGN, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!raw_dirent_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	raw_inode_slab = kmem_cache_create("jffs2_raw_inode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 					   sizeof(struct jffs2_raw_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 					   0, SLAB_HWCACHE_ALIGN, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (!raw_inode_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 						sizeof(struct jffs2_tmp_dnode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 						0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (!tmp_dnode_info_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	raw_node_ref_slab = kmem_cache_create("jffs2_refblock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 					      sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 					      0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (!raw_node_ref_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	node_frag_slab = kmem_cache_create("jffs2_node_frag",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 					   sizeof(struct jffs2_node_frag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 					   0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (!node_frag_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	inode_cache_slab = kmem_cache_create("jffs2_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 					     sizeof(struct jffs2_inode_cache),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 					     0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (!inode_cache_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #ifdef CONFIG_JFFS2_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	xattr_datum_cache = kmem_cache_create("jffs2_xattr_datum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 					     sizeof(struct jffs2_xattr_datum),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 					     0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (!xattr_datum_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	xattr_ref_cache = kmem_cache_create("jffs2_xattr_ref",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 					   sizeof(struct jffs2_xattr_ref),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					   0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!xattr_ref_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	jffs2_destroy_slab_caches();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) void jffs2_destroy_slab_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	kmem_cache_destroy(full_dnode_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	kmem_cache_destroy(raw_dirent_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	kmem_cache_destroy(raw_inode_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	kmem_cache_destroy(tmp_dnode_info_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	kmem_cache_destroy(raw_node_ref_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	kmem_cache_destroy(node_frag_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kmem_cache_destroy(inode_cache_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #ifdef CONFIG_JFFS2_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	kmem_cache_destroy(xattr_datum_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	kmem_cache_destroy(xattr_ref_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct jffs2_full_dirent *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	ret = kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	dbg_memalloc("%p\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	kfree(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct jffs2_full_dnode *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	dbg_memalloc("%p\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	kmem_cache_free(full_dnode_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct jffs2_raw_dirent *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	dbg_memalloc("%p\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	kmem_cache_free(raw_dirent_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct jffs2_raw_inode *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	dbg_memalloc("%p\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	kmem_cache_free(raw_inode_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct jffs2_tmp_dnode_info *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	dbg_memalloc("%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	kmem_cache_free(tmp_dnode_info_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct jffs2_raw_node_ref *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		for (i=0; i < REFS_PER_BLOCK; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			ret[i].flash_offset = REF_EMPTY_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			ret[i].next_in_ino = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		ret[i].flash_offset = REF_LINK_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		ret[i].next_in_ino = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				 struct jffs2_eraseblock *jeb, int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct jffs2_raw_node_ref **p, *ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	int i = nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	dbg_memalloc("%d\n", nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	p = &jeb->last_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ref = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	dbg_memalloc("Reserving %d refs for block @0x%08x\n", nr, jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	/* If jeb->last_node is really a valid node then skip over it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (ref && ref->flash_offset != REF_EMPTY_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		ref++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	while (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		if (!ref) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			dbg_memalloc("Allocating new refblock linked from %p\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			ref = *p = jffs2_alloc_refblock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			if (!ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (ref->flash_offset == REF_LINK_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			p = &ref->next_in_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			ref = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		ref++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	jeb->allocated_refs = nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	dbg_memalloc("Reserved %d refs for block @0x%08x, last_node is %p (%08x,%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		  nr, jeb->offset, jeb->last_node, jeb->last_node->flash_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		  jeb->last_node->next_in_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void jffs2_free_refblock(struct jffs2_raw_node_ref *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	kmem_cache_free(raw_node_ref_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct jffs2_node_frag *jffs2_alloc_node_frag(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct jffs2_node_frag *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	dbg_memalloc("%p\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) void jffs2_free_node_frag(struct jffs2_node_frag *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	kmem_cache_free(node_frag_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct jffs2_inode_cache *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	dbg_memalloc("%p\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	dbg_memalloc("%p\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	kmem_cache_free(inode_cache_slab, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #ifdef CONFIG_JFFS2_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct jffs2_xattr_datum *xd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	xd = kmem_cache_zalloc(xattr_datum_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	dbg_memalloc("%p\n", xd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (!xd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	xd->class = RAWNODE_CLASS_XATTR_DATUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	xd->node = (void *)xd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	INIT_LIST_HEAD(&xd->xindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return xd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) void jffs2_free_xattr_datum(struct jffs2_xattr_datum *xd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	dbg_memalloc("%p\n", xd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	kmem_cache_free(xattr_datum_cache, xd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct jffs2_xattr_ref *ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	ref = kmem_cache_zalloc(xattr_ref_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	dbg_memalloc("%p\n", ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (!ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	ref->class = RAWNODE_CLASS_XATTR_REF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	ref->node = (void *)ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	return ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) void jffs2_free_xattr_ref(struct jffs2_xattr_ref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	dbg_memalloc("%p\n", ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	kmem_cache_free(xattr_ref_cache, ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #endif