2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * fs.c - Generic access to the file system modules.
25 * Copyright (c) 1999-2000 Apple Computer, Inc.
32 typedef long (* FSLoadFile
)(CICell ih
, char *filePath
);
33 typedef long (* FSGetDirEntry
)(CICell ih
, char *dirPath
,
34 long *dirIndex
, char **name
,
35 long *flags
, long *time
);
46 FSGetDirEntry getDirEntry
;
49 typedef struct PartInfo PartInfo
, *PartInfoPtr
;
51 #define kNumPartInfos (16)
52 static PartInfo gParts
[kNumPartInfos
];
54 // Private function prototypes
55 long LookupPartition(char *devSpec
);
60 long LoadFile(char *fileSpec
)
65 long ret
, length
, partIndex
;
67 ret
= ConvertFileSpec(fileSpec
, devSpec
, &filePath
);
68 if ((ret
== -1) || (filePath
== NULL
)) return -1;
70 // Get the partition index for devSpec.
71 partIndex
= LookupPartition(devSpec
);
72 if (partIndex
== -1) return -1;
74 loadFile
= gParts
[partIndex
].loadFile
;
75 length
= loadFile(gParts
[partIndex
].partIH
, filePath
);
77 // if (length == 0) return -1;
82 long GetFileInfo(char *dirSpec
, char *name
, long *flags
, long *time
)
88 ret
= GetDirEntry(dirSpec
, &index
, &curName
, flags
, time
);
91 if (!strcmp(name
, curName
)) break;
97 long GetDirEntry(char *dirSpec
, long *dirIndex
, char **name
,
98 long *flags
, long *time
)
102 FSGetDirEntry getDirEntry
;
105 ret
= ConvertFileSpec(dirSpec
, devSpec
, &dirPath
);
106 if ((ret
== -1) || (dirPath
== NULL
)) return -1;
108 // Get the partition index for devSpec.
109 partIndex
= LookupPartition(devSpec
);
110 if (partIndex
== -1) return -1;
112 getDirEntry
= gParts
[partIndex
].getDirEntry
;
113 ret
= getDirEntry(gParts
[partIndex
].partIH
, dirPath
,
114 dirIndex
, name
, flags
, time
);
119 long DumpDir(char *dirSpec
)
121 long ret
, flags
, time
, index
= 0;
124 printf("DumpDir on [%s]\n", dirSpec
);
127 ret
= GetDirEntry(dirSpec
, &index
, &name
, &flags
, &time
);
128 if (ret
== -1) break;
130 printf("%x %x [%s]\n", flags
, time
, name
);
139 long LookupPartition(char *devSpec
)
142 long partIndex
, partType
;
145 // See if the devSpec has already been opened.
146 for (partIndex
= 0; partIndex
< kNumPartInfos
; partIndex
++) {
147 if (!strcmp(gParts
[partIndex
].partName
, devSpec
)) break;
150 // If it has not been opened, do so now.
151 if (partIndex
== kNumPartInfos
) {
153 for (partIndex
= 0; partIndex
< kNumPartInfos
; partIndex
++) {
154 if (gParts
[partIndex
].partIH
== 0) break;
156 // No free slots, so return error.
157 if (partIndex
== kNumPartInfos
) return -1;
159 deviceType
= GetDeviceType(devSpec
);
160 switch (deviceType
) {
161 case kNetworkDeviceType
:
162 partIH
= NetInitPartition(devSpec
);
163 if (partIH
== 0) return -1;
167 case kBlockDeviceType
:
168 printf("Opening partition [%s]...\n", devSpec
);
169 partIH
= Open(devSpec
);
171 printf("Failed to open partition [%s].\n", devSpec
);
175 // Find out what kind of partition it is.
176 if (HFSInitPartition(partIH
) != -1) partType
= kPartHFS
;
177 else if (UFSInitPartition(partIH
) != -1) partType
= kPartUFS
;
178 else if (Ext2InitPartition(partIH
) != -1) partType
= kPartExt2
;
186 gParts
[partIndex
].partIH
= partIH
;
187 gParts
[partIndex
].partType
= partType
;
188 strcpy(gParts
[partIndex
].partName
, devSpec
);
192 gParts
[partIndex
].loadFile
= NetLoadFile
;
193 gParts
[partIndex
].getDirEntry
= NetGetDirEntry
;
197 gParts
[partIndex
].loadFile
= HFSLoadFile
;
198 gParts
[partIndex
].getDirEntry
= HFSGetDirEntry
;
202 gParts
[partIndex
].loadFile
= UFSLoadFile
;
203 gParts
[partIndex
].getDirEntry
= UFSGetDirEntry
;
207 gParts
[partIndex
].loadFile
= Ext2LoadFile
;
208 gParts
[partIndex
].getDirEntry
= Ext2GetDirEntry
;