+ /*
+ * get rid of the filename at the end of the swap file specification
+ * we only want the portion of the pathname that should already exist
+ */
+ strcpy(tmp, fileroot);
+ if ((q = strrchr(tmp, '/')))
+ *q = 0;
+
+ /*
+ * Remove all files in the swap directory.
+ */
+ clean_swap_directory(tmp);
+
+#if TARGET_OS_EMBEDDED
+ paging_mode = get_paging_mode();
+ paging_mode_length = sizeof(paging_mode);
+
+ switch (paging_mode) {
+ case VM_PAGING_MODE_DISABLED:
+ /* Paging disabled; nothing to do here so exit */
+ exit(EXIT_SUCCESS);
+
+ case VM_PAGING_MODE_FREEZE:
+ /* Freeze mode; one swap file of fixed size, so enable and override defaults if set */
+ err = sysctlbyname(VM_FREEZE_SYSCTL, NULL, 0, &paging_mode, paging_mode_length);
+ if (err < 0) {
+ (void)fprintf(stderr, "dynamic_pager: cannot set %s\n", VM_FREEZE_SYSCTL);
+ exit(EXIT_FAILURE);
+ }
+ variable_sized = 0;
+ limits[0].size = FREEZE_FIXED_SWAP_SIZE;
+ break;
+
+ case VM_PAGING_MODE_DYNAMIC:
+ /* Dynamic paging selected; proceed normally */
+ break;
+
+ default:
+ /* Invalid option */
+ (void)fprintf(stderr, "dynamic_pager: invalid paging_mode %d\n", paging_mode);
+ exit(EXIT_FAILURE);
+ }
+#endif
+
+ if (statfs(tmp, &sfs) == -1) {
+ /*
+ * Setup the swap directory.
+ */
+ if (mkdir(tmp, 0755) == -1) {
+ (void)fprintf(stderr, "dynamic_pager: cannot create swap directory %s\n", tmp);
+ exit(EXIT_FAILURE);
+ }
+ }
+ chown(tmp, 0, 0);
+