Copyright clean-up (part 1):
[AROS.git] / arch / all-linux / hostdisk / geometry.c
blob9643f5cea0fdb610750b16cd2cfb60880a83a7f5
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * Define struct stat64 on Linux.
8 * Define this before anything, since AROS includes
9 * may include POSIX includes (for example aros/debug.h
10 * includes string.h)
12 #define _LARGEFILE64_SOURCE
14 #include <aros/debug.h>
15 #include <aros/symbolsets.h>
16 #include <devices/trackdisk.h>
17 #include <proto/hostlib.h>
19 #include <linux/fs.h>
20 #include <linux/hdreg.h>
22 #include "hostdisk_host.h"
23 #include "hostdisk_device.h"
25 ULONG Host_DeviceGeometry(int file, struct DriveGeometry *dg, struct HostDiskBase *hdskBase)
27 int ret, err;
28 struct hd_geometry geo;
29 size_t blksize;
30 unsigned long devsize;
32 D(bug("hostdisk: Host_DeviceGeometry(%s)\n", Unit->filename));
34 HostLib_Lock();
36 ret = hdskBase->iface->ioctl(file, HDIO_GETGEO, &geo);
38 if (ret != -1)
39 ret = hdskBase->iface->ioctl(file, BLKSSZGET, &blksize);
41 if (ret != -1)
42 ret = hdskBase->iface->ioctl(file, BLKGETSIZE, &devsize);
44 err = *hdskBase->errnoPtr;
46 HostLib_Unlock();
48 if (ret == -1)
50 D(bug("hostdisk: Error %d\n", err));
52 return err;
55 D(bug("hostdisk: Block size: %lu\n", blksize));
56 D(bug("hostdisk: %lu blocks per 512 bytes\n", devsize));
57 D(bug("hostdisk: Disk has %u heads, %u sectors, %u cylinders\n", geo.heads, geo.sectors, geo.cylinders));
59 dg->dg_SectorSize = blksize;
60 dg->dg_TotalSectors = devsize / (blksize / 512);
61 dg->dg_CylSectors = geo.heads * geo.sectors;
63 if (dg->dg_TotalSectors % dg->dg_CylSectors)
65 dg->dg_CylSectors = 1;
66 dg->dg_Cylinders = dg->dg_TotalSectors;
68 D(bug("hostdisk: Geometry does not fit, use LBA\n"));
70 else
72 dg->dg_Heads = geo.heads;
73 dg->dg_TrackSectors = geo.sectors;
74 dg->dg_Cylinders = dg->dg_TotalSectors / dg->dg_CylSectors;
76 D(bug("hostdisk: Device size: %u cylinders\n", dg->dg_Cylinders));
79 return 0;
83 * This checks if the system has /dev/hd* entries at all
84 * and uses /dev/sd* if not.
85 * It is assumed that we have at least /dev/hda.
87 static int deviceProbe(struct HostDiskBase *hdskBase)
89 struct stat64 st;
90 int res;
92 HostLib_Lock();
93 res = hdskBase->iface->stat64("/dev/hda", &st);
94 HostLib_Unlock();
96 D(bug("hostdisk: /dev/hda check result: %d\n", res));
97 if (res == -1)
98 hdskBase->DiskDevice = "/dev/sd%lc";
100 return TRUE;
103 ADD2INITLIB(deviceProbe, 10);