Example #1
0
static bool fs_sis_try_link(struct sis_fs_file *file)
{
	const char *path = fs_file_path(&file->file);
	const struct stat *st;
	struct stat st2;

	st = i_stream_stat(file->hash_input, FALSE);

	/* we can use the existing file */
	if (fs_link(file->super->fs, file->hash_path, path) < 0) {
		if (errno != ENOENT && errno != EMLINK)
			i_error("fs-sis: %s", fs_last_error(file->super->fs));
		/* failed to use link(), continue as if it hadn't been equal */
		return FALSE;
	}
	if (fs_stat(file->super->fs, path, &st2) < 0) {
		i_error("fs-sis: %s", fs_last_error(file->super->fs));
		if (fs_unlink(file->super->fs, path) < 0)
			i_error("fs-sis: %s", fs_last_error(file->super->fs));
		return FALSE;
	}
	if (st->st_ino != st2.st_ino) {
		/* the hashes/ file was already replaced with something else */
		if (fs_unlink(file->super->fs, path) < 0)
			i_error("fs-sis: %s", fs_last_error(file->super->fs));
		return FALSE;
	}
	return TRUE;
}
Example #2
0
void unlink_device(char *sym_name, enum FS_STO_TYPE type)
{
	char mount_name[16]; // like "/mnt/uda1"
	struct stat st;
	
	if(fs_stat(sym_name, &st) == 0)
	{
		fs_readlink(sym_name, mount_name, 16);
		switch(type)
		{
			case MNT_TYPE_IDE:
				if(mount_name[5] == 'h')
					fs_unlink(sym_name);
				break;
			case MNT_TYPE_SD:
				if((mount_name[5] == 's') && (mount_name[6] == 'd'))
					fs_unlink(sym_name);
				break;
			case MNT_TYPE_USB:
				if(mount_name[5] == 'u')
					fs_unlink(sym_name);
				break;
			case MNT_TYPE_SATA:
				if((mount_name[5] == 's') && (mount_name[6] == 'h'))
					fs_unlink(sym_name);
				break;
			default:
				break;
		}
	}	
}
Example #3
0
static void fs_sis_replace_hash_file(struct sis_fs_file *file)
{
	const char *hash_fname, *path = fs_file_path(&file->file);
	struct fs *super_fs = file->super->fs;
	string_t *temp_path;
	int ret;

	if (file->hash_input == NULL) {
		/* hash file didn't exist previously. we should be able to
		   create it with link() */
		if (fs_link(super_fs, path, file->hash_path) < 0) {
			if (errno == EEXIST) {
				/* the file was just created. it's probably
				   a duplicate, but it's too much trouble
				   trying to deduplicate it anymore */
			} else {
				i_error("fs-sis: %s", fs_last_error(super_fs));
			}
		}
		return;
	}

	temp_path = t_str_new(256);
	hash_fname = strrchr(file->hash_path, '/');
	if (hash_fname == NULL)
		hash_fname = file->hash_path;
	else {
		str_append_n(temp_path, file->hash_path,
			     (hash_fname-file->hash_path) + 1);
		hash_fname++;
	}
	str_printfa(temp_path, "%s%s.tmp",
		    super_fs->set.temp_file_prefix, hash_fname);

	/* replace existing hash file atomically */
	ret = fs_link(super_fs, path, str_c(temp_path));
	if (ret < 0 && errno == EEXIST) {
		/* either someone's racing us or it's a stale file.
		   try to continue. */
		if (fs_unlink(super_fs, str_c(temp_path)) < 0 &&
		    errno != ENOENT)
			i_error("fs-sis: %s", fs_last_error(super_fs));
		ret = fs_link(super_fs, path, str_c(temp_path));
	}
	if (ret < 0) {
		i_error("fs-sis: %s", fs_last_error(super_fs));
		return;
	}
	if (fs_rename(super_fs, str_c(temp_path), file->hash_path) < 0) {
		if (errno == ENOENT) {
			/* apparently someone else just renamed it. ignore. */
		} else {
			i_error("fs-sis: %s", fs_last_error(super_fs));
		}
		(void)fs_unlink(super_fs, str_c(temp_path));
	}
}
Example #4
0
static int unlink_recursive(char path[STORAGE_PATH_MAX])
{
	size_t path_len;
	fs_dir_t dir;
	int err;

	err = fs_opendir(&dir, path);
	if (err) {
		return err;
	}

	/* We calculate this up-front so we can keep reusing the same
	 * buffer for the path when recursing.
	 */
	path_len = strlen(path);

	while (1) {
		struct fs_dirent entry;

		err = fs_readdir(&dir, &entry);
		if (err) {
			break;
		}

		if (entry.name[0] == '\0') {
			break;
		}

		snprintk(path + path_len, STORAGE_PATH_MAX - path_len, "/%s",
			 entry.name);

		if (entry.type == FS_DIR_ENTRY_DIR) {
			err = unlink_recursive(path);
		} else {
			err = fs_unlink(path);
		}

		if (err) {
			break;
		}
	}

	fs_closedir(&dir);

	/* Return to the original value */
	path[path_len] = '\0';

	fs_unlink(path);

	return err;
}
Example #5
0
void fs_sis_try_unlink_hash_file(struct fs *fs, struct fs *super,
                                 const char *path)
{
    struct stat st1, st2;
    const char *dir, *hash, *hash_path, *hash_dir;

    if (fs_sis_path_parse(fs, path, &dir, &hash) == 0 &&
            fs_stat(super, path, &st1) == 0 && st1.st_nlink == 2) {
        /* this may be the last link. if hashes/ file is the same,
           delete it. */
        hash_path = t_strdup_printf("%s/"HASH_DIR_NAME"/%s", dir, hash);
        if (fs_stat(super, hash_path, &st2) == 0 &&
                st1.st_ino == st2.st_ino &&
                CMP_DEV_T(st1.st_dev, st2.st_dev)) {
            if (fs_unlink(super, hash_path) < 0)
                i_error("%s", fs_last_error(super));
            else {
                /* try to rmdir the hashes/ directory */
                hash_dir = t_strdup_printf("%s/"HASH_DIR_NAME,
                                           dir);
                (void)fs_rmdir(super, hash_dir);
            }
        }
    }
}
/**
 * Deletes the main image version number from the boot vector.
 *
 * @return                  0 on success; nonzero on failure.
 */
