Added CONFIG_CLEAR and CONFIG_RESET to config.maemo
[busybox4maemo] / debian / patches / fsync.patch
1 Index: busybox/coreutils/fsync.c
2 ===================================================================
3 --- busybox/coreutils/fsync.c   (revision 0)
4 +++ busybox/coreutils/fsync.c   (revision 0)
5 @@ -0,0 +1,46 @@
6 +/* vi: set sw=4 ts=4: */
7 +/*
8 + * Mini fsync implementation for busybox
9 + *
10 + * Copyright (C) 2008 Nokia Corporation. All rights reserved.
11 + *
12 + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 + */
14 +
15 +#include "libbb.h"
16 +
17 +/* This is a NOFORK applet. Be very careful! */
18 +
19 +int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
20 +int fsync_main(int argc, char **argv)
21 +{
22 +       int status = EXIT_SUCCESS;
23 +       int flags;
24 +       int fd;
25 +       char *path;
26 +
27 +       flags = getopt32(argv, "d"); /* fdatasync */
28 +       argv += optind;
29 +
30 +       if (!*argv) {
31 +               bb_show_usage();
32 +       }
33 +
34 +       for (path = *argv++; path; path = *argv++) {
35 +               fd = open(path, O_NOATIME | O_NOCTTY | O_RDONLY);
36 +
37 +               if (fd == -1) {
38 +                       bb_simple_perror_msg(path);
39 +                       status = EXIT_FAILURE;
40 +                       continue;
41 +               }
42 +               
43 +               if ((flags ? fdatasync(fd) : fsync(fd)) == -1) {
44 +                       bb_simple_perror_msg(path);
45 +               }
46 +
47 +               close(fd);
48 +       }
49 +
50 +       return status;
51 +}
52 Index: busybox/coreutils/Kbuild
53 ===================================================================
54 --- busybox/coreutils/Kbuild    (revision 23238)
55 +++ busybox/coreutils/Kbuild    (working copy)
56 @@ -36,6 +36,7 @@
57  lib-$(CONFIG_EXPAND)    += expand.o
58  lib-$(CONFIG_FALSE)     += false.o
59  lib-$(CONFIG_FOLD)      += fold.o
60 +lib-$(CONFIG_FSYNC)     += fsync.o
61  lib-$(CONFIG_HEAD)      += head.o
62  lib-$(CONFIG_HOSTID)    += hostid.o
63  lib-$(CONFIG_ID)        += id.o
64 Index: busybox/coreutils/Config.in
65 ===================================================================
66 --- busybox/coreutils/Config.in (revision 23238)
67 +++ busybox/coreutils/Config.in (working copy)
68 @@ -249,6 +249,12 @@
69         help
70           Wrap text to fit a specific width.
71  
72 +config FSYNC
73 +       bool "fsync"
74 +       default n
75 +       help
76 +         fsync is used to flush file-related cached blocks to disk.
77 +
78  config HEAD
79         bool "head"
80         default n
81 Index: busybox/include/usage.h
82 ===================================================================
83 --- busybox/include/usage.h     (revision 23238)
84 +++ busybox/include/usage.h     (working copy)
85 @@ -3905,6 +3905,13 @@
86  #define sync_full_usage "\n\n" \
87         "Write all buffered filesystem blocks to disk"
88  
89 +#define fsync_trivial_usage \
90 +       "[OPTION]... FILE..."
91 +#define fsync_full_usage \
92 +       "Write files' buffered blocks to disk\n" \
93 +     "\nOptions:" \
94 +     "\n        -d     Avoid syncing metadata (like access time)"
95 +
96  #define sysctl_trivial_usage \
97         "[OPTIONS]... [VALUE]..."
98  #define sysctl_full_usage "\n\n" \
99 Index: busybox/include/applets.h
100 ===================================================================
101 --- busybox/include/applets.h   (revision 23238)
102 +++ busybox/include/applets.h   (working copy)
103 @@ -160,6 +160,7 @@
104  //USE_E2FSCK(APPLET_ODDNAME(fsck.ext2, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_ext2))
105  //USE_E2FSCK(APPLET_ODDNAME(fsck.ext3, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_ext3))
106  USE_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_minix))
107 +USE_FSYNC(APPLET_NOFORK(fsync, fsync, _BB_DIR_BIN, _BB_SUID_NEVER, fsync))
108  USE_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER, ftpget))
109  USE_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER, ftpput))
110  USE_FUSER(APPLET(fuser, _BB_DIR_USR_BIN, _BB_SUID_NEVER))