Reapplication of sonic's patches originally done in r29201 and r29210:
[tangerine.git] / rom / devs / filesys / afs / os_unix_support.c
blob76c2f6178989480b002b8bf117d0a3d33d2bb389
1 /*
2 Copyright © 1995-2005, 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>
17 #include "os.h"
18 #include "error.h"
19 #include "volumes.h"
21 void showPtrArgsText(struct AFSBase *afsbase, char *string, va_list args) {
22 vprintf(string, args);
23 printf("\n");
26 void showText(struct AFSBase *afsbase, char *string, ...) {
27 va_list ap;
29 va_start(ap, string);
30 showPtrArgsText(afsbase, string, ap);
31 va_end(ap);
34 LONG showError(struct AFSBase *afsbase, ULONG error, ...) {
35 char *texts[]={0,
36 "No ioport",
37 "Couldn't open device %s",
38 "Couldn't add disk as dosentry",
39 "Disk is not validated!\n",
40 "Wrong data block %ld",
41 "Wrong checksum on block %ld",
42 "Missing some more bitmap blocks",
43 "Wrong blocktype on block %ld",
44 "Read/Write Error (%ld)",
45 "*** This may be a non-AFS disk. ***\n"
46 "Any attempt to fix it in this case may render the original\n"
47 "file system invalid, and its contents unrecoverable.\n\n"
48 "Please select what to do.",
49 "Block %lu used twice",
50 "Block %lu is located outside volume scope\nand will be removed.",
51 "Repairing disk structure will lead to data loss.\n"
52 "It's best to make a backup before proceeding.\n\n"
53 "Please select what to do.",
55 "Unknown error"
58 if (error==ERR_ALREADY_PRINTED)
59 return 0;
60 if (error>=ERR_UNKNOWN)
62 showText(afsbase, texts[ERR_UNKNOWN], error);
64 else
66 va_list ap;
67 va_start(ap, error);
68 showPtrArgsText(afsbase, texts[error], ap);
69 va_end(ap);
71 return 0;
74 LONG readDisk
76 struct AFSBase *afsbase,
77 struct Volume *volume,
78 ULONG start, ULONG count, APTR mem
81 struct IOHandle *ioh;
83 ioh = &volume->ioh;
84 if (fseek(ioh->fh, start*512, SEEK_SET) == 0)
86 if (fread(mem, 512, count, ioh->fh) == count)
88 return 0;
91 return 1;
94 LONG writeDisk
96 struct AFSBase *afsbase,
97 struct Volume *volume,
98 ULONG start, ULONG count, APTR mem
101 struct IOHandle *ioh;
103 ioh = &volume->ioh;
104 if (fseek(ioh->fh, start*512, SEEK_SET) == 0)
106 if (fwrite(mem, 512, count, ioh->fh) == count)
108 return 0;
111 return 1;
114 UBYTE diskPresent(struct AFSBase *afsbase, struct IOHandle *ioh) {
115 return ioh->fh ? 1 : 0;
118 void check64BitSupport(struct AFSBase *afsbase, struct Volume *volume) {
119 printf("%s: We just support 64Bit (or not ...)\n", __FUNCTION__);
122 struct IOHandle *openBlockDevice(struct AFSBase *afsbase, struct IOHandle *ioh) {
123 ioh->fh = fopen(ioh->blockdevice, "r+");
124 if (ioh->fh != NULL)
126 ioh->ioflags |= IOHF_DISK_IN;
127 return ioh;
129 else
130 showError(afsbase, ERR_DEVICE, ioh->blockdevice);
131 return NULL;
134 void closeBlockDevice(struct AFSBase *afsbase, struct IOHandle *ioh) {
135 fclose(ioh->fh);
136 ioh->fh = NULL;
137 ioh->ioflags &= ~IOHF_DISK_IN;
140 BOOL flush(struct AFSBase *afsbase, struct Volume *volume) {
141 flushCache(afsbase, volume);
142 clearCache(afsbase, volume->blockcache);
143 return DOSFALSE;
146 LONG osMediumInit(struct AFSBase *afsbase, struct Volume *volume, struct BlockCache *blockbuffer) {
147 printf("%s: Don't know what to do here\n", __FUNCTION__);
148 return 0;
151 void osMediumFree(struct AFSBase *afsbase, struct Volume *volume, LONG all) {
152 printf("%s: Don't know what to do here\n", __FUNCTION__);
155 void remDosNode(struct AFSBase *afsbase, struct DosList *dl)
157 printf("%s: Don't know what to do here\n", __FUNCTION__);
160 /********************************* OS Functions *****************************/
161 /* exec */
162 void *AllocMem(ULONG size, ULONG flags) {
163 void *mem;
165 if (flags & MEMF_CLEAR)
166 mem = calloc(1, size);
167 else
168 mem = malloc(size);
169 return mem;
172 void *AllocVec(ULONG size, ULONG flags) {
173 return AllocMem(size, flags);
176 void FreeMem(APTR mem, ULONG size) {
177 free(mem);
180 void FreeVec(APTR mem) {
181 free(mem);
184 void CopyMem(APTR src, APTR dst, ULONG size) {
185 memcpy(dst, src, size);
188 /* dos */
189 struct DateStamp *DateStamp(struct DateStamp *ds) {
190 time_t current;
191 time_t diff;
192 struct tm as={0, 0, 0, 1, 0, 78, -1, -1, -1};
194 time(&current);
195 diff = mktime(&as);
196 current -= diff; /* time since 00:00:00, Jan 1, 1978 */
197 ds->ds_Days = current/60/60/24;
198 current -= (ds->ds_Days*60*60*24);
199 ds->ds_Minute = current/60;
200 current -= (ds->ds_Minute*60);
201 ds->ds_Tick = current*50;
202 return ds;
205 STRPTR PathPart(STRPTR path) {
206 STRPTR ptr;
208 /* '/' at the begining of the string really is part of the path */
209 while (*path == '/')
211 ++path;
214 ptr = path;
216 while (*ptr)
218 if (*ptr == '/')
220 path = ptr;
222 else if (*ptr == ':')
224 path = ptr + 1;
227 ptr++;
230 return path;