[fix] Re: sysutils/ntfs-3g: 'PAGE_SHIFT' undeclared on loongson

2013-12-30 Thread Jérémie Courrèges-Anglas
Donovan Watteau tso...@gmail.com writes:

 On Wed, 25 Dec 2013, Jérémie Courrèges-Anglas wrote:
 Theo de Raadt dera...@cvs.openbsd.org writes:
 
  The hiding of PAGE_SIZE is intentional.
 
  The code should be using getpagesize() or some API which asks the
  kernel.
 
  The reason is that PAGE_SIZE is not a standardized symbol, and on some
  of our architectures it changes between different processor models.
 
 [...]
 
 Here's a compile-tested diff.  Donovan, does this fix your problem?

 D'oh, I had started a similar diff thanks to Theo's explanations and the
 already existing function in ntfsprogs/, but Christmas made me slack.

 Anyway, it builds and works fine with an NTFS formated USB flash drive,
 thanks!

Same diff + bump.  ok?

Index: Makefile
===
RCS file: /cvs/ports/sysutils/ntfs-3g/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- Makefile15 Jul 2013 08:05:50 -  1.3
+++ Makefile25 Dec 2013 01:17:31 -
@@ -7,7 +7,7 @@ DISTNAME =  ntfs-3g_ntfsprogs-${V}
 PKGNAME =  ntfs_3g-${V}
 SHARED_LIBS += ntfs-3g 0.0 # .84
 CATEGORIES =   sysutils
-REVISION = 1
+REVISION = 2
 
 HOMEPAGE = http://www.tuxera.com/
 
Index: patches/patch-libntfs-3g_mft_c
===
RCS file: patches/patch-libntfs-3g_mft_c
diff -N patches/patch-libntfs-3g_mft_c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ patches/patch-libntfs-3g_mft_c  25 Dec 2013 01:17:12 -
@@ -0,0 +1,82 @@
+$OpenBSD$
+- rip off mkntfs_get_page_size() from mkntfs.c, to avoid a build error
+  on archs where PAGE_SIZE is unusable.
+--- libntfs-3g/mft.c.orig  Wed Dec 25 02:12:11 2013
 libntfs-3g/mft.c   Wed Dec 25 02:16:16 2013
