m2mb API docs  30.00.005
m2mb API sets documentation
m2mb_fs_posix.h File Reference

File system posix library implementation. More...

Go to the source code of this file.

Data Structures

struct  M2MB_STAT
 
struct  M2MB_STATVFS
 
struct  M2MB_DIRENT
 

Macros

#define M2MB_O_RDONLY   00
 
#define M2MB_O_WRONLY   01
 
#define M2MB_O_RDWR   02
 
#define M2MB_O_LARGE   010
 
#define M2MB_O_CREAT   0100
 
#define M2MB_O_EXCL   0200
 
#define M2MB_O_NOCTTY   0400
 
#define M2MB_O_TRUNC   01000
 
#define M2MB_O_APPEND   02000
 
#define M2MB_SEEK_SET   0 /* Seek from beginning of file */
 
#define M2MB_SEEK_CUR   1 /* Seek from current position */
 
#define M2MB_SEEK_END   2 /* Seek from end of file */
 
#define M2MB_S_IRUSR   0400 /* User has Read permission */
 
#define M2MB_S_IWUSR   0200 /* User has Write permission */
 
#define M2MB_S_IXUSR   0100 /* User has eXecute permission*/
 
#define M2MB_S_IRWXU   0700
 
#define M2MB_S_IRGRP   0040 /* Group has Read permission */
 
#define M2MB_S_IWGRP   0020 /* Group has Write permission */
 
#define M2MB_S_IXGRP   0010 /* Group has eXecute permission */
 
#define M2MB_S_IRWXG   0070
 
#define M2MB_S_IROTH   0004 /* Others has Read permission */
 
#define M2MB_S_IWOTH   0002 /* Others has Write permission */
 
#define M2MB_S_IXOTH   0001 /* Others has eXecutepermission */
 
#define M2MB_S_IRWXO   0007
 
#define S_ISUID   04000 /* Set UID on execution */
 
#define S_ISGID   02000 /* Set GID on execution */
 
#define S_ISVTX   01000 /* Sticky */
 
#define M2MB_ACCESSPERMS   0777
 
#define M2MB_ALLPERMS   0777
 
#define M2MB_S_IFDIR   0040000 /* Directory */
 
#define M2MB_S_IFREG   0100000 /* Regular file */
 

Typedefs

typedef struct M2MB_DIR_TAG M2MB_DIR_T
 

Functions

INT32 m2mb_fs_open (const CHAR *path, INT32 oflag,...)
 Open file. More...
 
SSIZE_T m2mb_fs_read (INT32 fd, void *buf, SIZE_T nbyte)
 Read file. More...
 
SSIZE_T m2mb_fs_write (INT32 fd, const void *buf, SIZE_T nbyte)
 Write file. More...
 
INT32 m2mb_fs_close (INT32 fd)
 Close file. More...
 
OFF_T m2mb_fs_lseek (INT32 fd, OFF_T offset, INT32 whence)
 Move file offset. More...
 
INT32 m2mb_fs_stat (const CHAR *path, struct M2MB_STAT *buf)
 File status. More...
 
INT32 m2mb_fs_fstat (INT32 fd, struct M2MB_STAT *buf)
 File status. More...
 
INT32 m2mb_fs_unlink (const CHAR *path)
 Delete file. More...
 
INT32 m2mb_fs_truncate (const CHAR *path, OFF_T length)
 Truncate file. More...
 
INT32 m2mb_fs_mkdir (const CHAR *path, MODE_T mode)
 Create directory. More...
 
INT32 m2mb_fs_rmdir (const CHAR *path)
 Remove directory. More...
 
M2MB_DIR_T * m2mb_fs_opendir (const CHAR *name)
 Open directory as stream. More...
 
struct M2MB_DIRENTm2mb_fs_readdir (M2MB_DIR_T *dirp)
 Read directory as stream. More...
 
INT32 m2mb_fs_closedir (M2MB_DIR_T *dirp)
 Close directory as stream. More...
 
INT32 m2mb_fs_statvfs (const CHAR *path, struct M2MB_STATVFS *buf)
 File system statistics. More...
 

Detailed Description

File system posix library implementation.

m2m/m2m_common/m2mb_inc/m2mb_fs_posix.h

posix library for files. Not all the standard posix functions are available but only the most commonly used.

@notes Dependencies: m2m/m2m_common/m2mb_inc/m2mb_types.h

Author
Giorgio De Pauli
Date
20/02/2017

Function Documentation

◆ m2mb_fs_close()

INT32 m2mb_fs_close ( INT32  fd)

Close file.

The function closes the file associated with the open file descriptor, fd.

Parameters
[in]fdFile descriptor.
Returns
Upon successful completion, 0 is returned. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_closedir()

INT32 m2mb_fs_closedir ( M2MB_DIR_T *  dirp)

Close directory as stream.

The function closes the directory stream pointed to by dirp (writing any buffered output data) and closes the underlying file descriptor.

Parameters
[in]streamPointer to stream directory object.
Returns
Upon successful completion 0 is returned. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_fstat()

INT32 m2mb_fs_fstat ( INT32  fd,
struct M2MB_STAT buf 
)

File status.

The function gets status of the open file associated with the file descriptor fd, and writes it to the area pointed to by buf.

Parameters
[in]fdFile descriptor.
[in]bufPointer to a stat structure (see definition) to be filled with the stutus of the file.
Returns
Upon successful completion 0 is returned. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_lseek()

OFF_T m2mb_fs_lseek ( INT32  fd,
OFF_T  offset,
INT32  whence 
)

Move file offset.

The function sets the file offset for the open file description associated with the file descriptor fd. The new offset, measured in bytes, is obtained by adding offset bytes to the position specified by whence.

Parameters
[in]fdFile descriptor.
[in]offsetNumber of bytes to move the file offset from the position specified by whence.
[in]whenceFile position. M2MB_SEEK_SET Beginning of the file. M2MB_SEEK_CUR Current file position. M2MB_SEEK_END End of file.
Returns
Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, is returned. Otherwise, (OFF_T)-1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_mkdir()

INT32 m2mb_fs_mkdir ( const CHAR *  path,
MODE_T  mode 
)

Create directory.

The function creates a new directory with name path.

Parameters
[in]pathName of directory to be created.
[in]...Mode for creating directory. It defines file permissions. See m2mb_fs_open for details.
Returns
Upon successful completion returns 0. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_open()

INT32 m2mb_fs_open ( const CHAR *  path,
INT32  oflag,
  ... 
)

Open file.

The function opens the file whose name is the string pointed to by path.

Parameters
[in]pathName of file to be open.
[in]oflagFlags for opening file. One of the following three flags must be used: M2MB_O_RDONLY Open for reading only. M2MB_O_WRONLY Open for writing only. M2MB_O_RDWR Open for reading and writing. In addition any of the following flags may be bitwise ORed: M2MB_O_APPEND If set, the file offset shall be set to the end of the file prior to each write. M2MB_O_CREAT If the file exists, this flag has no effect except as noted under M2MB_O_EXCL below. Otherwise, the file shall be created. M2MB_O_EXCL If M2MB_O_CREAT and M2MB_O_EXCL are set, open fails if the file exists. M2MB_O_TRUNC If the file exists and is a regular file, and the file is successfully opened with M2MB_O_RDWR or M2MB_O_WRONLY, its length is truncated to 0, and the mode is unchanged.
[in]...Mode for opening file. It must be used only if oflag includes M2MB_O_CREAT. It defines file permissions. M2MB_S_IRUSR 0400 User has Read permission M2MB_S_IWUSR 0200 User has Write permission M2MB_S_IXUSR 0100 User has eXecute permission M2MB_S_IRWU 0700 M2MB_S_IRGRP 0040 Group has Read permission M2MB_S_IWGRP 0020 Group has Write permission M2MB_S_IXGRP 0010 Group has eXecute permission M2MB_S_IRWXG 0070 M2MB_S_IROTH 0004 Others has Read permission M2MB_S_IWOTH 0002 Others has Write permission M2MB_S_IXOTH 0001 Others has eXecutepermission M2MB_S_IRWXO 0007 M2MB_ACCESSPERMS 0777 M2MB_ALLPERMS 0777
Returns
Upon successful completion returns a non-negative integer representing the lowest numbered unused file descriptor. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_opendir()

