android下支持ccode写的开源软件真是一件费力的事情,原因是android下的libcuclib的一个子集,在移植过程中发现要实现libc没有但uclib有的一些函数,不然程序跑不起来。还有就是android.mk需从新编写,来取代automake生成的makefile文件。

1.编写android.mk

ntfs-3g解压在externel目录下,在解压后的ntfs-3g目录下添加android.mk,可以参照externel目录下的其他软件包。本人也是参照一些模板,网上查了一些android.mk资料。对于静态库和应用程序这一条路的生成走通了。对于ntfs-3g内容如下

ifneq($(TARGET_SIMULATOR),true)

LOCAL_PATH:=$(callmy-dir)

###################################################################

##Forstage1,wehavetomakelibfuse

###################################################################

include$(CLEAR_VARS)

LOCAL_SRC_FILES:=/

libfuse-lite/fuse.clibfuse-lite/fusermount.clibfuse-lite/fuse_kern_chan.clibfuse-lite/fuse_loop.c/

libfuse-lite/fuse_lowlevel.clibfuse-lite/fuse_opt.clibfuse-lite/fuse_session.clibfuse-lite/fuse_signals.c/

libfuse-lite/helper.clibfuse-lite/mount.clibfuse-lite/mount_util.c

LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include/fuse-lite

LOCAL_CFLAGS:=-O2-g-W-Wall-D_LARGEFILE_SOURCE-D_FILE_OFFSET_BITS=64-DHAVE_CONFIG_H

LOCAL_MODULE:=libfuse

LOCAL_MODULE_TAGS:=

LOCAL_SYSTEM_SHARED_LIBRARIES:=libclibcutils

include$(BUILD_STATIC_LIBRARY)

###################################################################

##Forstage2,wehavetomakelibntfs-3g

###################################################################

include$(CLEAR_VARS)

LOCAL_SRC_FILES:=libntfs-3g/acls.clibntfs-3g/attrib.clibntfs-3g/attrlist.clibntfs-3g/bitmap.c/

libntfs-3g/bootsect.clibntfs-3g/cache.clibntfs-3g/collate.clibntfs-3g/compat.clibntfs-3g/compress.c/

libntfs-3g/debug.clibntfs-3g/device.clibntfs-3g/dir.clibntfs-3g/efs.clibntfs-3g/index.clibntfs-3g/inode.c/

libntfs-3g/lcnalloc.clibntfs-3g/logfile.clibntfs-3g/logging.clibntfs-3g/mft.clibntfs-3g/misc.clibntfs-3g/mst.c/

libntfs-3g/object_id.clibntfs-3g/reparse.clibntfs-3g/runlist.clibntfs-3g/security.clibntfs-3g/unistr.c/

libntfs-3g/unix_io.clibntfs-3g/volume.c

LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include/fuse-lite$(LOCAL_PATH)/include/ntfs-3g

LOCAL_CFLAGS:=-O2-g-W-Wall-D_LARGEFILE_SOURCE-D_FILE_OFFSET_BITS=64-DHAVE_CONFIG_H

LOCAL_MODULE:=libntfs-3g

LOCAL_MODULE_TAGS:=

LOCAL_SYSTEM_SHARED_LIBRARIES:=libclibcutils

include$(BUILD_STATIC_LIBRARY)

###################################################################

##Forstage3,wemakentfs-3g

###################################################################

include$(CLEAR_VARS)

LOCAL_SRC_FILES:=src/ntfs-3g.c

LOCAL_C_INCLUDES:=$(LOCAL_PATH)/include/fuse-lite$(LOCAL_PATH)/include/ntfs-3g/

$(LOCAL_PATH)/src

LOCAL_CFLAGS:=-O2-g-W-Wall-D_LARGEFILE_SOURCE-D_FILE_OFFSET_BITS=64-DHAVE_CONFIG_H

LOCAL_MODULE:=ntfs-3g

LOCAL_MODULE_TAGS:=

LOCAL_SYSTEM_SHARED_LIBRARIES:=libclibcutils

LOCAL_STATIC_LIBRARIES:=libfuselibntfs-3g

include$(BUILD_EXECUTABLE)

2.修改源码

android.mk顶层添加-DHAVE_CONFIG_H支持config.h

config.h添加

#define MOUNTED "/etc/mtab"

#define _PATH_MOUNTED "/etc/mtab"

去除(因anroid没有支持)

#defineHAVE_SYS_STATVFS_H1

#defineHAVE_SETXATTR1

ntfstime.h文件

删除重复定义

structtimespec{

time_ttv_sec;

longtv_nsec;

};

fuse.hfuse_lowlevel.h关于#include<sys/statvfs.h>和引用structstatvfs的函数添加

#ifHAVE_SYS_STATVFS_H

#endif

libfuse-lite目录

fuse_misc.h添加

typedefstruct_pthread_rwlock_t

{

//struct_pthread_fastlock__rw_lock;/*Locktoguaranteemutualexclusion*/

int__rw_readers;/*Numberofreaders*/

//_pthread_descr__rw_writer;/*Identityofwriter,orNULLifnone*/

//_pthread_descr__rw_read_waiting;/*Threadswaitingforreading*/

//_pthread_descr__rw_write_waiting;/*Threadswaitingforwriting*/

int__rw_kind;/*Reader/Writerpreferenceselection*/

int__rw_pshared;/*Sharedbetweenprocessesornot*/

}pthread_rwlock_t;

