4 Contains: A robust, general purpose file copy routine.
6 Version: Technology: MoreFiles
9 Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
11 Bugs?: For bug reports, consult the following page on
14 http://developer.apple.com/bugreporter/
19 You may incorporate this sample code into your applications without
20 restriction, though the sample code has been provided "AS IS" and the
21 responsibility for its operation is 100% yours. However, what you are
22 not permitted to do is to redistribute the source as "DSC Sample Code"
23 after having made changes. If you're going to re-distribute the source,
24 we require that you make it clear in the source that the code was
25 descended from Apple Sample Code, but that you've made changes.
39 #include "Optimization.h"
54 #if PRAGMA_STRUCT_ALIGN
55 #pragma options align=mac68k
56 #elif PRAGMA_STRUCT_PACKPUSH
58 #elif PRAGMA_STRUCT_PACK
62 /*****************************************************************************/
68 ConstStr255Param srcName
,
71 ConstStr255Param dstPathname
,
72 ConstStr255Param copyName
,
79 The FileCopy function duplicates a file and optionally renames it.
80 Since the PBHCopyFile routine is only available on some
81 AFP server volumes under specific conditions, this routine
82 either uses PBHCopyFile, or does all of the work PBHCopyFile
83 does. The srcVRefNum, srcDirID and srcName are used to
84 determine the location of the file to copy. The dstVRefNum
85 dstDirID and dstPathname are used to determine the location of
86 the destination directory. If copyName <> NIL, then it points
87 to the name of the new file. If copyBufferPtr <> NIL, it
88 points to a buffer of copyBufferSize that is used to copy
89 the file's data. The larger the supplied buffer, the
90 faster the copy. If copyBufferPtr = NIL, then this routine
91 allocates a buffer in the application heap. If you pass a
92 copy buffer to this routine, make its size a multiple of 512
93 ($200) bytes for optimum performance.
95 srcVRefNum input: Source volume specification.
96 srcDirID input: Source directory ID.
97 srcName input: Source file name.
98 dstVRefNum input: Destination volume specification.
99 dstDirID input: Destination directory ID.
100 dstPathname input: Pointer to destination directory name, or
101 nil when dstDirID specifies a directory.
102 copyName input: Points to the new file name if the file is
103 to be renamed or nil if the file isn't to
105 copyBufferPtr input: Points to a buffer of copyBufferSize that
106 is used the i/o buffer for the copy or
107 nil if you want FileCopy to allocate its
108 own buffer in the application heap.
109 copyBufferSize input: The size of the buffer pointed to
111 preflight input: If true, FileCopy makes sure there are enough
112 allocation blocks on the destination volume to
113 hold both the data and resource forks before
118 readErr Ð19 Driver does not respond to read requests
119 writErr Ð20 Driver does not respond to write requests
120 badUnitErr Ð21 Driver reference number does not
122 unitEmptyErr Ð22 Driver reference number specifies a
123 nil handle in unit table
124 abortErr Ð27 Request aborted by KillIO
125 notOpenErr Ð28 Driver not open
126 dskFulErr -34 Destination volume is full
127 nsvErr -35 No such volume
129 bdNamErr -37 Bad filename
130 tmfoErr -42 Too many files open
131 fnfErr -43 Source file not found, or destination
132 directory does not exist
133 wPrErr -44 Volume locked by hardware
134 fLckdErr -45 File is locked
135 vLckdErr -46 Destination volume is read-only
136 fBsyErr -47 The source or destination file could
137 not be opened with the correct access
139 dupFNErr -48 Destination file already exists
140 opWrErr -49 File already open for writing
141 paramErr -50 No default volume or function not
143 permErr -54 File is already open and cannot be opened using specified deny modes
144 memFullErr -108 Copy buffer could not be allocated
145 dirNFErr -120 Directory not found or incomplete pathname
146 wrgVolTypErr -123 Function not supported by volume
147 afpAccessDenied -5000 User does not have the correct access
148 afpDenyConflict -5006 The source or destination file could
149 not be opened with the correct access
151 afpObjectTypeErr -5025 Source is a directory, directory not found
152 or incomplete pathname
156 Also see: FSpFileCopy, DirectoryCopy, FSpDirectoryCopy
159 /*****************************************************************************/
163 const FSSpec
* srcSpec
,
164 const FSSpec
* dstSpec
,
165 ConstStr255Param copyName
,
166 void * copyBufferPtr
,
172 The FSpFileCopy function duplicates a file and optionally renames it.
173 Since the PBHCopyFile routine is only available on some
174 AFP server volumes under specific conditions, this routine
175 either uses PBHCopyFile, or does all of the work PBHCopyFile
176 does. The srcSpec is used to
177 determine the location of the file to copy. The dstSpec is
178 used to determine the location of the
179 destination directory. If copyName <> NIL, then it points
180 to the name of the new file. If copyBufferPtr <> NIL, it
181 points to a buffer of copyBufferSize that is used to copy
182 the file's data. The larger the supplied buffer, the
183 faster the copy. If copyBufferPtr = NIL, then this routine
184 allocates a buffer in the application heap. If you pass a
185 copy buffer to this routine, make its size a multiple of 512
186 ($200) bytes for optimum performance.
188 srcSpec input: An FSSpec record specifying the source file.
189 dstSpec input: An FSSpec record specifying the destination
191 copyName input: Points to the new file name if the file is
192 to be renamed or nil if the file isn't to
194 copyBufferPtr input: Points to a buffer of copyBufferSize that
195 is used the i/o buffer for the copy or
196 nil if you want FileCopy to allocate its
197 own buffer in the application heap.
198 copyBufferSize input: The size of the buffer pointed to
200 preflight input: If true, FSpFileCopy makes sure there are
201 enough allocation blocks on the destination
202 volume to hold both the data and resource forks
203 before starting the copy.
207 readErr Ð19 Driver does not respond to read requests
208 writErr Ð20 Driver does not respond to write requests
209 badUnitErr Ð21 Driver reference number does not
211 unitEmptyErr Ð22 Driver reference number specifies a
212 nil handle in unit table
213 abortErr Ð27 Request aborted by KillIO
214 notOpenErr Ð28 Driver not open
215 dskFulErr -34 Destination volume is full
216 nsvErr -35 No such volume
218 bdNamErr -37 Bad filename
219 tmfoErr -42 Too many files open
220 fnfErr -43 Source file not found, or destination
221 directory does not exist
222 wPrErr -44 Volume locked by hardware
223 fLckdErr -45 File is locked
224 vLckdErr -46 Destination volume is read-only
225 fBsyErr -47 The source or destination file could
226 not be opened with the correct access
228 dupFNErr -48 Destination file already exists
229 opWrErr -49 File already open for writing
230 paramErr -50 No default volume or function not
232 permErr -54 File is already open and cannot be opened using specified deny modes
233 memFullErr -108 Copy buffer could not be allocated
234 dirNFErr -120 Directory not found or incomplete pathname
235 wrgVolTypErr -123 Function not supported by volume
236 afpAccessDenied -5000 User does not have the correct access
237 afpDenyConflict -5006 The source or destination file could
238 not be opened with the correct access
240 afpObjectTypeErr -5025 Source is a directory, directory not found
241 or incomplete pathname
245 Also see: FileCopy, DirectoryCopy, FSpDirectoryCopy
248 /*****************************************************************************/
250 #include "OptimizationEnd.h"
252 #if PRAGMA_STRUCT_ALIGN
253 #pragma options align=reset
254 #elif PRAGMA_STRUCT_PACKPUSH
256 #elif PRAGMA_STRUCT_PACK
260 #ifdef PRAGMA_IMPORT_OFF
270 #endif /* __FILECOPY__ */