revert between 56095 -> 55830 in arch
[AROS.git] / rom / filesys / afs / os_unix_support.c
blobbf5d497222078bf6790dd3d7734cf9f1eee4434b
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * -date------ -name------------------- -description-----------------------------
8 * 02-jan-2008 [Tomasz Wiszkowski] added disk check option for broken disks
9 * 04-jan-2008 [Tomasz Wiszkowski] corrected tabulation
12 #include <stdarg.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <time.h>
18 #include "os.h"
19 #include "error.h"
20 #include "errstrings.h"
21 #include "volumes.h"
23 void showPtrArgsText(struct AFSBase *afsbase, const char *const string, va_list args)
25 vprintf(string, args);
26 printf("\n");
29 void showText(struct AFSBase *afsbase, const char *const string, ...)
31 va_list ap;
33 va_start(ap, string);
34 showPtrArgsText(afsbase, string, ap);
35 va_end(ap);
38 LONG showError(struct AFSBase *afsbase, ULONG error, ...) {
39 if (error==ERR_ALREADY_PRINTED)
40 return 0;
41 if (error>=ERR_UNKNOWN)
43 showText(afsbase, texts[ERR_UNKNOWN].text, error);
45 else
47 va_list ap;
48 va_start(ap, error);
49 showPtrArgsText(afsbase, texts[error].text, ap);
50 va_end(ap);
52 return 0;
55 LONG readDisk
57 struct AFSBase *afsbase,
58 struct Volume *volume,
59 ULONG start, ULONG count, APTR mem
62 struct IOHandle *ioh;
64 ioh = &volume->ioh;
65 if (fseek(ioh->fh, start*512, SEEK_SET) == 0)
67 if (fread(mem, 512, count, ioh->fh) == count)
69 return 0;
72 return 1;
75 LONG writeDisk
77 struct AFSBase *afsbase,
78 struct Volume *volume,
79 ULONG start, ULONG count, APTR mem
82 struct IOHandle *ioh;
84 ioh = &volume->ioh;
85 if (fseek(ioh->fh, start*512, SEEK_SET) == 0)
87 if (fwrite(mem, 512, count, ioh->fh) == count)
89 return 0;
92 return 1;
95 UBYTE diskPresent(struct AFSBase *afsbase, struct IOHandle *ioh) {
96 return ioh->fh ? 1 : 0;
99 BOOL diskWritable(struct AFSBase *afsbase, struct IOHandle *ioh)
101 return ioh->fh ? 1 : 0;
104 ULONG sectorSize(struct AFSBase *afsbase, struct IOHandle *ioh)
106 return 512;
109 void check64BitSupport(struct AFSBase *afsbase, struct Volume *volume) {
110 printf("%s: We just support 64Bit (or not ...)\n", __FUNCTION__);
113 struct IOHandle *openBlockDevice(struct AFSBase *afsbase, struct IOHandle *ioh) {
114 ioh->fh = fopen(ioh->blockdevice, "r+");
115 if (ioh->fh != NULL)
117 ioh->ioflags |= IOHF_DISK_IN;
118 return ioh;
120 else
121 showError(afsbase, ERR_DEVICE, ioh->blockdevice);
122 return NULL;
125 void closeBlockDevice(struct AFSBase *afsbase, struct IOHandle *ioh) {
126 fclose(ioh->fh);
127 ioh->fh = NULL;
128 ioh->ioflags &= ~IOHF_DISK_IN;
131 BOOL flush(struct AFSBase *afsbase, struct Volume *volume) {
132 flushCache(afsbase, volume);
133 clearCache(afsbase, volume->blockcache);
134 return DOSFALSE;
137 LONG attemptAddDosVolume(struct AFSBase *afsbase, struct Volume *volume) {
138 printf("%s: Don't know what to do here\n", __FUNCTION__);
139 return 0;
142 LONG osMediumInit(struct AFSBase *afsbase, struct Volume *volume, struct BlockCache *blockbuffer) {
143 printf("%s: Don't know what to do here\n", __FUNCTION__);
144 return 0;
147 void osMediumFree(struct AFSBase *afsbase, struct Volume *volume, LONG all) {
148 printf("%s: Don't know what to do here\n", __FUNCTION__);
151 void remDosNode(struct AFSBase *afsbase, struct DosList *dl)
153 printf("%s: Don't know what to do here\n", __FUNCTION__);
156 /********************************* OS Functions *****************************/
157 /* exec */
158 void *AllocMem(ULONG size, ULONG flags) {
159 void *mem;
161 if (flags & MEMF_CLEAR)
162 mem = calloc(1, size);
163 else
164 mem = malloc(size);
165 return mem;
168 void *AllocVec(ULONG size, ULONG flags) {
169 return AllocMem(size, flags);
172 void FreeMem(APTR mem, ULONG size) {
173 free(mem);
176 void FreeVec(APTR mem) {
177 free(mem);
180 void CopyMem(const void *src, APTR dst, ULONG size) {
181 memcpy(dst, src, size);
184 /* dos */
185 struct DateStamp *DateStamp(struct DateStamp *ds) {
186 time_t current;
187 time_t diff;
188 struct tm as={0, 0, 0, 1, 0, 78, -1, -1, -1};
190 time(&current);
191 diff = mktime(&as);
192 current -= diff; /* time since 00:00:00, Jan 1, 1978 */
193 ds->ds_Days = current/60/60/24;
194 current -= (ds->ds_Days*60*60*24);
195 ds->ds_Minute = current/60;
196 current -= (ds->ds_Minute*60);
197 ds->ds_Tick = current*50;
198 return ds;
201 CONST_STRPTR PathPart(CONST_STRPTR path)
203 CONST_STRPTR ptr;
205 /* '/' at the beginning of the string really is part of the path */
206 while (*path == '/')
207 ++path;
209 ptr = path;
211 while (*ptr)
213 if (*ptr == '/')
214 path = ptr;
215 else if (*ptr == ':')
216 path = ptr + 1;
218 ptr++;
221 return path;