Split cdrom.c to media.c with clients cdrom.c and disk.c
[captive.git] / src / libcaptive / storage / disk.c
1 /* $Id$
2  * "\Device\CaptiveHarddisk%d" storage emulation driver for reactos of libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "captive/storage.h"    /* self */
23 #include "captive/client.h"
24 #include "media.h"
25 #include <glib/gmessages.h>
26 #include "captive/unicode.h"
27 #include "reactos/ddk/status.h" /* for NT_SUCCESS() */
28
29
30 /**
31  * captive_disk_init:
32  *
33  * Creates system device "\Device\CaptiveHarddisk%d" providing readwrite access
34  * to the given #captive_image_iochannel as emulation of harddisk driver.
35  * reactos initializes "\Device\Harddisk%d\Partition0" as the whole disk
36  * and each partition it founds by IoReadPartitionTable() it will create
37  * as "\Device\Harddisk%d\Partition1", "\Device\Harddisk%d\Partition2" etc.
38  *
39  * libcaptive does not (yet?) support any partitions and it will always create
40  * just the disk device for the whole given #captive_image_iochannel.
41  * As this behaviour is a bit specific we rather create some non-standard name
42  * of the device; anyway I have seen some "\Device\Harddisk%dVolume%d" on W32
43  * system.
44  *
45  * captive currently supports just one drive and thus "\Device\CaptiveHarddisk0"
46  * is always created. It is forbidden to call this function twice.
47  *
48  * Returns: %TRUE if the initialization was successful.
49  */
50 gboolean captive_disk_init(void)
51 {
52 static struct captive_DriverObject disk_captive_DriverObject;
53 NTSTATUS err;
54
55         g_return_val_if_fail(captive_image_iochannel!=NULL,FALSE);
56
57         disk_captive_DriverObject.DiskGeometry.BytesPerSector=512;
58         disk_captive_DriverObject.DiskGeometry.MediaType=FixedMedia;
59         disk_captive_DriverObject.DeviceName_utf8="\\Device\\CaptiveHarddisk0";
60         disk_captive_DriverObject.DeviceType=FILE_DEVICE_DISK;
61         disk_captive_DriverObject.DeviceCharacteristics=0;      /* !FILE_REMOVABLE_MEDIA && !FILE_READ_ONLY_DEVICE */
62         err=captive_media_DriverEntry(
63                         &disk_captive_DriverObject,     /* DriverEntry_DriverObject */
64                         captive_utf8_to_UnicodeString_alloca("\\captive\\storage\\disk"));      /* DriverEntry_RegistryPath; ignored */
65         g_return_val_if_fail(NT_SUCCESS(err),FALSE);
66
67         return TRUE;
68 }