Пример #1
0
int write_device_alias(const char *src, const char *dst, const char *alias)
{
	char filename[PATH_MAX + 1];

	create_name(filename, PATH_MAX, STORAGEDIR, src, "aliases");

	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

	return textfile_put(filename, dst, alias);
}
Пример #2
0
int create_fd(const char *arg, int is_output, enum proto *proto, char *name, size_t max_name_size)
{
  if (strncmp(arg, "udp:", 4) == 0 || strncmp(arg, "UDP:", 4) == 0) {
    *proto = UDP;
    arg += 4;
  } else if (strncmp(arg, "tcp:", 4) == 0 || strncmp(arg, "TCP:", 4) == 0) {
    *proto = TCP;
    arg += 4;
  } else if (strncmp(arg, "file:", 5) == 0) {
    *proto = File;
    arg += 5;
  } else if (strncmp(arg, "eth:", 4) == 0) {
    *proto = Eth;
    arg += 4;
  } else if (strcmp(arg, "null:") == 0) {
    *proto = File;
    arg = "/dev/null";
  } else if (strcmp(arg, "zero:") == 0) {
    *proto = File;
    arg = "/dev/zero";
  } else if (strcmp(arg, "stdin:") == 0) {
    *proto = StdIn;
    arg = "stdin";
  } else if (strcmp(arg, "stdout:") == 0) {
    *proto = StdOut;
    arg = "stdout";
  } else if (strcmp(arg, "stderr:") == 0) {
    *proto = StdErr;
    arg = "stderr";
  } else if (strchr(arg, ':') != 0) {
    *proto = UDP;
  } else if (strcmp(arg, "-") == 0) {
    *proto = is_output ? StdOut : StdIn;
    arg = is_output ? "stdout" : "stdin";
  } else {
    *proto = File;
  }

  if (name != 0)
    strncpy(name, arg, max_name_size);

  switch (*proto) {
    case UDP	:
    case TCP	: return create_IP_socket(arg, is_output, *proto);

    case File	: return create_file(arg, is_output);

    case Eth	: return create_raw_eth_socket(arg, is_output);

    case StdIn	:
    case StdOut:
    case StdErr	: return create_stdio(is_output, *proto);
    default     : fprintf(stderr, "Cannot create fd for unknown proto %d\n", *proto), exit(1);
  }
}
Пример #3
0
int syscall_creat(const char *path, mode_t mode)
{
	int i, drive;
	int curdir_handle, new_handle;
	char name_comp[13], conv_name[11], dir_path[501];

	if (strlen(path) > 500) return ELONGPATH;

	parse_path(path, &drive, dir_path, name_comp);
	if (dir_path[0] != 0)
	{
		curdir_handle = open_path(drive, dir_path);

		if (curdir_handle < 0)
			return curdir_handle;	// Error
	}
	else
	{
		curdir_handle = get_curdir_handle(drive);
		increment_ref_count(curdir_handle);
	}

	// Last file name component.
	if (convert_name(name_comp, conv_name) < 0)
	{
		close_dir(curdir_handle);
		return EINVALIDNAME; // Error
	}

	mode = mode & 0x3f; // Valid bits
	if (mode == 0) mode = 0x20;
	else	mode = mode & (~(FTYPE_DIR | FTYPE_VOLUME));

	new_handle = create_file(curdir_handle, conv_name, mode);
	close_dir(curdir_handle);
	
        for (i=3; i<20; i++)
        {
                if (fileinf->fhandles[i] < 0)
                break;
        }
        if (i < 20)
        {
                fileinf->fhandles[i] = new_handle;
                new_handle = i;
        }
        else
        {
                close_file(new_handle);
                new_handle = ENO_FREE_FILE_TABLE_SLOT;
        }

	return new_handle; // may be failure or success
}
Пример #4
0
static int test_symlink(void)
{
	char buf[1024];
	const char *data = testdata;
	int datalen = testdatalen;
	int linklen = strlen(testfile);
	int err = 0;
	int res;

	start_test("symlink");
	res = create_file(testfile, data, datalen);
	if (res == -1)
		return -1;

	unlink(testfile2);
	res = symlink(testfile, testfile2);
	if (res == -1) {
		PERROR("symlink");
		return -1;
	}
	res = check_type(testfile2, S_IFLNK);
	if (res == -1)
		return -1;
	err += check_mode(testfile2, 0777);
	err += check_nlink(testfile2, 1);
	res = readlink(testfile2, buf, sizeof(buf));
	if (res == -1) {
		PERROR("readlink");
		err--;
	}
	if (res != linklen) {
		ERROR("short readlink: %u instead of %u", res, linklen);
		err--;
	}
	if (memcmp(buf, testfile, linklen) != 0) {
		ERROR("link mismatch");
		err--;
	}
	err += check_size(testfile2, datalen);
	err += check_data(testfile2, data, 0, datalen);
	res = unlink(testfile2);
	if (res == -1) {
		PERROR("unlink");
		return -1;
	}
	res = check_nonexist(testfile2);
	if (res == -1)
		return -1;
	if (err)
		return -1;

	success();
	return 0;
}
void save_fournisseur(char* filename, Fournisseur* fournisseur) {

    // Avant tout, tester si fournisseur n'est pas NULL
    if (!fournisseur) return;

    // Créer le fichier s'il n'existe pas
    if (!file_exist(filename)) create_file(filename);

    // Cherche si le médicament existe
    // Si oui, il suffit de modifier le médicament
    // Existant, Sinon on crée un nouveau médicament
    // Dans la base de donnée
    FILE* file = fopen(filename, "r+b");

    // Sortir si le fichier ne peux pas s'ouvrir
    if (!file) return;

    // Itérer
    do {

        Fournisseur* current_fournisseur = (Fournisseur*)malloc(sizeof(Fournisseur));
        if (!fread(current_fournisseur, sizeof(Fournisseur), 1, file)) break;

        // Si le médicament est trouvé
        if (current_fournisseur -> fournisseur_id == fournisseur -> fournisseur_id) {

            // Modifier le médicament
            long int currPost = ftell(file);
            fseek(file, currPost - sizeof(Fournisseur), SEEK_SET);
            fwrite(fournisseur, sizeof(Fournisseur), 1, file);

            // Sortir de la fonction
            fclose(file);
            return;
        }

    } while (1);

    // Trouver le dernier client ajouté
    Fournisseur* last_fournisseur = get_last_fournisseur(filename);

    // Set nouveau id
    int new_id = (last_fournisseur == NULL) ? 1 : last_fournisseur -> fournisseur_id + 1;

    // Set nouveau id
    fournisseur -> fournisseur_id = new_id;

    // Sauvegarder la commande
    fwrite(fournisseur, sizeof(Fournisseur), 1, file);

    // Fermer le fichier
    fclose(file);

}
Пример #6
0
ATF_TC_BODY(stat_mode, tc)
{
    atf_fs_path_t p;
    atf_fs_stat_t st;

    create_file("f1", 0400);
    create_file("f2", 0644);

    RE(atf_fs_path_init_fmt(&p, "f1"));
    RE(atf_fs_stat_init(&st, &p));
    ATF_CHECK_EQ(0400, atf_fs_stat_get_mode(&st));
    atf_fs_stat_fini(&st);
    atf_fs_path_fini(&p);

    RE(atf_fs_path_init_fmt(&p, "f2"));
    RE(atf_fs_stat_init(&st, &p));
    ATF_CHECK_EQ(0644, atf_fs_stat_get_mode(&st));
    atf_fs_stat_fini(&st);
    atf_fs_path_fini(&p);
}
Пример #7
0
void output_key(char filename[], unsigned char key[], int key_size) {
    // http://stackoverflow.com/a/8004250
    if (strcmp(filename, "-") != 0) {
        FILE *out = create_file(filename);
        fwrite(key, key_size, 1, out);
        fclose(out);
    } else {
        fwrite(bytes_to_hex(key, key_size), key_size * 2, 1, stdout);
        fputs("\n", stdout);
    }
}
/***************************************************************
 * setup() - performs all ONE TIME setup for this test.
 ***************************************************************/
