[Patch 2/7] tabled: Make DB object host byte order independent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I did a partial conversion back in the day because I was afraid to
lose track of changes. Let's finish it now.

Signed-off-by: Pete Zaitcev <zaitcev@xxxxxxxxxx>

---
 server/bucket.c |    4 ++--
 server/object.c |   16 +++++++++-------
 server/tdbadm.c |    4 ++--
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/server/bucket.c b/server/bucket.c
index b3c73de..09ff14c 100644
--- a/server/bucket.c
+++ b/server/bucket.c
@@ -1022,8 +1022,8 @@ static bool bucket_list_keys(struct client *cli, const char *user,
 		strcpy(v.md5, obj->md5);
 		if (!(GUINT32_FROM_LE(obj->flags) & DB_OBJ_INLINE))
 			memcpy(&v.addr, &obj->d.a, sizeof(v.addr));
-		v.mtime = obj->mtime;
-		v.size = obj->size;
+		v.mtime = GUINT64_FROM_LE(obj->mtime);
+		v.size = GUINT64_FROM_LE(obj->size);
 		free(obj);
 
 		if (bucket_list_iter(tmpkey->key, &v, &bli))
diff --git a/server/object.c b/server/object.c
index 69f3af0..b329c0d 100644
--- a/server/object.c
+++ b/server/object.c
@@ -332,6 +332,7 @@ static bool object_put_end(struct client *cli)
 	GArray *string_lens;
 	uint16_t tmp16;
 	uint32_t n_str;
+	uint64_t tmp_time;
 	void *mem;
 
 	if (http11(&cli->req))
@@ -444,8 +445,9 @@ static bool object_put_end(struct client *cli)
 		goto err_out_rb;
 
 	/* encode object header */
-	obj->size = cli->out_size;
-	obj->mtime = (uint64_t)time(NULL) * 1000000;
+	obj->size = GUINT64_TO_LE(cli->out_size);
+	tmp_time = (uint64_t)time(NULL) * 1000000;
+	obj->mtime = GUINT64_TO_LE(tmp_time);
 	memcpy(&obj->d.a, &obj_addr, sizeof(struct db_obj_addr));
 	strncpy(obj->bucket, cli->out_bucket, sizeof(obj->bucket));
 	strncpy(obj->owner, cli->out_user, sizeof(obj->owner));
@@ -1213,7 +1215,7 @@ bool object_get_body(struct client *cli, const char *user, const char *bucket,
 			goto err_out_in_end;
 		}
 
-		if (obj->mtime / 1000000 > t) {
+		if (GUINT64_FROM_LE(obj->mtime) / 1000000 > t) {
 			err = PreconditionFailed;
 			goto err_out_in_end;
 		}
@@ -1229,7 +1231,7 @@ bool object_get_body(struct client *cli, const char *user, const char *bucket,
 			goto err_out_in_end;
 		}
 
-		if (obj->mtime / 1000000 <= t) {
+		if (GUINT64_FROM_LE(obj->mtime) / 1000000 <= t) {
 			modified = false;
 			want_body = false;
 		}
@@ -1253,10 +1255,10 @@ bool object_get_body(struct client *cli, const char *user, const char *bucket,
 		     cli->req.major,
 		     cli->req.minor,
 		     modified ? 200 : 304,
-		     (unsigned long long) obj->size,
+		     (unsigned long long) GUINT64_FROM_LE(obj->size),
 		     md5,
 		     time2str(timestr, time(NULL)),
-		     time2str(modstr, obj->mtime / 1000000),
+		     time2str(modstr, GUINT64_FROM_LE(obj->mtime) / 1000000),
 		     extra_hdr->str) < 0)
 		goto err_out_in_end;
 
@@ -1271,7 +1273,7 @@ bool object_get_body(struct client *cli, const char *user, const char *bucket,
 		goto start_write;
 	}
 
-	cli->in_len = obj->size;
+	cli->in_len = GUINT64_FROM_LE(obj->size);
 
 	bytes = stor_get_buf(&cli->in_ce, buf, MIN(cli->in_len, sizeof(buf)));
 	if (bytes < 0) {
diff --git a/server/tdbadm.c b/server/tdbadm.c
index 823432a..5ab007b 100644
--- a/server/tdbadm.c
+++ b/server/tdbadm.c
@@ -430,11 +430,11 @@ static void print_obj(struct db_obj_ent *obj)
 	char *dbstr;
 
 	if (GUINT32_FROM_LE(obj->flags) & DB_OBJ_INLINE) {
-		printf("%s\t%s\t%s\t[%d]\t%u\n",
+		printf("%s\t%s\t%s\t[%u]\t%u\n",
 			obj->bucket,
 			obj->owner,
 			obj->md5,
-			GUINT16_FROM_LE(obj->size),
+			(unsigned) GUINT64_FROM_LE(obj->size),
 			n_str);
 	} else {
 		printf("%s\t%s\t%s\t%llX",
--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Fedora Clound]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux