Subversion Repositories HelenOS

Rev

Rev 2394 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2007 Konopa-Jelen-Majer
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup FileSystemTask
  30.  * @{
  31.  */
  32.  
  33. /**
  34.  * @file    message.c
  35.  * @brief   Sending extended well formed messages to FS over
  36.  *        standard HelenOS message agrs and over shared buffer.
  37.  */
  38.  
  39. #include <async.h>
  40. #include <task.h>
  41. #include "../fs/fs.h"
  42. #include "message.h"
  43.  
  44. int send_request(int phoneid, ipcarg_t method, message_params_t *params, void *shared_buffer);
  45. void unpack_message(message_params_t *message, ipc_call_t m_input, void *shared_buffer);
  46.  
  47. /**
  48.  * Forms and sends extended message to FS
  49.  * This method should be used by all callers of FS. Candidate at library function.
  50.  */
  51. int send_request(int phoneid, ipcarg_t method, message_params_t *params, void *shared_buffer)
  52. {
  53.    
  54.     int retval, shift;
  55.     size_t size;
  56.    
  57.     size = sizeof(message_params_t);
  58.     memset((void *)shared_buffer, 0, size);
  59.    
  60.     /* Setting 'buffered' parameters. */
  61.     memcpy((void* )shared_buffer, (void *)(&params->nbytes), sizeof(unsigned int));
  62.     shift = sizeof(unsigned int);
  63.     memcpy((void *)(shared_buffer + shift), (void *)(&params->offset), sizeof(offset_t));
  64.     shift += sizeof(offset_t);
  65.     memcpy((void *)(shared_buffer + shift), (void *)(&params->fname), DIRSIZEX);
  66.     params->fname[DIRSIZEX-1] = '\0';
  67.     shift += DIRSIZEX * sizeof(char);
  68.     memcpy((void *)(shared_buffer + shift), (void *)(&params->entry_number), sizeof(int));
  69.    
  70.     /* 'Most used' parameters will be pass in standart message parameters. */
  71.     retval = async_req_3(phoneid, method, task_get_id(), params->fd, params->whence, NULL, NULL, NULL);
  72.  
  73.     return retval; 
  74. }
  75.  
  76. /**
  77.  * Unpacks message to given message_params_t* structure
  78.  * Will be used by FS to unpacking incoming extended message.
  79.  */
  80. void unpack_message(message_params_t *message, ipc_call_t m_input, void *shared_buffer)
  81. {
  82.    
  83.     int shift;
  84.  
  85.     /* Core message parameters. */
  86.     message->id_task = IPC_GET_ARG1(m_input);
  87.     message->fd = IPC_GET_ARG2(m_input);
  88.     message->whence = IPC_GET_ARG3(m_input);
  89.  
  90.     /* Buffered parameters - extended. */
  91.     memcpy((void *)&message->nbytes, (void *)(shared_buffer), sizeof(unsigned int));
  92.     shift = sizeof(unsigned int);
  93.     memcpy((void *)(&message->offset), (void *)(shared_buffer + shift), sizeof(offset_t));
  94.     shift += sizeof(offset_t);
  95.     memcpy((void *)(&message->fname), (void *)(shared_buffer + shift), DIRSIZEX);
  96.     shift += DIRSIZEX * sizeof(char);
  97.     memcpy((void *)(&message->entry_number), (void *)(shared_buffer + shift), sizeof(int));
  98.  
  99. }
  100.  
  101. /**
  102.  *}
  103.  */
  104.    
  105.