+@@ -26,6 +26,9 @@
+ #include config.h
+ #endif
+ 
++#ifdef  HAVE_UNISTD_H
++#include unistd.h
++#endif
+ #ifdef HAVE_STDLIB_H
+ #include stdlib.h
+ #endif
+@@ -453,9 +456,28 @@ static int ntfs_is_mft(ntfs_inode *ni)
+   return 0;
+ }
+ 
+-#ifndef PAGE_SIZE
+-#define PAGE_SIZE 4096
++/**
++ * mkntfs_get_page_size - detect the system's memory page size.
++ */
++static long mkntfs_get_page_size(void)
++{
++  long page_size;
++#ifdef _SC_PAGESIZE
++  page_size = sysconf(_SC_PAGESIZE);
++  if (page_size  0)
+ #endif
++#ifdef _SC_PAGE_SIZE
++  page_size = sysconf(_SC_PAGE_SIZE);
++  if (page_size  0)
++#endif
++  {
++  ntfs_log_warning(Failed to determine system page size.  
++  Assuming safe default of 4096 bytes.\n);
++  return 4096;
++  }
++  ntfs_log_debug(System page size is %li bytes.\n, page_size);
++  return page_size;
++}
+ 
+ #define RESERVED_MFT_RECORDS   64
+ 
+@@ -481,6 +503,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
+   s64 pass_end, ll, data_pos, pass_start, ofs, bit;
+   ntfs_attr *mftbmp_na;
+   u8 *buf, *byte;
++  long page_size;
+   unsigned int size;
+   u8 pass, b;
+   int ret = -1;
+@@ -492,7 +515,8 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
+* Set the end of the pass making sure we do not overflow the mft
+* bitmap.
+*/
+-  size = PAGE_SIZE;
++  page_size = mkntfs_get_page_size();
++  size = page_size;
+   pass_end = vol-mft_na-allocated_size  vol-mft_record_size_bits;
+   ll = mftbmp_na-initialized_size  3;
+   if (pass_end  ll)
+@@ -518,7 +542,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
+   pass = 2;
+   }
+   pass_start = data_pos;
+-  buf = ntfs_malloc(PAGE_SIZE);
++  buf = ntfs_malloc(page_size);
+   if (!buf)
+   goto leave;
+   
+@@ -531,7 +555,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
+   b = 0;
+ #endif
+   /* Loop until a free mft record is found. */
+-  for (; pass = 2; size = PAGE_SIZE) {
++  for (; pass = 2; size = page_size) {
+   /* Cap size to pass_end. */
+   ofs = data_pos  3;
+   ll = ((pass_end + 7)  3) - ofs;



Re: sysutils/ntfs-3g: 'PAGE_SHIFT' undeclared on loongson

2013-12-26 Thread Donovan Watteau
On Wed, 25 Dec 2013, Jérémie Courrèges-Anglas wrote:
 Theo de Raadt dera...@cvs.openbsd.org writes:
 
  The hiding of PAGE_SIZE is intentional.
 
  The code should be using getpagesize() or some API which asks the
  kernel.
 
  The reason is that PAGE_SIZE is not a standardized symbol, and on some
  of our architectures it changes between different processor models.
 
 [...]
 
 Here's a compile-tested diff.  Donovan, does this fix your problem?

D'oh, I had started a similar diff thanks to Theo's explanations and the
already existing function in ntfsprogs/, but Christmas made me slack.

Anyway, it builds and works fine with an NTFS formated USB flash drive,
thanks!



Re: sysutils/ntfs-3g: 'PAGE_SHIFT' undeclared on loongson

2013-12-25 Thread Jérémie Courrèges-Anglas
Theo de Raadt dera...@cvs.openbsd.org writes:

 The hiding of PAGE_SIZE is intentional.

 The code should be using getpagesize() or some API which asks the
 kernel.

 The reason is that PAGE_SIZE is not a standardized symbol, and on some
 of our architectures it changes between different processor models.

[...]

Here's a compile-tested diff.  Donovan, does this fix your problem?

$OpenBSD$
- take mkntfs_get_page_size() from mkntfs.c
  PAGE_SIZE is unusable on at least loongson
--- libntfs-3g/mft.c.orig   Wed Dec 25 02:12:11 2013
+++ libntfs-3g/mft.cWed Dec 25 02:16:16 2013
@@ -26,6 +26,9 @@
 #include config.h
 #endif
 
+#ifdef  HAVE_UNISTD_H
+#include unistd.h
+#endif
 #ifdef HAVE_STDLIB_H
 #include stdlib.h
 #endif
@@ -453,9 +456,28 @@ static int ntfs_is_mft(ntfs_inode *ni)
return 0;
 }
 
-#ifndef PAGE_SIZE
-#define PAGE_SIZE 4096
+/**
+ * mkntfs_get_page_size - detect the system's memory page size.
+ */
+static long mkntfs_get_page_size(void)
+{
+   long page_size;
+#ifdef _SC_PAGESIZE
+   page_size = sysconf(_SC_PAGESIZE);
+   if (page_size  0)
 #endif
+#ifdef _SC_PAGE_SIZE
+   page_size = sysconf(_SC_PAGE_SIZE);
+   if (page_size  0)
+#endif
+   {
+   ntfs_log_warning(Failed to determine system page size.  
+   Assuming safe default of 4096 bytes.\n);
+   return 4096;
+   }
+   ntfs_log_debug(System page size is %li bytes.\n, page_size);
+   return page_size;
+}
 
 #define RESERVED_MFT_RECORDS   64
 
@@ -481,6 +503,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
s64 pass_end, ll, data_pos, pass_start, ofs, bit;
ntfs_attr *mftbmp_na;
u8 *buf, *byte;
+   long page_size;
unsigned int size;
u8 pass, b;
int ret = -1;
@@ -492,7 +515,8 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
 * Set the end of the pass making sure we do not overflow the mft
 * bitmap.
 */
-   size = PAGE_SIZE;
+   page_size = mkntfs_get_page_size();
+   size = page_size;
pass_end = vol-mft_na-allocated_size  vol-mft_record_size_bits;
ll = mftbmp_na-initialized_size  3;
if (pass_end  ll)
@@ -518,7 +542,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
pass = 2;
}
pass_start = data_pos;
-   buf = ntfs_malloc(PAGE_SIZE);
+   buf = ntfs_malloc(page_size);
if (!buf)
goto leave;

