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 
00017 #include <string.h>
00018 #include <time.h>
00019 
00020 /* generic definitions for extended attributes */
00021 
00022 #define XATTR_FOR_FILE     0x00000001
00023 #define XATTR_FOR_DIR      0x00000002
00024 #define XATTR_FOR_SYMLINK  0x00000004
00025 #define XATTR_FOR_ALL      0x0000000F
00026 #define XATTR_RO           0x00000100
00027 #define XATTR_RW           0x00000200
00028 
00029 /* function for getting an attribute value */
00030 
00031 typedef int (*xattr_getfunc_t) (posixfsal_handle_t *,   /* object handle */
00032                                 posixfsal_op_context_t *,       /* context */
00033                                 caddr_t,        /* output buff */
00034                                 size_t, /* output buff size */
00035                                 size_t *);      /* output size */
00036 
00037 typedef int (*xattr_setfunc_t) (posixfsal_handle_t *,   /* object handle */
00038                                 posixfsal_op_context_t *,       /* context */
00039                                 caddr_t,        /* input buff */
00040                                 size_t, /* input size */
00041                                 int);   /* creation flag */
00042 
00043 typedef int (*xattr_printfunc_t) (caddr_t,      /* Input buffer */
00044                                   size_t,       /* Input size   */
00045                                   caddr_t,      /* Output (ASCII) buffer */
00046                                   size_t *);    /* Output size */
00047 
00048 typedef struct fsal_xattr_def__
00049 {
00050   char xattr_name[FSAL_MAX_NAME_LEN];
00051   xattr_getfunc_t get_func;
00052   xattr_setfunc_t set_func;
00053   xattr_printfunc_t print_func;
00054   int flags;
00055 } fsal_xattr_def_t;
00056 
00057 /*
00058  * DEFINE GET/SET FUNCTIONS
00059  */
00060 
00061 int get_fsalid(posixfsal_handle_t * p_objecthandle,     /* IN */
00062                posixfsal_op_context_t * p_context,      /* IN */
00063                caddr_t buffer_addr,     /* IN/OUT */
00064                size_t buffer_size,      /* IN */
00065                size_t * p_output_size)  /* OUT */
00066 {
00067   if(!p_objecthandle || !p_context || !p_output_size)
00068     return ERR_FSAL_FAULT;
00069 
00070   /* assuming buffer size is large enough for an int ! */
00071 
00072   memcpy(buffer_addr, &p_objecthandle->data.id, sizeof(p_objecthandle->data.id));
00073   *p_output_size = sizeof(p_objecthandle->data.id);
00074 
00075   return 0;
00076 
00077 }
00078 
00079 int print_fsalid(caddr_t InBuff, size_t InSize, caddr_t OutBuff, size_t * pOutSize)
00080 {
00081   fsal_u64_t fsalid = 0LL;
00082 
00083   memcpy((char *)&fsalid, InBuff, sizeof(fsalid));
00084 
00085   *pOutSize = snprintf(OutBuff, *pOutSize, "%llu", fsalid);
00086   return 0;
00087 }                               /* print_file_fsalid */
00088 
00089 int get_timestamp(posixfsal_handle_t * p_objecthandle,  /* IN */
00090                   posixfsal_op_context_t * p_context,   /* IN */
00091                   caddr_t buffer_addr,  /* IN/OUT */
00092                   size_t buffer_size,   /* IN */
00093                   size_t * p_output_size)       /* OUT */
00094 {
00095   if(!p_objecthandle || !p_context || !p_output_size)
00096     return ERR_FSAL_FAULT;
00097 
00098   /* assuming buffer size is large enough for an int ! */
00099 
00100   memcpy(buffer_addr, &p_objecthandle->data.ts, sizeof(p_objecthandle->data.ts));
00101   *p_output_size = sizeof(p_objecthandle->data.ts);
00102 
00103   return 0;
00104 
00105 }
00106 
00107 int print_timestamp(caddr_t InBuff, size_t InSize, caddr_t OutBuff, size_t * pOutSize)
00108 {
00109   unsigned int date = 0;
00110 
00111   memcpy((char *)&date, InBuff, sizeof(date));
00112 
00113   /* localtime_r( &date, &date_tm ) ;
00114 
00115    *pOutSize = strftime( OutBuff, *pOutSize, "%F %T", &date_tm ) ; */
00116   *pOutSize = snprintf(OutBuff, *pOutSize, "%u", date);
00117 
00118   return 0;
00119 }                               /* print_file_cos */
00120 
00121 int get_deviceid(posixfsal_handle_t * p_objecthandle,   /* IN */
00122                  posixfsal_op_context_t * p_context,    /* IN */
00123                  caddr_t buffer_addr,   /* IN/OUT */
00124                  size_t buffer_size,    /* IN */
00125                  size_t * p_output_size)        /* OUT */
00126 {
00127   fsal_status_t status;
00128   fsal_path_t fsalpath;
00129   struct stat buffstat;
00130 
00131   if(!p_objecthandle || !p_context || !p_output_size)
00132     return ERR_FSAL_FAULT;
00133 
00134   /* this retrieves device and inode from database */
00135 
00136   status =
00137       fsal_internal_getPathFromHandle(p_context, p_objecthandle, 0, &fsalpath, &buffstat);
00138 
00139   if(FSAL_IS_ERROR(status))
00140     return status.major;
00141 
00142   /* assuming buffer size is large enough for an int ! */
00143 
00144   memcpy(buffer_addr, &p_objecthandle->data.info.devid, sizeof(dev_t));
00145   *p_output_size = sizeof(dev_t);
00146 
00147   return 0;
00148 
00149 }
00150 
00151 int print_deviceid(caddr_t InBuff, size_t InSize, caddr_t OutBuff, size_t * pOutSize)
00152 {
00153   unsigned long devid = 0LL;
00154 
00155   memcpy((char *)&devid, InBuff, sizeof(devid));
00156 
00157   *pOutSize = snprintf(OutBuff, *pOutSize, "%lu", devid);
00158   return 0;
00159 }                               /* print_file_devid */
00160 
00161 int get_inode(posixfsal_handle_t * p_objecthandle,      /* IN */
00162               posixfsal_op_context_t * p_context,       /* IN */
00163               caddr_t buffer_addr,      /* IN/OUT */
00164               size_t buffer_size,       /* IN */
00165               size_t * p_output_size)   /* OUT */
00166 {
00167   fsal_status_t status;
00168   fsal_path_t fsalpath;
00169   struct stat buffstat;
00170 
00171   if(!p_objecthandle || !p_context || !p_output_size)
00172     return ERR_FSAL_FAULT;
00173 
00174   /* this retrieves device and inode from database */
00175 
00176   status =
00177       fsal_internal_getPathFromHandle(p_context, p_objecthandle, 0, &fsalpath, &buffstat);
00178 
00179   if(FSAL_IS_ERROR(status))
00180     return status.major;
00181 
00182   /* assuming buffer size is large enough for an int ! */
00183 
00184   memcpy(buffer_addr, &p_objecthandle->data.info.inode, sizeof(ino_t));
00185   *p_output_size = sizeof(ino_t);
00186 
00187   return 0;
00188 }
00189 
00190 int print_inode(caddr_t InBuff, size_t InSize, caddr_t OutBuff, size_t * pOutSize)
00191 {
00192   fsal_u64_t inode = 0LL;
00193 
00194   memcpy((char *)&inode, InBuff, sizeof(inode));
00195 
00196   *pOutSize = snprintf(OutBuff, *pOutSize, "%llu", inode);
00197   return 0;
00198 }                               /* print_file_inode */
00199 
00200 int get_objtype(posixfsal_handle_t * p_objecthandle,    /* IN */
00201                 posixfsal_op_context_t * p_context,     /* IN */
00202                 caddr_t buffer_addr,    /* IN/OUT */
00203                 size_t buffer_size,     /* IN */
00204                 size_t * p_output_size) /* OUT */
00205 {
00206   if(!p_objecthandle || !p_context || !p_output_size)
00207     return ERR_FSAL_FAULT;
00208 
00209   switch (p_objecthandle->data.info.ftype)
00210     {
00211     case FSAL_TYPE_DIR:
00212       strncpy((char *)buffer_addr, "directory", buffer_size);
00213       break;
00214 
00215     case FSAL_TYPE_FILE:
00216       strncpy((char *)buffer_addr, "file", buffer_size);
00217       break;
00218 
00219     case FSAL_TYPE_LNK:
00220       strncpy((char *)buffer_addr, "symlink", buffer_size);
00221       break;
00222 
00223     case FSAL_TYPE_JUNCTION:
00224       strncpy((char *)buffer_addr, "junction", buffer_size);
00225       break;
00226 
00227     default:
00228       strncpy((char *)buffer_addr, "other/unknown", buffer_size);
00229       break;
00230     }
00231   ((char *)buffer_addr)[strlen((char *)buffer_addr)] = '\n';
00232   *p_output_size = strlen((char *)buffer_addr) + 1;
00233   return 0;
00234 
00235 }
00236 
00237 int get_path(posixfsal_handle_t * p_objecthandle,       /* IN */
00238              posixfsal_op_context_t * p_context,        /* IN */
00239              caddr_t buffer_addr,       /* IN/OUT */
00240              size_t buffer_size,        /* IN */
00241              size_t * p_output_size)    /* OUT */
00242 {
00243   fsal_status_t status;
00244   fsal_path_t fsalpath;
00245   struct stat buffstat;
00246 
00247   if(!p_objecthandle || !p_context || !p_output_size)
00248     return ERR_FSAL_FAULT;
00249 
00250   status =
00251       fsal_internal_getPathFromHandle(p_context, p_objecthandle, 0, &fsalpath, &buffstat);
00252 
00253   if(FSAL_IS_ERROR(status))
00254     return status.major;
00255 
00256   strncpy(buffer_addr, fsalpath.path, buffer_size);
00257   *p_output_size = strlen((char *)buffer_addr) + 1;
00258 
00259   return 0;
00260 
00261 }
00262 
00263 /* DEFINE HERE YOUR ATTRIBUTES LIST */
00264 
00265 static fsal_xattr_def_t xattr_list[] = {
00266   {"device_id", get_deviceid, NULL, print_deviceid, XATTR_FOR_ALL | XATTR_RO},
00267   {"inode", get_inode, NULL, print_inode, XATTR_FOR_ALL | XATTR_RO},
00268   {"path", get_path, NULL, NULL, XATTR_FOR_ALL | XATTR_RO},
00269   {"fsal_object_id", get_fsalid, NULL, print_fsalid, XATTR_FOR_ALL | XATTR_RO},
00270   {"timestamp", get_timestamp, NULL, print_timestamp, XATTR_FOR_ALL | XATTR_RO},
00271   {"type", get_objtype, NULL, NULL, XATTR_FOR_ALL | XATTR_RO}
00272 };
00273 
00274 #define XATTR_COUNT 6
00275 
00276 /* we assume that this number is < 254 */
00277 #if ( XATTR_COUNT > 254 )
00278 #error "ERROR: xattr count > 254"
00279 #endif
00280 
00281 /* YOUR SHOULD NOT HAVE TO MODIFY THE FOLLOWING FUNCTIONS */
00282 
00283 /* test if an object has a given attribute */
00284 int do_match_type(int xattr_flag, fsal_nodetype_t obj_type)
00285 {
00286   switch (obj_type)
00287     {
00288     case FSAL_TYPE_FILE:
00289       return ((xattr_flag & XATTR_FOR_FILE) == XATTR_FOR_FILE);
00290 
00291     case FSAL_TYPE_DIR:
00292       return ((xattr_flag & XATTR_FOR_DIR) == XATTR_FOR_DIR);
00293 
00294     case FSAL_TYPE_LNK:
00295       return ((xattr_flag & XATTR_FOR_SYMLINK) == XATTR_FOR_SYMLINK);
00296 
00297     default:
00298       return ((xattr_flag & XATTR_FOR_ALL) == XATTR_FOR_ALL);
00299     }
00300 }
00301 
00302 static int file_attributes_to_xattr_attrs(fsal_attrib_list_t * file_attrs,
00303                                           fsal_attrib_list_t * p_xattr_attrs,
00304                                           unsigned int attr_index)
00305 {
00306 
00307   /* supported attributes are:
00308    * - owner (same as the objet)
00309    * - group (same as the objet)
00310    * - type FSAL_TYPE_XATTR
00311    * - fileid (attr index ? or (fileid^((index+1)<<24)) )
00312    * - mode (config & file)
00313    * - atime, mtime, ctime = these of the object ?
00314    * - size=1block, used=1block
00315    * - rdev=0
00316    * - nlink=1
00317    */
00318   fsal_attrib_mask_t supported = FSAL_ATTR_SUPPATTR | FSAL_ATTR_MODE | FSAL_ATTR_FILEID
00319       | FSAL_ATTR_TYPE | FSAL_ATTR_OWNER | FSAL_ATTR_GROUP
00320       | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME
00321       | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_SIZE
00322       | FSAL_ATTR_SPACEUSED | FSAL_ATTR_NUMLINKS | FSAL_ATTR_RAWDEV | FSAL_ATTR_FSID;
00323   fsal_attrib_mask_t unsupp;
00324 
00325   /* only those supported by filesystem */
00326   supported &= global_fs_info.supported_attrs;
00327 
00328   if(p_xattr_attrs->asked_attributes == 0)
00329     {
00330       p_xattr_attrs->asked_attributes = supported;
00331 
00332       LogCrit(COMPONENT_FSAL,
00333               "Error: p_xattr_attrs->asked_attributes was 0 in %s() line %d, file %s",
00334               __FUNCTION__, __LINE__, __FILE__);
00335     }
00336 
00337   unsupp = p_xattr_attrs->asked_attributes & (~supported);
00338 
00339   if(unsupp)
00340     {
00341       LogDebug(COMPONENT_FSAL,
00342                "Asking for unsupported attributes in %s(): %#llX removing it from asked attributes",
00343                __FUNCTION__, unsupp);
00344 
00345       p_xattr_attrs->asked_attributes &= (~unsupp);
00346     }
00347 
00348   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_SUPPATTR)
00349     p_xattr_attrs->supported_attributes = supported;
00350 
00351   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_MODE)
00352     {
00353       p_xattr_attrs->mode = file_attrs->mode & global_fs_info.xattr_access_rights;
00354       if(xattr_list[attr_index].flags & XATTR_RO)
00355         p_xattr_attrs->mode &= ~(0222);
00356     }
00357 
00358   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_FILEID)
00359     {
00360       unsigned int i;
00361       unsigned long hash = attr_index + 1;
00362       char *str = (char *)&file_attrs->fileid;
00363 
00364       for(i = 0; i < sizeof(p_xattr_attrs->fileid); i++, str++)
00365         {
00366           hash = (hash << 5) - hash + (unsigned long)(*str);
00367         }
00368       p_xattr_attrs->fileid = hash;
00369     }
00370 
00371   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_TYPE)
00372     p_xattr_attrs->type = FSAL_TYPE_XATTR;
00373 
00374   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_OWNER)
00375     p_xattr_attrs->owner = file_attrs->owner;
00376 
00377   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_GROUP)
00378     p_xattr_attrs->group = file_attrs->group;
00379 
00380   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_ATIME)
00381     p_xattr_attrs->atime = file_attrs->atime;
00382 
00383   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_MTIME)
00384     p_xattr_attrs->mtime = file_attrs->mtime;
00385 
00386   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_CTIME)
00387     p_xattr_attrs->ctime = file_attrs->ctime;
00388 
00389   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_CREATION)
00390     p_xattr_attrs->creation = file_attrs->creation;
00391 
00392   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_CHGTIME)
00393     {
00394       p_xattr_attrs->chgtime = file_attrs->chgtime;
00395       p_xattr_attrs->change = (uint64_t) p_xattr_attrs->chgtime.seconds;
00396     }
00397 
00398   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_SIZE)
00399     p_xattr_attrs->filesize = DEV_BSIZE;
00400 
00401   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_SPACEUSED)
00402     p_xattr_attrs->spaceused = DEV_BSIZE;
00403 
00404   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_NUMLINKS)
00405     p_xattr_attrs->numlinks = 1;
00406 
00407   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_RAWDEV)
00408     {
00409       p_xattr_attrs->rawdev.major = 0;
00410       p_xattr_attrs->rawdev.minor = 0;
00411     }
00412 
00413   if(p_xattr_attrs->asked_attributes & FSAL_ATTR_FSID)
00414     {
00415       p_xattr_attrs->fsid = file_attrs->fsid;
00416     }
00417 
00418   /* if mode==0, then owner is set to root and mode is set to 0600 */
00419   if((p_xattr_attrs->asked_attributes & FSAL_ATTR_OWNER)
00420      && (p_xattr_attrs->asked_attributes & FSAL_ATTR_MODE) && (p_xattr_attrs->mode == 0))
00421     {
00422       p_xattr_attrs->owner = 0;
00423       p_xattr_attrs->mode = 0600;
00424       if(xattr_list[attr_index].flags & XATTR_RO)
00425         p_xattr_attrs->mode &= ~(0200);
00426     }
00427 
00428   return 0;
00429 
00430 }
00431 
00440 fsal_status_t POSIXFSAL_GetXAttrAttrs(fsal_handle_t * objecthandle,      /* IN */
00441                                       fsal_op_context_t * context,       /* IN */
00442                                       unsigned int xattr_id,    /* IN */
00443                                       fsal_attrib_list_t * p_attrs
00445     )
00446 {
00447   posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
00448   posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
00449   int rc;
00450   fsal_status_t st;
00451   fsal_attrib_list_t file_attrs;
00452 
00453   /* sanity checks */
00454   if(!p_objecthandle || !p_context || !p_attrs)
00455     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrAttrs);
00456 
00457   /* check that this index match the type of entry */
00458   if(xattr_id >= XATTR_COUNT
00459      || !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->data.info.ftype))
00460     {
00461       Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrAttrs);
00462     }
00463 
00464   /* object attributes we want to retrieve from parent */
00465   file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
00466       | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME
00467       | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;
00468 
00469   /* don't retrieve attributes not asked */
00470 
00471   file_attrs.asked_attributes &= p_attrs->asked_attributes;
00472 
00473   st = POSIXFSAL_getattrs(objecthandle, context, &file_attrs);
00474 
00475   if(FSAL_IS_ERROR(st))
00476     Return(st.major, st.minor, INDEX_FSAL_GetXAttrAttrs);
00477 
00478   if((rc = file_attributes_to_xattr_attrs(&file_attrs, p_attrs, xattr_id)))
00479     {
00480       Return(ERR_FSAL_INVAL, rc, INDEX_FSAL_GetXAttrAttrs);
00481     }
00482 
00483   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrAttrs);
00484 
00485 }                               /* FSAL_GetXAttrAttrs */
00486 
00499 fsal_status_t POSIXFSAL_ListXAttrs(fsal_handle_t * objecthandle, /* IN */
00500                                    unsigned int argcookie, /* IN */
00501                                    fsal_op_context_t * context,  /* IN */
00502                                    fsal_xattrent_t * xattrs_tab,        /* IN/OUT */
00503                                    unsigned int xattrs_tabsize, /* IN */
00504                                    unsigned int *p_nb_returned, /* OUT */
00505                                    int *end_of_list     /* OUT */
00506     )
00507 {
00508   posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
00509   posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
00510   unsigned int index;
00511   unsigned int out_index;
00512   fsal_status_t st;
00513   fsal_attrib_list_t file_attrs;
00514   unsigned int cookie = argcookie ;
00515 
00516   /* sanity checks */
00517   if(!p_objecthandle || !p_context || !xattrs_tab || !p_nb_returned || !end_of_list)
00518     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_ListXAttrs);
00519 
00520   /* Deal with special cookie */
00521   if( argcookie == FSAL_XATTR_RW_COOKIE ) cookie = XATTR_COUNT ;
00522 
00523   /* object attributes we want to retrieve from parent */
00524   file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
00525       | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME
00526       | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;
00527 
00528   /* don't retrieve unsuipported attributes */
00529   file_attrs.asked_attributes &= global_fs_info.supported_attrs;
00530 
00531   st = POSIXFSAL_getattrs(objecthandle, context, &file_attrs);
00532 
00533   if(FSAL_IS_ERROR(st))
00534     Return(st.major, st.minor, INDEX_FSAL_ListXAttrs);
00535 
00536   for(index = cookie, out_index = 0;
00537       index < XATTR_COUNT && out_index < xattrs_tabsize; index++)
00538     {
00539       if(do_match_type(xattr_list[index].flags, p_objecthandle->data.info.ftype))
00540         {
00541           /* fills an xattr entry */
00542           xattrs_tab[out_index].xattr_id = index;
00543           FSAL_str2name(xattr_list[index].xattr_name, FSAL_MAX_NAME_LEN,
00544                         &xattrs_tab[out_index].xattr_name);
00545           xattrs_tab[out_index].xattr_cookie = index + 1;
00546 
00547           /* set asked attributes (all supported) */
00548           xattrs_tab[out_index].attributes.asked_attributes =
00549               global_fs_info.supported_attrs;
00550 
00551           if(file_attributes_to_xattr_attrs
00552              (&file_attrs, &xattrs_tab[out_index].attributes, index))
00553             {
00554               /* set error flag */
00555               xattrs_tab[out_index].attributes.asked_attributes = FSAL_ATTR_RDATTR_ERR;
00556             }
00557 
00558           /* next output slot */
00559           out_index++;
00560         }
00561     }
00562 
00563   *p_nb_returned = out_index;
00564   *end_of_list = (index == XATTR_COUNT);
00565 
00566   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_ListXAttrs);
00567 
00568 }
00569 
00580 fsal_status_t POSIXFSAL_GetXAttrValueById(fsal_handle_t * objecthandle,  /* IN */
00581                                           unsigned int xattr_id,        /* IN */
00582                                           fsal_op_context_t * context,   /* IN */
00583                                           caddr_t buffer_addr,  /* IN/OUT */
00584                                           size_t buffer_size,   /* IN */
00585                                           size_t * p_output_size        /* OUT */
00586     )
00587 {
00588   posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
00589   posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
00590   int rc;
00591   char buff[MAXNAMLEN];
00592 
00593   /* sanity checks */
00594   if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr)
00595     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);
00596 
00597   /* check that this index match the type of entry */
00598   if(xattr_id >= XATTR_COUNT
00599      || !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->data.info.ftype))
00600     {
00601       Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrValue);
00602     }
00603 
00604   /* get the value */
00605   if(xattr_list[xattr_id].print_func == NULL)
00606     {
00607       rc = xattr_list[xattr_id].get_func(p_objecthandle,
00608                                          p_context,
00609                                          buffer_addr, buffer_size, p_output_size);
00610     }
00611   else
00612     {
00613       rc = xattr_list[xattr_id].get_func(p_objecthandle,
00614                                          p_context, buff, MAXNAMLEN, p_output_size);
00615 
00616       xattr_list[xattr_id].print_func(buff, MAXNAMLEN, buffer_addr, p_output_size);
00617     }
00618 
00619   Return(rc, 0, INDEX_FSAL_GetXAttrValue);
00620 }
00621 
00632 fsal_status_t POSIXFSAL_GetXAttrIdByName(fsal_handle_t * objecthandle,   /* IN */
00633                                          const fsal_name_t * xattr_name, /* IN */
00634                                          fsal_op_context_t * context,    /* IN */
00635                                          unsigned int *pxattr_id        /* OUT */
00636     )
00637 {
00638   posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
00639   unsigned int index;
00640   int found = FALSE;
00641 
00642   /* sanity checks */
00643   if(!p_objecthandle || !xattr_name)
00644     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);
00645 
00646   for(index = 0; index < XATTR_COUNT; index++)
00647     {
00648       if(do_match_type(xattr_list[index].flags, p_objecthandle->data.info.ftype)
00649          && !strcmp(xattr_list[index].xattr_name, xattr_name->name))
00650         {
00651           found = TRUE;
00652           break;
00653         }
00654     }
00655 
00656   if(found)
00657     {
00658       *pxattr_id = index;
00659       Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrValue);
00660     }
00661   else
00662     Return(ERR_FSAL_NOENT, ENOENT, INDEX_FSAL_GetXAttrValue);
00663 }                               /* FSAL_GetXAttrIdByName */
00664 
00675 fsal_status_t POSIXFSAL_GetXAttrValueByName(fsal_handle_t * objecthandle,   /* IN */
00676                                             const fsal_name_t * xattr_name, /* IN */
00677                                             fsal_op_context_t * context, /* IN */
00678                                             caddr_t buffer_addr,        /* IN/OUT */
00679                                             size_t buffer_size, /* IN */
00680                                             size_t * p_output_size      /* OUT */
00681     )
00682 {
00683   posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
00684   posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
00685   unsigned int index;
00686 
00687   /* sanity checks */
00688   if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr || !xattr_name)
00689     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);
00690 
00691   /* look for this name */
00692 
00693   for(index = 0; index < XATTR_COUNT; index++)
00694     {
00695       if(do_match_type(xattr_list[index].flags, p_objecthandle->data.info.ftype)
00696          && !strcmp(xattr_list[index].xattr_name, xattr_name->name))
00697         {
00698 
00699           return POSIXFSAL_GetXAttrValueById(objecthandle, index, context,
00700                                              buffer_addr, buffer_size, p_output_size);
00701 
00702         }
00703     }
00704 
00705   /* not found */
00706   Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_GetXAttrValue);
00707 
00708 }
00709 
00710 fsal_status_t POSIXFSAL_SetXAttrValue(fsal_handle_t * p_objecthandle,      /* IN */
00711                                       const fsal_name_t * xattr_name,   /* IN */
00712                                       fsal_op_context_t * p_context,       /* IN */
00713                                       caddr_t buffer_addr,      /* IN */
00714                                       size_t buffer_size,       /* IN */
00715                                       int create        /* IN */
00716     )
00717 {
00718   Return(ERR_FSAL_PERM, 0, INDEX_FSAL_SetXAttrValue);
00719 }
00720 
00721 fsal_status_t POSIXFSAL_SetXAttrValueById(fsal_handle_t * p_objecthandle,  /* IN */
00722                                           unsigned int xattr_id,        /* IN */
00723                                           fsal_op_context_t * p_context,   /* IN */
00724                                           caddr_t buffer_addr,  /* IN */
00725                                           size_t buffer_size    /* IN */
00726     )
00727 {
00728   Return(ERR_FSAL_PERM, 0, INDEX_FSAL_SetXAttrValue);
00729 }
00730 
00738 fsal_status_t POSIXFSAL_RemoveXAttrById(fsal_handle_t * p_objecthandle,    /* IN */
00739                                         fsal_op_context_t * p_context,     /* IN */
00740                                         unsigned int xattr_id)  /* IN */
00741 {
00742   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00743 }                               /* FSAL_RemoveXAttrById */
00744 
00752 fsal_status_t POSIXFSAL_RemoveXAttrByName(fsal_handle_t * p_objecthandle,  /* IN */
00753                                           fsal_op_context_t * p_context,   /* IN */
00754                                           const fsal_name_t * xattr_name)       /* IN */
00755 {
00756   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00757 }                               /* FSAL_RemoveXAttrByName */
00758 
00759 int POSIXFSAL_GetXattrOffsetSetable( void )
00760 {
00761   return XATTR_COUNT ;
00762 }