nfs-ganesha 1.4

fsal_convert.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 #include "fsal_convert.h"
00018 #include "fsal_internal.h"
00019 #include <unistd.h>
00020 #include <sys/types.h>
00021 #include <sys/stat.h>
00022 #include <errno.h>
00023 
00024 #define MAX_2( x, y )    ( (x) > (y) ? (x) : (y) )
00025 #define MAX_3( x, y, z ) ( (x) > (y) ? MAX_2((x),(z)) : MAX_2((y),(z)) )
00026 
00038 int fuse2fsal_error(int errorcode, int noent_is_stale)
00039 {
00040 
00041   int error_abs = errorcode > 0 ? errorcode : -errorcode;
00042 
00043   if(noent_is_stale && (error_abs == ENOENT))
00044     return ERR_FSAL_STALE;
00045 
00046   switch (error_abs)
00047     {
00048 
00049     case EPERM:
00050       return ERR_FSAL_PERM;
00051 
00052     case ENOENT:
00053       return ERR_FSAL_NOENT;
00054 
00055       /* connection error */
00056 #ifdef _AIX_5
00057     case ENOCONNECT:
00058 #elif defined _LINUX
00059     case ECONNREFUSED:
00060     case ECONNABORTED:
00061     case ECONNRESET:
00062 #endif
00063 
00064       /* IO error */
00065     case EIO:
00066 
00067       /* too many open files */
00068     case ENFILE:
00069     case EMFILE:
00070 
00071       /* broken pipe */
00072     case EPIPE:
00073 
00074       /* all shown as IO errors */
00075       return ERR_FSAL_IO;
00076 
00077       /* no such device */
00078     case ENODEV:
00079     case ENXIO:
00080       return ERR_FSAL_NXIO;
00081 
00082       /* invalid file descriptor : */
00083     case EBADF:
00084       /* we suppose it was not opened... */
00085 
00093       return ERR_FSAL_NOT_OPENED;
00094 
00095     case ENOMEM:
00096       return ERR_FSAL_NOMEM;
00097 
00098     case EACCES:
00099       return ERR_FSAL_ACCESS;
00100 
00101     case EFAULT:
00102       return ERR_FSAL_FAULT;
00103 
00104     case EEXIST:
00105       return ERR_FSAL_EXIST;
00106 
00107     case EXDEV:
00108       return ERR_FSAL_XDEV;
00109 
00110     case ENOTDIR:
00111       return ERR_FSAL_NOTDIR;
00112 
00113     case EISDIR:
00114       return ERR_FSAL_ISDIR;
00115 
00116     case EINVAL:
00117       return ERR_FSAL_INVAL;
00118 
00119     case EFBIG:
00120       return ERR_FSAL_FBIG;
00121 
00122     case EROFS:
00123       return ERR_FSAL_ROFS;
00124 
00125     case ENOSPC:
00126       return ERR_FSAL_NOSPC;
00127 
00128     case EMLINK:
00129       return ERR_FSAL_MLINK;
00130 
00131     case EDQUOT:
00132       return ERR_FSAL_DQUOT;
00133 
00134     case ENAMETOOLONG:
00135       return ERR_FSAL_NAMETOOLONG;
00136 
00143 #ifdef _AIX
00144     case 87:
00145 #else
00146     case ENOTEMPTY:
00147 #endif
00148       return ERR_FSAL_NOTEMPTY;
00149 
00150     case ESTALE:
00151       return ERR_FSAL_STALE;
00152 
00153       /* Error code that needs a retry */
00154     case EAGAIN:
00155     case EBUSY:
00156 
00157       return ERR_FSAL_DELAY;
00158 
00159     default:
00160 
00161       /* other unexpected errors */
00162       return ERR_FSAL_SERVERFAULT;
00163 
00164     }
00165 
00166 }
00167 
00168 fsal_status_t posix2fsal_attributes(struct stat * p_buffstat,
00169                                     fsal_attrib_list_t * p_fsalattr_out)
00170 {
00171 
00172   fsal_attrib_mask_t supp_attr, unsupp_attr;
00173 
00174   /* sanity checks */
00175   if(!p_buffstat || !p_fsalattr_out)
00176     ReturnCode(ERR_FSAL_FAULT, 0);
00177 
00178   /* check that asked attributes are supported */
00179   supp_attr = global_fs_info.supported_attrs;
00180 
00181   unsupp_attr = (p_fsalattr_out->asked_attributes) & (~supp_attr);
00182   if(unsupp_attr)
00183     {
00184       LogFullDebug(COMPONENT_FSAL, "Unsupported attributes: %#llX", unsupp_attr);
00185       p_fsalattr_out->asked_attributes =
00186           p_fsalattr_out->asked_attributes & (~unsupp_attr);
00187     }
00188 
00189   /* Initialize ACL regardless of whether ACL was asked or not.
00190    * This is needed to make sure ACL attribute is initialized. */
00191   p_fsalattr_out->acl = NULL;
00192 
00193   /* Fills the output struct */
00194   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SUPPATTR))
00195     {
00196       p_fsalattr_out->supported_attributes = supp_attr;
00197     }
00198   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_TYPE))
00199     {
00200       p_fsalattr_out->type = posix2fsal_type(p_buffstat->st_mode);
00201     }
00202   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SIZE))
00203     {
00204       p_fsalattr_out->filesize = p_buffstat->st_size;
00205     }
00206   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FSID))
00207     {
00208       p_fsalattr_out->fsid = posix2fsal_fsid(p_buffstat->st_dev);
00209     }
00210   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ACL))
00211     {
00212       p_fsalattr_out->acl = NULL;
00213     }
00214   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FILEID))
00215     {
00216       p_fsalattr_out->fileid = (fsal_u64_t) (p_buffstat->st_ino);
00217     }
00218 
00219   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MODE))
00220     {
00221       p_fsalattr_out->mode = unix2fsal_mode(p_buffstat->st_mode);
00222     }
00223   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_NUMLINKS))
00224     {
00225       p_fsalattr_out->numlinks = p_buffstat->st_nlink;
00226     }
00227   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_OWNER))
00228     {
00229       p_fsalattr_out->owner = p_buffstat->st_uid;
00230     }
00231   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_GROUP))
00232     {
00233       p_fsalattr_out->group = p_buffstat->st_gid;
00234     }
00235   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ATIME))
00236     {
00237       p_fsalattr_out->atime = posix2fsal_time(p_buffstat->st_atime);
00238 
00239     }
00240 
00241   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CTIME))
00242     {
00243       p_fsalattr_out->ctime = posix2fsal_time(p_buffstat->st_ctime);
00244     }
00245   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MTIME))
00246     {
00247       p_fsalattr_out->mtime = posix2fsal_time(p_buffstat->st_mtime);
00248     }
00249 
00250   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CHGTIME))
00251     {
00252       p_fsalattr_out->chgtime
00253           = posix2fsal_time(MAX_2(p_buffstat->st_mtime, p_buffstat->st_ctime));
00254       p_fsalattr_out->change = (uint64_t) p_fsalattr_out->chgtime.seconds ;
00255     }
00256 
00257   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SPACEUSED))
00258     {
00259       p_fsalattr_out->spaceused = p_buffstat->st_blocks * S_BLKSIZE;
00260     }
00261 
00262   if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_RAWDEV))
00263     {
00264       p_fsalattr_out->rawdev = posix2fsal_devt(p_buffstat->st_rdev);    /* XXX: convert ? */
00265     }
00266 
00267   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00268 }