Whamcloud - gitweb
build: fix compile warnings on OSX
[tools/e2fsprogs.git] / lib / ext2fs / mkdir.c
index ea189d9..b12bf2d 100644 (file)
@@ -1,14 +1,15 @@
 /*
  * mkdir.c --- make a directory in the filesystem
- * 
+ *
  * Copyright (C) 1994, 1995 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
 errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
                       const char *name)
 {
+       ext2_extent_handle_t    handle;
        errcode_t               retval;
        struct ext2_inode       parent_inode, inode;
        ext2_ino_t              ino = inum;
        ext2_ino_t              scratch_ino;
-       blk_t                   blk;
+       blk64_t                 blk;
        char                    *block = 0;
 
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -55,7 +57,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
        /*
         * Allocate a data block for the directory
         */
-       retval = ext2fs_new_block(fs, 0, 0, &blk);
+       retval = ext2fs_new_block2(fs, 0, 0, &blk);
        if (retval)
                goto cleanup;
 
@@ -82,10 +84,12 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
        memset(&inode, 0, sizeof(struct ext2_inode));
        inode.i_mode = LINUX_S_IFDIR | (0777 & ~fs->umask);
        inode.i_uid = inode.i_gid = 0;
-       inode.i_blocks = fs->blocksize / 512;
-       inode.i_block[0] = blk;
+       ext2fs_iblk_set(fs, &inode, 1);
+       if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)
+               inode.i_flags |= EXT4_EXTENTS_FL;
+       else
+               inode.i_block[0] = blk;
        inode.i_links_count = 2;
-       inode.i_ctime = inode.i_atime = inode.i_mtime = time(NULL);
        inode.i_size = fs->blocksize;
 
        /*
@@ -94,10 +98,20 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
        retval = ext2fs_write_dir_block(fs, blk, block);
        if (retval)
                goto cleanup;
-       retval = ext2fs_write_inode(fs, ino, &inode); 
+       retval = ext2fs_write_new_inode(fs, ino, &inode);
        if (retval)
                goto cleanup;
 
+       if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) {
+               retval = ext2fs_extent_open2(fs, ino, &inode, &handle);
+               if (retval)
+                       goto cleanup;
+               retval = ext2fs_extent_set_bmap(handle, 0, blk, 0);
+               ext2fs_extent_free(handle);
+               if (retval)
+                       goto cleanup;
+       }
+
        /*
         * Link the directory into the filesystem hierarchy
         */
@@ -125,16 +139,16 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
                if (retval)
                        goto cleanup;
        }
-       
+
        /*
         * Update accounting....
         */
-       ext2fs_block_alloc_stats(fs, blk, +1);
+       ext2fs_block_alloc_stats2(fs, blk, +1);
        ext2fs_inode_alloc_stats2(fs, ino, +1, 1);
 
 cleanup:
        if (block)
-               ext2fs_free_mem((void **) &block);
+               ext2fs_free_mem(&block);
        return retval;
 
 }