Subversion Repositories HelenOS

Rev

Rev 4581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4581 Rev 4718
Line 41... Line 41...
41
#include <malloc.h>
41
#include <malloc.h>
42
#include <string.h>
42
#include <string.h>
43
#include <libfs.h>
43
#include <libfs.h>
44
#include <fibril_sync.h>
44
#include <fibril_sync.h>
45
#include <adt/hash_table.h>
45
#include <adt/hash_table.h>
-
 
46
#include <sys/stat.h>
46
#include "devfs.h"
47
#include "devfs.h"
47
#include "devfs_ops.h"
48
#include "devfs_ops.h"
48
 
49
 
49
#define PLB_GET_CHAR(pos)  (devfs_reg.plb_ro[pos % PLB_SIZE])
50
#define PLB_GET_CHAR(pos)  (devfs_reg.plb_ro[pos % PLB_SIZE])
50
 
51
 
Line 161... Line 162...
161
        first %= PLB_SIZE;
162
        first %= PLB_SIZE;
162
    }
163
    }
163
   
164
   
164
    if (first >= last) {
165
    if (first >= last) {
165
        /* Root entry */
166
        /* Root entry */
166
        if (lflag & L_DIRECTORY)
167
        if (!(lflag & L_FILE))
167
            ipc_answer_5(rid, EOK, devfs_reg.fs_handle, dev_handle, 0, 0, 0);
168
            ipc_answer_5(rid, EOK, devfs_reg.fs_handle, dev_handle, 0, 0, 0);
168
        else
169
        else
169
            ipc_answer_0(rid, ENOENT);
170
            ipc_answer_0(rid, ENOENT);
170
    } else {
171
    } else {
171
        if (lflag & L_FILE) {
172
        if (!(lflag & L_DIRECTORY)) {
172
            size_t len;
173
            size_t len;
173
            if (last >= first)
174
            if (last >= first)
174
                len = last - first + 1;
175
                len = last - first + 1;
175
            else
176
            else
176
                len = first + PLB_SIZE - last + 1;
177
                len = first + PLB_SIZE - last + 1;
Line 275... Line 276...
275
    fibril_mutex_unlock(&devices_mutex);
276
    fibril_mutex_unlock(&devices_mutex);
276
   
277
   
277
    ipc_answer_3(rid, EOK, 0, 1, L_FILE);
278
    ipc_answer_3(rid, EOK, 0, 1, L_FILE);
278
}
279
}
279
 
280
 
280
void devfs_device(ipc_callid_t rid, ipc_call_t *request)
281
void devfs_stat(ipc_callid_t rid, ipc_call_t *request)
281
{
282
{
-
 
283
    dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
282
    fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
284
    fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
283
   
285
   
-
 
286
    ipc_callid_t callid;
-
 
287
    size_t size;
-
 
288
    if (!ipc_data_read_receive(&callid, &size) ||
-
 
289
        size != sizeof(struct stat)) {
-
 
290
        ipc_answer_0(callid, EINVAL);
-
 
291
        ipc_answer_0(rid, EINVAL);
-
 
292
        return;
-
 
293
    }
-
 
294
 
-
 
295
    struct stat stat;
-
 
296
    memset(&stat, 0, sizeof(struct stat));
-
 
297
 
-
 
298
    stat.fs_handle = devfs_reg.fs_handle;
-
 
299
    stat.dev_handle = dev_handle;
-
 
300
    stat.index = index;
-
 
301
    stat.lnkcnt = 1;
-
 
302
    stat.is_file = (index != 0);
-
 
303
    stat.size = 0;
-
 
304
   
284
    if (index != 0) {
305
    if (index != 0) {
285
        unsigned long key[] = {
306
        unsigned long key[] = {
286
            [DEVICES_KEY_HANDLE] = (unsigned long) index
307
            [DEVICES_KEY_HANDLE] = (unsigned long) index
287
        };
308
        };
288
       
309
       
289
        fibril_mutex_lock(&devices_mutex);
310
        fibril_mutex_lock(&devices_mutex);
290
        link_t *lnk = hash_table_find(&devices, key);
311
        link_t *lnk = hash_table_find(&devices, key);
291
        if (lnk == NULL) {
312
        if (lnk != NULL)
292
            fibril_mutex_unlock(&devices_mutex);
313
            stat.devfs_stat.device = (dev_handle_t)index;
293
            ipc_answer_0(rid, ENOENT);
-
 
294
            return;
-
 
295
        }
-
 
296
        fibril_mutex_unlock(&devices_mutex);
314
        fibril_mutex_unlock(&devices_mutex);
297
       
315
    }
-
 
316
 
298
        ipc_answer_1(rid, EOK, (ipcarg_t) index);
317
    ipc_data_read_finalize(callid, &stat, sizeof(struct stat));
299
    } else
-
 
300
        ipc_answer_0(rid, ENOTSUP);
318
    ipc_answer_0(rid, EOK);
301
}
319
}
302
 
320
 
303
void devfs_read(ipc_callid_t rid, ipc_call_t *request)
321
void devfs_read(ipc_callid_t rid, ipc_call_t *request)
304
{
322
{
305
    fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
323
    fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);