Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfs: file system abstraction #5616

Merged
merged 16 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,20 @@ ifneq (,$(filter emcute,$(USEMODULE)))
USEMODULE += xtimer
endif

ifneq (,$(filter constfs,$(USEMODULE)))
USEMODULE += vfs
endif

ifneq (,$(filter devfs,$(USEMODULE)))
USEMODULE += vfs
endif

ifneq (,$(filter vfs,$(USEMODULE)))
ifeq (native, $(BOARD))
USEMODULE += native_vfs
endif
endif

# include package dependencies
-include $(USEPKG:%=$(RIOTPKG)/%/Makefile.dep)

Expand Down
6 changes: 2 additions & 4 deletions boards/mulle/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += lis3dh
endif

# The RTT clock drives the core clock in the default configuration
FEATURES_REQUIRED += periph_rtt

# The Mulle uses NVRAM to store persistent variables, such as boot count.
USEMODULE += nvram_spi
FEATURES_REQUIRED += periph_spi
USEMODULE += nvram
USEMODULE += devfs

ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
Expand Down
14 changes: 13 additions & 1 deletion boards/mulle/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
#include "cpu.h"
#include "mcg.h"
#include "periph/gpio.h"
#include "periph/uart.h"
#include "periph/rtt.h"
#include "periph/spi.h"
#include "nvram-spi.h"
#include "nvram.h"
#include "xtimer.h"
#include "vfs.h"
#include "fs/devfs.h"

static nvram_t mulle_nvram_dev;
nvram_t *mulle_nvram = &mulle_nvram_dev;
Expand All @@ -39,6 +41,12 @@ static nvram_spi_params_t nvram_spi_params = {
.address_count = MULLE_NVRAM_SPI_ADDRESS_COUNT,
};

static devfs_t mulle_nvram_devfs = {
.path = "/mulle-fram",
.f_op = &nvram_vfs_ops,
.private_data = &mulle_nvram_dev,
};

/** @brief Initialize the GPIO pins controlling the power switches. */
static inline void power_pins_init(void);

Expand Down Expand Up @@ -210,6 +218,10 @@ static int mulle_nvram_init(void)
return -5;
}
}

/* Register DevFS node */
devfs_register(&mulle_nvram_devfs);

return 0;
}

Expand Down
10 changes: 2 additions & 8 deletions cpu/atmega_common/avr-libc-extra/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
#ifndef TIME_H
#define TIME_H

#include <inttypes.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -111,12 +111,6 @@ extern "C" {
/** \ingroup avr_time */
/* @{ */

/**
time_t represents seconds elapsed from Midnight, Jan 1 2000 UTC (the Y2K 'epoch').
Its range allows this implementation to represent time up to Tue Feb 7 06:28:15 2136 UTC.
*/
typedef uint32_t time_t;

/**
The time function returns the systems current time stamp.
If timer is not a null pointer, the return value is also assigned to the object it points to.
Expand Down
92 changes: 85 additions & 7 deletions cpu/atmega_common/avr-libc-extra/unistd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2016 Eistec AB
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
Expand All @@ -9,21 +10,98 @@
#ifndef UNISTD_H
#define UNISTD_H

#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

#define STDIN_FILENO 0 ///< stdin file descriptor
#define STDOUT_FILENO 1 ///< stdout file descriptor
#define STDERR_FILENO 2 ///< stderr file descriptor
#define STDIN_FILENO 0 /* standard input file descriptor */
#define STDOUT_FILENO 1 /* standard output file descriptor */
#define STDERR_FILENO 2 /* standard error file descriptor */

int close(int fildes);
#define F_OK 0
#define R_OK 4
#define W_OK 2
#define X_OK 1

typedef uint32_t useconds_t;
int usleep(useconds_t usec);
unsigned int sleep(unsigned int seconds);
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

