2 ** Apple Macintosh Developer Technical Support
4 ** FileCopy: A robust, general purpose file copy routine.
6 ** by Jim Luther, Apple Developer Technical Support Emeritus
10 ** Copyright © 1992-1998 Apple Computer, Inc.
11 ** All rights reserved.
13 ** You may incorporate this sample code into your applications without
14 ** restriction, though the sample code has been provided "AS IS" and the
15 ** responsibility for its operation is 100% yours. However, what you are
16 ** not permitted to do is to redistribute the source as "DSC Sample Code"
17 ** after having made changes. If you're going to re-distribute the source,
18 ** we require that you make it clear in the source that the code was
19 ** descended from Apple Sample Code, but that you've made changes.
34 /*****************************************************************************/
36 pascal OSErr
FileCopy(short srcVRefNum
,
38 ConstStr255Param srcName
,
41 ConstStr255Param dstPathname
,
42 ConstStr255Param copyName
,
46 /* ¦ Duplicate a file and optionally rename it.
47 The FileCopy function duplicates a file and optionally renames it.
48 Since the PBHCopyFile routine is only available on some
49 AFP server volumes under specific conditions, this routine
50 either uses PBHCopyFile, or does all of the work PBHCopyFile
51 does. The srcVRefNum, srcDirID and srcName are used to
52 determine the location of the file to copy. The dstVRefNum
53 dstDirID and dstPathname are used to determine the location of
54 the destination directory. If copyName <> NIL, then it points
55 to the name of the new file. If copyBufferPtr <> NIL, it
56 points to a buffer of copyBufferSize that is used to copy
57 the file's data. The larger the supplied buffer, the
58 faster the copy. If copyBufferPtr = NIL, then this routine
59 allocates a buffer in the application heap. If you pass a
60 copy buffer to this routine, make its size a multiple of 512
61 ($200) bytes for optimum performance.
63 srcVRefNum input: Source volume specification.
64 srcDirID input: Source directory ID.
65 srcName input: Source file name.
66 dstVRefNum input: Destination volume specification.
67 dstDirID input: Destination directory ID.
68 dstPathname input: Pointer to destination directory name, or
69 nil when dstDirID specifies a directory.
70 copyName input: Points to the new file name if the file is
71 to be renamed or nil if the file isn't to
73 copyBufferPtr input: Points to a buffer of copyBufferSize that
74 is used the i/o buffer for the copy or
75 nil if you want FileCopy to allocate its
76 own buffer in the application heap.
77 copyBufferSize input: The size of the buffer pointed to
79 preflight input: If true, FileCopy makes sure there are enough
80 allocation blocks on the destination volume to
81 hold both the data and resource forks before
86 readErr Ð19 Driver does not respond to read requests
87 writErr Ð20 Driver does not respond to write requests
88 badUnitErr Ð21 Driver reference number does not
90 unitEmptyErr Ð22 Driver reference number specifies a
91 nil handle in unit table
92 abortErr Ð27 Request aborted by KillIO
93 notOpenErr Ð28 Driver not open
94 dskFulErr -34 Destination volume is full
95 nsvErr -35 No such volume
97 bdNamErr -37 Bad filename
98 tmfoErr -42 Too many files open
99 fnfErr -43 Source file not found, or destination
100 directory does not exist
101 wPrErr -44 Volume locked by hardware
102 fLckdErr -45 File is locked
103 vLckdErr -46 Destination volume is read-only
104 fBsyErr -47 The source or destination file could
105 not be opened with the correct access
107 dupFNErr -48 Destination file already exists
108 opWrErr -49 File already open for writing
109 paramErr -50 No default volume or function not
111 permErr -54 File is already open and cannot be opened using specified deny modes
112 memFullErr -108 Copy buffer could not be allocated
113 dirNFErr -120 Directory not found or incomplete pathname
114 wrgVolTypErr -123 Function not supported by volume
115 afpAccessDenied -5000 User does not have the correct access
116 afpDenyConflict -5006 The source or destination file could
117 not be opened with the correct access
119 afpObjectTypeErr -5025 Source is a directory, directory not found
120 or incomplete pathname
124 Also see: FSpFileCopy, DirectoryCopy, FSpDirectoryCopy
127 /*****************************************************************************/
129 pascal OSErr
FSpFileCopy(const FSSpec
*srcSpec
,
130 const FSSpec
*dstSpec
,
131 ConstStr255Param copyName
,
135 /* ¦ Duplicate a file and optionally rename it.
136 The FSpFileCopy function duplicates a file and optionally renames it.
137 Since the PBHCopyFile routine is only available on some
138 AFP server volumes under specific conditions, this routine
139 either uses PBHCopyFile, or does all of the work PBHCopyFile
140 does. The srcSpec is used to
141 determine the location of the file to copy. The dstSpec is
142 used to determine the location of the
143 destination directory. If copyName <> NIL, then it points
144 to the name of the new file. If copyBufferPtr <> NIL, it
145 points to a buffer of copyBufferSize that is used to copy
146 the file's data. The larger the supplied buffer, the
147 faster the copy. If copyBufferPtr = NIL, then this routine
148 allocates a buffer in the application heap. If you pass a
149 copy buffer to this routine, make its size a multiple of 512
150 ($200) bytes for optimum performance.
152 srcSpec input: An FSSpec record specifying the source file.
153 dstSpec input: An FSSpec record specifying the destination
155 copyName input: Points to the new file name if the file is
156 to be renamed or nil if the file isn't to
158 copyBufferPtr input: Points to a buffer of copyBufferSize that
159 is used the i/o buffer for the copy or
160 nil if you want FileCopy to allocate its
161 own buffer in the application heap.
162 copyBufferSize input: The size of the buffer pointed to
164 preflight input: If true, FSpFileCopy makes sure there are
165 enough allocation blocks on the destination
166 volume to hold both the data and resource forks
167 before starting the copy.
171 readErr Ð19 Driver does not respond to read requests
172 writErr Ð20 Driver does not respond to write requests
173 badUnitErr Ð21 Driver reference number does not
175 unitEmptyErr Ð22 Driver reference number specifies a
176 nil handle in unit table
177 abortErr Ð27 Request aborted by KillIO
178 notOpenErr Ð28 Driver not open
179 dskFulErr -34 Destination volume is full
180 nsvErr -35 No such volume
182 bdNamErr -37 Bad filename
183 tmfoErr -42 Too many files open
184 fnfErr -43 Source file not found, or destination
185 directory does not exist
186 wPrErr -44 Volume locked by hardware
187 fLckdErr -45 File is locked
188 vLckdErr -46 Destination volume is read-only
189 fBsyErr -47 The source or destination file could
190 not be opened with the correct access
192 dupFNErr -48 Destination file already exists
193 opWrErr -49 File already open for writing
194 paramErr -50 No default volume or function not
196 permErr -54 File is already open and cannot be opened using specified deny modes
197 memFullErr -108 Copy buffer could not be allocated
198 dirNFErr -120 Directory not found or incomplete pathname
199 wrgVolTypErr -123 Function not supported by volume
200 afpAccessDenied -5000 User does not have the correct access
201 afpDenyConflict -5006 The source or destination file could
202 not be opened with the correct access
204 afpObjectTypeErr -5025 Source is a directory, directory not found
205 or incomplete pathname
209 Also see: FileCopy, DirectoryCopy, FSpDirectoryCopy
212 /*****************************************************************************/
218 #include "optimend.h"
220 #endif /* __FILECOPY__ */