Exemple #1
0
/* xar_data_archive
 * This is the arcmod archival entry point for archiving the file's
 * data into the heap file.
 */
int32_t xar_data_archive(xar_t x, xar_file_t f, const char *file, const char *buffer, size_t len) {
	const char *opt;
	int32_t retval = 0;
	struct _data_context context;
	xar_prop_t tmpp;
	
	memset(&context,0,sizeof(struct _data_context));

	if( !xar_check_prop(x, "data") )
		return 0;

	xar_prop_get(f, "type", &opt);
	if(!opt) return 0;
	if( strcmp(opt, "file") != 0 ) {
		if( strcmp(opt, "hardlink") == 0 ) {
			opt = xar_attr_get(f, "type", "link");
			if( !opt )
				return 0;
			if( strcmp(opt, "original") != 0 )
				return 0;
			/* else, we're an original hardlink, so keep going */
		} else
			return 0;
	}

	if( 0 == len ){
		context.fd = open(file, O_RDONLY);
		if( context.fd < 0 ) {
			xar_err_new(x);
			xar_err_set_file(x, f);
			xar_err_set_string(x, "io: Could not open file");
			xar_err_callback(x, XAR_SEVERITY_NONFATAL, XAR_ERR_ARCHIVE_CREATION);
			return -1;
		}		
	}else{
		context.buffer = (void *)buffer;
		context.length = len;
		context.offset = 0;
	}

#ifdef F_NOCACHE
	fcntl(context.fd, F_NOCACHE, 1);
#endif

	tmpp = xar_prop_pset(f, NULL, "data", NULL);
	retval = xar_attrcopy_to_heap(x, f, tmpp, xar_data_read,(void *)(&context));
	if( context.total == 0 )
		xar_prop_unset(f, "data");

	if(context.fd > 0){
		close(context.fd);
		context.fd = -1;
	}
	
	return retval;
}
Exemple #2
0
int32_t xar_linuxattr_archive(xar_t x, xar_file_t f, const char* file, const char *buffer, size_t len)
{
#if defined(HAVE_SYS_XATTR_H) && defined(HAVE_LGETXATTR) && !defined(__APPLE__)
	char *i, *buf = NULL;
	int ret, retval=0, bufsz = 1024;
	struct statfs sfs;
	char *fsname = NULL;
	struct _linuxattr_context context;
	
	memset(&context,0,sizeof(struct _linuxattr_context));
	
	/* data from buffers don't have linuxattr */
	if(len)
		return 0;
	if( file == NULL )
		return 0;
	
TRYAGAIN:
	buf = malloc(bufsz);
	if(!buf)
		goto TRYAGAIN;
	ret = llistxattr(file, buf, bufsz);
	if( ret < 0 ) {
		switch(errno) {
		case ERANGE: bufsz = bufsz*2; free(buf); goto TRYAGAIN;
		case ENOTSUP: retval = 0; goto BAIL;
		default: retval = -1; goto BAIL;
		};
	}
	if( ret == 0 ) goto BAIL;

	memset(&sfs, 0, sizeof(sfs));
	statfs(file, &sfs);

	switch(sfs.f_type) {
	case EXT3_SUPER_MAGIC: fsname = "ext3"; break; /* assume ext3 */
	case JFS_SUPER_MAGIC:  fsname = "jfs" ; break;
	case REISERFS_SUPER_MAGIC:fsname = "reiser" ; break;
	case XFS_SUPER_MAGIC:  fsname = "xfs" ; break;
	default: retval=0; goto BAIL;
	};

	for( i=buf; (i-buf) < ret; i += strlen(i)+1 ) {
		xar_ea_t e;

		context.bufsz = 0;
		context.off = 0;
		context.buf = NULL;
		context.file = file;
		e = xar_ea_new(f, i);
		xar_ea_pset(f, e, "fstype", fsname);
		context.attrname = i;
		context.ea = e;
		xar_attrcopy_to_heap(x, f, xar_ea_root(e), xar_linuxattr_read,&context);
		free(context.buf);
		context.attrname = NULL;
	}

BAIL:
	free(buf);
	return retval;
#endif
	return 0;
}