1 Upstream-Status: inappropriate
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.
8 Consolidate some processing that occurs when allocating a filesystem
11 genext2fs.c | 49 +++++++++++++++++++++++++------------------------
12 1 files changed, 25 insertions(+), 24 deletions(-)
14 diff --git a/genext2fs.c b/genext2fs.c
15 index d130362..497c9af 100644
18 @@ -2240,6 +2240,29 @@ swap_badfs(filesystem *fs)
22 +// Allocate a new filesystem structure, allocate internal memory,
23 +// and initialize the contents.
25 +alloc_fs(uint32 nbblocks)
29 + fs = malloc(sizeof(*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);
45 // initialize an empty 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;
52 - fs = malloc(sizeof(*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))
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);
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));
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);