M2MB_DIR_T* m2mb_fs_opendir ( const CHAR *  name)

Open directory as stream.

The function opens the directory whose name is the string pointed to by name, and and associates a stream with it. The stream is positioned at the first entry in the directory.

Parameters
[in]nameName of directory to be open.
Returns
Upon successful completion returns a pointer to stream directory object. Otherwise, NULL is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_read()

SSIZE_T m2mb_fs_read ( INT32  fd,
void *  buf,
SIZE_T  nbyte 
)

Read file.

The function reads nbyte bytes from the file associated with the open file descriptor, fd, into the buffer pointed to by buf.

Parameters
[in]fdFile descriptor.
[out]bufBuffer to fill with read data.
[in]nbyteNumber of bytes to read.
Returns
Upon successful completion returns a non-negative integer indicating the number of bytes actually read. Otherwise, -1 is returned
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_readdir()

struct M2MB_DIRENT* m2mb_fs_readdir ( M2MB_DIR_T *  dirp)

Read directory as stream.

The function reads the next directory entry in the directory stream pointed to by dirp and returns corresponding information in a pointer to a dirent structure. It returns NULL on reaching the end of the directory stream

Parameters
[in]dirpPointer to stream directory object.
Returns
On success returns a pointer to dirent structure. If an error occurs, or the end of the directory stream is reached, NULL is returned.
Note
Posix requires that dirent structure contain at least 'd_name', different platform may contain more elements. Do not attempt to free pointer to returned dirent structure. The data returned by m2mb_fs_readdir() may be overwritten by subsequent calls to m2mb_fs_readdir() for the same directory stream.

Example

<C code example>

◆ m2mb_fs_rmdir()

INT32 m2mb_fs_rmdir ( const CHAR *  path)

Remove directory.

The function a directory whose name is given by path. The directory shall be removed only if it is an empty directory.

Parameters
[in]pathName of directory to be removed.
Returns
Upon successful completion returns 0. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_stat()

INT32 m2mb_fs_stat ( const CHAR *  path,
struct M2MB_STAT buf 
)

File status.

The function gets status of the file whose name is the string pointed to by path, and writes it to the area pointed to by buf. .

Parameters
[in]pathName of file.
[in]bufPointer to a stat structure (see definition) to be filled with the stutus of the file.
Returns
Upon successful completion, 0 is returned. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_statvfs()

INT32 m2mb_fs_statvfs ( const CHAR *  path,
struct M2MB_STATVFS buf 
)

File system statistics.

The function gets information about file system specified by the string pointed to by path, and writes it to the area pointed to by buf.

Parameters
[in]pathPathname of any file within the mounted file system.
[in]bufPointer to a statvfs structure (see definition) to be filled with the information about file system.
Returns
Upon successful completion 0 is returned. Otherwise, -1 is returned.
Note
In parameter path, root or any mounted path can be given to get information about file system.

Example

<C code example>

◆ m2mb_fs_truncate()

INT32 m2mb_fs_truncate ( const CHAR *  path,
OFF_T  length 
)

Truncate file.

The function effect is that the regular file named by path will have a size which will be equal to length bytes.

Parameters
[in]pathName of file to be truncated.
[in]lengthNew size of the file.
Returns
Upon successful completion returns 0. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_unlink()

INT32 m2mb_fs_unlink ( const CHAR *  path)

Delete file.

The function deletes the file whose name is the string pointed to by path.

Parameters
[in]pathName of file to be deleted.
Returns
Upon successful completion returns 0. Otherwise, -1 is returned.
Note
<Notes>

Example

<C code example>

◆ m2mb_fs_write()

SSIZE_T m2mb_fs_write ( INT32  fd,
const void *  buf,
SIZE_T  nbyte 
)

Write file.

The function writes nbyte bytes from the buffer pointed to by buf to the file associated with the open file descriptor, fd.

Parameters
[in]fdFile descriptor.
[in]bufBuffer containing data to be written.
[in]nbyteNumber of bytes to write.
Returns
Upon successful completion returns the number of bytes actually written. Otherwise, -1 is returned
Note
<Notes>

Example

<C code example>