blob: f1f83faa36ecb0f67f45b8eaff54ad6d4e485995 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
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
25typedef int (*gfs2_filldir_t) (void *opaque,
26 const char *name, unsigned int length,
Steven Whitehousecd915492006-09-04 12:49:07 -040027 u64 offset,
David Teiglandb3b94fa2006-01-16 16:50:04 +000028 struct gfs2_inum *inum, unsigned int type);
29
Steven Whitehousec7526662006-03-20 12:30:04 -050030int gfs2_dir_search(struct inode *dir, const struct qstr *filename,
31 struct gfs2_inum *inum, unsigned int *type);
32int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
33 const struct gfs2_inum *inum, unsigned int type);
34int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename);
Steven Whitehousecd915492006-09-04 12:49:07 -040035int gfs2_dir_read(struct inode *inode, u64 * offset, void *opaque,
Steven Whitehousec7526662006-03-20 12:30:04 -050036 gfs2_filldir_t filldir);
37int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
38 struct gfs2_inum *new_inum, unsigned int new_type);
David Teiglandb3b94fa2006-01-16 16:50:04 +000039
40int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip);
41
Steven Whitehousec7526662006-03-20 12:30:04 -050042int gfs2_diradd_alloc_required(struct inode *dir,
43 const struct qstr *filename);
Steven Whitehousecd915492006-09-04 12:49:07 -040044int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block,
Steven Whitehouse61e085a2006-04-24 10:07:13 -040045 struct buffer_head **bhp);
Steven Whitehousec7526662006-03-20 12:30:04 -050046
Steven Whitehousecd915492006-09-04 12:49:07 -040047static inline u32 gfs2_disk_hash(const char *data, int len)
Steven Whitehouse71b86f52006-03-28 14:14:04 -050048{
49 return crc32_le(0xFFFFFFFF, data, len) ^ 0xFFFFFFFF;
50}
51
52
53static inline void gfs2_str2qstr(struct qstr *name, const char *fname)
54{
55 name->name = fname;
56 name->len = strlen(fname);
57 name->hash = gfs2_disk_hash(name->name, name->len);
58}
59
Steven Whitehousec7526662006-03-20 12:30:04 -050060/* N.B. This probably ought to take inum & type as args as well */
61static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct gfs2_dirent *dent)
62{
63 dent->de_inum.no_addr = cpu_to_be64(0);
64 dent->de_inum.no_formal_ino = cpu_to_be64(0);
65 dent->de_hash = cpu_to_be32(name->hash);
66 dent->de_rec_len = cpu_to_be16(reclen);
67 dent->de_name_len = cpu_to_be16(name->len);
68 dent->de_type = cpu_to_be16(0);
69 memset(dent->__pad, 0, sizeof(dent->__pad));
70 memcpy((char*)(dent+1), name->name, name->len);
71}
David Teiglandb3b94fa2006-01-16 16:50:04 +000072
David Teiglandb3b94fa2006-01-16 16:50:04 +000073#endif /* __DIR_DOT_H__ */