nfs-ganesha 1.4

api_fgetattr.c

Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include "config.h"
00003 #endif
00004 #include "hpssclapiext.h"
00005 #include <sys/types.h>
00006 #include <sys/stat.h>
00007 #include <fcntl.h>
00008 #include <unistd.h>
00009 #include <u_signed64.h>
00010 #include <api_internal.h>
00011 #include <ss_pvlist.h>
00012 
00013 /*
00014  * The BFS needs to add this somewhere
00015  */
00016 
00017 #define BFS_SET_MAX (32)
00018 
00019 /*
00020  * Macro to retrieve size of PV list
00021  */
00022 
00023 #define SIZEOF_PVLIST(N) \
00024    (sizeof(pv_list_t)+((N)-1)*sizeof(pv_list_element_t))
00025 
00026 /*
00027  * Local function definition
00028  */
00029 
00030 static int HPSSFSAL_Common_FileGetAttributes(apithrdstate_t * ThreadContext,    /* IN - thread context */
00031                                              ns_ObjHandle_t * ObjHandle,        /* IN - parent object handle */
00032                                              char *Path,        /* IN - path to the object */
00033                                              api_cwd_stack_t * CwdStack,        /* IN - cwd stack */
00034                                              hpss_reqid_t RequestID,    /* IN - request id */
00035                                              unsigned32 Flags,  /* IN - flags for storage attrs */
00036                                              unsigned32 ChaseFlags,     /* IN - whether to chase symlinks/junctions */
00037                                              unsigned32 StorageLevel,   /* IN - storage level to query  */
00038                                              TYPE_CRED_HPSS * Ucred,    /* IN - user credentials */
00039                                              TYPE_TOKEN_HPSS * AuthzTicket,     /* OUT - authorization ticket */
00040                                              hpss_fileattr_t * AttrOut, /* OUT - attributes after query */
00041                                              hpss_xfileattr_t * XAttrOut);      /* OUT - xattributes after query */
00042 
00043 /*============================================================================
00044  *
00045  * Function:    hpss_GetRawAttrHandle
00046  *
00047  * Synopsis:
00048  *
00049  * int
00050  * hpss_GetRawAttrHandle(
00051  * ns_ObjHandle_t       *ObjHandle,     ** IN - parent object handle
00052  * char                 *Path,          ** IN - path of file to get attributes
00053  * hsec_UserCred        *Ucred,         ** IN - user credentials
00054  * int                  traverse_junction, ** IN - boolean for junction traversal
00055  * ns_ObjHandle_t       *HandleOut,     ** OUT - returned object handle
00056  * gss_token_t          *AuthzTicket,   ** OUT - returned authorization
00057  * hpss_vattr_t         *AttrOut)       ** OUT - returned attributes
00058  *
00059  * Description:
00060  *
00061  *      The 'hpss_GetRawAttrHandle' function obtains information about the 
00062  *      symlink or the junction named by 'Path', taken relative to the 
00063  *      directory indicated by 'ObjHandle'.  Attributes are returned in the 
00064  *      area pointed to by 'AttrOut'.
00065  *
00066  * Other Inputs:
00067  *      None.
00068  *
00069  * Outputs:
00070  *              0               - No error.  Valid information returned.
00071  *
00072  * Interfaces:
00073  *      DCE pthreads, DCE/RPC, HPSSFSAL_Common_FileGetAttributes.
00074  *
00075  * Resources Used:
00076  *
00077  * Limitations:
00078  *
00079  * Assumptions:
00080  *
00081  * Notes:
00082  *
00083  *-------------------------------------------------------------------------*/
00084 
00085 int HPSSFSAL_GetRawAttrHandle(ns_ObjHandle_t * ObjHandle,       /* IN - parent object handle */
00086                               char *Path,       /* IN - path of junction to get attributes */
00087                               TYPE_CRED_HPSS * Ucred,   /* IN - user credentials */
00088                               int traverse_junction,
00090                               ns_ObjHandle_t * HandleOut,       /* OUT - returned object handle */
00091                               TYPE_TOKEN_HPSS * AuthzTicket,    /* OUT - returned authorization */
00092                               hpss_Attrs_t * AttrsOut)  /* OUT - returned attributes */
00093 {
00094   static char function_name[] = "hpss_GetRawAttrHandle";
00095   long error = 0;               /* return error */
00096   apithrdstate_t *threadcontext;        /* thread context */
00097   TYPE_CRED_HPSS *ucred_ptr;    /* user credentials */
00098   hpss_fileattr_t file_attrs_out;       /* file attributes out */
00099   hpss_reqid_t rqstid;          /* request id */
00100 
00101   API_ENTER(function_name);
00102 
00103   /*
00104    *  Initialize the thread if not already initialized.
00105    *  Get a pointer back to the thread specific context.
00106    */
00107 
00108   error = API_ClientAPIInit(&threadcontext);
00109   if(error != 0)
00110     API_RETURN(error);
00111 
00112   /*
00113    *  Check that the object handle is not NULL.
00114    */
00115 
00116   if(ObjHandle == (ns_ObjHandle_t *) NULL)
00117     API_RETURN(-EINVAL);
00118 
00119   /*
00120    *  Check that the pathname the string is not the NULL string.
00121    */
00122 
00123   if(Path != NULL && *Path == '\0')
00124     API_RETURN(-ENOENT);
00125 
00126   /*
00127    *  If user credentials were not passed, use the ones in the
00128    *  current thread context.
00129    */
00130 
00131   if(Ucred == (TYPE_CRED_HPSS *) NULL)
00132     ucred_ptr = &threadcontext->UserCred;
00133   else
00134     ucred_ptr = Ucred;
00135 
00136   /*
00137    *  Generate a unique request id.
00138    */
00139 
00140   rqstid = API_GetUniqueRequestID();
00141 
00142   /*
00143    * Call the common routine to do most of the get attribute
00144    * processing
00145    */
00146 
00147   error = HPSSFSAL_Common_FileGetAttributes(threadcontext,
00148                                             ObjHandle,
00149                                             Path,
00150                                             API_NULL_CWD_STACK,
00151                                             rqstid,
00152                                             0,
00153                                             (traverse_junction ? API_CHASE_JUNCTION :
00154                                              API_CHASE_NONE), 0, ucred_ptr, AuthzTicket,
00155                                             &file_attrs_out, (hpss_xfileattr_t *) NULL);
00156 
00157   /*
00158    * WE DON'T WANT TO Convert the HPSS attributes to HPSS VFS attributes !!!
00159    */
00160 
00161   if(AttrsOut != (hpss_Attrs_t *) NULL)
00162     {
00163       *AttrsOut = file_attrs_out.Attrs;
00164     }
00165 
00166   if(HandleOut != (ns_ObjHandle_t *) NULL)
00167     {
00168       *HandleOut = file_attrs_out.ObjectHandle;
00169     }
00170 
00171   API_RETURN(error);
00172 }
00173 
00174 /*============================================================================
00175  *
00176  * Function:    HPSSFSAL_Common_FileGetAttributes
00177  *
00178  * Synopsis:
00179  *
00180  * int
00181  * HPSSFSAL_Common_FileGetAttributes(
00182  * apithrdstate_t       *ThreadContext, ** IN - thread context
00183  * ns_ObjHandle_t       *ObjHandle,     ** IN - parent object handle
00184  * char                 *Path,          ** IN - path to the object
00185  * api_cwd_stack_t      *CwdStack,      ** IN - cwd stack
00186  * unsigned32           RequestID,      ** IN - request id
00187  * unsigned32           Flags,          ** IN - flags for storage attrs
00188  * unsigned32           ChaseFlags,     ** IN - chase symlinks/junctions ?
00189  * unsigned32           StorageLevel,   ** IN - storage level to query
00190  * hsec_UserCred_t      *Ucred,         ** IN - user credentials
00191  * gss_token_t          *AuthzTicket,   ** OUT - authorization ticket
00192  * hpss_fileattr_t      *AttrOut,       ** OUT - attributes after query
00193  * hpss_xfileattr_t     *XAttrOut)      ** OUT - xattributes after query
00194  *
00195  * Description:
00196  *
00197  *      The HPSSFSAL_Common_FileGetAttributes function can be used to query attributes
00198  *      on an entry in the name/file system that is refered to by 'ObjHandle'
00199  *      and 'Path'.
00200  *
00201  * Other Inputs:
00202  *      None.
00203  *
00204  * Outputs:
00205  *              0 -             No error, caller has access.
00206  *
00207  * Interfaces:
00208  *      DCE pthreads, DCE/RPC, API_TraversePath.
00209  *
00210  * Resources Used:
00211  *
00212  * Limitations:
00213  *
00214  * Assumptions:
00215  *
00216  * Notes:
00217  *
00218  *-------------------------------------------------------------------------*/
00219 
00220 static int HPSSFSAL_Common_FileGetAttributes(apithrdstate_t * ThreadContext,    /* IN - thread context */
00221                                              ns_ObjHandle_t * ObjHandle,        /* IN - parent object handle */
00222                                              char *Path,        /* IN - path to the object */
00223                                              api_cwd_stack_t * CwdStack,        /* IN - cwd stack */
00224                                              hpss_reqid_t RequestID,    /* IN - request id */
00225                                              unsigned32 Flags,  /* IN - flags for storage attrs */
00226                                              unsigned32 ChaseFlags,     /* IN - chase symlinks/junctions ? */
00227                                              unsigned32 StorageLevel,   /* IN - storage level to query  */
00228                                              TYPE_CRED_HPSS * Ucred,    /* IN - user credentials */
00229                                              TYPE_TOKEN_HPSS * AuthzTicket,     /* OUT - authorization ticket */
00230                                              hpss_fileattr_t * AttrOut, /* OUT - attributes after query */
00231                                              hpss_xfileattr_t * XAttrOut)       /* OUT - xattributes after query */
00232 {
00233   static char function_name[] = "HPSSFSAL_Common_FileGetAttributes";
00234 #if (HPSS_MAJOR_VERSION == 5) || (HPSS_MAJOR_VERSION == 7)
00235   volatile long error = 0;      /* return error */
00236 #elif (HPSS_MAJOR_VERSION == 6)
00237   signed32 error = 0;           /* return error */
00238 #else
00239 #error "Unexpected HPSS VERSION MAJOR"
00240 #endif
00241   hpss_AttrBits_t select_flags; /* attribute select bits */
00242   hpss_AttrBits_t parent_flags; /* attribute select bits */
00243   TYPE_TOKEN_HPSS ta;           /* security token */
00244   unsigned32 xattr_options;     /* xattribute option flags */
00245   unsigned32 xattr_options_cnt; /* options specified */
00246   bf_sc_attrib_t *xattr_ptr;    /* extended information */
00247 
00248   API_ENTER(function_name);
00249 
00250   xattr_options = 0;
00251   xattr_ptr = NULL;
00252 
00253   if(XAttrOut != NULL)
00254     {
00255       memset(XAttrOut, 0, sizeof(hpss_xfileattr_t));
00256       xattr_options_cnt = 0;
00257       xattr_ptr = XAttrOut->SCAttrib;
00258       if((Flags & API_GET_STATS_FOR_LEVEL) != 0)
00259         {
00260           xattr_options_cnt++;
00261           xattr_options |= CORE_GETATTRS_STATS_FOR_LEVEL;
00262         }
00263       if((Flags & API_GET_STATS_FOR_1STLEVEL) != 0)
00264         {
00265           xattr_options_cnt++;
00266           xattr_options |= CORE_GETATTRS_STATS_1ST_LEVEL;
00267         }
00268       if((Flags & API_GET_STATS_OPTIMIZE) != 0)
00269         {
00270           xattr_options_cnt++;
00271           xattr_options |= CORE_GETATTRS_STATS_OPTIMIZE;
00272         }
00273       if((Flags & API_GET_STATS_FOR_ALL_LEVELS) != 0)
00274         {
00275           xattr_options_cnt++;
00276           xattr_options |= CORE_GETATTRS_STATS_ALL_LEVELS;
00277         }
00278       if(xattr_options_cnt > 1)
00279         {
00280           return (-EINVAL);
00281         }
00282 #if ( HPSS_LEVEL >= 622 )
00283       if((Flags & API_GET_XATTRS_NO_BLOCK) != 0)
00284         xattr_options |= CORE_GETATTRS_NO_BLOCK;
00285 #endif
00286     }
00287 
00288   /*
00289    *  Now get the requested attributes
00290    */
00291 
00292   (void)memset(&ta, 0, sizeof(ta));
00293   (void)memset(AttrOut, 0, sizeof(*AttrOut));
00294   (void)memset(&select_flags, 0, sizeof(select_flags));
00295   (void)memset(&parent_flags, 0, sizeof(parent_flags));
00296 
00297   select_flags = API_AddAllRegisterValues(MAX_CORE_ATTR_INDEX);
00298 
00299   error = API_TraversePath(ThreadContext,
00300                            RequestID,
00301                            Ucred,
00302                            ObjHandle,
00303                            Path,
00304                            CwdStack,
00305                            ChaseFlags,
00306                            xattr_options,
00307                            StorageLevel,
00308                            select_flags,
00309                            parent_flags,
00310                            API_NULL_CWD_STACK,
00311                            &AttrOut->ObjectHandle, &AttrOut->Attrs, NULL, NULL,
00312 #if ( HPSS_MAJOR_VERSION < 7 )
00313                            &ta,
00314 #endif
00315                            NULL, xattr_ptr);
00316 
00317   if(error != 0)
00318     {
00319       API_DEBUG_FPRINTF(DebugFile, &RequestID,
00320                         "%s: Could not get attributes, error=%d\n", function_name, error);
00321     }
00322   else if(XAttrOut != NULL)
00323     {
00324       XAttrOut->ObjectHandle = AttrOut->ObjectHandle;
00325       XAttrOut->Attrs = AttrOut->Attrs;
00326     }
00327 
00328   /*
00329    *  If everything completed successfully, go ahead and copy
00330    *  the authorization ticket that we received
00331    */
00332 
00333   if(error == 0 && AuthzTicket != (TYPE_TOKEN_HPSS *) NULL)
00334     {
00335       *AuthzTicket = ta;
00336     }
00337 
00338   return (error);
00339 }
00340 
00341 /*============================================================================
00342  *
00343  * Function:    hpss_FileGetXAttributes
00344  *
00345  * Synopsis:
00346  *
00347  * int
00348  * hpss_FileGetXAttributes(
00349  * char                 *Path,          ** IN - path to the object
00350  * unsigned32           Flags,          ** IN - flags for storage attrs
00351  * unsigned32           StorageLevel,   ** IN - storage level to query
00352  * hpss_xfileattr_t     *AttrOut);      ** OUT - attributes after query
00353  *
00354  * Description:
00355  *
00356  *      The hpss_FileGetXAttributes function can be used to query attributes
00357  *      on an entry in the name/file system that is refered to by 'Path'.
00358  *      Additional Flags and StorageLevel parms allow getting storage attrs.
00359  *
00360  * Other Inputs:
00361  *      None.
00362  *
00363  * Outputs:
00364  *              0 -             No error, caller has access.
00365  *
00366  * Interfaces:
00367  *      Common_FileGetAttributes
00368  *
00369  * Resources Used:
00370  *
00371  * Limitations:
00372  *
00373  * Assumptions:
00374  *
00375  * Notes:
00376  *
00377  *-------------------------------------------------------------------------*/
00378 
00379 /* This function is provided from HPSS 6.2.2 */
00380 #if ( HPSS_LEVEL < 622 )
00381 int HPSSFSAL_FileGetXAttributesHandle(ns_ObjHandle_t * ObjHandle,       /* IN - object handle */
00382                                       unsigned32 Flags, /* IN - flags for storage attrs */
00383                                       unsigned32 StorageLevel,  /* IN - level to query     */
00384                                       hpss_xfileattr_t * AttrOut)       /* OUT - attributes after query */
00385 {
00386   static char function_name[] = "hpss_FileGetXAttributes";
00387   volatile long error = 0;      /* return error */
00388   hpss_reqid_t rqstid;          /* request id */
00389   int i, j;                     /* array indices */
00390   char *newpath;                /* new path */
00391   hpss_fileattr_t file_attrs;   /* NS object attributes */
00392   apithrdstate_t *threadcontext;        /* thread context */
00393 
00394   API_ENTER(function_name);
00395 
00396   /*
00397    *  Initialize the thread if not already initialized.
00398    *  Get a pointer back to the thread specific context.
00399    */
00400 
00401   error = API_ClientAPIInit(&threadcontext);
00402   if(error != 0)
00403     API_RETURN(error);
00404 
00405   /*
00406    *  Check that the return attribute pointer is not NULL.
00407    */
00408 
00409   if(AttrOut == (hpss_xfileattr_t *) NULL)
00410     API_RETURN(-EFAULT);
00411 
00412   /*
00413    *  Generate a unique request id.
00414    */
00415 
00416   rqstid = API_GetUniqueRequestID();
00417 
00418   /*
00419    * Call the common routine to do most of the get attribute
00420    * processing
00421    */
00422 
00423   error = HPSSFSAL_Common_FileGetAttributes(threadcontext, ObjHandle, NULL,
00424 #if ( HPSS_MAJOR_VERSION < 7 )
00425                                             threadcontext->CwdStackPtr,
00426 #else
00427                                             API_NULL_CWD_STACK,
00428 #endif
00429                                             rqstid,
00430                                             Flags,
00431                                             API_CHASE_ALL,
00432                                             StorageLevel,
00433                                             &threadcontext->UserCred,
00434                                             NULL, &file_attrs, AttrOut);
00435   error = Common_FileGetAttributes(threadcontext,
00436                                    ObjHandle,
00437                                    Path,
00438                                    API_NULL_CWD_STACK,
00439                                    rqstid,
00440                                    Flags,
00441                                    API_CHASE_ALL,
00442                                    StorageLevel, ucred_ptr, &file_attrs, AttrOut);
00443 
00444   if(error != 0)
00445     xdr_free((xdrproc_t) xdr_bf_sc_attrib_t, (void *)AttrOut->SCAttrib);
00446 
00447   API_RETURN(error);
00448 
00449 }
00450 #endif