Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * \file sofs_ifuncs_1_adb.c (implementation file of function soAllocDataCluster)
- *
- * \author Artur Carneiro Pereira - September 2008 / September 2011
- * \author António Rui Borges - September 2010 / September 2011
- *
- * \remarks In case an error occurs, all functions return a negative value which is the symmetric of the system error
- * or the local error that better represents the error cause. Local errors are out of the range of the
- * system errors.
- */
- #include <stdio.h>
- #include <errno.h>
- #include <inttypes.h>
- #include <time.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include "sofs_probe.h"
- #include "sofs_buffercache.h"
- #include "sofs_superblock.h"
- #include "sofs_inode.h"
- #include "sofs_datacluster.h"
- #include "sofs_basicoper.h"
- #include "sofs_basicconsist.h"
- /** binary implementation prototype */
- int soAllocDataCluster_bin (uint32_t nInode, uint32_t *p_nClust);
- /**
- * \brief Allocate a free data cluster and associate it to an inode.
- *
- * The inode is supposed to be associated to a file (a regular file, a directory or a symbolic link), but the only
- * consistency check at this stage should be to check the inode is not free.
- *
- * The cluster is retrieved from the retrieval cache of free data cluster references. If the cache is empty, it has to
- * be replenished before the retrieval may take place. If the data cluster is in the dirty state, it has to be cleaned
- * first. The header fields of the allocated cluster should be all filled in: <tt>prev</tt> and <tt>next</tt> should be
- * set to \c NULL_CLUSTER and <tt>stat</tt> to the given inode number.
- *
- * \param nInode number of the inode the data cluster should be associated to
- * \param p_nClust pointer to the location where the logical number of the allocated data cluster is to be stored
- *
- * \return <tt>0 (zero)</tt>, on success
- * \return -\c EINVAL, the <em>inode number</em> is out of range or the <em>pointer to the logical data cluster
- * number</em> is \c NULL
- * \return -\c ENOSPC, if there are no free data clusters
- * \return -\c EIUININVAL, if the inode in use is inconsistent
- * \return -\c ELDCININVAL, if the list of data cluster references belonging to an inode is inconsistent
- * \return -\c EDCINVAL, if the data cluster header is inconsistent
- * \return -\c ELIBBAD, if some kind of inconsistency was detected at some internal storage lower level
- * \return -\c EBADF, if the device is not already opened
- * \return -\c EIO, if it fails reading or writing
- * \return -<em>other specific error</em> issued by \e lseek system call
- */
- int soAllocDataCluster (uint32_t nInode, uint32_t *p_nClust)
- {
- SOInode *p_soInode;
- uint32_t nBlk, offset;
- soProbe (413, "soAllocDataCluster(%"PRIu32", %p)\n", nInode, p_nClust);
- /* Sanity checks
- * nInode == 0 => this is where the ROOT DIR is located ...
- * p_nClust can't be NULL
- */
- if (nInode == 0 || p_nClust == NULL) {
- return -EINVAL;
- }
- /* Load the nInode */
- {
- /* Convert the given nInode into the logical stuff */
- if ( (status = soConvertRefInT(nInode, &nBlk, &offset)) != 0) {
- return status;
- }
- /* Load the block using the acquired information */
- if ( (status = soLoadBlockInT(nBlk)) != 0) {
- return status;
- }
- /* Grab the pointer to the inode */
- if ( (p_soInode = soGetBlockInT(void)) == NULL_INODE ) {
- return p_soInode;
- }
- /* Check if iNode is free (via bit 12) */
- if ( (p_soInode->mode & FREE_INODE) == 0) {
- return
- }
- }
- int soConvertRefInT (uint32_t nInode, uint32_t *p_nBlk, uint32_t *p_offset)
- Convert the inode number, which translates to an entry of the inode table, into the logical number (the ordinal, starting at zero, of the succession blocks that the table of inodes comprises) and the offset of the block where it is stored.
- int soLoadBlockInT (uint32_t nBlk)
- Load the contents of a specific block of the table of inodes into internal storage.
- SOInode * soGetBlockInT (void)
- Get a pointer to the contents of a specific block of the table of inodes.
- /* check if inode is free (via bit 12) */
- if ((nInode & INODE_FREE) == 0) {
- return 0;
- }
- return soAllocDataCluster_bin(nInode, p_nClust);
- }
Add Comment
Please, Sign In to add comment