17336d0e6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2b3b94faaSDavid Teigland /*
3b3b94faaSDavid Teigland * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
43a8a9a10SSteven Whitehouse * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5b3b94faaSDavid Teigland */
6b3b94faaSDavid Teigland
7b3b94faaSDavid Teigland #ifndef __DIR_DOT_H__
8b3b94faaSDavid Teigland #define __DIR_DOT_H__
9b3b94faaSDavid Teigland
10f2f7ba52SSteven Whitehouse #include <linux/dcache.h>
11b5289681SSteven Whitehouse #include <linux/crc32.h>
12f2f7ba52SSteven Whitehouse
13f2f7ba52SSteven Whitehouse struct inode;
14f2f7ba52SSteven Whitehouse struct gfs2_inode;
15f2f7ba52SSteven Whitehouse struct gfs2_inum;
162b47dad8SSteven Whitehouse struct buffer_head;
172b47dad8SSteven Whitehouse struct gfs2_dirent;
18f2f7ba52SSteven Whitehouse
193c1c0ae1SSteven Whitehouse struct gfs2_diradd {
203c1c0ae1SSteven Whitehouse unsigned nr_blocks;
212b47dad8SSteven Whitehouse struct gfs2_dirent *dent;
222b47dad8SSteven Whitehouse struct buffer_head *bh;
2319aeb5a6SBob Peterson int save_loc;
243c1c0ae1SSteven Whitehouse };
253c1c0ae1SSteven Whitehouse
26*d312fbf6SAndreas Gruenbacher struct inode *gfs2_dir_search(struct inode *dir,
275a00f3ccSSteven Whitehouse const struct qstr *filename,
285a00f3ccSSteven Whitehouse bool fail_on_exist);
29*d312fbf6SAndreas Gruenbacher int gfs2_dir_check(struct inode *dir, const struct qstr *filename,
30dbb7cae2SSteven Whitehouse const struct gfs2_inode *ip);
31*d312fbf6SAndreas Gruenbacher int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
322b47dad8SSteven Whitehouse const struct gfs2_inode *ip, struct gfs2_diradd *da);
gfs2_dir_no_add(struct gfs2_diradd * da)332b47dad8SSteven Whitehouse static inline void gfs2_dir_no_add(struct gfs2_diradd *da)
342b47dad8SSteven Whitehouse {
352b47dad8SSteven Whitehouse brelse(da->bh);
362b47dad8SSteven Whitehouse da->bh = NULL;
372b47dad8SSteven Whitehouse }
38*d312fbf6SAndreas Gruenbacher int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry);
39*d312fbf6SAndreas Gruenbacher int gfs2_dir_read(struct inode *inode, struct dir_context *ctx,
40d81a8ef5SAl Viro struct file_ra_state *f_ra);
41*d312fbf6SAndreas Gruenbacher int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
42dbb7cae2SSteven Whitehouse const struct gfs2_inode *nip, unsigned int new_type);
43b3b94faaSDavid Teigland
44*d312fbf6SAndreas Gruenbacher int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip);
45b3b94faaSDavid Teigland
46*d312fbf6SAndreas Gruenbacher int gfs2_diradd_alloc_required(struct inode *dir,
473c1c0ae1SSteven Whitehouse const struct qstr *filename,
483c1c0ae1SSteven Whitehouse struct gfs2_diradd *da);
49*d312fbf6SAndreas Gruenbacher int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block,
5018ec7d5cSSteven Whitehouse struct buffer_head **bhp);
51*d312fbf6SAndreas Gruenbacher void gfs2_dir_hash_inval(struct gfs2_inode *ip);
52b3b94faaSDavid Teigland
gfs2_disk_hash(const char * data,int len)53cd915493SSteven Whitehouse static inline u32 gfs2_disk_hash(const char *data, int len)
5471b86f56SSteven Whitehouse {
552bdbc5d7SSteven Whitehouse return crc32_le((u32)~0, data, len) ^ (u32)~0;
5671b86f56SSteven Whitehouse }
5771b86f56SSteven Whitehouse
5871b86f56SSteven Whitehouse
gfs2_str2qstr(struct qstr * name,const char * fname)5971b86f56SSteven Whitehouse static inline void gfs2_str2qstr(struct qstr *name, const char *fname)
6071b86f56SSteven Whitehouse {
6171b86f56SSteven Whitehouse name->name = fname;
6271b86f56SSteven Whitehouse name->len = strlen(fname);
6371b86f56SSteven Whitehouse name->hash = gfs2_disk_hash(name->name, name->len);
6471b86f56SSteven Whitehouse }
6571b86f56SSteven Whitehouse
66c752666cSSteven Whitehouse /* N.B. This probably ought to take inum & type as args as well */
gfs2_qstr2dirent(const struct qstr * name,u16 reclen,struct gfs2_dirent * dent)67c752666cSSteven Whitehouse static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct gfs2_dirent *dent)
68c752666cSSteven Whitehouse {
69c752666cSSteven Whitehouse dent->de_inum.no_addr = cpu_to_be64(0);
70c752666cSSteven Whitehouse dent->de_inum.no_formal_ino = cpu_to_be64(0);
71c752666cSSteven Whitehouse dent->de_hash = cpu_to_be32(name->hash);
72c752666cSSteven Whitehouse dent->de_rec_len = cpu_to_be16(reclen);
73c752666cSSteven Whitehouse dent->de_name_len = cpu_to_be16(name->len);
74c752666cSSteven Whitehouse dent->de_type = cpu_to_be16(0);
75c752666cSSteven Whitehouse memset(dent->__pad, 0, sizeof(dent->__pad));
762bdbc5d7SSteven Whitehouse memcpy(dent + 1, name->name, name->len);
77c752666cSSteven Whitehouse }
78c752666cSSteven Whitehouse
798d123585SSteven Whitehouse extern struct qstr gfs2_qdot;
808d123585SSteven Whitehouse extern struct qstr gfs2_qdotdot;
818d123585SSteven Whitehouse
82b3b94faaSDavid Teigland #endif /* __DIR_DOT_H__ */
83