00001 /* 00002 ** fatvar.h for in /root/research/lseosr2a/programs/fat 00003 ** 00004 ** Copyright (c)2004 Julien Quintard 00005 ** Login <quinta_j@epita.fr> 00006 ** 00007 ** Started on Tue Mar 30 13:19:22 2004 Julien Quintard 00008 ** Last update Mon Dec 6 12:24:19 2004 Vianney Rancurel 00009 */ 00010 #ifndef __FATVAR_H__ 00011 #define __FATVAR_H__ 1 00012 #include <libc.h> 00013 #include <libide.h> 00014 #include <libpart.h> 00015 #include <libtimer.h> 00016 00017 #define DEBUG_FAT 00018 00019 #define FAT_SIGNATURE 0x29 00020 #define FAT_NAMESZ_BASE 0x8 00021 #define FAT_NAMESZ_EXT 0x3 00022 #define FAT_NAMESZ (FAT_NAMESZ_BASE + FAT_NAMESZ_EXT) 00023 #define FAT_PARENT_DIR ".." 00024 #define FAT_PATH_SEPARATOR "/" 00025 #define FAT_FREE_CLUSTER 0x00000000 00026 00027 #define FAT_CACHESZ 64 00028 00029 /* 00030 * fat structures 00031 */ 00032 00033 typedef struct s_fat_direntry 00034 { 00035 u_int8_t de_name[FAT_NAMESZ]; 00036 00037 #define FAT_ATTR_READ_ONLY 0x01 00038 #define FAT_ATTR_HIDDEN 0x02 00039 #define FAT_ATTR_SYSTEM 0x04 00040 #define FAT_ATTR_VOLUME_ID 0x08 00041 #define FAT_ATTR_DIRECTORY 0x10 00042 #define FAT_ATTR_ARCHIVE 0x20 00043 #define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | \ 00044 FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID) 00045 00046 u_int8_t de_attr; 00047 00048 #define FAT_EATTR_UW 0x01 00049 #define FAT_EATTR_UX 0x02 00050 #define FAT_EATTR_GW 0x04 00051 #define FAT_EATTR_GX 0x08 00052 #define FAT_EATTR_OW 0x10 00053 #define FAT_EATTR_OX 0x20 00054 00055 u_int8_t de_ntres; 00056 u_int8_t de_crttimetenth; 00057 u_int16_t de_crttime; 00058 u_int16_t de_crtdate; 00059 u_int16_t de_lstaccdate; 00060 u_int16_t de_fstclu_hi; 00061 u_int16_t de_wrttime; 00062 u_int16_t de_wrtdate; 00063 u_int16_t de_fstclu_lo; 00064 u_int32_t de_filesize; 00065 } t_fat_direntry; 00066 00067 typedef struct s_fat16 00068 { 00069 /* 00070 * for fat12 and fat16 00071 */ 00072 00073 u_int8_t f_drvnum; 00074 u_int8_t f_reserved; 00075 u_int8_t f_bootsig; 00076 u_int32_t f_volid; 00077 u_int8_t f_vollabel[11]; 00078 u_int8_t f_fstype[8]; 00079 } t_fat16; 00080 00081 typedef struct s_fat32 00082 { 00083 u_int32_t f_fatsz_32b; 00084 u_int16_t f_extflags; 00085 u_int16_t f_fsver; 00086 u_int32_t f_root; 00087 u_int16_t f_fsinfo; 00088 u_int16_t f_backup; 00089 u_int8_t f_reserved1[12]; 00090 u_int8_t f_drvnum; 00091 u_int8_t f_bootsig; 00092 u_int32_t f_volid; 00093 u_int8_t f_vollabel[11]; 00094 u_int8_t f_fstype[8]; 00095 } t_fat32; 00096 00097 typedef struct s_fat_common 00098 { 00099 u_int8_t fc_jmp[3]; 00100 u_int8_t fc_oemname[8]; 00101 u_int16_t fc_bps; /* bytes per sector */ 00102 u_int8_t fc_spc; /* sectors per cluster */ 00103 u_int16_t fc_reserved; 00104 u_int8_t fc_fats_num; 00105 u_int16_t fc_root; 00106 u_int16_t fc_sectors_16b; 00107 u_int8_t fc_media; 00108 u_int16_t fc_fatsz_16b; 00109 u_int16_t fc_spt; /* sectors per track */ 00110 u_int16_t fc_heads; 00111 u_int32_t fc_hidden; 00112 u_int32_t fc_sectors_32b; 00113 00114 union 00115 { 00116 t_fat16 fc_fat16; 00117 t_fat32 fc_fat32; 00118 } u_fat_spe; 00119 } __attribute__((packed)) t_fat_common; 00120 00121 typedef struct s_fat_lookup 00122 { 00123 u_int32_t l_addr; 00124 u_int32_t l_addroff; 00125 u_int32_t l_data; 00126 t_fat_direntry l_dir; 00127 } t_fat_lookup; 00128 00129 typedef struct s_fat_sb 00130 { 00131 00132 #define FAT_TYPE_UNKNOWN 0x0 00133 #define FAT_TYPE_FAT12 0x1 00134 #define FAT_TYPE_FAT16 0x2 00135 #define FAT_TYPE_FAT32 0x3 00136 00137 u_int8_t sb_type; 00138 00139 #define FAT_MEDIA_UNKNOWN 0x0 00140 #define FAT_MEDIA_FIXED 0x1 00141 #define FAT_MEDIA_REMOVABLE 0x2 00142 00143 u_int8_t sb_media; 00144 00145 u_int32_t sb_bpc; /* bytes per cluster */ 00146 u_int16_t sb_bps; 00147 u_int8_t sb_spc; 00148 u_int16_t sb_spt; 00149 u_int16_t sb_heads; 00150 00151 u_int32_t sb_sectors; 00152 u_int32_t sb_fatsz; /* sectors by fat */ 00153 00154 u_int32_t sb_fat_start; 00155 u_int32_t sb_fat_size; 00156 00157 u_int16_t sb_root; 00158 u_int32_t sb_rootsz; /* root directory sectors */ 00159 00160 u_int32_t sb_fds; /* first data sector */ 00161 u_int32_t sb_data_sectors; 00162 u_int32_t sb_data_clusters; 00163 00164 u_int32_t sb_root_num; 00165 } t_fat_sb; 00166 00167 typedef struct s_fat_cache 00168 { 00169 u_int32_t offset; 00170 void *buffer; 00171 } t_fat_cache; 00172 00173 typedef struct s_fat_fs 00174 { 00175 /* 00176 * owner of the mounted filesystem 00177 */ 00178 00179 u_int32_t fs_uid; 00180 u_int32_t fs_gid; 00181 00182 /* 00183 * device 00184 */ 00185 00186 u_int32_t fs_dev; 00187 00188 /* 00189 * part 00190 */ 00191 00192 u_int32_t fs_pdev; 00193 u_int32_t fs_id; 00194 u_int32_t fs_unit; 00195 00196 u_int32_t fs_start; 00197 u_int32_t fs_size; 00198 00199 /* 00200 * fat superblock 00201 */ 00202 00203 t_fat_sb fs_sb; 00204 00205 /* 00206 * fat cache 00207 */ 00208 00209 t_fat_cache fs_cache[FAT_CACHESZ]; 00210 } t_fat_fs; 00211 00212 typedef struct s_fat 00213 { 00214 __cpu_simple_lock_t f_lock; 00215 } t_fat; 00216 00217 /* ---------------------------------------------------------*/ 00218 00219 typedef struct s_fat_fd 00220 { 00221 u_int8_t fd_state; 00222 u_int32_t fd_type; 00223 00224 u_int32_t fd_addr; 00225 u_int32_t fd_addroff; 00226 00227 u_int32_t fd_data; 00228 u_int32_t fd_size; 00229 00230 u_int32_t fd_offset; 00231 } t_fat_fd; 00232 00233 void sys_fat(void); 00234 00235 /* PROTO main.c */ 00236 #ifdef KERNEL 00237 /* main.c */ 00238 #endif /* KERNEL */ 00239 #endif