fs: support exfat filesystem

VELAPLATFO-15

Change-Id: I222cc45cec45018db26f7e0d1551d6e84285b739
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong
2021-08-09 14:53:09 +08:00
parent 0371a4df22
commit b3cb28a9ae
11 changed files with 1650 additions and 1 deletions
+1
View File
@@ -134,3 +134,4 @@ source "fs/littlefs/Kconfig"
source "fs/unionfs/Kconfig"
source "fs/userfs/Kconfig"
source "fs/hostfs/Kconfig"
source fs/exfat/Kconfig
+1
View File
@@ -56,6 +56,7 @@ include unionfs/Make.defs
include userfs/Make.defs
include hostfs/Make.defs
include littlefs/Make.defs
include exfat/Make.defs
endif
+7
View File
@@ -0,0 +1,7 @@
config FS_EXFAT
bool "EXFAT File System"
default n
select FS_LARGEFILE
depends on !DISABLE_MOUNTPOINT
---help---
Build the EXFAT file system. https://en.wikipedia.org/wiki/ExFAT
+64
View File
@@ -0,0 +1,64 @@
############################################################################
# fs/exfat/Make.defs
#
# 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.
#
############################################################################
ifeq ($(CONFIG_FS_EXFAT),y)
# Files required for exfat file system support
CSRCS += exfat_vfs.c exfat_io.c
DEPPATH += --dep-path exfat
VPATH += :exfat
CSRCS += cluster.c lookup.c mount.c node.c repair.c
CSRCS += time.c utils.c utf.c log.c
DEPPATH += --dep-path exfat/exfat/libexfat
VPATH += : exfat/exfat/libexfat
CSRCS += cbm.c fat.c mkexfat.c rootdir.c uctc.c uct.c
CSRCS += vbr.c
DEPPATH += --dep-path exfat/exfat/mkfs
VPATH += : exfat/exfat/mkfs
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" exfat/exfat/libexfat}
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" exfat/exfat/mkfs}
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" exfat/}
CFLAGS += -D__GLIBC__
EXFAT_VERSION ?= 1.3.0
EXFAT_TARBALL = v$(EXFAT_VERSION).tar.gz
$(EXFAT_TARBALL):
$(Q) curl -L -o exfat/$(EXFAT_TARBALL) https://https://github.com/relan/exfat/archive/$(EXFAT_TARBALL)
.exfatunpack: $(EXFAT_TARBALL)
$(Q) tar zxf exfat/$(EXFAT_TARBALL) -C exfat
$(Q) mv exfat/exfat-$(EXFAT_VERSION) exfat/exfat
$(Q) touch exfat/.exfatunpack
context::# .exfatunpack
distclean::
# $(call DELFILE, exfat/.exfatunpack)
# $(call DELFILE, exfat/$(EXFAT_TARBALL))
# $(call DELDIR, exfat/exfat)
endif
+46
View File
@@ -0,0 +1,46 @@
/* libexfat/config.h. Generated from config.h.in by configure. */
/* libexfat/config.h.in. Generated from configure.ac by autoheader. */
/* Name of package */
#define PACKAGE "exfat"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "relan@users.noreply.github.com"
/* Define to the full name of this package. */
#define PACKAGE_NAME "Free exFAT implementation"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "Free exFAT implementation 1.3.0"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "exfat"
/* Define to the home page for this package. */
#define PACKAGE_URL "https://github.com/relan/exfat"
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.3.0"
/* Define if block devices are not supported. */
/* #undef USE_UBLIO */
/* Version number of package */
#define VERSION "1.3.0"
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Enable vsyslog(). */
#define _DEFAULT_SOURCE /**/
/* Number of bits in a file offset, on hosts where this is settable. */
/* #undef _FILE_OFFSET_BITS */
/* Define for large files, on AIX-style hosts. */
/* #undef _LARGE_FILES */
/* Enable pread() and pwrite(). */
#define _XOPEN_SOURCE 500
+157
View File
@@ -0,0 +1,157 @@
/****************************************************************************
* fs/exfat/exfat_io.c
*
* 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 <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/kmalloc.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "exfat.h"
/****************************************************************************
* Private Types
****************************************************************************/
struct exfat_dev
{
struct file file;
enum exfat_mode mode;
off_t size; /* in bytes */
};
/****************************************************************************
* Public Functions
****************************************************************************/
FAR struct exfat_dev *exfat_open(FAR const char *spec, enum exfat_mode mode)
{
FAR struct exfat_dev *dev;
struct stat stbuf;
int ret;
dev = kmm_malloc(sizeof(*dev));
if (dev == NULL)
{
return NULL;
}
ret = file_open(&dev->file, spec, (mode != EXFAT_MODE_RO) ?
O_RDWR : O_RDONLY);
if (ret < 0)
{
if (mode == EXFAT_MODE_ANY)
{
mode = EXFAT_MODE_RO;
ret = file_open(&dev->file, spec, O_RDONLY);
}
if (ret < 0)
{
return NULL;
}
}
dev->mode = mode;
ret = file_fstat(&dev->file, &stbuf);
if (ret < 0)
{
goto errout;
}
if (!S_ISBLK(stbuf.st_mode) && !S_ISCHR(stbuf.st_mode) &&
!S_ISREG(stbuf.st_mode))
{
goto errout;
}
dev->size = stbuf.st_size;
return dev;
errout:
file_close(&dev->file);
kmm_free(dev);
return NULL;
}
int exfat_close(FAR struct exfat_dev *dev)
{
int ret;
ret = file_close(&dev->file);
kmm_free(dev);
return ret;
}
int exfat_fsync(FAR struct exfat_dev *dev)
{
int ret;
ret = file_ioctl(&dev->file, BIOC_FLUSH, 0);
return ret == -ENOTTY ? OK : ret;
}
enum exfat_mode exfat_get_mode(FAR const struct exfat_dev *dev)
{
return dev->mode;
}
off_t exfat_get_size(FAR const struct exfat_dev *dev)
{
return dev->size;
}
off_t exfat_seek(FAR struct exfat_dev *dev, off_t offset, int whence)
{
return file_seek(&dev->file, offset, whence);
}
ssize_t exfat_read(FAR struct exfat_dev *dev, FAR void *buffer, size_t size)
{
return file_read(&dev->file, buffer, size);
}
ssize_t exfat_write(FAR struct exfat_dev *dev, FAR const void *buffer,
size_t size)
{
return file_write(&dev->file, buffer, size);
}
ssize_t exfat_pread(FAR struct exfat_dev *dev, FAR void *buffer, size_t size,
off_t offset)
{
return file_pread(&dev->file, buffer, size, offset);
}
ssize_t exfat_pwrite(FAR struct exfat_dev *dev, FAR const void *buffer,
size_t size, off_t offset)
{
return file_pwrite(&dev->file, buffer, size, offset);
}
+1356
View File
File diff suppressed because it is too large Load Diff
+6
View File
@@ -105,6 +105,12 @@ FAR const char *fs_gettype(FAR struct statfs *statbuf)
break;
#endif
#ifdef CONFIG_FS_EXFAT
case EXFAT_SUPER_MAGIC:
fstype = "exfatfs";
break;
#endif
#ifdef CONFIG_NFS
case NFS_SUPER_MAGIC:
fstype = "nfs";
+8 -1
View File
@@ -51,7 +51,8 @@
*/
#if defined(CONFIG_FS_FAT) || defined(CONFIG_FS_ROMFS) || \
defined(CONFIG_FS_SMARTFS) || defined(CONFIG_FS_LITTLEFS)
defined(CONFIG_FS_SMARTFS) || defined(CONFIG_FS_LITTLEFS) || \
defined(CONFIG_FS_EXFAT)
# define BDFS_SUPPORT 1
#endif
@@ -101,6 +102,9 @@ extern const struct mountpt_operations smartfs_operations;
#ifdef CONFIG_FS_LITTLEFS
extern const struct mountpt_operations littlefs_operations;
#endif
#ifdef CONFIG_FS_EXFAT
extern const struct mountpt_operations exfatfs_operations;
#endif
static const struct fsmap_t g_bdfsmap[] =
{
@@ -115,6 +119,9 @@ static const struct fsmap_t g_bdfsmap[] =
#endif
#ifdef CONFIG_FS_LITTLEFS
{ "littlefs", &littlefs_operations },
#endif
#ifdef CONFIG_FS_EXFAT
{ "exfatfs", &exfatfs_operations },
#endif
{ NULL, NULL },
};
+3
View File
@@ -279,6 +279,9 @@ struct fs_dirent_s
#ifdef CONFIG_FS_LITTLEFS
FAR void *littlefs;
#endif
#ifdef CONFIG_FS_EXFAT
FAR void *exfat;
#endif
#ifdef CONFIG_FS_UNIONFS
struct fs_unionfsdir_s unionfs;
#endif
+1
View File
@@ -82,6 +82,7 @@
#define _XIAFS_SUPER_MAGIC 0x012fd16d
#define SPIFFS_SUPER_MAGIC 0x20090315
#define LITTLEFS_SUPER_MAGIC 0x0a732923
#define EXFAT_SUPER_MAGIC 0x45584641
/* NuttX specific file-systems */