Lumiera  0.pre.03
»edityourfreedom«
filedescriptor.c File Reference

Go to the source code of this file.

Description

Implementation of a file descriptor management framework.

Todo:
development in this area is stalled since 2010

Definition in file filedescriptor.c.

#include "include/logging.h"
#include "lib/mutex.h"
#include "lib/safeclib.h"
#include "lib/tmpbuf.h"
#include "backend/file.h"
#include "backend/filedescriptor.h"
#include "backend/filedescriptorregistry.h"
#include "backend/filehandle.h"
#include "backend/filehandlecache.h"
#include <sys/types.h>
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
#include <errno.h>

Functions

LumieraFiledescriptor lumiera_filedescriptor_acquire (const char *name, int flags, LList filenode)
 Find existing filedescriptor or create one. More...
 
void lumiera_filedescriptor_delete (LumieraFiledescriptor self, const char *name)
 Delete a filedescriptor Called whenever its reference count drops to zero. More...
 
int lumiera_filedescriptor_flags (LumieraFiledescriptor self)
 
int lumiera_filedescriptor_handle_acquire (LumieraFiledescriptor self)
 
void lumiera_filedescriptor_handle_release (LumieraFiledescriptor self)
 
const char * lumiera_filedescriptor_name (LumieraFiledescriptor self)
 
LumieraFiledescriptor lumiera_filedescriptor_new (LumieraFiledescriptor template)
 Allocate a new filedescriptor cloned from a template. More...
 
LumieraFiledescriptor lumiera_filedescriptor_rdlock (LumieraFiledescriptor self)
 
void lumiera_filedescriptor_release (LumieraFiledescriptor self, const char *name, LList filenode)
 Release a filedescriptor. More...
 
int lumiera_filedescriptor_samestat (LumieraFiledescriptor self, struct stat *stat)
 
LumieraFiledescriptor lumiera_filedescriptor_unlock (LumieraFiledescriptor self)
 
LumieraFiledescriptor lumiera_filedescriptor_wrlock (LumieraFiledescriptor self)
 

Variables

lumiera_mutex lumiera_filecreate_mutex
 Protect lookup and creation of files. More...
 

Function Documentation

◆ lumiera_filedescriptor_acquire()

LumieraFiledescriptor lumiera_filedescriptor_acquire ( const char *  name,
int  flags,
LList  filenode 
)

Find existing filedescriptor or create one.

Parameters
namename of the file
flagsopening flags for the filedescriptor
Returns
descriptor on success or NULL on error

Definition at line 55 of file filedescriptor.c.

References llist_insert_head, LUMIERA_ERROR_SET_CRITICAL, lumiera_filecreate_mutex, lumiera_filedescriptorregistry_ensure(), LUMIERA_MUTEX_SECTION, lumiera_tmpbuf_strndup(), NULL, and TRACE().

