Subversion Repositories HelenOS

Rev

Rev 2628 | Rev 2638 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2628 Rev 2629
1
/*
1
/*
2
 * Copyright (c) 2007 Jakub Jermar
2
 * Copyright (c) 2007 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:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup fs
29
/** @addtogroup fs
30
 * @{
30
 * @{
31
 */
31
 */
32
 
32
 
33
#ifndef FAT_FAT_H_
33
#ifndef FAT_FAT_H_
34
#define FAT_FAT_H_
34
#define FAT_FAT_H_
35
 
35
 
36
#include <ipc/ipc.h>
36
#include <ipc/ipc.h>
37
#include <atomic.h>
37
#include <atomic.h>
38
#include <sys/types.h>
38
#include <sys/types.h>
39
#include <bool.h>
39
#include <bool.h>
40
 
40
 
41
#define dprintf(...)    printf(__VA_ARGS__)
41
#define dprintf(...)    printf(__VA_ARGS__)
42
 
42
 
43
typedef struct {
43
typedef struct {
44
    uint8_t     ji[3];      /**< Jump instruction. */
44
    uint8_t     ji[3];      /**< Jump instruction. */
45
    uint8_t     oem_name[8];
45
    uint8_t     oem_name[8];
46
    /* BIOS Parameter Block */
46
    /* BIOS Parameter Block */
47
    uint16_t    bps;        /**< Bytes per sector. */
47
    uint16_t    bps;        /**< Bytes per sector. */
48
    uint8_t     spc;        /**< Sectors per cluster. */
48
    uint8_t     spc;        /**< Sectors per cluster. */
49
    uint16_t    rsc;        /**< Reserved sector count. */
49
    uint16_t    rsc;        /**< Reserved sector count. */
50
    uint8_t     fatcnt;     /**< Number of FATs. */
50
    uint8_t     fatcnt;     /**< Number of FATs. */
51
    uint16_t    root_ent_max;   /**< Maximum number of root directory
51
    uint16_t    root_ent_max;   /**< Maximum number of root directory
52
                         entries. */
52
                         entries. */
53
    uint16_t    totsec;     /**< Total sectors. */
53
    uint16_t    totsec;     /**< Total sectors. */
54
    uint8_t     mdesc;      /**< Media descriptor. */
54
    uint8_t     mdesc;      /**< Media descriptor. */
55
    uint16_t    sec_per_fat;    /**< Sectors per FAT12/FAT16. */
55
    uint16_t    sec_per_fat;    /**< Sectors per FAT12/FAT16. */
56
    uint16_t    sec_per_track;  /**< Sectors per track. */
56
    uint16_t    sec_per_track;  /**< Sectors per track. */
57
    uint16_t    headcnt;    /**< Number of heads. */
57
    uint16_t    headcnt;    /**< Number of heads. */
58
    uint32_t    hidden_sec; /**< Hidden sectors. */
58
    uint32_t    hidden_sec; /**< Hidden sectors. */
59
    uint32_t    total_sec;  /**< Total sectors. */
59
    uint32_t    total_sec;  /**< Total sectors. */
60
 
60
 
61
    union {
61
    union {
62
        struct {
62
        struct {
63
            /* FAT12/FAT16 only: Extended BIOS Parameter Block */
63
            /* FAT12/FAT16 only: Extended BIOS Parameter Block */
64
            /** Physical drive number. */
64
            /** Physical drive number. */
65
            uint8_t     pdn;
65
            uint8_t     pdn;
66
            uint8_t     reserved;
66
            uint8_t     reserved;
67
            /** Extended boot signature. */
67
            /** Extended boot signature. */
68
            uint8_t     ebs;
68
            uint8_t     ebs;
69
            /** Serial number. */
69
            /** Serial number. */
70
            uint32_t    id;
70
            uint32_t    id;
71
            /** Volume label. */
71
            /** Volume label. */
72
            uint8_t     label[11];
72
            uint8_t     label[11];
73
            /** FAT type. */
73
            /** FAT type. */
74
            uint8_t     type[8];
74
            uint8_t     type[8];
75
            /** Boot code. */
75
            /** Boot code. */
76
            uint8_t     boot_code[448];
76
            uint8_t     boot_code[448];
77
            /** Boot sector signature. */
77
            /** Boot sector signature. */
78
            uint16_t    signature;
78
            uint16_t    signature;
79
        } __attribute__ ((packed));
79
        } __attribute__ ((packed));
80
        struct {
80
        struct {
81
            /* FAT32 only */
81
            /* FAT32 only */
82
            /** Sectors per FAT. */
82
            /** Sectors per FAT. */
83
            uint32_t    sectors_per_fat;
83
            uint32_t    sectors_per_fat;
84
            /** FAT flags. */
84
            /** FAT flags. */
85
            uint16_t    flags;
85
            uint16_t    flags;
86
            /** Version. */
86
            /** Version. */
87
            uint16_t    version;
87
            uint16_t    version;
88
            /** Cluster number of root directory. */
88
            /** Cluster number of root directory. */
89
            uint32_t    root_cluster;
89
            uint32_t    root_cluster;
90
            /** Sector number of file system information sector. */
90
            /** Sector number of file system information sector. */
91
            uint16_t    fsinfo_sec;
91
            uint16_t    fsinfo_sec;
92
            /** Sector number of boot sector copy. */
92
            /** Sector number of boot sector copy. */
93
            uint16_t    bscopy_sec;
93
            uint16_t    bscopy_sec;
94
            uint8_t     reserved1[12];
94
            uint8_t     reserved1[12];
95
            /** Physical drive number. */
95
            /** Physical drive number. */
96
            uint8_t     pdn;
96
            uint8_t     pdn;
97
            uint8_t     reserved2;
97
            uint8_t     reserved2;
98
            /** Extended boot signature. */
98
            /** Extended boot signature. */
99
            uint8_t     ebs;
99
            uint8_t     ebs;
100
            /** Serial number. */
100
            /** Serial number. */
101
            uint32_t    id;
101
            uint32_t    id;
102
            /** Volume label. */
102
            /** Volume label. */
103
            uint8_t     label;
103
            uint8_t     label;
104
            /** FAT type. */
104
            /** FAT type. */
105
            uint8_t     type[8];
105
            uint8_t     type[8];
106
            /** Boot code. */
106
            /** Boot code. */
107
            uint8_t     boot_code[420];
107
            uint8_t     boot_code[420];
108
            /** Signature. */
108
            /** Signature. */
109
            uint16_t    signature;
109
            uint16_t    signature;
110
        } __attribute__ ((packed));
110
        } __attribute__ ((packed));
111
    };
111
    };
112
} fat_bs_t __attribute__ ((packed));
112
} __attribute__ ((packed)) fat_bs_t;
-
 
