/** * FSAL_open: * Open a regular file for reading/writing its data content. * * \param filehandle (input): * Handle of the file to be read/modified. * \param cred (input): * Authentication context for the operation (user,...). * \param openflags (input): * Flags that indicates behavior for file opening and access. * This is an inclusive OR of the following values * ( such of them are not compatible) : * - FSAL_O_RDONLY: opening file for reading only. * - FSAL_O_RDWR: opening file for reading and writing. * - FSAL_O_WRONLY: opening file for writting only. * - FSAL_O_APPEND: always write at the end of the file. * - FSAL_O_TRUNC: truncate the file to 0 on opening. * \param file_descriptor (output): * The file descriptor to be used for FSAL_read/write operations. * \param file_attributes (optionnal input/output): * Post operation attributes. * As input, it defines the attributes that the caller * wants to retrieve (by positioning flags into this structure) * and the output is built considering this input * (it fills the structure according to the flags it contains). * * \return Major error codes: * - ERR_FSAL_NO_ERROR (no error) * - ERR_FSAL_ACCESS (user doesn't have the permissions for opening the file) * - ERR_FSAL_STALE (filehandle does not address an existing object) * - ERR_FSAL_INVAL (filehandle does not address a regular file, * or open flags are conflicting) * - ERR_FSAL_FAULT (a NULL pointer was passed as mandatory argument) * - Other error codes can be returned : * ERR_FSAL_IO, ... */ fsal_status_t ZFSFSAL_open(zfsfsal_handle_t * filehandle, /* IN */ zfsfsal_op_context_t * p_context, /* IN */ fsal_openflags_t openflags, /* IN */ zfsfsal_file_t * file_descriptor, /* OUT */ fsal_attrib_list_t * file_attributes /* [ IN/OUT ] */ ) { int rc; /* sanity checks. * note : file_attributes is optional. */ if(!filehandle || !p_context || !file_descriptor) Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_open); /* >> you can check if this is a file if the information * is stored into the handle << */ if(filehandle->data.type != FSAL_TYPE_FILE) Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_open); /* >> convert fsal open flags to your FS open flags * Take care of conflicting flags << */ int posix_flags; rc = fsal2posix_openflags(openflags, &posix_flags); if(rc) Return(rc, 0, INDEX_FSAL_open); TakeTokenFSCall(); /* >> call your FS open function << */ libzfswrap_vnode_t *p_vnode; rc = libzfswrap_open(p_context->export_context->p_vfs, &p_context->user_credential.cred, filehandle->data.zfs_handle, posix_flags, &p_vnode); ReleaseTokenFSCall(); /* >> interpret returned status << */ if(rc) Return(posix2fsal_error(rc), rc, INDEX_FSAL_open); /* >> fill output struct << */ file_descriptor->p_vfs = p_context->export_context->p_vfs; file_descriptor->flags = posix_flags; file_descriptor->current_offset = 0; file_descriptor->p_vnode = p_vnode; file_descriptor->zfs_handle = filehandle->data.zfs_handle; file_descriptor->cred = p_context->user_credential.cred; file_descriptor->is_closed = 0; if(file_attributes) { fsal_status_t status = ZFSFSAL_getattrs(filehandle, p_context, file_attributes); /* On error, we set a flag in the returned attributes */ if(FSAL_IS_ERROR(status)) { FSAL_CLEAR_MASK(file_attributes->asked_attributes); FSAL_SET_MASK(file_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); } } Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_open); }
/** * FSAL_open: * Open a regular file for reading/writing its data content. * * \param filehandle (input): * Handle of the file to be read/modified. * \param cred (input): * Authentication context for the operation (user,...). * \param openflags (input): * Flags that indicates behavior for file opening and access. * This is an inclusive OR of the following values * ( such of them are not compatible) : * - FSAL_O_RDONLY: opening file for reading only. * - FSAL_O_RDWR: opening file for reading and writing. * - FSAL_O_WRONLY: opening file for writting only. * - FSAL_O_APPEND: always write at the end of the file. * - FSAL_O_TRUNC: truncate the file to 0 on opening. * \param file_descriptor (output): * The file descriptor to be used for FSAL_read/write operations. * \param file_attributes (optionnal input/output): * Post operation attributes. * As input, it defines the attributes that the caller * wants to retrieve (by positioning flags into this structure) * and the output is built considering this input * (it fills the structure according to the flags it contains). * * \return Major error codes: * - ERR_FSAL_NO_ERROR (no error) * - ERR_FSAL_ACCESS (user doesn't have the permissions for opening the file) * - ERR_FSAL_STALE (filehandle does not address an existing object) * - ERR_FSAL_INVAL (filehandle does not address a regular file, * or open flags are conflicting) * - ERR_FSAL_FAULT (a NULL pointer was passed as mandatory argument) * - Other error codes can be returned : * ERR_FSAL_IO, ... */ fsal_status_t ZFSFSAL_open(fsal_handle_t * file_hdl, /* IN */ fsal_op_context_t * p_context, /* IN */ fsal_openflags_t openflags, /* IN */ fsal_file_t * file_desc, /* OUT */ fsal_attrib_list_t * file_attributes /* [ IN/OUT ] */ ) { int rc; creden_t cred; zfsfsal_handle_t * filehandle = (zfsfsal_handle_t *)file_hdl; zfsfsal_file_t * file_descriptor = ( zfsfsal_file_t *)file_desc; /* sanity checks. * note : file_attributes is optional. */ if(!filehandle || !p_context || !file_descriptor) Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_open); /* Check if this is a file */ if(filehandle->data.type != FSAL_TYPE_FILE) Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_open); /* Get the right VFS */ ZFSFSAL_VFS_RDLock(); libzfswrap_vfs_t *p_vfs = ZFSFSAL_GetVFS(filehandle); if(!p_vfs) { ZFSFSAL_VFS_Unlock(); Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_open); } /* >> convert fsal open flags to your FS open flags * Take care of conflicting flags << */ int posix_flags; rc = fsal2posix_openflags(openflags, &posix_flags); if(rc) Return(rc, 0, INDEX_FSAL_open); cred.uid = p_context->credential.user; cred.gid = p_context->credential.group; TakeTokenFSCall(); /* >> call your FS open function << */ libzfswrap_vnode_t *p_vnode; rc = libzfswrap_open(p_vfs, &cred, filehandle->data.zfs_handle, posix_flags, &p_vnode); ReleaseTokenFSCall(); ZFSFSAL_VFS_Unlock(); /* >> interpret returned status << */ if(rc) Return(posix2fsal_error(rc), 0, INDEX_FSAL_open); /* >> fill output struct << */ file_descriptor->flags = posix_flags; file_descriptor->current_offset = 0; file_descriptor->p_vnode = p_vnode; file_descriptor->handle = *filehandle; file_descriptor->cred = cred; file_descriptor->is_closed = 0; if(file_attributes) { fsal_status_t status = ZFSFSAL_getattrs(file_hdl, p_context, file_attributes); /* On error, we set a flag in the returned attributes */ if(FSAL_IS_ERROR(status)) { FSAL_CLEAR_MASK(file_attributes->asked_attributes); FSAL_SET_MASK(file_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); } } Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_open); }