2 ** Apple Macintosh Developer Technical Support
4 ** The long lost high-level and FSSpec File Manager functions.
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.
26 #define __COMPILINGMOREFILES
31 /*****************************************************************************/
33 pascal OSErr
HGetVolParms(ConstStr255Param volName
,
35 GetVolParmsInfoBuffer
*volParmsInfo
,
41 pb
.ioParam
.ioNamePtr
= (StringPtr
)volName
;
42 pb
.ioParam
.ioVRefNum
= vRefNum
;
43 pb
.ioParam
.ioBuffer
= (Ptr
)volParmsInfo
;
44 pb
.ioParam
.ioReqCount
= *infoSize
;
45 error
= PBHGetVolParmsSync(&pb
);
48 *infoSize
= pb
.ioParam
.ioActCount
;
53 /*****************************************************************************/
55 pascal OSErr
HCreateMinimum(short vRefNum
,
57 ConstStr255Param fileName
)
61 pb
.fileParam
.ioNamePtr
= (StringPtr
)fileName
;
62 pb
.fileParam
.ioVRefNum
= vRefNum
;
63 pb
.ioParam
.ioVersNum
= 0;
64 pb
.fileParam
.ioDirID
= dirID
;
65 return ( PBHCreateSync(&pb
) );
68 /*****************************************************************************/
70 pascal OSErr
FSpCreateMinimum(const FSSpec
*spec
)
72 return ( HCreateMinimum(spec
->vRefNum
, spec
->parID
, spec
->name
) );
75 /*****************************************************************************/
77 pascal OSErr
ExchangeFiles(short vRefNum
,
79 ConstStr255Param srcName
,
81 ConstStr255Param dstName
)
85 pb
.fidParam
.ioVRefNum
= vRefNum
;
86 pb
.fidParam
.ioSrcDirID
= srcDirID
;
87 pb
.fidParam
.ioNamePtr
= (StringPtr
)srcName
;
88 pb
.fidParam
.ioDestDirID
= dstDirID
;
89 pb
.fidParam
.ioDestNamePtr
= (StringPtr
)dstName
;
90 return ( PBExchangeFilesSync(&pb
) );
93 /*****************************************************************************/
95 pascal OSErr
ResolveFileIDRef(ConstStr255Param volName
,
106 if ( volName
!= NULL
)
108 BlockMoveData(volName
, tempStr
, volName
[0] + 1);
110 pb
.fidParam
.ioNamePtr
= (StringPtr
)tempStr
;
111 pb
.fidParam
.ioVRefNum
= vRefNum
;
112 pb
.fidParam
.ioFileID
= fileID
;
113 error
= PBResolveFileIDRefSync(&pb
);
114 if ( error
== noErr
)
116 *parID
= pb
.fidParam
.ioSrcDirID
;
117 if ( fileName
!= NULL
)
119 BlockMoveData(tempStr
, fileName
, tempStr
[0] + 1);
125 /*****************************************************************************/
127 pascal OSErr
FSpResolveFileIDRef(ConstStr255Param volName
,
134 error
= DetermineVRefNum(volName
, vRefNum
, &(spec
->vRefNum
));
135 if ( error
== noErr
)
137 error
= ResolveFileIDRef(volName
, vRefNum
, fileID
, &(spec
->parID
), spec
->name
);
142 /*****************************************************************************/
144 pascal OSErr
CreateFileIDRef(short vRefNum
,
146 ConstStr255Param fileName
,
152 pb
.fidParam
.ioNamePtr
= (StringPtr
)fileName
;
153 pb
.fidParam
.ioVRefNum
= vRefNum
;
154 pb
.fidParam
.ioSrcDirID
= parID
;
155 error
= PBCreateFileIDRefSync(&pb
);
156 if ( error
== noErr
)
158 *fileID
= pb
.fidParam
.ioFileID
;
163 /*****************************************************************************/
165 pascal OSErr
FSpCreateFileIDRef(const FSSpec
*spec
,
168 return ( CreateFileIDRef(spec
->vRefNum
, spec
->parID
, spec
->name
, fileID
) );
171 /*****************************************************************************/
173 pascal OSErr
DeleteFileIDRef(ConstStr255Param volName
,
179 pb
.fidParam
.ioNamePtr
= (StringPtr
)volName
;
180 pb
.fidParam
.ioVRefNum
= vRefNum
;
181 pb
.fidParam
.ioFileID
= fileID
;
182 return ( PBDeleteFileIDRefSync(&pb
) );
185 /*****************************************************************************/
187 pascal OSErr
FlushFile(short refNum
)
191 pb
.ioParam
.ioRefNum
= refNum
;
192 return ( PBFlushFileSync(&pb
) );
195 /*****************************************************************************/
197 pascal OSErr
LockRange(short refNum
,
203 pb
.ioParam
.ioRefNum
= refNum
;
204 pb
.ioParam
.ioReqCount
= rangeLength
;
205 pb
.ioParam
.ioPosMode
= fsFromStart
;
206 pb
.ioParam
.ioPosOffset
= rangeStart
;
207 return ( PBLockRangeSync(&pb
) );
210 /*****************************************************************************/
212 pascal OSErr
UnlockRange(short refNum
,
218 pb
.ioParam
.ioRefNum
= refNum
;
219 pb
.ioParam
.ioReqCount
= rangeLength
;
220 pb
.ioParam
.ioPosMode
= fsFromStart
;
221 pb
.ioParam
.ioPosOffset
= rangeStart
;
222 return ( PBUnlockRangeSync(&pb
) );
225 /*****************************************************************************/
227 pascal OSErr
GetForeignPrivs(short vRefNum
,
229 ConstStr255Param name
,
230 void *foreignPrivBuffer
,
231 long *foreignPrivSize
,
232 long *foreignPrivInfo1
,
233 long *foreignPrivInfo2
,
234 long *foreignPrivInfo3
,
235 long *foreignPrivInfo4
)
240 pb
.foreignPrivParam
.ioNamePtr
= (StringPtr
)name
;
241 pb
.foreignPrivParam
.ioVRefNum
= vRefNum
;
242 pb
.foreignPrivParam
.ioForeignPrivDirID
= dirID
;
243 pb
.foreignPrivParam
.ioForeignPrivBuffer
= (Ptr
)foreignPrivBuffer
;
244 pb
.foreignPrivParam
.ioForeignPrivReqCount
= *foreignPrivSize
;
245 error
= PBGetForeignPrivsSync(&pb
);
246 *foreignPrivSize
= pb
.foreignPrivParam
.ioForeignPrivActCount
;
247 *foreignPrivInfo1
= pb
.foreignPrivParam
.ioForeignPrivInfo1
;
248 *foreignPrivInfo2
= pb
.foreignPrivParam
.ioForeignPrivInfo2
;
249 *foreignPrivInfo3
= pb
.foreignPrivParam
.ioForeignPrivInfo3
;
250 *foreignPrivInfo4
= pb
.foreignPrivParam
.ioForeignPrivInfo4
;
254 /*****************************************************************************/
256 pascal OSErr
FSpGetForeignPrivs(const FSSpec
*spec
,
257 void *foreignPrivBuffer
,
258 long *foreignPrivSize
,
259 long *foreignPrivInfo1
,
260 long *foreignPrivInfo2
,
261 long *foreignPrivInfo3
,
262 long *foreignPrivInfo4
)
264 return ( GetForeignPrivs(spec
->vRefNum
, spec
->parID
, spec
->name
,
265 foreignPrivBuffer
, foreignPrivSize
,
266 foreignPrivInfo1
, foreignPrivInfo2
,
267 foreignPrivInfo3
, foreignPrivInfo4
) );
270 /*****************************************************************************/
272 pascal OSErr
SetForeignPrivs(short vRefNum
,
274 ConstStr255Param name
,
275 const void *foreignPrivBuffer
,
276 long *foreignPrivSize
,
277 long foreignPrivInfo1
,
278 long foreignPrivInfo2
,
279 long foreignPrivInfo3
,
280 long foreignPrivInfo4
)
285 pb
.foreignPrivParam
.ioNamePtr
= (StringPtr
)name
;
286 pb
.foreignPrivParam
.ioVRefNum
= vRefNum
;
287 pb
.foreignPrivParam
.ioForeignPrivDirID
= dirID
;
288 pb
.foreignPrivParam
.ioForeignPrivBuffer
= (Ptr
)foreignPrivBuffer
;
289 pb
.foreignPrivParam
.ioForeignPrivReqCount
= *foreignPrivSize
;
290 pb
.foreignPrivParam
.ioForeignPrivInfo1
= foreignPrivInfo1
;
291 pb
.foreignPrivParam
.ioForeignPrivInfo2
= foreignPrivInfo2
;
292 pb
.foreignPrivParam
.ioForeignPrivInfo3
= foreignPrivInfo3
;
293 pb
.foreignPrivParam
.ioForeignPrivInfo4
= foreignPrivInfo4
;
294 error
= PBSetForeignPrivsSync(&pb
);
295 if ( error
== noErr
)
297 *foreignPrivSize
= pb
.foreignPrivParam
.ioForeignPrivActCount
;
302 /*****************************************************************************/
304 pascal OSErr
FSpSetForeignPrivs(const FSSpec
*spec
,
305 const void *foreignPrivBuffer
,
306 long *foreignPrivSize
,
307 long foreignPrivInfo1
,
308 long foreignPrivInfo2
,
309 long foreignPrivInfo3
,
310 long foreignPrivInfo4
)
312 return ( SetForeignPrivs(spec
->vRefNum
, spec
->parID
, spec
->name
,
313 foreignPrivBuffer
, foreignPrivSize
,
314 foreignPrivInfo1
, foreignPrivInfo2
,
315 foreignPrivInfo3
, foreignPrivInfo4
) );
318 /*****************************************************************************/
320 pascal OSErr
HGetLogInInfo(ConstStr255Param volName
,
328 pb
.objParam
.ioNamePtr
= (StringPtr
)volName
;
329 pb
.objParam
.ioVRefNum
= vRefNum
;
330 pb
.objParam
.ioObjNamePtr
= userName
;
331 error
= PBHGetLogInInfoSync(&pb
);
332 if ( error
== noErr
)
334 *loginMethod
= pb
.objParam
.ioObjType
;
339 /*****************************************************************************/
341 pascal OSErr
HGetDirAccess(short vRefNum
,
343 ConstStr255Param name
,
351 pb
.accessParam
.ioNamePtr
= (StringPtr
)name
;
352 pb
.accessParam
.ioVRefNum
= vRefNum
;
353 pb
.fileParam
.ioDirID
= dirID
;
354 error
= PBHGetDirAccessSync(&pb
);
355 if ( error
== noErr
)
357 *ownerID
= pb
.accessParam
.ioACOwnerID
;
358 *groupID
= pb
.accessParam
.ioACGroupID
;
359 *accessRights
= pb
.accessParam
.ioACAccess
;
364 /*****************************************************************************/
366 pascal OSErr
FSpGetDirAccess(const FSSpec
*spec
,
371 return ( HGetDirAccess(spec
->vRefNum
, spec
->parID
, spec
->name
,
372 ownerID
, groupID
, accessRights
) );
375 /*****************************************************************************/
377 pascal OSErr
HSetDirAccess(short vRefNum
,
379 ConstStr255Param name
,
386 pb
.accessParam
.ioNamePtr
= (StringPtr
)name
;
387 pb
.accessParam
.ioVRefNum
= vRefNum
;
388 pb
.fileParam
.ioDirID
= dirID
;
389 pb
.accessParam
.ioACOwnerID
= ownerID
;
390 pb
.accessParam
.ioACGroupID
= groupID
;
391 pb
.accessParam
.ioACAccess
= accessRights
;
392 return ( PBHSetDirAccessSync(&pb
) );
395 /*****************************************************************************/
397 pascal OSErr
FSpSetDirAccess(const FSSpec
*spec
,
402 return ( HSetDirAccess(spec
->vRefNum
, spec
->parID
, spec
->name
,
403 ownerID
, groupID
, accessRights
) );
406 /*****************************************************************************/
408 pascal OSErr
HMapID(ConstStr255Param volName
,
416 pb
.objParam
.ioNamePtr
= (StringPtr
)volName
;
417 pb
.objParam
.ioVRefNum
= vRefNum
;
418 pb
.objParam
.ioObjType
= objType
;
419 pb
.objParam
.ioObjNamePtr
= name
;
420 pb
.objParam
.ioObjID
= ugID
;
421 return ( PBHMapIDSync(&pb
) );
424 /*****************************************************************************/
426 pascal OSErr
HMapName(ConstStr255Param volName
,
428 ConstStr255Param name
,
435 pb
.objParam
.ioNamePtr
= (StringPtr
)volName
;
436 pb
.objParam
.ioVRefNum
= vRefNum
;
437 pb
.objParam
.ioObjType
= objType
;
438 pb
.objParam
.ioObjNamePtr
= (StringPtr
)name
;
439 error
= PBHMapNameSync(&pb
);
440 if ( error
== noErr
)
442 *ugID
= pb
.objParam
.ioObjID
;
447 /*****************************************************************************/
449 pascal OSErr
HCopyFile(short srcVRefNum
,
451 ConstStr255Param srcName
,
454 ConstStr255Param dstPathname
,
455 ConstStr255Param copyName
)
459 pb
.copyParam
.ioVRefNum
= srcVRefNum
;
460 pb
.copyParam
.ioDirID
= srcDirID
;
461 pb
.copyParam
.ioNamePtr
= (StringPtr
)srcName
;
462 pb
.copyParam
.ioDstVRefNum
= dstVRefNum
;
463 pb
.copyParam
.ioNewDirID
= dstDirID
;
464 pb
.copyParam
.ioNewName
= (StringPtr
)dstPathname
;
465 pb
.copyParam
.ioCopyName
= (StringPtr
)copyName
;
466 return ( PBHCopyFileSync(&pb
) );
469 /*****************************************************************************/
471 pascal OSErr
FSpCopyFile(const FSSpec
*srcSpec
,
472 const FSSpec
*dstSpec
,
473 ConstStr255Param copyName
)
475 return ( HCopyFile(srcSpec
->vRefNum
, srcSpec
->parID
, srcSpec
->name
,
476 dstSpec
->vRefNum
, dstSpec
->parID
,
477 dstSpec
->name
, copyName
) );
480 /*****************************************************************************/
482 pascal OSErr
HMoveRename(short vRefNum
,
484 ConstStr255Param srcName
,
486 ConstStr255Param dstpathName
,
487 ConstStr255Param copyName
)
491 pb
.copyParam
.ioVRefNum
= vRefNum
;
492 pb
.copyParam
.ioDirID
= srcDirID
;
493 pb
.copyParam
.ioNamePtr
= (StringPtr
)srcName
;
494 pb
.copyParam
.ioNewDirID
= dstDirID
;
495 pb
.copyParam
.ioNewName
= (StringPtr
)dstpathName
;
496 pb
.copyParam
.ioCopyName
= (StringPtr
)copyName
;
497 return ( PBHMoveRenameSync(&pb
) );
500 /*****************************************************************************/
502 pascal OSErr
FSpMoveRename(const FSSpec
*srcSpec
,
503 const FSSpec
*dstSpec
,
504 ConstStr255Param copyName
)
508 /* make sure the FSSpecs refer to the same volume */
509 if ( srcSpec
->vRefNum
!= dstSpec
->vRefNum
)
515 error
= HMoveRename(srcSpec
->vRefNum
, srcSpec
->parID
, srcSpec
->name
,
516 dstSpec
->parID
, dstSpec
->name
, copyName
);
521 /*****************************************************************************/
523 pascal OSErr
GetVolMountInfoSize(ConstStr255Param volName
,
529 pb
.ioParam
.ioNamePtr
= (StringPtr
)volName
;
530 pb
.ioParam
.ioVRefNum
= vRefNum
;
531 pb
.ioParam
.ioBuffer
= (Ptr
)size
;
532 return ( PBGetVolMountInfoSize(&pb
) );
535 /*****************************************************************************/
537 pascal OSErr
GetVolMountInfo(ConstStr255Param volName
,
543 pb
.ioParam
.ioNamePtr
= (StringPtr
)volName
;
544 pb
.ioParam
.ioVRefNum
= vRefNum
;
545 pb
.ioParam
.ioBuffer
= (Ptr
)volMountInfo
;
546 return ( PBGetVolMountInfo(&pb
) );
549 /*****************************************************************************/
551 pascal OSErr
VolumeMount(const void *volMountInfo
,
557 pb
.ioParam
.ioBuffer
= (Ptr
)volMountInfo
;
558 error
= PBVolumeMount(&pb
);
559 if ( error
== noErr
)
561 *vRefNum
= pb
.ioParam
.ioVRefNum
;
566 /*****************************************************************************/
568 pascal OSErr
Share(short vRefNum
,
570 ConstStr255Param name
)
574 pb
.fileParam
.ioNamePtr
= (StringPtr
)name
;
575 pb
.fileParam
.ioVRefNum
= vRefNum
;
576 pb
.fileParam
.ioDirID
= dirID
;
577 return ( PBShareSync(&pb
) );
580 /*****************************************************************************/
582 pascal OSErr
FSpShare(const FSSpec
*spec
)
584 return ( Share(spec
->vRefNum
, spec
->parID
, spec
->name
) );
587 /*****************************************************************************/
589 pascal OSErr
Unshare(short vRefNum
,
591 ConstStr255Param name
)
595 pb
.fileParam
.ioNamePtr
= (StringPtr
)name
;
596 pb
.fileParam
.ioVRefNum
= vRefNum
;
597 pb
.fileParam
.ioDirID
= dirID
;
598 return ( PBUnshareSync(&pb
) );
601 /*****************************************************************************/
603 pascal OSErr
FSpUnshare(const FSSpec
*spec
)
605 return ( Unshare(spec
->vRefNum
, spec
->parID
, spec
->name
) );
608 /*****************************************************************************/
610 pascal OSErr
GetUGEntry(short objType
,
617 pb
.objParam
.ioObjType
= objType
;
618 pb
.objParam
.ioObjNamePtr
= objName
;
619 pb
.objParam
.ioObjID
= *objID
;
620 error
= PBGetUGEntrySync(&pb
);
621 if ( error
== noErr
)
623 *objID
= pb
.objParam
.ioObjID
;
628 /*****************************************************************************/