2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
7 * Define struct stat64 on Linux.
8 * Define this before anything, since AROS includes
9 * may include POSIX includes (for example aros/debug.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>
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
)
28 struct hd_geometry geo
;
30 unsigned long devsize
;
32 D(bug("hostdisk: Host_DeviceGeometry(%s)\n", Unit
->filename
));
36 ret
= hdskBase
->iface
->ioctl(file
, HDIO_GETGEO
, &geo
);
39 ret
= hdskBase
->iface
->ioctl(file
, BLKSSZGET
, &blksize
);
42 ret
= hdskBase
->iface
->ioctl(file
, BLKGETSIZE
, &devsize
);
44 err
= *hdskBase
->errnoPtr
;
50 D(bug("hostdisk: Error %d\n", 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"));
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
));
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
)
93 res
= hdskBase
->iface
->stat64("/dev/hda", &st
);
96 D(bug("hostdisk: /dev/hda check result: %d\n", res
));
98 hdskBase
->DiskDevice
= "/dev/sd%lc";
103 ADD2INITLIB(deviceProbe
, 10);