/* ad_util.c */
extern int openvol(AFPObj *obj, const char *path, afpvol_t *vol);
extern void closevol(afpvol_t *vol);
-extern cnid_t cnid_for_path(const afpvol_t *vol, const char *path, cnid_t *did);
extern cnid_t cnid_for_paths_parent(const afpvol_t *vol, const char *path, cnid_t *did);
extern char *utompath(const struct vol *, const char *);
extern int convert_dots_encoding(const afpvol_t *svol, const afpvol_t *dvol, char *path, size_t buflen);
/* Get CNID of Parent and add new childir to CNID database */
ppdid = pdid;
- if ((did = cnid_for_path(&dvolume, to.p_path, &pdid)) == CNID_INVALID) {
+ if ((did = cnid_for_path(dvolume.vol->v_cdb, dvolume.vol->v_path, to.p_path, &pdid)) == CNID_INVALID) {
SLOG("Error resolving CNID for %s", to.p_path);
badcp = rval = 1;
return -1;
/* Get CNID of Parent and add new childir to CNID database */
pdid = did;
cnid_t cnid;
- if ((cnid = cnid_for_path(&dvolume, to.p_path, &did)) == CNID_INVALID) {
+ if ((cnid = cnid_for_path(dvolume.vol->v_cdb, dvolume.vol->v_path, to.p_path, &did)) == CNID_INVALID) {
SLOG("Error resolving CNID for %s", to.p_path);
badcp = rval = 1;
return -1;
cnid_t cnid = 0;
if (!mustcopy) {
- if ((cnid = cnid_for_path(&svolume, from, &did)) == CNID_INVALID) {
+ if ((cnid = cnid_for_path(svolume.vol->v_cdb, svolume.vol->v_path, from, &did)) == CNID_INVALID) {
SLOG("Couldn't resolve CNID for %s", from);
return -1;
}
/* Get CNID of Parent and add new childir to CNID database */
pdid = did;
- if ((cnid = cnid_for_path(&volume, path, &did)) == CNID_INVALID) {
+ if ((cnid = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &did)) == CNID_INVALID) {
SLOG("Error resolving CNID for %s", path);
return -1;
}
}
/* Get CNID of Parent and add new childir to CNID database */
- if ((did = cnid_for_path(&volume, path, &pdid)) == CNID_INVALID) {
+ if ((did = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &pdid)) == CNID_INVALID) {
SLOG("Error resolving CNID for %s", path);
return -1;
}
/* Get CNID of Parent and add new childir to CNID database */
pdid = did;
- if ((cnid = cnid_for_path(&volume, path, &did)) == CNID_INVALID) {
+ if ((cnid = cnid_for_path(volume.vol->v_cdb, volume.vol->v_path, path, &did)) == CNID_INVALID) {
SLOG("Error resolving CNID for %s", path);
return -1;
}
return 0;
}
-/*!
- * ResolvesCNID of a given paths
- *
- * path might be:
- * (a) relative:
- * "dir/subdir" with cwd: "/afp_volume/topdir"
- * (b) absolute:
- * "/afp_volume/dir/subdir"
- *
- * path MUST be pointing inside vol, this is usually the case as vol has been build from
- * path using loadvolinfo and friends.
- *
- * @param vol (r) pointer to afpvol_t
- * @param path (r) path, see above
- * @param did (rw) parent CNID of returned CNID
- *
- * @returns CNID of path
- */
-cnid_t cnid_for_path(const afpvol_t *vol,
- const char *path,
- cnid_t *did)
-{
- EC_INIT;
-
- cnid_t cnid;
- bstring rpath = NULL;
- bstring statpath = NULL;
- struct bstrList *l = NULL;
- struct stat st;
-
- cnid = htonl(2);
-
- EC_NULL(rpath = rel_path_in_vol(path, vol->vol->v_path));
- EC_NULL(statpath = bfromcstr(vol->vol->v_path));
- EC_ZERO(bcatcstr(statpath, "/"));
-
- l = bsplit(rpath, '/');
- for (int i = 0; i < l->qty ; i++) {
- *did = cnid;
-
- EC_ZERO(bconcat(statpath, l->entry[i]));
- EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
- "lstat(rpath: %s, elem: %s): %s: %s",
- cfrombstr(rpath), cfrombstr(l->entry[i]),
- cfrombstr(statpath), strerror(errno));
-
- if ((cnid = cnid_add(vol->vol->v_cdb,
- &st,
- *did,
- cfrombstr(l->entry[i]),
- blength(l->entry[i]),
- 0)) == CNID_INVALID) {
- EC_FAIL;
- }
- EC_ZERO(bcatcstr(statpath, "/"));
- }
-
-EC_CLEANUP:
- bdestroy(rpath);
- bstrListDestroy(l);
- bdestroy(statpath);
- if (ret != 0)
- return CNID_INVALID;
-
- return cnid;
-}
-
/*!
* Resolves CNID of a given paths parent directory
*
#include <atalk/unicode.h>
#include <atalk/bstrlib.h>
+#include <atalk/cnid.h>
/* exit error codes */
#define EXITERR_CLNT 1 /* client related error */
*****************************************************************/
extern bstring rel_path_in_vol(const char *path, const char *volpath);
+extern cnid_t cnid_for_path(struct _cnid_db *cdb, const char *volpath, const char *path, cnid_t *did);
#endif /* _ATALK_UTIL_H */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
-
+#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
return NULL;
return fpath;
}
+
+/*!
+ * Resolves CNID of a given path
+ *
+ * path might be:
+ * (a) relative:
+ * "dir/subdir" with cwd: "/afp_volume/topdir"
+ * (b) absolute:
+ * "/afp_volume/dir/subdir"
+ *
+ * path MUST be pointing inside vol, this is usually the case as vol has been build from
+ * path using loadvolinfo and friends.
+ *
+ * @param cdb (r) CNID db handle
+ * @param volpath (r) UNIX path of volume
+ * @param path (r) path, see above
+ * @param did (w) parent CNID of returned CNID
+ *
+ * @returns CNID of path
+ */
+cnid_t cnid_for_path(struct _cnid_db *cdb,
+ const char *volpath,
+ const char *path,
+ cnid_t *did)
+{
+ EC_INIT;
+
+ cnid_t cnid;
+ bstring rpath = NULL;
+ bstring statpath = NULL;
+ struct bstrList *l = NULL;
+ struct stat st;
+
+ cnid = htonl(2);
+
+ EC_NULL(rpath = rel_path_in_vol(path, volpath));
+ EC_NULL(statpath = bfromcstr(volpath));
+ EC_ZERO(bcatcstr(statpath, "/"));
+
+ l = bsplit(rpath, '/');
+ for (int i = 0; i < l->qty ; i++) {
+ *did = cnid;
+
+ EC_ZERO(bconcat(statpath, l->entry[i]));
+ EC_ZERO_LOGSTR(lstat(cfrombstr(statpath), &st),
+ "lstat(rpath: %s, elem: %s): %s: %s",
+ cfrombstr(rpath), cfrombstr(l->entry[i]),
+ cfrombstr(statpath), strerror(errno));
+
+ if ((cnid = cnid_add(cdb,
+ &st,
+ *did,
+ cfrombstr(l->entry[i]),
+ blength(l->entry[i]),
+ 0)) == CNID_INVALID) {
+ EC_FAIL;
+ }
+ EC_ZERO(bcatcstr(statpath, "/"));
+ }
+
+EC_CLEANUP:
+ bdestroy(rpath);
+ bstrListDestroy(l);
+ bdestroy(statpath);
+ if (ret != 0)
+ return CNID_INVALID;
+
+ return cnid;
+}