stat.h File Reference

Typedef blksize_t

typedef __blksize_t blksize_t

Used for block sizes.

_BLKSIZE_T_DECLARED

Typedef blkcnt_t

typedef __blkcnt_t blkcnt_t

Used for file block counts.

_BLKCNT_T_DECLARED

Typedef dev_t

typedef __dev_t dev_t

device number or struct cdev

_DEV_T_DECLARED

Typedef fflags_t

typedef __fflags_t fflags_t

file flags

_FFLAGS_T_DECLARED

Typedef gid_t

typedef __gid_t gid_t

_GID_T_DECLARED

Typedef ino_t

typedef __ino_t ino_t

Used for file serial numbers.

_INO_T_DECLARED

Typedef mode_t

typedef __mode_t mode_t

_MODE_T_DECLARED

Typedef nlink_t

typedef __nlink_t nlink_t

Used for link counts.

_NLINK_T_DECLARED

Typedef off_t

typedef __off_t off_t

_OFF_T_DECLARED

Typedef time_t

typedef __time_t time_t

_TIME_T_DECLARED

Typedef uid_t

typedef __uid_t uid_t

_UID_T_DECLARED

S_ISUID

set user id on execution

S_ISGID

set group id on execution

S_IRWXU

RWX mask for owner

S_IRUSR

R for owner

S_IWUSR

W for owner

S_IXUSR

X for owner

S_IRWXG

RWX mask for group

S_IRGRP

R for group

S_IWGRP

W for group

S_IXGRP

X for group

S_IRWXO

RWX mask for other

S_IROTH

R for other

S_IWOTH

W for other

S_IXOTH

X for other

S_IFMT

type of file mask

S_IFIFO

named pipe (fifo)

S_IFCHR

character special

S_IFDIR

directory

S_IFBLK

block special

S_IFREG

regular

S_IFLNK

symbolic link

S_IFSOCK

S_ISVTX

save swapped text even after use

S_ISDIR

directory.

S_ISCHR

char special.

S_ISBLK

block special

S_ISREG

regular file

S_ISFIFO

fifo or socket

S_ISLNK

symbolic link

S_ISSOCK

chmod ( const char *, mode_t )

IMPORT_C intchmod(const char *,
mode_t
)
  #include < sys/stat.h > :
The file permission bits of the file named specified by _path or referenced by the file descriptor fd are changed to _mode. The chmod system call verifies that the process owner (user) either owns the file specified by _path (or fd ), or is the super-user. The chmod system call follows symbolic links to operate on the target of the link rather than the link itself.

The lchmod system call is similar to chmod but does not follow symbolic links.

A mode is created from ored permission bit masks defined in #include <sys/stat.h> :

#define S_IRWXU 0000700    // RWX mask for owner
#define S_IRUSR 0000400    // R for owner 
#define S_IWUSR 0000200    // W for owner 
#define S_IXUSR 0000100    // X for owner 
#define S_IRWXG 0000070    // RWX mask for group
#define S_IRGRP 0000040    // R for group
#define S_IWGRP 0000020    // W for group
#define S_IXGRP 0000010    // X for group
#define S_IRWXO 0000007    // RWX mask for other
#define S_IROTH 0000004    // R for other
#define S_IWOTH 0000002    // W for other
#define S_IXOTH 0000001    // X for other
#define S_ISUID 0004000    // set user id on execution
#define S_ISGID 0002000    // set group id on execution
#ifndef __BSD_VISIBLE
#define S_ISTXT 0001000    // sticky bit
#endif

Notes :

Sticky bit and set id on execution are not supported.

Permission values for group and others are ignored as there is no concept of group and others on the Symbian OS. The flag bits S_IXUSR, S_IXGRP & S_IXOTH are ignored as execute permissions on a file are meaningless on Symbian OS.

An attempt to change file permission to write-only changes the file permission to read-write.

Either or both of S_IRUSR or S_IWUSR bits must be set in the _mode argument, else chmod fails with EINVAL.

Permissions for directories are ignored.

000 mode is treated as invalid mode as Symbian OS cannot have entries with both read and write permissions absent.

Examples:
/*Detailed description: This test code demonstartes usage of chmod system call, it
 changes mode of file Example.txt in the current working directory to read-only.
 Preconditions: Example.txt file should be present in the current working directory.
 */
