2 * Copyright 2009-2014, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
7 #include "PackagesDirectory.h"
15 #include "DebugSupport.h"
18 PackagesDirectory::PackagesDirectory()
29 PackagesDirectory::~PackagesDirectory()
39 PackagesDirectory::IsNewer(const PackagesDirectory
* a
,
40 const PackagesDirectory
* b
)
42 if (b
->fStateName
.IsEmpty())
44 if (a
->fStateName
.IsEmpty())
46 return strcmp(a
->fStateName
, b
->fStateName
) > 0;
51 PackagesDirectory::Init(const char* path
, dev_t mountPointDeviceID
,
52 ino_t mountPointNodeID
, struct stat
& _st
)
54 // Open the directory. We want the path be interpreted depending on from
55 // where it came (kernel or userland), but we always want a FD in the
56 // kernel I/O context. There's no VFS service method to do that for us,
57 // so we need to do that ourselves.
59 = team_get_current_team_id() == team_get_kernel_team_id();
60 // Not entirely correct, but good enough for now. The only
61 // alternative is to have that information passed in as well.
66 error
= vfs_get_vnode_from_path(path
, calledFromKernel
, &vnode
);
68 // No path given -- use the "packages" directory at our mount point.
69 error
= vfs_entry_ref_to_vnode(mountPointDeviceID
, mountPointNodeID
,
73 ERROR("Failed to open packages directory \"%s\"\n", strerror(error
));
77 return _Init(vnode
, _st
);
82 PackagesDirectory::InitOldState(dev_t adminDirDeviceID
, ino_t adminDirNodeID
,
83 const char* stateName
)
85 if (!fStateName
.SetTo(stateName
))
86 RETURN_ERROR(B_NO_MEMORY
);
89 status_t error
= vfs_entry_ref_to_vnode(adminDirDeviceID
, adminDirNodeID
,
92 ERROR("Failed to open old state directory \"%s\"\n", strerror(error
));
97 return _Init(vnode
, st
);
102 PackagesDirectory::_Init(struct vnode
* vnode
, struct stat
& _st
)
104 fDirFD
= vfs_open_vnode(vnode
, O_RDONLY
, true);
107 ERROR("Failed to open packages directory \"%s\"\n", strerror(fDirFD
));
108 vfs_put_vnode(vnode
);
109 RETURN_ERROR(fDirFD
);
111 // Our vnode reference has been transferred to the FD.
113 // Is it a directory at all?
114 struct stat
& st
= _st
;
115 if (fstat(fDirFD
, &st
) < 0)
118 fNodeRef
.device
= st
.st_dev
;
119 fNodeRef
.node
= st
.st_ino
;
121 // get a normalized path
122 KPath normalizedPath
;
123 if (normalizedPath
.InitCheck() != B_OK
)
124 RETURN_ERROR(normalizedPath
.InitCheck());
126 char* normalizedPathBuffer
= normalizedPath
.LockBuffer();
127 status_t error
= vfs_entry_ref_to_path(fNodeRef
.device
, fNodeRef
.node
, NULL
,
128 true, normalizedPathBuffer
, normalizedPath
.BufferSize());
132 fPath
= strdup(normalizedPathBuffer
);
134 RETURN_ERROR(B_NO_MEMORY
);