Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/util-linux/swaponoff.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 815 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 7  Line 7 
7   * Licensed under the GPL version 2, see the file LICENSE in this tarball.   * Licensed under the GPL version 2, see the file LICENSE in this tarball.
8   */   */
9    
10  #include "busybox.h"  #include "libbb.h"
11  #include <mntent.h>  #include <mntent.h>
12  #include <sys/swap.h>  #include <sys/swap.h>
13    
14    #if ENABLE_FEATURE_SWAPON_PRI
15    struct globals {
16     int flags;
17    };
18    #define G (*(struct globals*)&bb_common_bufsiz1)
19    #define g_flags (G.flags)
20    #else
21    #define g_flags 0
22    #endif
23    
24  static int swap_enable_disable(char *device)  static int swap_enable_disable(char *device)
25  {  {
# Line 19  static int swap_enable_disable(char *dev Line 28  static int swap_enable_disable(char *dev
28    
29   xstat(device, &st);   xstat(device, &st);
30    
31    #if ENABLE_DESKTOP
32   /* test for holes */   /* test for holes */
33   if (S_ISREG(st.st_mode))   if (S_ISREG(st.st_mode))
34   if (st.st_blocks * 512 < st.st_size)   if (st.st_blocks * (off_t)512 < st.st_size)
35   bb_error_msg_and_die("swap file has holes");   bb_error_msg("warning: swap file has holes");
36    #endif
37    
38   if (applet_name[5] == 'n')   if (applet_name[5] == 'n')
39   status = swapon(device, 0);   status = swapon(device, g_flags);
40   else   else
41   status = swapoff(device);   status = swapoff(device);
42    
43   if (status != 0) {   if (status != 0) {
44   bb_perror_msg("%s", device);   bb_simple_perror_msg(device);
45   return 1;   return 1;
46   }   }
47    
# Line 57  static int do_em_all(void) Line 68  static int do_em_all(void)
68   return err;   return err;
69  }  }
70    
71  #define DO_ALL    0x01  int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
72    int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
 int swap_on_off_main(int argc, char **argv)  
73  {  {
74   int ret;   int ret;
75    
76   if (argc == 1)  #if !ENABLE_FEATURE_SWAPON_PRI
77   bb_show_usage();   ret = getopt32(argv, "a");
78    #else
79     opt_complementary = "p+";
80     ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);
81    
82     if (ret & 2) { // -p
83     g_flags = SWAP_FLAG_PREFER |
84     ((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
85     ret &= 1;
86     }
87    #endif
88    
89   ret = getopt32(argc, argv, "a");   if (ret /* & 1: not needed */) // -a
  if (ret & DO_ALL)  
90   return do_em_all();   return do_em_all();
91    
92   ret = 0;   argv += optind;
93   while (*++argv)   if (!*argv)
94     bb_show_usage();
95    
96     /* ret = 0; redundant */
97     do {
98   ret += swap_enable_disable(*argv);   ret += swap_enable_disable(*argv);
99     } while (*++argv);
100    
101   return ret;   return ret;
102  }  }

Legend:
Removed from v.815  
changed lines
  Added in v.816