Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 *
3
 *
4
 *
5
 */
6
 
7
#ifndef __MSDOS_H__
8
#define __MSDOS_H__
9
 
10
#include "dentry.h"
11
#include "inode.h"
12
#include "super.h"
13
 
14
#include "dentryop.h"
15
#include "inodeop.h"
16
#include "superop.h"
17
 
18
extern struct dentry_operations msdos_dentry_operations;
19
extern struct inode_operations  msdos_inode_ro_operations;
20
extern struct file_operations   msdos_file_ro_operations;
21
extern struct super_operations  msdos_super_operations;
22
 
23
extern struct inode_operations  msdos_inode_rw_operations;
24
extern struct file_operations   msdos_file_rw_operations;
25
 
26
/*
27
 * directory entry
28
 */
29
 
30
#define ATTR_RDONLY 0x01
31
#define ATTR_HIDDEN 0x02
32
#define ATTR_SYSTEM 0x04
33
#define ATTR_VOLUME 0x08
34
#define ATTR_DIR    0x10
35
#define ATTR_ARCH   0x20
36
 
37
struct directoryentry {
38
  __uint8_t  name[8];
39
  __uint8_t  ext[3];
40
  __uint8_t  attribute;
41
  __uint8_t  reserved[10];
42
  __uint16_t time;
43
  __uint16_t date;
44
  __uint16_t cluster;
45
  __uint32_t size;
46
} __attribute__ ((packed));
47
 
48
/* for debugging */
49
extern void msdos_dump_direntry(struct directoryentry *ptr);
50
 
51
/* directory entry types */
52
 
53
#define LASTENTRYCHAR   0x00
54
#define ERASEDENTRYCHAR 0xe5
55
 
56
extern __inline__ int msdos_islastentry(struct directoryentry *de)
57
{
58
  return (*((de)->name)==LASTENTRYCHAR);
59
}
60
 
61
extern __inline__ int msdos_isfreeentry(struct directoryentry *de)
62
{
63
  return (*((de)->name)==LASTENTRYCHAR||
64
          *((de)->name)==ERASEDENTRYCHAR);
65
}
66
 
67
extern __inline__ int msdos_isunvalidentry(struct directoryentry *de)
68
{
69
  return (*((de)->name)==ERASEDENTRYCHAR)||
70
    ((de)->attribute&ATTR_VOLUME)||
71
    (msdos_islastentry(de));
72
}
73
 
74
extern __inline__ void msdos_markentrybusy(struct directoryentry *de)
75
{
76
  *((de)->name)='~';
77
}
78
 
79
extern __inline__ void msdos_markentryfree(struct directoryentry *de)
80
{
81
  *((de)->name)=ERASEDENTRYCHAR;
82
}
83
 
84
/* */
85
extern int msdos_formatname(struct directoryentry *de, struct qstr *str);
86
 
87
/*
88
 * constants
89
 */
90
 
91
#define CLUSTER_MASK    0xffff0000
92
#define CLUSTER_SHIFT   16
93
#define DENTRY_MASK     0x0000ffff
94
#define DENTRY_SHIFT    0
95
 
96
#define ROOT_CLUSTER    0x0000
97
#define SPECIAL_CLUSTER 0x0001
98
#define FREE_CLUSTER    0xfffe
99
#define NO_CLUSTER      0xffff
100
 
101
#define DIRENTRYSIZE    32
102
#define SECTORSIZE      512
103
 
104
/* first cluster of a msdos volume */
105
#define STARTCLUSTER    2
106
 
107
/* these on msdos directory structure */
108
#define FREECLUSTER 0x0000
109
#define LASTCLUSTER 0xffff
110
#define BADCLUSTER  0xfff7
111
 
112
/* max numbers of fats for volume (that must be supported) */
113
#define MAXFATS         4
114
/*
115
 * 0x01230008 e' la 8' entry del 123 cluster
116
 * 0x00000000 e' la root dir (non ha entry)
117
 * 0x00010005 e' la 5' entry nella root
118
 */
119
 
120
#define CLUOFF2INODE(cluster,deoffs) ((((__uint32_t)cluster)<<CLUSTER_SHIFT)|\
121
                                       ((deoffs)&DENTRY_MASK)\
122
                                       )
123
#define INODE2CLUSTER(inode) ((__uint16_t)((inode)>>CLUSTER_SHIFT))
124
#define INODE2DEOFFS(inode)  ((__uint16_t)((inode)&DENTRY_MASK))
125
 
126
#define ROOT_INODE      CLUOFF2INODE(ROOT_CLUSTER,0)
127
 
128
/*
129
 *
130
 */
131
 
132
/* what is the logical sector of a cluster */
133
extern __inline__ __uint32_t msdos_cluster2sector(struct inode *in,
134
                                                  __uint16_t cluster)
135
{
136
  if (cluster==NO_CLUSTER||
137
      cluster==SPECIAL_CLUSTER||
138
      cluster==FREE_CLUSTER) return (__uint32_t)(-1);
139
  if (cluster==ROOT_CLUSTER) return MSDOS_SB(in->i_sb).lroot;
140
  return (cluster-2)*MSDOS_SB(in->i_sb).spc+MSDOS_SB(in->i_sb).ldata;  
141
}
142
 
143
/*
144
#define msdos_cluster2sector(in,cl) \
145
( \
146
 ((cl)==NO_CLUSTER||(cl)==SPECIAL_CLUSTER||(cl)==FREE_CLUSTER)? \
147
 (-1): \
148
 ( \
149
  ((cl)==ROOT_CLUSTER?) \
150
  MSDOS_SB((in-)>i_sb).lroot: \
151
  ((cl)-2)*MSDOS_SB((in)->i_sb).spc+MSDOS_SB((in)->i_sb).ldata \
152
 ) \
153
)
154
*/
155
 
156
__uint32_t msdos_cluster2sector(struct inode *in, __uint16_t cluster);
157
 
158
__uint16_t msdos_nextcluster(struct super_block *sb, __uint16_t cluster);
159
void msdos_freecluster(struct super_block *sb, __uint16_t cluster);
160
void msdos_lastcluster(struct super_block *sb, __uint16_t cluster);
161
__uint16_t msdos_addcluster(struct super_block *sb, __uint16_t lacluster);
162
void msdos_freeclusterchain(struct super_block *sb, __uint16_t cluster);
163
 
164
#endif