[GFS2] Fix bug in directory code and tidy up
[safe/jmp/linux-2.6] / fs / gfs2 / dir.h
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License v.2.
8  */
9
10 #ifndef __DIR_DOT_H__
11 #define __DIR_DOT_H__
12
13 /**
14  * gfs2_filldir_t - Report a directory entry to the caller of gfs2_dir_read()
15  * @opaque: opaque data used by the function
16  * @name: the name of the directory entry
17  * @length: the length of the name
18  * @offset: the entry's offset in the directory
19  * @inum: the inode number the entry points to
20  * @type: the type of inode the entry points to
21  *
22  * Returns: 0 on success, 1 if buffer full
23  */
24
25 typedef int (*gfs2_filldir_t) (void *opaque,
26                               const char *name, unsigned int length,
27                               uint64_t offset,
28                               struct gfs2_inum *inum, unsigned int type);
29
30 int gfs2_dir_search(struct inode *dir, const struct qstr *filename,
31                     struct gfs2_inum *inum, unsigned int *type);
32 int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
33                  const struct gfs2_inum *inum, unsigned int type);
34 int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename);
35 int gfs2_dir_read(struct gfs2_inode *dip, uint64_t * offset, void *opaque,
36                   gfs2_filldir_t filldir);
37 int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
38                    struct gfs2_inum *new_inum, unsigned int new_type);
39
40 int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip);
41
42 int gfs2_diradd_alloc_required(struct inode *dir,
43                                const struct qstr *filename);
44 int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new,
45                         struct buffer_head **bhp);
46
47 /* N.B. This probably ought to take inum & type as args as well */
48 static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct gfs2_dirent *dent)
49 {
50         dent->de_inum.no_addr = cpu_to_be64(0);
51         dent->de_inum.no_formal_ino = cpu_to_be64(0);
52         dent->de_hash = cpu_to_be32(name->hash);
53         dent->de_rec_len = cpu_to_be16(reclen);
54         dent->de_name_len = cpu_to_be16(name->len);
55         dent->de_type = cpu_to_be16(0);
56         memset(dent->__pad, 0, sizeof(dent->__pad));
57         memcpy((char*)(dent+1), name->name, name->len);
58 }
59
60 #endif /* __DIR_DOT_H__ */