btrfs-progs: android build
Hi, I made btrfs-progs android build script and test it.\
And need some help on btrfs_wipe_existing_sb().\
On the test it looks work well.\
But I’m not sure it’s ok.
Quoted 1 line
From
66bae04ded4feb8f218f0a6d30f360792430be7cMon Sep 17 00:00:00 2001
From: "kenneth.kang" <[email protected]>
Date: Wed, 5 Aug 2015 18:08:25 +0900
Subject: [PATCH] btrfs-progs: Add Android build mk file
Add Android.mk to use btrfs on android device.
To using this funtion, there are some limitation.
1) phread_cancel was changed to pthread_kill due to android didn't support that.
2) This module needs lzo library on android/external folder.
3) blkid library doesn't support fully. So have to use -f option to work.
--- Android.mk | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ chunk-recover.c | 8 ++++ cmds-receive.c | 4 ++ cmds-restore.c | 1 + cmds-scrub.c | 22 ++++++++++- kerncompat.h | 3 ++ mkfs.c | 9 +++++ utils.c | 9 +++-- 8 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 Android.mk
Android.mk new file +111 -0
@@ -0,0 +1,111 @@ +LOCAL_PATH:= $(call my-dir) + +#include $(call all-subdir-makefiles) + +CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC + +LDFLAGS := -static -rdynamic + +LIBS := -luuid -lblkid -lz -llzo2 -L. -lpthread +LIBBTRFS_LIBS := $(LIBS) + +STATIC_CFLAGS := $(CFLAGS) -ffunction-sections -fdata-sections +STATIC_LDFLAGS := -static -Wl,--gc-sections +STATIC_LIBS := -luuid -lblkid -luuid \ + -lz -llzo2 -L. -pthread + +btrfs_shared_libraries := libext2_uuid \ + libext2_blkid + +objects := ctree.c disk-io.c radix-tree.c extent-tree.c print-tree.c \ + root-tree.c dir-item.c file-item.c inode-item.c inode-map.c \ + extent-cache.c extent_io.c volumes.c utils.c repair.c \ + qgroup.c raid6.c free-space-cache.c list_sort.c props.c \ + ulist.c qgroup-verify.c backref.c string-table.c task-utils.c \ + inode.c file.c find-root.c +cmds_objects := cmds-subvolume.c cmds-filesystem.c cmds-device.c cmds-scrub.c \ + cmds-inspect.c cmds-balance.c cmds-send.c cmds-receive.c \ + cmds-quota.c cmds-qgroup.c cmds-replace.c cmds-check.c \ + cmds-restore.c cmds-rescue.c chunk-recover.c super-recover.c \ + cmds-property.c cmds-fi-usage.c +libbtrfs_objects := send-stream.c send-utils.c rbtree.c btrfs-list.c crc32c.c \ + uuid-tree.c utils-lib.c rbtree-utils.c +libbtrfs_headers := send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ + crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \ + extent_io.h ioctl.h ctree.h btrfsck.h version.h +TESTS := fsck-tests.sh convert-tests.sh +blkid_objects := partition/ superblocks/ topology/ + + +# external/e2fsprogs/lib is needed for uuid/uuid.h +common_C_INCLUDES := $(LOCAL_PATH) external/e2fsprogs/lib/ external/lzo/include/ external/zlib/ + +#---------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(libbtrfs_objects) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +LOCAL_MODULE := libbtrfs +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +include $(BUILD_STATIC_LIBRARY) + +#---------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_MODULE := btrfs +#LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_SRC_FILES := \ + $(objects) \ + $(cmds_objects) \ + btrfs.c \ + help.c \ + +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +#LOCAL_LDLIBS := $(LIBBTRFS_LIBS) +#LOCAL_LDFLAGS := $(STATIC_LDFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static libz +LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils + +LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES) +#LOCAL_MODULE_TAGS := optional +include $(BUILD_EXECUTABLE) + +#---------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_MODULE := mkfs.btrfs +LOCAL_SRC_FILES := \ + $(objects) \ + mkfs.c + +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +#LOCAL_LDLIBS := $(LIBBTRFS_LIBS) +#LOCAL_LDFLAGS := $(STATIC_LDFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static +LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils + +LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES) +#LOCAL_MODULE_TAGS := optional +include $(BUILD_EXECUTABLE) + +#--------------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_MODULE := btrfstune +LOCAL_SRC_FILES := \ + $(objects) \ + btrfstune.c + +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +#LOCAL_LDLIBS := $(LIBBTRFS_LIBS) +#LOCAL_LDFLAGS := $(STATIC_LDFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static +LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils + +LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_MODULE_TAGS := optional +include $(BUILD_EXECUTABLE) +#--------------------------------------------------------------
chunk-recover.c +8 -0
@@ -17,7 +17,9 @@*/ #include <stdio.h> +#ifndef ANDROID #include <stdio_ext.h> +#endif #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h>
@@ -755,9 +757,11 @@ static int scan_one_device(void *dev_scan_struct)int fd = dev_scan->fd;int oldtype; +#ifndef ANDROID ret =pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS , &oldtype);if (ret)return 1 ; +#endif buf =malloc (sizeof (*buf) + rc->leafsize);if (!buf)
@@ -884,7 +888,11 @@ static int scan_devices(struct recover_control *rc) } out1:while (ret && (cancel_from <= cancel_to)) { +#ifdef ANDROID +pthread_kill (t_scans[cancel_from],SIGUSR1 ); +#else pthread_cancel (t_scans[cancel_from]); +#endif cancel_from++; } out2:
cmds-receive.c +4 -0
@@ -25,7 +25,11 @@#include <pthread.h> #include <math.h> #include <ftw.h> +#ifndef ANDROID #include <wait.h> +#else +#include <sys/wait.h> +#endif #include <assert.h> #include <getopt.h>
cmds-restore.c +1 -0
@@ -86,6 +86,7 @@ static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len, (void )inflateEnd (&strm);return 0 ; } +static inline size_t read_compress_length (unsigned char *buf) {__le32 dlen;
cmds-scrub.c +20 -2
@@ -780,12 +780,13 @@ static int scrub_write_progress(pthread_mutex_t *m, const char *fsid,int fd =-1 ;int old; +#ifndef ANDROID ret =pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , &old);if (ret) { err = -ret; goto out3; } - +#endif ret =pthread_mutex_lock (m);if (ret) { err = -ret;
@@ -816,10 +817,11 @@ out1: err = -ret; out2: +#ifndef ANDROID ret =pthread_setcancelstate (PTHREAD_CANCEL_ENABLE , &old);if (ret && !err) err = -ret; - +#endif out3:return err; }
@@ -898,9 +900,11 @@ static void *scrub_progress_cycle(void *ctx)struct sockaddr_un peer;socklen_t peer_size =sizeof (peer); +#ifndef ANDROID perr =pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS , &old);if (perr) goto out; +#endif uuid_unparse (spc->fi->fsid, fsid);
@@ -952,10 +956,12 @@ static void *scrub_progress_cycle(void *ctx)* result we got for the current write and go * on. flag should be set on next cycle, then. */ +#ifndef ANDROID perr =pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , &old);if (perr) goto out; +#endif perr =pthread_mutex_lock (&sp_shared->progress_mutex);if (perr) goto out;
@@ -964,20 +970,24 @@ static void *scrub_progress_cycle(void *ctx) &sp_shared->progress_mutex);if (perr) goto out; +#ifndef ANDROID perr =pthread_setcancelstate (PTHREAD_CANCEL_ENABLE , &old);if (perr) goto out; +#endif memcpy (sp, sp_last,sizeof (*sp));continue ; } perr =pthread_mutex_unlock (&sp_shared->progress_mutex);if (perr) goto out; +#ifndef ANDROID perr =pthread_setcancelstate (PTHREAD_CANCEL_ENABLE , &old);if (perr) goto out; +#endif memcpy (sp, sp_shared,sizeof (*sp));memcpy (sp_last, sp_shared,sizeof (*sp)); }
@@ -1506,7 +1516,11 @@ static int scrub_start(int argc, char **argv, int resume) } } +#ifdef ANDROID + ret =pthread_kill (t_prog,SIGUSR1 ); +#else ret =pthread_cancel (t_prog); +#endif if (!ret) ret =pthread_join (t_prog, &terr);
@@ -1517,7 +1531,11 @@ static int scrub_start(int argc, char **argv, int resume) }/* check for errors returned from the progress thread itself */ +#ifdef ANDROID +if (do_print && terr) { +#else if (do_print && terr && terr !=PTHREAD_CANCELED ) { +#endif fprintf (stderr,"ERROR: recording progress " "failed: %s\n" ,strerror (-PTR_ERR (terr))); }
kerncompat.h +3 -0
@@ -134,6 +134,9 @@ typedef long long s64;typedef int s32 ;#endif +#ifdef ANDROID +typedef struct blkid_struct_probe *blkid_probe ; +#endif struct vma_shared {int prio_tree_node; };struct vm_area_struct {
mkfs.c +9 -0
@@ -25,7 +25,12 @@#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> +#ifndef ANDROID #include <sys/dir.h> +#else +#include <dirent.h> +#define direct dirent +#endif #include <fcntl.h> #include <unistd.h> #include <getopt.h>
@@ -1359,7 +1364,11 @@ int main(int ac, char **av) dev_cnt = ac - optind; file = av[optind++]; +#ifndef ANDROID ssd =is_ssd (file); +#else + ssd = true; +#endif if (is_vol_small (file) || mixed) {if (verbose)
utils.c +6 -3
@@ -878,9 +878,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret, file, strerror(-ret));return 1 ; } - +#ifndef ANDROID btrfs_wipe_existing_sb (fd); - +#endif *block_count_ret = block_count;return 0 ; }
@@ -2267,7 +2267,6 @@ check_overwrite(return 0 ; ret =-1 ;/* will reset on success of all setup calls */ - pr =blkid_new_probe_from_filename (device);if (!pr) goto out;
@@ -2436,7 +2435,11 @@ int test_dev_for_mkfs(char *file, int force_overwrite)return 1 ; }if (!force_overwrite) { +#ifndef ANDROID if (check_overwrite (file)) { +#else + { +#endif fprintf (stderr,"Use the -f option to force overwrite.\n" );return 1 ; }
Signature · 1 line
1.8.2
David Sterba
maintainerHi,
Quoted 1 line · ������
Hi, I made btrfs-progs android build script and test it.\
Thanks. The changes as they stand are too intrusive to be added but give me an idea what's needed.
The makefile part shares some variables with current make and adds some specific variables and includes. Ideally there's only one makefile but I think that we can live with a separate makefile for android as there seem to be specific quirks that would complicate the common makefile.
This means we'd have to keep the shared part in sync manually but it's not that hard. New files or new libs, this always requires more care.
Quoted 2 lines
And need some help on btrfs_wipe_existing_sb().\
On the test it looks work well.\
The code changes should be hidden in wrappers and pulled via a separate header file. If this is not possible, the ifdefs should be in the function implementations (eg. is_ssd, check_overwrite), not at the call sites.
Other than that, I don't mind adding support for android builds. I don't have an android build environment at hand and cannot verify that it's always working, so the same holds as for musl libc, fixes are up to you.
I change the code that you are suggest.
I consider wrapper function, but it was affected by blkid library on build time. So I make CFLAG PLATFORM_ANDROID on Android.mk to using it for check the platform.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of David Sterba
Sent: Thursday, August 06, 2015 11:39 PM
Cc: [email protected]
Subject: Re: FW: btrfs-progs: android build
Hi,
Quoted 1 line · On Thu, Aug 06, 2015 at 06:45:11PM +0900, wrote:
Hi, I made btrfs-progs android build script and test it.\
Thanks. The changes as they stand are too intrusive to be added but give me an idea what's needed.
The makefile part shares some variables with current make and adds some specific variables and includes. Ideally there's only one makefile but I think that we can live with a separate makefile for android as there seem to be specific quirks that would complicate the common makefile.
This means we'd have to keep the shared part in sync manually but it's not that hard. New files or new libs, this always requires more care.
Quoted 2 lines
And need some help on btrfs_wipe_existing_sb().\ On the test it looks work well.\
The code changes should be hidden in wrappers and pulled via a separate header file. If this is not possible, the ifdefs should be in the function implementations (eg. is_ssd, check_overwrite), not at the call sites.
Other than that, I don't mind adding support for android builds. I don't have an android build environment at hand and cannot verify that it's always working, so the same holds as for musl libc, fixes are up to you. --
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line
From
66bae04ded4feb8f218f0a6d30f360792430be7cMon Sep 17 00:00:00 2001
From: "kenneth.kang" <[email protected]>
Date: Wed, 5 Aug 2015 18:08:25 +0900
Subject: [PATCH] btrfs-progs: Add Android build mk file
Add Android.mk to use btrfs on android device.
To using this funtion, there are some limitation.
1) phread_cancel was changed to pthread_kill due to android didn't support that.
2) This module needs lzo library on android/external folder.
3) blkid library doesn't support fully. So have to use -f option to work.
--- Android.mk | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ chunk-recover.c | 8 ++++ cmds-receive.c | 4 ++ cmds-restore.c | 1 + cmds-scrub.c | 22 ++++++++++- kerncompat.h | 3 ++ mkfs.c | 9 +++++ utils.c | 9 +++-- 8 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 Android.mk
Android.mk new file +111 -0
@@ -0,0 +1,111 @@ +LOCAL_PATH:= $(call my-dir) + +#include $(call all-subdir-makefiles) + +CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC + +LDFLAGS := -static -rdynamic + +LIBS := -luuid -lblkid -lz -llzo2 -L. -lpthread +LIBBTRFS_LIBS := $(LIBS) + +STATIC_CFLAGS := $(CFLAGS) -ffunction-sections -fdata-sections +STATIC_LDFLAGS := -static -Wl,--gc-sections +STATIC_LIBS := -luuid -lblkid -luuid \ + -lz -llzo2 -L. -pthread + +btrfs_shared_libraries := libext2_uuid \ + libext2_blkid + +objects := ctree.c disk-io.c radix-tree.c extent-tree.c print-tree.c \ + root-tree.c dir-item.c file-item.c inode-item.c inode-map.c \ + extent-cache.c extent_io.c volumes.c utils.c repair.c \ + qgroup.c raid6.c free-space-cache.c list_sort.c props.c \ + ulist.c qgroup-verify.c backref.c string-table.c task-utils.c \ + inode.c file.c find-root.c +cmds_objects := cmds-subvolume.c cmds-filesystem.c cmds-device.c cmds-scrub.c \ + cmds-inspect.c cmds-balance.c cmds-send.c cmds-receive.c \ + cmds-quota.c cmds-qgroup.c cmds-replace.c cmds-check.c \ + cmds-restore.c cmds-rescue.c chunk-recover.c super-recover.c \ + cmds-property.c cmds-fi-usage.c +libbtrfs_objects := send-stream.c send-utils.c rbtree.c btrfs-list.c crc32c.c \ + uuid-tree.c utils-lib.c rbtree-utils.c +libbtrfs_headers := send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ + crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \ + extent_io.h ioctl.h ctree.h btrfsck.h version.h +TESTS := fsck-tests.sh convert-tests.sh +blkid_objects := partition/ superblocks/ topology/ + + +# external/e2fsprogs/lib is needed for uuid/uuid.h +common_C_INCLUDES := $(LOCAL_PATH) external/e2fsprogs/lib/ external/lzo/include/ external/zlib/ + +#---------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(libbtrfs_objects) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +LOCAL_MODULE := libbtrfs +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +include $(BUILD_STATIC_LIBRARY) + +#---------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_MODULE := btrfs +#LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_SRC_FILES := \ + $(objects) \ + $(cmds_objects) \ + btrfs.c \ + help.c \ + +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +#LOCAL_LDLIBS := $(LIBBTRFS_LIBS) +#LOCAL_LDFLAGS := $(STATIC_LDFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static libz +LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils + +LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES) +#LOCAL_MODULE_TAGS := optional +include $(BUILD_EXECUTABLE) + +#---------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_MODULE := mkfs.btrfs +LOCAL_SRC_FILES := \ + $(objects) \ + mkfs.c + +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +#LOCAL_LDLIBS := $(LIBBTRFS_LIBS) +#LOCAL_LDFLAGS := $(STATIC_LDFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static +LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils + +LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES) +#LOCAL_MODULE_TAGS := optional +include $(BUILD_EXECUTABLE) + +#--------------------------------------------------------------- +include $(CLEAR_VARS) +LOCAL_MODULE := btrfstune +LOCAL_SRC_FILES := \ + $(objects) \ + btrfstune.c + +LOCAL_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_CFLAGS := $(STATIC_CFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +#LOCAL_LDLIBS := $(LIBBTRFS_LIBS) +#LOCAL_LDFLAGS := $(STATIC_LDFLAGS) +LOCAL_SHARED_LIBRARIES := $(btrfs_shared_libraries) +LOCAL_STATIC_LIBRARIES := libbtrfs liblzo-static +LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils + +LOCAL_EXPORT_C_INCLUDES := $(common_C_INCLUDES) +LOCAL_MODULE_TAGS := optional +include $(BUILD_EXECUTABLE) +#--------------------------------------------------------------
chunk-recover.c +8 -0
@@ -17,7 +17,9 @@*/ #include <stdio.h> +#ifndef ANDROID #include <stdio_ext.h> +#endif #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h>
@@ -755,9 +757,11 @@ static int scan_one_device(void *dev_scan_struct)int fd = dev_scan->fd;int oldtype; +#ifndef ANDROID ret =pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS , &oldtype);if (ret)return 1 ; +#endif buf =malloc (sizeof (*buf) + rc->leafsize);if (!buf)
@@ -884,7 +888,11 @@ static int scan_devices(struct recover_control *rc) } out1:while (ret && (cancel_from <= cancel_to)) { +#ifdef ANDROID +pthread_kill (t_scans[cancel_from],SIGUSR1 ); +#else pthread_cancel (t_scans[cancel_from]); +#endif cancel_from++; } out2:
cmds-receive.c +4 -0
@@ -25,7 +25,11 @@#include <pthread.h> #include <math.h> #include <ftw.h> +#ifndef ANDROID #include <wait.h> +#else +#include <sys/wait.h> +#endif #include <assert.h> #include <getopt.h>
cmds-restore.c +1 -0
@@ -86,6 +86,7 @@ static int decompress_zlib(char *inbuf, char *outbuf, u64 compress_len, (void )inflateEnd (&strm);return 0 ; } +static inline size_t read_compress_length (unsigned char *buf) {__le32 dlen;
cmds-scrub.c +20 -2
@@ -780,12 +780,13 @@ static int scrub_write_progress(pthread_mutex_t *m, const char *fsid,int fd =-1 ;int old; +#ifndef ANDROID ret =pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , &old);if (ret) { err = -ret; goto out3; } - +#endif ret =pthread_mutex_lock (m);if (ret) { err = -ret;
@@ -816,10 +817,11 @@ out1: err = -ret; out2: +#ifndef ANDROID ret =pthread_setcancelstate (PTHREAD_CANCEL_ENABLE , &old);if (ret && !err) err = -ret; - +#endif out3:return err; }
@@ -898,9 +900,11 @@ static void *scrub_progress_cycle(void *ctx)struct sockaddr_un peer;socklen_t peer_size =sizeof (peer); +#ifndef ANDROID perr =pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS , &old);if (perr) goto out; +#endif uuid_unparse (spc->fi->fsid, fsid);
@@ -952,10 +956,12 @@ static void *scrub_progress_cycle(void *ctx)* result we got for the current write and go * on. flag should be set on next cycle, then. */ +#ifndef ANDROID perr =pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , &old);if (perr) goto out; +#endif perr =pthread_mutex_lock (&sp_shared->progress_mutex);if (perr) goto out;
@@ -964,20 +970,24 @@ static void *scrub_progress_cycle(void *ctx) &sp_shared->progress_mutex);if (perr) goto out; +#ifndef ANDROID perr =pthread_setcancelstate (PTHREAD_CANCEL_ENABLE , &old);if (perr) goto out; +#endif memcpy (sp, sp_last,sizeof (*sp));continue ; } perr =pthread_mutex_unlock (&sp_shared->progress_mutex);if (perr) goto out; +#ifndef ANDROID perr =pthread_setcancelstate (PTHREAD_CANCEL_ENABLE , &old);if (perr) goto out; +#endif memcpy (sp, sp_shared,sizeof (*sp));memcpy (sp_last, sp_shared,sizeof (*sp)); }
@@ -1506,7 +1516,11 @@ static int scrub_start(int argc, char **argv, int resume) } } +#ifdef ANDROID + ret =pthread_kill (t_prog,SIGUSR1 ); +#else ret =pthread_cancel (t_prog); +#endif if (!ret) ret =pthread_join (t_prog, &terr);
@@ -1517,7 +1531,11 @@ static int scrub_start(int argc, char **argv, int resume) }/* check for errors returned from the progress thread itself */ +#ifdef ANDROID +if (do_print && terr) { +#else if (do_print && terr && terr !=PTHREAD_CANCELED ) { +#endif fprintf (stderr,"ERROR: recording progress " "failed: %s\n" ,strerror (-PTR_ERR (terr))); }
kerncompat.h +3 -0
@@ -134,6 +134,9 @@ typedef long long s64;typedef int s32 ;#endif +#ifdef ANDROID +typedef struct blkid_struct_probe *blkid_probe ; +#endif struct vma_shared {int prio_tree_node; };struct vm_area_struct {
mkfs.c +9 -0
@@ -25,7 +25,12 @@#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> +#ifndef ANDROID #include <sys/dir.h> +#else +#include <dirent.h> +#define direct dirent +#endif #include <fcntl.h> #include <unistd.h> #include <getopt.h>
@@ -1359,7 +1364,11 @@ int main(int ac, char **av) dev_cnt = ac - optind; file = av[optind++]; +#ifndef ANDROID ssd =is_ssd (file); +#else + ssd = true; +#endif if (is_vol_small (file) || mixed) {if (verbose)
utils.c +6 -3
@@ -878,9 +878,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret, file, strerror(-ret));return 1 ; } - +#ifndef ANDROID btrfs_wipe_existing_sb (fd); - +#endif *block_count_ret = block_count;return 0 ; }
@@ -2267,7 +2267,6 @@ check_overwrite(return 0 ; ret =-1 ;/* will reset on success of all setup calls */ - pr =blkid_new_probe_from_filename (device);if (!pr) goto out;
@@ -2436,7 +2435,11 @@ int test_dev_for_mkfs(char *file, int force_overwrite)return 1 ; }if (!force_overwrite) { +#ifndef ANDROID if (check_overwrite (file)) { +#else + { +#endif fprintf (stderr,"Use the -f option to force overwrite.\n" );return 1 ; }
Signature · 1 line
1.8.2
Quoted 1 line
From
a8c6477c88a2a44685058fb4f2c54ee71e83dc9fMon Sep 17 00:00:00 2001
From: "kenneth.kang" <[email protected]>
Date: Mon, 10 Aug 2015 13:24:56 +0900
Subject: [PATCH] arrange intrusive point on Android build patch
--- Android.mk | 2 +- mkfs.c | 7 +++---- utils.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 11 deletions(-)
Android.mk +1 -1
@@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir) #include $(call all-subdir-makefiles) -CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC +CFLAGS := -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC -DPLATFORM_ANDROID=1 LDFLAGS := -static -rdynamic
mkfs.c +3 -4
@@ -1113,6 +1113,9 @@ static int is_ssd(const char *file)char rotational;int ret; +if (PLATFORM_ANDROID ) +return 1 ; + probe =blkid_new_probe_from_filename (file);if (!probe)return 0 ;
@@ -1364,11 +1367,7 @@ int main(int ac, char **av) dev_cnt = ac - optind; file = av[optind++]; -#ifndef ANDROID ssd =is_ssd (file); -#else - ssd = true; -#endif if (is_vol_small (file) || mixed) {if (verbose)
utils.c +8 -6
@@ -801,6 +801,9 @@ static void btrfs_wipe_existing_sb(int fd)int rc =0 ;blkid_probe pr =NULL ; +if (PLATFORM_ANDROID ) +return ; + pr =blkid_new_probe ();if (!pr)return ;
@@ -878,9 +881,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret, file, strerror(-ret));return 1 ; } -#ifndef ANDROID +btrfs_wipe_existing_sb (fd); -#endif + *block_count_ret = block_count;return 0 ; }
@@ -2263,6 +2266,9 @@ check_overwrite(int ret;blkid_loff_t size; +if (PLATFORM_ANDROID ) +return 1 ; +if (!device || !*device)return 0 ;
@@ -2435,11 +2441,7 @@ int test_dev_for_mkfs(char *file, int force_overwrite)return 1 ; }if (!force_overwrite) { -#ifndef ANDROID if (check_overwrite (file)) { -#else - { -#endif fprintf (stderr,"Use the -f option to force overwrite.\n" );return 1 ; }
Signature · 1 line
1.8.2
Quoted 1 line · 강상우
I change the code that you are suggest.
Well, it's still not exactly what I expected. I'll add the makefile bits from you patch and do the wrappers and ifdefs myself. It's not always straightfowratd how to do it so I'll need to experiment a bit.
Quoted 6 lines · David Sterba
Quoted 1 line · 강상우
I change the code that you are suggest.
Well, it's still not exactly what I expected. I'll add the makefile bits from you patch and do the wrappers and ifdefs myself. It's not always straightfowratd how to do it so I'll need to experiment a bit.
So the preliminary support is merged. Outstanding issues are all related to blkid API:
- btrfs_wipe_existing_sb
- is_ssd
- check_overwrite
In the ssd check case it's safe to provide the 'return 1' replacement, but the other two are related to safety measures and I'm not comfortable to ifdef them out yet.
Quoted 4 lines · David Sterba
So the preliminary support is merged. Outstanding issues are all related to blkid API:
-
is_ssd
Fixed by trivially ifdef around the function.
Quoted 6 lines
-
btrfs_wipe_existing_sb
-check_overwriteIn the ssd check case it's safe to provide the 'return 1' replacement, but the other two are related to safety measures and I'm not comfortable to ifdef them out yet.
I'm not able to find the exact version of libblkid that android uses, closest guess is 2.14 which is pretty old. The low-level probing has been added to 2.15 and I think we can't avoid that. Reimpliementing the missing blkid functionality is possible but I'd rather not go that way.
Please let me know if there's a version of android build system that provides sufficiently new blkid otherwise I'm afraid that we can't support it.