Date: Mon, 19 Jan 2009 01:01:36 +0000 From: "Andrew Brampton" <brampton+freebsd-fs@gmail.com> To: freebsd-fs@freebsd.org Subject: Pseudofs and pfs_attr_t for non-process based files Message-ID: <d41814900901181701n7928e40cv2aa1dc4dff582fda@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
------=_Part_14457_7088607.1232326896122 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, I've recently been coding a pseudofs based file system to export data from a custom kernel module, and allow users to control the module via the file system. Anyway, I quite like how simple it is to use pseudofs, but I found one annoying "feature". If I call pfs_create_{dir, file, link} with a pfs_attr_t function pointer, my function will never be called. I tracked this problem to the function pfs_getattr inside sys/fs/pseudofs/pseudofs_vnops.c. It has the following lines of code: if (proc != NULL) { ... if (pn->pn_attr != NULL) error = pn_attr(curthread, proc, pn, vap); ... } Basically pn_attr calls my pfs_attr_t function pointer, but only if the proc != null. Now in my case none of my files are created PFS_PROCDEP flag, which mean proc will always be null. So unless you are writing a pseudofs which is dependent on the process calling it, you cannot use a pfs_attr_t function pointer, meaning I can't change the attributes on my pseudo files. Now, to fix this problem I made a very simple patch which will call pn_attr regardless of proc being null or not. By doing this I had to also make a minor change in procfs.c as it assumes a valid proc is always passed in. I'd be grateful if someone look over my patches, and advise me if this was the correct thing to do. Also I'd be interested to know why this was original coded like this? Or was it just a oversight? Just for reference there is also a few more callbacks for various file system operations, with all of them working if proc is null, with one exception, the pfs_vis_t callback. Perhaps that should also be updated also? Thanks Andrew ------=_Part_14457_7088607.1232326896122 Content-Type: application/octet-stream; name=pseudofs_vnops.patch Content-Transfer-Encoding: base64 X-Attachment-Id: f_fq4fhez20 Content-Disposition: attachment; filename=pseudofs_vnops.patch SW5kZXg6IHN5cy9mcy9wc2V1ZG9mcy9wc2V1ZG9mc192bm9wcy5jDQo9PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09DQotLS0g c3lzL2ZzL3BzZXVkb2ZzL3BzZXVkb2ZzX3Zub3BzLmMgICAgKHJldmlzaW9uIDE4NzQxNSkNCisr KyBzeXMvZnMvcHNldWRvZnMvcHNldWRvZnNfdm5vcHMuYyAgICAod29ya2luZyBjb3B5KQ0KQEAg LTIyNiwxNCArMjI2LDE3IEBADQogICAgICAgIGlmIChwcm9jICE9IE5VTEwpIHsNCiAgICAgICAg ICAgICAgICB2YXAtPnZhX3VpZCA9IHByb2MtPnBfdWNyZWQtPmNyX3J1aWQ7DQogICAgICAgICAg ICAgICAgdmFwLT52YV9naWQgPSBwcm9jLT5wX3VjcmVkLT5jcl9yZ2lkOw0KLSAgICAgICAgICAg ICAgIGlmIChwbi0+cG5fYXR0ciAhPSBOVUxMKQ0KLSAgICAgICAgICAgICAgICAgICAgICAgZXJy b3IgPSBwbl9hdHRyKGN1cnRocmVhZCwgcHJvYywgcG4sIHZhcCk7DQotICAgICAgICAgICAgICAg UFJPQ19VTkxPQ0socHJvYyk7DQogICAgICAgIH0gZWxzZSB7DQogICAgICAgICAgICAgICAgdmFw LT52YV91aWQgPSAwOw0KICAgICAgICAgICAgICAgIHZhcC0+dmFfZ2lkID0gMDsNCiAgICAgICAg fQ0KDQorICAgICAgIGlmIChwbi0+cG5fYXR0ciAhPSBOVUxMKQ0KKyAgICAgICAgICAgICAgIGVy cm9yID0gcG5fYXR0cihjdXJ0aHJlYWQsIHByb2MsIHBuLCB2YXApOw0KKw0KKyAgICAgICBpZihw cm9jICE9IE5VTEwpDQorICAgICAgICAgICAgICAgUFJPQ19VTkxPQ0socHJvYyk7DQorDQogICAg ICAgIFBGU19SRVRVUk4gKGVycm9yKTsNCiB9DQo= ------=_Part_14457_7088607.1232326896122 Content-Type: application/octet-stream; name=procfs.patch Content-Transfer-Encoding: base64 X-Attachment-Id: f_fq4fhxyu1 Content-Disposition: attachment; filename=procfs.patch SW5kZXg6IHN5cy9mcy9wcm9jZnMvcHJvY2ZzLmMNCj09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0NCi0tLSBzeXMvZnMvcHJv Y2ZzL3Byb2Nmcy5jICAgICAgKHJldmlzaW9uIDE4NzQxNSkNCisrKyBzeXMvZnMvcHJvY2ZzL3By b2Nmcy5jICAgICAgKHdvcmtpbmcgY29weSkNCkBAIC05OSw3ICs5OSw2IEBADQogaW50DQogcHJv Y2ZzX2F0dHIoUEZTX0FUVFJfQVJHUykNCiB7DQotICAgICAgIFBST0NfTE9DS19BU1NFUlQocCwg TUFfT1dORUQpOw0KDQogICAgICAgIC8qIFhYWCBpbmVmZmljaWVudCwgc3BsaXQgaW50byBzZXBh cmF0ZSBmdW5jdGlvbnMgKi8NCiAgICAgICAgaWYgKHN0cmNtcChwbi0+cG5fbmFtZSwgImN0bCIp ID09IDAgfHwNCkBAIC0xMTIsMTIgKzExMSwxNiBAQA0KICAgICAgICAgICAgc3RyY21wKHBuLT5w bl9uYW1lLCAiZnByZWdzIikgPT0gMCkNCiAgICAgICAgICAgICAgICB2YXAtPnZhX21vZGUgPSAw NjAwOw0KDQotICAgICAgIGlmICgocC0+cF9mbGFnICYgUF9TVUdJRCkgJiYgcG4tPnBuX3R5cGUg IT0gcGZzdHlwZV9wcm9jZGlyKQ0KLSAgICAgICAgICAgICAgIHZhcC0+dmFfbW9kZSA9IDA7DQor ICAgICAgIGlmIChwICE9IE5VTEwpIHsNCisgICAgICAgICAgICAgICBQUk9DX0xPQ0tfQVNTRVJU KHAsIE1BX09XTkVEKTsNCg0KLSAgICAgICB2YXAtPnZhX3VpZCA9IHAtPnBfdWNyZWQtPmNyX3Vp ZDsNCi0gICAgICAgdmFwLT52YV9naWQgPSBwLT5wX3VjcmVkLT5jcl9naWQ7DQorICAgICAgICAg ICAgICAgaWYgKChwLT5wX2ZsYWcgJiBQX1NVR0lEKSAmJiBwbi0+cG5fdHlwZSAhPSBwZnN0eXBl X3Byb2NkaXIpDQorICAgICAgICAgICAgICAgICAgICAgICB2YXAtPnZhX21vZGUgPSAwOw0KDQor ICAgICAgICAgICAgICAgdmFwLT52YV91aWQgPSBwLT5wX3VjcmVkLT5jcl91aWQ7DQorICAgICAg ICAgICAgICAgdmFwLT52YV9naWQgPSBwLT5wX3VjcmVkLT5jcl9naWQ7DQorICAgICAgIH0NCisN CiAgICAgICAgcmV0dXJuICgwKTsNCiB9DQo= ------=_Part_14457_7088607.1232326896122--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d41814900901181701n7928e40cv2aa1dc4dff582fda>