#
# NB Warning this Makefile does not include header dependencies.
#
-# $Id: Makefile,v 1.2 2009-10-08 23:11:12 charles Exp $
+# $Id: Makefile,v 1.3 2009-10-09 06:12:26 charles Exp $
#EXTRA_COMPILE_FLAGS = -DYAFFS_IGNORE_TAGS_ECC
yaffs_norif1.o ynorsim.o
-YAFFSTESTOBJS = $(COMMONTESTOBJS) yaffs_wrap.o yaffs_swig_helper.o
+YAFFSSWIGOBJS = $(COMMONTESTOBJS) yaffs_wrap.o yaffs_python_helper.o
+YAFFSLIBOBJS = $(COMMONTESTOBJS) yaffs_python_helper.o
-ALLOBJS = $(sort $(YAFFSTESTOBJS))
YAFFSSYMLINKS = devextras.h yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffsinterface.h yportenv.h yaffs_tagscompat.c yaffs_tagscompat.h \
yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h yaffs_nandemul2k.h \
SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS)
-all: _yaffs.so
+all: _yaffs.so libyaffsfs.so
yaffs_wrap.c: yaffs.i yaffsfs_for_swig.h
swig -python yaffs.i
sed -e "s/struct yaffs_stat/struct yaffs_stat_struct/g" \
> $@
-$(ALLOBJS): %.o: %.c
+$(YAFFSLIBOBJS): %.o: %.c
+ gcc -c $(CFLAGS) -o $@ $<
+
+yaffs_wrap.o: %.o: %.c
gcc -c $(CFLAGS) -I/usr/include/python2.6/ -o $@ $<
-_yaffs.so: $(SYMLINKS) yaffs_wrap.c $(ALLOBJS)
- gcc -shared $(ALLOBJS) -o $@
+_yaffs.so: $(SYMLINKS) yaffs_wrap.c $(YAFFSSWIGOBJS)
+ gcc -shared $(YAFFSSWIGOBJS) -o $@
+
+libyaffsfs.so: $(SYMLINKS) $(YAFFSLIBOBJS)
+ gcc -shared $(YAFFSLIBOBJS) -o $@
clean:
- rm -f _yaffs.so yaffs.py yaffs.pyc yaffs_wrap.c $(ALLOBJS) core $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS)
+ rm -f _yaffs.so yaffs.py yaffs.pyc yaffs_wrap.c $(YAFFSLIBOBJS) yaffs_wrap.o core $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS)
rm -f *.c.*
rm -f yaffsfs_for_swig.h
+ rm -f libyaffsfs.so
+
--- /dev/null
+Using python with yaffsfs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Herewith a brief session showing yaffs direct being accessed from python.
+
+I tried SWIG first, but ctypes turned out to be way, way easier...
+
+Thanks to the people on NZPUG mailing list that helped with the exercise.
+
+Build libyaffsfs.so with the accompanying Makefile.
+
+$ make libyaffsfs.so
+
+$ python
+Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
+[GCC 4.3.3] on linux2
+Type "help", "copyright", "credits" or "license" for more information.
+>>> from ctypes import *
+>>> cdll.LoadLibrary("./libyaffsfs.so")
+<CDLL './libyaffsfs.so', handle 9ed4178 at b7d418ac>
+>>> y = CDLL("./libyaffsfs.so")
+>>> y.yaffs_StartUp()
+0
+>>> y.yaffs_mount("/yaffs2")
+yaffs: Mounting /yaffs2
+yaffs: yaffs_GutsInitialise()
+yaffs_ScanBackwards starts intstartblk 1 intendblk 256...
+0 blocks to be sorted...
+...done
+yaffs_ScanBackwards ends
+
+Block summary
+0 blocks have illegal states
+Unknown 0 blocks
+Needs scanning 0 blocks
+Scanning 0 blocks
+Empty 256 blocks
+Allocating 0 blocks
+Full 0 blocks
+Dirty 0 blocks
+Checkpoint 0 blocks
+Collecting 0 blocks
+Dead 0 blocks
+
+yaffs: yaffs_GutsInitialise() done.
+
+0
+>>> y.yaffs_open("/yaffs2/xx",66,0666)
+yaffs: Tnodes added
+Allocated block 1, seq 4097, 255 left
+0
+>>> y.yaffs_write(0,"abc",3)
+3
+>>> y.yaffs_lseek(0,0,0)
+0
+>>> b = create_string_buffer("",100)
+>>> y.yaffs_read(0,b,100)
+3
+>>> b.value
+'abc'
+>>>
+
--- /dev/null
+
+/*
+ * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2007 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <charles@aleph1.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+/*
+ * These are some dangly bits that need to be built to wrap up the rest of the yaffs test harness.
+ *
+ *
+ * This is also the place where extra debugging stuff might end up.
+ *
+ */
+
+#include "yaffsfs.h"
+
+int simulate_power_failure;
+int random_seed;
+
+int yaffs_print_constants(void)
+{
+ printf( "O_CREAT........%d\n",O_CREAT);
+ printf( "O_RDONLY.......%d\n",O_RDONLY);
+ printf( "O_WRONLY.......%d\n",O_WRONLY);
+ printf( "O_RDWR.........%d\n",O_RDWR);
+ printf( "O_TRUNC........%d\n",O_TRUNC);
+
+ return 0;
+}
+
+int yaffs_O_CREAT(void) { return O_CREAT;}
+int yaffs_O_RDONLY(void) { return O_RDONLY;}
+int yaffs_O_WRONLY(void) { return O_WRONLY;}
+int yaffs_O_RDWR(void) { return O_RDWR;}
+int yaffs_O_TRUNC(void) { return O_TRUNC;}
+
+int yaffs_set_trace(unsigned int tm) { return yaffs_traceMask=tm; }
+int yaffs_get_trace(void) { return yaffs_traceMask; }
+++ /dev/null
-/*
- * These are some dangly bits that need to be built to wrap up the rest of the yaffs test harness
- * in SWIG.
- *
- * This is also the place where extra debugging stuff might end up.
- *
- */
-
-#include "yaffsfs.h"
-
-int simulate_power_failure;
-int random_seed;
-
-int yaffs_print_constants(void)
-{
- printf( "O_CREAT........%d\n",O_CREAT);
- printf( "O_RDONLY.......%d\n",O_RDONLY);
- printf( "O_WRONLY.......%d\n",O_WRONLY);
- printf( "O_RDWR.........%d\n",O_RDWR);
- printf( "O_TRUNC........%d\n",O_TRUNC);
-
- return 0;
-}