typedefstruct

{

int__lockkind;

int__pshared;

}pthread_rwlockattr_t;

staticinlineintpthread_rwlock_init(pthread_rwlock_t*__rwlock,

pthread_rwlockattr_t*__attr)

{

return1;

}

staticinlineintpthread_rwlock_destroy(pthread_rwlock_t*__rwlock)

{

return1;

}

/*AcquirereadlockforRWLOCK.*/

staticinlineintpthread_rwlock_rdlock(pthread_rwlock_t*__rwlock)

{

return1;

}

/*AcquirewritelockforRWLOCK.*/

staticinlineintpthread_rwlock_wrlock(pthread_rwlock_t*__rwlock)

{

return1;

}

fuse.cfuse_lowlevel.c引用structstatvfs的函数添加

#ifHAVE_SYS_STATVFS_H

#endif

fusermount.c添加

structmntent*getmntent_r(FILE*filep,

structmntent*mnt,char*buff,intbufsize)

{

staticconstcharsep[]="/t/n";

char*cp,*ptrptr;

if(!filep||!mnt||!buff)

returnNULL;

/*Looponthefile,skippingcommentlines.-FvK03/07/93*/

while((cp=fgets(buff,bufsize,filep))!=NULL){

if(buff[0]=='#'||buff[0]=='/n')

continue;

break;

}

/*AttheEOF,thebuffershouldbeunchanged.Weshould

*checkthereturnvaluefromfgets().

*/

if(cp==NULL)

returnNULL;

ptrptr=0;

mnt->mnt_fsname=strtok_r(buff,sep,&ptrptr);

if(mnt->mnt_fsname==NULL)

returnNULL;

mnt->mnt_dir=strtok_r(NULL,sep,&ptrptr);

if(mnt->mnt_dir==NULL)

returnNULL;

mnt->mnt_type=strtok_r(NULL,sep,&ptrptr);

if(mnt->mnt_type==NULL)

returnNULL;

mnt->mnt_opts=strtok_r(NULL,sep,&ptrptr);

if(mnt->mnt_opts==NULL)

mnt->mnt_opts="";

cp=strtok_r(NULL,sep,&ptrptr);

mnt->mnt_freq=(cp!=NULL)?atoi(cp):0;

cp=strtok_r(NULL,sep,&ptrptr);

mnt->mnt_passno=(cp!=NULL)?atoi(cp):0;

returnmnt;

}

structmntent*getmntent(FILE*filep)

{

structmntent*tmp;

staticchar*buff=NULL;

staticstructmntentmnt;

//__UCLIBC_MUTEX_LOCK(mylock);

if(!buff){

buff=malloc(BUFSIZ);

if(!buff)

abort();

}

tmp=getmntent_r(filep,&mnt,buff,BUFSIZ);

//__UCLIBC_MUTEX_UNLOCK(mylock);

return(tmp);

}

intaddmntent(FILE*filep,conststructmntent*mnt)

{

if(fseek(filep,0,SEEK_END)<0)

return1;

return(fprintf(filep,"%s%s%s%s%d%d/n",mnt->mnt_fsname,mnt->mnt_dir,

mnt->mnt_type,mnt->mnt_opts,mnt->mnt_freq,mnt->mnt_passno)<0?1:0);

}

char*hasmntopt(conststructmntent*mnt,constchar*opt)

{

returnstrstr(mnt->mnt_opts,opt);

}

FILE*setmntent(constchar*name,constchar*mode)

{

returnfopen(name,mode);

}

intendmntent(FILE*filep)

{

if(filep!=NULL)

fclose(filep);

return1;

}

libntfs-3g目录

acls.c删除#include"secaudit.h"

security.cntfs_get_perm()#if0 #endif屏蔽ntfs_allowed_access()直接return1;

Src目录

ntfs-3g.c

引用structstatvfs的函数添加

#ifHAVE_SYS_STATVFS_H

#endif

3.总结

从上可以看出android对于c库支持还是比较弱,需要移植uclib中的实现函数才能支持一般linux上的应用程序.

更多相关文章

  1. 简析Android对Linux内核的改动
  2. 最牛逼android上的图表库MpChart(一) 介绍篇
  3. Android新手入门 FAQ
  4. Android底层启动解析
  5. Android自定义视图一:扩展现有的视图,添加新的XML属性
  6. Android(安卓)Framework 分析---3PackageManager 分析
  7. Android普及入门
  8. Android与H5互调详细介绍
  9. Android新手入门 FAQ

随机推荐

  1. Android读写XML(中)——SAX
  2. [置顶] Android 定时任务的多种实现方式
  3. Android SystemProperties.get()和System
  4. Android数字签名?
  5. android 智能指针
  6. Java多种方式动态生成doc文档
  7. TV - 新的战场
  8. [Android] AsyncTask详解
  9. Android扮猪吃虎
  10. Android 重读官方文档 1