1/* 2 * Copyright (c) 2004-2010 Apple, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#ifndef _COPYFILE_H_ /* version 0.1 */ 24#define _COPYFILE_H_ 25 26/* 27 * this is an API to faciliatate copying of files and their 28 * associated metadata. There are several open source projects that 29 * need modifications to support preserving extended attributes and 30 * acls and this API collapses several hundred lines of modifications 31 * into one or two calls. 32 * 33 * This implementation is incomplete and the interface may change in a 34 * future release. 35 */ 36 37/* private */ 38#include <sys/cdefs.h> 39#include <stdint.h> 40 41__BEGIN_DECLS 42struct _copyfile_state; 43typedef struct _copyfile_state * copyfile_state_t; 44typedef uint32_t copyfile_flags_t; 45 46/* public */ 47 48/* receives: 49 * from path to source file system object 50 * to path to destination file system object 51 * state opaque blob for future extensibility 52 * Must be NULL in current implementation 53 * flags (described below) 54 * returns: 55 * int negative for error 56 */ 57 58int copyfile(const char *from, const char *to, copyfile_state_t state, copyfile_flags_t flags); 59int fcopyfile(int from_fd, int to_fd, copyfile_state_t, copyfile_flags_t flags); 60 61int copyfile_state_free(copyfile_state_t); 62copyfile_state_t copyfile_state_alloc(void); 63 64 65int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst); 66int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src); 67 68typedef int (*copyfile_callback_t)(int, int, copyfile_state_t, const char *, const char *, void *); 69 70#define COPYFILE_STATE_SRC_FD 1 71#define COPYFILE_STATE_SRC_FILENAME 2 72#define COPYFILE_STATE_DST_FD 3 73#define COPYFILE_STATE_DST_FILENAME 4 74#define COPYFILE_STATE_QUARANTINE 5 75#define COPYFILE_STATE_STATUS_CB 6 76#define COPYFILE_STATE_STATUS_CTX 7 77#define COPYFILE_STATE_COPIED 8 78#define COPYFILE_STATE_XATTRNAME 9 79 80 81#define COPYFILE_DISABLE_VAR "COPYFILE_DISABLE" 82 83/* flags for copyfile */ 84 85#define COPYFILE_ACL (1<<0) 86#define COPYFILE_STAT (1<<1) 87#define COPYFILE_XATTR (1<<2) 88#define COPYFILE_DATA (1<<3) 89 90#define COPYFILE_SECURITY (COPYFILE_STAT | COPYFILE_ACL) 91#define COPYFILE_METADATA (COPYFILE_SECURITY | COPYFILE_XATTR) 92#define COPYFILE_ALL (COPYFILE_METADATA | COPYFILE_DATA) 93 94#define COPYFILE_RECURSIVE (1<<15) /* Descend into hierarchies */ 95#define COPYFILE_CHECK (1<<16) /* return flags for xattr or acls if set */ 96#define COPYFILE_EXCL (1<<17) /* fail if destination exists */ 97#define COPYFILE_NOFOLLOW_SRC (1<<18) /* don't follow if source is a symlink */ 98#define COPYFILE_NOFOLLOW_DST (1<<19) /* don't follow if dst is a symlink */ 99#define COPYFILE_MOVE (1<<20) /* unlink src after copy */ 100#define COPYFILE_UNLINK (1<<21) /* unlink dst before copy */ 101#define COPYFILE_NOFOLLOW (COPYFILE_NOFOLLOW_SRC | COPYFILE_NOFOLLOW_DST) 102 103#define COPYFILE_PACK (1<<22) 104#define COPYFILE_UNPACK (1<<23) 105 106#define COPYFILE_VERBOSE (1<<30) 107 108#define COPYFILE_RECURSE_ERROR 0 109#define COPYFILE_RECURSE_FILE 1 110#define COPYFILE_RECURSE_DIR 2 111#define COPYFILE_RECURSE_DIR_CLEANUP 3 112#define COPYFILE_COPY_DATA 4 113#define COPYFILE_COPY_XATTR 5 114 115#define COPYFILE_START 1 116#define COPYFILE_FINISH 2 117#define COPYFILE_ERR 3 118#define COPYFILE_PROGRESS 4 119 120#define COPYFILE_CONTINUE 0 121#define COPYFILE_SKIP 1 122#define COPYFILE_QUIT 2 123 124__END_DECLS 125 126#endif /* _COPYFILE_H_ */ 127