nfs-ganesha 1.4

fsal_convert.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 
00015 #ifdef HAVE_CONFIG_H
00016 #include "config.h"
00017 #endif
00018 #include "fsal_convert.h"
00019 #include "fsal_internal.h"
00020 #include <sys/types.h>
00021 #include <sys/stat.h>
00022 #include <errno.h>
00023 #include <string.h>
00024 #include <fcntl.h>
00025 
00026 #define MAX_2( x, y )    ( (x) > (y) ? (x) : (y) )
00027 #define MAX_3( x, y, z ) ( (x) > (y) ? MAX_2((x),(z)) : MAX_2((y),(z)) )
00028 
00040 int posix2fsal_error(int posix_errorcode)
00041 {
00042 
00043   switch (posix_errorcode)
00044     {
00045 
00046     case EPERM:
00047       return ERR_FSAL_PERM;
00048 
00049     case ENOENT:
00050       return ERR_FSAL_NOENT;
00051 
00052       /* connection error */
00053 #ifdef _AIX_5
00054     case ENOCONNECT:
00055 #elif defined _LINUX
00056     case ECONNREFUSED:
00057     case ECONNABORTED:
00058     case ECONNRESET:
00059 #endif
00060 
00061       /* IO error */
00062     case EIO:
00063 
00064       /* too many open files */
00065     case ENFILE:
00066     case EMFILE:
00067 
00068       /* broken pipe */
00069     case EPIPE:
00070 
00071       /* all shown as IO errors */
00072       return ERR_FSAL_IO;
00073 
00074       /* no such device */
00075     case ENODEV:
00076     case ENXIO:
00077       return ERR_FSAL_NXIO;
00078 
00079       /* invalid file descriptor : */
00080     case EBADF:
00081       /* we suppose it was not opened... */
00082 
00090       return ERR_FSAL_NOT_OPENED;
00091 
00092     case ENOMEM:
00093       return ERR_FSAL_NOMEM;
00094 
00095     case EACCES:
00096       return ERR_FSAL_ACCESS;
00097 
00098     case EFAULT:
00099       return ERR_FSAL_FAULT;
00100 
00101     case EEXIST:
00102       return ERR_FSAL_EXIST;
00103 
00104     case EXDEV:
00105       return ERR_FSAL_XDEV;
00106 
00107     case ENOTDIR:
00108       return ERR_FSAL_NOTDIR;
00109 
00110     case EISDIR:
00111       return ERR_FSAL_ISDIR;
00112 
00113     case EINVAL:
00114       return ERR_FSAL_INVAL;
00115 
00116     case EFBIG:
00117       return ERR_FSAL_FBIG;
00118 
00119     case ENOSPC:
00120       return ERR_FSAL_NOSPC;
00121 
00122     case EMLINK:
00123       return ERR_FSAL_MLINK;
00124 
00125     case EDQUOT:
00126       return ERR_FSAL_DQUOT;
00127 
00128     case ENAMETOOLONG:
00129       return ERR_FSAL_NAMETOOLONG;
00130 
00137 #ifdef _AIX
00138     case 87:
00139 #else
00140     case ENOTEMPTY:
00141     case -ENOTEMPTY:
00142 #endif
00143       return ERR_FSAL_NOTEMPTY;
00144 
00145     case ESTALE:
00146       return ERR_FSAL_STALE;
00147 
00148       /* Error code that needs a retry */
00149     case EAGAIN:
00150     case EBUSY:
00151 #ifdef _SHOOK
00152     case ETIME:
00153 #endif
00154       return ERR_FSAL_DELAY;
00155 
00156     case ENOTSUP:
00157       return ERR_FSAL_NOTSUPP;
00158 
00159     default:
00160 
00161       /* other unexpected errors */
00162       return ERR_FSAL_SERVERFAULT;
00163 
00164     }
00165 
00166 }
00167 
00181 int fsal2posix_openflags(fsal_openflags_t fsal_flags, int *p_posix_flags)
00182 {
00183   int cpt;
00184 
00185   if(!p_posix_flags)
00186     return ERR_FSAL_FAULT;
00187 
00188   if(fsal_flags &
00189      ~(FSAL_O_RDONLY | FSAL_O_RDWR | FSAL_O_WRONLY | FSAL_O_APPEND |
00190        FSAL_O_SYNC   | FSAL_O_TRUNC))
00191     return ERR_FSAL_INVAL;
00192 
00193   /* Check for flags compatibility */
00194 
00195   /* O_RDONLY O_WRONLY O_RDWR cannot be used together */
00196 
00197   cpt = 0;
00198   if(fsal_flags & FSAL_O_RDONLY)
00199     cpt++;
00200   if(fsal_flags & FSAL_O_RDWR)
00201     cpt++;
00202   if(fsal_flags & FSAL_O_WRONLY)
00203     cpt++;
00204 
00205   if(cpt > 1)
00206     return ERR_FSAL_INVAL;
00207 
00208   /* FSAL_O_APPEND et FSAL_O_TRUNC cannot be used together */
00209 
00210   if((fsal_flags & FSAL_O_APPEND) && (fsal_flags & FSAL_O_TRUNC))
00211     return ERR_FSAL_INVAL;
00212 
00213   /* FSAL_O_TRUNC without FSAL_O_WRONLY or FSAL_O_RDWR */
00214 
00215   if((fsal_flags & FSAL_O_TRUNC) && !(fsal_flags & (FSAL_O_WRONLY | FSAL_O_RDWR)))
00216     return ERR_FSAL_INVAL;
00217 
00218   /* conversion */
00219   *p_posix_flags = 0;
00220 
00221   if(fsal_flags & FSAL_O_RDONLY)
00222     *p_posix_flags |= O_RDONLY;
00223   if(fsal_flags & FSAL_O_WRONLY)
00224     *p_posix_flags |= O_WRONLY;
00225   if(fsal_flags & FSAL_O_RDWR)
00226     *p_posix_flags |= O_RDWR;
00227 
00228   return ERR_FSAL_NO_ERROR;
00229 
00230 }
00231 
00232 fsal_status_t posix2fsal_attributes(struct stat * p_buffstat,
00233                                     fsal_attrib_list_t * p_fsalattr_out)
00234 {
00235 
00236   fsal_attrib_mask_t supp_attr, unsupp_attr;
00237 
00238   /* sanity checks */
00239   if(!p_buffstat || !p_fsalattr_out)
00240     ReturnCode(ERR_FSAL_FAULT, 0);
00241 
00242   /* check that asked attributes are supported */
00243   supp_attr = global_fs_info.supported_attrs;
00244 
00245   unsupp_attr = (p_fsalattr_out->asked_attributes) & (~supp_attr);
00246   if(unsupp_attr)
00247     {
00248       LogFullDebug(COMPONENT_FSAL, "Unsupported attributes: %#llX",
00249                         unsupp_attr);
00250       ReturnCode(ERR_FSAL_ATTRNOTSUPP, 0);
00251     }
00252 
00253   /* Initialize ACL regardless of whether ACL was asked or not.
00254    * This is needed to make sure ACL attribute is initialized. */
00255   p_fsalattr_out->acl = NULL;
00256 
00257   /* Fills the output struct */
00258   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SUPPATTR))
00259     {
00260       p_fsalattr_out->supported_attributes = supp_attr;
00261     }
00262   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_TYPE))
00263     {
00264       p_fsalattr_out->type = posix2fsal_type(p_buffstat->st_mode);
00265     }
00266   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SIZE))
00267     {
00268       p_fsalattr_out->filesize = p_buffstat->st_size;
00269     }
00270   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FSID))
00271     {
00272       p_fsalattr_out->fsid = posix2fsal_fsid(p_buffstat->st_dev);
00273     }
00274   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ACL))
00275     {
00276       p_fsalattr_out->acl = NULL;
00277     }
00278   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FILEID))
00279     {
00280       p_fsalattr_out->fileid = (fsal_u64_t) (p_buffstat->st_ino);
00281     }
00282 
00283   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MODE))
00284     {
00285       p_fsalattr_out->mode = unix2fsal_mode(p_buffstat->st_mode);
00286     }
00287   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_NUMLINKS))
00288     {
00289       p_fsalattr_out->numlinks = p_buffstat->st_nlink;
00290     }
00291   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_OWNER))
00292     {
00293       p_fsalattr_out->owner = p_buffstat->st_uid;
00294     }
00295   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_GROUP))
00296     {
00297       p_fsalattr_out->group = p_buffstat->st_gid;
00298     }
00299   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ATIME))
00300     {
00301       p_fsalattr_out->atime = posix2fsal_time(p_buffstat->st_atime);
00302 
00303     }
00304 
00305   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CTIME))
00306     {
00307       p_fsalattr_out->ctime = posix2fsal_time(p_buffstat->st_ctime);
00308     }
00309   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MTIME))
00310     {
00311       p_fsalattr_out->mtime = posix2fsal_time(p_buffstat->st_mtime);
00312     }
00313 
00314   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CHGTIME))
00315     {
00316       p_fsalattr_out->chgtime
00317           = posix2fsal_time(MAX_2(p_buffstat->st_mtime, p_buffstat->st_ctime));
00318       p_fsalattr_out->change = (uint64_t) p_fsalattr_out->chgtime.seconds ;
00319     }
00320 
00321   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SPACEUSED))
00322     {
00323       p_fsalattr_out->spaceused = p_buffstat->st_blocks * S_BLKSIZE;
00324     }
00325 
00326   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_RAWDEV))
00327     {
00328       p_fsalattr_out->rawdev = posix2fsal_devt(p_buffstat->st_rdev);    /* XXX: convert ? */
00329     }
00330   /* mounted_on_fileid :
00331      if ( FSAL_TEST_MASK(p_fsalattr_out->asked_attributes,
00332      FSAL_ATTR_MOUNTFILEID )){
00333      p_fsalattr_out->mounted_on_fileid = 
00334      hpss2fsal_64( p_hpss_attr_in->FilesetRootId );
00335      }
00336    */
00337 
00338   /* everything has been copied ! */
00339 
00340   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00341 }