2 * newdir.c --- create a new directory block
4 * Copyright (C) 1994, 1995 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
27 * Create new directory block
29 errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
30 ext2_ino_t parent_ino, char **block)
32 struct ext2_dir_entry *dir = NULL;
37 struct ext2_dir_entry_tail *t;
40 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
42 retval = ext2fs_get_mem(fs->blocksize, &buf);
45 memset(buf, 0, fs->blocksize);
46 dir = (struct ext2_dir_entry *) buf;
48 if (ext2fs_has_feature_metadata_csum(fs->super))
49 csum_size = sizeof(struct ext2_dir_entry_tail);
51 retval = ext2fs_set_rec_len(fs, fs->blocksize - csum_size, dir);
53 ext2fs_free_mem(&buf);
58 if (ext2fs_has_feature_filetype(fs->super))
59 filetype = EXT2_FT_DIR;
61 * Set up entry for '.'
64 ext2fs_dirent_set_name_len(dir, 1);
65 ext2fs_dirent_set_file_type(dir, filetype);
67 rec_len = (fs->blocksize - csum_size) - EXT2_DIR_REC_LEN(1);
68 dir->rec_len = EXT2_DIR_REC_LEN(1);
71 * Set up entry for '..'
73 dir = (struct ext2_dir_entry *) (buf + dir->rec_len);
74 retval = ext2fs_set_rec_len(fs, rec_len, dir);
76 ext2fs_free_mem(&buf);
79 dir->inode = parent_ino;
80 ext2fs_dirent_set_name_len(dir, 2);
81 ext2fs_dirent_set_file_type(dir, filetype);
88 t = EXT2_DIRENT_TAIL(buf, fs->blocksize);
89 ext2fs_initialize_dirent_tail(fs, t);
96 * Create new directory on inline data
98 errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs,
99 ext2_ino_t dir_ino EXT2FS_ATTR((unused)),
100 ext2_ino_t parent_ino, __u32 *iblock)
102 struct ext2_dir_entry *dir = NULL;
106 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
108 iblock[0] = ext2fs_cpu_to_le32(parent_ino);
110 dir = (struct ext2_dir_entry *)((char *)iblock +
111 EXT4_INLINE_DATA_DOTDOT_SIZE);
113 rec_len = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DATA_DOTDOT_SIZE;
114 retval = ext2fs_set_rec_len(fs, rec_len, dir);
118 #ifdef WORDS_BIGENDIAN
119 retval = ext2fs_dirent_swab_out2(fs, (char *)dir, rec_len, 0);