Package: cfs
Version: 1.4.1-20
Followup-For: Bug #451809

I reached some success in running CFS on 64 bit system.

Included patch contains following changes:
1) Made ``long'' types substitution through almost all code:
unsigned long -> uint32_t
long -> int32_t
u_long -> uint32_t

I left original ``long'' types only for file identifiers and file offsets.

After that cfs is somehow worked on amd64, but not very well.

2) Added check in fhsetattr* functions for microseconds parameters values: 
0 <= microsecond value < 1000000.
Otherwise all operations with attributes, where microseconds parameter
is not setted explicitely in call, are done with microseconds value of
1000000 (why?), which leads to ``Invalid argument'' error in utimes() syscall.
(Also it is was impossible even to open file with O_TRUNC in CFS filesystem, 
due to utimes() failures.)


As result now CFS runs in my amd64 environment this like:
 * Filesystems created in 32 bit environment can be mounted.
 * Files and directories can be readed in mounted fs.
 * Files can be created, removed, modified in mounted fs.
 * Directories in mounted fs can be removed, but cfsd fails with segfault on 
mkdir() syscall :(
 * cattach, cdetach, cmkdir seems works.

It is possible to debug CFS for 64 bit systems so, that it will work stable, 
but it would be very hard, because code is not supported for a long time.
Main goal of this patch is to provide possibility to mount old 32 bit 
filesystems on 64 bit system and extract it contents to some better 
supported cryptographics solution (I use ``encfs'' package now).

I hope my patch will be usefull.


-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing'), (497, 'unstable'), (495, 'stable'), (493, 
'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.24-1-amd64 (SMP w/1 CPU core)
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages cfs depends on:
ii  libc6                         2.7-10     GNU C Library: Shared libraries
ii  nfs-kernel-server             1:1.1.2-4  support for NFS kernel server

cfs recommends no packages.

-- no debconf information
diff -aur cfs-1.4.1-orig/admproto.x cfs-1.4.1/admproto.x
--- cfs-1.4.1-orig/admproto.x	1995-12-25 10:51:29.000000000 +0300
+++ cfs-1.4.1/admproto.x	2008-06-06 07:07:07.000000000 +0400
@@ -50,13 +50,13 @@
 
 
 struct cfs_adm_deskey {
-	long pl;	/* for the align police */
+	int32_t pl;	/* for the align police */
 	u_char primary[8];
 	u_char secondary[8];
 };
 
 struct cfs_adm_3deskey {
-	long pl;	/* for the align police */
+	int32_t pl;	/* for the align police */
 	u_char primary1[8];
 	u_char primary2[8];
 	u_char secondary1[8];	/* same as primaries */
@@ -64,7 +64,7 @@
 };
 
 struct cfs_adm_t3deskey {
-	long pl;	/* for the align police */
+	int32_t pl;	/* for the align police */
 	u_char primary1[8];
 	u_char primary2[8];
 	u_char primary3[8];
@@ -74,20 +74,20 @@
 };
 
 struct cfs_adm_blowkey {
-	long pl;		/* for 32 bit police */
+	int32_t pl;		/* for 32 bit police */
 	u_char primary[16];
 	u_char secondary[16];	/* same as primary */
 };
 
 struct cfs_adm_mcgkey {
-	long pl;		/* for 32 bit align police */
+	int32_t pl;		/* for 32 bit align police */
 	u_char primary[16];
 	u_char secondary[16];	/* same as primary */
 };
 
 
 struct cfs_adm_saferkey {
-	long pl;		/* for 32 bit align police */
+	int32_t pl;		/* for 32 bit align police */
 	u_char primary[16];
 	u_char secondary[16];	/* same as primary */
 };
diff -aur cfs-1.4.1-orig/cfs_fh.c cfs-1.4.1/cfs_fh.c
--- cfs-1.4.1-orig/cfs_fh.c	2008-06-06 06:40:04.000000000 +0400
+++ cfs-1.4.1/cfs_fh.c	2008-06-06 07:07:07.000000000 +0400
@@ -61,7 +61,7 @@
 }
 #endif
 
