1 /* vi: set sw=4 ts=4: */
3 * newdir.c --- create a new directory block
5 * Copyright (C) 1994, 1995 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
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;
38 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
40 retval = ext2fs_get_mem(fs->blocksize, &buf);
43 memset(buf, 0, fs->blocksize);
44 dir = (struct ext2_dir_entry *) buf;
45 dir->rec_len = fs->blocksize;
48 if (fs->super->s_feature_incompat &
49 EXT2_FEATURE_INCOMPAT_FILETYPE)
50 filetype = EXT2_FT_DIR << 8;
52 * Set up entry for '.'
55 dir->name_len = 1 | filetype;
57 rec_len = dir->rec_len - EXT2_DIR_REC_LEN(1);
58 dir->rec_len = EXT2_DIR_REC_LEN(1);
61 * Set up entry for '..'
63 dir = (struct ext2_dir_entry *) (buf + dir->rec_len);
64 dir->rec_len = rec_len;
65 dir->inode = parent_ino;
66 dir->name_len = 2 | filetype;