Subversion Repositories shark

Rev

Rev 1085 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
21
 CVS :        $Id: dosfs.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2002-09-02 09:37:41 $
26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2000 Paolo Gai and Gabriele Bolognini
31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
#include "kernel/kern.h"
49
#include "string.h"
50
#include "ll/i386/x-dos.h"
51
 
52
 
53
/* This is the buffer used by read_myfile */
54
char myfilebuf[1000];
55
 
56
/* This is the number of bytes read by read_myfile */
57
int myfilebuf_length;
58
 
59
/* This function write myfile.out (up to 30 chars) */
60
void write_myfile(void *arg);
61
 
62
int main(int argc, char **argv)
63
{
64
  int x;
65
 
66
  cprintf("\nBuffer contents:\n");
67
 
68
  for (x=0; x<myfilebuf_length; x++)
69
    cputc(myfilebuf[x]);
70
 
71
  /*
72
     WARNING: You can call these functions only when you are in
73
              real mode!!!
74
 
75
     The system is in real mode:
76
     - into __kernel_register_levels__()
77
     - into sys_atrunlevel functions posted with RUNLEVEL_AFTER_EXIT
78
  */
79
 
80
  if (myfilebuf_length)
81
    sys_atrunlevel(write_myfile, NULL, RUNLEVEL_AFTER_EXIT);
82
 
83
  return 0;
84
  /*
85
   * Since there is only one user task, the kernel will shut down after this
86
   * task finishes...
87
   */
88
}
89
 
90
/* This function read myfile.txt (up to 1000 chars) */
91
void read_myfile(void)
92
{
93
  /* DOS file descriptor */
94
  DOS_FILE *f;
95
 
96
  /* Error code */
97
  int err;
98
 
99
  /* open the DOS file for reading  (you can specify only "r" or "w") */
100
  f = DOS_fopen("myfile.txt","r");
101
 
102
  /* check for open errors */
103
  if (!f) {
104
    /* error!! */
105
    err = DOS_error();
106
 
107
    /* note that if you call DOS_error() here, it return 0!!! */
108
    cprintf("Error %d opening myfile.txt...\n", err);
109
    myfilebuf_length = 0;
110
    return;
111
  }
112
 
113
  /* read up to 1000 chars */
114
  myfilebuf_length = DOS_fread(&myfilebuf,1,1000,f);
115
 
116
  /* check for errors */
117
  err = DOS_error();
118
 
119
  cprintf("Read %d bytes from myfile.txt...\n", myfilebuf_length);
120
 
121
  if (err) {
122
    cprintf("Error %d reading myfile.txt...\n", err);
123
    myfilebuf_length = 0;
124
    /* there is not return because I want to close the file! */
125
  }
126
 
127
  /* Close the file */
128
  DOS_fclose(f);
129
}
130
 
131
/* This function write myfile.out (up to 30 chars) */
132
void write_myfile(void *arg)
133
{
134
  DOS_FILE *f;  /* DOS file descriptor */
135
  int err;  /* Error code */
136
  int maxbytes;
137
  int writtenbytes;  /* number of files written */
138
 
139
  /* open the DOS file for writing  (you can specify only "r" or "w") */
140
  f = DOS_fopen("myfile.out","w");
141
 
142
  /* check for open errors */
143
  if (!f) {
144
    /* error!! */
145
    err = DOS_error();
146
 
147
    /* note that if you call DOS_error() here, it return 0!!! */
148
    cprintf("Error %d opening myfile.out...\n", err);
149
    return;
150
  }
151
 
152
  /* write up to 30 bytes */
153
  if (myfilebuf_length > 30)
154
    maxbytes = 30;
155
  else
156
    maxbytes = myfilebuf_length;
157
 
158
  writtenbytes = DOS_fwrite(myfilebuf,1,maxbytes,f);
159
 
160
  /* check for errors */
161
  err = DOS_error();
162
 
163
  cprintf("Written %d bytes into myfile.out...\n", writtenbytes);
164
 
165
  if (err) {
166
    cprintf("Error %d writing myfile.txt...\n", err);
167
    /* there is not return because I want to close the file! */
168
  }
169
 
170
  /* Close the file */
171
  DOS_fclose(f);
172
}
173
 
174