Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / fs / fat / support.c
blob297f1091e4d23261da963575327abe98f6e3dc96
1 /*
2 * fat.handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007-2008 The AROS Development Team
7 * This program is free software; you can redistribute it and/or modify it
8 * under the same terms as AROS itself.
10 * $Id$
13 #include <exec/types.h>
14 #include <exec/execbase.h>
15 #include <dos/dosextens.h>
16 #include <dos/filehandler.h>
17 #include <devices/input.h>
18 #include <devices/inputevent.h>
19 #include <intuition/intuition.h>
20 #include <intuition/intuitionbase.h>
22 #include <proto/intuition.h>
23 #include <proto/exec.h>
25 #include <stdarg.h>
26 #include <string.h>
28 #include "fat_fs.h"
30 #ifdef __PPC__
31 #define ARGS(ap) ap->overflow_arg_area
32 #else
33 #define ARGS(ap) (ULONG *)ap
34 #endif
36 void SendEvent(LONG event) {
37 struct IOStdReq *InputRequest;
38 struct MsgPort *InputPort;
39 struct InputEvent *ie;
41 if ((InputPort = (struct MsgPort*)CreateMsgPort())) {
43 if ((InputRequest = (struct IOStdReq*)CreateIORequest(InputPort, sizeof(struct IOStdReq)))) {
45 if (!OpenDevice("input.device", 0, (struct IORequest*)InputRequest, 0)) {
47 if ((ie = AllocVec(sizeof(struct InputEvent), MEMF_PUBLIC | MEMF_CLEAR))) {
48 ie->ie_Class = event;
49 InputRequest->io_Command = IND_WRITEEVENT;
50 InputRequest->io_Data = ie;
51 InputRequest->io_Length = sizeof(struct InputEvent);
53 DoIO((struct IORequest*)InputRequest);
55 FreeVec(ie);
57 CloseDevice((struct IORequest*)InputRequest);
59 DeleteIORequest((struct IORequest *)InputRequest);
61 DeleteMsgPort (InputPort);
65 /*-------------------------------------------------------------------------*/
67 int ilog2(ULONG data) {
68 int bitoffset = 31;
69 ULONG bitmask = 1 << bitoffset;
71 do {
72 if ((data & bitmask) != 0)
73 return bitoffset;
75 bitoffset--;
76 bitmask >>= 1;
77 } while (bitmask != 0);
79 return 0;
82 /*-----------------------------------------------------------------------*/
84 void ErrorMessage(char *fmt, ...)
86 va_list ap;
87 struct IntuitionBase *IntuitionBase;
89 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 36);
90 if (IntuitionBase) {
91 struct EasyStruct es = {
92 sizeof (struct EasyStruct),
94 "FAT filesystem critical error",
95 NULL,
96 "Ok"
98 va_start(ap, fmt);
100 es.es_TextFormat = fmt;
101 EasyRequestArgs(NULL, &es, NULL, ARGS(ap));
102 va_end(ap);
103 CloseLibrary((struct Library *)IntuitionBase);