Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/swaponoff.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/swaponoff.c
r1765 r2725 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 6 * 7 * Licensed under the GPL version 2, see the file LICENSE in this tarball.7 * Licensed under GPLv2, see file LICENSE in this source tree. 8 8 */ 9 9 … … 12 12 #include <sys/swap.h> 13 13 14 #if ENABLE_FEATURE_MOUNT_LABEL 15 # include "volume_id.h" 16 #else 17 # define resolve_mount_spec(fsname) ((void)0) 18 #endif 19 20 #if ENABLE_FEATURE_SWAPON_PRI 21 struct globals { 22 int flags; 23 } FIX_ALIASING; 24 #define G (*(struct globals*)&bb_common_bufsiz1) 25 #define g_flags (G.flags) 26 #else 27 #define g_flags 0 28 #endif 29 14 30 static int swap_enable_disable(char *device) 15 31 { … … 17 33 struct stat st; 18 34 35 resolve_mount_spec(&device); 19 36 xstat(device, &st); 20 37 … … 22 39 /* test for holes */ 23 40 if (S_ISREG(st.st_mode)) 24 if (st.st_blocks * 512 < st.st_size)41 if (st.st_blocks * (off_t)512 < st.st_size) 25 42 bb_error_msg("warning: swap file has holes"); 26 43 #endif 27 44 28 45 if (applet_name[5] == 'n') 29 status = swapon(device, 0);46 status = swapon(device, g_flags); 30 47 else 31 48 status = swapoff(device); 32 49 33 50 if (status != 0) { 34 bb_ perror_msg("%s",device);51 bb_simple_perror_msg(device); 35 52 return 1; 36 53 } … … 50 67 51 68 err = 0; 52 while ((m = getmntent(f)) != NULL) 53 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0) 54 err += swap_enable_disable(m->mnt_fsname); 69 while ((m = getmntent(f)) != NULL) { 70 if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0) { 71 /* swapon -a should ignore entries with noauto, 72 * but swapoff -a should process them */ 73 if (applet_name[5] != 'n' 74 || hasmntopt(m, MNTOPT_NOAUTO) == NULL 75 ) { 76 err += swap_enable_disable(m->mnt_fsname); 77 } 78 } 79 } 55 80 56 endmntent(f); 81 if (ENABLE_FEATURE_CLEAN_UP) 82 endmntent(f); 57 83 58 84 return err; 59 85 } 60 86 61 int swap_on_off_main(int argc, char **argv) ;62 int swap_on_off_main(int argc , char **argv)87 int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 88 int swap_on_off_main(int argc UNUSED_PARAM, char **argv) 63 89 { 64 90 int ret; 65 91 66 if (argc == 1) 92 #if !ENABLE_FEATURE_SWAPON_PRI 93 ret = getopt32(argv, "a"); 94 #else 95 opt_complementary = "p+"; 96 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags); 97 98 if (ret & 2) { // -p 99 g_flags = SWAP_FLAG_PREFER | 100 ((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT); 101 ret &= 1; 102 } 103 #endif 104 105 if (ret /* & 1: not needed */) // -a 106 return do_em_all(); 107 108 argv += optind; 109 if (!*argv) 67 110 bb_show_usage(); 68 111 69 ret = getopt32(argv, "a"); 70 if (ret) 71 return do_em_all(); 112 /* ret = 0; redundant */ 113 do { 114 ret += swap_enable_disable(*argv); 115 } while (*++argv); 72 116 73 /* ret = 0; redundant */74 while (*++argv)75 ret += swap_enable_disable(*argv);76 117 return ret; 77 118 }
Note:
See TracChangeset
for help on using the changeset viewer.