lib: posix: Add Posix Style File System API support

Add IEEE 1003.1 Posix Style file system API support.
These API's will internally use corresponding Zephyr
File System API's.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
This commit is contained in:
Ramakrishna Pallala 2018-05-03 17:17:22 +05:30 committed by Anas Nashif
commit eb0aaca64d
9 changed files with 550 additions and 19 deletions

57
include/posix/sys/stat.h Normal file
View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __POSIX_STAT_H__
#define __POSIX_STAT_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CONFIG_PTHREAD_IPC
#include <kernel.h>
#ifdef CONFIG_POSIX_FS
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
/* File open modes */
#define O_ACCMODE 0003
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#define SEEK_SET 0 /* Seek from beginning of file. */
#define SEEK_CUR 1 /* Seek from current position. */
#define SEEK_END 2 /* Seek from end of file. */
struct stat {
unsigned long st_size;
unsigned long st_blksize;
unsigned long st_blocks;
};
#endif /* CONFIG_POSIX_FS */
#endif /* CONFIG_PTHREAD_IPC */
#ifdef __cplusplus
}
#endif
#endif /* __POSIX_STAT_H__ */

View file

@ -11,7 +11,9 @@
extern "C" {
#endif
#ifndef CONFIG_ARCH_POSIX
#include_next <sys/types.h>
#endif
#ifdef CONFIG_PTHREAD_IPC
#include <kernel.h>

View file

@ -11,11 +11,46 @@ extern "C" {
#endif
#include "sys/types.h"
#include "sys/stat.h"
#ifdef CONFIG_POSIX_FS
#include <fs.h>
#undef PATH_MAX
#define PATH_MAX 256
typedef struct fs_dir_t DIR;
typedef unsigned int mode_t;
struct dirent {
unsigned int d_ino;
char d_name[PATH_MAX + 1];
};
/* File related operations */
extern int open(const char *name, int flags);
extern int close(int file);
extern ssize_t write(int file, char *buffer, unsigned int count);
extern ssize_t read(int file, char *buffer, unsigned int count);
extern int lseek(int file, int offset, int whence);
/* Directory related operations */
extern DIR *opendir(const char *dirname);
extern int closedir(DIR *dirp);
extern struct dirent *readdir(DIR *dirp);
/* File System related operations */
extern int rename(const char *old, const char *newp);
extern int unlink(const char *path);
extern int stat(const char *path, struct stat *buf);
extern int mkdir(const char *path, mode_t mode);
#endif
unsigned sleep(unsigned int seconds);
int usleep(useconds_t useconds);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __POSIX_UNISTD_H__ */