Ejemplo n.º 1
0
/*
 * Get file attributes.
 *
 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are ignored. The
 * 'st_ino' field is ignored except if the 'use_ino' mount option is given.
 */
int tagfs_getattr(const char *path, struct stat *statbuf) {
	char *file_location = NULL;
	int file_id = 0;
	int retstat = 0;

	DEBUG(ENTRY);
	INFO("Retrieving attributes for %s", path);

	if (valid_path_to_file(path)) {
		file_id = file_id_from_path(path);
		file_location = get_file_location(file_id);

		/* read information from actual file */
		retstat = stat(file_location, statbuf);

		if(retstat < 0) {
			WARN("Reading information from file %s failed", file_location);
			delete_file(file_id);
		}

		free_single_ptr((void **)&file_location);
	}
	else if(valid_path_to_folder(path)) {
		statbuf->st_mode = S_IFDIR | 0755; /* TODO: Set hard links, etc. */
	}
	else {
		retstat = -ENOENT;
	}

	DEBUG(EXIT);
	return retstat;
} /* tagfs_getattr */
Ejemplo n.º 2
0
/*
 * File open operation
 *
 * No creation (O_CREAT, O_EXCL) and by default also no truncation (O_TRUNC)
 * flags will be passed to open(). If an application specifies O_TRUNC,
 * fuse first calls truncate() and then open(). Only if 'atomic_o_trunc' has
 * been specified and kernel version is 2.6.24 or later, O_TRUNC is passed on
 * to open.
 *
 * Unless the 'default_permissions' mount option is given, open should check if
 * the operation is permitted for the given flags. Optionally open may also
 * return an arbitrary filehandle in the fuse_file_info structure, which will
 * be passed to all file operations.
 *
 * Changed in version 2.2
 */
int tagfs_open(const char *path, struct fuse_file_info *fi) {
	char *file_location = NULL;
	int fd = 0;
	int file_id = 0;
	int retstat = 0;

	DEBUG(ENTRY);
	INFO("Opening file: %s", path);

	file_id = file_id_from_path(path);
	file_location = get_file_location(file_id);

	fd = open(file_location, fi->flags);

	if(fd < 0) {
		WARN("Opening file %s failed", file_location);
		retstat = -errno;
	}

	free_single_ptr((void **)&file_location);
	fi->fh = fd;

	DEBUG(EXIT);
	return retstat;
}
Ejemplo n.º 3
0
/*
 * Read data from an open file
 *
 * Read should return exactly the number of bytes requested except on EOF or
 * error, otherwise the rest of the data will be substituted with zeroes. An
 * exception to this is when the 'direct_io' mount option is specified, in
 * which case the return value of the read system call will reflect the return
 * value of this operation.
 *
 * Changed in version 2.2
 */
int tagfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
	char *file_location = NULL;
	int fd = 0;
	int file_id = 0;
	int retstat = 0;

	DEBUG(ENTRY);
	INFO("Reading %s", path);

	file_id = file_id_from_path(path);
	file_location = get_file_location(file_id);
	fd = open(file_location, O_RDONLY);
	free_single_ptr((void **)&file_location);
	retstat = pread(fd, buf, size, offset);

	DEBUG(EXIT);
	return retstat;
}
Ejemplo n.º 4
0
  /* Make a file spec for an LWFN file from a FOND resource and
     a file name. */
  static FT_Error
  make_lwfn_spec( Handle          fond,
                  unsigned char*  file_name,
                  FSSpec*         spec )
  {
    FT_Error  error;
    short     ref_num, v_ref_num;
    long      dir_id;
    Str255    fond_file_name;


    ref_num = HomeResFile( fond );

    error = ResError();
    if ( !error )
      error = get_file_location( ref_num, &v_ref_num,
                                 &dir_id, fond_file_name );
    if ( !error )
      error = FSMakeFSSpec( v_ref_num, dir_id, file_name, spec );

    return error;
  }