@@ -531,7 +555,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *
b = 0;
 #endif
/* Loop until a free mft record is found. */
-   for (; pass = 2; size = PAGE_SIZE) {
+   for (; pass = 2; size = page_size) {
/* Cap size to pass_end. */
ofs = data_pos  3;
ll = ((pass_end + 7)  3) - ofs;


-- 
jca | PGP: 0x06A11494 / 61DB D9A0 00A4 67CF 2A90  8961 6191 8FBF 06A1 1494



sysutils/ntfs-3g: 'PAGE_SHIFT' undeclared on loongson

2013-12-24 Thread Donovan Watteau
Hi,

sysutils/ntfs-3g fails to build on loongson.

$ sysctl kern.version
kern.version=OpenBSD 5.4-current (GENERIC) #78: Sat Dec 21 18:03:03 MST 2013
dera...@loongson.openbsd.org:/usr/src/sys/arch/loongson/compile/GENERIC

===  Building for ntfs_3g-2013.1.13p1
make  all-recursive
Making all in include
Making all in ntfs-3g
Making all in fuse-lite
Making all in libfuse-lite
Making all in libntfs-3g
/usr/bin/libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..   
-I/usr/local/include  -I../include/ntfs-3g -O2 -pipe -Wall -MT 
libntfs_3g_la-mft.lo -MD -MP -MF .deps/libntfs_3g_la-mft.Tpo -c -o 
libntfs_3g_la-mft.lo `test -f 'mft.c' || echo './'`mft.c
cc -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include -I../include/ntfs-3g -O2 -pipe 
-Wall -MT libntfs_3g_la-mft.lo -MD -MP -MF .deps/libntfs_3g_la-mft.Tpo -c mft.c 
-fPIC -DPIC -o .libs/libntfs_3g_la-mft.o
mft.c: In function 'ntfs_mft_bitmap_find_free_rec':
mft.c:495: error: 'PAGE_SHIFT' undeclared (first use in this function)
mft.c:495: error: (Each undeclared identifier is reported only once
mft.c:495: error: for each function it appears in.)
Error while executing cc -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include 
-I../include/ntfs-3g -O2 -pipe -Wall -MT libntfs_3g_la-mft.lo -MD -MP -MF 
.deps/libntfs_3g_la-mft.Tpo -c mft.c -fPIC -DPIC -o .libs/libntfs_3g_la-mft.o
*** Error 1 in libntfs-3g (Makefile:550 'libntfs_3g_la-mft.lo')
*** Error 1 in . (Makefile:357 'all-recursive')
*** Error 1 in 
/home/tsomi/ports/pobj/ntfs_3g-2013.1.13/ntfs-3g_ntfsprogs-2013.1.13 
(Makefile:248 'all')
*** Error 1 in . (/home/tsomi/ports/infrastructure/mk/bsd.port.mk:2661 
'/home/tsomi/ports/pobj/ntfs_3g-2013.1.13/.build_done')
*** Error 1 in /home/tsomi/ports/sysutils/ntfs-3g 
(/home/tsomi/ports/infrastructure/mk/bsd.port.mk:2394 'all')

libntfs-3g/mft.c uses PAGE_SIZE, which is (1  PAGE_SHIFT), but
PAGE_SHIFT is in an #ifdef _KERNEL in loongson/param.h (don't know if
it's intentional, maybe that's what the comment above PAGE_SHIFT
explains).

libntfs-3g/mft.c also has this:

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

So I don't know if it's a problem in the system headers on loongson, or
if mft.c should be patched to use a 4096 PAGE_SIZE instead.



Re: sysutils/ntfs-3g: 'PAGE_SHIFT' undeclared on loongson

2013-12-24 Thread Theo de Raadt
The hiding of PAGE_SIZE is intentional.

The code should be using getpagesize() or some API which asks the
kernel.

The reason is that PAGE_SIZE is not a standardized symbol, and on some
of our architectures it changes between different processor models.

sysutils/ntfs-3g fails to build on loongson.

$ sysctl kern.version
kern.version=OpenBSD 5.4-current (GENERIC) #78: Sat Dec 21 18:03:03 MST 2013
dera...@loongson.openbsd.org:/usr/src/sys/arch/loongson/compile/GENERIC

===  Building for ntfs_3g-2013.1.13p1
make  all-recursive
Making all in include
Making all in ntfs-3g
Making all in fuse-lite
Making all in libfuse-lite
Making all in libntfs-3g
/usr/bin/libtool  --tag=CC   --mode=compile cc -DHAVE_CONFIG_H -I. -I..   
-I/usr/local/include  -I../include/ntfs-3g -O2 -pipe -Wall -MT 
libntfs_3g_la-mft.lo -MD -MP -MF .deps/libntfs_3g_la-mft.Tpo -c -o 
libntfs_3g_la-mft.lo `test -f 'mft.c' || echo './'`mft.c
cc -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include -I../include/ntfs-3g -O2 
-pipe -Wall -MT libntfs_3g_la-mft.lo -MD -MP -MF .deps/libntfs_3g_la-mft.Tpo 
-c mft.c -fPIC -DPIC -o .libs/libntfs_3g_la-mft.o
mft.c: In function 'ntfs_mft_bitmap_find_free_rec':
mft.c:495: error: 'PAGE_SHIFT' undeclared (first use in this function)
mft.c:495: error: (Each undeclared identifier is reported only once
mft.c:495: error: for each function it appears in.)
Error while executing cc -DHAVE_CONFIG_H -I. -I.. -I/usr/local/include 
-I../include/ntfs-3g -O2 -pipe -Wall -MT libntfs_3g_la-mft.lo -MD -MP -MF 
.deps/libntfs_3g_la-mft.Tpo -c mft.c -fPIC -DPIC -o .libs/libntfs_3g_la-mft.o
*** Error 1 in libntfs-3g (Makefile:550 'libntfs_3g_la-mft.lo')
*** Error 1 in . (Makefile:357 'all-recursive')
*** Error 1 in 
/home/tsomi/ports/pobj/ntfs_3g-2013.1.13/ntfs-3g_ntfsprogs-2013.1.13 
(Makefile:248 'all')
*** Error 1 in . (/home/tsomi/ports/infrastructure/mk/bsd.port.mk:2661 
'/home/tsomi/ports/pobj/ntfs_3g-2013.1.13/.build_done')
*** Error 1 in /home/tsomi/ports/sysutils/ntfs-3g 
(/home/tsomi/ports/infrastructure/mk/bsd.port.mk:2394 'all')

libntfs-3g/mft.c uses PAGE_SIZE, which is (1  PAGE_SHIFT), but
PAGE_SHIFT is in an #ifdef _KERNEL in loongson/param.h (don't know if
it's intentional, maybe that's what the comment above PAGE_SHIFT
explains).

libntfs-3g/mft.c also has this:

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

So I don't know if it's a problem in the system headers on loongson, or
if mft.c should be patched to use a 4096 PAGE_SIZE instead.