To save more space (equivalent to the size of one erase sector of MTD device) and to achieve faster read and write speeds, a method for direct writing was introduced at the FTL layer. This can be accomplished simply by using the following oflags during the open operation: 1. O_DIRECT. when this flag is passed in, ftl internally uses the direct write strategy and no read cache is used in ftl; otherwise, each write will be executed with the minimum granularity of flash erase sector size which means a "sector read back - erase sector - write sector" operation is performed by using a read cache buffer in heap. 2. O_SYNC. When this flag is passed in, we assume that the flash has been erased in advance and no erasure operation will be performed internally within ftl. O_SYNC will take effect only when both O_DIRECT and O_SYNC are passed in simultaneously. 3. For uniformity, we remapped the mount flag in mount.h and unified it with the open flag in fcntl.h. The repetitive parts of their definitions were reused, and the remaining part of the mount flag redefine to the unused bit of open flags. Signed-off-by: jingfei <jingfei@xiaomi.com>
81 lines
2.5 KiB
C
81 lines
2.5 KiB
C
/****************************************************************************
|
|
* drivers/bch/bchdev_register.c
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright ownership. The
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <stdbool.h>
|
|
#include <errno.h>
|
|
#include <assert.h>
|
|
#include <debug.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
#include <nuttx/drivers/drivers.h>
|
|
|
|
#include "bch.h"
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: bchdev_register
|
|
*
|
|
* Description:
|
|
* Setup so that it exports the block driver referenced by 'blkdev' as a
|
|
* character device 'chardev'
|
|
*
|
|
****************************************************************************/
|
|
|
|
int bchdev_register(FAR const char *blkdev, FAR const char *chardev,
|
|
int oflags)
|
|
{
|
|
FAR void *handle;
|
|
int ret;
|
|
|
|
finfo("blkdev=\"%s\" chardev=\"%s\" oflags=0x%x\n",
|
|
blkdev, chardev, oflags);
|
|
|
|
/* Setup the BCH lib functions */
|
|
|
|
ret = bchlib_setup(blkdev, oflags, &handle);
|
|
if (ret < 0)
|
|
{
|
|
ferr("ERROR: bchlib_setup failed: %d\n", -ret);
|
|
return ret;
|
|
}
|
|
|
|
/* Then setup the character device */
|
|
|
|
ret = register_driver(chardev, &g_bch_fops, 0666, handle);
|
|
if (ret < 0)
|
|
{
|
|
ferr("ERROR: register_driver failed: %d\n", -ret);
|
|
bchlib_teardown(handle);
|
|
handle = NULL;
|
|
}
|
|
|
|
return ret;
|
|
}
|