- Implemented execp*.
[planlOS.git] / system / kernel / fs / scsi.c
blob72fd824ba3c77fba253e14146f50f15440ce4e31
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #include "fs/scsi.h"
23 #include "ke/errors.h"
24 #include <stdlib.h>
26 static FsSCSIDevice **devices = 0;
27 static uint32_t device_count = 0;
29 int fsRegisterSCSIDevice(FsSCSIDevice *device)
31 devices = realloc(devices, sizeof(FsSCSIDevice*) * (device_count + 1));
32 devices[device_count] = device;
33 device_count++;
34 return 0;
36 int fsRemoveSCSIDevice(FsSCSIDevice *device)
38 return KE_ERROR_NOTIMPLEMENTED;
41 uint32_t fsGetSCSIDeviceCount(void)
43 return device_count;
45 FsSCSIDevice *fsOpenSCSIDevice(uint32_t index)
47 if (index >= device_count) return 0;
48 if (keTryLockSpinlock(&devices[index]->opened)) return 0;
49 return devices[index];
51 void fsCloseSCSIDevice(FsSCSIDevice *device)
53 int index = -1;
54 uint32_t i;
55 for (i = 0; i < device_count; i++)
57 if (devices[i] == device)
59 index = i;
60 break;
63 if (index == -1) return;
64 keUnlockSpinlock(&devices[index]->opened);