<commit_before>/*
 * Copyright (c) 2019 Bolt Innovation Management, LLC
 * Copyright (c) 2019 <NAME>, LLC
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <string.h>
#include <kernel.h>
#include <errno.h>
#include <init.h>
#include <fs/fs.h>
#include <fs/fs_sys.h>

#define LFS_LOG_REGISTER
#include <lfs_util.h>

#include <lfs.h>
#include <fs/littlefs.h>
#include <drivers/flash.h>
#include <storage/flash_map.h>

#include "fs_impl.h"

struct lfs_file_data {
	struct lfs_file file;
	struct lfs_file_config config;
	void *cache_block;
};

#define LFS_FILEP(fp) (&((struct lfs_file_data *)(fp->filep))->file)

/* Global memory pool for open files and dirs */
static K_MEM_SLAB_DEFINE(file_data_pool, sizeof(struct lfs_file_data),
			 CONFIG_FS_LITTLEFS_NUM_FILES, 4);
static K_MEM_SLAB_DEFINE(lfs_dir_pool, sizeof(struct lfs_dir),
			 CONFIG_FS_LITTLEFS_NUM_DIRS, 4);

/* If either filecache memory pool is customized by either the legacy
 * mem_pool or heap Kconfig options then we need to use a heap.
 * Otherwise we can use a fixed region.
 */
#define FC_ON_HEAP defined(CONFIG_FS_LITTLEFS_FC_MEM_POOL)	\
	|| ((CONFIG_FS_LITTLEFS_FC_HEAP_SIZE - 0) > 0)

#if FC_ON_HEAP

/* Inferred overhead, in bytes, for each k_heap_aligned allocation for
 * the filecache heap.  This relates to the CHUNK_UNIT parameter in
 * the heap implementation, but that value is not visible outside the
 * kernel.
 */
#define FC_HEAP_PER_ALLOC_OVERHEAD 24U

/* If not explicitly customizing provide a default that's appropriate
 * based on other configuration options.
 */
#ifndef CONFIG_FS_LITTLEFS_FC_MEM_POOL
#define CONFIG_FS_LITTLEFS_FC_MEM_POOL_MAX_SIZE CONFIG_FS_LITTLEFS_CACHE_SIZE
#define CONFIG_FS_LITTLEFS_FC_MEM_POOL_NUM_BLOCKS CONFIG_FS_LITTLEFS_NUM_FILES
#endif
<commit_msg>fs: littlefs: fix mis-use of preprocessor<commit_after>/*
 * Copyright (c) 2019 Bolt Innovation Management, LLC
 * Copyright (c) 2019 <NAME>, LLC
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <string.h>
#include <kernel.h>
#include <errno.h>
#include <init.h>
#include <fs/fs.h>
#include <fs/fs_sys.h>

#define LFS_LOG_REGISTER
#include <lfs_util.h>

#include <lfs.h>
#include <fs/littlefs.h>
#include <drivers/flash.h>
#include <storage/flash_map.h>

#include "fs_impl.h"

struct lfs_file_data {
	struct lfs_file file;
	struct lfs_file_config config;
	void *cache_block;
};

#define LFS_FILEP(fp) (&((struct lfs_file_data *)(fp->filep))->file)

/* Global memory pool for open files and dirs */
static K_MEM_SLAB_DEFINE(file_data_pool, sizeof(struct lfs_file_data),
			 CONFIG_FS_LITTLEFS_NUM_FILES, 4);
static K_MEM_SLAB_DEFINE(lfs_dir_pool, sizeof(struct lfs_dir),
			 CONFIG_FS_LITTLEFS_NUM_DIRS, 4);

/* If either filecache memory pool is customized by either the legacy
 * mem_pool or heap Kconfig options then we need to use a heap.
 * Otherwise we can use a fixed region.
 */
#if defined(CONFIG_FS_LITTLEFS_FC_MEM_POOL)		\
	|| ((CONFIG_FS_LITTLEFS_FC_HEAP_SIZE - 0) > 0)
#define FC_ON_HEAP 1
#else
#define FC_ON_HEAP 0
#endif

#if FC_ON_HEAP

/* Inferred overhead, in bytes, for each k_heap_aligned allocation for
 * the filecache heap.  This relates to the CHUNK_UNIT parameter in
 * the heap implementation, but that value is not visible outside the
 * kernel.
 */
#define FC_HEAP_PER_ALLOC_OVERHEAD 24U

/* If not explicitly customizing provide a default that's appropriate
 * based on other configuration options.
 */
#ifndef CONFIG_FS_LITTLEFS_FC_MEM_POOL
#define CONFIG_FS_LITTLEFS_FC_MEM_POOL_MAX_SIZE CONFIG_FS_LITTLEFS_CACHE_SIZE
#define CONFIG_FS_LITTLEFS_FC_MEM_POOL_NUM_BLOCKS CONFIG_FS_LITTLEFS_NUM_FILES
#endif

{'fraction_non_alphanumeric': 0.09553791404325213, 'fraction_numerical': 0.0093074185600876, 'mean_word_length': 5.421792618629174, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6924852', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1352, 'n_words': 358}