28#ifndef _UCOMMON_FSYS_H_
29#define _UCOMMON_FSYS_H_
31#ifndef _UCOMMON_CONFIG_H_
35#ifndef _UCOMMON_PROTOCOLS_H_
39#ifndef _UCOMMON_THREAD_H_
43#ifndef _UCOMMON_TYPEREF_H_
47#ifndef _UCOMMON_MEMORY_H_
67#define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
70#if !defined(S_ISDIR) && defined(S_IFDIR)
71#define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR)
74#if !defined(S_ISCHR) && defined(S_IFCHR)
75#define S_ISCHR(mode) __S_ISTYPE((mode), S_IFCHR)
76#elif !defined(S_ISCHR)
77#define S_ISCHR(mode) 0
80#if !defined(S_ISBLK) && defined(S_IFBLK)
81#define S_ISBLK(mode) __S_ISTYPE((mode), S_IFBLK)
82#elif !defined(S_ISBLK)
83#define S_ISBLK(mode) 0
86#if !defined(S_ISREG) && defined(S_IFREG)
87#define S_ISREG(mode) __S_ISTYPE((mode), S_IFREG)
88#elif !defined(S_ISREG)
89#define S_ISREG(mode) 1
92#if !defined(S_ISSOCK) && defined(S_IFSOCK)
93#define S_ISSOCK(mode) __S_ISTYPE((mode), S_IFSOCK)
94#elif !defined(S_ISSOCK)
95#define S_ISSOCK(mode) (0)
98#if !defined(S_ISFIFO) && defined(S_IFIFO)
99#define S_ISFIFO(mode) __S_ISTYPE((mode), S_IFIFO)
100#elif !defined(S_ISFIFO)
101#define S_ISFIFO(mode) (0)
104#if !defined(S_ISLNK) && defined(S_IFLNK)
105#define S_ISLNK(mode) __S_ISTYPE((mode), S_IFLNK)
106#elif !defined(S_ISLNK)
107#define S_ISLNK(mode) (0)
136 OWNER_READONLY = 0400,
137 GROUP_READONLY = 0440,
138 PUBLIC_READONLY = 0444,
139 OWNER_PRIVATE = 0600,
141 GROUP_PRIVATE = 0660,
144 DIR_TEMPORARY = 01777
147 typedef struct stat fileinfo_t;
150 static int remapError(
void);
152 inline static int remapError(
void) {
231 inline operator fd_t()
const {
246 inline operator bool()
const {
247 return fd != INVALID_HANDLE_VALUE;
255 return fd == INVALID_HANDLE_VALUE;
289 void set(fd_t descriptor);
329 ssize_t
read(
void *buffer,
size_t count);
337 ssize_t
write(
const void *buffer,
size_t count);
373 static int prefix(
char *path,
size_t size);
375 static stringref_t prefix(
void);
383 static int info(
const char *path, fileinfo_t *buffer);
399 static int copy(
const char *source,
const char *target,
size_t size = 1024);
407 static int rename(
const char *oldpath,
const char *newpath);
415 static int mode(
const char *path,
unsigned value);
503 object.fd = descriptor;
529 static int link(
const char *path,
const char *target);
537 static int hardlink(
const char *path,
const char *target);
545 static int linkinfo(
const char *path,
char *buffer,
size_t size);
557 inline int err(
void)
const {
566 static fd_t
input(
const char *path);
595 static int pipe(fd_t& input, fd_t& output,
size_t size = 0);
605 static int inherit(fd_t& descriptor,
bool enable);
618 static int load(
const char *path);
627 static int exec(
const char *path,
char **argv,
char **envp = NULL);
629 static inline bool is_file(
struct stat *inode) {
630 return S_ISREG(inode->st_mode);
633 static inline bool is_dir(
struct stat *inode) {
634 return S_ISDIR(inode->st_mode);
637 static inline bool is_link(
struct stat *inode) {
638 return S_ISLNK(inode->st_mode);
641 static inline bool is_dev(
struct stat *inode) {
642 return S_ISBLK(inode->st_mode) || S_ISCHR(inode->st_mode);
645 static inline bool is_char(
struct stat *inode) {
646 return S_ISCHR(inode->st_mode);
649 static inline bool is_disk(
struct stat *inode) {
650 return S_ISBLK(inode->st_mode);
653 static inline bool is_sys(
struct stat *inode) {
654 return S_ISSOCK(inode->st_mode) || S_ISFIFO(inode->st_mode);
678 typedef int (FAR WINAPI *addr_t)();
680 typedef void *addr_t;
703 void map(
const char *path);
716 addr_t
find(
const char *symbol)
const;
718 inline int err(
void)
const {
722 inline addr_t operator[](
const char *symbol)
const {
726 inline addr_t operator()(
const char *symbol)
const {
730 inline operator bool()
const {
734 inline bool operator!()
const {
747 WIN32_FIND_DATA *ptr;
776 static int create(
const char *path,
unsigned mode);
797 ssize_t
read(
char *buffer,
size_t count);
804 inline int err(
void)
const {
808 inline void reset(
void) {
816 inline operator bool()
const {
838inline bool is_exists(
const char *path)
843inline bool is_readable(
const char *path)
848inline bool is_writable(
const char *path)
853inline bool is_executable(
const char *path)
858inline bool is_file(
const char *path)
863inline bool is_dir(
const char *path)
868inline bool is_link(
const char *path)
873inline bool is_device(
const char *path)
Private heaps, pools, and associations.
A thread-safe atomic heap management system.
Various miscellaneous platform specific headers and defines.
Abstract interfaces and support.
Common namespace for all ucommon objects.
fsys fsys_t
Convience type for fsys.
void * mem_t
Convenience type for loader operations.
A container for generic and o/s portable threadsafe file system functions.
static bool is_link(const char *path)
Test if path is a symlink.
int seek(offset_t offset)
Set the position of a file descriptor.
static bool is_device(const char *path)
Test if path is a device path.
bool is_tty(void) const
See if current file stream is a tty device.
fd_t handle(void) const
Get the native system descriptor handle of the file descriptor.
static int load(const char *path)
Load a library into memory.
int trunc(offset_t offset)
Truncate file to specified length.
static fd_t input(const char *path)
Direct means to open a read-only file path and return a descriptor.
static bool is_dir(const char *path)
Test if path is a directory.
int drop(offset_t size=0)
Drop cached data from start of file.
fsys(const fsys &descriptor)
Copy (dup) an existing fsys descriptor.
static int prefix(char *path, size_t size)
Get current directory prefix (pwd).
static int prefix(const char *path)
Set directory prefix (chdir).
fd_t operator*() const
Get the descriptor from the object by pointer reference.
int err(void) const
Get last error.
static bool is_tty(fd_t fd)
See if the file handle is a tty device.
static fd_t output(const char *path)
Direct means to create or access a writable path and return descriptor.
static int exec(const char *path, char **argv, char **envp=NULL)
Execute a process and get exit code.
static int link(const char *path, const char *target)
Create a symbolic link.
void assign(fd_t descriptor)
Assign descriptor directly.
void reset(void)
Reset error flag.
static int linkinfo(const char *path, char *buffer, size_t size)
Read a symbolic link to get it's target.
static const offset_t end
Used to mark "append" in set position operations.
static int erase(const char *path)
Erase (remove) a file only.
ssize_t write(const void *buffer, size_t count)
Write data to descriptor.
static int info(const char *path, fileinfo_t *buffer)
Stat a file.
static int mode(const char *path, unsigned value)
Change file access mode.
fd_t release(void)
Release descriptor, do not close.
static int pipe(fd_t &input, fd_t &output, size_t size=0)
Create pipe.
void open(const char *path, unsigned mode, access_t access)
Open a file descriptor directly.
static fd_t append(const char *path)
Direct means to create or append a writable path and return descriptor.
access_t
Enumerated file access modes.
int close(void)
Close a fsys resource.
fsys(const char *path, unsigned permission, access_t access)
Create a fsys descriptor by creating a file.
static int inherit(fd_t &descriptor, bool enable)
Changle inheritable handle.
static int rename(const char *oldpath, const char *newpath)
Rename a file.
static int unlink(const char *path)
Remove a symbolic link explicitly.
void open(const char *path, access_t access)
Open a file or directory.
int info(fileinfo_t *buffer)
Get status of open descriptor.
fsys & operator*=(fd_t &descriptor)
Replace current file descriptor with an external descriptor.
static fd_t null(void)
Create inheritable /dev/null handle.
fsys(const char *path, access_t access)
Create a fsys descriptor by opening an existing file or directory.
static bool is_file(const char *path)
Test if path is a file.
ssize_t read(void *buffer, size_t count)
Read data from descriptor or scan directory.
long offset_t
File offset type.
static int hardlink(const char *path, const char *target)
Create a hard link.
static bool is_exists(const char *path)
Test if path exists.
~fsys()
Close and release a file descriptor.
fsys(fd_t handle)
Contruct fsys from raw file handle.
static void assign(fsys &object, fd_t descriptor)
Assign a descriptor directly.
static bool is_readable(const char *path)
Test if path readable.
fsys & operator=(fd_t descriptor)
Assing file descriptor from system descriptor.
static bool is_writable(const char *path)
Test if path writable.
bool operator!() const
Test if file descriptor is closed.
fsys()
Construct an unattached fsys descriptor.
static void release(fd_t descriptor)
Release a file descriptor.
int sync(void)
Commit changes to the filesystem.
static int copy(const char *source, const char *target, size_t size=1024)
Copy a file.
fsys & operator=(const fsys &descriptor)
Assign file descriptor by duplicating another descriptor.
void set(fd_t descriptor)
Set with external descriptor.
static bool is_hidden(const char *path)
Test if path is a hidden file.
static bool is_executable(const char *path)
Test if path is executable.
Convenience class for library plugins.
addr_t find(const char *symbol) const
Find symbol in loaded module.
~dso()
Destroy dso and release library.
void map(const char *path)
Map library object with library.
dso()
Create dso object for use by load functions.
dso(const char *path)
Create and map a dso object.
void release(void)
Release loaded library.
Convenience class for directories.
dir()
Construct an unopened directory.
static int create(const char *path, unsigned mode)
Simple direct method to create a directory.
ssize_t read(char *buffer, size_t count)
Read data from directory.
void open(const char *path)
Open a directory path for reading.
static int remove(const char *path)
Remove an empty directory.
void close(void)
Close and release directory object.
bool operator!() const
Test if file descriptor is closed.
~dir()
Close and release directory.
dir(const char *path)
Construct and open a directory path.
Thread classes and sychronization objects.