[BACK]Return to fatfs.h CVS log [TXT][DIR] Up to [local] / prex / usr / server / fs / fatfs

Annotation of prex/usr/server/fs/fatfs/fatfs.h, Revision 1.1.1.1

1.1       nbrk        1: /*
                      2:  * Copyright (c) 2005-2007, Kohsuke Ohtani
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. Neither the name of the author nor the names of any co-contributors
                     14:  *    may be used to endorse or promote products derived from this software
                     15:  *    without specific prior written permission.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     27:  * SUCH DAMAGE.
                     28:  */
                     29:
                     30: #ifndef _FATFS_H
                     31: #define _FATFS_H
                     32:
                     33: #include <prex/prex.h>
                     34: #include <sys/cdefs.h>
                     35: #include <sys/types.h>
                     36: #include <sys/vnode.h>
                     37: #include <sys/file.h>
                     38: #include <sys/mount.h>
                     39: #include <sys/syslog.h>
                     40: #include <sys/buf.h>
                     41:
                     42: /* #define DEBUG_FATFS 1 */
                     43:
                     44: #ifdef DEBUG_FATFS
                     45: #define DPRINTF(a)     dprintf a
                     46: #define ASSERT(e)      assert(e)
                     47: #else
                     48: #define DPRINTF(a)     do {} while (0)
                     49: #define ASSERT(e)
                     50: #endif
                     51:
                     52:
                     53: #if CONFIG_FS_THREADS > 1
                     54: #define malloc(s)              malloc_r(s)
                     55: #define free(p)                        free_r(p)
                     56: #else
                     57: #define mutex_init(m)          do {} while (0)
                     58: #define mutex_destroy(m)       do {} while (0)
                     59: #define mutex_lock(m)          do {} while (0)
                     60: #define mutex_unlock(m)                do {} while (0)
                     61: #define mutex_trylock(m)       do {} while (0)
                     62: #endif
                     63:
                     64:
                     65: #define SEC_SIZE       512             /* sector size */
                     66: #define SEC_INVAL      0xffffffff      /* invalid sector */
                     67:
                     68: /*
                     69:  * Pre-defined cluster number
                     70:  */
                     71: #define CL_ROOT                0               /* cluster 0 means the root directory */
                     72: #define CL_FREE                0               /* cluster 0 also means the free cluster */
                     73: #define CL_FIRST       2               /* first legal cluster */
                     74: #define CL_LAST                0xfffffff5      /* last legal cluster */
                     75: #define CL_EOF         0xffffffff      /* EOF cluster */
                     76:
                     77: #define EOF_MASK       0xfffffff8      /* mask of eof */
                     78:
                     79: #define FAT12_MASK     0x00000fff
                     80: #define FAT16_MASK     0x0000ffff
                     81:
                     82:
                     83: /*
                     84:  * BIOS parameter block
                     85:  */
                     86: struct fat_bpb {
                     87:        uint16_t        jmp_instruction;
                     88:        uint8_t         nop_instruction;
                     89:        uint8_t         oem_id[8];
                     90:        uint16_t        bytes_per_sector;
                     91:        uint8_t         sectors_per_cluster;
                     92:        uint16_t        reserved_sectors;
                     93:        uint8_t         num_of_fats;
                     94:        uint16_t        root_entries;
                     95:        uint16_t        total_sectors;
                     96:        uint8_t         media_descriptor;
                     97:        uint16_t        sectors_per_fat;
                     98:        uint16_t        sectors_per_track;
                     99:        uint16_t        heads;
                    100:        uint32_t        hidden_sectors;
                    101:        uint32_t        big_total_sectors;
                    102:        uint8_t         physical_drive;
                    103:        uint8_t         reserved;
                    104:        uint8_t         ext_boot_signature;
                    105:        uint32_t        serial_no;
                    106:        uint8_t         volume_id[11];
                    107:        uint8_t         file_sys_id[8];
                    108: } __packed;
                    109:
                    110: /*
                    111:  * FAT directory entry
                    112:  */
                    113: struct fat_dirent {
                    114:        uint8_t         name[11];
                    115:        uint8_t         attr;
                    116:        uint8_t         reserve[10];
                    117:        uint16_t        time;
                    118:        uint16_t        date;
                    119:        uint16_t        cluster;
                    120:        uint32_t        size;
                    121: } __packed;
                    122:
                    123: #define SLOT_EMPTY     0x00
                    124: #define SLOT_DELETED   0xe5
                    125:
                    126: #define DIR_PER_SEC     (SEC_SIZE / sizeof(struct fat_dirent))
                    127:
                    128: /*
                    129:  * FAT attribute for attr
                    130:  */
                    131: #define FA_RDONLY      0x01
                    132: #define FA_HIDDEN      0x02
                    133: #define FA_SYSTEM      0x04
                    134: #define FA_VOLID       0x08
                    135: #define FA_SUBDIR      0x10
                    136: #define FA_ARCH        0x20
                    137: #define FA_DEVICE      0x40
                    138:
                    139: #define IS_DIR(de)     (((de)->attr) & FA_SUBDIR)
                    140: #define IS_VOL(de)     (((de)->attr) & FA_VOLID)
                    141: #define IS_FILE(de)    (!IS_DIR(de) && !IS_VOL(de))
                    142:
                    143: #define IS_DELETED(de)  ((de)->name[0] == 0xe5)
                    144: #define IS_EMPTY(de)    ((de)->name[0] == 0)
                    145:
                    146: /*
                    147:  * Mount data
                    148:  */
                    149: struct fatfsmount {
                    150:        int     fat_type;       /* 12 or 16 */
                    151:        u_long  root_start;     /* start sector for root directory */
                    152:        u_long  fat_start;      /* start sector for fat entries */
                    153:        u_long  data_start;     /* start sector for data */
                    154:        u_long  fat_eof;        /* id of end cluster */
                    155:        u_long  sec_per_cl;     /* sectors per cluster */
                    156:        u_long  cluster_size;   /* cluster size */
                    157:        u_long  last_cluster;   /* last cluser */
                    158:        u_long  fat_mask;       /* mask for cluster# */
                    159:        u_long  free_scan;      /* start cluster# to free search */
                    160:        vnode_t root_vnode;     /* vnode for root */
                    161:        char    *io_buf;        /* local data buffer */
                    162:        char    *fat_buf;       /* buffer for fat entry */
                    163:        char    *dir_buf;       /* buffer for directory entry */
                    164:        dev_t   dev;            /* mounted device */
                    165: #if CONFIG_FS_THREADS > 1
                    166:        mutex_t lock;           /* file system lock */
                    167: #endif
                    168: };
                    169:
                    170: #define FAT12(fat)     ((fat)->fat_type == 12)
                    171: #define FAT16(fat)     ((fat)->fat_type == 16)
                    172:
                    173: #define IS_EOFCL(fat, cl) \
                    174:        (((cl) & EOF_MASK) == ((fat)->fat_mask & EOF_MASK))
                    175:
                    176: /*
                    177:  * File/directory node
                    178:  */
                    179: struct fatfs_node {
                    180:        struct fat_dirent dirent; /* copy of directory entry */
                    181:        u_long  sector;         /* sector# for directory entry */
                    182:        u_long  offset;         /* offset of directory entry in sector */
                    183: };
                    184:
                    185: extern struct vnops fatfs_vnops;
                    186:
                    187: /* Macro to convert cluster# to logical sector# */
                    188: #define cl_to_sec(fat, cl) \
                    189:             (fat->data_start + (cl - 2) * fat->sec_per_cl)
                    190:
                    191: extern int fat_next_cluster(struct fatfsmount *fmp, u_long cl, u_long *next);
                    192: extern int fat_set_cluster(struct fatfsmount *fmp, u_long cl, u_long next);
                    193: extern int fat_alloc_cluster(struct fatfsmount *fmp, u_long scan_start, u_long *free);
                    194: extern int fat_free_clusters(struct fatfsmount *fmp, u_long start);
                    195: extern int fat_seek_cluster(struct fatfsmount *fmp, u_long start, u_long offset,
                    196:                            u_long *cl);
                    197: extern int fat_expand_file(struct fatfsmount *fmp, u_long cl, int size);
                    198: extern int fat_expand_dir(struct fatfsmount *fmp, u_long cl, u_long *new_cl);
                    199:
                    200: extern void fat_convert_name(char *org, char *name);
                    201: extern void fat_restore_name(char *org, char *name);
                    202: extern int fat_valid_name(char *name);
                    203: extern int fat_compare_name(char *n1, char *n2);
                    204: extern void fat_mode_to_attr(mode_t mode, u_char *attr);
                    205: extern void fat_attr_to_mode(u_char attr, mode_t *mode);
                    206:
                    207: extern int fatfs_lookup_node(vnode_t dvp, char *name, struct fatfs_node *node);
                    208: extern int fatfs_get_node(vnode_t dvp, int index, struct fatfs_node *node);
                    209: extern int fatfs_put_node(struct fatfsmount *fmp, struct fatfs_node *node);
                    210: extern int fatfs_add_node(vnode_t dvp, struct fatfs_node *node);
                    211:
                    212: #endif /* !_FATFS_H */

CVSweb