2018-12-09 02:59:04 +00:00
|
|
|
const Errors = require('./errors.js');
|
|
|
|
const Node = require('./node');
|
2014-10-17 16:55:36 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2018-12-09 02:59:04 +00:00
|
|
|
Node.create(node, callback);
|
2014-10-17 16:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|