source: trunk/kernel/ksh/eomtkp.c @ 145

Last change on this file since 145 was 1, checked in by alain, 8 years ago

First import

File size: 2.7 KB
RevLine 
[1]1/*
2   This file is part of MutekP.
3 
4   MutekP is free software; you can redistribute it and/or modify it
5   under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8 
9   MutekP is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   General Public License for more details.
13 
14   You should have received a copy of the GNU General Public License
15   along with MutekP; if not, write to the Free Software Foundation,
16   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18   UPMC / LIP6 / SOC (c) 2008
19   Copyright Ghassan Almaless <ghassan.almaless@gmail.com>
20*/
21
22#include <cpu.h>
23#include <string.h>
24#include <stdint.h>
25#include <kminiShell.h>
26#include <vfs.h>
27#include <sgiImg.h>
28#include <sys-vfs.h>
29
30#ifdef BUFFER_SIZE
31#undef BUFFER_SIZE //512 //2048
32#define BUFFER_SIZE 512
33#endif
34
35error_t eomtkp_func(void *param)
36{
37  char *src_name;
38  error_t err;
39  uint16_t x_size;
40  uint16_t y_size;
41  ssize_t size;
42  int src_fd;
43  int dst_fd;
44  int tmp_fd;
45  clock_t tm_start;             /* start of command */
46  clock_t tm_header;            /* image's header paressing */
47  clock_t tm_end;               /* end of command */
48  clock_t tm_tmp;
49  ms_args_t *args;
50  struct sgi_info_s *sgi_info;
51
52  sys_clock(&tm_start);
53
54  args  = (ms_args_t *) param;
55  src_name = args->argv[1];
56  err = 0;
57  memset(buffer,0,BUFFER_SIZE);
58
59  if((dst_fd = sys_open("/DEV/SCREEN",VFS_O_WRONLY,0)) == -1)
60    return -1;
61     
62  if((src_fd = sys_open(src_name,VFS_O_RDONLY,0)) == -1){
63    sys_close(dst_fd);
64    ksh_print("error while opinig %s\n",src_name);
65    return -2;
66  }
67 
68  if((size = sys_read(src_fd, buffer,sizeof(*sgi_info))) < 0)
69  {
70    sys_close(dst_fd);
71    sys_close(src_fd);
72    return -3;
73  }
74
75  sgi_info = (struct sgi_info_s*) buffer;
76  x_size = SGI_TO_LE2(sgi_info->x_size);
77  y_size = SGI_TO_LE2(sgi_info->y_size);
78
79  if((tmp_fd = sys_open("/DEV/SCREEN",VFS_O_WRONLY,0)) == -1)
80    return -1;
81 
82  ksh_print("Image XSIZE %d, YSIZE %d\n", x_size, y_size);
83  ksh_print("Image Name: %s\n", sgi_info->img_name);
84 
85  if((size = sys_lseek(src_fd, sizeof(struct sgi_info_s), VFS_SEEK_SET)) == -1)
86    return -4;
87
88  sys_clock(&tm_tmp);
89  tm_header = tm_tmp - tm_start;
90
91  size = 0;
92  while((size = sys_read(src_fd,buffer,BUFFER_SIZE)) > 0)
93  {
94    if((size=sys_write(dst_fd,buffer,size)) < 0)
95      break;
96  }
97 
98  sys_close(src_fd);
99  sys_close(dst_fd);
100 
101  sys_clock(&tm_end);
102
103  ksh_print("  Command statistics:\n\tStart time: %u\n\tEnd time: %u\n\tElapsed time: %u\n\tHeader time: %u\n",
104         tm_start,
105         tm_end,
106         tm_end - tm_start,
107         tm_header);
108  return size;
109}
Note: See TracBrowser for help on using the repository browser.