12.07.2015 Views

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FILEASSOC (9) <strong>NetBSD</strong> <strong>Kernel</strong> Developer’s <strong>Manual</strong> FILEASSOC (9)Note that calling fileassoc_deregister() only frees the associated slot in the fileassocsubsystem. It is up to the developer to take care of garbage collection.Lookup RoutinesThese routines allow lookup of fileassoc mounts, files, and private data attached to them.void ∗ fileassoc_lookup(struct vnode ∗vp , fileassoc_t id)Returns the private data for the file/id combination or NULL if not found.Mount-wide Routinesint fileassoc_table_delete(struct mount ∗mp)Deletes a fileassoc table for mp.int fileassoc_table_clear(struct mount ∗mp , fileassoc_t id)Clear all table entries for fileassoc from mp.If specified, the fileassoc’s “cleanup routine” will be called with a pointer to the private data-structure.int fileassoc_table_run(struct mount ∗mp , fileassoc_t id , fileassoc_cb_tcb , void ∗cookie)For each entry for id, call cb with the entry being the first argument, and cookie being the secondargument.cb is a function returning void and receiving one void ∗ parameter.File-specific Routinesint fileassoc_file_delete(struct vnode ∗vp)Delete the fileassoc entries for vp.If specified, the “cleanup routines” of all fileassoc types added will be called with a pointer to thecorresponding private data structure and indication of FILEASSOC_CLEANUP_FILE.Fileassoc-specific Routinesint fileassoc_add(struct vnode ∗vp , fileassoc_t id , void ∗data)Add private data in data for vp, for the fileassoc specified by id.If a table for the mount-point vp is on doesn’t exist, one will be created automatically.fileassoc manages internally the optimal table sizes as tables are modified.int fileassoc_clear(struct vnode ∗vp , fileassoc_t id)Clear the private data for vp, for the fileassoc specified by id.If specified, the fileassoc’s “cleanup routine” will be called with a pointer to the private data-structureand indication of FILEASSOC_CLEANUP_FILE.EXAMPLESThe following code examples should give you a clue on using fileassoc for your purposes.First, we’ll begin with registering a new id. We need to do that to save a slot for private data storage witheach mount and/or file:fileassoc_t myhook_id;int error;error = fileassoc_register("my_hook", myhook_cleanup, &myhook_id);if (error != 0)<strong>NetBSD</strong> 3.0 May 15, 2007 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!