X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fsymlink.c;h=6ef0dab16490787a6591f645399c52363b95e53a;hp=60f5ebb601cbd57758ae4678311349623f565c57;hb=277957c10e96a23f822b2e6ae22c8d126a93141a;hpb=ed828dc4cbf4eabc9f8b32cb4c6a86a04e087f7a diff --git a/src/symlink.c b/src/symlink.c index 60f5ebb6..6ef0dab1 100644 --- a/src/symlink.c +++ b/src/symlink.c @@ -10,16 +10,16 @@ * This file is part of wimlib, a library for working with WIM files. * * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) + * terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) * any later version. * * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * - * You should have received a copy of the GNU Lesser General Public License + * You should have received a copy of the GNU General Public License * along with wimlib; if not, see http://www.gnu.org/licenses/. */ @@ -105,7 +105,7 @@ static ssize_t get_symlink_name(const u8 *resource, size_t resource_len, translated_target += 4; link_target_len -= 4; /* There's a drive letter, so just leave the backslashes since - * it won't go anyhwere on UNIX anyway... + * it won't go anyhwere on UNIX anyway... * * XXX * NTFS-3g tries to re-map these links to actually point to @@ -131,27 +131,23 @@ void *make_symlink_reparse_data_buf(const char *symlink_target, size_t *len_ret) char *name_utf16 = utf8_to_utf16(symlink_target, utf8_len, &utf16_len); if (!name_utf16) return NULL; - /*DEBUG("utf16_len = %zu", utf16_len);*/ + for (size_t i = 0; i < utf16_len / 2; i++) - if (((u16*)name_utf16)[i] == to_le16('/')) - ((u16*)name_utf16)[i] = to_le16('\\'); - size_t len = 12 + utf16_len * 2 + 4; + if (((u16*)name_utf16)[i] == cpu_to_le16('/')) + ((u16*)name_utf16)[i] = cpu_to_le16('\\'); + size_t len = 12 + utf16_len * 2; void *buf = MALLOC(len); if (!buf) goto out; - /* XXX Fix absolute paths */ u8 *p = buf; - p = put_u16(p, utf16_len + 2); /* Substitute name offset */ + p = put_u16(p, utf16_len); /* Substitute name offset */ p = put_u16(p, utf16_len); /* Substitute name length */ p = put_u16(p, 0); /* Print name offset */ p = put_u16(p, utf16_len); /* Print name length */ - p = put_u32(p, 1); + p = put_u32(p, 1); /* flags: 0 iff *full* target, including drive letter??? */ p = put_bytes(p, utf16_len, (const u8*)name_utf16); - p = put_u16(p, 0); p = put_bytes(p, utf16_len, (const u8*)name_utf16); - p = put_u16(p, 0); - /*DEBUG("utf16_len = %zu, len = %zu", utf16_len, len);*/ *len_ret = len; out: FREE(name_utf16); @@ -162,15 +158,15 @@ out: * * The dentry may be either "real" symlink or a junction point. */ -ssize_t dentry_readlink(const struct dentry *dentry, char *buf, size_t buf_len, - const WIMStruct *w) +ssize_t inode_readlink(const struct inode *inode, char *buf, size_t buf_len, + const WIMStruct *w, int read_resource_flags) { const struct lookup_table_entry *lte; int ret; - wimlib_assert(dentry_is_symlink(dentry)); + wimlib_assert(inode_is_symlink(inode)); - lte = dentry_unnamed_lte(dentry, w->lookup_table); + lte = inode_unnamed_lte(inode, w->lookup_table); if (!lte) return -EIO; @@ -178,35 +174,15 @@ ssize_t dentry_readlink(const struct dentry *dentry, char *buf, size_t buf_len, return -EIO; u8 res_buf[wim_resource_size(lte)]; - ret = read_full_wim_resource(lte, res_buf); + ret = read_full_wim_resource(lte, res_buf, read_resource_flags); if (ret != 0) return -EIO; return get_symlink_name(res_buf, wim_resource_size(lte), buf, - buf_len, dentry->reparse_tag); -} - -static int dentry_set_symlink_buf(struct dentry *dentry, - struct lookup_table_entry *lte) -{ - struct ads_entry *ads_entries; - - ads_entries = CALLOC(2, sizeof(struct ads_entry)); - if (!ads_entries) - return WIMLIB_ERR_NOMEM; - - wimlib_assert(dentry->num_ads == 0); - wimlib_assert(dentry->ads_entries == NULL); - - ads_entries[0].lte = lte; - - /*dentry_free_ads_entries(dentry);*/ - dentry->num_ads = 2; - dentry->ads_entries = ads_entries; - return 0; + buf_len, inode->reparse_tag); } -/* - * Sets @dentry to be a symbolic link pointing to @target. +/* + * Sets @inode to be a symbolic link pointing to @target. * * A lookup table entry for the symbolic link data buffer is created and * inserted into @lookup_table, unless there is an existing lookup table entry @@ -216,9 +192,9 @@ static int dentry_set_symlink_buf(struct dentry *dentry, * * On failure @dentry and @lookup_table are not modified. */ -int dentry_set_symlink(struct dentry *dentry, const char *target, - struct lookup_table *lookup_table, - struct lookup_table_entry **lte_ret) +int inode_set_symlink(struct inode *inode, const char *target, + struct lookup_table *lookup_table, + struct lookup_table_entry **lte_ret) { int ret; @@ -226,14 +202,14 @@ int dentry_set_symlink(struct dentry *dentry, const char *target, struct lookup_table_entry *lte = NULL, *existing_lte; u8 symlink_buf_hash[SHA1_HASH_SIZE]; void *symlink_buf; - + symlink_buf = make_symlink_reparse_data_buf(target, &symlink_buf_len); if (!symlink_buf) return WIMLIB_ERR_NOMEM; DEBUG("Made symlink reparse data buf (len = %zu, name len = %zu)", symlink_buf_len, symlink_buf_len); - + sha1_buffer(symlink_buf, symlink_buf_len, symlink_buf_hash); existing_lte = __lookup_resource(lookup_table, symlink_buf_hash); @@ -253,16 +229,11 @@ int dentry_set_symlink(struct dentry *dentry, const char *target, lte->attached_buffer = symlink_buf; lte->resource_entry.original_size = symlink_buf_len; lte->resource_entry.size = symlink_buf_len; - lte->resource_entry.flags = 0; copy_hash(lte->hash, symlink_buf_hash); } - ret = dentry_set_symlink_buf(dentry, lte); - - if (ret != 0) - goto out_free_lte; - - dentry->resolved = true; + inode->lte = lte; + inode->resolved = true; DEBUG("Loaded symlink buf"); @@ -273,9 +244,6 @@ int dentry_set_symlink(struct dentry *dentry, const char *target, if (lte_ret) *lte_ret = lte; return 0; -out_free_lte: - if (lte != existing_lte) - FREE(lte); out_free_symlink_buf: FREE(symlink_buf); return ret;