ShingledFS 2.0
SMR-AwareFUSE-basedFileSystem

helper.c File Reference

Implementation of Helper functions. More...

#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/xattr.h>
#include <linux/limits.h>
#include "helper.h"
#include "failstop.h"
#include "emulator.h"
#include "band_log.h"

Go to the source code of this file.

Functions

void read_edi_parameters (int fd, uint32_t *blk_size, band_t *band_count, rba_t *band_size)
 Reads the EDI Parameters and saves them in the FUSE private context.
void translate_path (const char *in_path, const char *prefix, char *out_path)
 Translate the incoming path by adding the specified prefix to it.
void xattr_path (const char *in_path, char *out_path)
 Generates the name of the attribute replication file for the specified input file path.
int xattr_get (const char *path, const char *name, void *value, size_t size)
 Retrieves the extended attributes of the specified file.
void xattr_set (const char *path, const char *name, void *value, size_t size, int flags)
 Sets the replicated attributes of the specified file.
int is_valid_dir (const char *path)
 Validates the specified path to be a directory.
int is_valid_file (const char *path)
 Validates the specified path to be a file.
void mark_for_cleaning (inode_t inode)
 Performs all the updates needed to mark the band space defined by the specified inode for cleaning.
void inode_free (int inodeno)
 Frees the specified inode.
void inode_update (inode_t *inode, band_t band, rba_t rba, size_t size)
 Updates the band usage data in the inode.
void inode_unlink (inode_t inode)
 Unlinks the inode.

Detailed Description

Implementation of Helper functions.

Author:
Anand Suresh <anandsur@andrew.cmu.edu>

Definition in file helper.c.


Function Documentation

void inode_free ( int  inodeno) [inline]

Frees the specified inode.

This function should be called when an inode needs to be freed. This usually occurs when a file has been deleted or renamed (when a file is renamed to an existing file).

Parameters:
inodenoThe inode no. of the inode to be freed

Definition at line 302 of file helper.c.

Referenced by inode_unlink().

void inode_unlink ( inode_t  inode) [inline]

Unlinks the inode.

This function marks the space described by the inode for cleaning and then frees the inode.

Parameters:
inodeInode of the file that is being deleted

Definition at line 360 of file helper.c.

References inode_free(), and mark_for_cleaning().

Referenced by bc_close(), bc_rename(), and shingledfs_unlink().

void inode_update ( inode_t inode,
band_t  band,
rba_t  rba,
size_t  size 
) [inline]

Updates the band usage data in the inode.

Parameters:
inodeInode of the file that is being updated
bandThe updated band no.
rbaThe updated RBA
sizeThe new size/extent of the file

Definition at line 329 of file helper.c.

int is_valid_dir ( const char *  path)

Validates the specified path to be a directory.

Parameters:
pathThe path to the directory to be verified
Returns:
1 on successful validation; 0 on validation failure.

Definition at line 225 of file helper.c.

int is_valid_file ( const char *  path)

Validates the specified path to be a file.

Parameters:
pathThe path to the file to be verified
Returns:
1 on successful validation; 0 on validation failure.

Definition at line 248 of file helper.c.

void mark_for_cleaning ( inode_t  inode) [inline]

Performs all the updates needed to mark the band space defined by the specified inode for cleaning.

This function should be called whenever a space allocated to a file on any band needs to be marked for cleaning. This should usually be called when a file is updated or deleted.

Parameters:
inodeInode of the file that is being deleted/updated.

Definition at line 274 of file helper.c.

Referenced by inode_unlink().

void read_edi_parameters ( int  fd,
uint32_t *  blk_size,
band_t *  band_count,
rba_t *  band_size 
)

Reads the EDI Parameters and saves them in the FUSE private context.

Parameters:
fd_ediFile Descriptor to open EDI file
blk_sizePointer to variable storing the block size of the EDI
band_countPointer to variable storing the no. of bands on the EDI
band_sizePointer to variable storing the size of a band on the EDI

Definition at line 50 of file helper.c.

Referenced by shingledfs_init().

void translate_path ( const char *  in_path,
const char *  prefix,
char *  out_path 
)

Translate the incoming path by adding the specified prefix to it.

out_path must be large enough to store the concatenation of in_path and prefix, plus the terminating null character.

Parameters:
in_pathThe input path
prefixThe path to prefix to the incoming path
out_pathThe location to store the resulting concatenation

Definition at line 77 of file helper.c.

Referenced by init_inodebitmap(), init_inodelist(), shingledfs_access(), shingledfs_chmod(), shingledfs_chown(), shingledfs_getattr(), shingledfs_getxattr(), shingledfs_link(), shingledfs_listxattr(), shingledfs_mkdir(), shingledfs_mknod(), shingledfs_open(), shingledfs_opendir(), shingledfs_readlink(), shingledfs_release(), shingledfs_releasedir(), shingledfs_removexattr(), shingledfs_rename(), shingledfs_rmdir(), shingledfs_setxattr(), shingledfs_statfs(), shingledfs_symlink(), shingledfs_truncate(), shingledfs_unlink(), and shingledfs_utime().

int xattr_get ( const char *  path,
const char *  name,
void *  value,
size_t  size 
)

Retrieves the extended attributes of the specified file.

Parameters:
pathThe path to the file on the unshingled partition
nameName of the extended attribute to retrieve
valueBuffer to hold the value of the extended attribute
sizeSize of the buffer
Returns:
0 on success; -1 on failure

Definition at line 162 of file helper.c.

References xattr_path().

Referenced by bc_open(), shingledfs_access(), shingledfs_chmod(), shingledfs_chown(), shingledfs_getattr(), shingledfs_getxattr(), shingledfs_link(), shingledfs_truncate(), shingledfs_unlink(), and shingledfs_utime().

void xattr_path ( const char *  in_path,
char *  out_path 
)

Generates the name of the attribute replication file for the specified input file path.

This function should not be called for directories!

Given the path to the input file, this function appends the Attribute Replication file prefix (.xattr_) to the name of the file.

Todo:
Consider adding the S_ISREG() check on the stats of the input path!
Parameters:
in_pathThe path to the file on the unshingled partition
out_pathThe location to store the resulting concatenation

Definition at line 114 of file helper.c.

Referenced by bc_open(), shingledfs_mknod(), shingledfs_rename(), shingledfs_unlink(), xattr_get(), and xattr_set().

void xattr_set ( const char *  path,
const char *  name,
void *  value,
size_t  size,
int  flags 
)

Sets the replicated attributes of the specified file.

Parameters:
pathThe path to the file on the unshingled partition
nameName of the extended attribute to update
valueBuffer holding the value to be set for the extended attribute
sizeSize of the data in the buffer

Definition at line 187 of file helper.c.

References xattr_path().

Referenced by shingledfs_chmod(), shingledfs_chown(), shingledfs_link(), shingledfs_mknod(), shingledfs_setxattr(), shingledfs_truncate(), and shingledfs_utime().