163 |
return count; |
return count; |
164 |
} |
} |
165 |
|
|
166 |
/* Opens of creates a file or directory */ |
/* Opens or creates a file or directory */ |
167 |
NTSTATUS |
NTSTATUS |
168 |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
169 |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
181 |
if (filename[strlen(filename) - 1] == '/') |
if (filename[strlen(filename) - 1] == '/') |
182 |
filename[strlen(filename) - 1] = 0; |
filename[strlen(filename) - 1] = 0; |
183 |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
|
//printf("Open: %s\n", path); |
|
184 |
|
|
185 |
switch (create_disposition) |
switch (create_disposition) |
186 |
{ |
{ |
215 |
break; |
break; |
216 |
} |
} |
217 |
|
|
218 |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
/* the sad part is that we can't trust this flag */ |
219 |
|
/* directories aren't always marked */ |
220 |
|
if (flags_and_attributes ^ FILE_DIRECTORY_FILE) |
221 |
{ |
{ |
222 |
if (flags & O_CREAT) |
if (accessmask & GENERIC_ALL |
223 |
|
|| (accessmask & GENERIC_READ && accessmask & GENERIC_WRITE)) |
224 |
{ |
{ |
225 |
mkdir(path, mode); |
flags |= O_RDWR; |
226 |
|
} |
227 |
|
else if ((accessmask & GENERIC_WRITE) && !(accessmask & GENERIC_READ)) |
228 |
|
{ |
229 |
|
flags |= O_WRONLY; |
230 |
|
} |
231 |
|
else |
232 |
|
{ |
233 |
|
flags |= O_RDONLY; |
234 |
} |
} |
235 |
|
|
236 |
dirp = opendir(path); |
handle = open(path, flags, mode); |
237 |
if (!dirp) |
if (handle == -1) |
238 |
{ |
{ |
239 |
switch (errno) |
switch (errno) |
240 |
{ |
{ |
248 |
|
|
249 |
default: |
default: |
250 |
|
|
251 |
perror("opendir"); |
perror("open"); |
252 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
253 |
} |
} |
254 |
} |
} |
255 |
handle = DIRFD(dirp); |
|
256 |
|
/* all read and writes of files should be non blocking */ |
257 |
|
if (fcntl(handle, F_SETFL, O_NONBLOCK) == -1) |
258 |
|
perror("fcntl"); |
259 |
} |
} |
260 |
else |
|
261 |
|
/* since we can't trust the FILE_DIRECTORY_FILE flag */ |
262 |
|
/* we need to double check that the file isn't a dir */ |
263 |
|
if (handle != 0) |
264 |
{ |
{ |
265 |
if (accessmask & GENERIC_ALL |
/* Must check if this file isn't actually a directory */ |
266 |
|| (accessmask & GENERIC_READ && accessmask & GENERIC_WRITE)) |
struct stat filestat; |
267 |
{ |
|
268 |
flags |= O_RDWR; |
// Get information about file and set that flag ourselfs |
269 |
} |
if ((fstat(handle, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
|
else if ((accessmask & GENERIC_WRITE) && !(accessmask & GENERIC_READ)) |
|
270 |
{ |
{ |
271 |
flags |= O_WRONLY; |
flags_and_attributes |= FILE_DIRECTORY_FILE; |
272 |
|
close(handle); |
273 |
|
handle = 0; |
274 |
} |
} |
275 |
else |
} |
276 |
|
|
277 |
|
|
278 |
|
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
279 |
|
{ |
280 |
|
if (flags & O_CREAT) |
281 |
{ |
{ |
282 |
flags |= O_RDONLY; |
mkdir(path, mode); |
283 |
} |
} |
284 |
|
|
285 |
handle = open(path, flags, mode); |
dirp = opendir(path); |
286 |
if (handle == -1) |
if (!dirp) |
287 |
{ |
{ |
288 |
switch (errno) |
switch (errno) |
289 |
{ |
{ |
297 |
|
|
298 |
default: |
default: |
299 |
|
|
300 |
perror("open"); |
perror("opendir"); |
301 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
302 |
} |
} |
303 |
} |
} |
304 |
|
handle = DIRFD(dirp); |
305 |
} |
} |
306 |
|
|
307 |
if (handle >= MAX_OPEN_FILES) |
if (handle >= MAX_OPEN_FILES) |
315 |
g_fileinfo[handle].pdir = dirp; |
g_fileinfo[handle].pdir = dirp; |
316 |
g_fileinfo[handle].device_id = device_id; |
g_fileinfo[handle].device_id = device_id; |
317 |
g_fileinfo[handle].flags_and_attributes = flags_and_attributes; |
g_fileinfo[handle].flags_and_attributes = flags_and_attributes; |
318 |
|
// printf("create: attrib: %u handle %u\n", g_fileinfo[handle].flags_and_attributes, handle ); |
319 |
strncpy(g_fileinfo[handle].path, path, 255); |
strncpy(g_fileinfo[handle].path, path, 255); |
320 |
|
|
321 |
*phandle = handle; |
*phandle = handle; |
347 |
{ |
{ |
348 |
int n; |
int n; |
349 |
|
|
350 |
|
/* browsing dir ???? */ |
351 |
|
/* each request is 24 bytes */ |
352 |
|
if (g_fileinfo[handle].flags_and_attributes & FILE_DIRECTORY_FILE) |
353 |
|
{ |
354 |
|
*result = 0; |
355 |
|
return STATUS_SUCCESS; |
356 |
|
} |
357 |
|
|
358 |
if (offset) |
if (offset) |
359 |
lseek(handle, offset, SEEK_SET); |
lseek(handle, offset, SEEK_SET); |
360 |
n = read(handle, data, length); |
n = read(handle, data, length); |
635 |
|
|
636 |
// Get information for directory entry |
// Get information for directory entry |
637 |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
638 |
/* JIF |
/* JIF |
639 |
printf("Stat: %s\n", fullpath); */ |
printf("Stat: %s\n", fullpath); */ |
640 |
if (stat(fullpath, &fstat)) |
if (stat(fullpath, &fstat)) |
641 |
{ |
{ |