Moved tests into appropriate subdirs.
[AROS.git] / workbench / fs / ntfs / timer.c
blob7e81d683b59a45078815086f0ec8fb6f1fa9113e
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 <devices/timer.h>
13 #include <dos/dos.h>
14 #include <proto/exec.h>
16 #include "ntfs_fs.h"
17 #include "ntfs_protos.h"
19 #include "debug.h"
21 LONG InitTimer(void)
23 LONG err = ERROR_NO_FREE_STORE;
25 D(bug("[NTFS]: %s()\n", __PRETTY_FUNCTION__));
27 glob->timerport = CreateMsgPort();
28 if (glob->timerport) {
29 glob->timereq = (struct timerequest *)CreateIORequest(glob->timerport,
30 sizeof(struct timerequest));
31 if (glob->timereq) {
32 if (OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)glob->timereq, 0))
33 err = ERROR_DEVICE_NOT_MOUNTED;
34 else {
35 glob->timer_active = 0;
36 glob->restart_timer = 1;
37 D(bug("[NTFS] %s: Timer ready\n", __PRETTY_FUNCTION__));
38 return 0;
40 DeleteIORequest((struct IORequest *)glob->timereq);
42 DeleteMsgPort(glob->timerport);
44 return err;
47 void CleanupTimer(void)
49 D(bug("[NTFS]: %s()\n", __PRETTY_FUNCTION__));
51 D(bug("[NTFS] %s: Cleaning up timer\n", __PRETTY_FUNCTION__));
52 if (glob->timer_active) {
53 D(bug("[NTFS] %s: Terminating active request\n", __PRETTY_FUNCTION__));
54 AbortIO((struct IORequest *)glob->timereq);
55 WaitIO((struct IORequest *)glob->timereq);
57 CloseDevice((struct IORequest *)glob->timereq);
58 DeleteIORequest((struct IORequest *)glob->timereq);
59 DeleteMsgPort(glob->timerport);
62 void RestartTimer(void)
64 D(bug("[NTFS]: %s()\n", __PRETTY_FUNCTION__));
66 if (glob->timer_active) {
67 D(bug("[NTFS] %s: Queuing timer restart\n", __PRETTY_FUNCTION__));
68 glob->restart_timer = 1;
69 } else {
70 D(bug("[NTFS] %s: Immediate timer restart\n", __PRETTY_FUNCTION__));
71 glob->timereq->tr_node.io_Command = TR_ADDREQUEST;
72 glob->timereq->tr_time.tv_secs = 1;
73 glob->timereq->tr_time.tv_micro = 0;
74 SendIO((struct IORequest *)glob->timereq);
75 glob->timer_active = 1;
79 void HandleTimer(void)
81 D(bug("[NTFS]: %s()\n", __PRETTY_FUNCTION__));
83 WaitIO((struct IORequest *)glob->timereq);
84 glob->timer_active = 0;
85 if (glob->restart_timer) {
86 D(bug("[NTFS] %s: Timer restart queued\n", __PRETTY_FUNCTION__));
87 glob->restart_timer = 0;
88 RestartTimer();
89 } else {
90 D(bug("[NTFS] %s: Updating disk\n", __PRETTY_FUNCTION__));
91 UpdateDisk();