xref: /linux/fs/bcachefs/dirent_format.h (revision e91c37f1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_DIRENT_FORMAT_H
3 #define _BCACHEFS_DIRENT_FORMAT_H
4 
5 /*
6  * Dirents (and xattrs) have to implement string lookups; since our b-tree
7  * doesn't support arbitrary length strings for the key, we instead index by a
8  * 64 bit hash (currently truncated sha1) of the string, stored in the offset
9  * field of the key - using linear probing to resolve hash collisions. This also
10  * provides us with the readdir cookie posix requires.
11  *
12  * Linear probing requires us to use whiteouts for deletions, in the event of a
13  * collision:
14  */
15 
16 struct bch_dirent {
17 	struct bch_val		v;
18 
19 	/* Target inode number: */
20 	union {
21 	__le64			d_inum;
22 	struct {		/* DT_SUBVOL */
23 	__le32			d_child_subvol;
24 	__le32			d_parent_subvol;
25 	};
26 	};
27 
28 	/*
29 	 * Copy of mode bits 12-15 from the target inode - so userspace can get
30 	 * the filetype without having to do a stat()
31 	 */
32 	__u8			d_type;
33 
34 	__u8			d_name[];
35 } __packed __aligned(8);
36 
37 #define DT_SUBVOL	16
38 #define BCH_DT_MAX	17
39 
40 #define BCH_NAME_MAX	512
41 
42 #endif /* _BCACHEFS_DIRENT_FORMAT_H */
43