1 commit 2db3b2b33ee796f4ea61316773452d936303ad27
2 Author: Pravin Shelar <Pravin.Shelar@sun.com>
3 AuthorDate: Sun Oct 4 18:13:14 2009 +0000
4 Subject: ext4: add ext4-data-in-dirent patch
6 Allows ext4 to store extra data records inside the ext4_dirent
7 along with the regular directory entry (type, length, filename).
8 Data is stored in ext4 dirent after filename, with a bit flag in
9 de->file_type to indicate if any record after de->name is used.
10 Each in-use record is variable length and must store a 1-byte
11 length (including the length byte itself) at the start so that it
12 can be skipped if the record type is unknown/uneeded. The record
13 starts after a NUL byte terminator for the filename. This extra
14 space is accounted in de->rec_len but not de->name_len.
16 Flag EXT4_DIRENT_LUFID is used for a 128-bit file identifier.
17 Make use of dentry->d_fsdata to pass LUFID to ext4, so no changes
18 in ext4_add_entry() interface are required.
21 Signed-off-by: Pravin Shelar <Pravin.Shelar@sun.com>
22 Reviewed-by: Huang Hua <h.huang@sun.com>
23 Signed-off-by: Andreas Dilger <andreas.dilger@sun.com>
25 Index: linux-4.15.0/fs/ext4/dir.c
26 ===================================================================
27 --- linux-4.15.0.orig/fs/ext4/dir.c
28 +++ linux-4.15.0/fs/ext4/dir.c
29 @@ -68,11 +68,11 @@ int __ext4_check_dir_entry(const char *f
30 const int rlen = ext4_rec_len_from_disk(de->rec_len,
31 dir->i_sb->s_blocksize);
33 - if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
34 + if (unlikely(rlen < __EXT4_DIR_REC_LEN(1)))
35 error_msg = "rec_len is smaller than minimal";
36 else if (unlikely(rlen % 4 != 0))
37 error_msg = "rec_len % 4 != 0";
38 - else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
39 + else if (unlikely(rlen < EXT4_DIR_REC_LEN(de)))
40 error_msg = "rec_len is too small for name_len";
41 else if (unlikely(((char *) de - buf) + rlen > size))
42 error_msg = "directory entry across range";
43 @@ -219,7 +219,7 @@ static int ext4_readdir(struct file *fil
44 * failure will be detected in the
45 * dirent test below. */
46 if (ext4_rec_len_from_disk(de->rec_len,
47 - sb->s_blocksize) < EXT4_DIR_REC_LEN(1))
48 + sb->s_blocksize) < __EXT4_DIR_REC_LEN(1))
50 i += ext4_rec_len_from_disk(de->rec_len,
52 @@ -442,12 +442,17 @@ int ext4_htree_store_dirent(struct file
53 struct fname *fname, *new_fn;
54 struct dir_private_info *info;
58 info = dir_file->private_data;
59 p = &info->root.rb_node;
61 /* Create and allocate the fname structure */
62 - len = sizeof(struct fname) + ent_name->len + 1;
63 + if (dirent->file_type & EXT4_DIRENT_LUFID)
64 + extra_data = ext4_get_dirent_data_len(dirent);
66 + len = sizeof(struct fname) + ent_name->len + extra_data + 1;
68 new_fn = kzalloc(len, GFP_KERNEL);
71 @@ -456,7 +461,7 @@ int ext4_htree_store_dirent(struct file
72 new_fn->inode = le32_to_cpu(dirent->inode);
73 new_fn->name_len = ent_name->len;
74 new_fn->file_type = dirent->file_type;
75 - memcpy(new_fn->name, ent_name->name, ent_name->len);
76 + memcpy(new_fn->name, ent_name->name, ent_name->len + extra_data);
77 new_fn->name[ent_name->len] = 0;
80 Index: linux-4.15.0/fs/ext4/ext4.h
81 ===================================================================
82 --- linux-4.15.0.orig/fs/ext4/ext4.h
83 +++ linux-4.15.0/fs/ext4/ext4.h
84 @@ -1055,6 +1055,7 @@ struct ext4_inode_info {
92 @@ -1088,6 +1089,7 @@ struct ext4_inode_info {
93 * Mount flags set via mount options or defaults
95 #define EXT4_MOUNT_NO_MBCACHE 0x00001 /* Do not use mbcache */
96 +#define EXT4_MOUNT_DIRDATA 0x00002 /* Data in directory entries */
97 #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
98 #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
99 #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
100 @@ -1768,6 +1770,7 @@ EXT4_FEATURE_INCOMPAT_FUNCS(encrypt, EN
101 EXT4_FEATURE_INCOMPAT_FLEX_BG| \
102 EXT4_FEATURE_INCOMPAT_EA_INODE| \
103 EXT4_FEATURE_INCOMPAT_MMP | \
104 + EXT4_FEATURE_INCOMPAT_DIRDATA| \
105 EXT4_FEATURE_INCOMPAT_INLINE_DATA | \
106 EXT4_FEATURE_INCOMPAT_ENCRYPT | \
107 EXT4_FEATURE_INCOMPAT_CSUM_SEED | \
108 @@ -1943,6 +1946,43 @@ struct ext4_dir_entry_tail {
109 #define EXT4_FT_SYMLINK 7
111 #define EXT4_FT_MAX 8
112 +#define EXT4_FT_MASK 0xf
114 +#if EXT4_FT_MAX > EXT4_FT_MASK
115 +#error "conflicting EXT4_FT_MAX and EXT4_FT_MASK"
119 + * d_type has 4 unused bits, so it can hold four types data. these different
120 + * type of data (e.g. lustre data, high 32 bits of 64-bit inode number) can be
121 + * stored, in flag order, after file-name in ext4 dirent.
124 + * this flag is added to d_type if ext4 dirent has extra data after
125 + * filename. this data length is variable and length is stored in first byte
126 + * of data. data start after filename NUL byte.
127 + * This is used by Lustre FS.
129 +#define EXT4_DIRENT_LUFID 0x10
131 +#define EXT4_LUFID_MAGIC 0xAD200907UL
132 +struct ext4_dentry_param {
133 + __u32 edp_magic; /* EXT4_LUFID_MAGIC */
134 + char edp_len; /* size of edp_data in bytes */
135 + char edp_data[0]; /* packed array of data */
138 +static inline unsigned char *ext4_dentry_get_data(struct super_block *sb,
139 + struct ext4_dentry_param *p)
142 + if (!ext4_has_feature_dirdata(sb))
144 + if (p && p->edp_magic == EXT4_LUFID_MAGIC)
145 + return &p->edp_len;
150 #define EXT4_FT_DIR_CSUM 0xDE
152 @@ -1953,8 +1993,11 @@ struct ext4_dir_entry_tail {
154 #define EXT4_DIR_PAD 4
155 #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
156 -#define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
157 +#define __EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
159 +#define EXT4_DIR_REC_LEN(de) (__EXT4_DIR_REC_LEN((de)->name_len +\
160 + ext4_get_dirent_data_len(de)))
162 #define EXT4_MAX_REC_LEN ((1<<16)-1)
165 @@ -2357,11 +2400,11 @@ extern int ext4_find_dest_de(struct inod
166 struct buffer_head *bh,
167 void *buf, int buf_size,
168 struct ext4_filename *fname,
169 - struct ext4_dir_entry_2 **dest_de);
170 + struct ext4_dir_entry_2 **dest_de, int *dlen);
171 void ext4_insert_dentry(struct inode *inode,
172 struct ext4_dir_entry_2 *de,
174 - struct ext4_filename *fname);
175 + struct ext4_filename *fname, void *data);
176 static inline void ext4_update_dx_flag(struct inode *inode)
178 if (!ext4_has_feature_dir_index(inode->i_sb))
179 @@ -2373,10 +2416,17 @@ static const unsigned char ext4_filetype
181 static inline unsigned char get_dtype(struct super_block *sb, int filetype)
183 - if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX)
184 + int fl_index = filetype & EXT4_FT_MASK;
186 + if (!ext4_has_feature_filetype(sb) || fl_index >= EXT4_FT_MAX)
189 - return ext4_filetype_table[filetype];
190 + if (!test_opt(sb, DIRDATA))
191 + return ext4_filetype_table[fl_index];
193 + return (ext4_filetype_table[fl_index]) |
194 + (filetype & EXT4_DIRENT_LUFID);
197 extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh,
198 void *buf, int buf_size);
199 @@ -2525,6 +2575,8 @@ extern struct inode *ext4_create_inode(h
200 extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
201 struct ext4_dir_entry_2 *de_del,
202 struct buffer_head *bh);
203 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
204 + struct inode *inode, const void *, const void *);
205 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
206 __u32 start_minor_hash, __u32 *next_hash);
207 extern int ext4_search_dir(struct buffer_head *bh,
208 @@ -3265,6 +3317,36 @@ static inline void ext4_clear_io_unwritt
210 extern const struct iomap_ops ext4_iomap_ops;
213 + * Compute the total directory entry data length.
214 + * This includes the filename and an implicit NUL terminator (always present),
215 + * and optional extensions. Each extension has a bit set in the high 4 bits of
216 + * de->file_type, and the extension length is the first byte in each entry.
218 +static inline int ext4_get_dirent_data_len(struct ext4_dir_entry_2 *de)
220 + char *len = de->name + de->name_len + 1 /* NUL terminator */;
222 + __u8 extra_data_flags = (de->file_type & ~EXT4_FT_MASK) >> 4;
223 + struct ext4_dir_entry_tail *t = (struct ext4_dir_entry_tail *)de;
225 + if (!t->det_reserved_zero1 &&
226 + le16_to_cpu(t->det_rec_len) ==
227 + sizeof(struct ext4_dir_entry_tail) &&
228 + !t->det_reserved_zero2 &&
229 + t->det_reserved_ft == EXT4_FT_DIR_CSUM)
232 + while (extra_data_flags) {
233 + if (extra_data_flags & 1) {
234 + dlen += *len + (dlen == 0);
237 + extra_data_flags >>= 1;
242 #endif /* __KERNEL__ */
244 #define EFSBADCRC EBADMSG /* Bad CRC detected */
245 Index: linux-4.15.0/fs/ext4/namei.c
246 ===================================================================
247 --- linux-4.15.0.orig/fs/ext4/namei.c
248 +++ linux-4.15.0/fs/ext4/namei.c
249 @@ -242,7 +242,8 @@ static unsigned dx_get_count(struct dx_e
250 static unsigned dx_get_limit(struct dx_entry *entries);
251 static void dx_set_count(struct dx_entry *entries, unsigned value);
252 static void dx_set_limit(struct dx_entry *entries, unsigned value);
253 -static unsigned dx_root_limit(struct inode *dir, unsigned infosize);
254 +static inline unsigned dx_root_limit(struct inode *dir,
255 + struct ext4_dir_entry_2 *dot_de, unsigned infosize);
256 static unsigned dx_node_limit(struct inode *dir);
257 static struct dx_frame *dx_probe(struct ext4_filename *fname,
259 @@ -385,22 +386,23 @@ static struct dx_countlimit *get_dx_coun
261 struct ext4_dir_entry *dp;
262 struct dx_root_info *root;
264 + int count_offset, dot_rec_len, dotdot_rec_len;
266 if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
268 - else if (le16_to_cpu(dirent->rec_len) == 12) {
269 - dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
271 + dot_rec_len = le16_to_cpu(dirent->rec_len);
272 + dp = (struct ext4_dir_entry *)(((void *)dirent) + dot_rec_len);
273 if (le16_to_cpu(dp->rec_len) !=
274 - EXT4_BLOCK_SIZE(inode->i_sb) - 12)
275 + EXT4_BLOCK_SIZE(inode->i_sb) - dot_rec_len)
277 - root = (struct dx_root_info *)(((void *)dp + 12));
278 + dotdot_rec_len = EXT4_DIR_REC_LEN((struct ext4_dir_entry_2 *)dp);
279 + root = (struct dx_root_info *)(((void *)dp + dotdot_rec_len));
280 if (root->reserved_zero ||
281 root->info_length != sizeof(struct dx_root_info))
286 + count_offset = 8 + dot_rec_len + dotdot_rec_len;
290 *offset = count_offset;
291 @@ -505,11 +506,12 @@ ext4_next_entry(struct ext4_dir_entry_2
293 struct dx_root_info *dx_get_dx_info(struct ext4_dir_entry_2 *de)
295 + BUG_ON(de->name_len != 1);
296 /* get dotdot first */
297 - de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
298 + de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(de));
300 /* dx root info is after dotdot entry */
301 - de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
302 + de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(de));
304 return (struct dx_root_info *)de;
306 @@ -554,10 +556,16 @@ static inline void dx_set_limit(struct d
307 ((struct dx_countlimit *) entries)->limit = cpu_to_le16(value);
310 -static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
311 +static inline unsigned dx_root_limit(struct inode *dir,
312 + struct ext4_dir_entry_2 *dot_de, unsigned infosize)
314 - unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
315 - EXT4_DIR_REC_LEN(2) - infosize;
316 + struct ext4_dir_entry_2 *dotdot_de;
317 + unsigned entry_space;
319 + BUG_ON(dot_de->name_len != 1);
320 + dotdot_de = ext4_next_entry(dot_de, dir->i_sb->s_blocksize);
321 + entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(dot_de) -
322 + EXT4_DIR_REC_LEN(dotdot_de) - infosize;
324 if (ext4_has_metadata_csum(dir->i_sb))
325 entry_space -= sizeof(struct dx_tail);
326 @@ -566,7 +574,7 @@ static inline unsigned dx_root_limit(str
328 static inline unsigned dx_node_limit(struct inode *dir)
330 - unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
331 + unsigned entry_space = dir->i_sb->s_blocksize - __EXT4_DIR_REC_LEN(0);
333 if (ext4_has_metadata_csum(dir->i_sb))
334 entry_space -= sizeof(struct dx_tail);
335 @@ -678,7 +686,7 @@ static struct stats dx_show_leaf(struct
336 (unsigned) ((char *) de - base));
339 - space += EXT4_DIR_REC_LEN(de->name_len);
340 + space += EXT4_DIR_REC_LEN(de);
343 de = ext4_next_entry(de, size);
344 @@ -785,11 +793,14 @@ dx_probe(struct ext4_filename *fname, st
346 entries = (struct dx_entry *)(((char *)info) + info->info_length);
348 - if (dx_get_limit(entries) != dx_root_limit(dir,
349 - info->info_length)) {
350 + if (dx_get_limit(entries) !=
351 + dx_root_limit(dir, (struct ext4_dir_entry_2 *)frame->bh->b_data,
352 + info->info_length)) {
353 ext4_warning_inode(dir, "dx entry: limit %u != root limit %u",
354 dx_get_limit(entries),
355 - dx_root_limit(dir, info->info_length));
357 + (struct ext4_dir_entry_2 *)frame->bh->b_data,
358 + info->info_length));
362 @@ -981,7 +992,7 @@ static int htree_dirblock_to_tree(struct
363 de = (struct ext4_dir_entry_2 *) bh->b_data;
364 top = (struct ext4_dir_entry_2 *) ((char *) de +
365 dir->i_sb->s_blocksize -
366 - EXT4_DIR_REC_LEN(0));
367 + __EXT4_DIR_REC_LEN(0));
368 #ifdef CONFIG_EXT4_FS_ENCRYPTION
369 /* Check if the directory is encrypted */
370 if (ext4_encrypted_inode(dir)) {
371 @@ -1653,7 +1664,7 @@ dx_move_dirents(char *from, char *to, st
373 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *)
374 (from + (map->offs<<2));
375 - rec_len = EXT4_DIR_REC_LEN(de->name_len);
376 + rec_len = EXT4_DIR_REC_LEN(de);
377 memcpy (to, de, rec_len);
378 ((struct ext4_dir_entry_2 *) to)->rec_len =
379 ext4_rec_len_to_disk(rec_len, blocksize);
380 @@ -1677,7 +1688,7 @@ static struct ext4_dir_entry_2* dx_pack_
381 while ((char*)de < base + blocksize) {
382 next = ext4_next_entry(de, blocksize);
383 if (de->inode && de->name_len) {
384 - rec_len = EXT4_DIR_REC_LEN(de->name_len);
385 + rec_len = EXT4_DIR_REC_LEN(de);
387 memmove(to, de, rec_len);
388 to->rec_len = ext4_rec_len_to_disk(rec_len, blocksize);
389 @@ -1808,14 +1819,16 @@ int ext4_find_dest_de(struct inode *dir,
390 struct buffer_head *bh,
391 void *buf, int buf_size,
392 struct ext4_filename *fname,
393 - struct ext4_dir_entry_2 **dest_de)
394 + struct ext4_dir_entry_2 **dest_de, int *dlen)
396 struct ext4_dir_entry_2 *de;
397 - unsigned short reclen = EXT4_DIR_REC_LEN(fname_len(fname));
398 + unsigned short reclen = __EXT4_DIR_REC_LEN(fname_len(fname)) +
399 + (dlen ? *dlen : 0);
401 unsigned int offset = 0;
404 + dlen ? *dlen = 0 : 0; /* default set to 0 */
405 de = (struct ext4_dir_entry_2 *)buf;
406 top = buf + buf_size - reclen;
407 while ((char *) de <= top) {
408 @@ -1824,10 +1837,26 @@ int ext4_find_dest_de(struct inode *dir,
409 return -EFSCORRUPTED;
410 if (ext4_match(fname, de))
412 - nlen = EXT4_DIR_REC_LEN(de->name_len);
413 + nlen = EXT4_DIR_REC_LEN(de);
414 rlen = ext4_rec_len_from_disk(de->rec_len, buf_size);
415 if ((de->inode ? rlen - nlen : rlen) >= reclen)
417 + /* Then for dotdot entries, check for the smaller space
418 + * required for just the entry, no FID */
419 + if (fname_len(fname) == 2 && memcmp(fname_name(fname), "..", 2) == 0) {
420 + if ((de->inode ? rlen - nlen : rlen) >=
421 + __EXT4_DIR_REC_LEN(fname_len(fname))) {
422 + /* set dlen=1 to indicate not
423 + * enough space store fid */
424 + dlen ? *dlen = 1 : 0;
427 + /* The new ".." entry must be written over the
428 + * previous ".." entry, which is the first
429 + * entry traversed by this scan. If it doesn't
430 + * fit, something is badly wrong, so -EIO. */
433 de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
436 @@ -1841,12 +1870,12 @@ int ext4_find_dest_de(struct inode *dir,
437 void ext4_insert_dentry(struct inode *inode,
438 struct ext4_dir_entry_2 *de,
440 - struct ext4_filename *fname)
441 + struct ext4_filename *fname, void *data)
446 - nlen = EXT4_DIR_REC_LEN(de->name_len);
447 + nlen = EXT4_DIR_REC_LEN(de);
448 rlen = ext4_rec_len_from_disk(de->rec_len, buf_size);
450 struct ext4_dir_entry_2 *de1 =
451 @@ -1860,6 +1889,11 @@ void ext4_insert_dentry(struct inode *in
452 ext4_set_de_type(inode->i_sb, de, inode->i_mode);
453 de->name_len = fname_len(fname);
454 memcpy(de->name, fname_name(fname), fname_len(fname));
456 + de->name[fname_len(fname)] = 0;
457 + memcpy(&de->name[fname_len(fname) + 1], data, *(char *)data);
458 + de->file_type |= EXT4_DIRENT_LUFID;
463 @@ -1877,14 +1911,19 @@ static int add_dirent_to_buf(handle_t *h
465 unsigned int blocksize = dir->i_sb->s_blocksize;
469 + unsigned char *data;
471 + data = ext4_dentry_get_data(inode->i_sb, (struct ext4_dentry_param *)
472 + EXT4_I(inode)->i_dirdata);
473 if (ext4_has_metadata_csum(inode->i_sb))
474 csum_size = sizeof(struct ext4_dir_entry_tail);
478 + dlen = (*data) + 1;
479 err = ext4_find_dest_de(dir, inode, bh, bh->b_data,
480 - blocksize - csum_size, fname, &de);
481 + blocksize - csum_size, fname, &de, &dlen);
485 @@ -1896,7 +1935,10 @@ static int add_dirent_to_buf(handle_t *h
488 /* By now the buffer is marked for journaling */
489 - ext4_insert_dentry(inode, de, blocksize, fname);
490 + /* If writing the short form of "dotdot", don't add the data section */
493 + ext4_insert_dentry(inode, de, blocksize, fname, data);
496 * XXX shouldn't update any times until successful
497 @@ -2005,7 +2047,8 @@ static int make_indexed_dir(handle_t *ha
499 dx_set_block(entries, 1);
500 dx_set_count(entries, 1);
501 - dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
502 + dx_set_limit(entries, dx_root_limit(dir,
503 + dot_de, sizeof(*dx_info)));
505 /* Initialize as for dx_probe */
506 fname->hinfo.hash_version = dx_info->hash_version;
507 @@ -2055,6 +2098,8 @@ static int ext4_update_dotdot(handle_t *
508 struct buffer_head *dir_block;
509 struct ext4_dir_entry_2 *de;
510 int len, journal = 0, err = 0;
515 return PTR_ERR(handle);
516 @@ -2072,19 +2117,24 @@ static int ext4_update_dotdot(handle_t *
517 /* the first item must be "." */
518 assert(de->name_len == 1 && de->name[0] == '.');
519 len = le16_to_cpu(de->rec_len);
520 - assert(len >= EXT4_DIR_REC_LEN(1));
521 - if (len > EXT4_DIR_REC_LEN(1)) {
522 + assert(len >= __EXT4_DIR_REC_LEN(1));
523 + if (len > __EXT4_DIR_REC_LEN(1)) {
524 BUFFER_TRACE(dir_block, "get_write_access");
525 err = ext4_journal_get_write_access(handle, dir_block);
530 - de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(1));
531 + de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
534 - len -= EXT4_DIR_REC_LEN(1);
535 - assert(len == 0 || len >= EXT4_DIR_REC_LEN(2));
536 + len -= EXT4_DIR_REC_LEN(de);
537 + data = ext4_dentry_get_data(dir->i_sb,
538 + (struct ext4_dentry_param *)dentry->d_fsdata);
541 + assert(len == 0 || len >= __EXT4_DIR_REC_LEN(2 + dlen));
543 de = (struct ext4_dir_entry_2 *)
544 ((char *) de + le16_to_cpu(de->rec_len));
546 @@ -2098,10 +2148,15 @@ static int ext4_update_dotdot(handle_t *
548 de->rec_len = cpu_to_le16(len);
550 - assert(le16_to_cpu(de->rec_len) >= EXT4_DIR_REC_LEN(2));
551 + assert(le16_to_cpu(de->rec_len) >= __EXT4_DIR_REC_LEN(2));
553 strcpy(de->name, "..");
554 - ext4_set_de_type(dir->i_sb, de, S_IFDIR);
555 + if (data != NULL && ext4_get_dirent_data_len(de) >= dlen) {
557 + memcpy(&de->name[2 + 1], data, *data);
558 + ext4_set_de_type(dir->i_sb, de, S_IFDIR);
559 + de->file_type |= EXT4_DIRENT_LUFID;
564 @@ -2140,6 +2195,7 @@ static int ext4_add_entry(handle_t *hand
565 ext4_lblk_t block, blocks;
568 + EXT4_I(inode)->i_dirdata = dentry->d_fsdata;
569 if (ext4_has_metadata_csum(inode->i_sb))
570 csum_size = sizeof(struct ext4_dir_entry_tail);
572 @@ -2661,37 +2717,70 @@ err_unlock_inode:
577 + struct inode *inode;
582 struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
583 struct ext4_dir_entry_2 *de,
584 int blocksize, int csum_size,
585 unsigned int parent_ino, int dotdot_real_len)
587 + void *data1 = NULL, *data2 = NULL;
588 + int dot_reclen = 0;
590 + if (dotdot_real_len == 10) {
591 + struct tp_block *tpb = (struct tp_block *)inode;
592 + data1 = tpb->data1;
593 + data2 = tpb->data2;
594 + inode = tpb->inode;
595 + dotdot_real_len = 0;
597 de->inode = cpu_to_le32(inode->i_ino);
599 - de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len),
601 strcpy(de->name, ".");
602 ext4_set_de_type(inode->i_sb, de, S_IFDIR);
604 + /* get packed fid data*/
605 + data1 = ext4_dentry_get_data(inode->i_sb,
606 + (struct ext4_dentry_param *) data1);
609 + memcpy(&de->name[2], data1, *(char *) data1);
610 + de->file_type |= EXT4_DIRENT_LUFID;
612 + de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
613 + dot_reclen = cpu_to_le16(de->rec_len);
614 de = ext4_next_entry(de, blocksize);
615 de->inode = cpu_to_le32(parent_ino);
617 + strcpy(de->name, "..");
618 + ext4_set_de_type(inode->i_sb, de, S_IFDIR);
619 + data2 = ext4_dentry_get_data(inode->i_sb,
620 + (struct ext4_dentry_param *) data2);
623 + memcpy(&de->name[3], data2, *(char *) data2);
624 + de->file_type |= EXT4_DIRENT_LUFID;
626 if (!dotdot_real_len)
627 de->rec_len = ext4_rec_len_to_disk(blocksize -
628 - (csum_size + EXT4_DIR_REC_LEN(1)),
629 + (csum_size + dot_reclen),
632 de->rec_len = ext4_rec_len_to_disk(
633 - EXT4_DIR_REC_LEN(de->name_len), blocksize);
634 - strcpy(de->name, "..");
635 - ext4_set_de_type(inode->i_sb, de, S_IFDIR);
636 + EXT4_DIR_REC_LEN(de), blocksize);
638 return ext4_next_entry(de, blocksize);
641 static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
642 - struct inode *inode)
643 + struct inode *inode,
644 + const void *data1, const void *data2)
646 + struct tp_block param;
647 struct buffer_head *dir_block = NULL;
648 struct ext4_dir_entry_2 *de;
649 struct ext4_dir_entry_tail *t;
650 @@ -2716,7 +2805,11 @@ static int ext4_init_new_dir(handle_t *h
651 if (IS_ERR(dir_block))
652 return PTR_ERR(dir_block);
653 de = (struct ext4_dir_entry_2 *)dir_block->b_data;
654 - ext4_init_dot_dotdot(inode, de, blocksize, csum_size, dir->i_ino, 0);
655 + param.inode = inode;
656 + param.data1 = (void *)data1;
657 + param.data2 = (void *)data2;
658 + ext4_init_dot_dotdot((struct inode *)(¶m), de, blocksize,
659 + csum_size, dir->i_ino, 10);
662 t = EXT4_DIRENT_TAIL(dir_block->b_data, blocksize);
663 @@ -2733,6 +2826,29 @@ out:
667 +/* Initialize @inode as a subdirectory of @dir, and add the
668 + * "." and ".." entries into the first directory block. */
669 +int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
670 + struct inode *inode,
671 + const void *data1, const void *data2)
675 + if (IS_ERR(handle))
676 + return PTR_ERR(handle);
678 + if (IS_DIRSYNC(dir))
679 + ext4_handle_sync(handle);
681 + inode->i_op = &ext4_dir_inode_operations;
682 + inode->i_fop = &ext4_dir_operations;
683 + rc = ext4_init_new_dir(handle, dir, inode, data1, data2);
685 + rc = ext4_mark_inode_dirty(handle, inode);
688 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
690 static int ext4_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
693 @@ -2759,7 +2875,7 @@ retry:
695 inode->i_op = &ext4_dir_inode_operations;
696 inode->i_fop = &ext4_dir_operations;
697 - err = ext4_init_new_dir(handle, dir, inode);
698 + err = ext4_init_new_dir(handle, dir, inode, NULL, NULL);
700 goto out_clear_inode;
701 err = ext4_mark_inode_dirty(handle, inode);
702 @@ -2811,7 +2927,7 @@ bool ext4_empty_dir(struct inode *inode)
706 - if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2)) {
707 + if (inode->i_size < __EXT4_DIR_REC_LEN(1) + __EXT4_DIR_REC_LEN(2)) {
708 EXT4_ERROR_INODE(inode, "invalid size");
711 Index: linux-4.15.0/fs/ext4/inline.c
712 ===================================================================
713 --- linux-4.15.0.orig/fs/ext4/inline.c
714 +++ linux-4.15.0/fs/ext4/inline.c
715 @@ -1017,7 +1017,7 @@ static int ext4_add_dirent_to_inline(han
716 struct ext4_dir_entry_2 *de;
718 err = ext4_find_dest_de(dir, inode, iloc->bh, inline_start,
719 - inline_size, fname, &de);
720 + inline_size, fname, &de, NULL);
724 @@ -1025,7 +1025,7 @@ static int ext4_add_dirent_to_inline(han
725 err = ext4_journal_get_write_access(handle, iloc->bh);
728 - ext4_insert_dentry(inode, de, inline_size, fname);
729 + ext4_insert_dentry(inode, de, inline_size, fname, NULL);
731 ext4_show_inline_dir(dir, iloc->bh, inline_start, inline_size);
733 @@ -1094,7 +1094,7 @@ static int ext4_update_inline_dir(handle
734 int old_size = EXT4_I(dir)->i_inline_size - EXT4_MIN_INLINE_DATA_SIZE;
735 int new_size = get_max_inline_xattr_value_size(dir, iloc);
737 - if (new_size - old_size <= EXT4_DIR_REC_LEN(1))
738 + if (new_size - old_size <= __EXT4_DIR_REC_LEN(1))
741 ret = ext4_update_inline_data(handle, dir,
742 @@ -1375,7 +1375,7 @@ int htree_inlinedir_to_tree(struct file
744 strcpy(fake.name, ".");
745 fake.rec_len = ext4_rec_len_to_disk(
746 - EXT4_DIR_REC_LEN(fake.name_len),
747 + EXT4_DIR_REC_LEN(&fake),
749 ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
751 @@ -1385,7 +1385,7 @@ int htree_inlinedir_to_tree(struct file
753 strcpy(fake.name, "..");
754 fake.rec_len = ext4_rec_len_to_disk(
755 - EXT4_DIR_REC_LEN(fake.name_len),
756 + EXT4_DIR_REC_LEN(&fake),
758 ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
760 @@ -1483,8 +1483,8 @@ int ext4_read_inline_dir(struct file *fi
761 * So we will use extra_offset and extra_size to indicate them
762 * during the inline dir iteration.
764 - dotdot_offset = EXT4_DIR_REC_LEN(1);
765 - dotdot_size = dotdot_offset + EXT4_DIR_REC_LEN(2);
766 + dotdot_offset = __EXT4_DIR_REC_LEN(1);
767 + dotdot_size = dotdot_offset + __EXT4_DIR_REC_LEN(2);
768 extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE;
769 extra_size = extra_offset + inline_size;
771 @@ -1519,7 +1519,7 @@ int ext4_read_inline_dir(struct file *fi
772 * failure will be detected in the
773 * dirent test below. */
774 if (ext4_rec_len_from_disk(de->rec_len, extra_size)
775 - < EXT4_DIR_REC_LEN(1))
776 + < __EXT4_DIR_REC_LEN(1))
778 i += ext4_rec_len_from_disk(de->rec_len,
780 Index: linux-4.15.0/fs/ext4/super.c
781 ===================================================================
782 --- linux-4.15.0.orig/fs/ext4/super.c
783 +++ linux-4.15.0/fs/ext4/super.c
784 @@ -1347,7 +1347,7 @@ enum {
785 Opt_data_err_abort, Opt_data_err_ignore, Opt_test_dummy_encryption,
786 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
787 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
788 - Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
789 + Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err, Opt_dirdata,
790 Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version, Opt_dax,
791 Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_mblk_io_submit,
792 Opt_lazytime, Opt_nolazytime, Opt_debug_want_extra_isize,
793 @@ -1420,6 +1420,7 @@ static const match_table_t tokens = {
794 {Opt_nolazytime, "nolazytime"},
795 {Opt_debug_want_extra_isize, "debug_want_extra_isize=%u"},
796 {Opt_nodelalloc, "nodelalloc"},
797 + {Opt_dirdata, "dirdata"},
798 {Opt_removed, "mblk_io_submit"},
799 {Opt_removed, "nomblk_io_submit"},
800 {Opt_block_validity, "block_validity"},
801 @@ -1641,6 +1642,7 @@ static const struct mount_opts {
802 {Opt_usrjquota, 0, MOPT_Q},
803 {Opt_grpjquota, 0, MOPT_Q},
804 {Opt_offusrjquota, 0, MOPT_Q},
805 + {Opt_dirdata, EXT4_MOUNT_DIRDATA, MOPT_SET},
806 {Opt_offgrpjquota, 0, MOPT_Q},
807 {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
808 {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},