-#define hash(x) ((u_long)((x)&HMASK))
+#define hash(x) ((uint32_t)((x)&HMASK))
 int inst = 0;/* starting point */
 instance *instances[NINSTANCES];
 
@@ -135,7 +135,6 @@
 	int headlen;
 	int writemore=0;
 	struct stat sb;
-	u_long mask = ~0;	/*tells us whether to expand file */
 	char buf[8216];	/* big enough, may not even need it */
 
 	/* first, normalize to the proper boundries */
@@ -231,9 +230,9 @@
  */
 chksum(s,l)
      char *s;
-     long l;
+     int32_t l;
 {
-	u_long acc;
+	uint32_t acc;
 	int i;
 	u_char bits[8];
 
@@ -258,9 +257,9 @@
 
 unchksum(s,l)
     char *s;
-    long l;
+    int32_t l;
 {
-	u_long acc;
+	uint32_t acc;
 	int i;
 	u_char bits[8];
 
@@ -325,7 +324,7 @@
      cfskey *k;
      char *s;
      int l;
-     u_long salt;
+     uint32_t salt;
      char *vect;
 {
 	int i,j,smsize;
@@ -347,7 +346,7 @@
      cfskey *k;
      char *s;
      int l;
-     u_long salt;
+     uint32_t salt;
      char *vect;
 {
 	int i,j,smsize;
@@ -720,7 +719,7 @@
 			return -1;
 	}
 	if (((int)a->atime.seconds>=0) || ((int)a->mtime.seconds>=0)) {
-		if ((int)a->atime.seconds<0) {
+		if ((int)a->atime.seconds<0 || (int)a->atime.useconds < 0 || (int)a->atime.useconds >= 1000000) {
 			lstat(f->name,&sb);
 			tv[0].tv_sec=sb.st_atime;
 			tv[0].tv_usec=0;
@@ -728,7 +727,7 @@
 			tv[0].tv_sec=a->atime.seconds;
 			tv[0].tv_usec=a->atime.useconds;
 		}
-		if ((int)a->mtime.seconds<0) {
+		if ((int)a->mtime.seconds<0 || (int)a->mtime.useconds < 0 || (int)a->mtime.useconds >= 1000000) {
 			lstat(f->name,&sb);
 			tv[1].tv_sec=sb.st_mtime;
 			tv[1].tv_usec=0;
@@ -769,7 +768,7 @@
 		return 0;
 	/* same as above, modulo the chmod */
 	if (((int)a->atime.seconds>=0) || ((int)a->mtime.seconds>=0)) {
-		if ((int)a->atime.seconds<0) {
+		if ((int)a->atime.seconds<0 || (int)a->atime.useconds < 0 || (int)a->atime.useconds >= 1000000) {
 			lstat(f->name,&sb);
 			tv[0].tv_sec=sb.st_atime;
 			tv[0].tv_usec=0;
@@ -777,7 +776,7 @@
 			tv[0].tv_sec=a->atime.seconds;
 			tv[0].tv_usec=a->atime.useconds;
 		}
-		if ((int)a->mtime.seconds<0) {
+		if ((int)a->mtime.seconds<0 || (int)a->mtime.useconds < 0 || (int)a->mtime.useconds >= 1000000) {
 			lstat(f->name,&sb);
 			tv[1].tv_sec=sb.st_mtime;
 			tv[1].tv_usec=0;
@@ -833,7 +832,7 @@
 	char vect[9];
 	union{
 		u_char ch[9];
-		u_long i[2];
+		uint32_t i[2];
 	} buf;
 	char linkname[NFS_MAXPATHLEN+1];
 	
@@ -860,10 +859,10 @@
 	   if (p->ins->highsec) {	/* create new pert file iff highsec */
 		/* note that there's a race condition here until the simlink */
 		/*
-		sprintf((char *)buf,"%08x",(u_long)sb.st_ino+(u_long)sb.st_ctime);
+		sprintf((char *)buf,"%08x",(uint32_t)sb.st_ino+(uint32_t)sb.st_ctime);
 		*/
-		buf.i[0]=(u_long)sb.st_ino;
-		buf.i[1]=(u_long)sb.st_ctime;
+		buf.i[0]=(uint32_t)sb.st_ino;
+		buf.i[1]=(uint32_t)sb.st_ctime;
 		q_block_cipher("fixedkey",&buf,1);
 		/* des is just used here as a hash fn to spread the bits */
 		/* since we only use 32 bits of the result, its a nonperfect */
@@ -1228,7 +1227,7 @@
    break anything */
 struct dirent *
 rootrd(cookie)
-     long cookie;
+     int32_t cookie;
 {
 	static struct dirent d;
 
diff -aur cfs-1.4.1-orig/cfs_nfs.c cfs-1.4.1/cfs_nfs.c
--- cfs-1.4.1-orig/cfs_nfs.c	2008-06-06 06:40:04.000000000 +0400
+++ cfs-1.4.1/cfs_nfs.c	2008-06-06 07:35:21.000000000 +0400
@@ -873,7 +882,7 @@
 	ne=0;
 	prev= &ret.readdirres_u.reply.entries;
 	*prev=NULL;
-	cookie = ntohl(*(unsigned long*)(ap->cookie));
+	cookie = ntohl(*(uint32_t*)(ap->cookie));
 	eof=TRUE;
 	
 	key=keyof(h);
@@ -1127,7 +1136,7 @@
 	ne=0;
 	prev= &ret.readdirres_u.reply.entries;
 	*prev=NULL;
-	cookie = ntohl(*(unsigned long*)(ap->cookie));
+	cookie = ntohl(*(uint32_t*)(ap->cookie));
 	eof=1;
 	
 	ret.status=NFS_OK;
diff -aur cfs-1.4.1-orig/cmkdir.c cfs-1.4.1/cmkdir.c
--- cfs-1.4.1-orig/cmkdir.c	2008-06-06 06:40:04.000000000 +0400
+++ cfs-1.4.1/cmkdir.c	2008-06-06 07:07:07.000000000 +0400
@@ -46,7 +46,7 @@
 	FILE *fp;
 	char *flg;
 	struct timeval tv;
-	u_long r;
+	uint32_t r;
 	int i;
 	int ciph=CFS_THREE_DES;
 	int cfmt=1;
diff -aur cfs-1.4.1-orig/esm_cipher.c cfs-1.4.1/esm_cipher.c
--- cfs-1.4.1-orig/esm_cipher.c	1995-12-25 12:27:41.000000000 +0300
+++ cfs-1.4.1/esm_cipher.c	2008-06-06 07:07:07.000000000 +0400
@@ -157,7 +157,7 @@
 	unsigned int n;
 	int i;
 	struct timeval tv;
-	unsigned long truerand();
+	uint32_t truerand();
 	unsigned char b[20];
 	
 	R_RandomInit(&rs);
diff -aur cfs-1.4.1-orig/nfsproto.x cfs-1.4.1/nfsproto.x
--- cfs-1.4.1-orig/nfsproto.x	2008-06-06 06:40:04.000000000 +0400
+++ cfs-1.4.1/nfsproto.x	2008-06-06 07:07:07.000000000 +0400
@@ -259,7 +259,7 @@
 };
 
 struct entry {
-	unsigned long fileid;
+	uint32_t fileid;
 	filename name;
 	nfscookie cookie;
 	entry *nextentry;
diff -aur cfs-1.4.1-orig/shs.c cfs-1.4.1/shs.c
--- cfs-1.4.1-orig/shs.c	2008-06-06 06:40:04.000000000 +0400
+++ cfs-1.4.1/shs.c	2008-06-06 07:07:07.000000000 +0400
@@ -98,7 +98,7 @@
 	int nd32;
 	
 	nd32 = (int)(nbits >> 5);
-	w[nd32] = (u_long)(((u_long)c0<<24) | ((u_long)c1<<16) | ((u_long)c2<<8) | (u_long)c3);
+	w[nd32] = (uint32_t)(((uint32_t)c0<<24) | ((uint32_t)c1<<16) | ((uint32_t)c2<<8) | (uint32_t)c3);
 	
 	nbits += 32;
 	if(nbits==512){
@@ -129,19 +129,19 @@
 	uint32_t A, B, C, D, E;
 	int t;
 	
-#define S(n,x) (u_long)(((x)<<(n))|((MASK&(x))>>(32-(n))))
+#define S(n,x) (uint32_t)(((x)<<(n))|((MASK&(x))>>(32-(n))))
 	
 	wp = w;
 	t = 8;
 	do {
-		wp[16] = S(1, (u_long)(wp[13]^wp[8]^wp[2]^wp[0]));
-		wp[17] = S(1, (u_long)(wp[14]^wp[9]^wp[3]^wp[1]));
-		wp[18] = S(1, (u_long)(wp[15]^wp[10]^wp[4]^wp[2]));
-		wp[19] = S(1, (u_long)(wp[16]^wp[11]^wp[5]^wp[3]));
-		wp[20] = S(1, (u_long)(wp[17]^wp[12]^wp[6]^wp[4]));
-		wp[21] = S(1, (u_long)(wp[18]^wp[13]^wp[7]^wp[5]));
-		wp[22] = S(1, (u_long)(wp[19]^wp[14]^wp[8]^wp[6]));
-		wp[23] = S(1, (u_long)(wp[20]^wp[15]^wp[9]^wp[7]));
+		wp[16] = S(1, (uint32_t)(wp[13]^wp[8]^wp[2]^wp[0]));
+		wp[17] = S(1, (uint32_t)(wp[14]^wp[9]^wp[3]^wp[1]));
+		wp[18] = S(1, (uint32_t)(wp[15]^wp[10]^wp[4]^wp[2]));
+		wp[19] = S(1, (uint32_t)(wp[16]^wp[11]^wp[5]^wp[3]));
+		wp[20] = S(1, (uint32_t)(wp[17]^wp[12]^wp[6]^wp[4]));
+		wp[21] = S(1, (uint32_t)(wp[18]^wp[13]^wp[7]^wp[5]));
+		wp[22] = S(1, (uint32_t)(wp[19]^wp[14]^wp[8]^wp[6]));
+		wp[23] = S(1, (uint32_t)(wp[20]^wp[15]^wp[9]^wp[7]));
 		wp += 8;
 		t--;
 	} while (t > 0);
@@ -180,7 +180,7 @@
 	h[4] = MASK&(h[4] + E);
 }
 
-#define CHARSTOLONG(wp,s,i) {*wp++ = (u_long)((((u_long)(s[i])&0xff)<<24)|(((u_long)(s[i+1])&0xff)<<16)|(((u_long)(s[i+2])&0xff)<<8)|(u_long)(s[i+3]&0xff));}
+#define CHARSTOLONG(wp,s,i) {*wp++ = (uint32_t)((((uint32_t)(s[i])&0xff)<<24)|(((uint32_t)(s[i+1])&0xff)<<16)|(((uint32_t)(s[i+2])&0xff)<<8)|(uint32_t)(s[i+3]&0xff));}
 
 
 void
@@ -212,7 +212,7 @@
 	mdContext->totalLength += n;
 	
 	nbits = 0;
-	n = n/(u_long)64;
+	n = n/(uint32_t)64;
 	wp = w;
 	
 	while(n>0){
@@ -241,7 +241,7 @@
 	while(i>3) {
 		CHARSTOLONG(wp,s,0);
 		s = (s + 4);
-		nbits += (u_long)32;
+		nbits += (uint32_t)32;
 		i -= 4;
 	}
 	while (i) {

Reply via email to