-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappl.c
87 lines (66 loc) · 2.12 KB
/
appl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/************************/
/* Your Name: Sining Ma */
/* Date: 05/10/2014 */
/* CS 244B */
/* Spring 2013 */
/************************/
#define DEBUG
#include <stdio.h>
#include <string.h>
#include <client.h>
#include <appl.h>
/* ------------------------------------------------------------------ */
int
main() {
int fd;
int loopCnt;
int byteOffset= 0;
char strData[MaxBlockLength];
char fileName[32] = "writeTest.txt";
/*****************************/
/* Initialize the system */
/*****************************/
if( InitReplFs( ReplFsPort, 0, 2 ) < 0 ) {
fprintf( stderr, "Error initializing the system\n" );
return( ErrorExit );
}
/*****************************/
/* Open the file for writing */
/*****************************/
fd = OpenFile( fileName );
if ( fd < 0 ) {
fprintf( stderr, "Error opening file '%s'\n", fileName );
return( ErrorExit );
}
/**************************************/
/* Write incrementing numbers to the file */
/**************************************/
for ( loopCnt=0; loopCnt<128; loopCnt++ ) {
sprintf( strData, "%d\n", loopCnt );
#ifdef DEBUG
printf( "%d: Writing '%s' to file.\n", loopCnt, strData );
#endif
if ( WriteBlock( fd, strData, byteOffset, strlen( strData ) ) < 0 ) {
printf( "Error writing to file %s [LoopCnt=%d]\n", fileName, loopCnt );
return( ErrorExit );
}
byteOffset += strlen( strData );
}
/**********************************************/
/* Can we commit the writes to the server(s)? */
/**********************************************/
if ( Commit( fd ) < 0 ) {
printf( "Could not commit changes to File '%s'\n", fileName );
return( ErrorExit );
}
/**************************************/
/* Close the writes to the server(s) */
/**************************************/
if ( CloseFile( fd ) < 0 ) {
printf( "Error Closing File '%s'\n", fileName );
return( ErrorExit );
}
printf( "Writes to file '%s' complete.\n", fileName );
return( NormalExit );
}
/* ------------------------------------------------------------------ */