]> code.ossystems Code Review - openembedded-core.git/blob
25adeb63c0d0062d18171c5d413baf782c693a3f
[openembedded-core.git] /
1 Upstream-Status: inappropriate
2
3 From 797e8548e5857b7a0586b27a9bdcadbea1561d8d Mon Sep 17 00:00:00 2001
4 From: Corey Minyard <cminyard@mvista.com>
5 Date: Sun, 5 Jun 2011 14:53:57 -0500
6 Subject: [PATCH 08/19] Separate out the creation of the filesystem structure.
7
8 Consolidate some processing that occurs when allocating a filesystem
9 structure.
10 ---
11  genext2fs.c |   49 +++++++++++++++++++++++++------------------------
12  1 files changed, 25 insertions(+), 24 deletions(-)
13
14 diff --git a/genext2fs.c b/genext2fs.c
15 index d130362..497c9af 100644
16 --- a/genext2fs.c
17 +++ b/genext2fs.c
18 @@ -2240,6 +2240,29 @@ swap_badfs(filesystem *fs)
19         }
20  }
21  
22 +// Allocate a new filesystem structure, allocate internal memory,
23 +// and initialize the contents.
24 +static filesystem *
25 +alloc_fs(uint32 nbblocks)
26 +{
27 +       filesystem *fs;
28 +
29 +       fs = malloc(sizeof(*fs));
30 +       if (!fs)
31 +               error_msg_and_die("not enough memory for filesystem");
32 +       memset(fs, 0, sizeof(*fs));
33 +       if(!(fs->data = calloc(nbblocks, BLOCKSIZE)))
34 +               error_msg_and_die("not enough memory for filesystem");
35 +       fs->hdlink_cnt = HDLINK_CNT;
36 +       fs->hdlinks.hdl = calloc(sizeof(struct hdlink_s), fs->hdlink_cnt);
37 +       if (!fs->hdlinks.hdl)
38 +               error_msg_and_die("Not enough memory");
39 +       fs->hdlinks.count = 0 ;
40 +       fs->sb = (superblock *) (fs->data + BLOCKSIZE);
41 +       fs->gd = (groupdescriptor *) (fs->sb + 1);
42 +       return fs;
43 +}
44 +
45  // initialize an empty filesystem
46  static filesystem *
47  init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp)
48 @@ -2290,21 +2313,10 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
49         free_blocks = nbblocks - overhead_per_group*nbgroups - 1 /*boot block*/;
50         free_blocks_per_group = nbblocks_per_group - overhead_per_group;
51  
52 -       fs = malloc(sizeof(*fs));
53 -       if (!fs)
54 -               error_msg_and_die("not enough memory for filesystem");
55 +       fs = alloc_fs(nbblocks);
56         fs->nheadblocks = (((nbgroups * sizeof(groupdescriptor))
57                             + sizeof(superblock) + (BLOCKSIZE - 1))
58                            / BLOCKSIZE);
59 -       if(!(fs->data = calloc(nbblocks, BLOCKSIZE)))
60 -               error_msg_and_die("not enough memory for filesystem");
61 -       fs->hdlink_cnt = HDLINK_CNT;
62 -       fs->hdlinks.hdl = calloc(sizeof(struct hdlink_s), fs->hdlink_cnt);
63 -       if (!fs->hdlinks.hdl)
64 -               error_msg_and_die("Not enough memory");
65 -       fs->hdlinks.count = 0 ;
66 -       fs->sb = (superblock *) (fs->data + BLOCKSIZE);
67 -       fs->gd = (groupdescriptor *) (fs->sb + 1);
68  
69         // create the superblock for an empty filesystem
70         fs->sb->s_inodes_count = nbinodes_per_group * nbgroups;
71 @@ -2442,20 +2454,9 @@ load_fs(FILE * fh, int swapit)
72         fssize = (fssize + BLOCKSIZE - 1) / BLOCKSIZE;
73         if(fssize < 16) // totally arbitrary
74                 error_msg_and_die("too small filesystem");
75 -       fs = malloc(sizeof(*fs));
76 -       if (!fs)
77 -               error_msg_and_die("not enough memory for filesystem");
78 -       fs->hdlink_cnt = HDLINK_CNT;
79 -       fs->hdlinks.hdl = calloc(sizeof(struct hdlink_s), fs->hdlink_cnt);
80 -       if (!fs->hdlinks.hdl)
81 -               error_msg_and_die("Not enough memory");
82 -       fs->hdlinks.count = 0 ;
83 -       if(!(fs->data = calloc(fssize, BLOCKSIZE)))
84 -               error_msg_and_die("not enough memory for filesystem");
85 +       fs = alloc_fs(fssize);
86         if(fread(fs->data, BLOCKSIZE, fssize, fh) != fssize)
87                 perror_msg_and_die("input filesystem image");
88 -       fs->sb = (superblock *) (fs->data + BLOCKSIZE);
89 -       fs->gd = (groupdescriptor *) (fs->sb + 1);
90  
91         if(swapit)
92                 swap_badfs(fs);
93 -- 
94 1.7.4.1
95