3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * Copyright (C) 2009 Martin 'povik' Poviser (martin.povik@gmail.com)
6 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 int write (unsigned fd
, void *buf
, unsigned len
)
40 fd_t
*d
= fd_get (fd
);
43 DPRINT ("write () -> !fd %d", fd
);
47 if (d
->flags
& O_RDONLY
)
50 if (d
->flags
& FD_PIPE
) {
51 pipe_t
*p
= pipe_get (fd
);
54 return pipe_write (p
, buf
, len
);
59 if (d
->flags
& FD_TERM
) {
60 tty_t
*ttyold
= currtty
;
64 tty
= tty_find (d
->dev
->devname
+5);
71 //task_t *taskold = _curr_task;
72 //_curr_task = tty->task;
74 char *str
= (char *) buf
;
78 for (i
= len
; i
>= 0; i
--)
90 //_curr_task = taskold;
100 DPRINT ("write () -> !file");
104 unsigned file_len
= strlen (file
);
106 /* create file when not exist */
107 if (d
->flags
& O_CREAT
)
108 vfs_touch ((char *) file
, file_len
);
111 cache_t
*cache
= cache_create (buf
, len
, 1);
116 d
->s
= (char *) &cache
->data
;
117 //memcpy (d->s, (char *) buf, len);
120 DPRINT ("write () - file descriptor got wrong address space");
125 proc_t
*proc
= proc_find (_curr_task
);
128 proc
= (proc_t
*) &proc_kernel
;
130 /* calculate size of process image (binary file) */
131 unsigned p
= (unsigned) palign ((void *) (proc
->end
- proc
->start
));
133 vfs_content_t content
;
134 content
.ptr
= d
->s
- p
;
137 if (!vfs_mmap (file
, file_len
, &content
)) {
138 DPRINT ("write () -> !vfs_mmap");
142 DPRINT ("write () - d->e > 0 (not implemented) - O_APPEND..");