int main()
{
  if(chmod("Example.txt" , 0444) < 0 )  
  {
     printf("change mode of file Example.txt failed");
     return -1;
  }
  printf("Chmod system call successful");
  return 0;
}
Output
Chmod system call successful
/* Detailed description : This sample code demonstrates the usage of fchmod system call, this code
 changes mode of file Example.txt using fchmod system call.
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
 int fd = 0;
 fd = open("Example.txt" , O_CREAT | O_RDWR , 0666);
 if(fd < 0 )   {
    printf("Failed to open file Example.txt");
    return -1;
 }
 if(fchmod(fd , 0444) < 0 )  {
    printf("fchmod failed to change mode of file Example.txt");
    return -1;
 }
 printf("Fchmod call changed mode of Example.txt");
 return 0;
}
Output
Fchmod call changed mode of Example.txt

Limitations:

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

See also: chmod() chown() open() stat()

Parameters
Note: This description also covers the following functions - fchmod() lchmod()
Return Value
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
Capability
DeferredRFs::SetAtt(const TDesC16&, unsigned, unsigned)

fstat ( int, struct stat * )

IMPORT_C intfstat(int,
struct stat *
)

Notes:

If 'fd' refers to a shared memory object, the implementation updates only the st_uid, st_gid, st_size, and st_mode fields in the stat structure pointed to by the 'st' argument .

See also: access() chmod() chown() utimes() symlink()

Parameters
Refer to stat() for the documentation

lstat ( const char *, struct stat * )

IMPORT_C intlstat(const char *__restrict,
struct stat *__restrict
)
Parameters
__restrictRefer to stat() for the documentation
Capability
DeferredRFs::Entry(const TDesC16&, TEntry&)

__xstat ( int, const char *, struct stat * )

IMPORT_C int__xstat(int,
const char *file,
struct stat *buf
)
Parameters
bufRefer to stat() for the documentation

__lxstat ( int, const char *, struct stat * )

IMPORT_C int__lxstat(int,
const char *file,
struct stat *buf
)
Parameters
bufRefer to stat() for the documentation

mkdir ( const char *, mode_t )

IMPORT_C intmkdir(const char *,
mode_t
)

The directory _path is created with the access permissions specified by _mode.

Notes:

_mode values and access permissions are ignored in Symbian OS.

The default working directory of a process is initialized to C: \private\U ID (UID of the calling application) and any data written into this directory persists between phone resets.

The parent directory's time stamp is not updated when a new child is created.

The newly created directory will be empty (i.e. it doesn't have "." and ".." entries)

Examples:
/* Detailed description : This test code demonstrates usage of mkdir systemcall,
 it creates function a  directory Example in current working directory.
 */
int main()
{
  if(mkdir("Example" , 0666) < 0 )  
  {
      printf("Directory creation failed");
      return -1;
  }
  printf("Directory Example created");
  return 0;
}
Output
Directory Example created

Limitations:

The path parameter in mkdir() should not exceed 256 characters in length.

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

The path given to mkdir() should be complete. Attempting to create a directory my calling mkdir("logs",0400|0200|0100) will pass on emulator but fails on h/w because the cwd is taken as c: on emulator and z: on h/w. Since Z drive is a rom on h/w, mkdir() fails by setting errno to 13 on hardware.

See also: chmod() stat() umask()

Return Value
The mkdir() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
Capability
Deferred

mkfifo ( const char *, mode_t )

IMPORT_C intmkfifo(const char *,
mode_t
)

The mkfifo system call creates a new FIFO(First In First Out) file with name path. The access permissions are specified by mode and restricted by the umask of the calling process. With the current implementation, the use of umask has no effect.

The FIFO's owner ID and group ID are set to root.

Please note that running stat on a FIFO file does not provide modification time information (it provides the creation time). Use fstat on the fd to retrieve the last modified time.

Examples:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

int main(void)
{
    char *pathname = "C:\XXX";
    mode_t mode = 0666;
    if (mkfifo(pathname, mode) == -1) {
        printf("mkfifo() failed");
    }
    return 0;
}

See also: chmod() stat() umask()

Limitations:

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

Return Value
The mkfifo function returns the value 0 if successful; otherwise the value -1 is returned and errno is set to indicate the error.
Capability
Deferred

stat ( const char *, struct stat * )

IMPORT_C intstat(const char *__restrict,
struct stat *__restrict
)
 st_dev The numeric ID of the device containing the file.
 st_ino The file's inode number.
 st_nlink
  The number of hard links to the file.
 st_atime Time when file data last accessed.
 Changed by the .Xr utimes 2, read and readv system calls.
 st_mtime Time when file data last modified.
 Changed by the mkdir, mkfifo, mknod, utimes, write and writev system calls.
 st_ctime Time when file status was last changed (inode data modification).
 Changed by the chmod, chown, creat, link, mkdir, mkfifo, mknod, rename, rmdir, symlink, truncate, unlink, utimes, write and writev system calls.
 st_birthtime
  Time when the inode was created.
 st_size The file size in bytes.
 st_blksize
  The optimal I/O block size for the file.
 st_blocks The actual number of blocks allocated for the file in 512-byte units.
 As short symbolic links are stored in the inode, this number may
 be zero.
 st_uid The user ID of the file's owner.
 st_gid The group ID of the file.
 st_mode
  Status of the file (see below).
 Test for a block special file.
 Test for a character special file.
 Test for a directory.
 Test for a pipe or FIFO special file.
 Test for a symbolic link. NOTE: Inode structure is not supported by Symbian OS and hence link count updation is not possible.
 Check for symbolic link would always fail because of this reason.
 Test for a regular file.
 Test for a socket.
 Test for a whiteout.
