Subversion Repositories HelenOS

Rev

Rev 2643 | Rev 2796 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2643 Rev 2793
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2007 Jakub Jermar
2
 * Copyright (c) 2008 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 35... Line 35...
35
 * @brief   Implementation of VFS operations for the FAT file system server.
35
 * @brief   Implementation of VFS operations for the FAT file system server.
36
 */
36
 */
37
 
37
 
38
#include "fat.h"
38
#include "fat.h"
39
#include "../../vfs/vfs.h"
39
#include "../../vfs/vfs.h"
-
 
40
#include <libfs.h>
40
#include <ipc/ipc.h>
41
#include <ipc/ipc.h>
41
#include <async.h>
42
#include <async.h>
42
#include <errno.h>
43
#include <errno.h>
43
 
-
 
44
#define PLB_GET_CHAR(i)     (fat_reg.plb_ro[(i) % PLB_SIZE])
44
#include <string.h>
45
 
45
 
46
#define FAT_NAME_LEN        8
46
#define FAT_NAME_LEN        8
47
#define FAT_EXT_LEN     3
47
#define FAT_EXT_LEN     3
48
 
48
 
49
#define FAT_PAD         ' ' 
49
#define FAT_PAD         ' ' 
Line 51... Line 51...
51
#define FAT_DENTRY_UNUSED   0x00
51
#define FAT_DENTRY_UNUSED   0x00
52
#define FAT_DENTRY_E5_ESC   0x05
52
#define FAT_DENTRY_E5_ESC   0x05
53
#define FAT_DENTRY_DOT      0x2e
53
#define FAT_DENTRY_DOT      0x2e
54
#define FAT_DENTRY_ERASED   0xe5
54
#define FAT_DENTRY_ERASED   0xe5
55
 
55
 
56
/** Compare one component of path to a directory entry.
-
 
57
 *
-
 
58
 * @param dentry    Directory entry to compare the path component with.
-
 
59
 * @param start     Index into PLB where the path component starts.
-
 
60
 * @param last      Index of the last character of the path in PLB.
-
 
61
 *
-
 
62
 * @return      Zero on failure or delta such that (index + delta) %
-
 
63
 *          PLB_SIZE points to a new path component in PLB.
-
 
64
 */
-
 
65
static unsigned match_path_component(fat_dentry_t *dentry, unsigned start,
56
static void dentry_name_canonify(fat_dentry_t *d, char *buf)
66
    unsigned last)
-
 
