- Implemented execp*.
[planlOS.git] / system / kernel / fs / request.c
blob173ad7ba051e96fb41b025ac37e36a69e0839a9c
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/request.h"
23 #include "ke/cpu.h"
24 #include "ke/errors.h"
25 #include "ke/debug.h"
27 int fsCreateRequest(FsRequest *request, int wait, KeProcess *process)
29 if (!request->fs->query_request)
31 kePrint("Error: Filesystem %x does not support requests.\n", request->fs);
32 return KE_ERROR_UNKNOWN;
34 if (process)
36 request->process = process;
38 else
40 if (keGetCurrentCPU()->currentthread)
41 request->process = keGetCurrentCPU()->currentthread->process;
42 else
43 request->process = 0;
45 int status = request->fs->query_request(request->fs, request);
46 if (status) return status;
47 if (wait) return fsWaitRequest(request);
48 return 0;
50 int fsWaitRequest(FsRequest *request)
52 // TODO: Thread safety
53 if (request->finished) return 0;
54 KeExecLevel oldlevel = keSetExecutionLevel(KE_LEVEL_HIGH);
55 request->caller = keGetCurrentCPU()->currentthread;
56 request->caller->status = KE_THREAD_FSREQUEST;
57 // Schedule out of the thread
58 asm volatile("int $0x32");
59 keSetExecutionLevel(oldlevel);
60 return 0;
62 int fsFinishRequest(FsRequest *request)
64 request->finished = 1;
65 if (request->caller)
67 request->caller->status = KE_THREAD_RUNNING;
69 return 0;