Use the new dev+inode union in the flist_struct.
authorWayne Davison <wayned@samba.org>
Sun, 11 Jan 2004 07:56:14 +0000 (07:56 +0000)
committerWayne Davison <wayned@samba.org>
Sun, 11 Jan 2004 07:56:14 +0000 (07:56 +0000)
flist.c
hlink.c

diff --git a/flist.c b/flist.c
index 8b80b16..f2096f3 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -416,12 +416,12 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
                flags |= SAME_TIME;
        else
                modtime = file->modtime;
-       if (file->flags & HAS_INODE_DATA) {
-               if (file->dev == dev) {
+       if (file->link_u.idev) {
+               if (file->F_DEV == dev) {
                        if (protocol_version >= 28)
                                flags |= SAME_DEV;
                } else
-                       dev = file->dev;
+                       dev = file->F_DEV;
                flags |= HAS_INODE_DATA;
        }
 
@@ -493,12 +493,12 @@ void send_file_entry(struct file_struct *file, int f, unsigned short base_flags)
                if (protocol_version < 26) {
                        /* 32-bit dev_t and ino_t */
                        write_int(f, dev);
-                       write_int(f, file->inode);
+                       write_int(f, file->F_INODE);
                } else {
                        /* 64-bit dev_t and ino_t */
                        if (!(flags & SAME_DEV))
                                write_longint(f, dev);
-                       write_longint(f, file->inode);
+                       write_longint(f, file->F_INODE);
                }
        }
 #endif
@@ -649,19 +649,20 @@ void receive_file_entry(struct file_struct **fptr, unsigned short flags, int f)
                        sanitize_path(file->u.link, file->dirname);
        }
 #if SUPPORT_HARD_LINKS
-       if (preserve_hard_links && protocol_version < 28
-           && S_ISREG(mode))
-               file->flags |= HAS_INODE_DATA;
-       if (file->flags & HAS_INODE_DATA) {
+       if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode))
+               flags |= HAS_INODE_DATA;
+       if (flags & HAS_INODE_DATA) {
+               if (!(file->link_u.idev = new(struct idev)))
+                       out_of_memory("file inode data");
                if (protocol_version < 26) {
                        dev = read_int(f);
-                       file->inode = read_int(f);
+                       file->F_INODE = read_int(f);
                } else {
                        if (!(flags & SAME_DEV))
                                dev = read_longint(f);
-                       file->inode = read_longint(f);
+                       file->F_INODE = read_longint(f);
                }
-               file->dev = dev;
+               file->F_DEV = dev;
        }
 #endif
 
@@ -825,11 +826,12 @@ struct file_struct *make_file(char *fname, struct string_area **ap,
        file->uid = st.st_uid;
        file->gid = st.st_gid;
        if (preserve_hard_links) {
-               if (protocol_version < 28? S_ISREG(st.st_mode)
+               if (protocol_version < 28 ? S_ISREG(st.st_mode)
                    : !S_ISDIR(st.st_mode) && st.st_nlink > 1) {
-                       file->dev = st.st_dev;
-                       file->inode = st.st_ino;
-                       file->flags |= HAS_INODE_DATA;
+                       if (!(file->link_u.idev = new(struct idev)))
+                               out_of_memory("file inode data");
+                       file->F_DEV = st.st_dev;
+                       file->F_INODE = st.st_ino;
                }
        }
 #ifdef HAVE_STRUCT_STAT_ST_RDEV
@@ -1300,6 +1302,8 @@ void free_file(struct file_struct *file)
                free(file->basename);
        if (!IS_DEVICE(file->mode) && file->u.link)
                free(file->u.link); /* Handles u.sum too. */
+       if (file->link_u.idev)
+               free((char*)file->link_u.idev); /* Handles link_u.links too. */
        *file = null_file;
 }
 
diff --git a/hlink.c b/hlink.c
index 5a61720..289842e 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -29,11 +29,11 @@ static int hlink_compare(struct file_struct **file1, struct file_struct **file2)
        struct file_struct *f1 = *file1;
        struct file_struct *f2 = *file2;
 
-       if (f1->dev != f2->dev)
-               return (int) (f1->dev > f2->dev ? 1 : -1);
+       if (f1->F_DEV != f2->F_DEV)
+               return (int) (f1->F_DEV > f2->F_DEV ? 1 : -1);
 
-       if (f1->inode != f2->inode)
-               return (int) (f1->inode > f2->inode ? 1 : -1);
+       if (f1->F_INODE != f2->F_INODE)
+               return (int) (f1->F_INODE > f2->F_INODE ? 1 : -1);
 
        return file_compare(file1, file2);
 }
@@ -62,7 +62,7 @@ void init_hard_links(struct file_list *flist)
  */
        hlink_count = 0;
        for (i = 0; i < flist->count; i++) {
-               if (flist->files[i]->flags & HAS_INODE_DATA)
+               if (flist->files[i]->link_u.idev)
                        hlink_list[hlink_count++] = flist->files[i];
        }
 
@@ -86,7 +86,7 @@ int check_hard_link(struct file_struct *file)
        int low = 0, high = hlink_count - 1;
        int ret = 0;
 
-       if (!hlink_list || !(file->flags & HAS_INODE_DATA))
+       if (!hlink_list || !file->link_u.idev)
                return 0;
 
        while (low != high) {
@@ -108,8 +108,8 @@ int check_hard_link(struct file_struct *file)
                return 0;
 
        if (low > 0 &&
-           file->dev == hlink_list[low - 1]->dev &&
-           file->inode == hlink_list[low - 1]->inode) {
+           file->F_DEV == hlink_list[low - 1]->F_DEV &&
+           file->F_INODE == hlink_list[low - 1]->F_INODE) {
                if (verbose >= 2) {
                        rprintf(FINFO, "check_hard_link: \"%s\" is a hard link to file %d, \"%s\"\n",
                                f_name(file), low-1, f_name(hlink_list[low-1]));
@@ -173,8 +173,8 @@ void do_hard_links(void)
 
        for (i = 1; i < hlink_count; i++) {
                if (hlink_list[i]->basename && hlink_list[i - 1]->basename &&
-                   hlink_list[i]->dev == hlink_list[i - 1]->dev &&
-                   hlink_list[i]->inode == hlink_list[i - 1]->inode) {
+                   hlink_list[i]->F_DEV == hlink_list[i - 1]->F_DEV &&
+                   hlink_list[i]->F_INODE == hlink_list[i - 1]->F_INODE) {
                        hard_link_one(i);
                }
        }