2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * fs.c - Generic access to the file system modules.
28 * Copyright (c) 1999-2000 Apple Computer, Inc.
35 typedef long (* FSLoadFile
)(CICell ih
, char *filePath
);
36 typedef long (* FSGetDirEntry
)(CICell ih
, char *dirPath
,
37 long *dirIndex
, char **name
,
38 long *flags
, long *time
);
49 FSGetDirEntry getDirEntry
;
52 typedef struct PartInfo PartInfo
, *PartInfoPtr
;
54 #define kNumPartInfos (16)
55 static PartInfo gParts
[kNumPartInfos
];
56 static char gMakeDirSpec
[1024];
58 // Private function prototypes
59 long LookupPartition(char *devSpec
);
64 long LoadFile(char *fileSpec
)
69 long ret
, length
, partIndex
;
71 ret
= ConvertFileSpec(fileSpec
, devSpec
, &filePath
);
72 if ((ret
== -1) || (filePath
== NULL
)) return -1;
74 // Get the partition index for devSpec.
75 partIndex
= LookupPartition(devSpec
);
76 if (partIndex
== -1) return -1;
78 loadFile
= gParts
[partIndex
].loadFile
;
79 length
= loadFile(gParts
[partIndex
].partIH
, filePath
);
81 // if (length == 0) return -1;
86 long GetFileInfo(char *dirSpec
, char *name
, long *flags
, long *time
)
96 for (idx
= len
; idx
&& (name
[idx
] != '\\'); idx
--) {}
98 strncpy(gMakeDirSpec
, name
, idx
);
100 dirSpec
= gMakeDirSpec
;
104 ret
= GetDirEntry(dirSpec
, &index
, &curName
, flags
, time
);
105 if (ret
== -1) break;
107 if (!strcmp(name
, curName
)) break;
113 long GetDirEntry(char *dirSpec
, long *dirIndex
, char **name
,
114 long *flags
, long *time
)
118 FSGetDirEntry getDirEntry
;
121 ret
= ConvertFileSpec(dirSpec
, devSpec
, &dirPath
);
122 if ((ret
== -1) || (dirPath
== NULL
)) return -1;
124 // Get the partition index for devSpec.
125 partIndex
= LookupPartition(devSpec
);
126 if (partIndex
== -1) return -1;
128 getDirEntry
= gParts
[partIndex
].getDirEntry
;
129 ret
= getDirEntry(gParts
[partIndex
].partIH
, dirPath
,
130 dirIndex
, name
, flags
, time
);
135 long DumpDir(char *dirSpec
)
137 long ret
, flags
, time
, index
= 0;
140 printf("DumpDir on [%s]\n", dirSpec
);
143 ret
= GetDirEntry(dirSpec
, &index
, &name
, &flags
, &time
);
144 if (ret
== -1) break;
146 printf("%x %x [%s]\n", flags
, time
, name
);
155 long LookupPartition(char *devSpec
)
158 long partIndex
, partType
;
161 // See if the devSpec has already been opened.
162 for (partIndex
= 0; partIndex
< kNumPartInfos
; partIndex
++) {
163 if (!strcmp(gParts
[partIndex
].partName
, devSpec
)) break;
166 // If it has not been opened, do so now.
167 if (partIndex
== kNumPartInfos
) {
169 for (partIndex
= 0; partIndex
< kNumPartInfos
; partIndex
++) {
170 if (gParts
[partIndex
].partIH
== 0) break;
172 // No free slots, so return error.
173 if (partIndex
== kNumPartInfos
) return -1;
175 deviceType
= GetDeviceType(devSpec
);
176 switch (deviceType
) {
177 case kNetworkDeviceType
:
178 partIH
= NetInitPartition(devSpec
);
179 if (partIH
== 0) return -1;
183 case kBlockDeviceType
:
184 printf("Opening partition [%s]...\n", devSpec
);
185 partIH
= Open(devSpec
);
187 printf("Failed to open partition [%s].\n", devSpec
);
191 // Find out what kind of partition it is.
192 if (HFSInitPartition(partIH
) != -1) partType
= kPartHFS
;
193 else if (UFSInitPartition(partIH
) != -1) partType
= kPartUFS
;
194 else if (Ext2InitPartition(partIH
) != -1) partType
= kPartExt2
;
202 gParts
[partIndex
].partIH
= partIH
;
203 gParts
[partIndex
].partType
= partType
;
204 strcpy(gParts
[partIndex
].partName
, devSpec
);
208 gParts
[partIndex
].loadFile
= NetLoadFile
;
209 gParts
[partIndex
].getDirEntry
= NetGetDirEntry
;
213 gParts
[partIndex
].loadFile
= HFSLoadFile
;
214 gParts
[partIndex
].getDirEntry
= HFSGetDirEntry
;
218 gParts
[partIndex
].loadFile
= UFSLoadFile
;
219 gParts
[partIndex
].getDirEntry
= UFSGetDirEntry
;
223 gParts
[partIndex
].loadFile
= Ext2LoadFile
;
224 gParts
[partIndex
].getDirEntry
= Ext2GetDirEntry
;