Beispiel #1
0
func (fs *Goofys) SetInodeAttributes(
	ctx context.Context,
	op *fuseops.SetInodeAttributesOp) (err error) {

	fs.mu.Lock()
	inode := fs.getInodeOrDie(op.Inode)
	fs.mu.Unlock()

	attr, err := inode.GetAttributes(fs)
	op.Attributes = *attr
	op.AttributesExpiration = time.Now().Add(365 * 24 * time.Hour)
	return
}
Beispiel #2
0
// SetInodeAttributes sets specified attributes to file or directory.
//
// Required for fuse.FileSystem.
func (k *KodingNetworkFS) SetInodeAttributes(ctx context.Context, op *fuseops.SetInodeAttributesOp) error {
	entry, err := k.getEntry(ctx, op.Inode)
	if err != nil {
		return err
	}

	attrs := entry.GetAttrs()

	// optionally update attrs
	if op.Mode != nil {
		attrs.Mode = *op.Mode
	}
	if op.Atime != nil {
		attrs.Atime = *op.Atime
	}

	// optionally update attrs only if entry is a file
	if file, isFile := entry.(*File); isFile {
		if op.Mtime != nil {
			attrs.Mtime = *op.Mtime
		}

		if op.Size != nil {
			if err := file.TruncateTo(*op.Size); err != nil {
				return err
			}
			attrs.Size = *op.Size
		}
	}

	entry.SetAttrs(attrs)
	op.Attributes = *attrs

	return nil
}
Beispiel #3
0
func (fs *memFS) SetInodeAttributes(
	op *fuseops.SetInodeAttributesOp) (err error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	// Grab the inode.
	inode := fs.getInodeOrDie(op.Inode)

	// Handle the request.
	inode.SetAttributes(op.Size, op.Mode, op.Mtime)

	// Fill in the response.
	op.Attributes = inode.attrs

	// We don't spontaneously mutate, so the kernel can cache as long as it wants
	// (since it also handles invalidation).
	op.AttributesExpiration = fs.clock.Now().Add(365 * 24 * time.Hour)

	return
}
Beispiel #4
0
// LOCKS_EXCLUDED(fs.mu)
func (fs *fileSystem) SetInodeAttributes(
	op *fuseops.SetInodeAttributesOp) (err error) {
	// Find the inode.
	fs.mu.Lock()
	in := fs.inodes[op.Inode]
	fs.mu.Unlock()

	in.Lock()
	defer in.Unlock()

	// The only thing we support changing is size, and then only for directories.
	if op.Mode != nil || op.Atime != nil || op.Mtime != nil {
		err = fuse.ENOSYS
		return
	}

	file, ok := in.(*inode.FileInode)
	if !ok {
		err = fuse.ENOSYS
		return
	}

	// Set the size, if specified.
	if op.Size != nil {
		if err = file.Truncate(op.Context(), int64(*op.Size)); err != nil {
			err = fmt.Errorf("Truncate: %v", err)
			return
		}
	}

	// Fill in the response.
	op.Attributes, err = in.Attributes(op.Context())
	if err != nil {
		return
	}

	return
}