Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / fs / hfs / low.c
1 /*
2  * libhfs - library for reading and writing Macintosh HFS volumes
3  * Copyright (C) 1996-1998, 2001 Robert Leslie
4  *
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
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
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
17  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  * $Id: low.c,v 1.8 1998/11/02 22:09:03 rob Exp $
21  */
22
23 #include "config.h"
24 #include "libhfs.h"
25 #include "low.h"
26 #include "data.h"
27 #include "block.h"
28 #include "file.h"
29
30 /*
31  * NAME:        low->getpmentry()
32  * DESCRIPTION: read a partition map entry
33  */
34 int l_getpmentry(hfsvol *vol, Partition *map, unsigned long bnum)
35 {
36   block b;
37   const byte *ptr = b;
38   int i;
39
40   if (b_readpb(vol, bnum, &b, 1) == -1)
41     goto fail;
42
43   d_fetchsw(&ptr, &map->pmSig);
44   d_fetchsw(&ptr, &map->pmSigPad);
45   d_fetchsl(&ptr, &map->pmMapBlkCnt);
46   d_fetchsl(&ptr, &map->pmPyPartStart);
47   d_fetchsl(&ptr, &map->pmPartBlkCnt);
48
49   strncpy((char *) map->pmPartName, (const char *) ptr, 32);
50   map->pmPartName[32] = 0;
51   ptr += 32;
52
53   strncpy((char *) map->pmParType, (const char *) ptr, 32);
54   map->pmParType[32] = 0;
55   ptr += 32;
56
57   d_fetchsl(&ptr, &map->pmLgDataStart);
58   d_fetchsl(&ptr, &map->pmDataCnt);
59   d_fetchsl(&ptr, &map->pmPartStatus);
60   d_fetchsl(&ptr, &map->pmLgBootStart);
61   d_fetchsl(&ptr, &map->pmBootSize);
62   d_fetchsl(&ptr, &map->pmBootAddr);
63   d_fetchsl(&ptr, &map->pmBootAddr2);
64   d_fetchsl(&ptr, &map->pmBootEntry);
65   d_fetchsl(&ptr, &map->pmBootEntry2);
66   d_fetchsl(&ptr, &map->pmBootCksum);
67
68   strncpy((char *) map->pmProcessor, (const char *) ptr, 16);
69   map->pmProcessor[16] = 0;
70   ptr += 16;
71
72   for (i = 0; i < 188; ++i)
73     d_fetchsw(&ptr, &map->pmPad[i]);
74
75   ASSERT(ptr - b == HFS_BLOCKSZ);
76
77   return 0;
78
79 fail:
80   return -1;
81 }
82
83
84 /*
85  * NAME:        low->getmdb()
86  * DESCRIPTION: read a master directory block
87  */
88 int l_getmdb(hfsvol *vol, MDB *mdb, int backup)
89 {
90   block b;
91   const byte *ptr = b;
92   int i;
93
94   if (b_readlb(vol, backup ? vol->vlen - 2 : 2, &b) == -1)
95     goto fail;
96
97   d_fetchsw(&ptr, &mdb->drSigWord);
98   d_fetchsl(&ptr, &mdb->drCrDate);
99   d_fetchsl(&ptr, &mdb->drLsMod);
100   d_fetchsw(&ptr, &mdb->drAtrb);
101   d_fetchuw(&ptr, &mdb->drNmFls);
102   d_fetchuw(&ptr, &mdb->drVBMSt);
103   d_fetchuw(&ptr, &mdb->drAllocPtr);
104   d_fetchuw(&ptr, &mdb->drNmAlBlks);
105   d_fetchul(&ptr, &mdb->drAlBlkSiz);
106   d_fetchul(&ptr, &mdb->drClpSiz);
107   d_fetchuw(&ptr, &mdb->drAlBlSt);
108   d_fetchsl(&ptr, &mdb->drNxtCNID);
109   d_fetchuw(&ptr, &mdb->drFreeBks);
110
111   d_fetchstr(&ptr, mdb->drVN, sizeof(mdb->drVN));
112
113   ASSERT(ptr - b == 64);
114
115   d_fetchsl(&ptr, &mdb->drVolBkUp);
116   d_fetchsw(&ptr, &mdb->drVSeqNum);
117   d_fetchul(&ptr, &mdb->drWrCnt);
118   d_fetchul(&ptr, &mdb->drXTClpSiz);
119   d_fetchul(&ptr, &mdb->drCTClpSiz);
120   d_fetchuw(&ptr, &mdb->drNmRtDirs);
121   d_fetchul(&ptr, &mdb->drFilCnt);
122   d_fetchul(&ptr, &mdb->drDirCnt);
123
124   for (i = 0; i < 8; ++i)
125     d_fetchsl(&ptr, &mdb->drFndrInfo[i]);
126
127   ASSERT(ptr - b == 124);
128
129   d_fetchuw(&ptr, &mdb->drEmbedSigWord);
130   d_fetchuw(&ptr, &mdb->drEmbedExtent.xdrStABN);
131   d_fetchuw(&ptr, &mdb->drEmbedExtent.xdrNumABlks);
132
133   d_fetchul(&ptr, &mdb->drXTFlSize);
134
135   for (i = 0; i < 3; ++i)
136     {
137       d_fetchuw(&ptr, &mdb->drXTExtRec[i].xdrStABN);
138       d_fetchuw(&ptr, &mdb->drXTExtRec[i].xdrNumABlks);
139     }
140
141   ASSERT(ptr - b == 146);
142
143   d_fetchul(&ptr, &mdb->drCTFlSize);
144
145   for (i = 0; i < 3; ++i)
146     {
147       d_fetchuw(&ptr, &mdb->drCTExtRec[i].xdrStABN);
148       d_fetchuw(&ptr, &mdb->drCTExtRec[i].xdrNumABlks);
149     }
150
151   ASSERT(ptr - b == 162);
152
153   return 0;
154
155 fail:
156   return -1;
157 }