Referenced by lumiera_file_init(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_release()

void lumiera_filedescriptor_release ( LumieraFiledescriptor  self,
const char *  name,
LList  filenode 
)

Release a filedescriptor.

Parameters
selffiledescriptor to be released
filethe file struct which initiated the release

Definition at line 121 of file filedescriptor.c.

References lumiera_filedescriptor_delete(), LUMIERA_MUTEX_SECTION, and TRACE().

Referenced by lumiera_file_destroy(), and TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_handle_acquire()

int lumiera_filedescriptor_handle_acquire ( LumieraFiledescriptor  self)

Definition at line 138 of file filedescriptor.c.

References lumiera_filehandle_handle(), lumiera_filehandlecache_checkout(), lumiera_filehandlecache_handle_acquire(), LUMIERA_MUTEX_SECTION, and TRACE().

Referenced by lumiera_file_handle_acquire(), lumiera_filedescriptor_rdlock(), and lumiera_filedescriptor_wrlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_handle_release()

void lumiera_filedescriptor_handle_release ( LumieraFiledescriptor  self)

Definition at line 160 of file filedescriptor.c.

References lumiera_filehandlecache_checkin(), LUMIERA_MUTEX_SECTION, and TRACE().

Referenced by lumiera_file_handle_release(), lumiera_filedescriptor_rdlock(), lumiera_filedescriptor_unlock(), and lumiera_filedescriptor_wrlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_name()

const char* lumiera_filedescriptor_name ( LumieraFiledescriptor  self)

Definition at line 171 of file filedescriptor.c.

References llist_head.

Referenced by lumiera_file_bias_get(), lumiera_file_chunksize_get(), lumiera_file_mmapings(), lumiera_filedescriptor_rdlock(), lumiera_filedescriptor_unlock(), lumiera_filedescriptor_wrlock(), lumiera_filehandle_handle(), lumiera_filehandlecache_handle_acquire(), lumiera_mmap_init(), and lumiera_mmap_init_exact().

+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_flags()

int lumiera_filedescriptor_flags ( LumieraFiledescriptor  self)

Definition at line 180 of file filedescriptor.c.

Referenced by lumiera_filehandle_handle().

+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_samestat()

int lumiera_filedescriptor_samestat ( LumieraFiledescriptor  self,
struct stat *  stat 
)

Definition at line 187 of file filedescriptor.c.

Referenced by lumiera_filehandle_handle().

+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_new()

LumieraFiledescriptor lumiera_filedescriptor_new ( LumieraFiledescriptor  template)

Allocate a new filedescriptor cloned from a template.

Parameters
templatethe source filedescriptor
Returns
the constructed filedescriptor

Definition at line 197 of file filedescriptor.c.

References lumiera_malloc(), lumiera_mutex_init(), lumiera_rwlock_init(), NULL, psplaynode_init(), and TRACE().

Referenced by lumiera_filedescriptorregistry_ensure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_delete()

void lumiera_filedescriptor_delete ( LumieraFiledescriptor  self,
const char *  name 
)

Delete a filedescriptor Called whenever its reference count drops to zero.

Parameters
selfthe filedescriptor to be deleted

Definition at line 223 of file filedescriptor.c.

References lumiera_filedescriptorregistry_remove(), lumiera_filehandle_handle(), lumiera_filehandlecache_checkin(), lumiera_filehandlecache_checkout(), lumiera_free(), lumiera_mmapings_delete(), lumiera_mutex_destroy(), lumiera_rwlock_destroy(), and TRACE().

Referenced by delete_fn(), and lumiera_filedescriptor_release().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_rdlock()

LumieraFiledescriptor lumiera_filedescriptor_rdlock ( LumieraFiledescriptor  self)

Definition at line 255 of file filedescriptor.c.

References LUMIERA_ERROR_SET_WARNING, lumiera_filedescriptor_handle_acquire(), lumiera_filedescriptor_handle_release(), lumiera_filedescriptor_name(), LUMIERA_MUTEX_SECTION, lumiera_rwlock_rdlock(), lumiera_rwlock_unlock(), NULL, and TRACE().

Referenced by lumiera_file_rdlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_wrlock()

LumieraFiledescriptor lumiera_filedescriptor_wrlock ( LumieraFiledescriptor  self)

Definition at line 301 of file filedescriptor.c.

References LUMIERA_ERROR_SET_WARNING, lumiera_filedescriptor_handle_acquire(), lumiera_filedescriptor_handle_release(), lumiera_filedescriptor_name(), LUMIERA_MUTEX_SECTION, lumiera_rwlock_unlock(), lumiera_rwlock_wrlock(), NULL, and TRACE().

Referenced by lumiera_file_wrlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filedescriptor_unlock()

LumieraFiledescriptor lumiera_filedescriptor_unlock ( LumieraFiledescriptor  self)

Definition at line 343 of file filedescriptor.c.

References LUMIERA_ERROR_SET_WARNING, lumiera_filedescriptor_handle_release(), lumiera_filedescriptor_name(), lumiera_filehandle_get(), LUMIERA_MUTEX_SECTION, lumiera_rwlock_unlock(), NULL, and TRACE().

Referenced by lumiera_file_unlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ lumiera_filecreate_mutex

lumiera_mutex lumiera_filecreate_mutex

Protect lookup and creation of files.

Trying to access a nonexistent file with O_CREAT would be racy. Defined in filedescriptor.c

Definition at line 51 of file filedescriptor.c.

Referenced by lumiera_backend_destroy(), lumiera_backend_init(), and lumiera_filedescriptor_acquire().