commit f8cb4f58c78a989d72b00ff66522b9f7fc25a6ed
Author: Yiannis Pericleous <[EMAIL PROTECTED]>
Date:   Sat Feb 24 15:40:43 2007 -0500

    uuids

diff --git a/fs/unionfs/odf.c b/fs/unionfs/odf.c
index b6ecc76..5c84f68 100644
--- a/fs/unionfs/odf.c
+++ b/fs/unionfs/odf.c
@@ -799,6 +799,13 @@ int __odf_set_opaque(struct inode *i, int branch)
        return err;
 }
 
+void print_uuid(unsigned char *uuid)
+{
+       int i;
+       for (i = 0; i < 4; i++){
+               printk("%x-", *((unsigned int *) ((uuid+i*4))));                
}
+       printk("\n");
+}
 /* 
  * Requires an odf_sb_info, returns the dirs= part of the mount options 
  */
@@ -812,6 +819,7 @@ char *odf_get_options(struct odf_sb_info *odf_sb)
        char *ptr;
        mm_segment_t oldfs;
        int perms, len, count, version;
+       unsigned char uuid[UUID_LEN];
        __le32 le32;
 
        options = kzalloc(ODF_OPTIONS_LEN, GFP_KERNEL); /*XXX*/
@@ -868,6 +876,8 @@ char *odf_get_options(struct odf_sb_info *odf_sb)
                file->f_op->read(file, ptr, len, &file->f_pos);
                file->f_op->read(file, (char*)&le32, sizeof(__le32), 
&file->f_pos);
                perms = le32_to_cpu(le32);
+               file->f_op->read(file, (char*)uuid, UUID_LEN, &file->f_pos);
+               print_uuid(uuid);
                ptr+=len;
                if (perms == MAY_READ)
                        sprintf(ptr,"=ro:");
@@ -911,7 +921,6 @@ int odf_is_new(struct odf_sb_info *osi, int unset)
        dput(newbit);
        return 1;
 }
-
 /*
  *     Writes the superblock data for new odf's, generates branch UUID's
  */
@@ -921,9 +930,11 @@ int odf_put_options(struct super_block* sb_union, struct 
unionfs_dentry_info *hi
        struct vfsmount *m, *odf_mnt;
        struct file *file;
        char *name;
-       int perms, len, bindex;
-       int err = 0;
+       int perms, len, bindex, i;
+       int count, err = 0;
        __le32 le32;
+       unsigned char *uuid = NULL;
+       u32 *bid = NULL;
        char *branch_entry = kmalloc(ODF_BRANCH_PATH, GFP_KERNEL);
        char *branch_path = kmalloc(ODF_BRANCH_PATH, GFP_KERNEL);
        mm_segment_t oldfs;
@@ -969,9 +980,18 @@ int odf_put_options(struct super_block* sb_union, struct 
unionfs_dentry_info *hi
        file->f_op->write(file, (char*)&le32, sizeof(__le32), &file->f_pos);
 
        /* number of branches */
-       le32 = cpu_to_le32(hidden_root->bend - hidden_root->bstart + 1);
+       count = hidden_root->bend - hidden_root->bstart + 1;
+       le32 = cpu_to_le32(count);
        file->f_op->write(file, (char*)&le32, sizeof(__le32), &file->f_pos);
 
+       bid = kmalloc(count * sizeof(u32), GFP_KERNEL);
+       uuid = kmalloc(count * UUID_LEN, GFP_KERNEL);
+       if (!bid || !uuid) {
+               err = -ENOMEM;
+               goto out_close;
+       }
+       count = 0;
+
        /* now info about each branch */
        for (bindex = hidden_root->bstart;
                        bindex >= 0 && bindex <= hidden_root->bend;
@@ -986,16 +1006,34 @@ int odf_put_options(struct super_block* sb_union, struct 
unionfs_dentry_info *hi
                perms = branchperms(sb_union, bindex); 
                len = strlen(name);
        
-               /* also need to store UUIDs here */
+               /* generate UUIDs, we want to have same ids for same fss*/
+               for (i = 0; i < count; i++) {
+                       if ((u32)m == bid[i])
+                               break;
+               }
+               if (i == count)
+                       generate_random_uuid(uuid + count * UUID_LEN);
+               else
+                       memcpy(uuid + count * UUID_LEN, uuid + i * UUID_LEN, 
UUID_LEN);
+               print_uuid(uuid + count * UUID_LEN);
+               bid[count] = (u32)m;
+
+               /* write */
                le32 = cpu_to_le32(len);        
                file->f_op->write(file, (char*)&le32, sizeof(__le32), 
&file->f_pos);
                file->f_op->write(file, name, strlen(name), &file->f_pos);
                le32 = cpu_to_le32(perms);
                file->f_op->write(file, (char*)&le32, sizeof(__le32), 
&file->f_pos);
+               file->f_op->write(file, (char*)uuid + count * UUID_LEN, 
UUID_LEN, &file->f_pos);
+               count++;
        }
+
+out_close:
        set_fs(oldfs);
        filp_close(file,NULL);
 out:
+       kfree(uuid);
+       kfree(bid);
        kfree(branch_path);
        kfree(branch_entry);
        return err;
diff --git a/fs/unionfs/odf.h b/fs/unionfs/odf.h
index aeaf68e..e586418 100644
--- a/fs/unionfs/odf.h
+++ b/fs/unionfs/odf.h
@@ -3,6 +3,7 @@
 
 #include "../ext2/ext2.h"
 
+#define UUID_LEN 16
 #define ODF_VERSION_MINOR 0
 #define ODF_VERSION_MAJOR 1
 
@@ -94,5 +95,6 @@ static inline void odf_unlock(struct odf_dentry_info *odi)
        mutex_unlock(&odi->lock);
 }
 
+extern void generate_random_uuid(unsigned char uuid_out[16]);
 
 #endif /* _ODF_H_ */
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to