Go to the documentation of this file.
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);
611 static fd_t
null(void);
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 {
838 inline bool is_exists(
const char *path)
843 inline bool is_readable(
const char *path)
848 inline bool is_writable(
const char *path)
853 inline bool is_executable(
const char *path)
858 inline bool is_file(
const char *path)
863 inline bool is_dir(
const char *path)
868 inline bool is_link(
const char *path)
873 inline bool is_device(
const char *path)
Convenience class for directories.
dso(const char *path)
Create and map a dso object.
static int copy(const char *source, const char *target, size_t size=1024)
Copy a file.
static fd_t output(const char *path)
Direct means to create or access a writable path and return descriptor.
static int inherit(fd_t &descriptor, bool enable)
Changle inheritable handle.
Convenience class for library plugins.
~fsys()
Close and release a file descriptor.
static bool is_writable(const char *path)
Test if path writable.
int info(fileinfo_t *buffer)
Get status of open descriptor.
ssize_t read(void *buffer, size_t count)
Read data from descriptor or scan directory.
~dir()
Close and release directory.
void map(const char *path)
Map library object with library.
void release(void)
Release loaded library.
static int erase(const char *path)
Erase (remove) a file only.
static int prefix(const char *path)
Set directory prefix (chdir).
static const offset_t end
Used to mark "append" in set position operations.
static int prefix(char *path, size_t size)
Get current directory prefix (pwd).
void open(const char *path, access_t access)
Open a file or directory.
static int mode(const char *path, unsigned value)
Change file access mode.
void set(fd_t descriptor)
Set with external descriptor.
A container for generic and o/s portable threadsafe file system functions.
void reset(void)
Reset error flag.
static bool is_device(const char *path)
Test if path is a device path.
static bool is_link(const char *path)
Test if path is a symlink.
static fd_t append(const char *path)
Direct means to create or append a writable path and return descriptor.
void assign(fd_t descriptor)
Assign descriptor directly.
dir(const char *path)
Construct and open a directory path.
static int exec(const char *path, char **argv, char **envp=NULL)
Execute a process and get exit code.
static void release(fd_t descriptor)
Release a file descriptor.
fd_t operator*() const
Get the descriptor from the object by pointer reference.
fsys fsys_t
Convience type for fsys.
void open(const char *path)
Open a directory path for reading.
static int hardlink(const char *path, const char *target)
Create a hard link.
fsys()
Construct an unattached fsys descriptor.
static int load(const char *path)
Load a library into memory.
static bool is_exists(const char *path)
Test if path exists.
ssize_t write(const void *buffer, size_t count)
Write data to descriptor.
static bool is_hidden(const char *path)
Test if path is a hidden file.
fsys(const fsys &descriptor)
Copy (dup) an existing fsys descriptor.
static int info(const char *path, fileinfo_t *buffer)
Stat a file.
static void assign(fsys &object, fd_t descriptor)
Assign a descriptor directly.
dso()
Create dso object for use by load functions.
static int linkinfo(const char *path, char *buffer, size_t size)
Read a symbolic link to get it's target.
bool operator!() const
Test if file descriptor is closed.
A thread-safe atomic heap management system.
int seek(offset_t offset)
Set the position of a file descriptor.
fsys & operator=(fd_t descriptor)
Assing file descriptor from system descriptor.
int trunc(offset_t offset)
Truncate file to specified length.
fsys & operator=(const fsys &descriptor)
Assign file descriptor by duplicating another descriptor.
int close(void)
Close a fsys resource.
fd_t handle(void) const
Get the native system descriptor handle of the file descriptor.
access_t
Enumerated file access modes.
static int create(const char *path, unsigned mode)
Simple direct method to create a directory.
static int link(const char *path, const char *target)
Create a symbolic link.
Various miscellaneous platform specific headers and defines.
long offset_t
File offset type.
int drop(offset_t size=0)
Drop cached data from start of file.
static int rename(const char *oldpath, const char *newpath)
Rename a file.
Common namespace for all ucommon objects.
addr_t find(const char *symbol) const
Find symbol in loaded module.
fd_t release(void)
Release descriptor, do not close.
static bool is_dir(const char *path)
Test if path is a directory.
static int unlink(const char *path)
Remove a symbolic link explicitly.
fsys(const char *path, access_t access)
Create a fsys descriptor by opening an existing file or directory.
void * mem_t
Convenience type for loader operations.
bool operator!() const
Test if file descriptor is closed.
ssize_t read(char *buffer, size_t count)
Read data from directory.
Private heaps, pools, and associations.
static bool is_executable(const char *path)
Test if path is executable.
static int remove(const char *path)
Remove an empty directory.
void close(void)
Close and release directory object.
bool is_tty(void) const
See if current file stream is a tty device.
fsys & operator*=(fd_t &descriptor)
Replace current file descriptor with an external descriptor.
void open(const char *path, unsigned mode, access_t access)
Open a file descriptor directly.
~dso()
Destroy dso and release library.
int sync(void)
Commit changes to the filesystem.
Abstract interfaces and support.
dir()
Construct an unopened directory.
int err(void) const
Get last error.
Thread classes and sychronization objects.
fsys(fd_t handle)
Contruct fsys from raw file handle.
static bool is_readable(const char *path)
Test if path readable.
static bool is_file(const char *path)
Test if path is a file.
static fd_t input(const char *path)
Direct means to open a read-only file path and return a descriptor.
static int pipe(fd_t &input, fd_t &output, size_t size=0)
Create pipe.
fsys(const char *path, unsigned permission, access_t access)
Create a fsys descriptor by creating a file.
static bool is_tty(fd_t fd)
See if the file handle is a tty device.