X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lib%2Fext2fs%2Fnewdir.c;h=b0a1e4763334e4d78bbee08b3d26b598ee938223;hb=9026b3db3af838983ed81aad2b4d5e09df1013e3;hp=948bad9f82eb13c44217227f7b177312c53985a2;hpb=3839e65723771b85975f4263102dd3ceec4523c0;p=tools%2Fe2fsprogs.git diff --git a/lib/ext2fs/newdir.c b/lib/ext2fs/newdir.c index 948bad9..b0a1e47 100644 --- a/lib/ext2fs/newdir.c +++ b/lib/ext2fs/newdir.c @@ -1,56 +1,77 @@ /* * newdir.c --- create a new directory block - * - * Copyright (C) 1994 Theodore Ts'o. This file may be redistributed - * under the terms of the GNU Public License. + * + * Copyright (C) 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% */ +#include "config.h" #include #include +#if HAVE_UNISTD_H #include -#include -#include -#include +#endif +#include "ext2_fs.h" #include "ext2fs.h" +#ifndef EXT2_FT_DIR +#define EXT2_FT_DIR 2 +#endif + /* * Create new directory block */ -errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino, ino_t parent_ino, - char **block) +errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, + ext2_ino_t parent_ino, char **block) { - char *buf; - struct ext2_dir_entry *dir = NULL; - int rec_len; + struct ext2_dir_entry *dir = NULL; + errcode_t retval; + char *buf; + int rec_len; + int filetype = 0; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - buf = malloc(fs->blocksize); - if (!buf) - return ENOMEM; + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; memset(buf, 0, fs->blocksize); dir = (struct ext2_dir_entry *) buf; - dir->rec_len = fs->blocksize; + + retval = ext2fs_set_rec_len(fs, fs->blocksize, dir); + if (retval) + return retval; if (dir_ino) { + if (fs->super->s_feature_incompat & + EXT2_FEATURE_INCOMPAT_FILETYPE) + filetype = EXT2_FT_DIR << 8; /* * Set up entry for '.' */ dir->inode = dir_ino; - dir->name_len = 1; + dir->name_len = 1 | filetype; dir->name[0] = '.'; - rec_len = dir->rec_len - EXT2_DIR_REC_LEN(dir->name_len); - dir->rec_len = EXT2_DIR_REC_LEN(dir->name_len); + rec_len = fs->blocksize - EXT2_DIR_REC_LEN(1); + dir->rec_len = EXT2_DIR_REC_LEN(1); /* * Set up entry for '..' */ dir = (struct ext2_dir_entry *) (buf + dir->rec_len); - dir->rec_len = rec_len; + retval = ext2fs_set_rec_len(fs, rec_len, dir); + if (retval) + return retval; dir->inode = parent_ino; - dir->name_len = 2; + dir->name_len = 2 | filetype; dir->name[0] = '.'; dir->name[1] = '.'; - + } *block = buf; return 0;