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 ESRCH:                /* Returned by quotaclt */
00129       return ERR_FSAL_NO_QUOTA;
00130 
00131     case ENAMETOOLONG:
00132       return ERR_FSAL_NAMETOOLONG;
00133 
00140 #ifdef _AIX
00141     case 87:
00142 #else
00143     case ENOTEMPTY:
00144     case -ENOTEMPTY:
00145 #endif
00146       return ERR_FSAL_NOTEMPTY;
00147 
00148     case ESTALE:
00149       return ERR_FSAL_STALE;
00150 
00151       /* Error code that needs a retry */
00152     case EAGAIN:
00153     case EBUSY:
00154 
00155       return ERR_FSAL_DELAY;
00156 
00157     case ENOTSUP:
00158       return ERR_FSAL_NOTSUPP;
00159 
00160     default:
00161 
00162       /* other unexpected errors */
00163       return ERR_FSAL_SERVERFAULT;
00164 
00165     }
00166 
00167 }
00168 
00182 int fsal2posix_openflags(fsal_openflags_t fsal_flags, int *p_posix_flags)
00183 {
00184   int cpt;
00185 
00186   if(!p_posix_flags)
00187     return ERR_FSAL_FAULT;
00188 
00189   /* check that all used flags exist */
00190 
00191   if(fsal_flags &
00192      ~(FSAL_O_RDONLY | FSAL_O_RDWR | FSAL_O_WRONLY | FSAL_O_APPEND | FSAL_O_TRUNC))
00193     return ERR_FSAL_INVAL;
00194 
00195   /* Check for flags compatibility */
00196 
00197   /* O_RDONLY O_WRONLY O_RDWR cannot be used together */
00198 
00199   cpt = 0;
00200   if(fsal_flags & FSAL_O_RDONLY)
00201     cpt++;
00202   if(fsal_flags & FSAL_O_RDWR)
00203     cpt++;
00204   if(fsal_flags & FSAL_O_WRONLY)
00205     cpt++;
00206 
00207   if(cpt > 1)
00208     return ERR_FSAL_INVAL;
00209 
00210   /* FSAL_O_APPEND et FSAL_O_TRUNC cannot be used together */
00211 
00212   if((fsal_flags & FSAL_O_APPEND) && (fsal_flags & FSAL_O_TRUNC))
00213     return ERR_FSAL_INVAL;
00214 
00215   /* FSAL_O_TRUNC without FSAL_O_WRONLY or FSAL_O_RDWR */
00216 
00217   if((fsal_flags & FSAL_O_TRUNC) && !(fsal_flags & (FSAL_O_WRONLY | FSAL_O_RDWR)))
00218     return ERR_FSAL_INVAL;
00219 
00220   /* conversion */
00221   *p_posix_flags = 0;
00222 
00223   if(fsal_flags & FSAL_O_RDONLY)
00224     *p_posix_flags |= O_RDONLY;
00225   if(fsal_flags & FSAL_O_WRONLY)
00226     *p_posix_flags |= O_WRONLY;
00227   if(fsal_flags & FSAL_O_RDWR)
00228     *p_posix_flags |= O_RDWR;
00229 
00230   return ERR_FSAL_NO_ERROR;
00231 
00232 }
00233 
00234 fsal_status_t posix2fsal_attributes(struct stat * p_buffstat,
00235                                     fsal_attrib_list_t * p_fsalattr_out)
00236 {
00237 
00238   fsal_attrib_mask_t supp_attr, unsupp_attr;
00239 
00240   /* sanity checks */
00241   if(!p_buffstat || !p_fsalattr_out)
00242     ReturnCode(ERR_FSAL_FAULT, 0);
00243 
00244   /* check that asked attributes are supported */
00245   supp_attr = global_fs_info.supported_attrs;
00246 
00247   unsupp_attr = (p_fsalattr_out->asked_attributes) & (~supp_attr);
00248   if(unsupp_attr)
00249     {
00250       LogFullDebug(COMPONENT_FSAL, "Unsupported attributes: %#llX",
00251                         unsupp_attr);
00252       ReturnCode(ERR_FSAL_ATTRNOTSUPP, 0);
00253     }
00254 
00255   /* Initialize ACL regardless of whether ACL was asked or not.
00256    * This is needed to make sure ACL attribute is initialized. */
00257   p_fsalattr_out->acl = NULL;
00258 
00259   /* Fills the output struct */
00260   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SUPPATTR))
00261     {
00262       p_fsalattr_out->supported_attributes = supp_attr;
00263     }
00264   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_TYPE))
00265     {
00266       p_fsalattr_out->type = posix2fsal_type(p_buffstat->st_mode);
00267     }
00268   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SIZE))
00269     {
00270       p_fsalattr_out->filesize = p_buffstat->st_size;
00271     }
00272   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FSID))
00273     {
00274       p_fsalattr_out->fsid = posix2fsal_fsid(p_buffstat->st_dev);
00275     }
00276   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ACL))
00277     {
00278       p_fsalattr_out->acl = NULL;
00279     }
00280   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FILEID))
00281     {
00282       p_fsalattr_out->fileid = (fsal_u64_t) (p_buffstat->st_ino);
00283     }
00284 
00285   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MODE))
00286     {
00287       p_fsalattr_out->mode = unix2fsal_mode(p_buffstat->st_mode);
00288     }
00289   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_NUMLINKS))
00290     {
00291       p_fsalattr_out->numlinks = p_buffstat->st_nlink;
00292     }
00293   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_OWNER))
00294     {
00295       p_fsalattr_out->owner = p_buffstat->st_uid;
00296     }
00297   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_GROUP))
00298     {
00299       p_fsalattr_out->group = p_buffstat->st_gid;
00300     }
00301   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ATIME))
00302     {
00303       p_fsalattr_out->atime = posix2fsal_time(p_buffstat->st_atime, 0);
00304 
00305     }
00306 
00307   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CTIME))
00308     {
00309       p_fsalattr_out->ctime = posix2fsal_time(p_buffstat->st_ctime, 0);
00310     }
00311   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MTIME))
00312     {
00313       p_fsalattr_out->mtime = posix2fsal_time(p_buffstat->st_mtime, 0);
00314     }
00315 
00316   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CHGTIME))
00317     {
00318       p_fsalattr_out->chgtime
00319           = posix2fsal_time(MAX_2(p_buffstat->st_mtime, p_buffstat->st_ctime), 0);
00320       p_fsalattr_out->change = (uint64_t) p_fsalattr_out->chgtime.seconds ;
00321     }
00322 
00323   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SPACEUSED))
00324     {
00325       p_fsalattr_out->spaceused = p_buffstat->st_blocks * S_BLKSIZE;
00326     }
00327 
00328   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_RAWDEV))
00329     {
00330       p_fsalattr_out->rawdev = posix2fsal_devt(p_buffstat->st_rdev);    /* XXX: convert ? */
00331     }
00332   /* mounted_on_fileid :
00333      if ( FSAL_TEST_MASK(p_fsalattr_out->asked_attributes,
00334      FSAL_ATTR_MOUNTFILEID )){
00335      p_fsalattr_out->mounted_on_fileid = 
00336      hpss2fsal_64( p_hpss_attr_in->FilesetRootId );
00337      }
00338    */
00339 
00340   /* everything has been copied ! */
00341 
00342   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00343 }