glibc源码分析之chown系列函数

glibc中关于chown的函数有3个,它们分别是chown,fchown,lchown。它们都是系统调用的封装函数。
关于chown的系统调用有6个,它们分别是lchown(16),fchown(95),chown(182),lchown32(198),fchown32(207),chown32(212)。它们都是用于改变文件的用户ID和组用户ID。chown系列系统调用只能将用户ID和组用户ID改为16位整数。chown32系列系统调用则能将用户ID和组用户ID改为32位整数。
chown系列函数是使用脚本生成封装函数的。

生成的脚本如下:

#define SYSCALL_NAME chown32
#define SYSCALL_NARGS 3
#define SYSCALL_SYMBOL __chown
#define SYSCALL_CANCELLABLE 0
#define SYSCALL_NOERRNO 0
#define SYSCALL_ERRVAL 0
#include <syscall-template.S>
#include <shlib-compat.h>
#if IS_IN (libc)
versioned_symbol (libc, __chown, chown, GLIBC_2_1)
#else
strong_alias (__chown, chown)
#endif

chown函数调用了chown32系统调用。

#define SYSCALL_NAME fchown32
#define SYSCALL_NARGS 3
#define SYSCALL_SYMBOL __fchown
#define SYSCALL_CANCELLABLE 0
#define SYSCALL_NOERRNO 0
#define SYSCALL_ERRVAL 0
#include <syscall-template.S>
weak_alias (__fchown, fchown)
hidden_weak (fchown)

fchown函数调用了fchown32系统调用。

#define SYSCALL_NAME lchown32
#define SYSCALL_NARGS 3
#define SYSCALL_SYMBOL __lchown
#define SYSCALL_CANCELLABLE 0
#define SYSCALL_NOERRNO 0
#define SYSCALL_ERRVAL 0
#include <syscall-template.S>
#include <shlib-compat.h>
#if IS_IN (libc)
versioned_symbol (libc, __lchown, lchown, GLIBC_2_0)
#else
strong_alias (__lchown, lchown)
#endif
#if defined SHARED && IS_IN (libc)
strong_alias (__lchown, __lchown_1)
compat_symbol (libc, __lchown_1, chown, GLIBC_2_0)
#endif

lchown函数调用了了lchown32系统调用。

发布了185 篇原创文章 · 获赞 18 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/pk_20140716/article/details/77264176