revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / fs / ntfs / support.c
blob839e4509773d291169929abc1b0caf9365d872c0
1 /*
2 * ntfs.handler - New Technology FileSystem handler
4 * Copyright © 2012 The AROS Development Team
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
9 * $Id $
12 #include <exec/types.h>
13 #include <exec/execbase.h>
14 #include <dos/dosextens.h>
15 #include <dos/filehandler.h>
16 #include <devices/input.h>
17 #include <devices/inputevent.h>
18 #include <intuition/intuition.h>
19 #include <intuition/intuitionbase.h>
21 #include <proto/intuition.h>
22 #include <proto/exec.h>
23 #include <proto/alib.h>
25 #include <stdarg.h>
26 #include <string.h>
28 #include "ntfs_fs.h"
29 #include "support.h"
31 #include "debug.h"
33 void SendEvent(LONG event) {
34 struct IOStdReq *InputRequest;
35 struct MsgPort *InputPort;
36 struct InputEvent *ie;
38 if ((InputPort = (struct MsgPort*)CreateMsgPort())) {
40 if ((InputRequest = (struct IOStdReq*)CreateIORequest(InputPort, sizeof(struct IOStdReq)))) {
42 if (!OpenDevice("input.device", 0, (struct IORequest*)InputRequest, 0)) {
44 if ((ie = AllocVec(sizeof(struct InputEvent), MEMF_PUBLIC | MEMF_CLEAR))) {
45 ie->ie_Class = event;
46 InputRequest->io_Command = IND_WRITEEVENT;
47 InputRequest->io_Data = ie;
48 InputRequest->io_Length = sizeof(struct InputEvent);
50 DoIO((struct IORequest*)InputRequest);
52 FreeVec(ie);
54 CloseDevice((struct IORequest*)InputRequest);
56 DeleteIORequest((struct IORequest *)InputRequest);
58 DeleteMsgPort (InputPort);
62 /*-------------------------------------------------------------------------*/
64 int ilog2(ULONG data) {
65 int bitoffset = 31;
66 ULONG bitmask = 1 << bitoffset;
68 do {
69 if ((data & bitmask) != 0)
70 return bitoffset;
72 bitoffset--;
73 bitmask >>= 1;
74 } while (bitmask != 0);
76 return 0;
79 /*-----------------------------------------------------------------------*/
81 void ErrorMessage(CONST_STRPTR fmt, ...)
83 struct IntuitionBase *IntuitionBase;
85 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 36);
86 if (IntuitionBase) {
87 struct EasyStruct es = {
88 sizeof (struct EasyStruct),
90 "NTFS filesystem critical error",
91 NULL,
92 "Ok"
95 es.es_TextFormat = fmt;
96 AROS_SLOWSTACKFORMAT_PRE(fmt);
97 EasyRequestArgs(NULL, &es, NULL, AROS_SLOWSTACKFORMAT_ARG(fmt));
98 AROS_SLOWSTACKFORMAT_POST(fmt);
99 CloseLibrary((struct Library *)IntuitionBase);
103 void NTFS2DateStamp(UQUAD *NTFSTime, struct DateStamp *DS)
105 UQUAD adjustedtime;
106 UQUAD nttimeoffset;
107 struct timeval tval;
109 // nttimeoffset = (377 * 365 + 91) * 24 * 3600 * 10000000;
110 nttimeoffset = 0x02C51CD000ULL * 10000000;
112 adjustedtime = *NTFSTime - nttimeoffset;
114 D(bug("[NTFS]: %s: adjusted = %d, offset = %d\n", __PRETTY_FUNCTION__, adjustedtime, nttimeoffset));
116 tval.tv_secs = adjustedtime / 10000000;
117 tval.tv_micro = (adjustedtime / 10) % 1000000;
119 /* calculate days since 1978-01-01 (DOS epoch) */
120 DS->ds_Days = tval.tv_secs / (60 * 60 * 24);
122 /* minutes since midnight */
123 DS->ds_Minute = tval.tv_secs / 60 % (24 * 60);
125 /* 1/50 sec ticks since last minute */
126 DS->ds_Tick = 50 * (tval.tv_secs % 60) + (tval.tv_micro / 20000);
129 APTR _AllocVecPooled(APTR mem_pool, ULONG size)
131 APTR newvec = AllocVecPooled(mem_pool, size);
132 D(bug("**** [pool:0x%p] Allocated %d bytes @ 0x%p\n", mem_pool, size, newvec));
133 return newvec;
136 void _FreeVecPooled(APTR mem_pool, APTR vecaddr)
138 D(bug("**** [pool:0x%p] Freeing 0x%p\n", mem_pool, vecaddr));
139 FreeVecPooled(mem_pool, vecaddr);