系统调用 fchownat
来源:互联网 发布:道可道 知乎 编辑:程序博客网 时间:2024/06/05 16:23
fchownat 是linux kernel 2.6.16 以后添加的系统调用
linux kernel 2.6.16 新增了系列 at 系统调用( openat, linkat ..... )
原型:include/linux/syscalls.h
asmlinkage long sys_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, int flag);
说明:
The fchownat() function sets the owner ID and group ID of the named file in the same manner as chown(). If, however, the path argument is relative, the path is resolved relative to the fildes argument rather than the current working directory. If the fildes argument has the special value FDCWD, the path path resolution reverts back to current working directory relative. If the flag argument is set to SYMLNK, the function behaves like lchown() with respect to symbolic links. If the path argument is absolute, the fildes argument is ignored. If the path argument is a null pointer, the function behaves like fchown().
这些 *at 系统调用相对与之前的系统调用增加了个文件描述符参数(上面的 int dfd)
功能是相对与相对与此文件描述符(目录)的路径而操作, 之前的系统调用的操作都是相对与进程当前位置的
当然,如果此文件描述符未设置或者不是个有效的目录文件描述符, *at 系统调用就和老版系统调用功能相同了
一个例子展示了 openat 系统调用的用法:
#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>int main(){ int dfd,ffd; dfd = open("/home", O_RDONLY|00200000); // 00200000其实就是 O_DIRECTORY if(dfd < 1) { perror("open home"); return -1; } ffd = openat(dfd, "../opt/openat", O_CREAT, 777); if(ffd < 1) { perror("open new file"); return -1; } return 0;}
该程序创建了文件 /opt/openat
下段代码则演示了 unlinkat 的用法:
#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>int main(){ int dfd,ffd; dfd = open("/opt/cc", O_RDONLY|00200000); if(dfd < 1) { perror("open home"); return -1; } //ffd = openat(dfd, "../opt/deny/openat", O_CREAT, 777); ffd = unlinkat(dfd,"../deny/openat", 0); if(ffd != 0) { perror("unlinkat new file"); return -1; } return 0;}
- 系统调用 fchownat
- chown, fchown, fchownat, and lchown Functions
- 函数chown、fchown、fchownat和lchown
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- 系统调用
- Web应用界面设计规范—给项目组培训
- 动态规划学习
- 面试重点问题
- Linux C函数环境变量(env)setenv unsetenv putenv unsetenv
- JavaWeb体系结构的理解-1.基础
- 系统调用 fchownat
- 查询mysql总结及预处理
- vs2010在win7下打包.net2.0框架的程序
- java数据结构冒泡算法
- ViewTreeObserver
- Linux内核部件分析--设备驱动模型之device
- Android实现多页左右滑动效果,支持子view动态创建和cache
- Linux常用C函数—内存及字符串操作篇
- PCA人脸识别过程