int access(const char *, int);
unsigned alarm(unsigned);
int chdir(const char *);
int chown(const char *, uid_t, gid_t);
int close(int);
size_t confstr(int, char *, size_t);
int dup(int);
int dup2(int, int);
void _exit(int);
int execl(const char *, const char *, ...);
int execle(const char *, const char *, ...);
int execlp(const char *, const char *, ...);
int execv(const char *, char *const []);
int execve(const char *, char *const [], char *const []);
int execvp(const char *, char *const []);
int faccessat(int, const char *, int, int);
int fchdir(int);
int fchown(int, uid_t, gid_t);
int fchownat(int, const char *, uid_t, gid_t, int);
int fexecve(int, char *const [], char *const []);
pid_t fork(void);
long fpathconf(int, int);
int ftruncate(int, off_t);
char *getcwd(char *, size_t);
gid_t getegid(void);
uid_t geteuid(void);
gid_t getgid(void);
int getgroups(int, gid_t []);
int gethostname(char *, size_t);
char *getlogin(void);
int getlogin_r(char *, size_t);
int getopt(int, char * const [], const char *);
pid_t getpgid(pid_t);
pid_t getpgrp(void);
pid_t getpid(void);
pid_t getppid(void);
pid_t getsid(pid_t);
uid_t getuid(void);
int isatty(int);
int lchown(const char *, uid_t, gid_t);
int link(const char *, const char *);
int linkat(int, const char *, int, const char *, int);
off_t lseek(int, off_t, int);
long pathconf(const char *, int);
int pause(void);
int pipe(int [2]);
ssize_t pread(int, void *, size_t, off_t);
ssize_t pwrite(int, const void *, size_t, off_t);
ssize_t read(int, void *, size_t);
ssize_t readlink(const char *restrict, char *restrict, size_t);
ssize_t readlinkat(int, const char *restrict, char *restrict, size_t);
int rmdir(const char *);
int setegid(gid_t);
int seteuid(uid_t);
int setgid(gid_t);
int setpgid(pid_t, pid_t);
pid_t setsid(void);
int setuid(uid_t);
unsigned sleep(unsigned);
int symlink(const char *, const char *);
int symlinkat(const char *, int, const char *);
long sysconf(int);
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
int truncate(const char *, off_t);
char *ttyname(int);
int ttyname_r(int, char *, size_t);
int unlink(const char *);
int unlinkat(int, const char *, int);
int usleep(useconds_t);
ssize_t write(int, const void *, size_t);

#ifdef __cplusplus
}
Expand Down
120 changes: 120 additions & 0 deletions cpu/atmega_common/include/sys/stat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (C) 2016 Eistec AB
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @file
* @brief POSIX compatible sys/stat.h definitions
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/

#ifndef SYS_STAT_H_
#define SYS_STAT_H_

#include <time.h> /* for struct timespec */
#include <sys/types.h> /* for fsblkcnt_t, fsfilcnt_t */

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief File information
*/
struct stat {
dev_t st_dev; /**< Device ID of device containing file. */
ino_t st_ino; /**< File serial number. */
mode_t st_mode; /**< Mode of file (see below). */
nlink_t st_nlink; /**< Number of hard links to the file. */
uid_t st_uid; /**< User ID of file. */
gid_t st_gid; /**< Group ID of file. */
dev_t st_rdev; /**< Device ID (if file is character or block special). */
/**
* For regular files, the file size in bytes.
* For symbolic links, the length in bytes of the pathname contained in the
* symbolic link.
* For a shared memory object, the length in bytes.
* For a typed memory object, the length in bytes.
* For other file types, the use of this field is unspecified.
*/
off_t st_size;
struct timespec st_atim; /**< Last data access timestamp. */
struct timespec st_mtim; /**< Last data modification timestamp. */
struct timespec st_ctim; /**< Last file status change timestamp. */
/**
* A file system-specific preferred I/O block size for this object. In some
* file system types, this may vary from file to file.
*/
blksize_t st_blksize;
blkcnt_t st_blocks; /**< Number of blocks allocated for this object. */
};

/* These bitmasks and numbers are the same as in newlib */
#define S_IFMT 0170000 /* type of file */
#define S_IFDIR 0040000 /* directory */
#define S_IFCHR 0020000 /* character special */
#define S_IFBLK 0060000 /* block special */
#define S_IFREG 0100000 /* regular */
#define S_IFLNK 0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFIFO 0010000 /* fifo */

