免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2126 | 回复: 0
打印 上一主题 下一主题

openat [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-31 17:11 |只看该作者 |倒序浏览
Linux : openat() support in Linux
January 20, 2006 - 4:23amSubmitted by
Kedar Sovani
-->
Submitted by
Kedar Sovani
on January 20, 2006 - 4:23am.


Recently,
patches
have been included in the upcoming Linux kernel, to add support to the openat() class of system calls. In the patch log, author, Ulrich Drepper, states "[A] total 13 new system calls which take a file descriptor/filename pair instead of a single file name [have been added]". These system calls interpret the filename relative to the file descriptor passed.
An example should help clarify the point :
int open(const char *path, int oflag, /* mode_t mode */...);
int openat(int dirfd, const char *relative_path, int oflag, /* mode_t mode */...);
This is of great help for implementing virtual per-thread current working directory. In the abscence of this, approaches like cwd_save/restore (which affects the entire process) or "/proc/self/fd/dirfd/relative_path" were being used. Apart from being faster than the older approaches, the new system calls also allow for race-free filesystem traversals. The new system calls include, openat, mkdirat, mknodat, fchownat, futimesat, newfstatat, unlinkat, renameat, linkat, symlinkat, readlinkat, fchmodat, faccessat.
These system calls
exist
in Solaris for quite a while now. The new Linux openat-variant system calls do not support the extended attribute feature, as is found with the Solaris openat-variants.
理解:
引用openat是方便一个进程内的各线程可拥有不同的当前目录,传统的chdir会影响整个进程,而使用openat只需要每个线程在初始化时打开一个目录(调用open),然后就可以以openat在“当前目录”操作文件了,如:

int dirfd = open("/tmp"); // 相当于chdir到“/tmp”
int filefd = openat(dirfd, "myfile"); // 在/tmp目录下打开“myfile”文件




本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/45170/showart_474275.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP