1f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle/*
2f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * Copyright (C) 2010 The Android Open Source Project
3f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle *
4f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * Licensed under the Apache License, Version 2.0 (the "License");
5f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * you may not use this file except in compliance with the License.
6f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * You may obtain a copy of the License at
7f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle *
8f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle *      http://www.apache.org/licenses/LICENSE-2.0
9f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle *
10f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * Unless required by applicable law or agreed to in writing, software
11f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * distributed under the License is distributed on an "AS IS" BASIS,
12f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * See the License for the specific language governing permissions and
14f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle * limitations under the License.
15f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle */
16f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
170cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle#ifndef FATBLOCK_H
180cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle#define FATBLOCK_H
19f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
20f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle#include <stdint.h>
21f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle#include <sys/types.h>
22f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
23f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle#include "fdpool.h"
240cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
250cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttletypedef uint64_t offset_t;
260cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
270cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttletypedef enum {
280cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	EXTENT_TYPE_BOOT,
290cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	EXTENT_TYPE_INFO,
300cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	EXTENT_TYPE_FAT,
310cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	EXTENT_TYPE_FILE,
320cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	EXTENT_TYPE_DIR
330cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle} extent_type;
340cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
350cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttlestruct extent {
360cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	offset_t start;
370cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	offset_t len;
380cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	extent_type type;
390cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
400cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle	struct extent *next;
410cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle};
42f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
43f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttlestruct file {
44f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	struct extent extent;
45f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
46f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	char *path;
47f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	uint32_t size;
48f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
49f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	dev_t dev;
50f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	ino_t ino;
51f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	time_t mtime;
52f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
53f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	struct pooled_fd pfd;
54f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle};
55f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
56f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttlestruct dir {
57f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	struct extent extent;
58f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
59f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	char *path;
60f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	uint32_t size;
61f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
62f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle	struct fat_dirent *entries;
63f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle};
64f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle
650cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttlestruct fs;
660cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
670cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttleint import_tree(struct fs *fs, char *path);
680cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttleint fs_read(struct fs *fs, char *buf, offset_t start, offset_t len);
690cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
700cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle#define MALLOC_FAIL (-41)    /* memory allocation failed somewhere. */
710cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle#define SKY_IS_FALLING (-42) /* One of the files changed out from under us. */
720cb61411eadd92b7202e045c1c9ec8df7fb636feThomas Tuttle
73f79b2dff1024db4f6326f3422236bed169dd902fThomas Tuttle#endif
74