nfs-ganesha 1.4

fsal_xattrs.c

Go to the documentation of this file.
00001 
00009 #ifdef HAVE_CONFIG_H
00010 #include "config.h"
00011 #endif
00012 
00013 #include "fsal.h"
00014 #include "fsal_internal.h"
00015 #include "fsal_convert.h"
00016 #include "namespace.h"
00017 
00018 #include <string.h>
00019 
00020 /* Those definitions are only used for attributes emulated by FSAL.
00021  * For FUSE filesystems, we call FS primitives directly.
00022  */
00023 #if 0
00024 
00025 /* generic definitions for extended attributes */
00026 
00027 #define XATTR_FOR_FILE     0x00000001
00028 #define XATTR_FOR_DIR      0x00000002
00029 #define XATTR_FOR_SYMLINK  0x00000004
00030 #define XATTR_FOR_ALL      0x0000000F
00031 #define XATTR_RO           0x00000100
00032 #define XATTR_RW           0x00000200
00033 
00034 /* function for getting an attribute value */
00035 
00036 typedef int (*xattr_getfunc_t) (fusefsal_handle_t *,    /* object handle */
00037                                 fusefsal_op_context_t *,        /* context */
00038                                 caddr_t,        /* output buff */
00039                                 size_t, /* output buff size */
00040                                 size_t *);      /* output size */
00041 
00042 typedef int (*xattr_setfunc_t) (fusefsal_handle_t *,    /* object handle */
00043                                 fusefsal_op_context_t *,        /* context */
00044                                 caddr_t,        /* input buff */
00045                                 size_t, /* input size */
00046                                 int);   /* creation flag */
00047 
00048 typedef int (*xattr_printfunc_t) (caddr_t,      /* Input buffer */
00049                                   size_t,       /* Input size   */
00050                                   caddr_t,      /* Output (ASCII) buffer */
00051                                   size_t *);    /* Output size */
00052 
00053 typedef struct fsal_xattr_def__
00054 {
00055   char xattr_name[FSAL_MAX_NAME_LEN];
00056   xattr_getfunc_t get_func;
00057   xattr_setfunc_t set_func;
00058   xattr_printfunc_t print_func;
00059   int flags;
00060 } fsal_xattr_def_t;
00061 
00062 /*
00063  * DEFINE HERE YOUR GET/SET FUNCTIONS
00064  */
00065 
00066 int get_void_attr(fusefsal_handle_t * p_objecthandle,   /* IN */
00067                   fusefsal_op_context_t * p_context,    /* IN */
00068                   caddr_t buffer_addr,  /* IN/OUT */
00069                   size_t buffer_size,   /* IN */
00070                   size_t * p_output_size)       /* OUT */
00071 {
00072   if(!p_objecthandle || !p_context || !p_output_size)
00073     return ERR_FSAL_FAULT;
00074 
00075   snprintf((char *)buffer_addr, buffer_size, "Hello World !");
00076 
00077   *p_output_size = strlen((char *)buffer_addr) + 1;
00078 
00079   return 0;
00080 
00081 }
00082 
00083 /* DEFINE HERE YOUR ATTRIBUTES LIST */
00084 
00085 static fsal_xattr_def_t xattr_list[] = {
00086   {"hello_world", get_void_attr, NULL, NULL, XATTR_FOR_ALL | XATTR_RO}
00087 };
00088 
00089 #define XATTR_COUNT 1
00090 
00091 /* YOUR SHOULD NOT HAVE TO MODIFY THE FOLLOWING FUNCTIONS */
00092 
00093 /* test if an object has a given attribute */
00094 int do_match_type(int xattr_flag, fsal_nodetype_t obj_type)
00095 {
00096   switch (obj_type)
00097     {
00098     case FSAL_TYPE_FILE:
00099       return ((xattr_flag & XATTR_FOR_FILE) == XATTR_FOR_FILE);
00100 
00101     case FSAL_TYPE_DIR:
00102       return ((xattr_flag & XATTR_FOR_DIR) == XATTR_FOR_DIR);
00103 
00104     case FSAL_TYPE_LNK:
00105       return ((xattr_flag & XATTR_FOR_SYMLINK) == XATTR_FOR_SYMLINK);
00106 
00107     default:
00108       return ((xattr_flag & XATTR_FOR_ALL) == XATTR_FOR_ALL);
00109     }
00110 }
00111 #else
00112 
00113 #define XATTR_COUNT 0
00114 #endif
00115 
00116 #if 0
00117 static int file_attributes_to_xattr_attrs(fsal_attrib_list_t * file_attrs,
00118                                           fsal_attrib_list_t * p_xattr_attrs,
00119                                           unsigned int attr_index)
00120 {
00121 
00122   /* supported attributes are:
00123    * - owner (same as the objet)
00124    * - group (same as the objet)
00125    * - type FSAL_TYPE_XATTR
00126    * - fileid (attr index ? or (fileid^((index+1)<<24)) )
00127    * - mode (config & file)
00128    * - atime, mtime, ctime = these of the object ?
00129    * - size=1block, used=1block
00130    * - rdev=0
00131    * - nlink=1
00132    */
00133   fsal_attrib_mask_t supported = FSAL_ATTR_SUPPATTR | FSAL_ATTR_MODE | FSAL_ATTR_FILEID
00134       | FSAL_ATTR_TYPE | FSAL_ATTR_OWNER | FSAL_ATTR_GROUP
00135       | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME
00136       | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_SIZE
00137       | FSAL_ATTR_SPACEUSED | FSAL_ATTR_NUMLINKS | FSAL_ATTR_RAWDEV | FSAL_ATTR_FSID;
00138   fsal_attrib_mask_t unsupp;
00139 
00140   /* only those supported by filesystem */
00141   supported &= global_fs_info.supported_attrs;
00142 
00143   if(p_xattr_attrs->asked_attributes == 0)
00144     {
00145       p_xattr_attrs->asked_attributes = supported;
00146 
00147       LogCrit(COMPONENT_FSAL,
00148               "Error: p_xattr_attrs->asked_attributes was 0 in %s() line %d, file %s",
00149               __FUNCTION__, __LINE__, __FILE__);
00150     }
00151 
00152   unsupp = p_xattr_attrs->asked_attributes & (~supported);
00153 
00154   if(unsupp)
00155     {
00156       LogDebug(COMPONENT_FSAL,
00157                "Asking for unsupported attributes in %s(): %#llX removing it from asked attributes",
00158                __FUNCTION__, unsupp);
00159 
00160       p_xattr_attrs->asked_attributes &= (~unsupp);
00161     }
00162 
00163   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_SUPPATTR)
00164     p_xattr_attrs->supported_attributes = supported;
00165 
00166   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_MODE)
00167     {
00168       p_xattr_attrs->mode = file_attrs->mode & global_fs_info.xattr_access_rights;
00169       if(xattr_list[attr_index].flags & XATTR_RO)
00170         p_xattr_attrs->mode &= ~(0222);
00171     }
00172 
00173   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_FILEID)
00174     {
00175       unsigned int i;
00176       unsigned long hash = attr_index + 1;
00177       char *str = (char *)&file_attrs->fileid;
00178 
00179       for(i = 0; i < sizeof(p_xattr_attrs->fileid); i++, str++)
00180         {
00181           hash = (hash << 5) - hash + (unsigned long)(*str);
00182         }
00183       p_xattr_attrs->fileid = hash;
00184     }
00185 
00186   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_TYPE)
00187     p_xattr_attrs->type = FSAL_TYPE_XATTR;
00188 
00189   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_OWNER)
00190     p_xattr_attrs->owner = file_attrs->owner;
00191 
00192   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_GROUP)
00193     p_xattr_attrs->group = file_attrs->group;
00194 
00195   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_ATIME)
00196     p_xattr_attrs->atime = file_attrs->atime;
00197 
00198   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_MTIME)
00199     p_xattr_attrs->mtime = file_attrs->mtime;
00200 
00201   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_CTIME)
00202     p_xattr_attrs->ctime = file_attrs->ctime;
00203 
00204   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_CREATION)
00205     p_xattr_attrs->creation = file_attrs->creation;
00206 
00207   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_CHGTIME)
00208     {
00209       p_xattr_attrs->chgtime = file_attrs->chgtime;
00210       p_xattr_attrs->change = (uint64_t) file_attrs->chgtime.seconds;
00211     }
00212 
00213   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_SIZE)
00214     p_xattr_attrs->filesize = DEV_BSIZE;
00215 
00216   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_SPACEUSED)
00217     p_xattr_attrs->spaceused = DEV_BSIZE;
00218 
00219   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_NUMLINKS)
00220     p_xattr_attrs->numlinks = 1;
00221 
00222   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_RAWDEV)
00223     {
00224       p_xattr_attrs->rawdev.major = 0;
00225       p_xattr_attrs->rawdev.minor = 0;
00226     }
00227 
00228   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_FSID)
00229     {
00230       p_xattr_attrs->fsid = file_attrs->fsid;
00231     }
00232 
00233   /* if mode==0, then owner is set to root and mode is set to 0600 */
00234   if((p_xattr_attrs->asked_attributes & FSAL_ATTR_OWNER)
00235      && (p_xattr_attrs->asked_attributes & FSAL_ATTR_MODE) && (p_xattr_attrs->mode == 0))
00236     {
00237       p_xattr_attrs->owner = 0;
00238       p_xattr_attrs->mode = 0600;
00239       if(xattr_list[attr_index].flags & XATTR_RO)
00240         p_xattr_attrs->mode &= ~(0200);
00241     }
00242 
00243   return 0;
00244 
00245 }
00246 #endif
00247 
00256 fsal_status_t FUSEFSAL_GetXAttrAttrs(fsal_handle_t * p_objecthandle,        /* IN */
00257                                      fsal_op_context_t * p_context, /* IN */
00258                                      unsigned int xattr_id,     /* IN */
00259                                      fsal_attrib_list_t * p_attrs
00261     )
00262 {
00263   /* sanity checks */
00264   if(!p_objecthandle || !p_context || !p_attrs)
00265     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrAttrs);
00266 
00267   /* @todo: to be implemented */
00268 
00269   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_GetXAttrAttrs);
00270 }                               /* FSAL_GetXAttrAttrs */
00271 
00284 fsal_status_t FUSEFSAL_ListXAttrs(fsal_handle_t *obj_handle,   /* IN */
00285                                   unsigned int cookie,  /* IN */
00286                                   fsal_op_context_t * p_context,    /* IN */
00287                                   fsal_xattrent_t * xattrs_tab, /* IN/OUT */
00288                                   unsigned int xattrs_tabsize,  /* IN */
00289                                   unsigned int *p_nb_returned,  /* OUT */
00290                                   int *end_of_list      /* OUT */
00291     )
00292 {
00293 
00294   /* sanity checks */
00295   if(!obj_handle || !p_context || !xattrs_tab || !p_nb_returned || !end_of_list)
00296     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_ListXAttrs);
00297 
00298   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_ListXAttrs);
00299 }
00300 
00311 fsal_status_t FUSEFSAL_GetXAttrValueById(fsal_handle_t * p_objecthandle,    /* IN */
00312                                          unsigned int xattr_id, /* IN */
00313                                          fsal_op_context_t * p_context,     /* IN */
00314                                          caddr_t buffer_addr,   /* IN/OUT */
00315                                          size_t buffer_size,    /* IN */
00316                                          size_t * p_output_size /* OUT */
00317     )
00318 {
00319   /* sanity checks */
00320   if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr)
00321     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);
00322 
00323   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_GetXAttrValue);
00324 }
00325 
00335 fsal_status_t FUSEFSAL_GetXAttrIdByName(fsal_handle_t * p_objecthandle,     /* IN */
00336                                         const fsal_name_t * xattr_name, /* IN */
00337                                         fsal_op_context_t * p_context,      /* IN */
00338                                         unsigned int *pxattr_id /* OUT */
00339     )
00340 {
00341   /* sanity checks */
00342   if(!p_objecthandle || !xattr_name)
00343     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);
00344 
00345   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_GetXAttrValue);
00346 }                               /* FSAL_GetXAttrIdByName */
00347 
00358 fsal_status_t FUSEFSAL_GetXAttrValueByName(fsal_handle_t * p_objecthandle,  /* IN */
00359                                            const fsal_name_t * xattr_name,      /* IN */
00360                                            fsal_op_context_t * p_context,   /* IN */
00361                                            caddr_t buffer_addr, /* IN/OUT */
00362                                            size_t buffer_size,  /* IN */
00363                                            size_t * p_output_size       /* OUT */
00364     )
00365 {
00366   /* sanity checks */
00367   if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr || !xattr_name)
00368     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);
00369 
00370   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_GetXAttrValue);
00371 }
00372 
00373 fsal_status_t FUSEFSAL_SetXAttrValue(fsal_handle_t * p_objecthandle,        /* IN */
00374                                      const fsal_name_t * xattr_name,    /* IN */
00375                                      fsal_op_context_t * p_context, /* IN */
00376                                      caddr_t buffer_addr,       /* IN */
00377                                      size_t buffer_size,        /* IN */
00378                                      int create /* IN */
00379     )
00380 {
00381   Return(ERR_FSAL_PERM, 0, INDEX_FSAL_SetXAttrValue);
00382 }
00383 
00384 fsal_status_t FUSEFSAL_SetXAttrValueById(fsal_handle_t * p_objecthandle,    /* IN */
00385                                          unsigned int xattr_id, /* IN */
00386                                          fsal_op_context_t * p_context,     /* IN */
00387                                          caddr_t buffer_addr,   /* IN */
00388                                          size_t buffer_size     /* IN */
00389     )
00390 {
00391   Return(ERR_FSAL_PERM, 0, INDEX_FSAL_SetXAttrValue);
00392 }
00393 
00401 fsal_status_t FUSEFSAL_RemoveXAttrById(fsal_handle_t * p_objecthandle,      /* IN */
00402                                        fsal_op_context_t * p_context,       /* IN */
00403                                        unsigned int xattr_id)   /* IN */
00404 {
00405   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00406 }                               /* FSAL_RemoveXAttrById */
00407 
00415 fsal_status_t FUSEFSAL_RemoveXAttrByName(fsal_handle_t * p_objecthandle,    /* IN */
00416                                          fsal_op_context_t * p_context,     /* IN */
00417                                          const fsal_name_t * xattr_name)        /* IN */
00418 {
00419   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00420 }                               /* FSAL_RemoveXAttrById */
00421