First public contribution.
1 /** @file ../include/sys/stat.h
5 /** @fn chmod(const char *_path, mode_t _mode)
9 Note: This description also covers the following functions -
12 @return Upon successful completion, the value 0 is returned; otherwise the
13 value -1 is returned and the global variable errno is set to indicate the
17 #include < sys/stat.h > :
19 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
20 the file specified by _path (or fd ),
23 The chmod system call follows symbolic links to operate on the target of the link
24 rather than the link itself.
26 The lchmod system call is similar to chmod but does not follow symbolic links.
28 A mode is created from ored permission bit masks
29 defined in \#include \<sys/stat.h\> :
32 #define S_IRWXU 0000700 // RWX mask for owner
33 #define S_IRUSR 0000400 // R for owner
34 #define S_IWUSR 0000200 // W for owner
35 #define S_IXUSR 0000100 // X for owner
36 #define S_IRWXG 0000070 // RWX mask for group
37 #define S_IRGRP 0000040 // R for group
38 #define S_IWGRP 0000020 // W for group
39 #define S_IXGRP 0000010 // X for group
40 #define S_IRWXO 0000007 // RWX mask for other
41 #define S_IROTH 0000004 // R for other
42 #define S_IWOTH 0000002 // W for other
43 #define S_IXOTH 0000001 // X for other
44 #define S_ISUID 0004000 // set user id on execution
45 #define S_ISGID 0002000 // set group id on execution
47 #define S_ISTXT 0001000 // sticky bit
53 Sticky bit and set id on execution are not supported.
55 Permission values for group and others are ignored as there is no concept of
56 group and others on the Symbian OS.
57 The flag bits S_IXUSR, S_IXGRP & S_IXOTH are ignored as execute permissions on a file are meaningless on Symbian OS.
59 An attempt to change file permission to write-only changes the file permission
62 Either or both of S_IRUSR or S_IWUSR bits must be set in the _mode argument, else chmod fails with EINVAL.
64 Permissions for directories are ignored.
66 000 mode is treated as invalid mode as Symbian OS cannot have entries with
67 both read and write permissions absent.
73 /*Detailed description: This test code demonstartes usage of chmod system call, it
74 * changes mode of file Example.txt in the current working directory to read-only.
75 * Preconditions: Example.txt file should be present in the current working directory.
79 if(chmod("Example.txt" , 0444) < 0 )
81 printf("change mode of file Example.txt failed");
84 printf("Chmod system call successful");
91 Chmod system call successful
95 /* Detailed description : This sample code demonstrates the usage of fchmod system call, this code
96 * changes mode of file Example.txt using fchmod system call.
98 #include <sys/types.h>
104 fd = open("Example.txt" , O_CREAT | O_RDWR , 0666);
106 printf("Failed to open file Example.txt");
109 if(fchmod(fd , 0444) < 0 ) {
110 printf("fchmod failed to change mode of file Example.txt");
113 printf("Fchmod call changed mode of Example.txt");
120 Fchmod call changed mode of Example.txt
126 KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive
127 not found or filesystem not mounted on the drive.
136 @capability Deferred @ref RFs::SetAtt(const TDesC16&, unsigned, unsigned)
139 @externallyDefinedApi
142 /** @fn fchmod(int fd, mode_t _mode)
146 Refer to chmod() for the documentation
157 @externallyDefinedApi
160 /** @fn fstat(int fd, struct stat *st)
164 Refer to stat() for the documentation
168 If 'fd' refers to a shared memory object, the implementation updates only the st_uid, st_gid, st_size,
169 and st_mode fields in the stat structure pointed to by the 'st' argument .
181 @externallyDefinedApi
184 /** @fn fstat64(int fd, struct stat64 *st)
188 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
193 @externallyDefinedApi
197 /** @fn lstat(const char *file_name, struct stat *buf)
201 Refer to stat() for the documentation
211 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
214 @externallyDefinedApi
217 /** @fn lstat64(const char *file_name, struct stat64 *buf)
221 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
226 @externallyDefinedApi
229 /** @fn __xstat(int, const char *file, struct stat *buf)
233 Refer to stat() for the documentation
248 /** @fn __xstat64(int, const char *file, struct stat64 *buf)
252 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
260 /** @fn __lxstat(int, const char *file, struct stat *buf)
264 Refer to stat() for the documentation
279 /** @fn __lxstat64(int, const char *file, struct stat64 *buf)
283 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
292 /** @fn mkdir(const char *_path, mode_t _mode)
295 @return The mkdir() function returns the value 0 if successful; otherwise the
296 value -1 is returned and the global variable errno is set to indicate the
299 The directory _path is created with the access permissions specified by _mode.
303 _mode values and access permissions are ignored in Symbian OS.
305 The default working directory of a process is initialized to C: \\private\\U ID
306 (UID of the calling application) and any data written into this directory persists between phone resets.
308 The parent directory's time stamp is not updated when a new child is created.
310 The newly created directory will be empty (i.e. it doesn't have "." and
315 /* Detailed description : This test code demonstrates usage of mkdir systemcall,
316 * it creates function a directory Example in current working directory.
320 if(mkdir("Example" , 0666) < 0 )
322 printf("Directory creation failed");
325 printf("Directory Example created");
332 Directory Example created
338 The path parameter in mkdir() should not exceed 256 characters in length.
340 KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive
341 not found or filesystem not mounted on the drive.
343 The path given to mkdir() should be complete. Attempting to create a directory my calling mkdir("logs",0400|0200|0100)
344 will pass on emulator but fails on h/w because the cwd is taken as c:\private\uid3 on emulator and
345 z:\private\uid3 on h/w. Since Z drive is a rom on h/w, mkdir() fails by setting errno to 13 on hardware.
353 @capability Deferred @ref RFs::MkDir(const TDesC16&)
356 @externallyDefinedApi
360 /** @fn mkfifo(const char *pathname, mode_t mode)
363 @return The mkfifo function returns the value 0 if successful; otherwise the
364 value -1 is returned and errno is set to indicate the error.
366 The mkfifo system call
367 creates a new FIFO(First In First Out) file with name path. The access permissions are
368 specified by mode and restricted by the umask of the calling process.
369 With the current implementation, the use of umask has no effect.
371 The FIFO's owner ID and group ID are set to root.
373 Please note that running stat on a FIFO file does not provide modification
374 time information (it provides the creation time). Use fstat on the fd to retrieve the last modified
379 #include <sys/types.h>
380 #include <sys/stat.h>
385 char *pathname = "C:\XXX";
387 if (mkfifo(pathname, mode) == -1) {
388 printf("mkfifo() failed");
400 KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive
401 not found or filesystem not mounted on the drive.
403 @capability Deferred @ref RFs::Delete(const TDesC16&)
406 @externallyDefinedApi
409 /** @fn stat(const char *name, struct stat *st)
413 Note: This description also covers the following functions -
414 lstat() fstat() __xstat() __lxstat()
416 @return Upon successful completion, the value 0 is returned; otherwise the
417 value -1 is returned and the global variable errno is set to indicate the error.
420 st_dev The numeric ID of the device containing the file.
421 st_ino The file's inode number.
423 The number of hard links to the file.
427 st_atime Time when file data last accessed.
428 Changed by the .Xr utimes 2, read and readv system calls.
429 st_mtime Time when file data last modified.
430 Changed by the mkdir, mkfifo, mknod, utimes, write and writev system calls.
431 st_ctime Time when file status was last changed (inode data modification).
432 Changed by the chmod, chown, creat, link, mkdir, mkfifo, mknod, rename, rmdir, symlink, truncate, unlink, utimes, write and writev system calls.
434 Time when the inode was created.
438 st_size The file size in bytes.
440 The optimal I/O block size for the file.
441 st_blocks The actual number of blocks allocated for the file in 512-byte units.
442 As short symbolic links are stored in the inode, this number may
447 st_uid The user ID of the file's owner.
448 st_gid The group ID of the file.
450 Status of the file (see below).
454 Test for a block special file.
455 Test for a character special file.
456 Test for a directory.
457 Test for a pipe or FIFO special file.
458 Test for a symbolic link. NOTE: Inode structure is not supported by Symbian OS and hence link count updation is not possible.
459 Check for symbolic link would always fail because of this reason.
460 Test for a regular file.
465 The stat system call obtains information about the file pointed to by path. Read, write or execute
466 permission of the named file is not required, but all directories
467 listed in the path name leading to the file must be searchable.
469 The lstat system call is like stat except in the case where the named file is a symbolic link,
470 in which case lstat returns information about the link,
471 while stat returns information about the file the link references.
473 The fstat system call obtains the same information about an open file
474 known by the file descriptor fd.
476 The __xstat and __lxstat system calls are exactly similar to stat and lstat functionality.
478 The sb argument is a pointer to a stat structure as defined by \#include \<sys/stat.h\> and into which information is
479 placed concerning the file.
481 The fields of struct stat
482 related to the file system are as follows:
486 st_dev The numeric ID of the device containing the file.
487 st_ino The file's inode number.
488 st_nlink The number of hard links to the file.
492 The st_dev and st_ino fields together identify the file uniquely within the system.
494 The time-related fields of struct stat
497 st_atime Time when file data last accessed.
498 Changed by the .Xr utimes 2, read and readv system calls.
499 st_mtime Time when file data last modified.
500 Changed by the mkdir, mkfifo, mknod, utimes, write and writev system calls.
501 st_ctime Time when file status was last changed (inode data modification).
502 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.
504 If _POSIX_SOURCE is not defined, the time-related fields are defined as:
507 #ifndef _POSIX_SOURCE
508 #define st_atime st_atimespec.tv_sec
509 #define st_mtime st_mtimespec.tv_sec
510 #define st_ctime st_ctimespec.tv_sec
514 The size-related fields of the struct stat
516 st_size The file size in bytes.
517 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.
519 As short symbolic links are stored in the inode, this number may
522 The access-related fields of struct stat
524 st_uid The user ID of the file's owner.
525 st_gid The group ID of the file.
526 st_mode Status of the file (see below).
528 The status information word st_mode has the following bits:
530 #define S_IFMT 0170000 // type of file
531 #define S_IFIFO 0010000 // named pipe (fifo)
532 #define S_IFCHR 0020000 // character special
533 #define S_IFDIR 0040000 // directory
534 #define S_IFBLK 0060000 // block special
535 #define S_IFREG 0100000 // regular
536 #define S_IFLNK 0120000 // symbolic link
537 #define S_IFSOCK 0140000 // socket
538 #define S_IFWHT 0160000 // whiteout
539 #define S_ISUID 0004000 // set user id on execution
540 #define S_ISGID 0002000 // set group id on execution
541 #define S_ISVTX 0001000 // save swapped text even after use
542 #define S_IRUSR 0000400 // read permission, owner
543 #define S_IWUSR 0000200 // write permission, owner
544 #define S_IXUSR 0000100 // execute/search permission, owner
548 For a list of access modes, see \#include \<sys/stat.h\> access and chmod The following macros are available to
549 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.
550 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.
552 The macros evaluate to a non-zero value if the test is true
553 or to the value 0 if the test is false.
555 Note: To obtain correct timestamps of FIFOs use fstat instead of stat call.
559 /* Detailed description: Sample usage of stat system call
560 * Preconditions: Example.txt file should be present in working directory
564 #include <sys/types.h>
565 #include <sys/stat.h>
569 if(stat("Example.txt" , &buf;) < 0 )
571 printf("Failed to stat Example.txt");
574 printf("Stat system call succeeded");
578 * Detailed description: Sample usage of fstat system call
583 #include <sys/types.h>
584 #include <sys/stat.h>
588 int fd = open("Example.txt" , O_RDONLY | O_CREAT , 0666);
589 if(fstat(fd , &buf;) < 0 )
591 printf("Failed to stat Example.txt");
594 printf("Stat system call succeeded");
602 Stat system call succeeded
607 Stat system call succeeded
613 The path parameters of the stat() and lstat() functions should not exceed 256 characters each in length.
615 KErrNotReady of Symbian error code is mapped to ENOENT, which typically means drive
616 not found or filesystem not mounted on the drive.
626 @capability Deferred @ref RFs::Entry(const TDesC16&, TEntry&)
629 @externallyDefinedApi
632 /** @fn stat64(const char *name, struct stat64 *st)
635 @return Upon successful completion, the value 0 is returned; otherwise the
636 value -1 is returned and the global variable errno is set to indicate the error.
638 For full documentation see: http://www.unix.org/version2/whatsnew/lfs20mar.html#3.0
643 @externallyDefinedApi
646 /** @fn umask(mode_t cmask)
648 @return This function always returns MASK_RWUSR.
650 This function is build supported but not available functionally. Symbian
651 OS does not support multiple users and groups
658 @externallyDefinedApi
664 This structure provides detailed information about a file. The information returned depends on the type of file and/or the file system on which the file resides.
665 Includes following members,
668 @externallyDefinedApi
671 /** @var stat::st_dev
675 /** @var stat::st_ino
679 /** @var stat::st_mode
680 inode protection mode
683 /** @var stat::st_nlink
687 /** @var stat::st_uid
688 user ID of the file's owner
691 /** @var stat::st_gid
692 group ID of the file's group
695 /** @var stat::st_rdev
699 /** @var stat::st_atimespec
703 /** @var stat::st_mtimespec
704 time of last data modification
707 /** @var stat::st_ctimespec
708 time of last file status change
711 /** @var stat::st_size
715 /** @var stat::st_blocks
716 blocks allocated for file
719 /** @var stat::st_blksize
720 optimal blocksize for IO
723 /** @var stat::st_flags
724 user defined flags for file
727 /** @var stat::st_gen
728 file generation number
733 The stat64 structure is similar to the stat structure, except that it is capable of returning information about files that are larger than 2 gigabytes.
734 This structure provides detailed information about a file. The information returned depends on the type of file and/or the file system on which the file resides.
735 Includes following members,
738 @externallyDefinedApi
741 /** @var stat64::st_dev
745 /** @var stat64::st_ino
749 /** @var stat64::st_mode
750 inode protection mode
753 /** @var stat64::st_nlink
757 /** @var stat64::st_uid
758 user ID of the file's owner
761 /** @var stat64::st_gid
762 group ID of the file's group
765 /** @var stat64::st_rdev
769 /** @var stat64::st_atimespec
773 /** @var stat64::st_mtimespec
774 time of last data modification
777 /** @var stat64::st_ctimespec
778 time of last file status change
781 /** @var stat64::st_size
785 /** @var stat64::st_blocks
786 blocks allocated for file
789 /** @var stat64::st_blksize
790 optimal blocksize for IO
793 /** @var stat64::st_flags
794 user defined flags for file
797 /** @var stat64::st_gen
798 file generation number
807 @externallyDefinedApi
815 @externallyDefinedApi
823 @externallyDefinedApi
831 @externallyDefinedApi
840 @externallyDefinedApi
848 @externallyDefinedApi
856 @externallyDefinedApi
864 @externallyDefinedApi
872 @externallyDefinedApi
880 @externallyDefinedApi
888 @externallyDefinedApi
896 @externallyDefinedApi
904 @externallyDefinedApi
912 @externallyDefinedApi
920 @externallyDefinedApi
928 @externallyDefinedApi
936 @externallyDefinedApi
941 set user id on execution
944 @externallyDefinedApi
949 set group id on execution
952 @externallyDefinedApi
960 @externallyDefinedApi
968 @externallyDefinedApi
977 @externallyDefinedApi
986 @externallyDefinedApi
994 @externallyDefinedApi
1003 @externallyDefinedApi
1012 @externallyDefinedApi
1021 @externallyDefinedApi
1026 save swapped text even after use
1029 @externallyDefinedApi