#include <sys/stat.h>
|
int
chmod (const char *path, mode_t mode); |
int
fchmod (int fd, mode_t mode); |
int
lchmod (const char *path, mode_t mode); |
The lchmod system call is similar to chmod but does not follow symbolic links.
A mode is created from or’d 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 Note : sticky bit and setuid on exec bit are not supported, permission values for users is considered while premissions values for group and others are ignored(As there is no concept of group and others). An attempt to change file permission to write-only changes the file permission to read-write. Permissions for directory will be ignored. Limitation: 000 mode is tereated as invalid mode 000mode is tereated as invalid mode(i.e., both read and write permission absent for a file system entry), as symbian file sytem cannot have entries with both read and write permissions absent.
|
/***************************************************************************************** * 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 \n"); return -1; } printf("Chmod system call successful \n"); 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\n"); return -1; } if(fchmod(fd , 0444) < 0 ) { printf("fchmod failed to change mode of file Example.txt \n"); return -1; } printf("Fchmod call changed mode of Example.txt \n"); return 0; }
Output
Fchmod call changed mode of Example.txt
[ENOTDIR] | |
A component of the path prefix is not a directory. | |
[ENAMETOOLONG] | |
A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters(Not supported). | |
[ENOENT] | |
The named file does not exist. | |
[EACCES] | |
Search permission is denied for a component of the path prefix(Not supported). | |
[ELOOP] | |
Too many symbolic links were encountered in translating the pathname( Not supported). | |
[EPERM] | |
The effective user ID does not match the owner of the file and the effective user ID is not the super-user(Not supported). | |
[EROFS] | |
The named file resides on a read-only file system(Not supported). | |
[EFAULT] | |
The path argument points outside the process’s allocated address space(Not supported). | |
[EFTYPE] | |
An attempt was made to set the sticky bit upon an executable(Not supported). | |
[EIO] |
An I/O error occurred while reading from or writing to the file system(Not supported). |
The fchmod system call will fail if:
[EBADF] | |
The descriptor is not valid. | |
[EINVAL] | |
The fd argument refers to a socket, not to a file. | |
[EROFS] | |
The file resides on a read-only file system. | |
[EIO] |
An I/O error occurred while reading from or writing to the file system(Not supported). |
© 2005-2007 Nokia |