Indentation fix, cleanup.
[AROS.git] / arch / all-hosted / devs / hostdisk / automount.c
blob895767b4b60b8d174c511bad01c42b726083b567
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <dos/filehandler.h>
8 #include <exec/rawfmt.h>
9 #include <libraries/expansion.h>
10 #include <libraries/expansionbase.h>
11 #include <proto/exec.h>
12 #include <proto/expansion.h>
14 #include LC_LIBDEFS_FILE
16 extern const char GM_UNIQUENAME(LibName)[];
18 static int Automount(struct HostDiskBase *hdskBase)
20 struct ExpansionBase *ExpansionBase = NULL;
21 char *unit;
22 struct DriveGeometry dg;
23 ULONG u, len;
25 if (hdskBase->segList)
27 D(bug("hostdisk: Loaded from disk, skipping automount.\n"));
28 return TRUE;
31 len = strlen(hdskBase->DiskDevice) + 5;
32 unit = AllocMem(len, MEMF_ANY);
33 if (!unit)
34 return FALSE;
36 for (u = 0; u < 30; u++)
38 IPTR pp[24];
40 NewRawDoFmt(hdskBase->DiskDevice, (VOID_FUNC)RAWFMTFUNC_STRING, unit, u + hdskBase->unitBase);
42 if (Host_ProbeGeometry(hdskBase, unit, &dg) == 0)
44 struct DeviceNode *devnode;
45 TEXT dosdevname[4] = "HD0";
47 if (!ExpansionBase)
49 ExpansionBase = (struct ExpansionBase *)OpenLibrary("expansion.library", 40);
50 if (!ExpansionBase)
52 FreeMem(unit, len);
53 return FALSE;
57 if (u < 10)
58 dosdevname[2] += u % 10;
59 else
60 dosdevname[2] = 'A' - 10 + u;
62 D(bug("hostdisk: Automounting %s as %s\n", unit, dosdevname));
64 pp[0] = (IPTR)dosdevname;
65 pp[1] = (IPTR)GM_UNIQUENAME(LibName);
66 pp[2] = u;
67 pp[DE_TABLESIZE + 4] = DE_BOOTBLOCKS;
68 pp[DE_SIZEBLOCK + 4] = dg.dg_SectorSize >> 2;
69 pp[DE_NUMHEADS + 4] = dg.dg_Heads;
70 pp[DE_SECSPERBLOCK + 4] = 1;
71 pp[DE_BLKSPERTRACK + 4] = dg.dg_TrackSectors;
72 pp[DE_RESERVEDBLKS + 4] = 2;
73 pp[DE_LOWCYL + 4] = 0;
74 pp[DE_HIGHCYL + 4] = dg.dg_Cylinders - 1;
75 pp[DE_NUMBUFFERS + 4] = 10;
76 pp[DE_BUFMEMTYPE + 4] = MEMF_PUBLIC;
77 pp[DE_MAXTRANSFER + 4] = 0x00200000;
78 pp[DE_MASK + 4] = -2; /* On Windows Host_Read() fails with ERROR_INVALID_PARAMETER on odd addresses */
79 pp[DE_BOOTPRI + 4] = 0;
80 pp[DE_DOSTYPE + 4] = AROS_MAKE_ID('D','O','S','\001');
81 pp[DE_CONTROL + 4] = 0;
82 pp[DE_BOOTBLOCKS + 4] = 2;
84 devnode = MakeDosNode(pp);
85 if (!devnode)
87 CloseLibrary(&ExpansionBase->LibNode);
88 FreeMem(unit, len);
89 return FALSE;
92 AddBootNode(pp[DE_BOOTPRI + 4], ADNF_STARTPROC, devnode, NULL);
96 if (ExpansionBase)
97 CloseLibrary(&ExpansionBase->LibNode);
99 FreeMem(unit, len);
100 return TRUE;
103 ADD2INITLIB(Automount, 20);