Rev 193 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 259 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | This file is part of a common library |
2 | This file is part of a common library |
3 | Copyright (C) 1990-2009 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 1990-2009 Toby Thain, toby@telegraphics.com.au |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
18 | */ |
19 | 19 | ||
20 | #include <files.h> |
20 | #include <files.h> |
21 | #include <gestalt.h> |
21 | #include <gestalt.h> |
22 | 22 | ||
23 | #include "file_compat.h" |
23 | #include "file_compat.h" |
24 | 24 | ||
25 | Boolean has_forks = false; |
25 | Boolean has_forks = false; |
26 | 26 | ||
27 | /* Check whether HFS+ calls are available (for large file support). */ |
27 | /* Check whether HFS+ calls are available (for large file support). */ |
28 | Boolean host_has_forks(){ |
28 | Boolean host_has_forks(){ |
29 | SInt32 resp; |
29 | SInt32 resp; |
30 | 30 | ||
31 | return !Gestalt(gestaltFSAttr, &resp) && (resp & (1L<<gestaltFSSupportsHFSPlusVols)); |
31 | return !Gestalt(gestaltFSAttr, &resp) && (resp & (1L<<gestaltFSSupportsHFSPlusVols)); |
32 | } |
32 | } |
33 | 33 | ||
34 | OSErr fspopendf_large(const FSSpec *spec, int perm, FILEREF *refNum){ |
34 | OSErr fspopendf_large(const FSSpec *spec, int perm, FILEREF *refNum){ |
35 | FSRef ref; |
35 | FSRef ref; |
36 | HFSUniStr255 dfname; |
36 | HFSUniStr255 dfname; |
37 | OSErr e; |
37 | OSErr e; |
38 | 38 | ||
39 | if(has_forks){ |
39 | if(has_forks){ |
40 | if( !(e = FSpMakeFSRef(spec,&ref)) && !(e = FSGetDataForkName(&dfname)) ) |
40 | if( !(e = FSpMakeFSRef(spec,&ref)) && !(e = FSGetDataForkName(&dfname)) ) |
41 | e = FSOpenFork(&ref,dfname.length,dfname.unicode,perm,refNum); |
41 | e = FSOpenFork(&ref,dfname.length,dfname.unicode,perm,refNum); |
42 | }else |
42 | }else |
43 | e = FSpOpenDF(spec,perm,refNum); |
43 | e = FSpOpenDF(spec,perm,refNum); |
44 | return e; |
44 | return e; |
45 | } |
45 | } |
46 | 46 | ||
47 | OSErr fsread_large(FILEREF refNum,FILECOUNT *count,void *buffPtr){ |
47 | OSErr fsread_large(FILEREF refNum,FILECOUNT *count,void *buffPtr){ |
48 | OSErr e = has_forks ? FSReadFork(refNum,fsFromMark,0,*count,buffPtr,count) |
48 | OSErr e = has_forks ? FSReadFork(refNum,fsFromMark,0,*count,buffPtr,count) |
49 | : FSRead(refNum,count,buffPtr); |
49 | : FSRead(refNum,count,buffPtr); |
50 | //if(e)DebugStr("\pfsread_large"); |
50 | //if(e)DebugStr("\pfsread_large"); |
51 | return e; |
51 | return e; |
52 | } |
52 | } |
53 | 53 | ||
54 | OSErr fswrite_large(FILEREF refNum,FILECOUNT *count,void *buffPtr){ |
54 | OSErr fswrite_large(FILEREF refNum,FILECOUNT *count,void *buffPtr){ |
55 | OSErr e = has_forks ? FSWriteFork(refNum,fsFromMark,0,*count,buffPtr,count) |
55 | OSErr e = has_forks ? FSWriteFork(refNum,fsFromMark,0,*count,buffPtr,count) |
56 | : FSWrite(refNum,count,buffPtr); |
56 | : FSWrite(refNum,count,buffPtr); |
57 | //if(e)DebugStr("\pfswrite_large"); |
57 | //if(e)DebugStr("\pfswrite_large"); |
58 | return e; |
58 | return e; |
59 | } |
59 | } |
60 | 60 | ||
61 | OSErr getfpos_large(FILEREF refNum,FILEPOS *filePos){ |
61 | OSErr getfpos_large(FILEREF refNum,FILEPOS *filePos){ |
62 | OSErr e; |
62 | OSErr e; |
63 | if(has_forks){ |
63 | if(has_forks){ |
64 | e = FSGetForkPosition(refNum,filePos); |
64 | e = FSGetForkPosition(refNum,filePos); |
65 | }else{ |
65 | }else{ |
66 | long p; |
66 | long p; |
67 | e = GetFPos(refNum,&p); |
67 | e = GetFPos(refNum,&p); |
68 | if(!e) |
68 | if(!e) |
69 | *filePos = p; |
69 | *filePos = p; |
70 | } |
70 | } |
71 | //if(e)DebugStr("\pgetfpos_large"); |
71 | //if(e)DebugStr("\pgetfpos_large"); |
72 | return e; |
72 | return e; |
73 | } |
73 | } |
74 | 74 | ||
75 | OSErr setfpos_large(FILEREF refNum,short posMode,FILEPOS posOff){ |
75 | OSErr setfpos_large(FILEREF refNum,short posMode,FILEPOS posOff){ |
76 | OSErr e = has_forks ? FSSetForkPosition(refNum,posMode,posOff) |
76 | OSErr e = has_forks ? FSSetForkPosition(refNum,posMode,posOff) |
77 | : SetFPos(refNum,posMode,posOff); |
77 | : SetFPos(refNum,posMode,posOff); |
78 | //if(e)DebugStr("\psetfpos_large"); |
78 | //if(e)DebugStr("\psetfpos_large"); |
79 | return e; |
79 | return e; |
80 | } |
80 | } |
81 | 81 | ||
82 | OSErr geteof_large(FILEREF refNum,FILEPOS *logEOF){ |
82 | OSErr geteof_large(FILEREF refNum,FILEPOS *logEOF){ |
83 | OSErr e; |
83 | OSErr e; |
84 | if(has_forks){ |
84 | if(has_forks){ |
85 | e = FSGetForkSize(refNum,logEOF); |
85 | e = FSGetForkSize(refNum,logEOF); |
86 | }else{ |
86 | }else{ |
87 | FILEPOS p; |
87 | FILEPOS p; |
88 | e = GetEOF(refNum,&p); |
88 | e = GetEOF(refNum,&p); |
89 | if(!e) |
89 | if(!e) |
90 | *logEOF = p; |
90 | *logEOF = p; |
91 | } |
91 | } |
92 | //if(e)DebugStr("\pgeteof_large"); |
92 | //if(e)DebugStr("\pgeteof_large"); |
93 | return e; |
93 | return e; |
94 | } |
94 | } |
95 | 95 | ||
96 | /* |
96 | /* |
97 | OSErr recoverfss(short refnum,FSSpec *fss){ |
97 | OSErr recoverfss(short refnum,FSSpec *fss){ |
98 | OSErr e; |
98 | OSErr e; |
99 | FCBPBRec pb; |
99 | FCBPBRec pb; |
100 | Str31 fname; |
100 | Str31 fname; |
101 | FSSpec fss; |
101 | FSSpec fss; |
102 | FSRef ref; |
102 | FSRef ref; |
103 | HFSUniStr255 dfname; |
103 | HFSUniStr255 dfname; |
104 | 104 | ||
105 | pb.ioNamePtr = fname; |
105 | pb.ioNamePtr = fname; |
106 | pb.ioVRefNum = 0; |
106 | pb.ioVRefNum = 0; |
107 | pb.ioRefNum = refnum; |
107 | pb.ioRefNum = refnum; |
108 | pb.ioFCBIndx = 0; |
108 | pb.ioFCBIndx = 0; |
109 | 109 | ||
110 | if(!(e = PBGetFCBInfoAsync(&pb)) ) |
110 | if(!(e = PBGetFCBInfoAsync(&pb)) ) |
111 | e = FSMakeFSSpec(pb.ioFCBVRefNum,pb.ioFCBParID,fname,fss); |
111 | e = FSMakeFSSpec(pb.ioFCBVRefNum,pb.ioFCBParID,fname,fss); |
112 | 112 | ||
113 | return e; |
113 | return e; |
114 | } |
114 | } |
115 | OSErr reopenfork(short refnum,SInt8 perm,SInt16 *forkref){ |
115 | OSErr reopenfork(short refnum,SInt8 perm,SInt16 *forkref){ |
116 | OSErr e; |
116 | OSErr e; |
117 | FCBPBRec pb; |
117 | FCBPBRec pb; |
118 | Str31 fname; |
118 | Str31 fname; |
119 | FSSpec fss; |
119 | FSSpec fss; |
120 | FSRef ref; |
120 | FSRef ref; |
121 | HFSUniStr255 dfname; |
121 | HFSUniStr255 dfname; |
122 | 122 | ||
123 | pb.ioNamePtr = fname; |
123 | pb.ioNamePtr = fname; |
124 | pb.ioVRefNum = 0; |
124 | pb.ioVRefNum = 0; |
125 | pb.ioRefNum = refnum; |
125 | pb.ioRefNum = refnum; |
126 | pb.ioFCBIndx = 0; |
126 | pb.ioFCBIndx = 0; |
127 | 127 | ||
128 | if(!(e = PBGetFCBInfoAsync(&pb)) |
128 | if(!(e = PBGetFCBInfoAsync(&pb)) |
129 | && !(e = FSMakeFSSpec(pb.ioFCBVRefNum,pb.ioFCBParID,fname,&fss)) |
129 | && !(e = FSMakeFSSpec(pb.ioFCBVRefNum,pb.ioFCBParID,fname,&fss)) |
130 | && !(e = FSpMakeFSRef(&fss,&ref)) |
130 | && !(e = FSpMakeFSRef(&fss,&ref)) |
131 | && !(e = FSGetDataForkName(&dfname)) ) |
131 | && !(e = FSGetDataForkName(&dfname)) ) |
132 | e = FSOpenFork(&ref,dfname.length,dfname.unicode,perm,forkref); |
132 | e = FSOpenFork(&ref,dfname.length,dfname.unicode,perm,forkref); |
133 | 133 | ||
134 | return e; |
134 | return e; |
135 | } |
135 | } |
136 | */ |
136 | */ |
137 | 137 |