The stat system call obtains information about the file pointed to by path. Read, write or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.

The lstat system call is like stat except in the case where the named file is a symbolic link, in which case lstat returns information about the link, while stat returns information about the file the link references.

The fstat system call obtains the same information about an open file known by the file descriptor fd.

The __xstat and __lxstat system calls are exactly similar to stat and lstat functionality.

The sb argument is a pointer to a stat structure as defined by #include <sys/stat.h> and into which information is placed concerning the file.

The fields of struct stat related to the file system are as follows:

st_dev The numeric ID of the device containing the file. 
st_ino The file's inode number. 
st_nlink  The number of hard links to the file.

The st_dev and st_ino fields together identify the file uniquely within the system.

The time-related fields of struct stat are as follows:

st_atime Time when file data last accessed. Changed by the .Xr utimes 2, read and readv system calls. st_mtime Time when file data last modified. Changed by the mkdir, mkfifo, mknod, utimes, write and writev system calls. st_ctime Time when file status was last changed (inode data modification). Changed by the chmod, chown, creat, link, mkdir, mkfifo, mknod, rename, rmdir, symlink, truncate, unlink, utimes, write and writev system calls. st_birthtime Time when the inode was created.

If _POSIX_SOURCE is not defined, the time-related fields are defined as:

#ifndef _POSIX_SOURCE
#define st_atime st_atimespec.tv_sec
#define st_mtime st_mtimespec.tv_sec
#define st_ctime st_ctimespec.tv_sec
#endif

The size-related fields of the struct stat are as follows: st_size The file size in bytes. st_blksize The optimal I/O block size for the file. st_blocks The actual number of blocks allocated for the file in 512-byte units.

As short symbolic links are stored in the inode, this number may be zero.

The access-related fields of struct stat are as follows: st_uid The user ID of the file's owner. st_gid The group ID of the file. st_mode Status of the file (see below).

The status information word st_mode has the following bits:
#define S_IFMT   0170000  // type of file
#define S_IFIFO  0010000  // named pipe (fifo) 
#define S_IFCHR  0020000  // character special 
#define S_IFDIR  0040000  // directory 
#define S_IFBLK  0060000  // block special 
#define S_IFREG  0100000  // regular 
#define S_IFLNK  0120000  // symbolic link 
#define S_IFSOCK 0140000  // socket 
#define S_IFWHT  0160000  // whiteout 
#define S_ISUID  0004000  // set user id on execution 
#define S_ISGID  0002000  // set group id on execution 
#define S_ISVTX  0001000  // save swapped text even after use 
#define S_IRUSR  0000400  // read permission, owner 
#define S_IWUSR  0000200  // write permission, owner 
#define S_IXUSR  0000100  // execute/search permission, owner 

For a list of access modes, see #include <sys/stat.h> access and chmod The following macros are available to test whether a st_mode value passed in the m argument corresponds to a file of the specified type: S_ISBLK (m); Test for a block special file. S_ISCHR (m); Test for a character special file. S_ISDIR (m); Test for a directory. S_ISFIFO (m); Test for a pipe or FIFO special file. S_ISLNK (m); Test for a symbolic link. NOTE: Inode structure is not supported by Symbian OS and hence link count updation is not possible. Check for symbolic link would always fail because of this reason. S_ISREG (m); Test for a regular file. S_ISSOCK (m); Test for a socket. S_ISWHT (m); Test for a whiteout.

The macros evaluate to a non-zero value if the test is true or to the value 0 if the test is false.

Note: To obtain correct timestamps of FIFOs use fstat instead of stat call.

Examples:
/* Detailed description: Sample usage of stat system call
 Preconditions: Example.txt file should be present in working directory 
 */
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
  struct stat buf;
   if(stat("Example.txt"  , &buf;) < 0 )
   {
      printf("Failed to stat Example.txt");
      return -1;
   }
   printf("Stat system call succeeded");
   return 0;
 }
/*
 Detailed description: Sample usage of fstat system call

 */
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
  struct stat buf;
   int fd = open("Example.txt" , O_RDONLY | O_CREAT  , 0666);
   if(fstat(fd  , &buf;) < 0 ) 
   {
      printf("Failed to stat Example.txt");
      return -1;
   }
   printf("Stat system call succeeded");
   close(fd);
   return 0;
 }
Output
Stat system call succeeded
Output
Stat system call succeeded

Limitations:

The path parameters of the stat() and lstat() functions should not exceed 256 characters each in length.

KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive not found or filesystem not mounted on the drive.

See also: access() chmod() chown() utimes() symlink()

Parameters
__restrictNote: This description also covers the following functions - lstat() fstat() __xstat() __lxstat()
Return Value
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
Capability
DeferredRFs::Entry(const TDesC16&, TEntry&)

umask ( mode_t )

IMPORT_C mode_tumask(mode_t)

This function is build supported but not available functionally. Symbian OS does not support multiple users and groups

Return Value
This function always returns MASK_RWUSR.