/* These numbers are well-known and can be found in the manual page for sys_stat.h */
#define S_IRWXU 0700 /**< Read, write, execute/search by owner. */
#define S_IRUSR 0400 /**< Read permission, owner. */
#define S_IWUSR 0200 /**< Write permission, owner. */
#define S_IXUSR 0100 /**< Execute/search permission, owner. */
#define S_IRWXG 070 /**< Read, write, execute/search by group. */
#define S_IRGRP 040 /**< Read permission, group. */
#define S_IWGRP 020 /**< Write permission, group. */
#define S_IXGRP 010 /**< Execute/search permission, group. */
#define S_IRWXO 07 /**< Read, write, execute/search by others. */
#define S_IROTH 04 /**< Read permission, others. */
#define S_IWOTH 02 /**< Write permission, others. */
#define S_IXOTH 01 /**< Execute/search permission, others. */
#define S_ISUID 04000 /**< Set-user-ID on execution. */
#define S_ISGID 02000 /**< Set-group-ID on execution. */
#define S_ISVTX 01000 /**< On directories, restricted deletion flag */

/* File type test macros, taken from newlib */
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)

/* These function prototypes are required by the standard */
int chmod(const char *, mode_t);
int fchmod(int, mode_t);
int fchmodat(int, const char *, mode_t, int);
int fstat(int, struct stat *);
int fstatat(int, const char *restrict, struct stat *restrict, int);
int futimens(int, const struct timespec [2]);
int lstat(const char *restrict, struct stat *restrict);
int mkdir(const char *, mode_t);
int mkdirat(int, const char *, mode_t);
int mkfifo(const char *, mode_t);
int mkfifoat(int, const char *, mode_t);
int mknod(const char *, mode_t, dev_t);
int mknodat(int, const char *, mode_t, dev_t);
int stat(const char *restrict, struct stat *restrict);
mode_t umask(mode_t);
int utimensat(int, const char *, const struct timespec [2], int);

/* Special tv_nsec values for futimens(2) and utimensat(2). */
#define UTIME_NOW (-2L)
#define UTIME_OMIT (-1L)

#ifdef __cplusplus
}
#endif

#endif /* SYS_STAT_H_ */

/** @} */
33 changes: 26 additions & 7 deletions cpu/atmega_common/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,41 @@
* directory for more details.
*/

#ifndef AVR_TYPES_H
#define AVR_TYPES_H
#ifndef SYS_TYPES_H_
#define SYS_TYPES_H_

#include <inttypes.h>
#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef int16_t suseconds_t;
typedef signed int ssize_t;
typedef unsigned int off_t;
typedef int32_t blkcnt_t; /**< Used for file block counts */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably a good idea to move the proposed atmega changes to a seperate PR, as they are mostly unrelated to this new feature. (here and above)

typedef int32_t blksize_t; /**< Used for block sizes */
typedef uint32_t clock_t; /**< Used for system times in clock ticks */
typedef uint32_t clockid_t; /**< Used for clock ID type in the clock and timer functions */
typedef int16_t dev_t; /**< Used for device IDs */
typedef uint32_t fsblkcnt_t; /**< Used for file system block counts */
typedef uint32_t fsfilcnt_t; /**< Used for file system file counts */
typedef uint16_t gid_t; /**< Used for group IDs */
typedef uint16_t id_t; /**< Used as a general identifier */
typedef uint32_t ino_t; /**< Used for file serial numbers */
typedef uint32_t key_t; /**< Used for XSI interprocess communication */
typedef uint32_t mode_t; /**< Used for some file attributes */
typedef uint16_t nlink_t; /**< Used for link counts */
typedef int32_t off_t; /**< Used for file sizes and offsets */
typedef int pid_t; /**< Used for process IDs and process group IDs */
typedef unsigned int size_t; /**< Used for sizes of objects */
typedef signed int ssize_t; /**< Used for a count of bytes or an error indication */
typedef int32_t suseconds_t; /**< Used for time in microseconds */
typedef int32_t time_t; /**< Used for time in seconds */
typedef uint32_t timer_t; /**< Used for timer ID returned by timer_create() */
typedef uint16_t uid_t; /**< Used for user IDs */
typedef uint32_t useconds_t; /**< Used for time in microseconds */

#ifdef __cplusplus
}
#endif

#endif /* ifndef AVR_TYPES_H */
#endif /* SYS_TYPES_H_ */
Loading