Example #1
0
static int chips_getattr(const char *path, struct stat *stbuf)
{
	memset(stbuf, 0, sizeof(struct stat));

	int fd = do_open((char *)path);

	if(fd < 0)
		return -ENOENT;

	potatoes_file_info_t info;
	get_file_info(fd, &info);

	if(info.mode == POTATOES_DIRECTORY)
	{
		stbuf->st_mode = S_IFDIR | 0777;
		stbuf->st_nlink = 2;
	}
	else
	{
		stbuf->st_mode = S_IFREG | 0666;
		stbuf->st_nlink = 1;
		stbuf->st_size = info.size;
	}

	do_close(fd);

	return 0;
}
void ana_dir(const char *name, const u_int8_t option) {
    DIR *dp; // 文件夹指针
    struct dirent *dirp; // 文件结构
    
    // 打开文件夹
    if ((dp = opendir(name)) == NULL) {
        fprintf(stderr, "ls: %s: %s.\n", name, strerror(errno));
        return;
    }
    
    // 遍历文件夹
    while ((dirp = readdir(dp)) != NULL) {
        if (dirp->d_name[0] == '.') {
            // 排除隐藏文件
            continue;
        }
        
        if (option) {
            get_file_info(name, dirp->d_name);
            printf("\n");
        } else {
            get_file(name, dirp->d_name);
        }
    }
    if (!option) {
        printf("\n");
    }
    
    // 关闭文件夹
    closedir(dp);
}
Example #3
0
vfs::vfs_status vfs::delete_file( unsigned char* path ) {
	vfs_node* node;
	vfs_status stat;

	if( (stat = get_file_info( path, &node )) != vfs_status::ok ) {
		return stat;
	}

	if( node->type != vfs_node_types::file ) {
		return vfs_status::incorrect_type;
	}

	node->fs->delete_file( (vfs_file*)node );

	if( node->parent->type != vfs_node_types::directory ) {
		return vfs_status::incorrect_type;
	}
	vfs_directory *parent = (vfs_directory*)node->parent;
	for(unsigned int i=0;i<parent->files.count();i++) {
		if( parent->files[i] == node ) {
			parent->files.remove(i);
			break;
		}
	}

	return vfs_status::ok;
}
Example #4
0
static int chips_rm(int argc, char **argv)
{
	if(argc != 2)
	{
		fprintf(stderr, "Usage: %s <path>\n", argv[0]);
		return -1;
	}
	int fd = do_open(argv[1]);
	if(fd < 0)
	{
		fprintf(stderr, "Failed to open %s\n", argv[1]);
		return 1;
	}

	potatoes_file_info_t info;
	get_file_info(fd, &info);
	do_close(fd);

	if(info.mode != POTATOES_DATA_FILE)
	{
		fprintf(stderr, "Not a file: %s\n", argv[1]);
		return 1;
	}

	if(!fs_delete(argv[1]))
	{
		fprintf(stderr, "Failed to delete %s\n", argv[1]);
		return 1;
	}
	return 0;
}
Example #5
0
int get_info(char **str, char *name, int how)
{
    int   res = OK;
    char *str_info = NULL;
    char  temp[SIZE];
    str_info = (char *)malloc(MAX);
    if (NULL == str_info) {
        printf("内存不足!");
        exit(NG);
    }/*end if*/

    memset(str_info, 0x0, MAX);

    *str = str_info;

    if (IS_DIR & how || NULL == name) {
        if (NULL == name) {
            memset(temp, 0x0, SIZE);
            sprintf(temp, "%s", LOCAL);
            name = temp;
        }
        res = get_dir_info(name, how);
        printf("\n");
    }else {
        res = get_file_info(&str_info, name, how);
    }/*end else*/

    return res;
}
Example #6
0
static uint32 smbvfs_wrap_write(PFILE_HND file_hnd, char *data, SMB_OFF_T offset, uint16 numtowrite, uint16 writethrough, uint16 *nwritten)
{
	files_struct *fsp = NULL;
	ssize_t nwrite;

	if (!get_file_info(file_hnd, &fsp))
		return NT_STATUS_INVALID_HANDLE;

	if (fsp == NULL)
		return NT_STATUS_NO_SUCH_FILE;

	DEBUG(12,("file name: [%s]\n", smbstrA(fsp->fsp_name)));

	nwrite = write_file(fsp, data, offset, numtowrite);

	DEBUG( 3, ( "SMBwriteX offset=%d nwritten=%d\n",
	                     (int)offset, nwrite ) );

	if (nwrite < 0)
	{
		*nwritten = 0;
		return NT_STATUS_ACCESS_DENIED;
	}

	*nwritten = nwrite;

	if (writethrough != 0)
		sync_file(fsp->conn, fsp);

	return NT_STATUS_NOPROBLEMO;
}
Example #7
0
bool vfs::file_exists( unsigned char* path ) {
	vfs_node* node;
	vfs_status stat = get_file_info(path, &node);
	if( stat != vfs_status::ok ) // includes vfs_status::not_found
		return false;
	return true;
}
Example #8
0
static int chips_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
	int fd = do_open((char *)path);
	if(fd < 0)
		return -ENOENT;

	potatoes_file_info_t info;
	get_file_info(fd, &info);

	if(info.mode != POTATOES_DIRECTORY)
		return -ENOENT;

	potatoes_dir_entry dir[POTATOES_DIR_ENTRIES_PER_BLOCK];
	int count, pos = 0;
	int i;
	while((count = do_read(fd, dir, sizeof(dir), pos)) != 0)
	{
		for(i = 0; i < count/sizeof(dir[0]) && dir[i].inode != 0; ++i)
		{
			printf("%s\n", dir[i].name);
			filler(buf, dir[i].name, NULL, 0);
		}
		pos += count;
	}

	do_close(fd);

	return 0;
}
Example #9
0
unsigned gbIso9660 :: get_file_size(const char * path)
{
	tree_entry * file = get_file_info(path);
	if(file)
		return file->size;

	return 0;
};
Example #10
0
unsigned gbIso9660 :: get_file_location(const char * path)
{
	tree_entry * file = get_file_info(path);
	if(file)
		return file->location * SECTOR_SIZE;

	return 0;
};
Example #11
0
vfs::vfs_status vfs::write_file(unsigned char* path, void* buffer, size_t size) {
	vfs_status stat;

	vfs_node *node;
	stat = get_file_info( path, &node );

	if( !((buffer == NULL) || (size == 0)) ) {
		if( stat == vfs_status::not_found ) {
			// file does not exist, create it
			vfs_directory *parent;

			if( (stat = get_path_parent( path, &parent )) != vfs_status::ok ) {
				return stat;
			}

			node = parent->fs->create_file( get_filename(path), parent );
			parent->files.add_end( node );

			stat = vfs_status::ok;
		}

		if( stat == vfs_status::ok ) {
			if( node->type == vfs_node_types::file ) {
				node->fs->write_file((vfs_file*)node, buffer, size);
				vfs_file* fn = (vfs_file*)node;
				fn->size = size;

				return vfs_status::ok;
			} else {
				return vfs_status::incorrect_type;
			}
		}

		return stat;
	} else { // just create the file, nothing more
		if( stat == vfs_status::not_found ) {
			vfs_directory *parent;

			if( (stat = get_path_parent( path, &parent )) != vfs_status::ok ) {
				return stat;
			}

			node = parent->fs->create_file( get_filename(path), parent );
			parent->files.add_end( node );

			return vfs_status::ok;
		} else if( stat == vfs_status::ok ) {
			return vfs_status::already_exists;
		} else {
			return stat;
		}
	}

	return vfs_status::unknown_error;
}
Example #12
0
int gbIso9660 :: extract_file(const char * file_name, const char * extract_path)
{
	tree_entry * te = get_file_info(file_name);

	//Check for the file data on the tree
	if(!te)
		return ERROR_NOT_FOUND;

	//Create the output file
	return copy_bytes(te->location * SECTOR_SIZE, te->size, extract_path);
};
Example #13
0
bool
tr_sys_path_get_info (const char        * path,
                      int                 flags,
                      tr_sys_path_info  * info,
                      tr_error         ** error)
{
  bool ret = false;
  wchar_t * wide_path;

  assert (path != NULL);
  assert (info != NULL);

  wide_path = tr_win32_utf8_to_native (path, -1);

  if ((flags & TR_SYS_PATH_NO_FOLLOW) == 0)
    {
      HANDLE handle = INVALID_HANDLE_VALUE;

      if (wide_path != NULL)
        handle = CreateFileW (wide_path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

      if (handle != INVALID_HANDLE_VALUE)
        {
          tr_error * my_error = NULL;
          ret = get_file_info (handle, info, &my_error);
          if (!ret)
            tr_error_propagate (error, &my_error);
          CloseHandle (handle);
        }
      else
        {
          set_system_error (error, GetLastError ());
        }
    }
  else
    {
      WIN32_FILE_ATTRIBUTE_DATA attributes;

      if (wide_path != NULL)
        ret = GetFileAttributesExW (wide_path, GetFileExInfoStandard, &attributes);

      if (ret)
        stat_to_sys_path_info (attributes.dwFileAttributes, attributes.nFileSizeLow,
                               attributes.nFileSizeHigh, &attributes.ftLastWriteTime,
                               info);
      else
        set_system_error (error, GetLastError ());
    }

  tr_free (wide_path);

  return ret;
}
Example #14
0
void docking_execute(struct dock_pak *dock, struct task_pak *task)
{
gchar *path, *cmd, *base, *input, *output;
GSList *list, *dir_list;
struct file_pak *file;

path = dock->path;

/*
printf("expected files: %d\n", dock->n);
*/

/* NB: have to change to the project directory in order to run GULP jobs in it */
/* TODO - save sysenv.cwd and restore after? */
if (chdir(path))
  {
  printf("Failed to change to project directory.\n");
  return;
  }

/* submit all GULP jobs in the project directory */
dir_list = file_dir_list(path, 0);
task->progress = 0.0;
for (list=dir_list ; list ; list=g_slist_next(list))
  {
  file = get_file_info(list->data, BY_EXTENSION);
  if (file)
    {
    if (file->id == GULP)
      {
      input = list->data;
      base = parse_strip(input);
      output = g_strconcat(base, ".got", NULL);

/* this doesn't work - why? */
/*
if (exec_gulp(input, output))
  printf(" >>> exec failed!!!\n");
*/

/* run the GULP jobs (NOT in bg as we're already a task) */
      cmd = g_strdup_printf("%s < %s > %s", sysenv.gulp_path, input, output);
      system(cmd);

      g_free(cmd);
      g_free(base);
      g_free(output);
      }
    }
  }
g_slist_free(dir_list);
}
Example #15
0
static uint32 smbvfs_wrap_read(PFILE_HND file_hnd, char *data, SMB_OFF_T offset, uint16 maxcnt, ssize_t *nread)
{
	files_struct *fsp = NULL;

	if (!get_file_info(file_hnd, &fsp))
		return NT_STATUS_INVALID_HANDLE;

	if (fsp == NULL)
		return NT_STATUS_NO_SUCH_FILE;

	*nread = read_file(fsp, data, offset, maxcnt);
  
	return NT_STATUS_NOPROBLEMO;
}
Example #16
0
int chips_unlink(const char *path)
{
	int fd = do_open((char *)path);
	if(fd < 0)
		return -ENOENT;

	potatoes_file_info_t info;
	get_file_info(fd, &info);

	if(info.mode != POTATOES_DATA_FILE)
		return -EPERM;
	do_close(fd);

	return fs_delete((char *)path) ? 0 : -1;
}
Example #17
0
void type_change(GtkWidget *w)
{
G_CONST_RETURN gchar *tmp;
struct file_pak *file_data;

tmp = gtk_entry_get_text(GTK_ENTRY(w));

/* update if valid type */
file_data = get_file_info((gpointer *) tmp, BY_LABEL);
if (file_data)
  {
  sysenv.file_type = file_data->id;
  update_file_pane();
  }
}
Example #18
0
vfs::vfs_status vfs::read_file( unsigned char* path, void* buffer ) {
	vfs_node* node;
	vfs_status stat;

	if( (stat = get_file_info( path, &node )) != vfs_status::ok ) {
		return stat;
	}

	if( node->type != vfs_node_types::file ) {
		return vfs_status::incorrect_type;
	}

	node->fs->read_file((vfs_file*)node, buffer);

	return vfs_status::ok;
}
Example #19
0
vfs::vfs_status vfs::copy_file( unsigned char* to, unsigned char* from ) {
	vfs_node* from_node;
	vfs_status stat;

	if( (stat = get_file_info( from, &from_node )) != vfs_status::ok ) {
		return stat;
	}

	if( from_node->type != vfs_node_types::file ) {
		return vfs_status::incorrect_type;
	}

	vfs_file* src = (vfs_file*)from_node;
	void* tmp = kmalloc(src->size);
	from_node->fs->read_file(src, tmp);

	return write_file( to, tmp, src->size );

	/*

	if( (stat = get_path_parent( to, &to_node )) != vfs_status::ok ) {
		return stat;
	}

	if( to_node->type != vfs_node_types::directory ) {
		return vfs_status::incorrect_type;
	}

	if( to_node->fs == from_node->fs ) {
		vfs_file* new_file = to_node->fs->copy_file( (vfs_file*)from_node, (vfs_directory*)to_node );
		vfs_directory* to_parent = (vfs_directory*)to_node;
		to_parent->files.add_end((vfs_node*)new_file);
		return vfs_status::ok;
	} else {
		vfs_file* src = (vfs_file*)from_node;
		void* tmp = kmalloc(src->size);
		from_node->fs->read_file(src, tmp);

		vfs_directory *dst = (vfs_directory*)to_node;
		return write_file( to, tmp, src->size );
	}

	*/

	return vfs_status::ok;
}
Example #20
0
/*****************************************************************************
 Perform rtkgps list command.
 *****************************************************************************/
void cmd_list(cmdlnopts_t *cmdopt) {
  int fd;
  status_t status;
  logfile_t *lgflp;
  /*unsigned int mem = 0;*/
  int n;

  fd = coms_open(cmdopt);

  if (cmdopt->vflg)
    printf("Requesting logger status information\n");

  status_read(fd, &status, cmdopt);

  gpsmouse_disable(fd, status.gpsms, cmdopt);

  if ((lgflp = malloc(status.nfile*sizeof(logfile_t))) == NULL) {
    fprintf(stderr,"rtkgps: Error allocating memory\n");
    gpsmouse_enable(fd, status.gpsms, cmdopt);
    coms_close(fd, cmdopt);
    exit(2);
  }

  for (n = 0; n < status.nfile; n++) {
    if (cmdopt->vflg) {
      printf("Requesting metadata for file %4d\n", n);
    }
    if (get_file_info(fd, n, lgflp+n) < 0) {
      fprintf(stderr,"rtkgps: Error reading information for file %d [%s]\n",
	      n, gcstrerror(rcerrno));
      free(lgflp);
      gpsmouse_enable(fd, status.gpsms, cmdopt);
      coms_close(fd, cmdopt);
      exit(5);
    }
  }

  printf("File num   Date      Fix type  Num fix  Mem ptr\n");
  for (n = 0; n < status.nfile; n++)
    printf("%8d   %8s  %8hd  %7d  %7d\n", n, lgflp[n].date, lgflp[n].fxtyp,
	   lgflp[n].nfix, lgflp[n].memp);

  free(lgflp);
  gpsmouse_enable(fd, status.gpsms, cmdopt);
  coms_close(fd, cmdopt);
}
Example #21
0
void docking_cleanup(struct dock_pak *dock, struct task_pak *task)
{
gchar *path, *ext;
GSList *list, *dir_list;
struct file_pak *file;
struct model_pak model;

/* temporary model data storage */
model_init(&model);

/* load gulp file energies into project */
/* TODO - scan for .res files */
/* TODO - if none - scan .got file for possible error reports */
path = dock->path;

/* scan project directory for .res files */
dir_list = file_dir_list(path, 0);
for (list=dir_list ; list ; list=g_slist_next(list))
  {
  file = get_file_info(list->data, BY_EXTENSION);
  if (file)
    {
    if (file->id == GULP)
      {
      ext  = find_char(list->data, '.', LAST);
      if (g_ascii_strncasecmp(ext, ".res", 3) == 0)
        {
/* process dump file */
        printf("%s\n", (gchar *) list->data);
        }
      }
    if (file->id == GULPOUT)
      {
/* process output file */

read_gulp_output(list->data, &model);

      printf("%s : %f\n", (gchar *) list->data, model.gulp.energy);
      }
    }
  }
/* cleanup */
g_slist_free(dir_list);
model_free(&model);
}
Example #22
0
static struct dir_entry *
vstafs_readdir (long sector)
{
  get_file_info (sector);
  if (FILE_INFO->type != 2)
    {
      errnum = ERR_FILE_NOT_FOUND;
      return 0;
    }
  
  a = FILE_INFO->blocks;
  curr_ext = 0;
  devread (a[curr_ext].a_start, 0, 512, (char *) DIRECTORY_BUF);
  current_direntry = 11;
  current_blockpos = 0;
  
  return &DIRECTORY_BUF[10];
}
Example #23
0
/**
 * Get and send the info for the current directory
 */
bool write_list(int sock, int client_sock, const char *current_dir) {
	
	if(client_sock>0) {
		if(sock!=client_sock) {
			send_repl(sock,REPL_150);
		}
	}
	else {
		if(sock!=client_sock) {
			send_repl(sock,REPL_425);
		}
		return FALSE;
	}
	DIR *dir = ensure_dir_exists(sock,current_dir);
	if(dir==NULL) {
		if(sock!=client_sock) {
			close(client_sock);
			send_repl(sock,REPL_451);
		}
		return FALSE;
	}
	
	char line[300];
	while(1) {
		struct dirent *d_next = readdir(dir);
		if(d_next==NULL)
			break;
		line[0]='\0';
		if(get_file_info(d_next->d_name,line)) {
			if(send_repl_client(client_sock,line)) {
				if(sock!=client_sock)
					send_repl(sock,REPL_451);
			}
		}
	}
	if(sock!=client_sock) {
		close(client_sock);
		send_repl(sock,REPL_226);
		//free(line);
	}
	//free(line);
	closedir(dir);
	return TRUE;
}
Example #24
0
int		cmd_get(void *info, t_msg *msg)
{
  t_handle	*handle;
  char		path[PATH_SIZE];
  int		size;

  handle = (t_handle*)info;
  memset(path, 0, PATH_SIZE);
  add_log("Client %d execute command get %s\n", 0, handle->cli_num, msg->arg);
  strcat(path, handle->path);
  strcat(path, "/");
  strcat(path, msg->arg);
  if (get_file_info(handle, &size, path) < 0)
    if (write(handle->cli_fd, "0", 1) < 0)
      return (_error("Can't write on client %d: %m\n", -1, handle->cli_num));
  if (receive_file(handle, path, size, msg) < 0)
    return (IWARNING);
  return (ISUCCESS);
}
Example #25
0
static int chips_open(const char *path, struct fuse_file_info *fi)
{
	int fd = do_open((char *)path);

	if(fd < 0)
		return -ENOENT;

	potatoes_file_info_t info;
	get_file_info(fd, &info);

	if(info.mode != POTATOES_DATA_FILE)
	{
		do_close(fd);
		return -ENOENT;
	}

	do_close(fd);
	return 0;
}
Example #26
0
static int chips_append(int argc, char **argv)
{
	if(argc != 2)
	{
		fprintf(stderr, "Usage: %s <file>\n", argv[0]);
		return -1;
	}
	int fd = do_open(argv[1]);
	if(fd < 0)
	{
		if(!fs_create(argv[1], POTATOES_DATA_FILE))	
		{
			fprintf(stderr, "Failed to create %s\n", argv[1]);
			return 1;
		}
		if((fd = do_open(argv[1])) < 0)
		{
			fprintf(stderr, "Failed to open %s\n", argv[1]);
			return 1;
		}
	}

	potatoes_file_info_t info;
	get_file_info(fd, &info);

	if(info.mode != POTATOES_DATA_FILE)
	{
		fprintf(stderr, "Not a file: %s\n", argv[1]);
		return 1;
	}

	char buf[512];
	int count;
	int off = info.size;
	while((count = read(0, buf, 512)) > 0)
	{
		do_write(fd, buf, count, off);
		off += count;
	}
	return 0;
}
Example #27
0
static struct dir_entry *
vstafs_readdir (long sector)
{
  /*
   * Get some information from the current directory
   */
  get_file_info (sector);
  if (FILE_INFO->type != 2)
    {
      *perrnum = ERR_FILE_NOT_FOUND;
      return 0;
    }

  a = (struct alloc *)FILE_INFO->blocks;
  curr_ext = 0;
  (*pdevread) (a[curr_ext].a_start, 0, 512, (char *) DIRECTORY_BUF);
  current_direntry = 11;
  current_blockpos = 0;

  return &DIRECTORY_BUF[10];
}
Example #28
0
static int chips_cat(int argc, char **argv)
{
	if(argc < 2)
	{
		fprintf(stderr, "Usage: %s <file> [more files ...]\n", argv[0]);
		return -1;
	}
	int i;
	for(i = 1; i < argc; ++i)
	{
		int fd = do_open(argv[i]);
		if(fd < 0)
		{
			fprintf(stderr, "Failed to open %s\n", argv[i]);
			return 1;
		}

		potatoes_file_info_t info;
		get_file_info(fd, &info);

		if(info.mode != POTATOES_DATA_FILE)
		{
			fprintf(stderr, "Not a file: %s\n", argv[i]);
			return 1;
		}

		char buf[512];
		int count;
		int off = 0;
		while((count = do_read(fd, buf, 512, off)) > 0)
		{
			off += count;
			write(1, buf, count);
		}
	}
	return 0;
}
Example #29
0
void
vnr_properties_dialog_update(VnrPropertiesDialog *dialog)
{
    const gchar *filetype = NULL;
    goffset filesize = 0;
    gchar *filetype_desc = NULL;
    gchar *filesize_str = NULL;

    get_file_info ((gchar*)VNR_FILE(dialog->vnr_win->file_list->data)->path,
                   &filesize, &filetype);

    if(filetype == NULL && filesize == 0)
    {
        vnr_properties_dialog_clear(dialog);
        return;
    }

    vnr_properties_dialog_update_image(dialog);
    vnr_properties_dialog_update_metadata(dialog);

    filesize_str = g_format_size (filesize);

    filetype_desc = g_content_type_get_description (filetype);

    gtk_label_set_text(GTK_LABEL(dialog->name_label),
                       (gchar*)VNR_FILE(dialog->vnr_win->file_list->data)->display_name);

    gtk_label_set_text(GTK_LABEL(dialog->location_label),
                       (gchar*)VNR_FILE(dialog->vnr_win->file_list->data)->path);

    gtk_label_set_text(GTK_LABEL(dialog->type_label), filetype_desc);
    gtk_label_set_text(GTK_LABEL(dialog->size_label), filesize_str);

    g_free(filesize_str);
    g_free((gchar*)filetype);
    g_free(filetype_desc);
}
int main(int argc, char** argv) {
    int fd, part_size, file_id;
	int k = 5;
	struct file_info* file_info;
	printf("%10d\n", k);


    sleep(2);

    if(argc!=4) {
		usage(argv[0]);
		return EXIT_FAILURE;
	}

    if(sethandler(SIG_IGN,SIGPIPE)) ERR("Seting SIGPIPE:");
    if(sethandler(sigint_handler,SIGINT)) ERR("Seting SIGINT:");

    fd = connect_socket(argv[1], atoi(argv[2]));

	send_message(fd, "UPL", "");

    part_size = wait_for_system_readiness(fd);

	file_info = get_file_info(fd, argv[3], part_size);

	if(( file_id = send_file_info(fd, argv[3], part_size, file_info)) < 0) ERR("write");

	file_info -> file_id = file_id;
	printf("File ID: %d\n\n\n\\n\n\n\n\n\n\n\\n\n\n\n\n\n\\n\n\n\n\n", file_info -> file_id);
	send_file(fd, argv[3], file_info, part_size);
	printf("File ID: %d\n\n\n\\n\n\n\n\n\n\n\\n\n\n\n\n\n\\n\n\n\n\n", file_info -> file_id);

	if(TEMP_FAILURE_RETRY(close(fd))<0) ERR("close");

	free(file_info);
    return 0;
}