int
boot_vect_delete_main(void)
{
    int rc;

    rc = fs_unlink(BOOT_PATH_MAIN);
    return rc;
}
/**
 * Deletes the test image version number from the boot vector.
 *
 * @return                  0 on success; nonzero on failure.
 */
int
boot_vect_delete_test(void)
{
    int rc;

    rc = fs_unlink(BOOT_PATH_TEST);
    return rc;
}
Example #8
0
int do_unlink(const char *filename,uint64_t lv,uint32_t ts,char *ptr) {
	uint32_t inode,parent;
	uint8_t name[256];
	EAT(ptr,filename,lv,'(');
	GETU32(parent,ptr);
	EAT(ptr,filename,lv,',');
	GETNAME(name,ptr,filename,lv,')');
	EAT(ptr,filename,lv,')');
	EAT(ptr,filename,lv,':');
	GETU32(inode,ptr);
	return fs_unlink(ts,parent,strlen((char*)name),name,inode);
}
Example #9
0
/*
	rm command
*/
LOCAL	void	cmd_rm(INT ac, B *av[])
{
	ER	er;

	if (ac < 2) return;

	er = fs_unlink(av[1]);
	if (er >= E_OK) {
		P("file '%s' removed\n", av[1]);
	} else {
		P("fs_unlink(%s) ERR [%#x]\n", av[1], er);
	}
}
Example #10
0
void WriteConfig(void)
{
    char configpath[300];

#ifdef _arch_dreamcast
    fs_unlink(configname);
#endif

    if(configdir[0])
        snprintf(configpath, sizeof(configpath), "%s/%s", configdir, configname);
    else
        strcpy(configpath, configname);

    const int file = open(configpath, O_CREAT | O_WRONLY | O_BINARY, 0644);
    if (file != -1)
    {
        word tmp=0xfefa;
        write(file,&tmp,sizeof(tmp));
        write(file,Scores,sizeof(HighScore) * MaxScores);

        write(file,&SoundMode,sizeof(SoundMode));
        write(file,&MusicMode,sizeof(MusicMode));
        write(file,&DigiMode,sizeof(DigiMode));

        write(file,&mouseenabled,sizeof(mouseenabled));
        write(file,&joystickenabled,sizeof(joystickenabled));
        boolean dummyJoypadEnabled = false;
        write(file,&dummyJoypadEnabled,sizeof(dummyJoypadEnabled));
        boolean dummyJoystickProgressive = false;
        write(file,&dummyJoystickProgressive,sizeof(dummyJoystickProgressive));
        int dummyJoystickPort = 0;
        write(file,&dummyJoystickPort,sizeof(dummyJoystickPort));

        write(file,dirscan,sizeof(dirscan));
        write(file,buttonscan,sizeof(buttonscan));
        write(file,buttonmouse,sizeof(buttonmouse));
        write(file,buttonjoy,sizeof(buttonjoy));

        write(file,&viewsize,sizeof(viewsize));
        write(file,&mouseadjustment,sizeof(mouseadjustment));

        close(file);
    }
#ifdef _arch_dreamcast
    DC_SaveToVMU(configname, NULL);
#endif
}
Example #11
0
static efi_status_t EFIAPI efi_file_delete(struct efi_file_handle *file)
{
	struct file_handle *fh = to_fh(file);
	efi_status_t ret = EFI_SUCCESS;

	EFI_ENTRY("%p", file);

	if (set_blk_dev(fh)) {
		ret = EFI_DEVICE_ERROR;
		goto error;
	}

	if (fs_unlink(fh->path))
		ret = EFI_DEVICE_ERROR;
	file_close(fh);

error:
	return EFI_EXIT(ret);
}
Example #12
0
int savegame_simple ()
{
	char home[MAX_PATH], path[MAX_PATH];

#ifdef DREAMCAST
	uint8 addr, port, unit;

	addr = maple_first_vmu();
	if(addr) {
		maple_create_port(addr, &port, &unit);
		sprintf(g_vmu_port, "%c%d", port + 'a', unit);
	} else {
		message_box("No VMU found.");
		return err_OK;
	}

	sprintf(path, VMU_PATH, g_vmu_port, game.id, slot);
	fs_unlink(path);
#else
	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Couldn't save game.");
		return err_BadFileOpen;
	}

	sprintf (path, "%s/" DATA_DIR "/", home);
	MKDIR (path, 0755);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
	MKDIR (path, 0711);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, 0);
