Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1663 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 2004-07-05 14:18:03 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1 $
25
 Last update: $Date: 2004-07-05 14:18:03 $
26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2001 Paolo Gai
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
 *
54
 * Read/Write functions
55
 *
56
 */
57
 
58
/* This is the buffer used by read_myfile */
59
char myfilebuf[1000];
60
 
61
/* This is the number of bytes read by read_myfile */
62
int myfilebuf_length;
63
 
64
/* This function read myfile.txt (up to 1000 chars) */
65
void read_myfile(void)
66
{
67
  /* DOS file descriptor */
68
  DOS_FILE *f;
69
 
70
  /* Error code */
71
  int err;
72
 
73
  /* open the DOS file for reading  (you can specify only "r" or "w") */
74
  f = DOS_fopen("myfile.txt","r");
75
 
76
  /* check for open errors */
77
  if (!f) {
78
    /* error!! */
79
    err = DOS_error();
80
 
81
    /* note that if you call DOS_error() here, it return 0!!! */
82
    cprintf("Error %d opening myfile.txt...\n", err);
83
    myfilebuf_length = 0;
84
    return;
85
  }
86
 
87
  /* read up to 1000 chars */
88
  myfilebuf_length = DOS_fread(&myfilebuf,1,1000,f);
89
 
90
  /* check for errors */
91
  err = DOS_error();
92
 
93
  cprintf("Read %d bytes from myfile.txt...\n", myfilebuf_length);
94
 
95
  if (err) {
96
    cprintf("Error %d reading myfile.txt...\n", err);
97
    myfilebuf_length = 0;
98
    /* there is not return because I want to close the file! */
99
  }
100
 
101
  /* Close the file */
102
  DOS_fclose(f);
103
}
104
 
105
/* This function write myfile.out (up to 30 chars) */
106
void write_myfile(void *arg)
107
{
108
  DOS_FILE *f;  /* DOS file descriptor */
109
  int err;  /* Error code */
110
  int maxbytes;
111
  int writtenbytes;  /* number of files written */
112
 
113
  /* open the DOS file for writing  (you can specify only "r" or "w") */
114
  f = DOS_fopen("myfile.out","w");
115
 
116
  /* check for open errors */
117
  if (!f) {
118
    /* error!! */
119
    err = DOS_error();
120
 
121
    /* note that if you call DOS_error() here, it return 0!!! */
122
    cprintf("Error %d opening myfile.out...\n", err);
123
    return;
124
  }
125
 
126
  /* write up to 30 bytes */
127
  if (myfilebuf_length > 30)
128
    maxbytes = 30;
129
  else
130
    maxbytes = myfilebuf_length;
131
 
132
  writtenbytes = DOS_fwrite(myfilebuf,1,maxbytes,f);
133
 
134
  /* check for errors */
135
  err = DOS_error();
136
 
137
  cprintf("Written %d bytes into myfile.out...\n", writtenbytes);
138
 
139
  if (err) {
140
    cprintf("Error %d writing myfile.txt...\n", err);
141
    /* there is not return because I want to close the file! */
142
  }
143
 
144
  /* Close the file */
145
  DOS_fclose(f);
146
}