Back to index

im-sdk  12.3.91
im-file-operation.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 
00005 #include <iiimp-data.h>
00006 #include <iiimp-opcode.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 IIIMP_message *
00011 iiimp_file_operation_new(
00012     IIIMP_data_s *           data_s,
00013     IIIMP_card16                im_id,
00014     IIIMP_card32                type,
00015     void *                  value)
00016 {
00017     IIIMP_message *  m;
00018     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00019     if (NULL == m) {
00020        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00021        return NULL;
00022     }
00023     m->opcode = IM_FILE_OPERATION;
00024     m->im_id = im_id;
00025     m->ic_id = -1;
00026     m->v.file_operation.type = type;
00027     m->v.file_operation.value = value;
00028     return m;
00029 }
00030 
00031 void
00032 iiimp_file_operation_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00033 {
00034     if (NULL == m) return;
00035 
00036     switch (m->v.file_operation.type) {
00037       case IIIMP_FILE_OPERATION_TYPE_OPEN:
00038        iiimp_open_delete(data_s, (IIIMP_open *)m->v.file_operation.value);
00039        break;
00040       case IIIMP_FILE_OPERATION_TYPE_READ:
00041        iiimp_read_delete(data_s, (IIIMP_read *)m->v.file_operation.value);
00042        break;
00043       case IIIMP_FILE_OPERATION_TYPE_WRITE:
00044        iiimp_write_delete(data_s, (IIIMP_write *)m->v.file_operation.value);
00045        break;
00046       case IIIMP_FILE_OPERATION_TYPE_CLOSE:
00047        iiimp_close_delete(data_s, (IIIMP_close *)m->v.file_operation.value);
00048        break;
00049       case IIIMP_FILE_OPERATION_TYPE_OPENDIR:
00050        iiimp_opendir_delete(data_s, (IIIMP_opendir *)m->v.file_operation.value);
00051        break;
00052       case IIIMP_FILE_OPERATION_TYPE_CLOSEDIR:
00053        iiimp_closedir_delete(data_s, (IIIMP_closedir *)m->v.file_operation.value);
00054        break;
00055       case IIIMP_FILE_OPERATION_TYPE_SEEK:
00056        iiimp_seek_delete(data_s, (IIIMP_seek *)m->v.file_operation.value);
00057        break;
00058       case IIIMP_FILE_OPERATION_TYPE_MKDIR:
00059        iiimp_mkdir_delete(data_s, (IIIMP_mkdir *)m->v.file_operation.value);
00060        break;
00061       case IIIMP_FILE_OPERATION_TYPE_RMDIR:
00062        iiimp_rmdir_delete(data_s, (IIIMP_rmdir *)m->v.file_operation.value);
00063        break;
00064       case IIIMP_FILE_OPERATION_TYPE_SYMLINK:
00065        iiimp_symlink_delete(data_s, (IIIMP_symlink *)m->v.file_operation.value);
00066        break;
00067       case IIIMP_FILE_OPERATION_TYPE_STAT:
00068        iiimp_stat_delete(data_s, (IIIMP_stat *)m->v.file_operation.value);
00069        break;
00070       case IIIMP_FILE_OPERATION_TYPE_LSTAT:
00071        iiimp_lstat_delete(data_s, (IIIMP_lstat *)m->v.file_operation.value);
00072        break;
00073       case IIIMP_FILE_OPERATION_TYPE_FSTAT:
00074        iiimp_fstat_delete(data_s, (IIIMP_fstat *)m->v.file_operation.value);
00075        break;
00076       case IIIMP_FILE_OPERATION_TYPE_CREAT:
00077        iiimp_creat_delete(data_s, (IIIMP_creat *)m->v.file_operation.value);
00078        break;
00079       case IIIMP_FILE_OPERATION_TYPE_LSEEK:
00080        iiimp_lseek_delete(data_s, (IIIMP_lseek *)m->v.file_operation.value);
00081        break;
00082       case IIIMP_FILE_OPERATION_TYPE_UNLINK:
00083        iiimp_unlink_delete(data_s, (IIIMP_unlink *)m->v.file_operation.value);
00084        break;
00085       case IIIMP_FILE_OPERATION_TYPE_RENAME:
00086        iiimp_rename_delete(data_s, (IIIMP_rename *)m->v.file_operation.value);
00087        break;
00088       case IIIMP_FILE_OPERATION_TYPE_FCNTL:
00089        iiimp_fcntl_delete(data_s, (IIIMP_fcntl *)m->v.file_operation.value);
00090        break;
00091       case IIIMP_FILE_OPERATION_TYPE_TRUNCATE:
00092        iiimp_truncate_delete(data_s, (IIIMP_truncate *)m->v.file_operation.value);
00093        break;
00094       case IIIMP_FILE_OPERATION_TYPE_FTRUNCATE:
00095        iiimp_ftruncate_delete(data_s, (IIIMP_ftruncate *)m->v.file_operation.value);
00096        break;
00097     }
00098     free(m);
00099     return;
00100 }
00101 
00102 uchar_t *
00103 iiimp_file_operation_pack(
00104     IIIMP_data_s *   data_s,
00105     IIIMP_card16        im_id,
00106     IIIMP_card32        type,
00107     void *           value,
00108     size_t *         buf_size)
00109 {
00110     size_t           nbyte;
00111     int                     length;
00112     uchar_t *        buf;
00113     size_t           rest;
00114     uchar_t *        p;
00115 
00116     nbyte = 0
00117        + 2                 /* input method id */
00118        + 2                 /* Pad(2) */
00119        + 4 ;               /* file operation type */
00120 
00121     if (NULL != value) {
00122        switch (type) {
00123          case IIIMP_FILE_OPERATION_TYPE_OPEN:
00124           nbyte += ((IIIMP_open *)value)->nbyte;
00125           break;
00126          case IIIMP_FILE_OPERATION_TYPE_READ:
00127           nbyte += ((IIIMP_read *)value)->nbyte;
00128           break;
00129          case IIIMP_FILE_OPERATION_TYPE_WRITE:
00130           nbyte += ((IIIMP_write *)value)->nbyte;
00131           break;
00132          case IIIMP_FILE_OPERATION_TYPE_CLOSE:
00133           nbyte += ((IIIMP_close *)value)->nbyte;
00134           break;
00135          case IIIMP_FILE_OPERATION_TYPE_OPENDIR:
00136           nbyte += ((IIIMP_opendir *)value)->nbyte;
00137           break;
00138          case IIIMP_FILE_OPERATION_TYPE_CLOSEDIR:
00139           nbyte += ((IIIMP_closedir *)value)->nbyte;
00140           break;
00141          case IIIMP_FILE_OPERATION_TYPE_SEEK:
00142           nbyte += ((IIIMP_seek *)value)->nbyte;
00143           break;
00144          case IIIMP_FILE_OPERATION_TYPE_MKDIR:
00145           nbyte += ((IIIMP_mkdir *)value)->nbyte;
00146           break;
00147          case IIIMP_FILE_OPERATION_TYPE_RMDIR:
00148           nbyte += ((IIIMP_rmdir *)value)->nbyte;
00149           break;
00150          case IIIMP_FILE_OPERATION_TYPE_SYMLINK:
00151           nbyte += ((IIIMP_symlink *)value)->nbyte;
00152           break;
00153          case IIIMP_FILE_OPERATION_TYPE_STAT:
00154           nbyte += ((IIIMP_stat *)value)->nbyte;
00155           break;
00156          case IIIMP_FILE_OPERATION_TYPE_LSTAT:
00157           nbyte += ((IIIMP_lstat *)value)->nbyte;
00158           break;
00159          case IIIMP_FILE_OPERATION_TYPE_FSTAT:
00160           nbyte += ((IIIMP_fstat *)value)->nbyte;
00161           break;
00162          case IIIMP_FILE_OPERATION_TYPE_CREAT:
00163           nbyte += ((IIIMP_creat *)value)->nbyte;
00164           break;
00165          case IIIMP_FILE_OPERATION_TYPE_LSEEK:
00166           nbyte += ((IIIMP_lseek *)value)->nbyte;
00167           break;
00168          case IIIMP_FILE_OPERATION_TYPE_UNLINK:
00169           nbyte += ((IIIMP_unlink *)value)->nbyte;
00170           break;
00171          case IIIMP_FILE_OPERATION_TYPE_RENAME:
00172           nbyte += ((IIIMP_rename *)value)->nbyte;
00173           break;
00174          case IIIMP_FILE_OPERATION_TYPE_FCNTL:
00175           nbyte += ((IIIMP_fcntl *)value)->nbyte;
00176           break;
00177          case IIIMP_FILE_OPERATION_TYPE_TRUNCATE:
00178           nbyte += ((IIIMP_truncate *)value)->nbyte;
00179           break;
00180          case IIIMP_FILE_OPERATION_TYPE_FTRUNCATE:
00181           nbyte += ((IIIMP_ftruncate *)value)->nbyte;
00182           break;
00183        }
00184     } 
00185 
00186     length = (nbyte >> 2);
00187     *buf_size = (1 + 3 + nbyte);
00188 
00189     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00190     if (NULL == buf) {
00191        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00192        return NULL;
00193     }
00194 
00195     PUT_PACKET_HEADER(buf, IM_FILE_OPERATION, length);
00196 
00197     rest = nbyte;
00198     p = (buf + 4);
00199 
00200     PUTU16(im_id, rest, p, data_s->byte_swap);
00201     PUTU16(0, rest, p, data_s->byte_swap);
00202     PUTU32(type, rest, p, data_s->byte_swap);
00203 
00204     if (NULL == value) {
00205        return NULL;
00206     } else {
00207        switch (type) {
00208          case IIIMP_FILE_OPERATION_TYPE_OPEN:
00209           iiimp_open_pack(data_s, (IIIMP_open *)value, &rest, &p);
00210           break;
00211          case IIIMP_FILE_OPERATION_TYPE_READ:
00212           iiimp_read_pack(data_s, (IIIMP_read *)value, &rest, &p);
00213           break;
00214          case IIIMP_FILE_OPERATION_TYPE_WRITE:
00215           iiimp_write_pack(data_s, (IIIMP_write *)value, &rest, &p);
00216           break;
00217          case IIIMP_FILE_OPERATION_TYPE_CLOSE:
00218           iiimp_close_pack(data_s, (IIIMP_close *)value, &rest, &p);
00219           break;
00220          case IIIMP_FILE_OPERATION_TYPE_OPENDIR:
00221           iiimp_opendir_pack(data_s, (IIIMP_opendir *)value, &rest, &p);
00222           break;
00223          case IIIMP_FILE_OPERATION_TYPE_CLOSEDIR:
00224           iiimp_closedir_pack(data_s, (IIIMP_closedir *)value, &rest, &p);
00225           break;
00226          case IIIMP_FILE_OPERATION_TYPE_SEEK:
00227           iiimp_seek_pack(data_s, (IIIMP_seek *)value, &rest, &p);
00228           break;
00229          case IIIMP_FILE_OPERATION_TYPE_MKDIR:
00230           iiimp_mkdir_pack(data_s, (IIIMP_mkdir *)value, &rest, &p);
00231           break;
00232          case IIIMP_FILE_OPERATION_TYPE_RMDIR:
00233           iiimp_rmdir_pack(data_s, (IIIMP_rmdir *)value, &rest, &p);
00234           break;
00235          case IIIMP_FILE_OPERATION_TYPE_SYMLINK:
00236           iiimp_symlink_pack(data_s, (IIIMP_symlink *)value, &rest, &p);
00237           break;
00238          case IIIMP_FILE_OPERATION_TYPE_STAT:
00239           iiimp_stat_pack(data_s, (IIIMP_stat *)value, &rest, &p);
00240           break;
00241          case IIIMP_FILE_OPERATION_TYPE_LSTAT:
00242           iiimp_lstat_pack(data_s, (IIIMP_lstat *)value, &rest, &p);
00243           break;
00244          case IIIMP_FILE_OPERATION_TYPE_FSTAT:
00245           iiimp_fstat_pack(data_s, (IIIMP_fstat *)value, &rest, &p);
00246           break;
00247          case IIIMP_FILE_OPERATION_TYPE_CREAT:
00248           iiimp_creat_pack(data_s, (IIIMP_creat *)value, &rest, &p);
00249           break;
00250          case IIIMP_FILE_OPERATION_TYPE_LSEEK:
00251           iiimp_lseek_pack(data_s, (IIIMP_lseek *)value, &rest, &p);
00252           break;
00253          case IIIMP_FILE_OPERATION_TYPE_UNLINK:
00254           iiimp_unlink_pack(data_s, (IIIMP_unlink *)value, &rest, &p);
00255           break;
00256          case IIIMP_FILE_OPERATION_TYPE_RENAME:
00257           iiimp_rename_pack(data_s, (IIIMP_rename *)value, &rest, &p);
00258           break;
00259          case IIIMP_FILE_OPERATION_TYPE_FCNTL:
00260           iiimp_fcntl_pack(data_s, (IIIMP_fcntl *)value, &rest, &p);
00261           break;
00262          case IIIMP_FILE_OPERATION_TYPE_TRUNCATE:
00263           iiimp_truncate_pack(data_s, (IIIMP_truncate *)value, &rest, &p);
00264           break;
00265          case IIIMP_FILE_OPERATION_TYPE_FTRUNCATE:
00266           iiimp_ftruncate_pack(data_s, (IIIMP_ftruncate *)value, &rest, &p);
00267           break;
00268         }
00269     }
00270     return buf;
00271 }
00272 
00273 IIIMP_message *
00274 iiimp_file_operation_unpack(
00275     IIIMP_data_s *   data_s,
00276     IIIMP_card7             opcode,
00277     size_t *         nbyte,
00278     const uchar_t ** ptr)
00279 {
00280     IIIMP_message *         m;
00281     IIIMP_file_operation_v *   v;
00282     size_t                  rest;
00283     const uchar_t *         p;
00284 
00285     rest = *nbyte;
00286     p = *ptr;
00287 
00288     if (rest < (2 + 2 + 4 + 4)) {
00289        data_s->status = IIIMP_DATA_INVALID;
00290        return NULL;
00291     }
00292 
00293     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00294     if (NULL == m) {
00295        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00296        return NULL;
00297     }
00298     v = &(m->v.file_operation);
00299 
00300     m->opcode = opcode;
00301     v->value = NULL;
00302 
00303     GETU16(m->im_id, rest, p, data_s->byte_swap);
00304     m->ic_id = -1;
00305     SKIP16(rest, p);
00306     GETU32(v->type, rest, p, data_s->byte_swap);
00307 
00308     switch (v->type) {
00309       case IIIMP_FILE_OPERATION_TYPE_OPEN:
00310        v->value = iiimp_open_unpack(data_s, &rest, &p, rest);
00311        break;
00312       case IIIMP_FILE_OPERATION_TYPE_READ:
00313        v->value = iiimp_read_unpack(data_s, &rest, &p, rest);
00314        break;
00315       case IIIMP_FILE_OPERATION_TYPE_WRITE:
00316        v->value = iiimp_write_unpack(data_s, &rest, &p, rest);
00317        break;
00318       case IIIMP_FILE_OPERATION_TYPE_CLOSE:
00319        v->value = iiimp_close_unpack(data_s, &rest, &p, rest);
00320        break;
00321       case IIIMP_FILE_OPERATION_TYPE_OPENDIR:
00322        v->value = iiimp_opendir_unpack(data_s, &rest, &p, rest);
00323        break;
00324       case IIIMP_FILE_OPERATION_TYPE_CLOSEDIR:
00325        v->value = iiimp_closedir_unpack(data_s, &rest, &p, rest);
00326        break;
00327       case IIIMP_FILE_OPERATION_TYPE_SEEK:
00328        v->value = iiimp_seek_unpack(data_s, &rest, &p, rest);
00329        break;
00330       case IIIMP_FILE_OPERATION_TYPE_MKDIR:
00331        v->value = iiimp_mkdir_unpack(data_s, &rest, &p, rest);
00332        break;
00333       case IIIMP_FILE_OPERATION_TYPE_RMDIR:
00334        v->value = iiimp_rmdir_unpack(data_s, &rest, &p, rest);
00335        break;
00336       case IIIMP_FILE_OPERATION_TYPE_SYMLINK:
00337        v->value = iiimp_symlink_unpack(data_s, &rest, &p, rest);
00338        break;
00339       case IIIMP_FILE_OPERATION_TYPE_STAT:
00340        v->value = iiimp_stat_unpack(data_s, &rest, &p, rest);
00341        break;
00342       case IIIMP_FILE_OPERATION_TYPE_LSTAT:
00343        v->value = iiimp_lstat_unpack(data_s, &rest, &p, rest);
00344        break;
00345       case IIIMP_FILE_OPERATION_TYPE_FSTAT:
00346        v->value = iiimp_fstat_unpack(data_s, &rest, &p, rest);
00347        break;
00348       case IIIMP_FILE_OPERATION_TYPE_CREAT:
00349        v->value = iiimp_creat_unpack(data_s, &rest, &p, rest);
00350        break;
00351       case IIIMP_FILE_OPERATION_TYPE_LSEEK:
00352        v->value = iiimp_lseek_unpack(data_s, &rest, &p, rest);
00353        break;
00354       case IIIMP_FILE_OPERATION_TYPE_UNLINK:
00355        v->value = iiimp_unlink_unpack(data_s, &rest, &p, rest);
00356        break;
00357       case IIIMP_FILE_OPERATION_TYPE_RENAME:
00358        v->value = iiimp_rename_unpack(data_s, &rest, &p, rest);
00359        break;
00360       case IIIMP_FILE_OPERATION_TYPE_FCNTL:
00361        v->value = iiimp_fcntl_unpack(data_s, &rest, &p, rest);
00362        break;
00363       case IIIMP_FILE_OPERATION_TYPE_TRUNCATE:
00364        v->value = iiimp_truncate_unpack(data_s, &rest, &p, rest);
00365        break;
00366       case IIIMP_FILE_OPERATION_TYPE_FTRUNCATE:
00367        v->value = iiimp_ftruncate_unpack(data_s, &rest, &p, rest);
00368        break;
00369     } 
00370 
00371     *nbyte = rest;
00372     *ptr = p;
00373 
00374     return m;
00375 }
00376 
00377 void
00378 iiimp_file_operation_print(
00379     IIIMP_data_s *   data_s,
00380     IIIMP_message *  m)
00381 {
00382     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00383     (void)fprintf(data_s->print_fp, "\ttype = %d\n", m->v.file_operation.type);
00384     // (void)fprintf(data_s->print_fp, "\tnbyte = %d\n", m->v.file_operation.nbyte);
00385     (void)fputc('\n', data_s->print_fp);
00386 
00387     switch (m->v.file_operation.type) {
00388       case IIIMP_FILE_OPERATION_TYPE_OPEN:
00389        iiimp_open_print(data_s, (IIIMP_open *)m->v.file_operation.value);
00390        break;
00391       case IIIMP_FILE_OPERATION_TYPE_READ:
00392        iiimp_read_print(data_s, (IIIMP_read *)m->v.file_operation.value);
00393        break;
00394       case IIIMP_FILE_OPERATION_TYPE_WRITE:
00395        iiimp_write_print(data_s, (IIIMP_write *)m->v.file_operation.value);
00396        break;
00397       case IIIMP_FILE_OPERATION_TYPE_CLOSE:
00398        iiimp_close_print(data_s, (IIIMP_close *)m->v.file_operation.value);
00399        break;
00400       case IIIMP_FILE_OPERATION_TYPE_OPENDIR:
00401        iiimp_opendir_print(data_s, (IIIMP_opendir *)m->v.file_operation.value);
00402        break;
00403       case IIIMP_FILE_OPERATION_TYPE_CLOSEDIR:
00404        iiimp_closedir_print(data_s, (IIIMP_closedir *)m->v.file_operation.value);
00405        break;
00406       case IIIMP_FILE_OPERATION_TYPE_SEEK:
00407        iiimp_seek_print(data_s, (IIIMP_seek *)m->v.file_operation.value);
00408        break;
00409       case IIIMP_FILE_OPERATION_TYPE_MKDIR:
00410        iiimp_mkdir_print(data_s, (IIIMP_mkdir *)m->v.file_operation.value);
00411        break;
00412       case IIIMP_FILE_OPERATION_TYPE_RMDIR:
00413        iiimp_rmdir_print(data_s, (IIIMP_rmdir *)m->v.file_operation.value);
00414        break;
00415       case IIIMP_FILE_OPERATION_TYPE_SYMLINK:
00416        iiimp_symlink_print(data_s, (IIIMP_symlink *)m->v.file_operation.value);
00417        break;
00418       case IIIMP_FILE_OPERATION_TYPE_STAT:
00419        iiimp_stat_print(data_s, (IIIMP_stat *)m->v.file_operation.value);
00420        break;
00421       case IIIMP_FILE_OPERATION_TYPE_LSTAT:
00422        iiimp_lstat_print(data_s, (IIIMP_lstat *)m->v.file_operation.value);
00423        break;
00424       case IIIMP_FILE_OPERATION_TYPE_FSTAT:
00425        iiimp_fstat_print(data_s, (IIIMP_fstat *)m->v.file_operation.value);
00426        break;
00427       case IIIMP_FILE_OPERATION_TYPE_CREAT:
00428        iiimp_creat_print(data_s, (IIIMP_creat *)m->v.file_operation.value);
00429        break;
00430       case IIIMP_FILE_OPERATION_TYPE_LSEEK:
00431        iiimp_lseek_print(data_s, (IIIMP_lseek *)m->v.file_operation.value);
00432        break;
00433       case IIIMP_FILE_OPERATION_TYPE_UNLINK:
00434        iiimp_unlink_print(data_s, (IIIMP_unlink *)m->v.file_operation.value);
00435        break;
00436       case IIIMP_FILE_OPERATION_TYPE_RENAME:
00437        iiimp_rename_print(data_s, (IIIMP_rename *)m->v.file_operation.value);
00438        break;
00439       case IIIMP_FILE_OPERATION_TYPE_FCNTL:
00440        iiimp_fcntl_print(data_s, (IIIMP_fcntl *)m->v.file_operation.value);
00441        break;
00442       case IIIMP_FILE_OPERATION_TYPE_TRUNCATE:
00443        iiimp_truncate_print(data_s, (IIIMP_truncate *)m->v.file_operation.value);
00444        break;
00445       case IIIMP_FILE_OPERATION_TYPE_FTRUNCATE:
00446        iiimp_ftruncate_print(data_s, (IIIMP_ftruncate *)m->v.file_operation.value);
00447        break;
00448     } 
00449 }
00450 
00451 /* Local Variables: */
00452 /* c-file-style: "iiim-project" */
00453 /* End: */