3 Copyright (C) 2006-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <libkernel/kernel.h>
20 #include <libkernel/type_noprefix.h>
21 #include <libkernel/message_noprefix.h>
22 #include <libserver/fs_noprefix.h>
24 // TODO: This is a HACK
25 size_t strlen(const char * s
)
34 char *strcpy(char *s1
, const char *s2
)
37 while ((*s1
++ = *s2
++));
40 char *strncpy(char *s1
, const char *s2
, size_t n
)
43 while (( n
> 0) && (*s1
++ = *s2
++))
58 port_id_t
_LIBSERVER_get_fs_from_name(port_id_t port
,
61 void *(*malloc
)(size_t))
63 shared_memory_t shm
= _LIBKERNEL_create_shared_memory(sizeof(file_name_info
));
64 file_name_info
*info
= shm
.address
;
65 strncpy(info
->name
, name
, FILENAME_MAX
);
67 message_t msg
= _LIBKERNEL_create_message_shm(PORT_VFS
,
71 SHM_TRANSFER_OWNERSHIP
);
72 _LIBKERNEL_send_message(port
, &msg
);
73 message_t reply
= _LIBKERNEL_create_message(PORT_VFS
,
78 _LIBKERNEL_add_wait_message(port
, &reply
);
79 _LIBKERNEL_wait_message(&reply
);
81 if (_LIBKERNEL_get_message_attribute(&reply
) == SHM_TRANSFER_OWNERSHIP
)
83 shared_memory_t shared
= _LIBKERNEL_get_shared_memory(&reply
);
84 file_name_info
*tmp
= shared
.address
;
85 *fsname
= malloc(strlen(tmp
->name
) + 1);
86 strcpy(*fsname
, tmp
->name
);
87 _LIBKERNEL_destroy_shared_memory(&shared
);
91 *fsname
= malloc(strlen(&name
[reply
.param2
]) + 1);
92 strcpy(*fsname
, &name
[reply
.param2
]);
94 _LIBKERNEL_destroy_shared_memory(&shm
);
98 bool _LIBSERVER_file_exists(port_id_t port
,
102 shared_memory_t shm
= _LIBKERNEL_create_shared_memory(sizeof(file_name_info
));
103 strncpy(shm
.address
, relname
, FILENAME_MAX
);
105 message_t msg
= _LIBKERNEL_create_message_shm(fsport
,
109 SHM_TRANSFER_OWNERSHIP
);
110 _LIBKERNEL_send_message(port
, &msg
);
111 message_t reply
= _LIBKERNEL_create_message(fsport
,
116 _LIBKERNEL_add_wait_message(port
, &reply
);
117 _LIBKERNEL_wait_message(&reply
);
121 bool _LIBSERVER_create_file(port_id_t port
,
124 message_param_t type
,
125 message_param_t flags
,
126 message_param_t blocksize
,
127 message_param_t blockcount
)
129 shared_memory_t shm
= _LIBKERNEL_create_shared_memory(sizeof(file_info
));
130 file_info
*info
= shm
.address
;
131 strncpy(info
->name
, relname
, FILENAME_MAX
);
133 info
->blocksize
= blocksize
;
134 info
->blockcount
= blockcount
;
136 message_t msg
= _LIBKERNEL_create_message_shm(fsport
,
140 SHM_TRANSFER_OWNERSHIP
);
141 _LIBKERNEL_send_message(port
, &msg
);
142 message_t reply
= _LIBKERNEL_create_message(fsport
,
147 _LIBKERNEL_add_wait_message(port
, &reply
);
148 _LIBKERNEL_wait_message(&reply
);
152 bool _LIBSERVER_open_file(port_id_t port
,
155 message_param_t flags
)
157 shared_memory_t shm
= _LIBKERNEL_create_shared_memory(sizeof(file_info
));
158 _LIBSERVER_file_info
*info
= shm
.address
;
159 strncpy(info
->name
, relname
, FILENAME_MAX
);
161 message_t msg
= _LIBKERNEL_create_message_shm(fsport
,
165 SHM_TRANSFER_OWNERSHIP
);
166 _LIBKERNEL_send_message(port
, &msg
);
167 message_t reply
= _LIBKERNEL_create_message(fsport
,
172 _LIBKERNEL_add_wait_message(port
, &reply
);
173 _LIBKERNEL_wait_message(&reply
);
174 if (reply
.param1
== 0)