patch-2.2.0-pre4 linux/fs/ntfs/util.c

Next file: linux/fs/ntfs/util.h
Previous file: linux/fs/ntfs/types.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.0-pre3/linux/fs/ntfs/util.c linux/fs/ntfs/util.c
@@ -2,13 +2,13 @@
  *  util.c
  *  Miscellaneous support
  *
- *  Copyright (C) 1997 Martin von Löwis
+ *  Copyright (C) 1997,1999 Martin von Löwis
  *  Copyright (C) 1997 Régis Duchesne
  *
- *  The utf8 routines are copied from Python wstrop module,
+ *  The utf8 routines are copied from Python wstrop module.
  */
 
-#include "types.h"
+#include "ntfstypes.h"
 #include "struct.h"
 #include "util.h"
 
@@ -20,6 +20,7 @@
 #include "support.h"
 
 /* Converts a single wide character to a sequence of utf8 bytes.
+ * The character is represented in host byte order.
  * Returns the number of bytes, or 0 on error.
  */
 static int
@@ -28,7 +29,7 @@
 	if(c==0)
 		return 0; /* No support for embedded 0 runes */
 	if(c<0x80){
-		if(buf)buf[0]=c;
+		if(buf)buf[0]=(unsigned char)c;
 		return 1;
 	}
 	if(c<0x800){
@@ -51,7 +52,8 @@
 }
 
 /* Decodes a sequence of utf8 bytes into a single wide character.
- * Returns the number of bytes consumed, or 0 on error
+ * The character is returned in host byte order.
+ * Returns the number of bytes consumed, or 0 on error.
  */
 static int
 from_utf8(const unsigned char* str,ntfs_u16 *c)
@@ -98,10 +100,10 @@
 	int len8;
 	unsigned char *result;
 
-	ntfs_debug(DEBUG_OTHER,"converting l=%d\n",in_len);
+	ntfs_debug(DEBUG_NAME1,"converting l=%d\n",in_len);
 	/* count the length of the resulting UTF-8 */
 	for(i=len8=0;i<in_len;i++){
-		tmp=to_utf8(in[i],0);
+		tmp=to_utf8(NTFS_GETU16(in+i),0);
 		if(!tmp)
 			/* invalid character */
 			return EILSEQ;
@@ -114,7 +116,8 @@
 	result[len8]='\0';
 	*out_len=len8;
 	for(i=len8=0;i<in_len;i++)
-		len8+=to_utf8(in[i],result+len8);
+		len8+=to_utf8(NTFS_GETU16(in+i),result+len8);
+	ntfs_debug(DEBUG_NAME1,"result %p:%s\n",result,result);
 	return 0;
 }
 
@@ -139,7 +142,10 @@
 	result[len16]=0;
 	*out_len=len16;
 	for(i=len16=0;i<in_len;i+=tmp,len16++)
-		tmp=from_utf8(in+i,result+len16);
+	{
+		tmp=from_utf8(in+i, &wtmp);
+		NTFS_PUTU16(result+len16, wtmp);
+	}
 	return 0;
 }
 
@@ -151,7 +157,7 @@
 
 	/* check for characters out of range */
 	for(i=0;i<in_len;i++)
-		if(in[i]>=256)
+		if(NTFS_GETU16(in+i)>=256)
 			return EILSEQ;
 	*out=result=ntfs_malloc(in_len+1);
 	if(!result)
@@ -159,7 +165,7 @@
 	result[in_len]='\0';
 	*out_len=in_len;
 	for(i=0;i<in_len;i++)
-		result[i]=in[i];
+		result[i]=(unsigned char)NTFS_GETU16(in+i);
 	return 0;
 }
 
@@ -174,7 +180,7 @@
 		return ENOMEM;
 	*out_len=in_len;
 	for(i=0;i<in_len;i++)
-		result[i]=in[i];
+		NTFS_PUTU16(result+i,in[i]);
 	return 0;
 }
 
@@ -210,19 +216,18 @@
 void ntfs_put(ntfs_io *dest,void *src,ntfs_size_t n)
 {
 	ntfs_memcpy(dest->param,src,n);
-	dest->param+=n;
+	((char*)dest->param)+=n;
 }
 
 void ntfs_get(void* dest,ntfs_io *src,ntfs_size_t n)
 {
 	ntfs_memcpy(dest,src->param,n);
-	src->param+=n;
+	((char*)src->param)+=n;
 }
 
 void *ntfs_calloc(int size)
 {
 	void *result=ntfs_malloc(size);
-
 	if(result)
 		ntfs_bzero(result,size);
 	return result;
@@ -272,9 +277,9 @@
 
 	for(i=0;i<n;i++)
 	{
-		if(a[i]<b[i])
+		if(NTFS_GETU16(a+i)<b[i])
 			return -1;
-		if(b[i]<a[i])
+		if(b[i]<NTFS_GETU16(a+i))
 			return 1;
 	}
 	return 0;
@@ -292,7 +297,7 @@
  * 3: Floating point math in the kernel would corrupt user data
  */
 	const unsigned int D = 10000000;
-	unsigned int H = (ntutc >> 32);
+	unsigned int H = (unsigned int)(ntutc >> 32);
 	unsigned int L = (unsigned int)ntutc;
 	unsigned int numerator2;
 	unsigned int lowseconds;
@@ -334,6 +339,25 @@
 ntfs_time64_t ntfs_unixutc2ntutc(ntfs_time_t t)
 {
 	return ((t + (ntfs_time64_t)(369*365+89)*24*3600) * 10000000);
+}
+
+/* Fill index name. */
+
+void
+ntfs_indexname(char *buf, int type)
+{
+	char hex[]="0123456789ABCDEF";
+	int index;
+	*buf++='$';
+	*buf++='I';
+	for (index=24; index>0; index-=4)
+		if((0xF << index) & type)
+			break;
+	while(index>=0) {
+		*buf++ = hex[(type >> index) & 0xF];
+		index-=4;
+	}
+	*buf='\0';
 }
 
 /*

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov