commit 1b402f91c0895eeac448e4723ed95b1887dd310e
Author: Yiannis Pericleous <[EMAIL PROTECTED]>
Date: Sat Feb 24 14:15:47 2007 -0500
odf version and endianes fix when writing sb
diff --git a/fs/unionfs/odf.c b/fs/unionfs/odf.c
index d83491f..b6ecc76 100644
--- a/fs/unionfs/odf.c
+++ b/fs/unionfs/odf.c
@@ -811,8 +811,8 @@ char *odf_get_options(struct odf_sb_info *odf_sb)
struct file *file;
char *ptr;
mm_segment_t oldfs;
- int perms = 0, len = 0;
- int count;
+ int perms, len, count, version;
+ __le32 le32;
options = kzalloc(ODF_OPTIONS_LEN, GFP_KERNEL); /*XXX*/
branch_entry = kzalloc(ODF_BRANCH_PATH, GFP_KERNEL);
@@ -848,12 +848,26 @@ char *odf_get_options(struct odf_sb_info *odf_sb)
oldfs = get_fs();
set_fs(KERNEL_DS);
- file->f_op->read(file, (char*)&count, sizeof(int), &file->f_pos);
+ /* version */
+ file->f_op->read(file, (char*)&le32, sizeof(__le32), &file->f_pos);
+ /* check version - dont allow greater than current */
+ version = le32_to_cpu(le32);
+ if (((version >> 16) > ODF_VERSION_MAJOR) ||
+ (((version >> 16) == ODF_VERSION_MAJOR) &&
+ (version & 0x0000FFFF) > ODF_VERSION_MINOR)) {
+ printk(KERN_WARNING "unionfs: unsupported odf version\n");
+ goto out_close;
+ }
+
+ /* branch count */
+ file->f_op->read(file, (char*)&le32, sizeof(__le32), &file->f_pos);
+ count = le32_to_cpu(le32);
while (count) {
- file->f_op->read(file, (char*)&len, sizeof(int), &file->f_pos);
+ file->f_op->read(file, (char*)&le32, sizeof(__le32),
&file->f_pos);
+ len = le32_to_cpu(le32);
file->f_op->read(file, ptr, len, &file->f_pos);
- file->f_op->read(file, (char*)&perms, sizeof(int),
&file->f_pos);
-
+ file->f_op->read(file, (char*)&le32, sizeof(__le32),
&file->f_pos);
+ perms = le32_to_cpu(le32);
ptr+=len;
if (perms == MAY_READ)
sprintf(ptr,"=ro:");
@@ -865,6 +879,9 @@ char *odf_get_options(struct odf_sb_info *odf_sb)
set_fs(oldfs);
filp_close(file,NULL);
goto out;
+out_close:
+ set_fs(oldfs);
+ filp_close(file,NULL);
out_err:
kfree(options);
options = NULL;
@@ -906,7 +923,7 @@ int odf_put_options(struct super_block* sb_union, struct
unionfs_dentry_info *hi
char *name;
int perms, len, bindex;
int err = 0;
- int count;
+ __le32 le32;
char *branch_entry = kmalloc(ODF_BRANCH_PATH, GFP_KERNEL);
char *branch_path = kmalloc(ODF_BRANCH_PATH, GFP_KERNEL);
mm_segment_t oldfs;
@@ -941,13 +958,21 @@ int odf_put_options(struct super_block* sb_union, struct
unionfs_dentry_info *hi
mntput(odf_mnt);
goto out;
}
- file->f_pos = 0; /* leave space for branch count */
+ file->f_pos = 0;
oldfs = get_fs();
set_fs(KERNEL_DS);
- count = hidden_root->bend - hidden_root->bstart + 1;
- file->f_op->write(file, (char*)&count, sizeof(int), &file->f_pos);
+ /* version */
+ le32 = (ODF_VERSION_MAJOR<<16) | (ODF_VERSION_MINOR);
+ le32 = cpu_to_le32(le32);
+ 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);
+ file->f_op->write(file, (char*)&le32, sizeof(__le32), &file->f_pos);
+
+ /* now info about each branch */
for (bindex = hidden_root->bstart;
bindex >= 0 && bindex <= hidden_root->bend;
bindex++) {
@@ -960,10 +985,13 @@ int odf_put_options(struct super_block* sb_union, struct
unionfs_dentry_info *hi
name = d_path(d, m, branch_path, ODF_BRANCH_PATH);
perms = branchperms(sb_union, bindex);
len = strlen(name);
-
- file->f_op->write(file, (char*)&len, sizeof(int), &file->f_pos);
+
+ /* also need to store UUIDs here */
+ 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);
- file->f_op->write(file, (char*)&perms, sizeof(int),
&file->f_pos);
+ le32 = cpu_to_le32(perms);
+ file->f_op->write(file, (char*)&le32, sizeof(__le32),
&file->f_pos);
}
set_fs(oldfs);
filp_close(file,NULL);
diff --git a/fs/unionfs/odf.h b/fs/unionfs/odf.h
index a598c10..aeaf68e 100644
--- a/fs/unionfs/odf.h
+++ b/fs/unionfs/odf.h
@@ -3,6 +3,9 @@
#include "../ext2/ext2.h"
+#define ODF_VERSION_MINOR 0
+#define ODF_VERSION_MAJOR 1
+
#define ODF_SB "sb"
#define ODF_IC "ic"
#define ODF_RC "reclaim"
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs