Subversion Repositories shark

Rev

Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1063 tullio 1
 
2 pj 2
/*
1063 tullio 3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
2 pj 7
 *
1063 tullio 8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
2 pj 12
 *
1063 tullio 13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2 pj 16
 *
17
 */
18
 
1063 tullio 19
 
2 pj 20
#ifndef __MSDOS_H__
21
#define __MSDOS_H__
22
 
23
#include "dentry.h"
24
#include "inode.h"
25
#include "super.h"
26
 
27
#include "dentryop.h"
28
#include "inodeop.h"
29
#include "superop.h"
30
 
31
extern struct dentry_operations msdos_dentry_operations;
32
extern struct inode_operations  msdos_inode_ro_operations;
33
extern struct file_operations   msdos_file_ro_operations;
34
extern struct super_operations  msdos_super_operations;
35
 
36
extern struct inode_operations  msdos_inode_rw_operations;
37
extern struct file_operations   msdos_file_rw_operations;
38
 
39
/*
40
 * directory entry
41
 */
42
 
43
#define ATTR_RDONLY 0x01
44
#define ATTR_HIDDEN 0x02
45
#define ATTR_SYSTEM 0x04
46
#define ATTR_VOLUME 0x08
47
#define ATTR_DIR    0x10
48
#define ATTR_ARCH   0x20
49
 
50
struct directoryentry {
51
  __uint8_t  name[8];
52
  __uint8_t  ext[3];
53
  __uint8_t  attribute;
54
  __uint8_t  reserved[10];
55
  __uint16_t time;
56
  __uint16_t date;
57
  __uint16_t cluster;
58
  __uint32_t size;
59
} __attribute__ ((packed));
60
 
61
/* for debugging */
62
extern void msdos_dump_direntry(struct directoryentry *ptr);
63
 
64
/* directory entry types */
65
 
66
#define LASTENTRYCHAR   0x00
67
#define ERASEDENTRYCHAR 0xe5
68
 
69
extern __inline__ int msdos_islastentry(struct directoryentry *de)
70
{
71
  return (*((de)->name)==LASTENTRYCHAR);
72
}
73
 
74
extern __inline__ int msdos_isfreeentry(struct directoryentry *de)
75
{
76
  return (*((de)->name)==LASTENTRYCHAR||
77
          *((de)->name)==ERASEDENTRYCHAR);
78
}
79
 
80
extern __inline__ int msdos_isunvalidentry(struct directoryentry *de)
81
{
82
  return (*((de)->name)==ERASEDENTRYCHAR)||
83
    ((de)->attribute&ATTR_VOLUME)||
84
    (msdos_islastentry(de));
85
}
86
 
87
extern __inline__ void msdos_markentrybusy(struct directoryentry *de)
88
{
89
  *((de)->name)='~';
90
}
91
 
92
extern __inline__ void msdos_markentryfree(struct directoryentry *de)
93
{
94
  *((de)->name)=ERASEDENTRYCHAR;
95
}
96
 
97
/* */
98
extern int msdos_formatname(struct directoryentry *de, struct qstr *str);
99
 
100
/*
101
 * constants
102
 */
103
 
104
#define CLUSTER_MASK    0xffff0000
105
#define CLUSTER_SHIFT   16
106
#define DENTRY_MASK     0x0000ffff
107
#define DENTRY_SHIFT    0
108
 
109
#define ROOT_CLUSTER    0x0000
110
#define SPECIAL_CLUSTER 0x0001
111
#define FREE_CLUSTER    0xfffe
112
#define NO_CLUSTER      0xffff
113
 
114
#define DIRENTRYSIZE    32
115
#define SECTORSIZE      512
116
 
117
/* first cluster of a msdos volume */
118
#define STARTCLUSTER    2
119
 
120
/* these on msdos directory structure */
121
#define FREECLUSTER 0x0000
122
#define LASTCLUSTER 0xffff
123
#define BADCLUSTER  0xfff7
124
 
125
/* max numbers of fats for volume (that must be supported) */
126
#define MAXFATS         4
127
/*
128
 * 0x01230008 e' la 8' entry del 123 cluster
129
 * 0x00000000 e' la root dir (non ha entry)
130
 * 0x00010005 e' la 5' entry nella root
131
 */
132
 
133
#define CLUOFF2INODE(cluster,deoffs) ((((__uint32_t)cluster)<<CLUSTER_SHIFT)|\
134
                                       ((deoffs)&DENTRY_MASK)\
135
                                       )
136
#define INODE2CLUSTER(inode) ((__uint16_t)((inode)>>CLUSTER_SHIFT))
137
#define INODE2DEOFFS(inode)  ((__uint16_t)((inode)&DENTRY_MASK))
138
 
139
#define ROOT_INODE      CLUOFF2INODE(ROOT_CLUSTER,0)
140
 
141
/*
142
 *
143
 */
144
 
145
/* what is the logical sector of a cluster */
146
extern __inline__ __uint32_t msdos_cluster2sector(struct inode *in,
147
                                                  __uint16_t cluster)
148
{
149
  if (cluster==NO_CLUSTER||
150
      cluster==SPECIAL_CLUSTER||
151
      cluster==FREE_CLUSTER) return (__uint32_t)(-1);
152
  if (cluster==ROOT_CLUSTER) return MSDOS_SB(in->i_sb).lroot;
153
  return (cluster-2)*MSDOS_SB(in->i_sb).spc+MSDOS_SB(in->i_sb).ldata;  
154
}
155
 
156
/*
157
#define msdos_cluster2sector(in,cl) \
158
( \
159
 ((cl)==NO_CLUSTER||(cl)==SPECIAL_CLUSTER||(cl)==FREE_CLUSTER)? \
160
 (-1): \
161
 ( \
162
  ((cl)==ROOT_CLUSTER?) \
163
  MSDOS_SB((in-)>i_sb).lroot: \
164
  ((cl)-2)*MSDOS_SB((in)->i_sb).spc+MSDOS_SB((in)->i_sb).ldata \
165
 ) \
166
)
167
*/
168
 
169
__uint32_t msdos_cluster2sector(struct inode *in, __uint16_t cluster);
170
 
171
__uint16_t msdos_nextcluster(struct super_block *sb, __uint16_t cluster);
172
void msdos_freecluster(struct super_block *sb, __uint16_t cluster);
173
void msdos_lastcluster(struct super_block *sb, __uint16_t cluster);
174
__uint16_t msdos_addcluster(struct super_block *sb, __uint16_t lacluster);
175
void msdos_freeclusterchain(struct super_block *sb, __uint16_t cluster);
176
 
177
#endif