#endif
        printf("here?\n");
	save_game (path, "Default savegame");

	return err_OK;
}
Example #13
0
void __elf_clear()
{
  fs_unlink(__elf_logfile);
}
/**
 * Prepares the booting process.  Based on the information provided in the
 * request object, this function moves images around in flash as appropriate,
 * and tells you what address to boot from.
 *
 * @param req                   Contains information about the flash layout.
 * @param rsp                   On success, indicates how booting should occur.
 *
 * @return                      0 on success; nonzero on failure.
 */
int
boot_go(const struct boot_req *req, struct boot_rsp *rsp)
{
    struct boot_image_location image_addrs[BOOT_NUM_SLOTS];
    int slot;
    int rc;
    int i;

    /* Set the global boot request object.  The remainder of the boot process
     * will reference the global.
     */
    boot_req = req;

    /* Initialize the flash hardware and the file system. */
    rc = boot_init_flash();
    if (rc != 0) {
        return rc;
    }

    /* Read the boot status to determine if an image copy operation was
     * interrupted (i.e., the system was reset before the boot loader could
     * finish its task last time).
     */
    boot_status_entries =
        malloc(req->br_num_image_areas * sizeof *boot_status_entries);
    if (boot_status_entries == NULL) {
        return BOOT_ENOMEM;
    }
    rc = boot_read_status(&boot_status, boot_status_entries,
                          boot_req->br_num_image_areas);
    if (rc == 0) {
        /* We are resuming an interrupted image copy. */
        rc = boot_copy_image(boot_status.bs_img1_length,
                             boot_status.bs_img2_length);

        if (rc != 0) {
            /* We failed to put the images back together; there is really no
             * solution here.
             */
            return rc;
        }
    }

    /* Cache the flash address of each image slot. */
    for (i = 0; i < BOOT_NUM_SLOTS; i++) {
        boot_slot_addr(i, &image_addrs[i].bil_flash_id,
                       &image_addrs[i].bil_address);
    }

    /* Attempt to read an image header from each slot. */
    boot_read_image_headers(boot_img_hdrs, image_addrs, BOOT_NUM_SLOTS);

    /* Build a boot status structure indicating the flash location of each
     * image part.  This structure will need to be used if an image copy
     * operation is required.
     */
    boot_build_status();

    /* Determine which image the user wants to run, and where it is located. */
    slot = boot_select_image_slot();
    if (slot == -1) {
        /* Either there is no image vector, or none of the requested images are
         * present.  Just try booting from the first image slot.
         */
        if (boot_img_hdrs[0].ih_magic != IMAGE_MAGIC_NONE) {
            slot = 0;
        } else if (boot_img_hdrs[1].ih_magic != IMAGE_MAGIC_NONE) {
            slot = 1;
        } else {
            /* No images present. */
            return BOOT_EBADIMAGE;
        }
    }

    switch (slot) {
    case 0:
        rsp->br_hdr = &boot_img_hdrs[0];
        break;

    case 1:
        /* The user wants to run the image in the secondary slot.  The contents
         * of this slot need to moved to the primary slot.
         */
        rc = boot_copy_image(boot_status.bs_img1_length,
                             boot_status.bs_img2_length);

        if (rc != 0) {
            /* We failed to put the images back together; there is really no
             * solution here.
             */
            return rc;
        }

        rsp->br_hdr = &boot_img_hdrs[1];
        break;

    default:
        assert(0);
        break;
    }

    /* Always boot from the primary slot. */
    rsp->br_flash_id = image_addrs[0].bil_flash_id;
    rsp->br_image_addr = image_addrs[0].bil_address;

    /* After successful boot, there should not be a status file. */
    fs_unlink(BOOT_PATH_STATUS);

    /* If an image is being tested, it should only be booted into once. */
    boot_vect_delete_test();

    return 0;
}
Example #15
0
int coleco_save_state(const char *filename) {
    char tmpfn[4096];
    int rv;
    uint32 crc, adler;
    uint8 *buf, *buf2;
    FILE *fp;
    long len;
    uLong clen;
    vmu_pkg_t pkg;
    uint8 *pkg_out;
    int pkg_size;
    maple_device_t *vmu;
    file_t f;
    int blocks_freed = 0;

    /* Make sure there's a VMU in port A1. */
    if(!(vmu = maple_enum_dev(0, 1))) {
        return -100;
    }

    if(!vmu->valid || !(vmu->info.functions & MAPLE_FUNC_MEMCARD)) {
        return -100;
    }

    sprintf(tmpfn, "/ram/%s", filename);
    rv = coleco_save_state_int(tmpfn);

    if(rv)
        return rv;

    /* Read in the uncompressed save state */
    fp = fopen(tmpfn, "rb");
    if(!fp) {
        fs_unlink(tmpfn);
        return -1;
    }

    fseek(fp, 0, SEEK_END);
    len = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    if(!(buf = (uint8 *)malloc(len))) {
        fclose(fp);
        fs_unlink(tmpfn);
        return -1;
    }

    fread(buf, 1, len, fp);
    fclose(fp);

    fs_unlink(tmpfn);

    /* Create a compressed version */
    clen = len * 2;

    if(!(buf2 = (uint8 *)malloc(clen + 8))) {
        free(buf);
        return -1;
    }

    if(compress2(buf2 + 8, &clen, buf, len, 9) != Z_OK) {
        free(buf2);
        free(buf);
        return -1;
    }

    /* Clean up the old buffer and save the length of the uncompressed data into
       the new buffer */
    free(buf);
    *((uint32 *)buf2) = (uint32)len;
    *(((uint32 *)buf2) + 1) = (uint32)clen;

    /* Make the VMU save */
    coleco_get_checksums(&crc, &adler);
    sprintf(tmpfn, "/vmu/a1/ss-%08" PRIX32, (uint32_t)crc);

    if(filename != NULL) {
        strncpy(pkg.desc_long, filename, 32);
        pkg.desc_long[31] = 0;
    }
    else {
        sprintf(pkg.desc_long, "CRC: %08" PRIX32 " Adler: %08" PRIX32,
                (uint32_t)crc, (uint32_t)adler);
    }

    strcpy(pkg.desc_short, "CrabEmu State");
    strcpy(pkg.app_id, "CrabEmu");
    pkg.icon_cnt = 1;
    pkg.icon_anim_speed = 0;
    memcpy(pkg.icon_pal, icon_pal, 32);
    pkg.icon_data = icon_img;
    pkg.eyecatch_type = VMUPKG_EC_NONE;
    pkg.data_len = clen + 4;
    pkg.data = buf2;

    vmu_pkg_build(&pkg, &pkg_out, &pkg_size);

    /* See if a file exists with that name, since we'll overwrite it. */
    f = fs_open(tmpfn, O_RDONLY);
    if(f != FILEHND_INVALID) {
        blocks_freed = fs_total(f) >> 9;
        fs_close(f);
    }
Example #16
0
int process_request(const char *line, FILE *fp, FileSystem *fs) {
    char command[4096];
    
#ifdef DEBUG
    fprintf(stderr, "process request `%s`\n", line);
#endif
    sscanf(line, "%s", command);
#ifdef DEBUG
    fprintf(stderr, "command is `%s`\n", command);
#endif
    if (0 == strcmp("f", command)) {
        fs_format(fs);
        return RESULT_DONE;
    } else if (0 == strcmp("mk", command)) {
        char f[4096];
        char parent_path[4096];
        
        sscanf(line + 2, "%s", f);
#ifdef DEBUG
        fprintf(stderr, "> mk `%s`\n", f);
#endif
        if (fs_exists(fs, f)) {
#ifdef DEBUG
            fprintf(stderr, "> `%s` already exists\n", f);
#endif
            return RESULT_NO;
        } else {
#ifdef DEBUG
            fprintf(stderr, "> going to create `%s`\n", f);
#endif
        }
        fs_split_path(f, parent_path, NULL);
        if (fs_isdir(fs, parent_path)) {
            if (fs_create(fs, f)) {
#ifdef DEBUG
                fprintf(stderr, "> failed to create `%s`\n", f);
#endif
                return RESULT_NO;
            }
            return RESULT_YES;
        }
#ifdef DEBUG
        fprintf(stderr, "> parent path `%s` is not a directory\n", parent_path);
#endif
        return RESULT_NO;
    } else if (0 == strcmp("mkdir", command)) {
        char d[4096];
        char parent_path[4096];
        
        sscanf(line + 5, "%s", d);
        if (fs_exists(fs, d)) {
            return RESULT_NO;
        }
        fs_split_path(d, parent_path, NULL);
        if (fs_isdir(fs, parent_path)) {
            if (fs_mkdir(fs, d)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
        return RESULT_NO;
    } else if (0 == strcmp("rm", command)) {
        char f[4096];
        
        sscanf(line + 2, "%s", f);
        if (fs_isfile(fs, f)) {
            if (fs_unlink(fs, f)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
        return RESULT_NO;
    } else if (0 == strcmp("cd", command)) {
        char path[4096];
        
        sscanf(line + 2, "%s", path);
        if (fs_isdir(fs, path)) {
            if (fs_chdir(fs, path)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
#ifdef DEBUG
        fprintf(stderr, "`%s` is not a directory\n", path);
#endif
        return RESULT_NO;
    } else if (0 == strcmp("rmdir", command)) {
        char d[4096];
        
        sscanf(line + 5, "%s", d);
        if (fs_isdir(fs, d)) {
            if (fs_rmdir(fs, d)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
        return RESULT_NO;
    } else if (0 == strcmp("ls", command)) {
        fs_ls(fs, fp);
        return RESULT_ELSE;
    } else if (0 == strcmp("cat", command)) {
        char f[4096];
        
        sscanf(line + 3, "%s", f);
        if (fs_isfile(fs, f)) {
            fs_cat(fs, f, fp);
            return RESULT_ELSE;
        }
        return RESULT_NO;
    } else if (0 == strcmp("w", command)) {
        char f[4096];
        int l;
        char data[4096];
        
        sscanf(line + 1, "%s %d %[^\n]", f, &l, data);
        if (fs_isfile(fs, f)) {
            if (fs_write(fs, f, l, data)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
        return RESULT_NO;
    } else if (0 == strcmp("i", command)) {
        char f[4096];
        int pos;
        int l;
        char data[4096];
        
        sscanf(line + 1, "%s %d %d %[^\n]", f, &pos, &l, data);
        if (fs_isfile(fs, f)) {
            if (fs_insert(fs, f, pos, l, data)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
        return RESULT_NO;
    } else if (0 == strcmp("d", command)) {
        char f[4096];
        int pos;
        int l;
        
        sscanf(line + 1, "%s %d %d", f, &pos, &l);
        if (fs_isfile(fs, f)) {
            if (fs_delete(fs, f, pos, l)) {
                return RESULT_NO;
            }
            return RESULT_YES;
        }
        return RESULT_NO;
    } else if (0 == strcmp("e", command)) {
        return RESULT_EXIT;
    }
    return RESULT_ELSE;
}
Example #17
0
int _unlink_r(void * reent, const char * fn) {
    (void)reent;
    return fs_unlink(fn);
}
Example #18
0
int savegame_dialog ()
{
#ifndef PALMOS /* FIXME */
	char home[MAX_PATH], path[MAX_PATH];
	char *desc;
	char *buttons[] = { "Do as I say!", "I regret", NULL }; 
	char dstr[200];
	int rc, slot = 0;
	int hm, vm, hp, vp;			/* box margins */
	int w;

	hm = 2; vm = 3;
	hp = hm * CHAR_COLS; vp = vm * CHAR_LINES;
	w = (40 - 2 * hm) - 1;

#ifdef DREAMCAST
	uint8 addr, port, unit;

	addr = maple_first_vmu();
	if(addr) {
		maple_create_port(addr, &port, &unit);
		sprintf(g_vmu_port, "%c%d", port + 'a', unit);
	} else {
		message_box("No VMU found.");
		return err_OK;
	}
#else
	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Couldn't save game.");
		return err_BadFileOpen;
	}
# ifdef CIBYL
	sprintf (path, "recordstore://%05X.%s:",
		game.crc, game.id);
# else
	/* DATADIR conflicts with ObjIdl.h in win32 SDK, renamed to DATA_DIR */
	sprintf (path, "%s/" DATA_DIR "/", home);
	MKDIR (path, 0755);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
	MKDIR (path, 0711);
# endif
#endif

	erase_both ();

	draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
	print_text ("Select a slot in which you wish to save the game:",
		0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	print_text ("Press ENTER to select, ESC cancels",
		0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);

	slot = select_slot (path);
	if (slot < 0)	/* ESC pressed */
		return err_OK;

	/* Get savegame description */
	draw_window (hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp,
		GFX_HEIGHT - vp - 9 * CHAR_LINES);
	print_text ("Enter a description for this game:",
		0, hm + 1, vm + 6, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	draw_rectangle (3 * CHAR_COLS, 11 * CHAR_LINES - 1,
		37 * CHAR_COLS, 12 * CHAR_LINES, MSG_BOX_TEXT);
	flush_block (3 * CHAR_COLS, 11 * CHAR_LINES - 1,
		37 * CHAR_COLS, 12 * CHAR_LINES);

	get_string (2, 11, 33, MAX_STRINGS);
	print_character (3, 11, game.cursor_char, MSG_BOX_COLOUR, MSG_BOX_TEXT);
        do { main_cycle (); } while (game.input_mode == INPUT_GETSTRING);
	close_window ();

 	desc = game.strings[MAX_STRINGS];

	sprintf (dstr, "Are you sure you want to save the game "
		"described as:\n\n%s\n\nin slot %d?\n\n\n",
		desc, slot);

	rc = selection_box (dstr, buttons);

	if (rc != 0) {
		message_box ("Game NOT saved.");
		return err_OK;
	}

#ifdef DREAMCAST
	sprintf(path, VMU_PATH, g_vmu_port, game.id, slot);
	fs_unlink(path);
#elif CIBYL
	sprintf (path, "recordstore://%05X.%s:%d",
		game.crc, game.id, slot+1);
        printf("path: %s\n", path);
#else
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, slot);
#endif
	_D (_D_WARN "file is [%s]", path);
	
	save_game (path, desc);

	message_box ("Game saved.");
#endif /* PALMOS */

	return err_OK;
}
Example #19
0
void Speedtest_Run(GUI_Widget *widget) {

	uint8 *buff = (uint8*)0x8c400000;
	size_t buff_size = 0x10000;
	int size = 0x800000, cnt = 0, rs; 
	int64 time_before, time_after;
	uint32 t;
	double speed;
	file_t fd;
	int read_only = 0;
	
	char name[64];
	char result[128];
	const char *wname = GUI_ObjectGetName((GUI_Object *)widget);
	
	if(!strncasecmp(wname, "/cd", 3)) {
		
		read_only = 1;
		snprintf(name, sizeof(name), "%s/1DS_CORE.BIN", wname);

		if(FileExists(name)) {
			goto readtest;
		} else {
			snprintf(name, sizeof(name), "%s/1ST_READ.BIN", wname);
			goto readtest;
		}
	}
	
	show_status_ok("Testing WRITE speed...");
	GUI_LabelSetText(self.speedwr, "...");
	GUI_LabelSetText(self.speedrd, "   ");
	
	snprintf(name, sizeof(name), "%s/%s.tst", wname, lib_get_name());
	
	if(FileExists(name)) {
		fs_unlink(name);
	}
	
	/* WRITE TEST */
	fd = fs_open(name, O_CREAT | O_WRONLY);
	
	if (fd == FILEHND_INVALID) {
		ds_printf("DS_ERROR: Can't open %s for write: %d\n", name, errno);
		show_status_error("Can't open file for write");
		return;
	}

	ShutdownVideoThread(); 
	time_before = timer_ms_gettime64();
	
	while(cnt < size) {
		
		rs = fs_write(fd, buff, buff_size);
		
		if(rs <= 0) {
			fs_close(fd);
			InitVideoThread(); 
			ds_printf("DS_ERROR: Can't write to file: %d\n", errno);
			show_status_error("Can't write to file");
			return;
		}
		
		buff += rs;
		cnt += rs;
	}
	
	time_after = timer_ms_gettime64();
	InitVideoThread();
	
	t = (uint32)(time_after - time_before);
	speed = size / ((float)t / 1000);
	fs_close(fd);
	
	snprintf(result, sizeof(result), 
				"Write speed %.2f Kbytes/s (%.2f Mbit/s) Time: %ld ms",
				speed / 1024, ((speed / 1024) / 1024) * 8, t);
	
	GUI_LabelSetText(self.speedwr, result);
	show_status_ok("Complete!"); 
	
	ds_printf("DS_OK: Complete!\n"
				" Test: write\n Time: %ld ms\n"
				" Speed: %.2f Kbytes/s (%.2f Mbit/s)\n"
				" Size: %d Kb\n Buff: %d Kb\n", 
				t, speed / 1024, 
				((speed / 1024) / 1024) * 8, 
				size / 1024, buff_size / 1024); 
				
readtest:

	show_status_ok("Testing READ speed...");
	GUI_LabelSetText(self.speedrd, "...");

	/* READ TEST */
	fd = fs_open(name, O_RDONLY);
	
	if (fd == FILEHND_INVALID) {
		ds_printf("DS_ERROR: Can't open %s for read: %d\n", name, errno);
		show_status_error("Can't open file for read");
		return;
	}

	if(read_only) {
		GUI_LabelSetText(self.speedwr, "Write test passed");
		/* Reset ISO9660 filesystem cache */
		fs_ioctl(fd, NULL, 0);
		fs_close(fd);
		fd = fs_open(name, O_RDONLY);
	}
	
	time_before = time_after = t = cnt = 0;
	speed = 0.0f;
	size = fs_total(fd);
	buff = rd_buff;

	ShutdownVideoThread();
	time_before = timer_ms_gettime64();

	while(cnt < size) {
		
		rs = fs_read(fd, buff, buff_size);
		
		if(rs <= 0) {
			fs_close(fd);
			InitVideoThread(); 
			ds_printf("DS_ERROR: Can't read file: %d\n", errno);
			show_status_error("Can't read file");
			return;
		}
		
		cnt += rs;
	}
	
	time_after = timer_ms_gettime64();
	t = (uint32)(time_after - time_before);
	speed = size / ((float)t / 1000);
	fs_close(fd);
	
	if(!read_only) { 
		fs_unlink(name);
	} else {
		cdrom_spin_down();
	}
	
	snprintf(result, sizeof(result), 
			"Read speed %.2f Kbytes/s (%.2f Mbit/s) Time: %ld ms",
			speed / 1024, ((speed / 1024) / 1024) * 8, t);
	
	InitVideoThread();
	
	ds_printf("DS_OK: Complete!\n"
				" Test: read\n Time: %ld ms\n"
				" Speed: %.2f Kbytes/s (%.2f Mbit/s)\n"
				" Size: %d Kb\n Buff: %d Kb\n", 
				t, speed / 1024, 
				((speed / 1024) / 1024) * 8, 
				size / 1024, buff_size / 1024);
    
	GUI_LabelSetText(self.speedrd, result);
	show_status_ok("Complete!"); 
}
/**
 * Erases the boot status from the flash file system.  The boot status
 * contains the current state of an in-progress image copy operation.  By
 * erasing the boot status, it is implied that there is no copy operation in
 * progress.
 */
void
boot_clear_status(void)
{
    fs_unlink(BOOT_PATH_STATUS);
}
Example #21
0
void gd_ripper_StartRip() {
	file_t fd;
	CDROM_TOC toc ;
	int status, disc_type ,cdcr ,start ,s_end ,nsec ,type ,tn ,session,terr=0;
	char dst_folder[MAX_FN_LEN];
	char dst_file[MAX_FN_LEN];
	char riplabel[64];
	char text[MAX_FN_LEN];
	uint64 stoptimer , starttimer , riptime;
	
	starttimer = timer_ms_gettime64 (); // timer
	cdrom_reinit();
	snprintf(text ,MAX_FN_LEN,"%s", GUI_TextEntryGetText(self.gname));
	if(GUI_WidgetGetState(self.sd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/sd/%s", text);
	}else if(GUI_WidgetGetState(self.hdd_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/ide/%s", text);
	}else if(GUI_WidgetGetState(self.net_c)) {
		snprintf(dst_folder, MAX_FN_LEN, "/net/%s", text);
	}
//ds_printf("Dst file1 %s\n" ,dst_folder);	
getstatus:	
	if((cdcr = cdrom_get_status(&status, &disc_type)) != ERR_OK) {
		switch (cdcr){
			case ERR_NO_DISC :
				ds_printf("DS_ERROR: Disk not inserted\n");
				return;
			case ERR_DISC_CHG :
				cdrom_reinit();
				goto getstatus;
			case CD_STATUS_BUSY :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SEEKING :
				thd_sleep(200);
				goto getstatus;
			case CD_STATUS_SCANNING :
				thd_sleep(200);
				goto getstatus;
			default:
				ds_printf("DS_ERROR: GD-rom error\n");
				return;
		}
	}
	if (disc_type == CD_CDROM_XA){
	rname:
			snprintf(dst_file,MAX_FN_LEN, "%s.iso", dst_folder);
			if ((fd=fs_open(dst_file , O_RDONLY)) != FILEHND_INVALID) {
				fs_close(fd); strcpy(dst_file,"\0"); 
				strcat(dst_folder , "0"); 
				goto rname ;
			} else disc_type = 1;
	} else if (disc_type == CD_GDROM){
	rname1:
			if ((fd=fs_open (dst_folder , O_DIR)) != FILEHND_INVALID) {
				fs_close(fd); 
				strcat(dst_folder , "0"); 
				goto rname1 ;
			} else {strcpy(dst_file,"\0");
			snprintf(dst_file,MAX_FN_LEN,"%s", dst_folder); 
			disc_type = 2; 
			fs_mkdir(dst_file);
			}
			
			while(cdrom_read_toc(&toc, 1) != CMD_OK) { 
				terr++;
				cdrom_reinit();
				if (terr > 100){
				ds_printf("DS_ERROR: Toc read error for gdlast\n");
				fs_rmdir(dst_folder); 
				return; 
				}
			}
			terr=0;
			self.lastgdtrack = TOC_TRACK(toc.last);
	} else {
			ds_printf("DS_ERROR: This is not game disk\nInserted %d disk\n",disc_type);
			return;
	}
//ds_printf("Dst file %s\n" ,dst_file);
	
	for (session=0; session < disc_type; session++) {
		cdrom_set_sector_size(2048);
		while(cdrom_read_toc(&toc, session) != CMD_OK) {
			terr++; 
			if(terr==5) cdrom_reinit(); 
			thd_sleep(500); 
			if (terr > 10) { 
				ds_printf("DS_ERROR: Toc read error\n");
			if (disc_type == 1) {
				if(fs_unlink(dst_file) != 0) 
				ds_printf("Error delete file: %s\n" ,dst_file);
			}else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				} 
				return; 
			}
		}
		terr = 0;
		int first = TOC_TRACK(toc.first);
		int last = TOC_TRACK(toc.last);
		for (tn=first; tn <= last; tn++ ) {
			if (disc_type == 1) tn = last;
			type = TOC_CTRL(toc.entry[tn-1]);
			if (disc_type == 2) {
				strcpy(dst_file,"\0"); 
				snprintf(dst_file,MAX_FN_LEN,"%s/track%02d.%s", dst_folder, tn, (type == 4 ? "iso" : "raw"));
			}
			
			start = TOC_LBA(toc.entry[tn-1]);
			s_end = TOC_LBA((tn == last ? toc.leadout_sector : toc.entry[tn]));
			nsec = s_end - start;
			
			if (disc_type == 1 && type == 4) nsec -= 2 ;
			else if (session==1 && tn != last && type != TOC_CTRL(toc.entry[tn])) nsec -= 150;
			else if (session==0 && type == 4) nsec -= 150;
			
			if (disc_type == 2 && session == 0) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else if (disc_type == 2 && session == 1 && tn != self.lastgdtrack) {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Track %d of %d\n",tn ,self.lastgdtrack );
			} else {
				strcpy(riplabel,"\0"); 
				sprintf(riplabel,"Last track\n");
			}
			
			GUI_LabelSetText(self.track_label, riplabel);
			
			if (rip_sec(tn, start, nsec, type, dst_file, disc_type) != CMD_OK) {
				GUI_LabelSetText(self.track_label, " ");
				stoptimer = timer_ms_gettime64 (); // timer
				GUI_ProgressBarSetPosition(self.pbar, 0.0);
				cdrom_spin_down();
				if (disc_type == 1) {
					if(fs_unlink(dst_file) != 0) ds_printf("Error delete file: %s\n" ,dst_file);
				} else {
					if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
						ds_printf("Error folder '%s' not found\n" ,dst_folder); 
						return;
					}
					
					dirent_t *dir;
					while ((dir = fs_readdir(fd))){
						if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
						strcpy(dst_file,"\0");
						snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
						fs_unlink(dst_file);
					}
					fs_close(fd);
					fs_rmdir(dst_folder);
				}
				return ;
			}
			GUI_LabelSetText(self.track_label, " ");
			GUI_ProgressBarSetPosition(self.pbar, 0.0);
		}
	}
	GUI_LabelSetText(self.track_label, " ");
	GUI_WidgetMarkChanged(self.app->body);
	if (disc_type == 2){
		if (gdfiles(dst_folder, dst_file, text) != CMD_OK){
			cdrom_spin_down();
			if ((fd=fs_open (dst_folder , O_DIR)) == FILEHND_INVALID) {
				ds_printf("Error folder '%s' not found\n" ,dst_folder); 
				return;
			}
			
			dirent_t *dir;
			
			while ((dir = fs_readdir(fd))){
				if (!strcmp(dir->name,".") || !strcmp(dir->name,"..")) continue;
				strcpy(dst_file,"\0");
				snprintf(dst_file, MAX_FN_LEN, "%s/%s", dst_folder, dir->name);
				fs_unlink(dst_file);
			}
			fs_close(fd);
			fs_rmdir(dst_folder);
			return;	
		}
		
		
	}
	GUI_ProgressBarSetPosition(self.pbar, 0.0);
	cdrom_spin_down();
	stoptimer = timer_ms_gettime64 (); // timer
	riptime = stoptimer - starttimer;
	int ripmin = riptime / 60000 ;
	int ripsec = riptime % 60 ;
	ds_printf("DS_OK: End ripping. Save at %d:%d\n",ripmin,ripsec);
}