Squashed commit of the following:

fs/fat:  Remove mkfatfs from the OS.  This is a user-space application and belongs in apps, not in the OS.
This commit is contained in:
Gregory Nutt
2017-10-20 12:36:25 -06:00
parent fc0a5e19d0
commit 9b31a81b00
16 changed files with 7 additions and 2589 deletions
+2 -2
View File
@@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4"> <tr align="center" bgcolor="#e4e4e4">
<td> <td>
<h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1> <h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1>
<p>Last Updated: August 11, 2017</p> <p>Last Updated: October 20, 2017</p>
</td> </td>
</tr> </tr>
</table> </table>
@@ -3481,7 +3481,7 @@ nsh&gt;
</tr> </tr>
<tr> <tr>
<td><b><code>mkfatfs</code></b></td> <td><b><code>mkfatfs</code></b></td>
<td>!<code>CONFIG_DISABLE_MOUNTPOINT</code> &amp;&amp; <code>CONFIG_NFILE_DESCRIPTORS</code> &gt; 0 &amp;&amp; <code>CONFIG_FS_FAT</code></td> <td>!<code>CONFIG_DISABLE_MOUNTPOINT</code> &amp;&amp; <code>CONFIG_NFILE_DESCRIPTORS</code> &gt; 0 &amp;&amp; <code>CONFIG_FSUTILS_MKFATFS</code></td>
<td><code>CONFIG_NSH_DISABLE_MKFATFS</code></td> <td><code>CONFIG_NSH_DISABLE_MKFATFS</code></td>
</tr> </tr>
<tr> <tr>
+4 -85
View File
@@ -13,7 +13,7 @@
<h1><big><font color="#3c34ec"><i>NuttX Operating System<p>User's Manual</i></font></big></h1> <h1><big><font color="#3c34ec"><i>NuttX Operating System<p>User's Manual</i></font></big></h1>
<p><small>by</small></p> <p><small>by</small></p>
<p>Gregory Nutt<p> <p>Gregory Nutt<p>
<p>Last Updated: October 2, 2017</p> <p>Last Updated: October 20, 2017</p>
</td> </td>
</tr> </tr>
</table> </table>
@@ -8404,8 +8404,7 @@ interface of the same name.
<li><a href="#aio">2.10.7 Asynchronous I/O</a></li> <li><a href="#aio">2.10.7 Asynchronous I/O</a></li>
<li><a href="#stdstrings">2.10.8 Standard String Operations</a></li> <li><a href="#stdstrings">2.10.8 Standard String Operations</a></li>
<li><a href="#PipesNFifos">2.10.9 Pipes and FIFOs</a></li> <li><a href="#PipesNFifos">2.10.9 Pipes and FIFOs</a></li>
<li><a href="#fatsupport">2.10.10 FAT File System Support</a></li> <li><a href="#mmapxip">2.10.10 <code>mmap()</code> and eXecute In Place (XIP)</a></li>
<li><a href="#mmapxip">2.10.11 <code>mmap()</code> and eXecute In Place (XIP)</a></li>
</ul> </ul>
<h3><a name="FileSystemOverview">2.10.1 NuttX File System Overview</a></h3> <h3><a name="FileSystemOverview">2.10.1 NuttX File System Overview</a></h3>
@@ -8957,85 +8956,7 @@ int mkfifo(FAR const char *pathname, mode_t mode);
</ul> </ul>
</p> </p>
<h3><a name="fatsupport">2.10.10 FAT File System Support</a></h3> <h3><a name="mmapxip">2.10.10 <code>mmap()</code> and eXecute In Place (XIP)</a></h3>
<h3>2.10.10.1 <a name="mkfatfs"><code>mkfatfs</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
<ul><pre>
#include &lt;nuttx/fs/mkfatfs.h&gt;
int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt);
</pre></ul>
<p>
<b>Description:</b>
<ul>
<p>
The <code>mkfats()</code> formats a FAT file system image on the block
device specified by <code>pathname</code>
</p>
<p>Assumptions: The caller must assure that the block driver is not mounted and not in
use when this function is called.
The result of formatting a mounted device is indeterminate (but likely not good).
</p>
</ul>
</p>
<p>
<b>Input Parameters:</b>
<ul>
<li>
<code>pathname</code>
The full path to the registered block driver in the file system.
</li>
<li>
<code>fmt</code>
A reference to an instance of a structure that provides caller-selectable
attributes of the created FAT file system.
<ul>
<pre>
struct fat_format_s
{
uint8_t ff_nfats; /* Number of FATs */
uint8_t ff_fattype; /* FAT size: 0 (autoselect), 12, 16, or 32 */
uint8_t ff_clustshift; /* Log2 of sectors per cluster: 0-5, 0xff (autoselect) */
uint8_t ff_volumelabel[11]; /* Volume label */
uint16_t ff_backupboot; /* Sector number of the backup boot sector (0=use default)*/
uint16_t ff_rootdirentries; /* Number of root directory entries */
uint16_t ff_rsvdseccount; /* Reserved sectors */
uint32_t ff_hidsec; /* Count of hidden sectors preceding fat */
uint32_t ff_volumeid; /* FAT volume id */
uint32_t ff_nsectors; /* Number of sectors from device to use: 0: Use all */
};
</pre>
</ul></li>
</li>
</ul>
</p>
<p>
<b>Returned Value:</b>
<ul>
<p>
Zero (<code>OK</code>) on success;
-1 (<code>ERROR</code>) on failure with <code>errno</code> set appropriately:
<ul>
<li><code>EINVAL</code> -
NULL block driver string, bad number of FATS in <code>fmt</code>,
bad FAT size in <code>fmt</code>, bad cluster size in <code>fmt</code>
</li>
<li><code>ENOENT</code> -
<code>pathname</code> does not refer to anything in the file-system.
</li>
<li><code>ENOTBLK</code> -
<code>pathname</code> does not refer to a block driver
</li>
<li><code>EACCESS</code> -
block driver does not support write or geometry methods
</li>
</ul>
</p>
</ul>
</p>
<h3><a name="mmapxip">2.10.11 <code>mmap()</code> and eXecute In Place (XIP)</a></h3>
<p> <p>
NuttX operates in a flat open address space and is focused on MCUs that do NuttX operates in a flat open address space and is focused on MCUs that do
support Memory Management Units (MMUs). Therefore, NuttX generally does not support Memory Management Units (MMUs). Therefore, NuttX generally does not
@@ -9170,8 +9091,7 @@ struct fat_format_s
</p> </p>
<ul><pre> <ul><pre>
#include &lt;sys/mman.h&gt; #include &lt;sys/mman.h&gt;
int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt); FAR void *mmap(FAR void *start, size_t length, int prot, int flags, int fd, off_t offset);
FAR void *mmap(FAR void *start, size_t length, int prot, int flags, int fd, off_t offset)
</pre></ul> </pre></ul>
<p> <p>
<b>Description:</b> <b>Description:</b>
@@ -10525,7 +10445,6 @@ notify a task when a message is available on a queue.
<li><a href="#drvrunistdops">lseek</a></li> <li><a href="#drvrunistdops">lseek</a></li>
<li><a href="#Message_Queue">Named Message Queue Interfaces</a> <li><a href="#Message_Queue">Named Message Queue Interfaces</a>
<li><a href="#standardio">mkdir</a></li> <li><a href="#standardio">mkdir</a></li>
<li><a href="#mkfatfs">mkfatfs</a></li>
<li><a href="#mkfifo">mkfifo</a></li> <li><a href="#mkfifo">mkfifo</a></li>
<li><a href="#mktime">mktime</a></li> <li><a href="#mktime">mktime</a></li>
<li><a href="#mqclose">mq_close</a></li> <li><a href="#mqclose">mq_close</a></li>
-7
View File
@@ -645,17 +645,10 @@ o Kernel/Protected Build
COMMAND KERNEL INTERFACE(s) COMMAND KERNEL INTERFACE(s)
-------- ---------------------------------------------- -------- ----------------------------------------------
mkfatfs mkfatfs
mkrd ramdisk_register() mkrd ramdisk_register()
ping icmp_ping() ping icmp_ping()
mount foreach_mountpoint() mount foreach_mountpoint()
The busybox mkfatfs does not involve any OS calls; it does
its job by simply opening the block driver (using open/xopen)
and modifying it with write operations. See:
http://git.busybox.net/busybox/tree/util-linux/mkfs_vfat.c
Status: Open Status: Open
Priority: Medium/High -- the kernel build configuration is not fully fielded Priority: Medium/High -- the kernel build configuration is not fully fielded
yet. yet.
-3
View File
@@ -66,9 +66,6 @@ ifeq ($(CONFIG_LPC31_USBOTG),y)
ifeq ($(CONFIG_USBHOST),y) ifeq ($(CONFIG_USBHOST),y)
CSRCS += lpc31_usbhost.c CSRCS += lpc31_usbhost.c
endif endif
ifeq ($(CONFIG_USBMSC),y)
CSRCS += lpc31_usbmsc.c
endif
endif endif
include $(TOPDIR)/configs/Board.mk include $(TOPDIR)/configs/Board.mk
-127
View File
@@ -1,127 +0,0 @@
/****************************************************************************
* configs/ea3131/src/lpc31_usbmsc.c
*
* Copyright (C) 2010, 2013, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Configure and register the SAM3U MMC/SD SDIO block driver.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <stdlib.h>
#include <nuttx/board.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/mkfatfs.h>
#include <nuttx/drivers/ramdisk.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_SYSTEM_USBMSC_DEVMINOR1
# define CONFIG_SYSTEM_USBMSC_DEVMINOR1 0
#endif
#ifndef CONFIG_SYSTEM_USBMSC_DEVPATH1
# define CONFIG_SYSTEM_USBMSC_DEVPATH1 "/dev/ram"
#endif
static const char g_source[] = CONFIG_SYSTEM_USBMSC_DEVPATH1;
static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
#define USBMSC_NSECTORS 64
#define USBMSC_SECTORSIZE 512
#define BUFFER_SIZE (USBMSC_NSECTORS*USBMSC_SECTORSIZE)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_usbmsc_initialize
*
* Description:
* Perform architecture specific initialization of the USB MSC device.
*
****************************************************************************/
int board_usbmsc_initialize(int port)
{
uint8_t *pbuffer;
int ret;
pbuffer = (uint8_t *)kmm_malloc(BUFFER_SIZE);
if (!pbuffer)
{
err("ERROR: Failed to allocate ramdisk of size %d\n", BUFFER_SIZE);
return -ENOMEM;
}
/* Register a RAMDISK device to manage this RAM image */
ret = ramdisk_register(CONFIG_SYSTEM_USBMSC_DEVMINOR1,
pbuffer,
USBMSC_NSECTORS,
USBMSC_SECTORSIZE,
RDFLAG_WRENABLED | RDFLAG_FUNLINK);
if (ret < 0)
{
err("ERROR: create_ramdisk: Failed to register ramdisk at %s: %d\n",
g_source, -ret);
kmm_free(pbuffer);
return ret;
}
/* Create a FAT filesystem on the ramdisk */
ret = mkfatfs(g_source, &g_fmt);
if (ret < 0)
{
err("ERROR: create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n",
g_source);
/* kmm_free(pbuffer); -- RAM disk is registered */
return ret;
}
return 0;
}
-3
View File
@@ -55,8 +55,5 @@ endif
ifeq ($(CONFIG_PAGING),y) ifeq ($(CONFIG_PAGING),y)
CSRCS += lpc31_fillpage.c CSRCS += lpc31_fillpage.c
endif endif
ifeq ($(CONFIG_USBMSC),y)
CSRCS += lpc31_usbmsc.c
endif
include $(TOPDIR)/configs/Board.mk include $(TOPDIR)/configs/Board.mk
-128
View File
@@ -1,128 +0,0 @@
/****************************************************************************
* configs/ea3152/src/lpc31_usbmsc.c
*
* Copyright (C) 2011, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Configure and register the SAM3U MMC/SD SDIO block driver.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <stdlib.h>
#include <nuttx/board.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/mkfatfs.h>
#include <nuttx/drivers/ramdisk.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_SYSTEM_USBMSC_DEVMINOR1
# define CONFIG_SYSTEM_USBMSC_DEVMINOR1 0
#endif
#ifndef CONFIG_SYSTEM_USBMSC_DEVPATH1
# define CONFIG_SYSTEM_USBMSC_DEVPATH1 "/dev/ram"
#endif
static const char g_source[] = CONFIG_SYSTEM_USBMSC_DEVPATH1;
static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
#define USBMSC_NSECTORS 64
#define USBMSC_SECTORSIZE 512
#define BUFFER_SIZE (USBMSC_NSECTORS*USBMSC_SECTORSIZE)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_usbmsc_initialize
*
* Description:
* Perform architecture specific initialization of the USB MSC device.
*
****************************************************************************/
int board_usbmsc_initialize(int port)
{
uint8_t *pbuffer;
int ret;
pbuffer = (uint8_t *)kmm_malloc(BUFFER_SIZE);
if (!pbuffer)
{
err("ERROR: board_usbmsc_initialize: Failed to allocate ramdisk of size %d\n",
BUFFER_SIZE);
return -ENOMEM;
}
/* Register a RAMDISK device to manage this RAM image */
ret = ramdisk_register(CONFIG_SYSTEM_USBMSC_DEVMINOR1,
pbuffer,
USBMSC_NSECTORS,
USBMSC_SECTORSIZE,
RDFLAG_WRENABLED | RDFLAG_FUNLINK);
if (ret < 0)
{
err("ERROR: create_ramdisk: Failed to register ramdisk at %s: %d\n",
g_source, -ret);
kmm_free(pbuffer);
return ret;
}
/* Create a FAT filesystem on the ramdisk */
ret = mkfatfs(g_source, &g_fmt);
if (ret < 0)
{
err("ERROR: create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n",
g_source);
/* kmm_free(pbuffer); -- RAM disk is registered */
return ret;
}
return 0;
}
@@ -2106,14 +2106,5 @@
<file> <file>
<name>$PROJ_DIR$/../../../../../fs/fat/fs_fat32util.c</name> <name>$PROJ_DIR$/../../../../../fs/fat/fs_fat32util.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$/../../../../../fs/fat/fs_mkfatfs.c</name>
</file>
<file>
<name>$PROJ_DIR$/../../../../../fs/fat/fs_configfat.c</name>
</file>
<file>
<name>$PROJ_DIR$/../../../../../fs/fat/fs_writefat.c</name>
</file>
</group> </group>
</project> </project>
@@ -608,21 +608,6 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>../../../../../fs/fat/fs_fat32util.c</FilePath> <FilePath>../../../../../fs/fat/fs_fat32util.c</FilePath>
</File> </File>
<File>
<FileName>fs_mkfatfs.c</FileName>
<FileType>1</FileType>
<FilePath>../../../../../fs/fat/fs_mkfatfs.c</FilePath>
</File>
<File>
<FileName>fs_configfat.c</FileName>
<FileType>1</FileType>
<FilePath>../../../../../fs/fat/fs_configfat.c</FilePath>
</File>
<File>
<FileName>fs_writefat.c</FileName>
<FileType>1</FileType>
<FilePath>../../../../../fs/fat/fs_writefat.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
</Groups> </Groups>
@@ -61,7 +61,6 @@
#include <nuttx/drivers/drivers.h> #include <nuttx/drivers/drivers.h>
#include <nuttx/drivers/ramdisk.h> #include <nuttx/drivers/ramdisk.h>
#include <nuttx/fs/nxffs.h> #include <nuttx/fs/nxffs.h>
#include <nuttx/fs/mkfatfs.h>
#include <nuttx/binfmt/elf.h> #include <nuttx/binfmt/elf.h>
#include <nuttx/i2c/i2c_master.h> #include <nuttx/i2c/i2c_master.h>
+1 -6
View File
@@ -1,7 +1,7 @@
############################################################################ ############################################################################
# Make.defs # Make.defs
# #
# Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved. # Copyright (C) 2008, 2011, 2013, 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org> # Author: Gregory Nutt <gnutt@nuttx.org>
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@@ -39,11 +39,6 @@ ifeq ($(CONFIG_FS_FAT),y)
ASRCS += ASRCS +=
CSRCS += fs_fat32.c fs_fat32dirent.c fs_fat32attrib.c fs_fat32util.c CSRCS += fs_fat32.c fs_fat32dirent.c fs_fat32attrib.c fs_fat32util.c
# Files required for mkfatfs utility function
ASRCS +=
CSRCS += fs_mkfatfs.c fs_configfat.c fs_writefat.c
# Include FAT build support # Include FAT build support
DEPPATH += --dep-path fat DEPPATH += --dep-path fat
File diff suppressed because it is too large Load Diff
-343
View File
@@ -1,343 +0,0 @@
/****************************************************************************
* fs/fat/fs_writefat.c
*
* Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/fat.h>
#include <nuttx/fs/mkfatfs.h>
#include "inode/inode.h"
#include "fs_fat32.h"
#include "fs_mkfatfs.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: mkfatfs_getgeometry
*
* Description:
* Get the sector size and number of sectors of the underlying block
* device.
*
* Input:
* fmt - Caller specified format parameters
* var - Other format parameters that are not caller specifiable. (Most
* set by mkfatfs_configfatfs()).
*
* Return:
* Zero on success; negated errno on failure
*
****************************************************************************/
static inline int mkfatfs_getgeometry(FAR struct fat_format_s *fmt,
FAR struct fat_var_s *var)
{
struct geometry geometry;
int ret;
/* Get the device geometry */
ret = DEV_GEOMETRY(geometry);
if (ret < 0)
{
ferr("ERROR: geometry() returned %d\n", ret);
return ret;
}
if (!geometry.geo_available || !geometry.geo_writeenabled)
{
ferr("ERROR: Media is not available\n", ret);
return -ENODEV;
}
/* Check if the user provided maxblocks was provided and, if so, that is it less than
* the actual number of blocks on the device.
*/
if (fmt->ff_nsectors != 0)
{
if (fmt->ff_nsectors > geometry.geo_nsectors)
{
ferr("ERROR: User maxblocks (%d) exceeds blocks on device (%d)\n",
fmt->ff_nsectors, geometry.geo_nsectors);
return -EINVAL;
}
}
else
{
/* Use the actual number of blocks on the device */
fmt->ff_nsectors = geometry.geo_nsectors;
}
/* Verify that we can handle this sector size */
var->fv_sectorsize = geometry.geo_sectorsize;
switch (var->fv_sectorsize)
{
case 512:
var->fv_sectshift = 9;
break;
case 1024:
var->fv_sectshift = 10;
break;
case 2048:
var->fv_sectshift = 11;
break;
case 4096:
var->fv_sectshift = 12;
break;
default:
ferr("ERROR: Unsupported sector size: %d\n", var->fv_sectorsize);
return -EPERM;
}
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mkfatfs
*
* Description:
* Make a FAT file system image on the specified block device. This
* function can automatically format a FAT12 or FAT16 file system. By
* tradition, FAT32 will only be selected is explicitly requested.
*
* Inputs:
* pathname - the full path to a registered block driver
* fmt - Describes characteristics of the desired filesystem
*
* Return:
* Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately:
*
* EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT
* size in 'fmt', bad cluster size in 'fmt'
* ENOENT - 'pathname' does not refer to anything in the filesystem.
* ENOTBLK - 'pathname' does not refer to a block driver
* EACCES - block driver does not support wrie or geometry methods
*
* Assumptions:
* - The caller must assure that the block driver is not mounted and not in
* use when this function is called. The result of formatting a mounted
* device is indeterminate (but likely not good).
*
****************************************************************************/
int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt)
{
struct fat_var_s var;
int ret;
/* Initialize */
memset(&var, 0, sizeof(struct fat_var_s));
/* Get the filesystem creation time */
var.fv_createtime = fat_systime2fattime();
/* Verify format options (only when DEBUG enabled) */
#ifdef CONFIG_DEBUG_FEATURES
if (!pathname)
{
ferr("ERROR: No block driver path\n");
ret = -EINVAL;
goto errout;
}
if (fmt->ff_nfats < 1 || fmt->ff_nfats > 4)
{
ferr("ERROR: Invalid number of fats: %d\n", fmt->ff_nfats);
ret = -EINVAL;
goto errout;
}
if (fmt->ff_fattype != 0 && fmt->ff_fattype != 12 &&
fmt->ff_fattype != 16 && fmt->ff_fattype != 32)
{
ferr("ERROR: Invalid FAT size: %d\n", fmt->ff_fattype);
ret = -EINVAL;
goto errout;
}
#endif
/* 0 will auto-selected by FAT12 and FAT16 (only). Otherwise,
* fv_fattype will specify the exact format to use.
*/
var.fv_fattype = fmt->ff_fattype;
/* The valid range off ff_clustshift is {0,1,..7} corresponding to
* cluster sizes of {1,2,..128} sectors. The special value of 0xff
* means that we should autoselect the cluster sizel.
*/
#ifdef CONFIG_DEBUG_FEATURES
if (fmt->ff_clustshift > 7 && fmt->ff_clustshift != 0xff)
{
ferr("ERROR: Invalid cluster shift value: %d\n", fmt->ff_clustshift);
ret = -EINVAL;
goto errout;
}
if (fmt->ff_rootdirentries != 0 &&
(fmt->ff_rootdirentries < 16 || fmt->ff_rootdirentries > 32767))
{
ferr("ERROR: Invalid number of root dir entries: %d\n",
fmt->ff_rootdirentries);
ret = -EINVAL;
goto errout;
}
if (fmt->ff_rsvdseccount != 0 && (fmt->ff_rsvdseccount < 1 ||
fmt->ff_rsvdseccount > 32767))
{
ferr("ERROR: Invalid number of reserved sectors: %d\n",
fmt->ff_rsvdseccount);
ret = -EINVAL;
goto errout;
}
#endif
/* Find the inode of the block driver indentified by 'source' */
ret = open_blockdriver(pathname, 0, &var.fv_inode);
if (ret < 0)
{
ferr("ERROR: Failed to open %s\n", pathname);
goto errout;
}
/* Make sure that the inode supports the write and geometry methods at a minimum */
if (!var.fv_inode->u.i_bops->write || !var.fv_inode->u.i_bops->geometry)
{
ferr("ERROR: %s does not support write or geometry methods\n",
pathname);
ret = -EACCES;
goto errout_with_driver;
}
/* Determine the volume configuration based upon the input values and upon the
* reported device geometry.
*/
ret = mkfatfs_getgeometry(fmt, &var);
if (ret < 0)
{
goto errout_with_driver;
}
/* Configure the file system */
ret = mkfatfs_configfatfs(fmt, &var);
if (ret < 0)
{
goto errout_with_driver;
}
/* Allocate a buffer that will be working sector memory */
#ifdef CONFIG_FAT_DMAMEMORY
var.fv_sect = (FAR uint8_t *)fat_dma_alloc(var.fv_sectorsize);
#else
var.fv_sect = (FAR uint8_t *)kmm_malloc(var.fv_sectorsize);
#endif
if (!var.fv_sect)
{
ferr("ERROR: Failed to allocate working buffers\n");
goto errout_with_driver;
}
/* Write the filesystem to media */
ret = mkfatfs_writefatfs(fmt, &var);
errout_with_driver:
/* Close the driver */
(void)close_blockdriver(var.fv_inode);
errout:
/* Release all allocated memory */
if (var.fv_sect)
{
#ifdef CONFIG_FAT_DMAMEMORY
fat_dma_free(var.fv_sect, var.fv_sectorsize);
#else
kmm_free(var.fv_sect);
#endif
}
/* Return any reported errors */
if (ret < 0)
{
set_errno(-ret);
return ERROR;
}
return OK;
}
-169
View File
@@ -1,169 +0,0 @@
/****************************************************************************
* fs/fat/fs_mkfat.h
*
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __FS_FAT_FS_MKATFS_H
#define __FS_FAT_FS_MKATFS_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Only the "hard drive" media type is used */
#define FAT_DEFAULT_MEDIA_TYPE 0xf8
/* Default hard driver geometry */
#define FAT_DEFAULT_SECPERTRK 63
#define FAT_DEFAULT_NUMHEADS 255
/* FSINFO is always at this sector */
#define FAT_DEFAULT_FSINFO_SECTOR 1
/* FAT32 foot cluster number */
#define FAT32_DEFAULT_ROOT_CLUSTER 2
/* Macros to simplify direct block driver access */
#define DEV_OPEN() \
var->fb_inode->u.i_bops->open ? \
var->fv_inode->u.i_bops->open(var->fv_inode) : \
0
#define DEV_CLOSE() \
var->fb_inode->u.i_bops->close ? \
var->fv_inode->u.i_bops->close(var->fv_inode) : \
0
#define DEV_READ(buf, sect, nsect) \
var->fv_inode->u.i_bops->read(var->fv_inode, buf, sect, nsect)
#define DEV_WRITE(buf, sect, nsect) \
var->fv_inode->u.i_bops->write(var->fv_inode, buf, sect, nsect)
#define DEV_GEOMETRY(geo) \
var->fv_inode->u.i_bops->geometry(var->fv_inode, &geo)
#define DEV_IOCTL(cmd, arg) \
var->fv_inode->u.i_bops->ioctl(var->fv_inode, cmd, arg)
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure (plus the user-provided struct fat_format_s) describes
* the format FAT file system. All "global" variables used in the format
* logic are contained in this structure so that is possible to format two
* block devices concurrently.
*/
struct fat_var_s
{
struct inode *fv_inode; /* The block driver "handle" */
uint8_t fv_jump[3]; /* 3-byte boot jump instruction */
uint8_t fv_sectshift; /* Log2 of fv_sectorsize */
uint8_t fv_nrootdirsects; /* Number of root directory sectors */
uint8_t fv_fattype; /* FAT size: 0 (not determined), 12, 16, or 32 */
uint16_t fv_bootcodesize; /* Size of array at fv_bootcode */
uint32_t fv_createtime; /* Creation time */
uint32_t fv_sectorsize; /* Size of one hardware sector */
uint32_t fv_nfatsects; /* Number of sectors in each FAT */
uint32_t fv_nclusters; /* Number of clusters */
uint8_t *fv_sect; /* Allocated working sector buffer */
const uint8_t *fv_bootcode; /* Points to boot code to put into MBR */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: mkfatfs_configfatfs
*
* Description:
* Based on the geometry of the block device and upon the caller-selected
* values, configure the FAT filesystem for the device.
*
* Input:
* fmt - Caller specified format parameters
* var - Holds disk geomtry data. Also, the location to return FAT
* configuration data
*
* Return:
* Zero on success; negated errno on failure
*
****************************************************************************/
int mkfatfs_configfatfs(FAR struct fat_format_s *fmt,
FAR struct fat_var_s *var);
/****************************************************************************
* Name: mkfatfs_writefat
*
* Description:
* Write the configured fat filesystem to the block device
*
* Input:
* fmt - Caller specified format parameters
* var - Other format parameters that are not caller specifiable. (Most
* set by mkfatfs_configfatfs()).
*
* Return:
* Zero on success; negated errno on failure
*
****************************************************************************/
int mkfatfs_writefatfs(FAR struct fat_format_s *fmt,
FAR struct fat_var_s *var);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __FS_FAT_FS_MKATFS_H */
File diff suppressed because it is too large Load Diff
-149
View File
@@ -1,149 +0,0 @@
/****************************************************************************
* include/nuttx/fs/mkfatfs.h
*
* Copyright (C) 2008-2009, 2012, 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_FS_MKFATFS_H
#define __INCLUDE_NUTTX_FS_MKFATFS_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MKFATFS_DEFAULT_NFATS 2 /* 2: Default number of FATs */
#define MKFATFS_DEFAULT_FATTYPE 0 /* 0: Autoselect FAT size */
#define MKFATFS_DEFAULT_CLUSTSHIFT 0xff /* 0xff: Autoselect cluster size */
#define MKFATFS_DEFAULT_VOLUMELABEL { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }
#define MKFATFS_DEFAULT_BKUPBOOT 0 /* 0: Determine sector number of the backup boot sector */
#define MKFATFS_DEFAULT_ROOTDIRENTS 0 /* 0: Autoselect number of root directory entries */
#define MKFATFS_DEFAULT_RSVDSECCOUNT 0 /* 0: Autoselect number reserved sectors (usually 32) */
#define MKFATFS_DEFAULT_HIDSEC 0 /* No hidden sectors */
#define MKFATFS_DEFAULT_VOLUMEID 0 /* No volume ID */
#define MKFATFS_DEFAULT_NSECTORS 0 /* 0: Use all sectors on device */
#define FAT_FORMAT_INITIALIZER \
{ \
MKFATFS_DEFAULT_NFATS, \
MKFATFS_DEFAULT_FATTYPE, \
MKFATFS_DEFAULT_CLUSTSHIFT, \
MKFATFS_DEFAULT_VOLUMELABEL, \
MKFATFS_DEFAULT_BKUPBOOT, \
MKFATFS_DEFAULT_ROOTDIRENTS, \
MKFATFS_DEFAULT_RSVDSECCOUNT, \
MKFATFS_DEFAULT_HIDSEC, \
MKFATFS_DEFAULT_VOLUMEID, \
MKFATFS_DEFAULT_NSECTORS \
}
/****************************************************************************
* Public Types
****************************************************************************/
/* These are input parameters for the format. On return, these values may be
* overwritten with actual values used in the format.
*/
struct fat_format_s
{
uint8_t ff_nfats; /* Number of FATs */
uint8_t ff_fattype; /* FAT size: 0 (autoselect), 12, 16, or 32 */
uint8_t ff_clustshift; /* Log2 of sectors per cluster: 0-5, 0xff (autoselect) */
uint8_t ff_volumelabel[11]; /* Volume label */
uint16_t ff_backupboot; /* Sector number of the backup boot sector (0=use default)*/
uint16_t ff_rootdirentries; /* Number of root directory entries */
uint16_t ff_rsvdseccount; /* Reserved sectors */
uint32_t ff_hidsec; /* Count of hidden sectors preceding fat */
uint32_t ff_volumeid; /* FAT volume id */
uint32_t ff_nsectors; /* Number of sectors from device to use: 0: Use all */
};
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: mkfatfs
*
* Description:
* Make a FAT file system image on the specified block device. This
* function can automatically format a FAT12 or FAT16 file system. By
* tradition, FAT32 will only be selected is explicitly requested.
*
* Inputs:
* pathname - the full path to a registered block driver
* fmt - Describes characteristics of the desired filesystem
*
* Return:
* Zero (OK) on success; -1 (ERROR) on failure with errno set appropriately:
*
* EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT
* size in 'fmt', bad cluster size in 'fmt'
* ENOENT - 'pathname' does not refer to anything in the filesystem.
* ENOTBLK - 'pathname' does not refer to a block driver
* EACCESS - block driver does not support write or geometry methods
*
* Assumptions:
* - The caller must assure that the block driver is not mounted and not in
* use when this function is called. The result of formatting a mounted
* device is indeterminate (but likely not good).
*
****************************************************************************/
int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_FS_MKFATFS_H */