Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How create file in the kernel ?



It's difficult, but try this:

- Allocate a memory mapped block for the filename path :

init_addr = VM_MIN_ADDRESS;
(void) vm_allocate(current_map(), &init_addr, MAXPATHLEN, TRUE);

- copy your kernel's memory mapped pathname into the new block

copyoutstr(kernelpath, init_addr,MAXPATHLEN,&lencopied);

- Fill in an Open parameter block :

typedef struct open_args {
char *path;
int flags;
int mode;
} open_args_t;

openargs.path = init_addr;
flags = what you want ...
mode = same ...

- Call the open syscall entry point

register_t retval;
error = (*sysent[SYS_open].sy_call)(current_proc(),openargs,&retval);


The problem is that the opened file descriptor is owned by the current task,
so you have to close the file before returning to user mode.

Also, don't forget to vm_deallocate() the block of memory ;-)

Hope this helps,
--
phildev

> Dear Sir:
> I need a function to create file in driver ,but I don't know how do this.
> where have sample in the kernel open with read file.Thanks
>
> Regards.
> _______________________________________________
> darwin-drivers mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/darwin-drivers
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-drivers mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-drivers
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.