Something went wrong. Try again.
Cider Isn't Darwin Emulation, Really
Something went wrong. Try again.
9.2 kB 284 lines
at appkit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285.\" Copyright (c) 2007 Apple Inc..\" All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. Neither the name of Apple Inc. ("Apple") nor the names of its.\" contributors may be used to endorse or promote products derived from.\" this software without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE.\" DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..\".Dd May 4, 2007.Dt REMOVEFILE 3.Os.Sh NAME.Nm removefile , removefile_state_alloc ,.Nm removefile_state_free , removefile_state_get ,.Nm removefile_state_set.Nd remove files or directories.Sh SYNOPSIS.In removefile.h.Ft int.Fn removefile "const char *path" "removefile_state_t state" "removefile_flags_t flags".Ft removefile_state_t.Fn removefile_state_alloc "void".Ft int.Fn removefile_state_free "removefile_state_t state".Ft int.Fn removefile_state_get "removefile_state_t state" "uint32_t key" "void * dst".Ft int.Fn removefile_state_set "removefile_state_t state" "uint32_t key" "const void * value".Ft int.Fn removefile_cancel "removefile_state_t state".Sh DESCRIPTION.PpThese functions are used to remove a file or directory. Various levelsof overwriting may be specified to prevent other people from recovering any information about the file..PpThe.Fn removefile_state_allocfunction initializes a.Vt removefile_state_tobject (which is an opaque data type).This object can be passed to.Fn removefile ..Fn removefile_state_getand.Fn removefile_state_setcan be used to manipulate the state (see below).The.Fn removefile_state_freefunction is used to deallocate the object and its contents..PpThe.Fn removefilefunction removes files and directories located at the named.Va pathfilesystem location. The named .Va pathlocation can be specified as either an absolute path or relative to the working directoryof the calling process.If the.Va stateparameter is the return value from.Fn removefile_state_alloc ,then.Fn removefilewill use the information from the state object; if it is.Dv NULL ,then .Fn removefilewill work normally, but less control will be available to the caller.The.Va flagsparameter controls deletion options:.Bl -tag -width REMOVEFILE_SECURE_1_PASS_ZERO.It Dv REMOVEFILE_RECURSIVEIf the .Va pathlocation is a directory, then recursively delete the entire directory..It Dv REMOVEFILE_KEEP_PARENTThe file or directory at the.Va pathlocation is not deleted. If specified in conjunction with REMOVEFILE_RECURSIVE,then all of the contents of the directory at .Va pathlocation will be deleted, but not the directory itself..It Dv REMOVEFILE_SECURE_7_PASSOverwrite the file with 7 US DoD compliant passes (0xF6, 0x00, 0xFF, random, 0x00, 0xFF, random)..It Dv REMOVEFILE_SECURE_35_PASSOverwrite the file using 35-pass Gutmann algorithm..It Dv REMOVEFILE_SECURE_3_PASSOverwrite the file twice with random bytes, and then with 0xAA..It Dv REMOVEFILE_SECURE_1_PASSOverwrite with a single pass of random data..It Dv REMOVEFILE_SECURE_1_PASS_ZEROOverwrite with a single pass of zeroes..El.PpThe.Fn removefile_state_getand.Fn removefile_state_setfunctions can be used to manipulate the.Ft removefile_state_tobject returned by.Fn removefile_state_alloc .In both functions, the.Va dstor the.Va valueparameter's type depends on the.Va keyparameter that is passed in..Bl -tag -width REMOVEFILE_STATE_CONFIRM_CALLBACK.It Dv REMOVEFILE_STATE_CONFIRM_CALLBACKGet or set the callback function of type .Va removefile_callback_tto be called prior to file deletion..It Dv REMOVEFILE_STATE_CONFIRM_CONTEXTGet or set any parameters of type.Va void *that are needed for the confirm callback function..It Dv REMOVEFILE_STATE_ERROR_CALLBACKGet or set the callback function of type.Va removefile_callback_tto be called when an error is detected..It Dv REMOVEFILE_STATE_ERROR_CONTEXTGet or set any parameters of type.Va void *that are needed for the error callback function..It Dv REMOVEFILE_STATE_ERRNOGet or set the current errno of type.Va int.It Dv REMOVEFILE_STATE_STATUS_CALLBACKGet or set the callback function of type .Va removefile_callback_tto be called subsequent to file deletion..It Dv REMOVEFILE_STATE_STATUS_CONTEXTGet or set any parameters of type.Va void *that are needed for the status callback function..El.PpThe .Va removefile_callback_tfunction pointer is defined as the following:.Pp.Ft int.Va (*removefile_callback_t) (removefile_state_t state, const char *path , void *context).PpThe return value of the callback function is given as:.Bl -tag -width REMOVEFILE_PROCEED.It Dv REMOVEFILE_PROCEEDFile is deleted and .Fn removefilecontinues operation as normal..It Dv REMOVEFILE_SKIPCurrent file is not deleted and.Fn removefilecontinues operation as normal..It Dv REMOVEFILE_STOPCurrent file is not deleted and .Fn removefileexits without continuing further..El.PpThe.Fn removefile_cancelfunction is used to cancel a remove that is in progress..Sh RETURN VALUESThe family of.Fn removefilefunctions returns less than 0 on error, and 0 on success..Sh ERRORS.Fn removefilewill fail if:.Bl -tag -width Er.It Bq Er EACCESThe .Va pathlocation specifies a file or directory for which the calling process does nothave proper permissions..It Bq Er EINVALA callback returned an invalid return value (not REMOVEFILE_PROCEED, REMOVEFILE_SKIP, or REMOVEFILE_STOP).It Bq Er EMLINKThe .Va pathlocation refers to a symbolic link..It Bq Er ENAMETOOLONGThe resource fork name of the file exceeds the maximum allowed length..It Bq Er ENOMEMA memory allocation failed..It Bq Er ENOTEMPTYThe .Va pathlocation specifies a directory that contains an immutable file which cannot bedeleted..It Bq Er EPERMThe .Va pathlocation specifies an immutable file that cannot be deleted..El.Pp.Fn removefile_cancelwill fail if:.Bl -tag -width Er.It Bq Er EINVALA.Va NULLparameter was passed into.Fn removefile_cancel ..El.PpIn addition, all functions may return an error from an underlying library orsystem call..Sh NOTES.Pp Write protected files owned by another user cannot be removed by.Fn removefile , regardless of the permissions on the directory containing the file..PpIf multiple of the REMOVEFILE_SECURE_1_PASS, REMOVEFILE_SECURE_7_PASS, and REMOVEFILE_SECURE_35_PASSflags are specified,.Fn removefilewill proceed using the flag that specifies the highest number of overwriting passes..Pp.Fn removefileis pathname-based; this means that, when descending into a hierarchy, there are potential race conditionsthat may add risk when run with privileges..Pp.Fn removefileoperates on symbolic links, rather than the target of the link..Sh EXAMPLES.Bd -literal -offset indent/* Initialize a state variable */removefile_state_t s;s = removefile_state_alloc();/* Recursively remove all files and directories while keeping parent tmp directory. */removefile("/tmp", s, REMOVEFILE_RECURSIVE | REMOVEFILE_KEEP_PARENT);/* Release the state variable */removefile_state_free(s);.Pp/* A more complex way to call removefile() -- define a callback function */int removefile_status_callback(removefile_state_t state, const char * path, void * context) { fprintf(stderr, "File deleted: %s", path); return REMOVEFILE_PROCEED;}/* Initialize a state variable */s = removefile_state_alloc();/* Set callback function properties */removefile_state_set(s, REMOVEFILE_STATE_CONFIRM_CALLBACK, removefile_confirm_callback);removefile_state_set(s, REMOVEFILE_STATE_CONFIRM_CONTEXT, NULL);/* Recursively remove all files and directories while keeping parent tmp directory, calling a confirm callback prior to each file deletion. */removefile("/tmp", s, REMOVEFILE_RECURSIVE | REMOVEFILE_KEEP_PARENT);/* Release the state variable. */removefile_state_free(s);.Ed.Sh "SEE ALSO".Xr srm 1 ,.Xr unlink 1 ,.Xr sync 2 ,.Xr sync_volume_np 3.Sh HISTORYThe.Fn removefileAPI was introduced in Mac OS X 10.5.