merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / drivers / fs / minix / mount.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.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; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * PROJECT: ReactOS kernel
21 * FILE: services/fs/minix/minix.c
22 * PURPOSE: Minix FSD
23 * PROGRAMMER: David Welch (welch@mcmail.com)
24 * UPDATE HISTORY:
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include <ddk/ntddk.h>
30 #include <ddk/ntifs.h>
31
32 //#define NDEBUG
33 #include <debug.h>
34
35 #include "minix.h"
36
37 /* GLOBALS *******************************************************************/
38
39 static PDRIVER_OBJECT DriverObject;
40
41 /* FUNCTIONS ****************************************************************/
42
43 VOID MinixMount(PDEVICE_OBJECT DeviceToMount)
44 {
45 PDEVICE_OBJECT DeviceObject;
46 MINIX_DEVICE_EXTENSION* DeviceExt;
47
48 IoCreateDevice(DriverObject,
49 sizeof(MINIX_DEVICE_EXTENSION),
50 NULL,
51 FILE_DEVICE_FILE_SYSTEM,
52 0,
53 FALSE,
54 &DeviceObject);
55 DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
56 DeviceExt = DeviceObject->DeviceExtension;
57
58 MinixReadSector(DeviceToMount,1,DeviceExt->superblock_buf);
59 DeviceExt->sb = (struct minix_super_block *)(DeviceExt->superblock_buf);
60
61 DeviceExt->StorageDevice = DeviceToMount;
62 DeviceExt->StorageDevice->Vpb->DeviceObject = DeviceObject;
63 DeviceExt->StorageDevice->Vpb->RealDevice = DeviceExt->StorageDevice;
64 DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED;
65 DeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1;
66 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
67
68 DeviceExt->FileObject = IoCreateStreamFileObject(NULL, DeviceObject);
69 }
70
71 NTSTATUS STDCALL
72 MinixFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
73 {
74 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
75 // PVPB vpb = Stack->Parameters.Mount.Vpb;
76 PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
77 NTSTATUS Status;
78 char* superblock_buf;
79 struct minix_super_block* sb;
80
81 DbgPrint("MinixFileSystemControl(DeviceObject %x, Irp %x)\n",DeviceObject,
82 Irp);
83 DPRINT("DeviceToMount %x\n",DeviceToMount);
84
85 superblock_buf = ExAllocatePool(NonPagedPool,BLOCKSIZE);
86
87 DPRINT("MinixReadSector %x\n",MinixReadSector);
88 MinixReadSector(DeviceToMount,1,superblock_buf);
89 sb = (struct minix_super_block *)superblock_buf;
90 DPRINT("Magic %x\n",sb->s_magic);
91 DPRINT("Imap blocks %x\n",sb->s_imap_blocks);
92 DPRINT("Zmap blocks %x\n",sb->s_zmap_blocks);
93 if (sb->s_magic==MINIX_SUPER_MAGIC2)
94 {
95 DPRINT("%s() = STATUS_SUCCESS\n",__FUNCTION__);
96 MinixMount(DeviceToMount);
97 Status = STATUS_SUCCESS;
98 }
99 else
100 {
101 DPRINT("%s() = STATUS_UNRECOGNIZED_VOLUME\n",__FUNCTION__);
102 Status = STATUS_UNRECOGNIZED_VOLUME;
103 }
104
105 Irp->IoStatus.Status = Status;
106 Irp->IoStatus.Information = 0;
107
108 IoCompleteRequest(Irp, IO_NO_INCREMENT);
109 return(Status);
110 }
111
112 NTSTATUS STDCALL
113 DriverEntry(PDRIVER_OBJECT _DriverObject,
114 PUNICODE_STRING RegistryPath)
115 /*
116 * FUNCTION: Called by the system to initalize the driver
117 * ARGUMENTS:
118 * DriverObject = object describing this driver
119 * RegistryPath = path to our configuration entries
120 * RETURNS: Success or failure
121 */
122 {
123 PDEVICE_OBJECT DeviceObject;
124 NTSTATUS ret;
125 UNICODE_STRING DeviceName;
126
127 DbgPrint("Minix FSD 0.0.1\n");
128
129 DriverObject = _DriverObject;
130
131 RtlInitUnicodeString(&DeviceName,
132 L"\\Device\\Minix");
133 ret = IoCreateDevice(DriverObject,
134 0,
135 &DeviceName,
136 FILE_DEVICE_FILE_SYSTEM,
137 0,
138 FALSE,
139 &DeviceObject);
140 if (!NT_SUCCESS(ret))
141 {
142 return(ret);
143 }
144
145 DeviceObject->Flags = 0;
146 DriverObject->MajorFunction[IRP_MJ_CLOSE] = MinixClose;
147 DriverObject->MajorFunction[IRP_MJ_CREATE] = MinixCreate;
148 DriverObject->MajorFunction[IRP_MJ_READ] = MinixRead;
149 DriverObject->MajorFunction[IRP_MJ_WRITE] = MinixWrite;
150 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
151 MinixFileSystemControl;
152 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
153 MinixDirectoryControl;
154 DriverObject->DriverUnload = NULL;
155
156 IoRegisterFileSystem(DeviceObject);
157
158 return(STATUS_SUCCESS);
159 }
160