void setup()
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	create_file();
}
Пример #9
0
int main(int ac,char *av[])
{
  int i=0;
  int j=0;
  int k=0;
  int l=0;
  char dir1[MAXN];
  char dir2[MAXN];
  char dir3[MAXN];
  char filename[MAXN];
  time_t t;
  int maxfiles=0xFFFFFF;
  int createfiles=0;

  if (ac > 1) {
    sscanf(av[1],"%x",&maxfiles);
    if (maxfiles==0) {
      printf("maxfile argument error (0 value)\n");
      exit(1);
    }
  }
  time(&t);
  srandom((unsigned int)getpid()^(((unsigned int)t<<16)| (unsigned int)t>>16));
  printf("Create files\n");
  for (i = 0 ; i < 0xFF ; i++) {
    sprintf(dir1,"%2.2x",i);
    makedir(dir1);
    changedir(dir1);
    for (j = 0 ; j < 0xFF ; j++) {
      sprintf(dir2,"%2.2x",j);
      makedir(dir2);
      changedir(dir2);
      for (k = 0 ; k < 0xFF ; k++) {
	sprintf(dir3,"%2.2x",k);
	makedir(dir3);
	changedir(dir3);
	for (l = 0 ; l < 0xFF ; l++) {
	  sprintf(filename,"%s%s%s%2.2x",dir1,dir2,dir3,l);
	  create_file(filename);
	  if (maxfiles < createfiles++) {
	    goto end;
	  }
	}
	changedir("../");
      }
      changedir("../");
    }
    changedir("../");
  }
end:
  fprintf(stderr,"\nTotal create files: %d\n",filecount);
  printf("Done\n");
        return 0;
}
Пример #10
0
void mess_up_inode_field(ocfs2_filesys *fs, enum fsck_type type, uint64_t blkno)
{
	errcode_t ret;
	uint64_t tmpblkno;
	uint32_t clusters = 10;

	char *buf = NULL;
	struct ocfs2_dinode *di;

	create_file(fs, blkno, &tmpblkno);

	if ((type == INODE_SPARSE_SIZE) || (type == INODE_SPARSE_CLUSTERS)) {

		if (!ocfs2_sparse_alloc(OCFS2_RAW_SB(fs->fs_super)))
			FSWRK_FATAL("should specfiy a sparse file supported "
				    "volume to do this corruption\n");

		ret = ocfs2_malloc_block(fs->fs_io, &buf);
		if (ret)
			FSWRK_COM_FATAL(progname, ret);

		ret = ocfs2_read_inode(fs, tmpblkno, buf);
		if (ret)
			FSWRK_COM_FATAL(progname, ret);

		di = (struct ocfs2_dinode *)buf;

		di->i_size = fs->fs_clustersize * 2;

		ret = ocfs2_write_inode(fs, tmpblkno, buf);
		if (ret)
			FSWRK_COM_FATAL(progname, ret);

		if (buf)
			ocfs2_free(&buf);
	}

	if ((type == INODE_CLUSTERS) || (type == INODE_SPARSE_CLUSTERS) ||
	    (type == INODE_SPARSE_SIZE)) {
		ret = ocfs2_extend_allocation(fs, tmpblkno, clusters);
		if (ret)
			FSWRK_COM_FATAL(progname, ret);
	}

	if (type == REFCOUNT_FLAG_INVALID &&
	    ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
		FSWRK_FATAL("should specfiy a norefcount volume\n");
	if (type == REFCOUNT_LOC_INVALID &&
	    !ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
		FSWRK_FATAL("Should specify a refcount supported volume\n");

	damage_inode(fs, tmpblkno, type);
	return;
}
Пример #11
0
int main(){

	num_small = (N_SMALL * MAX_SIZE) / SMALL;
	num_med = (N_MED * MAX_SIZE) / MED;
	num_large = (N_LARGE * MAX_SIZE) / LARGE;
	num_huge = (N_HUGE * MAX_SIZE) / HUGE;
	
	int i;

	FILE* nfile = fopen("./numbers.txt", "w");

	printf("creating %d small files\n", num_small);
	fprintf(nfile, "%f\t%d\n", N_SMALL, num_small);
	for(i = 0; i< num_small; i++){
		char path[256];
		sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/small/small%d", i);
		create_file(path, SMALL);
	}
	printf("creating %d med files\n", num_med);
	fprintf(nfile, "%f\t%d\n", N_MED, num_med);
	for(i = 0; i< num_med; i++){
		char path[256];
		sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/med/med%d", i);
		create_file(path, MED);
	}
	printf("creating %d large files\n", num_large);
	fprintf(nfile, "%f\t%d\n", N_LARGE, num_large);
	for(i = 0; i< num_large; i++){
		char path[256];
		sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/large/large%d", i);
		create_file(path, LARGE);
	}
	printf("creating %d huge files\n", num_huge);
	fprintf(nfile, "%f\t%d\n", N_HUGE, num_huge);
	for(i = 0; i< num_huge; i++){
		char path[256];
		sprintf(path, "/home/timstamler/harddrivecache/mnt/hd/huge/huge%d", i);
		create_file(path, HUGE);
	}
	fclose(nfile);
}
Пример #12
0
int fat_dev_create_file(fat_dev_t * pdev, const char * fname)
{
    assert(pdev && fname);
    pdev->fname = fname; // by gushui
    pdev->flag = O_CREAT|O_RDWR;// by gushui
    //fat_dev_init(pdev, fname, O_CREAT|O_RDWR); // by gushui
    if( 0 > create_file(pdev, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)){
        FAT_ERROR("create file failed! err:%s\n", strerror(errno));
        return -1;
    }
    return 0;
}
Пример #13
0
int main(int argc, char ** argv) {
	char * pwd = "."; /* TODO: Fetch the actual path */
	file_t * file = create_file(pwd, NEW_FILE);

	while(!file->term_status->quit_fl) {
		key_handle(file);
		render_all(file);
	}

	close_file(file);
	return 0;
}
Пример #14
0
static void refresh_relax_callback(NautilusMenuItem* item,
                                 gpointer user_data)
{
    g_print("now refreshing...");

    char* refresh_text = "refreshing...";
    int fd = create_file("/.relax-refresh");
    if(fd != -1)
        write(fd, refresh_text, strlen(refresh_text));

    close(fd);
}
Пример #15
0
int	footer()
{
  FILE		*file;
  char		*dt;

  file = create_file();
  dt = date_and_time();
  fwrite("\nScript done on ", 17, sizeof(char), file);
  fwrite(dt, strlen(dt), sizeof(char), file);
  fwrite("\n", 1, sizeof(char), file);
  return (0);
}
Пример #16
0
int	header()
{
  FILE		*file;
  char		*dt;
  
  file = create_file();
  dt = date_and_time();
  fwrite("\nScript started on ", 18, sizeof(char), file);
  fwrite(dt, strlen(dt), sizeof(char), file);
  fwrite("\n", 1, sizeof(char), file);
  return (0);
}
Пример #17
0
int write_discoverable_timeout(bdaddr_t *bdaddr, int timeout)
{
	char filename[PATH_MAX + 1], str[32];

	snprintf(str, sizeof(str), "%d", timeout);

	create_filename(filename, PATH_MAX, bdaddr, "config");

	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

	return textfile_put(filename, "discovto", str);
}
Пример #18
0
void file_mgr::write(const std::string& content)
{
    close();
    remove_file(file_path);
    create_file(file_path);
    open(file_path, open_mode.c_str());
    if (::fputs(content.c_str(), fp)<0)
    {
        perror("writing data failed");
        ::abort();
    }
}
Пример #19
0
static void
vfstest_mkdir(void)
{
        syscall_success(mkdir("mkdir", 0777));
        syscall_success(chdir("mkdir"));

        /* mkdir an existing file or directory */
        create_file("file");
        syscall_fail(mkdir("file", 0777), EEXIST);
        syscall_success(mkdir("dir", 0777));
        syscall_fail(mkdir("dir", 0777), EEXIST);

        /* mkdir an invalid path */
        syscall_fail(mkdir(LONGNAME, 0777), ENAMETOOLONG);
        syscall_fail(mkdir("file/dir", 0777), ENOTDIR);
        syscall_fail(mkdir("noent/dir", 0777), ENOENT);
        syscall_fail(rmdir("file/dir"), ENOTDIR);
        syscall_fail(rmdir("noent/dir"), ENOENT);
        syscall_fail(rmdir("noent"), ENOENT);
        syscall_fail(rmdir("."), EINVAL);
        syscall_fail(rmdir(".."), ENOTEMPTY);
        syscall_fail(rmdir("dir/."), EINVAL);
        syscall_fail(rmdir("dir/.."), ENOTEMPTY);
        syscall_fail(rmdir("noent/."), ENOENT);
        syscall_fail(rmdir("noent/.."), ENOENT);

        /* unlink and rmdir the inappropriate types */
        syscall_fail(rmdir("file"), ENOTDIR);
        syscall_fail(unlink("dir"), EISDIR);

        /* remove non-empty directory */
        create_file("dir/file");
        syscall_fail(rmdir("dir"), ENOTEMPTY);

        /* remove empty directory */
        syscall_success(unlink("dir/file"));
        syscall_success(rmdir("dir"));

        syscall_success(chdir(".."));
}
Пример #20
0
/**
 * open a file
 * @param filename is the name of the file to open
 * @param mode is MFS_MODE_READ or MFS_MODE_WRITE or MFS_MODE_CREATE
 * this function should be used for FILEs and not DIRs
 * no error checking (is this FILE and not DIR?) is done for MFS_MODE_READ
 * MFS_MODE_CREATE automatically creates a FILE and not a DIR
 * MFS_MODE_WRITE fails if the specified file is a DIR
 * @return index of file in array mfs_open_files or -1
 */
int mfs_file_open(const char *filename, int mode) {
  int dir_block;
  int dir_index;
  int current_index;
  int reuse_block = -1;
  int reuse_index = -1;
  //xil_printf("In mfs_file_open\r\n");

  if (mfs_num_open_files >= MFS_MAX_OPEN_FILES) {/* cannot open any more files */
    //xil_printf("case 1\r\n");
    return -1;
  }
  if (mode == MFS_MODE_READ || mode == MFS_MODE_WRITE) { /* look for existing file */
    if (get_dir_ent(filename, &dir_block, &dir_index, &reuse_block, &reuse_index)) { /* found it */
      if (mode == MFS_MODE_WRITE && mfs_file_system[mfs_file_system[dir_block].u.dir_data.dir_ent[dir_index].index].block_type != MFS_BLOCK_TYPE_FILE) {
	/* cannot open anything other than FILE for write */
	//xil_printf("case 2\r\n");
	return -1;
      }
      mfs_num_open_files++;
      current_index = get_first_free_ftab_index();
      mfs_open_files[current_index].first_block = mfs_file_system[dir_block].u.dir_data.dir_ent[dir_index].index;
      mfs_open_files[current_index].current_block = mfs_open_files[current_index].first_block;
      mfs_open_files[current_index].mode = mode;
      mfs_open_files[current_index].offset = 0;
      return current_index;
    }
    else {
       //file/dir not found, open it in create mode
       if (mode == MFS_MODE_WRITE)
          mode = MFS_MODE_CREATE;
    }
  }

  if (mode == MFS_MODE_CREATE) { /* create a new file */
     dir_block = create_file(filename, MFS_BLOCK_TYPE_FILE);
    if (dir_block == 0) { /* failed to create the file */
      //xil_printf("case 3\r\n");
      return -1;
    }
    mfs_num_open_files++;
    current_index = get_first_free_ftab_index();
    mfs_open_files[current_index].first_block = dir_block;
    mfs_open_files[current_index].current_block = dir_block;
    mfs_open_files[current_index].mode = MFS_MODE_WRITE;
    mfs_open_files[current_index].offset = 0;
    //xil_printf("case 4, current_index is %d\r\n",current_index);
    return current_index;
  }
  //xil_printf("case 5\r\n");
  return -1;
}
Пример #21
0
void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
{
    printf("##########Received response from remote device #############\n");
    if (CA_ADAPTER_IP == object->adapter)
    {
        printf("Remote Address: %s Port: %d secured:%d\n", object->addr,
               object->port, object->flags & CA_SECURE);
    }
    else
    {
        printf("Remote Address: %s \n", object->addr);
    }
    printf("response result : %d\n", responseInfo->result);
    printf("Data: %s\n", responseInfo->info.payload);
    printf("Message type: %s\n", MESSAGE_TYPE[responseInfo->info.type]);
    printf("Token: %s\n", responseInfo->info.token);
    printf("Resource URI: %s \n", responseInfo->info.resourceUri);

    if (responseInfo->info.options)
    {
        uint32_t len = responseInfo->info.numOptions;
        uint32_t i;
        for (i = 0; i < len; i++)
        {
            printf("Option %d\n", i + 1);
            printf("ID : %d\n", responseInfo->info.options[i].optionID);
            printf("Data[%d]: %s\n", responseInfo->info.options[i].optionLength,
                   responseInfo->info.options[i].optionData);
        }
    }
    printf("############################################################\n");
    g_received = 1;

    //Check if this has secure communication information
    if (responseInfo->info.payload)
    {
        int securePort = get_secure_information(responseInfo->info.payload);
        if (0 < securePort) //Set the remote endpoint secure details and send response
        {
            printf("This is secure resource...\n");
        }
    }

#ifdef WITH_BWT
    // if received message is bulk data, create output file
    if ((responseInfo->info.payload) &&
            (responseInfo->info.payloadSize > BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE)))
    {
        create_file(responseInfo->info.payload, responseInfo->info.payloadSize);
    }
#endif
}
Пример #22
0
static void fs_event_create_files_in_subdir(uv_timer_t* handle) {
  /* Make sure we're not attempting to create files we do not intend */
  ASSERT(fs_event_created < fs_event_file_count);

  /* Create the file */
  create_file(fs_event_get_filename_in_subdir(fs_event_created));

  if (++fs_event_created < fs_event_file_count) {
    /* Create another file on a different event loop tick.  We do it this way
     * to avoid fs events coalescing into one fs event. */
    ASSERT(0 == uv_timer_start(&timer, fs_event_create_files_in_subdir, 1, 0));
  }
}
Пример #23
0
int ploop_global_lock(void)
{
	if (access(PLOOP_GLOBAL_LOCK_FILE, F_OK)) {
		if (access(PLOOP_LOCK_DIR, F_OK) &&
				mkdir(PLOOP_LOCK_DIR, 0700) && errno != EEXIST) {
			ploop_err(errno, "Failed to create " PLOOP_LOCK_DIR);
			return -1;
		}
		if (create_file(PLOOP_GLOBAL_LOCK_FILE))
			return -1;
	}
	return do_lock(PLOOP_GLOBAL_LOCK_FILE, 0);
}
Пример #24
0
int write_device_mode(bdaddr_t *bdaddr, const char *mode)
{
	char filename[PATH_MAX + 1];

	create_filename(filename, PATH_MAX, bdaddr, "config");

	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

	if (strcmp(mode, "off") != 0)
		textfile_put(filename, "onmode", mode);

	return textfile_put(filename, "mode", mode);
}
Пример #25
0
static void
vfstest_getdents(void)
{
        int fd, ret;
        dirent_t dirents[4];

        syscall_success(mkdir("getdents", 0));
        syscall_success(chdir("getdents"));

        /* getdents works */
        syscall_success(mkdir("dir01", 0));
        syscall_success(mkdir("dir01/1", 0));
        create_file("dir01/2");

        syscall_success(fd = open("dir01", O_RDONLY, 0));
        syscall_success(ret = getdents(fd, dirents, 4 * sizeof(dirent_t)));
        test_assert(4 * sizeof(dirent_t) == ret, NULL);

        syscall_success(ret = getdents(fd, dirents, sizeof(dirent_t)));
        test_assert(0 == ret, NULL);

        syscall_success(lseek(fd, 0, SEEK_SET));
        test_fpos(fd, 0);
        syscall_success(ret = getdents(fd, dirents, 2 * sizeof(dirent_t)));
        test_assert(2 * sizeof(dirent_t) == ret, NULL);
        syscall_success(ret = getdents(fd, dirents, 2 * sizeof(dirent_t)));
        test_assert(2 * sizeof(dirent_t) == ret, NULL);
        syscall_success(ret = getdents(fd, dirents, sizeof(dirent_t)));
        test_assert(0 == ret, NULL);
        syscall_success(close(fd));

        /* Cannot call getdents on regular file */
        create_file("file01");
        syscall_success(fd = open("file01", O_RDONLY, 0));
        syscall_fail(getdents(fd, dirents, 4 * sizeof(dirent_t)), ENOTDIR);
        syscall_success(close(fd));

        syscall_success(chdir(".."));
}
Пример #26
0
int main(int argc,char *argv[]){ 
    int i; 
    if(argc<2){ 
        perror("you haven't input the filename,please try again!\n"); 
        exit(EXIT_FAILURE); 
    } 

    for(i=1;i<argc;i++){ 
        create_file(argv[i]);    
    } 

    exit(EXIT_SUCCESS); 
}
Пример #27
0
static void test_D3DXGetImageInfo(void)
{
    HRESULT hr;
    D3DXIMAGE_INFO info;
    BOOL testdummy_ok, testbitmap_ok;

    hr = create_file("testdummy.bmp", noimage, sizeof(noimage));  /* invalid image */
    testdummy_ok = SUCCEEDED(hr);

    hr = create_file("testbitmap.bmp", bmp01, sizeof(bmp01));  /* valid image */
    testbitmap_ok = SUCCEEDED(hr);

    /* D3DXGetImageInfoFromFile */
    if(testbitmap_ok) {
        todo_wine {
            hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
            ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
        }

        hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
        ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
    } else skip("Couldn't create \"testbitmap.bmp\"\n");
Пример #28
0
/* Sleep long enough to notice a timestamp difference on the file
   system in the current directory.  */
static void
nap (void)
{
  static long delay;
  if (!delay)
    {
      /* Initialize only once, by sleeping for 20 milliseconds (needed
         since xfs has a quantization of about 10 milliseconds, even
         though it has a granularity of 1 nanosecond, and since NTFS
         has a default quantization of 15.25 milliseconds, even though
         it has a granularity of 100 nanoseconds).  If the seconds
         differ, repeat the test one more time (in case we crossed a
         quantization boundary on a file system with 1 second
         resolution).  If we can't observe a difference in only the
         nanoseconds, then fall back to 1 second if the time is odd,
         and 2 seconds (needed for FAT) if time is even.  */
      struct stat st1;
      struct stat st2;
      ASSERT (stat ("t-stt-stamp1", &st1) == 0);
      ASSERT (force_unlink ("t-stt-stamp1") == 0);
      delay = 20000;
      usleep (delay);
      create_file ("t-stt-stamp1");
      ASSERT (stat ("t-stt-stamp1", &st2) == 0);
      if (st1.st_mtime != st2.st_mtime)
        {
          /* Seconds differ, give it one more shot.  */
          st1 = st2;
          ASSERT (force_unlink ("t-stt-stamp1") == 0);
          usleep (delay);
          create_file ("t-stt-stamp1");
          ASSERT (stat ("t-stt-stamp1", &st2) == 0);
        }
      if (! (st1.st_mtime == st2.st_mtime
             && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
    }
  usleep (delay);
}
Пример #29
0
int
main (void)
{	const char * fname = "test.wav" ;

	puts ("\nSimple example showing usage of the C++ SndfileHandle object.\n") ;

	create_file (fname, SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;

	read_file (fname) ;

	puts ("Done.\n") ;
	return 0 ;
} /* main */
Пример #30
0
Файл: qib_fs.c Проект: 01org/qib
static int add_cntr_files(struct super_block *sb, struct qib_devdata *dd)
{
	struct dentry *dir, *tmp;
	char unit[10];
	int ret, i;

	/* create the per-unit directory */
	snprintf(unit, sizeof unit, "%u", dd->unit);
	ret = create_file(unit, S_IFDIR|S_IRUGO|S_IXUGO, sb->s_root, &dir,
			  &simple_dir_operations, dd);
	if (ret) {
		printk(KERN_ERR "create_file(%s) failed: %d\n", unit, ret);
		goto bail;
	}

	/* create the files in the new directory */
	ret = create_file("counters", S_IFREG|S_IRUGO, dir, &tmp,
			  &cntr_ops[0], dd);
	if (ret) {
		printk(KERN_ERR "create_file(%s/counters) failed: %d\n",
		       unit, ret);
		goto bail;
	}
	ret = create_file("counter_names", S_IFREG|S_IRUGO, dir, &tmp,
			  &cntr_ops[1], dd);
	if (ret) {
		printk(KERN_ERR "create_file(%s/counter_names) failed: %d\n",
		       unit, ret);
		goto bail;
	}
	ret = create_file("portcounter_names", S_IFREG|S_IRUGO, dir, &tmp,
			  &portcntr_ops[0], dd);
	if (ret) {
		printk(KERN_ERR "create_file(%s/%s) failed: %d\n",
		       unit, "portcounter_names", ret);
		goto bail;
	}
	for (i = 1; i <= dd->num_pports; i++) {
		char portcntr[24];

		sprintf(portcntr, "port%dcounters", i);
		/* create the files in the new directory */
		ret = create_file(portcntr, S_IFREG|S_IRUGO, dir, &tmp,
				  &portcntr_ops[i], dd);
		if (ret) {
			printk(KERN_ERR "create_file(%s/%s) failed: %d\n",
				unit, portcntr, ret);
			goto bail;
		}
	}

	ret = create_file("flash", S_IFREG|S_IWUSR|S_IRUGO, dir, &tmp,
			  &flash_ops, dd);
	if (ret)
		printk(KERN_ERR "create_file(%s/flash) failed: %d\n",
			unit, ret);
bail:
	return ret;
}