unix 中的 utssys() 给出文件上的用户总数。它是一个未记录的 API,在 Solaris 手册页和 Linux 手册页中都没有此 API 的手动条目。Linux 中是否有任何等效的 API 或我也可以在 Linux 中使用相同的东西(我不知道它没有记录)。我也用谷歌搜索但没有得到任何信息。请帮助。
int DU_Utssys_Unix(void* buf, int arg, int type, void* out)
{
int result;
// Perform system-call
errno = 0;
if ((result = utssys(buf, arg, type, out)) < 0)
return result;
// Look into the result:
return ((fu_data_t*)outbp)->fud_user_count;
}
以上是我需要为 Linux 替换的代码段。我可以使用 syscall() 来找出文件上的用户数吗?如果是,它保存在哪里???
在 Unix 中,它们有以下结构来保存上面代码片段中使用的信息,我们在 Linux 中有相同的还是不同的?
typedef struct f_user
{
int fu_flags; /* see below */
union
{
struct
{
pid_t u_pid;
uid_t u_uid;
}u_info;
struct
{
int k_modid;
int k_instance;
int k_minor;
}k_info;
} fu_info;
}f_user_t;
typedef struct fu_data
{
int fud_user_max;
int fud_user_count;
struct f_user fud_user[1];
}fu_data_t;
最佳答案
我认为在 Linux 中没有执行此操作的系统调用,但您可以以 root 身份执行以下操作:
- 统计文件获取
st_dev
和st_ino
值 - 遍历
/proc/*/fd/*
并为每个条目: - 如果
st_dev
和st_ino
匹配则增加计数
关于c - 移植代码 : is there any API equivalent to utssys() in Linux? 我需要将 utssys() unix API 移植到 Linux 环境吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15407135/