67
{
57
{
68
    unsigned cur;   /* current position in PLB */
-
 
69
    int pos;    /* current position in dentry->name or dentry->ext */
-
 
70
    bool name_processed = false;
-
 
71
    bool dot_processed = false;
-
 
72
    bool ext_processed = false;
58
    int i;
73
 
59
 
74
    if (last < start)
-
 
75
        last += PLB_SIZE;
-
 
76
    for (pos = 0, cur = start; (cur <= last) && (PLB_GET_CHAR(cur) != '/');
-
 
77
        pos++, cur++) {
-
 
78
        if (!name_processed) {
-
 
79
            if ((pos == FAT_NAME_LEN - 1) ||
60
    for (i = 0; i < FAT_NAME_LEN; i++) {
80
                (dentry->name[pos + 1] == FAT_PAD)) {
61
        if (d->name[i] == FAT_PAD) {
81
                    /* this is the last character in name */
62
            buf++;
82
                name_processed = true;
63
            break;
83
            }
64
        }
84
            if (dentry->name[0] == FAT_PAD) {
-
 
85
                /* name is empty */
-
 
86
                name_processed = true;
-
 
87
            } else if ((pos == 0) && (dentry->name[pos] ==
-
 
88
                FAT_DENTRY_E5_ESC)) {
65
        if (d->name[i] == FAT_DENTRY_E5_ESC)
89
                if (PLB_GET_CHAR(cur) == 0xe5)
-
 
90
                    continue;
66
            *buf++ = 0xe5;
91
                else
67
        else
-
 
68
            *buf++ = d->name[i];
-
 
69
    }
-
 
70
    if (d->ext[0] != FAT_PAD)
-
 
71
        *buf++ = '.';
92
                    return 0;   /* character mismatch */
72
    for (i = 0; i < FAT_EXT_LEN; i++) {
-
 
73
        if (d->ext[i] == FAT_PAD) {
-
 
74
            *buf = '\0';
93
            } else {
75
            return;
-
 
76
        }
94
                if (PLB_GET_CHAR(cur) == dentry->name[pos])
77
        if (d->ext[i] == FAT_DENTRY_E5_ESC)
95
                    continue;
78
            *buf++ = 0xe5;
96
                else
79
        else
-
 
80
            *buf++ = d->ext[i];
-
 
81
    }
-
 
82
}
-
 
83
 
-
 
84
static fat_dentry_t *fat_dentry_get(fat_node_t *dirnode, unsigned idx)
-
 
85
{
97
                    return 0;   /* character mismatch */
86
    return NULL;    /* TODO */
-
 
87
}
-
 
88
 
-
 
89
static void fat_dentry_put(fat_dentry_t *dentry)
-
 
90
{
-
 
91
    /* TODO */
98
            }
92
}
-
 
93
 
-
 
94
static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index)
-
 
95
{
-
 
96
    return NULL;    /* TODO */
99
        }
97
}
-
 
98
 
-
 
99
static void *fat_match(void *prnt, const char *component)
-
 
100
{
100
        if (!dot_processed) {
101
    fat_node_t *parentp = (fat_node_t *)prnt;
-
 
102
    char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
-
 
103
    unsigned i;
101
            dot_processed = true;
104
    unsigned dentries;
102
            pos = -1;
105
    fat_dentry_t *d;
-
 
106
 
-
 
107
    dentries = parentp->size / sizeof(fat_dentry_t);
-
 
108
    for (i = 0; i < dentries; i++) {
-
 
109
        d = fat_dentry_get(parentp, i);
103
            if (PLB_GET_CHAR(cur) != '.')
110
        if (d->attr & FAT_ATTR_VOLLABEL) {
-
 
111
            /* volume label entry */
104
                return 0;
112
            fat_dentry_put(d);
105
            continue;
113
            continue;
106
        }
114
        }
107
        if (!ext_processed) {
-
 
108
            if ((pos == FAT_EXT_LEN - 1) ||
-
 
109
                (dentry->ext[pos + 1] == FAT_PAD)) {
-
 
110
                /* this is the last character in ext */
-
 
111
                ext_processed = true;
-
 
112
            }
-
 
113
            if (dentry->ext[0] == FAT_PAD) {
115
        if (d->name[0] == FAT_DENTRY_ERASED) {
114
                /* ext is empty; the match will fail */
116
            /* not-currently-used entry */
115
                ext_processed = true;
117
            fat_dentry_put(d);
116
            } else if (PLB_GET_CHAR(cur) == dentry->ext[pos]) {
-
 
117
                continue;
118
            continue;
118
            } else {
-
 
119
                /* character mismatch */
-
 
120
                return 0;
-
 
121
            }
119
        }
-
 
120
        if (d->name[0] == FAT_DENTRY_UNUSED) {
-
 
121
            /* never used entry */
-
 
122
            fat_dentry_put(d);
-
 
123
            break;
122
        }
124
        }
-
 
125
        if (d->name[0] == FAT_DENTRY_DOT) {
-
 
126
            /*
-
 
127
             * Most likely '.' or '..'.
123
        return 0;   /* extra characters in the component */
128
             * It cannot occur in a regular file name.
-
 
129
             */
-
 
130
            fat_dentry_put(d);
-
 
131
            continue;
-
 
132
        }
-
 
133
       
-
 
134
        dentry_name_canonify(d, name);
-
 
135
        if (strcmp(name, component) == 0) {
-
 
136
            /* hit */
-
 
137
            void *node = fat_node_get(parentp->dev_handle,
-
 
138
                (fs_index_t)d->firstc);
-
 
139
            fat_dentry_put(d);
-
 
140
            return node;
-
 
141
 
-
 
142
        } else {
-
 
143
            /* miss */
-
 
144
            fat_dentry_put(d);
124
    }
145
        }
125
    if (ext_processed || (name_processed && dentry->ext[0] == FAT_PAD))
-
 
126
        return cur - start;
-
 
127
    else
-
 
128
        return 0;
-
 
129
}
146
    }
130
 
147
 
131
void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
148
    return NULL;
132
{
149
}
133
    int first = IPC_GET_ARG1(*request);
-
 
134
    int second = IPC_GET_ARG2(*request);
-
 
135
    int dev_handle = IPC_GET_ARG3(*request);
-
 
136
 
150
 
-
 
151
/** libfs operations */
-
 
152
libfs_ops_t fat_libfs_ops = {
-
 
153
    .match = fat_match,
-
 
154
    .node_get = fat_node_get,
-
 
155
    .create = NULL,
-
 
156
    .destroy = NULL,
-
 
157
    .link = NULL,
-
 
158
    .unlink = NULL,
-
 
159
    .index_get = NULL,
-
 
160
    .size_get = NULL,
-
 
161
    .lnkcnt_get = NULL,
-
 
162
    .has_children = NULL,
-
 
163
    .root_get = NULL,
-
 
164
    .plb_get_char = NULL,
-
 
165
    .is_directory = NULL,
-
 
166
    .is_file = NULL
-
 
167
};
137
   
168
 
-
 
169
void fat_lookup(ipc_callid_t rid, ipc_call_t *request)
-
 
170
{
-
 
171
    libfs_lookup(&fat_libfs_ops, fat_reg.fs_handle, rid, request);
138
}
172
}
139
 
173
 
140
/**
174
/**
141
 * @}
175
 * @}
142
 */
176
 */