2014-10-17 16:55:36 +00:00
|
|
|
var Errors = require('./errors.js');
|
|
|
|
|
|
|
|
function OpenFileDescription(path, id, flags, position) {
|
2014-05-23 18:14:06 +00:00
|
|
|
this.path = path;
|
|
|
|
this.id = id;
|
|
|
|
this.flags = flags;
|
|
|
|
this.position = position;
|
2014-10-17 16:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tries to find the node associated with an ofd's `id`.
|
|
|
|
// If not found, an error is returned on the callback.
|
|
|
|
OpenFileDescription.prototype.getNode = function(context, callback) {
|
|
|
|
var id = this.id;
|
|
|
|
var path = this.path;
|
|
|
|
|
|
|
|
function check_if_node_exists(error, node) {
|
|
|
|
if(error) {
|
|
|
|
return callback(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!node) {
|
|
|
|
return callback(new Errors.EBADF('file descriptor refers to unknown node', path));
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.getObject(id, check_if_node_exists);
|
2014-05-23 18:14:06 +00:00
|
|
|
};
|
2014-10-17 16:55:36 +00:00
|
|
|
|
|
|
|
module.exports = OpenFileDescription;
|