2019-10-26 18:24:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/mkrd.c
|
|
|
|
*
|
2020-08-04 18:55:59 +02:00
|
|
|
* 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
|
2019-10-26 18:24:04 +02:00
|
|
|
*
|
2020-08-04 18:55:59 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-10-26 18:24:04 +02:00
|
|
|
*
|
2020-08-04 18:55:59 +02:00
|
|
|
* 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.
|
2019-10-26 18:24:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2019-10-27 00:54:59 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2019-10-26 18:24:04 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/drivers/ramdisk.h>
|
|
|
|
|
2019-10-26 19:43:34 +02:00
|
|
|
#ifdef CONFIG_DRVR_MKRD
|
2019-10-26 18:24:04 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mkrd
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is a wrapper function around ramdisk_register. It combines the
|
|
|
|
* necessary operations to create a RAM disk into a single callable
|
|
|
|
* function. Memory for the RAM disk is allocated, appropriated, from
|
|
|
|
* the kernel heap (in build modes where there is a distinct kernel heap).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* minor: Selects suffix of device named /dev/ramN, N={1,2,3...}
|
|
|
|
* nsectors: Number of sectors on device
|
|
|
|
* sectize: The size of one sector
|
|
|
|
* rdflags: See RDFLAG_* definitions. Typically
|
|
|
|
* RDFLAG_WRENABLED | RDFLAG_FUNLINK
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mkrd(int minor, uint32_t nsectors, uint16_t sectsize, uint8_t rdflags)
|
|
|
|
{
|
|
|
|
FAR uint8_t *buffer;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Allocate the memory backing up the ramdisk from the kernel heap */
|
|
|
|
|
|
|
|
buffer = (FAR uint8_t *)kmm_malloc(sectsize * nsectors);
|
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
2021-08-10 16:00:33 +02:00
|
|
|
ferr("ERROR: kmm_malloc() failed, enable DEBUG_MM for more info!\n");
|
2019-10-26 18:24:04 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_INFO
|
|
|
|
memset(buffer, 0, sectsize * nsectors);
|
|
|
|
#endif
|
|
|
|
finfo("RAMDISK at %p\n", buffer);
|
|
|
|
|
|
|
|
/* Then register the ramdisk */
|
|
|
|
|
|
|
|
ret = ramdisk_register(minor, buffer, nsectors, sectsize, rdflags);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ferr("ERROR: ramdisk_register() failed: %d\n", ret);
|
2020-08-04 18:55:59 +02:00
|
|
|
kmm_free(buffer);
|
2019-10-26 18:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-10-26 19:43:34 +02:00
|
|
|
#endif /* CONFIG_DRVR_MKRD */
|