revert between 56095 -> 55830 in arch
[AROS.git] / arch / ppc-sam440 / boot / parthenope / src / ext2.c
blob66f1a279bc5900e4e3777e3b54ee1d544704eb44
1 /* ext2.c */
3 /* <project_name> -- <project_description>
5 * Copyright (C) 2006 - 2007
6 * Giuseppe Coviello <cjg@cruxppc.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "context.h"
24 #include "rdb.h"
25 #include "ext2.h"
27 typedef struct {
28 int (*load_file) (void *this, char *filename, void *buffer);
29 void (*destroy) (void *this);
30 int discno;
31 int partno;
32 unsigned part_length;
33 } ext2_boot_dev_t;
35 static int load_file(ext2_boot_dev_t * this, char *filename, void *buffer)
37 int filelen;
39 if (!ext2fs_mount(this->part_length)) {
40 printf("** Bad ext2 partition or disk - %d:%d **\n",
41 this->discno, this->partno);
42 ext2fs_close();
43 return -4;
46 filelen = ext2fs_open(filename);
47 if (filelen < 0) {
48 printf("** File not found %s\n", filename);
49 ext2fs_close();
50 return -5;
53 if (ext2fs_read((char *)buffer, filelen) != filelen) {
54 printf("\n** Unable to read \"%s\" from %d:%d **\n",
55 filename, this->discno, this->partno);
56 ext2fs_close();
57 return -6;
60 ext2fs_close();
62 return filelen;
65 static int destroy(ext2_boot_dev_t * this)
67 free(this);
68 return 0;
71 boot_dev_t *ext2_create(struct RdbPartition *partition)
73 ext2_boot_dev_t *boot;
74 unsigned part_length;
76 if ((part_length = ext2fs_set_blk_dev_full(partition->dev_desc,
77 partition->info)) == 0) {
78 printf("** Bad partition - %d:%d **\n", partition->disk,
79 partition->partition);
80 ext2fs_close();
81 return NULL;
84 if (!ext2fs_mount(part_length)) {
85 printf("** Bad ext2 partition or disk - %d:%d **\n",
86 partition->disk, partition->partition);
87 ext2fs_close();
88 return NULL;
91 ext2fs_close();
93 boot = malloc(sizeof(ext2_boot_dev_t));
94 boot->load_file = (int (*)(void *, char *, void *))load_file;
95 boot->destroy = (void (*)(void *))destroy;
96 boot->discno = partition->disk;
97 boot->partno = partition->partition;
98 boot->part_length = part_length;
100 return (boot_dev_t *) boot;