1 Upstream-Status: inappropriate
3 From 1ea2332c6cec1fb979a7cb4502360005bed50da4 Mon Sep 17 00:00:00 2001
4 From: Corey Minyard <cminyard@mvista.com>
5 Date: Sun, 5 Jun 2011 14:08:02 -0500
6 Subject: [PATCH 07/19] Move hdlinks into the filesystem structure.
8 Since the hard links structures are associated with a filesystem, put
9 them in the filesystem structure since it can hold other stuff now.
11 genext2fs.c | 71 +++++++++++++++++++++++++++++++---------------------------
12 1 files changed, 38 insertions(+), 33 deletions(-)
14 diff --git a/genext2fs.c b/genext2fs.c
15 index e45e520..d130362 100644
18 @@ -583,6 +583,18 @@ typedef struct
22 +#define HDLINK_CNT 16
32 + struct hdlink_s *hdl;
35 /* Filesystem structure that support groups */
37 @@ -592,6 +604,8 @@ typedef struct
42 + struct hdlinks_s hdlinks;
45 #error UNHANDLED BLOCKSIZE
46 @@ -615,22 +629,6 @@ typedef struct
47 #define udecl32(x) this->x = swab32(this->x);
48 #define utdecl32(x,n) { int i; for(i=0; i<n; i++) this->x[i] = swab32(this->x[i]); }
50 -#define HDLINK_CNT 16
51 -static int32 hdlink_cnt = HDLINK_CNT;
61 - struct hdlink_s *hdl;
64 -static struct hdlinks_s hdlinks;
67 swap_sb(superblock *sb)
69 @@ -787,12 +785,12 @@ xreadlink(const char *path)
73 -is_hardlink(ino_t inode)
74 +is_hardlink(filesystem *fs, ino_t inode)
78 - for(i = 0; i < hdlinks.count; i++) {
79 - if(hdlinks.hdl[i].src_inode == inode)
80 + for(i = 0; i < fs->hdlinks.count; i++) {
81 + if(fs->hdlinks.hdl[i].src_inode == inode)
85 @@ -1989,9 +1987,9 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
87 /* Check for hardlinks */
88 if (!S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode) && st.st_nlink > 1) {
89 - int32 hdlink = is_hardlink(st.st_ino);
90 + int32 hdlink = is_hardlink(fs, st.st_ino);
92 - add2dir(fs, this_nod, hdlinks.hdl[hdlink].dst_nod, name);
93 + add2dir(fs, this_nod, fs->hdlinks.hdl[hdlink].dst_nod, name);
97 @@ -2035,17 +2033,17 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
98 error_msg("ignoring entry %s", name);
101 - if (hdlinks.count == hdlink_cnt) {
103 - realloc (hdlinks.hdl, (hdlink_cnt + HDLINK_CNT) *
104 + if (fs->hdlinks.count == fs->hdlink_cnt) {
105 + if ((fs->hdlinks.hdl =
106 + realloc (fs->hdlinks.hdl, (fs->hdlink_cnt + HDLINK_CNT) *
107 sizeof (struct hdlink_s))) == NULL) {
108 error_msg_and_die("Not enough memory");
110 - hdlink_cnt += HDLINK_CNT;
111 + fs->hdlink_cnt += HDLINK_CNT;
113 - hdlinks.hdl[hdlinks.count].src_inode = st.st_ino;
114 - hdlinks.hdl[hdlinks.count].dst_nod = nod;
116 + fs->hdlinks.hdl[fs->hdlinks.count].src_inode = st.st_ino;
117 + fs->hdlinks.hdl[fs->hdlinks.count].dst_nod = nod;
118 + fs->hdlinks.count++;
122 @@ -2300,6 +2298,11 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
124 if(!(fs->data = calloc(nbblocks, BLOCKSIZE)))
125 error_msg_and_die("not enough memory for filesystem");
126 + fs->hdlink_cnt = HDLINK_CNT;
127 + fs->hdlinks.hdl = calloc(sizeof(struct hdlink_s), fs->hdlink_cnt);
128 + if (!fs->hdlinks.hdl)
129 + error_msg_and_die("Not enough memory");
130 + fs->hdlinks.count = 0 ;
131 fs->sb = (superblock *) (fs->data + BLOCKSIZE);
132 fs->gd = (groupdescriptor *) (fs->sb + 1);
134 @@ -2442,12 +2445,18 @@ load_fs(FILE * fh, int swapit)
135 fs = malloc(sizeof(*fs));
137 error_msg_and_die("not enough memory for filesystem");
138 + fs->hdlink_cnt = HDLINK_CNT;
139 + fs->hdlinks.hdl = calloc(sizeof(struct hdlink_s), fs->hdlink_cnt);
140 + if (!fs->hdlinks.hdl)
141 + error_msg_and_die("Not enough memory");
142 + fs->hdlinks.count = 0 ;
143 if(!(fs->data = calloc(fssize, BLOCKSIZE)))
144 error_msg_and_die("not enough memory for filesystem");
145 if(fread(fs->data, BLOCKSIZE, fssize, fh) != fssize)
146 perror_msg_and_die("input filesystem image");
147 fs->sb = (superblock *) (fs->data + BLOCKSIZE);
148 fs->gd = (groupdescriptor *) (fs->sb + 1);
152 if(fs->sb->s_rev_level || (fs->sb->s_magic != EXT2_MAGIC_NUMBER))
153 @@ -2461,6 +2470,7 @@ load_fs(FILE * fh, int swapit)
155 free_fs(filesystem *fs)
157 + free(fs->hdlinks.hdl);
161 @@ -2964,11 +2974,6 @@ main(int argc, char **argv)
162 error_msg_and_die("Not enough arguments. Try --help or else see the man page.");
163 fsout = argv[optind];
165 - hdlinks.hdl = (struct hdlink_s *)malloc(hdlink_cnt * sizeof(struct hdlink_s));
167 - error_msg_and_die("Not enough memory");
168 - hdlinks.count = 0 ;
172 if(strcmp(fsin, "-"))