Fixed out-by-one error in previous commit.
[AROS.git] / workbench / fs / ntfs / support.c
blob866481e84733138b1a2c99e0d70dfca5baac89c7
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>
24 #include <stdarg.h>
25 #include <string.h>
27 #include "ntfs_fs.h"
29 #include "debug.h"
31 void SendEvent(LONG event) {
32 struct IOStdReq *InputRequest;
33 struct MsgPort *InputPort;
34 struct InputEvent *ie;
36 if ((InputPort = (struct MsgPort*)CreateMsgPort())) {
38 if ((InputRequest = (struct IOStdReq*)CreateIORequest(InputPort, sizeof(struct IOStdReq)))) {
40 if (!OpenDevice("input.device", 0, (struct IORequest*)InputRequest, 0)) {
42 if ((ie = AllocVec(sizeof(struct InputEvent), MEMF_PUBLIC | MEMF_CLEAR))) {
43 ie->ie_Class = event;
44 InputRequest->io_Command = IND_WRITEEVENT;
45 InputRequest->io_Data = ie;
46 InputRequest->io_Length = sizeof(struct InputEvent);
48 DoIO((struct IORequest*)InputRequest);
50 FreeVec(ie);
52 CloseDevice((struct IORequest*)InputRequest);
54 DeleteIORequest((struct IORequest *)InputRequest);
56 DeleteMsgPort (InputPort);
60 /*-------------------------------------------------------------------------*/
62 int ilog2(ULONG data) {
63 int bitoffset = 31;
64 ULONG bitmask = 1 << bitoffset;
66 do {
67 if ((data & bitmask) != 0)
68 return bitoffset;
70 bitoffset--;
71 bitmask >>= 1;
72 } while (bitmask != 0);
74 return 0;
77 /*-----------------------------------------------------------------------*/
79 void ErrorMessageArgs(char *fmt, IPTR *ap)
81 struct IntuitionBase *IntuitionBase;
83 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 36);
84 if (IntuitionBase) {
85 struct EasyStruct es = {
86 sizeof (struct EasyStruct),
88 "NTFS filesystem critical error",
89 NULL,
90 "Ok"
93 es.es_TextFormat = fmt;
94 EasyRequestArgs(NULL, &es, NULL, ap);
95 CloseLibrary((struct Library *)IntuitionBase);
99 void NTFS2DateStamp(UQUAD *NTFSTime, struct DateStamp *DS)
101 UQUAD adjustedtime;
102 UQUAD nttimeoffset;
103 struct timeval tval;
105 // nttimeoffset = (377 * 365 + 91) * 24 * 3600 * 10000000;
106 nttimeoffset = 0x02C51CD000ULL * 10000000;
108 adjustedtime = *NTFSTime - nttimeoffset;
110 D(bug("[NTFS]: %s: adjusted = %d, offset = %d\n", __PRETTY_FUNCTION__, adjustedtime, nttimeoffset));
112 tval.tv_secs = adjustedtime / 10000000;
113 tval.tv_micro = (adjustedtime / 10) % 1000000;
115 /* calculate days since 1978-01-01 (DOS epoch) */
116 DS->ds_Days = tval.tv_secs / (60 * 60 * 24);
118 /* minutes since midnight */
119 DS->ds_Minute = tval.tv_secs / 60 % (24 * 60);
121 /* 1/50 sec ticks since last minute */
122 DS->ds_Tick = 50 * (tval.tv_secs % 60) + (tval.tv_micro / 20000);
125 APTR _AllocVecPooled(APTR mem_pool, ULONG size)
127 APTR newvec = AllocVecPooled(mem_pool, size);
128 D(bug("**** [pool:0x%p] Allocated %d bytes @ 0x%p\n", mem_pool, size, newvec));
129 return newvec;
132 void _FreeVecPooled(APTR mem_pool, APTR vecaddr)
134 D(bug("**** [pool:0x%p] Freeing 0x%p\n", mem_pool, vecaddr));
135 FreeVecPooled(mem_pool, vecaddr);