113
 
-
 
114
typedef struct {
-
 
115
    uint8_t     name[8];
-
 
116
    uint8_t     ext[3];
-
 
117
    uint8_t     attr;
-
 
118
    uint8_t     reserved;
-
 
119
    uint8_t     ctime_fine;
-
 
120
    uint16_t    ctime;
-
 
121
    uint16_t    cdate;
-
 
122
    uint16_t    adate;
-
 
123
    union {
-
 
124
        uint16_t    eaidx;      /* FAT12/FAT16 */
-
 
125
        uint16_t    firstc_hi;  /* FAT32 */
-
 
126
    };
-
 
127
    uint16_t    mtime;
-
 
128
    uint16_t    mdate;
-
 
129
    union {
-
 
130
        uint16_t    firstc;     /* FAT12/FAT16 */
-
 
131
        uint16_t    firstc_lo;  /* FAT32 */
-
 
132
    };
-
 
133
    uint32_t    size;
-
 
134
} __attribute__ ((packed)) fat_dentry_t;
113
 
135
 
114
extern uint8_t *plb_ro;
136
extern uint8_t *plb_ro;
115
 
137
 
116
extern int block_read(int, unsigned long, void *);
138
extern int block_read(int, unsigned long, void *);
117
 
139
 
118
extern void fat_lookup(ipc_callid_t, ipc_call_t *);
140
extern void fat_lookup(ipc_callid_t, ipc_call_t *);
119
 
141
 
120
#endif
142
#endif
121
 
143
 
122
/**
144
/**
123
 * @}
145
 * @}
124
 */
146
 */
125
 
147