make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / include / linux / hfs_fs.h
1 /* 
2  * linux/include/linux/hfs_fs.h
3  *
4  * Copyright (C) 1995-1997  Paul H. Hargrove
5  * This file may be distributed under the terms of the GNU General Public License.
6  *
7  * The source code distribution of the Columbia AppleTalk Package for
8  * UNIX, version 6.0, (CAP) was used as a specification of the
9  * location and format of files used by CAP's Aufs.  No code from CAP
10  * appears in hfs_fs.  hfs_fs is not a work ``derived'' from CAP in
11  * the sense of intellectual property law.
12  *
13  * The source code distributions of Netatalk, versions 1.3.3b2 and
14  * 1.4b2, were used as a specification of the location and format of
15  * files used by Netatalk's afpd.  No code from Netatalk appears in
16  * hfs_fs.  hfs_fs is not a work ``derived'' from Netatalk in the
17  * sense of intellectual property law.
18  */
19
20 #ifndef _LINUX_HFS_FS_H
21 #define _LINUX_HFS_FS_H
22
23 #include <linux/hfs_sysdep.h>
24
25 /* magic numbers for Apple Double header files */
26 #define HFS_DBL_MAGIC           0x00051607
27 #define HFS_SNGL_MAGIC          0x00051600
28 #define HFS_HDR_VERSION_1       0x00010000
29 #define HFS_HDR_VERSION_2       0x00020000
30
31 /* magic numbers for various internal structures */
32 #define HFS_INO_MAGIC           0x4821
33 #define HFS_SB_MAGIC            0x4822
34
35 /* The space used for the AppleDouble or AppleSingle headers */
36 #define HFS_DBL_HDR_LEN         1024
37
38 /* The space used for the Netatalk header */
39 #define HFS_NAT_HDR_LEN         1024  /* 589 for an exact match */
40
41 /* Macros to extract CNID and file "type" from the Linux inode number */
42 #define HFS_CNID(X)     ((X) & 0x3FFFFFFF)
43 #define HFS_ITYPE(X)    ((X) & 0xC0000000)
44
45 /* Macros to enumerate types */
46 #define HFS_ITYPE_TO_INT(X)     ((X) >> 30)
47 #define HFS_INT_TO_ITYPE(X)     ((X) << 30)
48
49 /* generic ITYPEs */
50 #define HFS_ITYPE_0     0x00000000
51 #define HFS_ITYPE_1     0x40000000
52 #define HFS_ITYPE_2     0x80000000
53 #define HFS_ITYPE_3     0xC0000000
54 #define HFS_ITYPE_NORM  HFS_ITYPE_0     /* "normal" directory or file */
55
56 /* ITYPEs for CAP */
57 #define HFS_CAP_NORM    HFS_ITYPE_0     /* data fork or normal directory */
58 #define HFS_CAP_DATA    HFS_ITYPE_0     /* data fork of file */
59 #define HFS_CAP_NDIR    HFS_ITYPE_0     /* normal directory */
60 #define HFS_CAP_FNDR    HFS_ITYPE_1     /* finder info for file or dir */
61 #define HFS_CAP_RSRC    HFS_ITYPE_2     /* resource fork of file */
62 #define HFS_CAP_RDIR    HFS_ITYPE_2     /* .resource directory */
63 #define HFS_CAP_FDIR    HFS_ITYPE_3     /* .finderinfo directory */
64
65 /* ITYPEs for Apple Double */
66 #define HFS_DBL_NORM    HFS_ITYPE_0     /* data fork or directory */
67 #define HFS_DBL_DATA    HFS_ITYPE_0     /* data fork of file */
68 #define HFS_DBL_DIR     HFS_ITYPE_0     /* directory */
69 #define HFS_DBL_HDR     HFS_ITYPE_1     /* AD header of file or dir */
70
71 /* ITYPEs for netatalk */
72 #define HFS_NAT_NORM    HFS_ITYPE_0     /* data fork or directory */
73 #define HFS_NAT_DATA    HFS_ITYPE_0     /* data fork of file */
74 #define HFS_NAT_NDIR    HFS_ITYPE_0     /* normal directory */
75 #define HFS_NAT_HDR     HFS_ITYPE_1     /* AD header of file or dir */
76 #define HFS_NAT_HDIR    HFS_ITYPE_2     /* directory holding AD headers */
77
78 /* ITYPEs for Apple Single */
79 #define HFS_SGL_NORM    HFS_ITYPE_0     /* AppleSingle file or directory */
80 #define HFS_SGL_SNGL    HFS_ITYPE_0     /* AppleSingle file */
81 #define HFS_SGL_DIR     HFS_ITYPE_0     /* directory */
82 #define HFS_SGL_DINF    HFS_ITYPE_1     /* %DirInfo for directory */
83
84 /* IDs for elements of an AppleDouble or AppleSingle header */
85 #define HFS_HDR_DATA    1   /* data fork */
86 #define HFS_HDR_RSRC    2   /* resource fork */
87 #define HFS_HDR_FNAME   3   /* full (31-character) name */
88 #define HFS_HDR_COMNT   4   /* comment */
89 #define HFS_HDR_BWICN   5   /* b/w icon */
90 #define HFS_HDR_CICON   6   /* color icon info */
91 #define HFS_HDR_OLDI    7   /* old file info */
92 #define HFS_HDR_DATES   8   /* file dates info */
93 #define HFS_HDR_FINFO   9   /* Finder info */
94 #define HFS_HDR_MACI    10  /* Macintosh info */
95 #define HFS_HDR_PRODOSI 11  /* ProDOS info */
96 #define HFS_HDR_MSDOSI  12  /* MSDOS info */
97 #define HFS_HDR_SNAME   13  /* short name */
98 #define HFS_HDR_AFPI    14  /* AFP file info */
99 #define HFS_HDR_DID     15  /* directory id */
100 #define HFS_HDR_MAX     16
101
102 /*
103  * There are three time systems.  All three are based on seconds since
104  * a particular time/date.
105  *      Unix:   unsigned lil-endian since 00:00 GMT, Jan. 1, 1970
106  *      mac:    unsigned big-endian since 00:00 GMT, Jan. 1, 1904
107  *      header:   SIGNED big-endian since 00:00 GMT, Jan. 1, 2000
108  *
109  */
110 #define hfs_h_to_mtime(ARG)     htonl((hfs_s32)ntohl(ARG)+3029529600U)
111 #define hfs_m_to_htime(ARG)     ((hfs_s32)htonl(ntohl(ARG)-3029529600U))
112 #define hfs_h_to_utime(ARG)     ((hfs_s32)hfs_to_utc(ntohl(ARG)+946684800U))
113 #define hfs_u_to_htime(ARG)     ((hfs_s32)htonl(hfs_from_utc(ARG)-946684800U))
114 #define hfs_u_to_mtime(ARG)     htonl(hfs_from_utc(ARG)+2082844800U)
115 #define hfs_m_to_utime(ARG)     (hfs_to_utc(ntohl(ARG)-2082844800U))
116
117 /*======== Data structures kept in memory ========*/
118
119 /*
120  * A descriptor for a single entry within the header of an
121  * AppleDouble or AppleSingle header file.
122  * An array of these make up a table of contents for the file.
123  */
124 struct hfs_hdr_descr {
125         hfs_u32 id;     /* The Apple assigned ID for the entry type */
126         hfs_u32 offset; /* The offset to reach the entry */
127         hfs_u32 length; /* The length of the entry */
128 };
129
130 /*
131  * The info needed to reconstruct a given header layout
132  */
133 struct hfs_hdr_layout {
134         hfs_u32         magic;                  /* AppleSingle or AppleDouble */
135         hfs_u32         version;                /* 0x00010000 or 0x00020000 */
136         hfs_u16         entries;                /* How many entries used */
137         struct hfs_hdr_descr    
138                         descr[HFS_HDR_MAX];     /* Descriptors */
139         struct hfs_hdr_descr    
140                         *order[HFS_HDR_MAX];    /* 'descr' ordered by offset */
141 };
142
143 /* header layout for netatalk's v1 appledouble file format */
144 struct hfs_nat_hdr {
145         hfs_lword_t     magic;
146         hfs_lword_t     version;
147         hfs_byte_t      homefs[16];
148         hfs_word_t      entries;
149         hfs_byte_t      descrs[12*5];
150         hfs_byte_t      real_name[255]; /* id=3 */
151         hfs_byte_t      comment[200];   /* id=4 XXX: not yet implemented */
152         hfs_byte_t      old_info[16];   /* id=7 */
153         hfs_u8          finderinfo[32]; /* id=9 */
154 };
155
156 /* 
157  * Default header layout for Netatalk and AppleDouble
158  */
159 struct hfs_dbl_hdr {
160         hfs_lword_t     magic;
161         hfs_lword_t     version;
162         hfs_byte_t      filler[16];
163         hfs_word_t      entries;
164         hfs_byte_t      descrs[12*HFS_HDR_MAX];
165         hfs_byte_t      real_name[255]; /* id=3 */
166         hfs_byte_t      comment[200];   /* id=4 XXX: not yet implemented */
167         hfs_u32         create_time;    /* \              */
168         hfs_u32         modify_time;    /*  | id=8 (or 7) */
169         hfs_u32         backup_time;    /*  |             */
170         hfs_u32         access_time;    /* /  (attributes with id=7) */
171         hfs_u8          finderinfo[32]; /* id=9 */
172         hfs_u32         fileinfo;       /* id=10 */
173         hfs_u32         cnid;           /* id=15 */
174         hfs_u8          short_name[12]; /* id=13 */
175         hfs_u8          prodosi[8];     /* id=11 */
176 };
177
178
179 /* finder metadata for CAP */
180 struct hfs_cap_info {
181         hfs_byte_t      fi_fndr[32];    /* Finder's info */
182         hfs_word_t      fi_attr;        /* AFP attributes (f=file/d=dir) */
183 #define HFS_AFP_INV             0x001   /* Invisible bit (f/d) */
184 #define HFS_AFP_EXPFOLDER       0x002   /* exported folder (d) */
185 #define HFS_AFP_MULTI           0x002   /* Multiuser bit (f) */
186 #define HFS_AFP_SYS             0x004   /* System bit (f/d) */
187 #define HFS_AFP_DOPEN           0x008   /* data fork already open (f) */
188 #define HFS_AFP_MOUNTED         0x008   /* mounted folder (d) */
189 #define HFS_AFP_ROPEN           0x010   /* resource fork already open (f) */
190 #define HFS_AFP_INEXPFOLDER     0x010   /* folder in shared area (d) */
191 #define HFS_AFP_WRI             0x020   /* Write inhibit bit (readonly) (f) */
192 #define HFS_AFP_BACKUP          0x040   /* backup needed bit (f/d)  */
193 #define HFS_AFP_RNI             0x080   /* Rename inhibit bit (f/d) */
194 #define HFS_AFP_DEI             0x100   /* Delete inhibit bit (f/d) */
195 #define HFS_AFP_NOCOPY          0x400   /* Copy protect bit (f) */
196 #define HFS_AFP_RDONLY  (       HFS_AFP_WRI|HFS_AFP_RNI|HFS_AFP_DEI)
197         hfs_byte_t      fi_magic1;      /* Magic number: */
198 #define HFS_CAP_MAGIC1          0xFF
199         hfs_byte_t      fi_version;     /* Version of this structure: */
200 #define HFS_CAP_VERSION         0x10
201         hfs_byte_t      fi_magic;       /* Another magic number: */
202 #define HFS_CAP_MAGIC           0xDA
203         hfs_byte_t      fi_bitmap;      /* Bitmap of which names are valid: */
204 #define HFS_CAP_SHORTNAME       0x01
205 #define HFS_CAP_LONGNAME        0x02
206         hfs_byte_t      fi_shortfilename[12+1]; /* "short name" (unused) */
207         hfs_byte_t      fi_macfilename[32+1];   /* Original (Macintosh) name */
208         hfs_byte_t      fi_comln;       /* Length of comment (always 0) */
209         hfs_byte_t      fi_comnt[200];  /* Finder comment (unused) */
210         /* optional:    used by aufs only if compiled with USE_MAC_DATES */
211         hfs_byte_t      fi_datemagic;   /* Magic number for dates extension: */
212 #define HFS_CAP_DMAGIC          0xDA
213         hfs_byte_t      fi_datevalid;   /* Bitmap of which dates are valid: */
214 #define HFS_CAP_MDATE           0x01
215 #define HFS_CAP_CDATE           0x02
216         hfs_lword_t     fi_ctime;       /* Creation date (in AFP format) */
217         hfs_lword_t     fi_mtime;       /* Modify date (in AFP format) */
218         hfs_lword_t     fi_utime;       /* Un*x time of last mtime change */
219         hfs_byte_t      pad;
220 };
221
222 #ifdef __KERNEL__
223
224 typedef ssize_t hfs_rwret_t;
225 typedef size_t hfs_rwarg_t;
226
227 #include <asm/uaccess.h>
228
229 /* Some forward declarations */
230 struct hfs_fork;
231 struct hfs_cat_key;
232 struct hfs_cat_entry;
233 extern struct hfs_cat_entry *hfs_cat_get(struct hfs_mdb *,
234                                          const struct hfs_cat_key *);
235
236 /* dir.c */
237 extern int hfs_create(struct inode *, struct dentry *, int);
238 extern int hfs_mkdir(struct inode *, struct dentry *, int);
239 extern int hfs_unlink(struct inode *, struct dentry *);
240 extern int hfs_rmdir(struct inode *, struct dentry *);
241 extern int hfs_rename(struct inode *, struct dentry *,
242                       struct inode *, struct dentry *);
243
244 /* dir_cap.c */
245 extern const struct hfs_name hfs_cap_reserved1[];
246 extern const struct hfs_name hfs_cap_reserved2[];
247 extern struct inode_operations hfs_cap_ndir_inode_operations;
248 extern struct inode_operations hfs_cap_fdir_inode_operations;
249 extern struct inode_operations hfs_cap_rdir_inode_operations;
250 extern struct file_operations hfs_cap_dir_operations;
251 extern void hfs_cap_drop_dentry(struct dentry *, const ino_t);
252
253 /* dir_dbl.c */
254 extern const struct hfs_name hfs_dbl_reserved1[];
255 extern const struct hfs_name hfs_dbl_reserved2[];
256 extern struct inode_operations hfs_dbl_dir_inode_operations;
257 extern struct file_operations hfs_dbl_dir_operations;
258 extern void hfs_dbl_drop_dentry(struct dentry *, const ino_t);
259
260 /* dir_nat.c */
261 extern const struct hfs_name hfs_nat_reserved1[];
262 extern const struct hfs_name hfs_nat_reserved2[];
263 extern struct inode_operations hfs_nat_ndir_inode_operations;
264 extern struct inode_operations hfs_nat_hdir_inode_operations;
265 extern struct file_operations hfs_nat_dir_operations;
266 extern void hfs_nat_drop_dentry(struct dentry *, const ino_t);
267
268 /* file.c */
269 extern hfs_s32 hfs_do_read(struct inode *, struct hfs_fork *, hfs_u32,
270                            char *, hfs_u32, int);
271 extern hfs_s32 hfs_do_write(struct inode *, struct hfs_fork *, hfs_u32,
272                             const char *, hfs_u32);
273 extern void hfs_file_fix_mode(struct hfs_cat_entry *entry);
274 extern struct inode_operations hfs_file_inode_operations;
275 extern struct file_operations hfs_file_operations;
276
277 /* file_cap.c */
278 extern struct inode_operations hfs_cap_info_inode_operations;
279 extern struct file_operations hfs_cap_info_operations;
280
281 /* file_hdr.c */
282 extern struct inode_operations hfs_hdr_inode_operations;
283 extern struct file_operations hfs_hdr_operations;
284 extern const struct hfs_hdr_layout hfs_dbl_fil_hdr_layout;
285 extern const struct hfs_hdr_layout hfs_dbl_dir_hdr_layout;
286 extern const struct hfs_hdr_layout hfs_nat_hdr_layout;
287 extern const struct hfs_hdr_layout hfs_nat2_hdr_layout;
288 extern const struct hfs_hdr_layout hfs_sngl_hdr_layout;
289 extern void hdr_truncate(struct inode *,size_t);
290
291 /* inode.c */
292 extern void hfs_put_inode(struct inode *);
293 extern int hfs_notify_change(struct dentry *, struct iattr *);
294 extern int hfs_notify_change_cap(struct dentry *, struct iattr *);
295 extern int hfs_notify_change_hdr(struct dentry *, struct iattr *);
296 extern struct inode *hfs_iget(struct hfs_cat_entry *, ino_t, struct dentry *);
297
298 extern void hfs_cap_ifill(struct inode *, ino_t, const int);
299 extern void hfs_dbl_ifill(struct inode *, ino_t, const int);
300 extern void hfs_nat_ifill(struct inode *, ino_t, const int);
301 extern void hfs_sngl_ifill(struct inode *, ino_t, const int);
302
303 /* super.c */
304 extern struct super_block *hfs_read_super(struct super_block *,void *,int);
305
306 /* trans.c */
307 extern void hfs_colon2mac(struct hfs_name *, const char *, int);
308 extern void hfs_prcnt2mac(struct hfs_name *, const char *, int);
309 extern void hfs_triv2mac(struct hfs_name *, const char *, int);
310 extern void hfs_latin2mac(struct hfs_name *, const char *, int);
311 extern int hfs_mac2cap(char *, const struct hfs_name *);
312 extern int hfs_mac2nat(char *, const struct hfs_name *);
313 extern int hfs_mac2latin(char *, const struct hfs_name *);
314 extern int hfs_mac2seven(char *, const struct hfs_name *);
315 extern int hfs_mac2eight(char *, const struct hfs_name *);
316 extern int hfs_mac2alpha(char *, const struct hfs_name *);
317 extern int hfs_mac2triv(char *, const struct hfs_name *);
318 extern void hfs_tolower(unsigned char *, int);
319
320 #define HFS_I(X)        (&((X)->u.hfs_i))
321 #define HFS_SB(X)       (&((X)->u.hfs_sb))
322
323 static inline void hfs_nameout(struct inode *dir, struct hfs_name *out,
324                                    const char *in, int len) {
325         HFS_SB(dir->i_sb)->s_nameout(out, in, len);
326 }
327
328 static inline int hfs_namein(struct inode *dir, char *out,
329                                  const struct hfs_name *in) {
330         int len = HFS_SB(dir->i_sb)->s_namein(out, in);
331         if (HFS_SB(dir->i_sb)->s_lowercase) {
332                 hfs_tolower(out, len);
333         }
334         return len;
335 }
336
337 #endif /* __KERNEL__ */
338 #endif