Subversion Repositories HelenOS

Rev

Rev 2949 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2949 Rev 2959
Line 40... Line 40...
40
#include <vfs/vfs.h>
40
#include <vfs/vfs.h>
41
#include <sys/types.h>
41
#include <sys/types.h>
42
#include "data.h"
42
#include "data.h"
43
 
43
 
44
#define min(a,b) ((a)>(b) ? (b) : (a))
44
#define min(a,b) ((a)>(b) ? (b) : (a))
-
 
45
 
45
int main(int argc, char *argv[])
46
int write_file(const uint8_t *data, size_t length, const char *file_name)
46
{
47
{
47
    int fd;
-
 
48
    int cnt;
-
 
49
    int rc;
-
 
50
    int nbytes;
48
    int nbytes;
51
    uint8_t *dp;
49
    uint8_t *dp;
52
    int written;
50
    int written;
-
 
51
    int fd;
-
 
52
    int cnt;
53
 
53
 
54
    printf("This is iramfs\n");
54
    printf("Create %s\n", file_name);
55
    do {
-
 
56
        rc = mount("tmpfs", "/", "nulldev0");
-
 
57
        printf("mount tmpfs on / -> %d\n", rc);
-
 
58
        if (rc == 0) break;
-
 
59
 
-
 
60
        usleep(1000 * 1000);
-
 
61
    } while (1);
-
 
62
   
-
 
63
 
55
 
64
    fd = open(data_filename, O_CREAT);
56
    fd = open(file_name, O_CREAT);
65
    if (fd < 0) { printf("open failed\n"); return 1; }
57
    if (fd < 0) { printf("open failed\n"); return -1; }
66
 
58
 
67
    printf("write %d bytes...\n", data_size);
59
    printf("write %d bytes...\n", length);
68
    nbytes = data_size; dp = data; written = 0;
60
    nbytes = length; dp = data; written = 0;
69
    while (nbytes > 0) {
61
    while (nbytes > 0) {
70
        cnt = write(fd, dp, min(4096, nbytes));
62
        cnt = write(fd, dp, min(4096, nbytes));
71
        if (cnt < 0) { printf("write failed\n"); return 1; }
63
        if (cnt < 0) { printf("write failed\n"); return -1; }
72
        dp += cnt;
64
        dp += cnt;
73
        written += cnt;
65
        written += cnt;
74
        nbytes -= cnt;
66
        nbytes -= cnt;
75
        printf("written: %d, cnt: %d, left: %d\n", written, cnt, nbytes);
67
        printf("written: %d, cnt: %d, left: %d\n", written, cnt, nbytes);
76
    }
68
    }
77
 
69
 
78
    printf("\n\nwritten %d bytes\n", written);
70
    printf("\n\nwritten %d bytes\n", written);
79
    close(fd);
71
    close(fd);
80
 
72
 
-
 
73
    return 0;
-
 
74
}
-
 
75
 
-
 
76
int main(int argc, char *argv[])
-
 
77
{
-
 
78
    int rc;
-
 
79
 
-
 
80
    printf("This is iramfs\n");
-
 
81
    do {
-
 
82
        rc = mount("tmpfs", "/", "nulldev0");
-
 
83
        printf("mount tmpfs on / -> %d\n", rc);
-
 
84
        if (rc == 0) break;
-
 
85
 
-
 
86
        usleep(1000 * 1000);
-
 
87
    } while (1);
-
 
88
 
-
 
89
    if (write_file(rtld, rtld_size, rtld_filename) < 0) return 1;
-
 
90
    if (write_file(tetris, tetris_size, tetris_filename) < 0) return 1;
-
 
91
 
81
    printf("done\n");
92
    printf("done\n");
82
    getchar();
93
    getchar();
83
    return 0;
94
    return 0;
84
}
95
}
85
 
96