4 Contains: The long lost high-level and FSSpec File Manager functions.
8 Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
10 You may incorporate this sample code into your applications without
11 restriction, though the sample code has been provided "AS IS" and the
12 responsibility for its operation is 100% yours. However, what you are
13 not permitted to do is to redistribute the source as "DSC Sample Code"
14 after having made changes. If you're going to re-distribute the source,
15 we require that you make it clear in the source that the code was
16 descended from Apple Sample Code, but that you've made changes.
20 DRI: Apple Macintosh Developer Technical Support
22 Other Contact: Apple Macintosh Developer Technical Support
23 <http://developer.apple.com/bugreporter/>
25 Technology: DTS Sample Code
31 Change History (most recent first):
33 <2> 2/7/01 JL Added standard header. Updated names of includes.
34 <1> 12/06/99 JL MoreFiles 1.5.
38 #include <MacErrors.h>
41 #define __COMPILINGMOREFILES
43 #include "MoreFiles.h"
44 #include "MoreFilesExtras.h"
46 /*****************************************************************************/
48 pascal OSErr
HGetVolParms(ConstStr255Param volName
,
50 GetVolParmsInfoBuffer
*volParmsInfo
,
56 pb
.ioParam
.ioNamePtr
= (StringPtr
)volName
;
57 pb
.ioParam
.ioVRefNum
= vRefNum
;
58 pb
.ioParam
.ioBuffer
= (Ptr
)volParmsInfo
;
59 pb
.ioParam
.ioReqCount
= *infoSize
;
60 error
= PBHGetVolParmsSync(&pb
);
63 *infoSize
= pb
.ioParam
.ioActCount
;
68 /*****************************************************************************/
70 pascal OSErr
HCreateMinimum(short vRefNum
,
72 ConstStr255Param fileName
)
76 pb
.fileParam
.ioNamePtr
= (StringPtr
)fileName
;
77 pb
.fileParam
.ioVRefNum
= vRefNum
;
78 pb
.ioParam
.ioVersNum
= 0;
79 pb
.fileParam
.ioDirID
= dirID
;
80 return ( PBHCreateSync(&pb
) );
83 /*****************************************************************************/
85 pascal OSErr
FSpCreateMinimum(const FSSpec
*spec
)
87 return ( HCreateMinimum(spec
->vRefNum
, spec
->parID
, spec
->name
) );
90 /*****************************************************************************/
92 pascal OSErr
ExchangeFiles(short vRefNum
,
94 ConstStr255Param srcName
,
96 ConstStr255Param dstName
)
100 pb
.fidParam
.ioVRefNum
= vRefNum
;
101 pb
.fidParam
.ioSrcDirID
= srcDirID
;
102 pb
.fidParam
.ioNamePtr
= (StringPtr
)srcName
;
103 pb
.fidParam
.ioDestDirID
= dstDirID
;
104 pb
.fidParam
.ioDestNamePtr
= (StringPtr
)dstName
;
105 return ( PBExchangeFilesSync(&pb
) );
108 /*****************************************************************************/
110 pascal OSErr
ResolveFileIDRef(ConstStr255Param volName
,
121 if ( volName
!= NULL
)
123 BlockMoveData(volName
, tempStr
, volName
[0] + 1);
125 pb
.fidParam
.ioNamePtr
= (StringPtr
)tempStr
;
126 pb
.fidParam
.ioVRefNum
= vRefNum
;
127 pb
.fidParam
.ioFileID
= fileID
;
128 error
= PBResolveFileIDRefSync(&pb
);
129 if ( error
== noErr
)
131 *parID
= pb
.fidParam
.ioSrcDirID
;
132 if ( fileName
!= NULL
)
134 BlockMoveData(tempStr
, fileName
, tempStr
[0] + 1);
140 /*****************************************************************************/
142 pascal OSErr
FSpResolveFileIDRef(ConstStr255Param volName
,
149 error
= DetermineVRefNum(volName
, vRefNum
, &(spec
->vRefNum
));
150 if ( error
== noErr
)
152 error
= ResolveFileIDRef(volName
, vRefNum
, fileID
, &(spec
->parID
), spec
->name
);
157 /*****************************************************************************/
159 pascal OSErr
CreateFileIDRef(short vRefNum
,
161 ConstStr255Param fileName
,
167 pb
.fidParam
.ioNamePtr
= (StringPtr
)fileName
;
168 pb
.fidParam
.ioVRefNum
= vRefNum
;
169 pb
.fidParam
.ioSrcDirID
= parID
;
170 error
= PBCreateFileIDRefSync(&pb
);
171 if ( (error
== noErr
) || (error
== fidExists
) || (error
== afpIDExists
) )
173 *fileID
= pb
.fidParam
.ioFileID
;
178 /*****************************************************************************/
180 pascal OSErr
FSpCreateFileIDRef(const FSSpec
*spec
,
183 return ( CreateFileIDRef(spec
->vRefNum
, spec
->parID
, spec
->name
, fileID
) );
186 /*****************************************************************************/
188 pascal OSErr
DeleteFileIDRef(ConstStr255Param volName
,
194 pb
.fidParam
.ioNamePtr
= (StringPtr
)volName
;
195 pb
.fidParam
.ioVRefNum
= vRefNum
;
196 pb
.fidParam
.ioFileID
= fileID
;
197 return ( PBDeleteFileIDRefSync(&pb
) );
200 /*****************************************************************************/
202 pascal OSErr
FlushFile(short refNum
)
206 pb
.ioParam
.ioRefNum
= refNum
;
207 return ( PBFlushFileSync(&pb
) );
210 /*****************************************************************************/
212 pascal OSErr
LockRange(short refNum
,
218 pb
.ioParam
.ioRefNum
= refNum
;
219 pb
.ioParam
.ioReqCount
= rangeLength
;
220 pb
.ioParam
.ioPosMode
= fsFromStart
;
221 pb
.ioParam
.ioPosOffset
= rangeStart
;
222 return ( PBLockRangeSync(&pb
) );
225 /*****************************************************************************/
227 pascal OSErr
UnlockRange(short refNum
,
233 pb
.ioParam
.ioRefNum
= refNum
;
234 pb
.ioParam
.ioReqCount
= rangeLength
;
235 pb
.ioParam
.ioPosMode
= fsFromStart
;
236 pb
.ioParam
.ioPosOffset
= rangeStart
;
237 return ( PBUnlockRangeSync(&pb
) );
240 /*****************************************************************************/
242 pascal OSErr
GetForeignPrivs(short vRefNum
,
244 ConstStr255Param name
,
245 void *foreignPrivBuffer
,
246 long *foreignPrivSize
,
247 long *foreignPrivInfo1
,
248 long *foreignPrivInfo2
,
249 long *foreignPrivInfo3
,
250 long *foreignPrivInfo4
)
255 pb
.foreignPrivParam
.ioNamePtr
= (StringPtr
)name
;
256 pb
.foreignPrivParam
.ioVRefNum
= vRefNum
;
257 pb
.foreignPrivParam
.ioForeignPrivDirID
= dirID
;
258 pb
.foreignPrivParam
.ioForeignPrivBuffer
= (Ptr
)foreignPrivBuffer
;
259 pb
.foreignPrivParam
.ioForeignPrivReqCount
= *foreignPrivSize
;
260 error
= PBGetForeignPrivsSync(&pb
);
261 *foreignPrivSize
= pb
.foreignPrivParam
.ioForeignPrivActCount
;
262 *foreignPrivInfo1
= pb
.foreignPrivParam
.ioForeignPrivInfo1
;
263 *foreignPrivInfo2
= pb
.foreignPrivParam
.ioForeignPrivInfo2
;
264 *foreignPrivInfo3
= pb
.foreignPrivParam
.ioForeignPrivInfo3
;
265 *foreignPrivInfo4
= pb
.foreignPrivParam
.ioForeignPrivInfo4
;
269 /*****************************************************************************/
271 pascal OSErr
FSpGetForeignPrivs(const FSSpec
*spec
,
272 void *foreignPrivBuffer
,
273 long *foreignPrivSize
,
274 long *foreignPrivInfo1
,
275 long *foreignPrivInfo2
,
276 long *foreignPrivInfo3
,
277 long *foreignPrivInfo4
)
279 return ( GetForeignPrivs(spec
->vRefNum
, spec
->parID
, spec
->name
,
280 foreignPrivBuffer
, foreignPrivSize
,
281 foreignPrivInfo1
, foreignPrivInfo2
,
282 foreignPrivInfo3
, foreignPrivInfo4
) );
285 /*****************************************************************************/
287 pascal OSErr
SetForeignPrivs(short vRefNum
,
289 ConstStr255Param name
,
290 const void *foreignPrivBuffer
,
291 long *foreignPrivSize
,
292 long foreignPrivInfo1
,
293 long foreignPrivInfo2
,
294 long foreignPrivInfo3
,
295 long foreignPrivInfo4
)
300 pb
.foreignPrivParam
.ioNamePtr
= (StringPtr
)name
;
301 pb
.foreignPrivParam
.ioVRefNum
= vRefNum
;
302 pb
.foreignPrivParam
.ioForeignPrivDirID
= dirID
;
303 pb
.foreignPrivParam
.ioForeignPrivBuffer
= (Ptr
)foreignPrivBuffer
;
304 pb
.foreignPrivParam
.ioForeignPrivReqCount
= *foreignPrivSize
;
305 pb
.foreignPrivParam
.ioForeignPrivInfo1
= foreignPrivInfo1
;
306 pb
.foreignPrivParam
.ioForeignPrivInfo2
= foreignPrivInfo2
;
307 pb
.foreignPrivParam
.ioForeignPrivInfo3
= foreignPrivInfo3
;
308 pb
.foreignPrivParam
.ioForeignPrivInfo4
= foreignPrivInfo4
;
309 error
= PBSetForeignPrivsSync(&pb
);
310 if ( error
== noErr
)
312 *foreignPrivSize
= pb
.foreignPrivParam
.ioForeignPrivActCount
;
317 /*****************************************************************************/
319 pascal OSErr
FSpSetForeignPrivs(const FSSpec
*spec
,
320 const void *foreignPrivBuffer
,
321 long *foreignPrivSize
,
322 long foreignPrivInfo1
,
323 long foreignPrivInfo2
,
324 long foreignPrivInfo3
,
325 long foreignPrivInfo4
)
327 return ( SetForeignPrivs(spec
->vRefNum
, spec
->parID
, spec
->name
,
328 foreignPrivBuffer
, foreignPrivSize
,
329 foreignPrivInfo1
, foreignPrivInfo2
,
330 foreignPrivInfo3
, foreignPrivInfo4
) );
333 /*****************************************************************************/
335 pascal OSErr
HGetLogInInfo(ConstStr255Param volName
,
343 pb
.objParam
.ioNamePtr
= (StringPtr
)volName
;
344 pb
.objParam
.ioVRefNum
= vRefNum
;
345 pb
.objParam
.ioObjNamePtr
= userName
;
346 error
= PBHGetLogInInfoSync(&pb
);
347 if ( error
== noErr
)
349 *loginMethod
= pb
.objParam
.ioObjType
;
354 /*****************************************************************************/
356 pascal OSErr
HGetDirAccess(short vRefNum
,
358 ConstStr255Param name
,
366 pb
.accessParam
.ioNamePtr
= (StringPtr
)name
;
367 pb
.accessParam
.ioVRefNum
= vRefNum
;
368 pb
.fileParam
.ioDirID
= dirID
;
369 error
= PBHGetDirAccessSync(&pb
);
370 if ( error
== noErr
)
372 *ownerID
= pb
.accessParam
.ioACOwnerID
;
373 *groupID
= pb
.accessParam
.ioACGroupID
;
374 *accessRights
= pb
.accessParam
.ioACAccess
;
379 /*****************************************************************************/
381 pascal OSErr
FSpGetDirAccess(const FSSpec
*spec
,
386 return ( HGetDirAccess(spec
->vRefNum
, spec
->parID
, spec
->name
,
387 ownerID
, groupID
, accessRights
) );
390 /*****************************************************************************/
392 pascal OSErr
HSetDirAccess(short vRefNum
,
394 ConstStr255Param name
,
401 pb
.accessParam
.ioNamePtr
= (StringPtr
)name
;
402 pb
.accessParam
.ioVRefNum
= vRefNum
;
403 pb
.fileParam
.ioDirID
= dirID
;
404 pb
.accessParam
.ioACOwnerID
= ownerID
;
405 pb
.accessParam
.ioACGroupID
= groupID
;
406 pb
.accessParam
.ioACAccess
= accessRights
;
407 return ( PBHSetDirAccessSync(&pb
) );
410 /*****************************************************************************/
412 pascal OSErr
FSpSetDirAccess(const FSSpec
*spec
,
417 return ( HSetDirAccess(spec
->vRefNum
, spec
->parID
, spec
->name
,
418 ownerID
, groupID
, accessRights
) );
421 /*****************************************************************************/
423 pascal OSErr
HMapID(ConstStr255Param volName
,
431 pb
.objParam
.ioNamePtr
= (StringPtr
)volName
;
432 pb
.objParam
.ioVRefNum
= vRefNum
;
433 pb
.objParam
.ioObjType
= objType
;
434 pb
.objParam
.ioObjNamePtr
= name
;
435 pb
.objParam
.ioObjID
= ugID
;
436 return ( PBHMapIDSync(&pb
) );
439 /*****************************************************************************/
441 pascal OSErr
HMapName(ConstStr255Param volName
,
443 ConstStr255Param name
,
450 pb
.objParam
.ioNamePtr
= (StringPtr
)volName
;
451 pb
.objParam
.ioVRefNum
= vRefNum
;
452 pb
.objParam
.ioObjType
= objType
;
453 pb
.objParam
.ioObjNamePtr
= (StringPtr
)name
;
454 error
= PBHMapNameSync(&pb
);
455 if ( error
== noErr
)
457 *ugID
= pb
.objParam
.ioObjID
;
462 /*****************************************************************************/
464 pascal OSErr
HCopyFile(short srcVRefNum
,
466 ConstStr255Param srcName
,
469 ConstStr255Param dstPathname
,
470 ConstStr255Param copyName
)
474 pb
.copyParam
.ioVRefNum
= srcVRefNum
;
475 pb
.copyParam
.ioDirID
= srcDirID
;
476 pb
.copyParam
.ioNamePtr
= (StringPtr
)srcName
;
477 pb
.copyParam
.ioDstVRefNum
= dstVRefNum
;
478 pb
.copyParam
.ioNewDirID
= dstDirID
;
479 pb
.copyParam
.ioNewName
= (StringPtr
)dstPathname
;
480 pb
.copyParam
.ioCopyName
= (StringPtr
)copyName
;
481 return ( PBHCopyFileSync(&pb
) );
484 /*****************************************************************************/
486 pascal OSErr
FSpCopyFile(const FSSpec
*srcSpec
,
487 const FSSpec
*dstSpec
,
488 ConstStr255Param copyName
)
490 return ( HCopyFile(srcSpec
->vRefNum
, srcSpec
->parID
, srcSpec
->name
,
491 dstSpec
->vRefNum
, dstSpec
->parID
,
492 dstSpec
->name
, copyName
) );
495 /*****************************************************************************/
497 pascal OSErr
HMoveRename(short vRefNum
,
499 ConstStr255Param srcName
,
501 ConstStr255Param dstpathName
,
502 ConstStr255Param copyName
)
506 pb
.copyParam
.ioVRefNum
= vRefNum
;
507 pb
.copyParam
.ioDirID
= srcDirID
;
508 pb
.copyParam
.ioNamePtr
= (StringPtr
)srcName
;
509 pb
.copyParam
.ioNewDirID
= dstDirID
;
510 pb
.copyParam
.ioNewName
= (StringPtr
)dstpathName
;
511 pb
.copyParam
.ioCopyName
= (StringPtr
)copyName
;
512 return ( PBHMoveRenameSync(&pb
) );
515 /*****************************************************************************/
517 pascal OSErr
FSpMoveRename(const FSSpec
*srcSpec
,
518 const FSSpec
*dstSpec
,
519 ConstStr255Param copyName
)
523 /* make sure the FSSpecs refer to the same volume */
524 if ( srcSpec
->vRefNum
!= dstSpec
->vRefNum
)
530 error
= HMoveRename(srcSpec
->vRefNum
, srcSpec
->parID
, srcSpec
->name
,
531 dstSpec
->parID
, dstSpec
->name
, copyName
);
536 /*****************************************************************************/
538 pascal OSErr
GetVolMountInfoSize(ConstStr255Param volName
,
544 pb
.ioParam
.ioNamePtr
= (StringPtr
)volName
;
545 pb
.ioParam
.ioVRefNum
= vRefNum
;
546 pb
.ioParam
.ioBuffer
= (Ptr
)size
;
547 return ( PBGetVolMountInfoSize(&pb
) );
550 /*****************************************************************************/
552 pascal OSErr
GetVolMountInfo(ConstStr255Param volName
,
558 pb
.ioParam
.ioNamePtr
= (StringPtr
)volName
;
559 pb
.ioParam
.ioVRefNum
= vRefNum
;
560 pb
.ioParam
.ioBuffer
= (Ptr
)volMountInfo
;
561 return ( PBGetVolMountInfo(&pb
) );
564 /*****************************************************************************/
566 pascal OSErr
VolumeMount(const void *volMountInfo
,
572 pb
.ioParam
.ioBuffer
= (Ptr
)volMountInfo
;
573 error
= PBVolumeMount(&pb
);
574 if ( error
== noErr
)
576 *vRefNum
= pb
.ioParam
.ioVRefNum
;
581 /*****************************************************************************/
583 pascal OSErr
Share(short vRefNum
,
585 ConstStr255Param name
)
589 pb
.fileParam
.ioNamePtr
= (StringPtr
)name
;
590 pb
.fileParam
.ioVRefNum
= vRefNum
;
591 pb
.fileParam
.ioDirID
= dirID
;
592 return ( PBShareSync(&pb
) );
595 /*****************************************************************************/
597 pascal OSErr
FSpShare(const FSSpec
*spec
)
599 return ( Share(spec
->vRefNum
, spec
->parID
, spec
->name
) );
602 /*****************************************************************************/
604 pascal OSErr
Unshare(short vRefNum
,
606 ConstStr255Param name
)
610 pb
.fileParam
.ioNamePtr
= (StringPtr
)name
;
611 pb
.fileParam
.ioVRefNum
= vRefNum
;
612 pb
.fileParam
.ioDirID
= dirID
;
613 return ( PBUnshareSync(&pb
) );
616 /*****************************************************************************/
618 pascal OSErr
FSpUnshare(const FSSpec
*spec
)
620 return ( Unshare(spec
->vRefNum
, spec
->parID
, spec
->name
) );
623 /*****************************************************************************/
625 pascal OSErr
GetUGEntry(short objType
,
632 pb
.objParam
.ioObjType
= objType
;
633 pb
.objParam
.ioObjNamePtr
= objName
;
634 pb
.objParam
.ioObjID
= *objID
;
635 error
= PBGetUGEntrySync(&pb
);
636 if ( error
== noErr
)
638 *objID
= pb
.objParam
.ioObjID
;
643 /*****************************************************************************/