1 This attempts to accomplish some per-file memory-savings by moving the
2 uid+gid items out of the file-list (since their values are common to
3 multiple file-list entries) and replacing them with an index to an
6 This only saves 4 bytes per file (not counting the overhead of the array).
8 This probably needs a hashing algorithm to be added if the uid+gid list
9 gets to be really large.
11 --- orig/flist.c 2006-01-31 02:30:18
12 +++ flist.c 2006-01-26 10:56:31
13 @@ -60,6 +60,7 @@ extern int protocol_version;
14 extern int sanitize_paths;
15 extern const char *io_write_phase;
16 extern struct stats stats;
17 +extern struct id_pair *id_pairs;
18 extern struct file_list *the_file_list;
20 extern char curr_dir[MAXPATHLEN];
21 @@ -363,14 +364,14 @@ static void send_file_entry(struct file_
23 } else if (protocol_version < 28)
25 - if (file->uid == uid)
26 + if (id_pairs[file->id_ndx].uid == uid)
27 flags |= XMIT_SAME_UID;
30 - if (file->gid == gid)
31 + uid = id_pairs[file->id_ndx].uid;
32 + if (id_pairs[file->id_ndx].gid == gid)
33 flags |= XMIT_SAME_GID;
36 + gid = id_pairs[file->id_ndx].gid;
37 if (file->modtime == modtime)
38 flags |= XMIT_SAME_TIME;
40 @@ -623,8 +624,7 @@ static struct file_struct *receive_file_
41 file->modtime = modtime;
42 file->length = file_length;
46 + file->id_ndx = id_pair(uid, gid);
49 file->dirname = lastdir = bp;
50 @@ -875,8 +875,7 @@ struct file_struct *make_file(char *fnam
51 file->modtime = st.st_mtime;
52 file->length = st.st_size;
53 file->mode = st.st_mode;
54 - file->uid = st.st_uid;
55 - file->gid = st.st_gid;
56 + file->id_ndx = id_pair(st.st_uid, st.st_gid);
58 #ifdef SUPPORT_HARD_LINKS
59 if (flist && flist->hlink_pool) {
60 @@ -944,8 +943,7 @@ struct file_struct *make_file(char *fnam
61 file->modtime = st2.st_mtime;
62 file->length = st2.st_size;
63 file->mode = st2.st_mode;
64 - file->uid = st2.st_uid;
65 - file->gid = st2.st_gid;
66 + file->id_ndx = id_pair(st2.st_uid, st2.st_gid);
69 file->mode = save_mode;
70 @@ -1389,7 +1387,7 @@ struct file_list *recv_file_list(int f)
71 clean_flist(flist, relative_paths, 1);
74 - recv_uid_list(f, flist);
77 /* Recv the io_error flag */
78 if (lp_ignore_errors(module_id) || ignore_errors)
79 @@ -1705,13 +1703,15 @@ static void output_flist(struct file_lis
81 for (i = 0; i < flist->count; i++) {
82 file = flist->files[i];
83 - if ((am_root || am_sender) && preserve_uid)
84 - sprintf(uidbuf, " uid=%ld", (long)file->uid);
86 + if ((am_root || am_sender) && preserve_uid) {
87 + sprintf(uidbuf, " uid=%ld",
88 + (long)id_pairs[file->id_ndx].uid);
91 - if (preserve_gid && file->gid != GID_NONE)
92 - sprintf(gidbuf, " gid=%ld", (long)file->gid);
94 + if (preserve_gid && id_pairs[file->id_ndx].gid != GID_NONE) {
95 + sprintf(gidbuf, " gid=%ld",
96 + (long)id_pairs[file->id_ndx].gid);
100 sprintf(depthbuf, "%d", file->dir.depth);
101 --- orig/generator.c 2006-01-31 02:30:18
102 +++ generator.c 2006-01-25 17:39:42
103 @@ -91,6 +91,7 @@ extern dev_t filesystem_dev;
104 extern char *backup_dir;
105 extern char *backup_suffix;
106 extern int backup_suffix_len;
107 +extern struct id_pair *id_pairs;
108 extern struct file_list *the_file_list;
109 extern struct filter_list_struct server_filter_list;
111 @@ -326,10 +327,12 @@ int unchanged_attrs(struct file_struct *
112 && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
115 - if (am_root && preserve_uid && st->st_uid != file->uid)
116 + if (am_root && preserve_uid
117 + && st->st_uid != id_pairs[file->id_ndx].uid)
120 - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
121 + if (preserve_gid && id_pairs[file->id_ndx].gid != GID_NONE
122 + && st->st_gid != id_pairs[file->id_ndx].gid)
126 @@ -342,6 +345,8 @@ void itemize(struct file_struct *file, i
127 int keep_time = !preserve_times ? 0
128 : S_ISDIR(file->mode) ? !omit_dir_times
129 : !S_ISLNK(file->mode);
130 + uid_t uid = id_pairs[file->id_ndx].uid;
131 + gid_t gid = id_pairs[file->id_ndx].gid;
133 if (S_ISREG(file->mode) && file->length != st->st_size)
134 iflags |= ITEM_REPORT_SIZE;
135 @@ -352,10 +357,10 @@ void itemize(struct file_struct *file, i
137 && (file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
138 iflags |= ITEM_REPORT_PERMS;
139 - if (preserve_uid && am_root && file->uid != st->st_uid)
140 + if (preserve_uid && am_root && uid != st->st_uid)
141 iflags |= ITEM_REPORT_OWNER;
142 - if (preserve_gid && file->gid != GID_NONE
143 - && st->st_gid != file->gid)
144 + if (preserve_gid && gid != GID_NONE
145 + && st->st_gid != gid)
146 iflags |= ITEM_REPORT_GROUP;
148 iflags |= ITEM_IS_NEW;
149 --- orig/rsync.c 2006-01-31 02:30:18
150 +++ rsync.c 2006-01-25 17:26:06
151 @@ -40,6 +40,7 @@ extern int inplace;
152 extern int keep_dirlinks;
153 extern int make_backups;
154 extern struct stats stats;
155 +extern struct id_pair *id_pairs;
159 @@ -78,6 +79,8 @@ int set_file_attrs(char *fname, struct f
162 int change_uid, change_gid;
168 @@ -104,9 +107,11 @@ int set_file_attrs(char *fname, struct f
172 - change_uid = am_root && preserve_uid && st->st_uid != file->uid;
173 - change_gid = preserve_gid && file->gid != GID_NONE
174 - && st->st_gid != file->gid;
175 + uid = id_pairs[file->id_ndx].uid;
176 + gid = id_pairs[file->id_ndx].gid;
177 + change_uid = am_root && preserve_uid && st->st_uid != uid;
178 + change_gid = preserve_gid && gid != GID_NONE
179 + && st->st_gid != gid;
180 #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
181 if (S_ISLNK(st->st_mode))
183 @@ -118,18 +123,18 @@ int set_file_attrs(char *fname, struct f
185 "set uid of %s from %ld to %ld\n",
187 - (long)st->st_uid, (long)file->uid);
188 + (long)st->st_uid, (long)uid);
192 "set gid of %s from %ld to %ld\n",
194 - (long)st->st_gid, (long)file->gid);
195 + (long)st->st_gid, (long)gid);
199 - change_uid ? file->uid : st->st_uid,
200 - change_gid ? file->gid : st->st_gid) != 0) {
201 + change_uid ? uid : st->st_uid,
202 + change_gid ? gid : st->st_gid) != 0) {
203 /* shouldn't have attempted to change uid or gid
204 * unless have the privilege */
205 rsyserr(FERROR, errno, "%s %s failed",
206 --- orig/rsync.h 2006-01-30 20:39:09
207 +++ rsync.h 2006-01-25 17:15:44
208 @@ -493,6 +493,11 @@ struct hlink {
217 #define F_DEV link_u.idev->dev
218 #define F_INODE link_u.idev->inode
220 @@ -517,8 +522,7 @@ struct file_struct {
228 uchar flags; /* this item MUST remain last */
230 --- orig/uidlist.c 2006-01-25 17:15:13
231 +++ uidlist.c 2006-01-25 17:31:20
232 @@ -37,6 +37,8 @@ extern int preserve_gid;
233 extern int numeric_ids;
236 +struct id_pair *id_pairs;
241 @@ -46,6 +48,8 @@ struct idlist {
242 static struct idlist *uidlist;
243 static struct idlist *gidlist;
245 +static int pair_cnt = 0, pair_alloc = 0;
247 static struct idlist *add_to_list(struct idlist **root, int id, char *name,
250 @@ -307,7 +311,7 @@ void send_uid_list(int f)
252 /* recv a complete uid/gid mapping from the peer and map the uid/gid
253 * in the file list to local names */
254 -void recv_uid_list(int f, struct file_list *flist)
255 +void recv_uid_list(int f)
259 @@ -338,11 +342,40 @@ void recv_uid_list(int f, struct file_li
261 /* Now convert all the uids/gids from sender values to our values. */
262 if (am_root && preserve_uid && !numeric_ids) {
263 - for (i = 0; i < flist->count; i++)
264 - flist->files[i]->uid = match_uid(flist->files[i]->uid);
265 + for (i = 0; i < pair_cnt; i++)
266 + id_pairs[i].uid = match_uid(id_pairs[i].uid);
268 if (preserve_gid && (!am_root || !numeric_ids)) {
269 - for (i = 0; i < flist->count; i++)
270 - flist->files[i]->gid = match_gid(flist->files[i]->gid);
271 + for (i = 0; i < pair_cnt; i++)
272 + id_pairs[i].gid = match_gid(id_pairs[i].gid);
276 +int id_pair(uid_t uid, gid_t gid)
282 + /* We start our search where we left off because
283 + * the IDs usually come in clumps. */
285 + if (uid == id_pairs[j].uid && gid == id_pairs[j].gid)
287 + if (++j == pair_cnt)
289 + } while (j != start);
292 + if (pair_cnt == pair_alloc) {
294 + id_pairs = realloc_array(id_pairs, struct id_pair,
299 + id_pairs[j].uid = uid;
300 + id_pairs[j].gid = gid;