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 Public
26 * Create new directory block
28 errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
29 ext2_ino_t parent_ino, char **block)
31 struct ext2_dir_entry *dir = NULL;
37 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
39 retval = ext2fs_get_mem(fs->blocksize, &buf);
42 memset(buf, 0, fs->blocksize);
43 dir = (struct ext2_dir_entry *) buf;
44 dir->rec_len = fs->blocksize;
47 if (fs->super->s_feature_incompat &
48 EXT2_FEATURE_INCOMPAT_FILETYPE)
49 filetype = EXT2_FT_DIR << 8;
51 * Set up entry for '.'
54 dir->name_len = 1 | filetype;
56 rec_len = dir->rec_len - EXT2_DIR_REC_LEN(1);
57 dir->rec_len = EXT2_DIR_REC_LEN(1);
60 * Set up entry for '..'
62 dir = (struct ext2_dir_entry *) (buf + dir->rec_len);
63 dir->rec_len = rec_len;
64 dir->inode = parent_ino;
65 dir->name_len = 2 | filetype;