系统文件,读写o创建自定义元数据或属性扩展 [英] system file, read write o create custom metadata or attributes extended

查看:98
本文介绍了系统文件,读写o创建自定义元数据或属性扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来从任意文件读取,写入或创建(自定义)标签,扩展属性或元数据。如果没有库和C语言或C ++。我想我可以与FOPEN,FREAD,FWRITE,但不知道如何访问元数据。

I am looking for a way to read, write or create (custom) tags, extended attributes or metadata from any file. Without libraries and language c or c + +. I think I can be with fopen, fread, fwrite, but not how to access the metadata.

由于提前,

推荐答案

Linux系统要求操作扩展属性是 setxattr getxattr remotexattr 。这个程序可以做你所要求的:

The Linux system calls for manipulating extended attributes are setxattr, getxattr, and remotexattr. This program might do what you are asking for:

// UNTESTED
#include <sys/types.h>
#include <sys/xattr.h>
#include <cstring>
#include <cstdio>

int main () {
  const char* file = "/work/a.txt";
  const char* attr = "user.MyAttr";
  const char* value = "MyValue";
  int rc = setxattr(file, attr, value, strlen(value), 0);
  if(rc < 0)
    perror(file);
  return !!rc;
}

这篇关于系统文件,读写o创建自定义元数据或属性扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