~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to libocfs2/newdir.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c; c-basic-offset: 8; -*-
2
 
 * vim: noexpandtab sw=8 ts=8 sts=0:
3
 
 *
4
 
 * newdir.c
5
 
 *
6
 
 * Create a new directory block
7
 
 *
8
 
 * Copyright (C) 2004 Oracle.  All rights reserved.
9
 
 *
10
 
 * This program is free software; you can redistribute it and/or
11
 
 * modify it under the terms of the GNU General Public
12
 
 * License, version 2,  as published by the Free Software Foundation.
13
 
 * 
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
 * General Public License for more details.
18
 
 * 
19
 
 * You should have received a copy of the GNU General Public
20
 
 * License along with this program; if not, write to the
21
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
 
 * Boston, MA 021110-1307, USA.
23
 
 *
24
 
 *  This code is a port of e2fsprogs/lib/ext2fs/newdir.c
25
 
 *  Copyright (C) 1994, 1995 Theodore Ts'o.
26
 
 */
27
 
 
28
 
#define _XOPEN_SOURCE 600 /* Triggers magic in features.h */
29
 
#define _LARGEFILE64_SOURCE
30
 
 
31
 
#include <stdio.h>
32
 
#include <string.h>
33
 
#if HAVE_UNISTD_H
34
 
#include <unistd.h>
35
 
#endif
36
 
 
37
 
#include "ocfs2.h"
38
 
 
39
 
/*
40
 
 * Create new directory block
41
 
 */
42
 
errcode_t ocfs2_new_dir_block(ocfs2_filesys *fs, uint64_t dir_ino,
43
 
                              uint64_t parent_ino, char **block)
44
 
{
45
 
        struct ocfs2_dir_entry  *dir;
46
 
        errcode_t               ret;
47
 
        char                    *buf;
48
 
 
49
 
        ret = ocfs2_malloc_block(fs->fs_io, &buf);
50
 
        if (ret)
51
 
                return ret;
52
 
 
53
 
        memset(buf, 0, fs->fs_blocksize);
54
 
 
55
 
        dir = (struct ocfs2_dir_entry *) buf;
56
 
        dir->rec_len = fs->fs_blocksize;
57
 
 
58
 
        if (dir_ino) {
59
 
                /*
60
 
                 * Set up entry for '.'
61
 
                 */
62
 
                dir->inode = dir_ino;
63
 
                dir->rec_len = OCFS2_DIR_REC_LEN(1);
64
 
                dir->name_len = 1;
65
 
                dir->file_type = OCFS2_FT_DIR;
66
 
                dir->name[0] = '.';
67
 
 
68
 
                /*
69
 
                 * Set up entry for '..'
70
 
                 */
71
 
                dir = (struct ocfs2_dir_entry *) (buf + dir->rec_len);
72
 
                dir->inode = parent_ino;
73
 
                dir->rec_len = fs->fs_blocksize - OCFS2_DIR_REC_LEN(1);
74
 
                dir->name_len = 2;
75
 
                dir->file_type = OCFS2_FT_DIR;
76
 
                dir->name[0] = '.';
77
 
                dir->name[1] = '.';
78
 
        }
79
 
 
80
 
        *block = buf;
81
 
        return 0;
82
 
}