Chameleon

Chameleon Svn Source Tree

Root/branches/Bungo/i386/libsaio/ext2fs.c

1/*
2 * ext2fs.c
3 *
4 *
5 * Created by mackerintel on 1/26/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
7 *
8 */
9
10#include "libsaio.h"
11#include "sl.h"
12#include "ext2fs.h"
13
14#define EX2ProbeSize2048
15
16bool EX2Probe (const void *buf)
17{
18return (OSReadLittleInt16(buf+0x438,0)==0xEF53);
19}
20
21void EX2GetDescription(CICell ih, char *str, long strMaxLen)
22{
23char * buf=malloc (EX2ProbeSize);
24str[0]=0;
25if (!buf) {
26return;
27}
28Seek(ih, 0);
29Read(ih, (long)buf, EX2ProbeSize);
30if (!EX2Probe (buf)) {
31free (buf);
32return;
33}
34if (OSReadLittleInt32 (buf+0x44c,0)<1) {
35free (buf);
36return;
37}
38str[strMaxLen]=0;
39strncpy (str, buf+0x478, MIN(strMaxLen, 16));
40//verbose("EXT2: label=%s\n", str);
41free (buf);
42}
43
44long EX2GetUUID(CICell ih, char *uuidStr)
45{
46uint8_t *b, *buf=malloc (EX2ProbeSize);
47if (!buf) {
48return -1;
49}
50Seek(ih, 0);
51Read(ih, (long)buf, EX2ProbeSize);
52if (!EX2Probe (buf)) {
53free (buf);
54return -1;
55}
56if (OSReadLittleInt32 (buf+0x44c,0)<1) {
57free (buf);
58return -1;
59}
60b=buf+0x468;
61sprintf(uuidStr,
62"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
63b[0], b[1], b[2], b[3],
64b[4], b[5],
65b[6], b[7],
66b[8], b[9],
67b[10], b[11], b[12], b[13], b[14], b[15]);
68free (buf);
69return 0;
70}
71

Archive Download this file

Revision: HEAD