Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation against musl libc #64

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: ci
on: [pull_request]

jobs:
build:
name: build
build_ubuntu:
name: build on Ubuntu
runs-on: ubuntu-22.04
steps:
- name: checking out
Expand All @@ -15,3 +15,18 @@ jobs:
working-directory: tgt
run: |
make
build_alpine:
name: build on Alpine Linux
runs-on: ubuntu-22.04
steps:
- name: checking out
uses: actions/checkout@v3
with:
path: tgt
- name: Setup Alpine Linux
uses: jirutka/setup-alpine@v1

- name: build
working-directory: tgt
run: |
make
1 change: 1 addition & 0 deletions usr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ endif

INCLUDES += -I.

CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -D_GNU_SOURCE
CFLAGS += $(INCLUDES)
ifneq ($(DEBUG),)
Expand Down
12 changes: 6 additions & 6 deletions usr/bs_rdwr.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
break;
}

ret = pread64(fd, tmpbuf, length, offset);
ret = pread(fd, tmpbuf, length, offset);

if (ret != length) {
set_medium_error(cmd);
Expand Down Expand Up @@ -113,7 +113,7 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
break;
}

ret = pread64(fd, tmpbuf, length, offset);
ret = pread(fd, tmpbuf, length, offset);

if (ret != length) {
set_medium_error(cmd);
Expand Down Expand Up @@ -175,7 +175,7 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
length = scsi_get_out_length(cmd);
write_buf = scsi_get_out_buffer(cmd);
write:
ret = pwrite64(fd, write_buf, length,
ret = pwrite(fd, write_buf, length,
offset);
if (ret == length) {
struct mode_pg *pg;
Expand Down Expand Up @@ -233,7 +233,7 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
break;
}

ret = pwrite64(fd, tmpbuf, blocksize, offset);
ret = pwrite(fd, tmpbuf, blocksize, offset);
if (ret != blocksize)
set_medium_error(cmd);

Expand All @@ -246,7 +246,7 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
case READ_12:
case READ_16:
length = scsi_get_in_length(cmd);
ret = pread64(fd, scsi_get_in_buffer(cmd), length,
ret = pread(fd, scsi_get_in_buffer(cmd), length,
offset);

if (ret != length)
Expand Down Expand Up @@ -278,7 +278,7 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
break;
}

ret = pread64(fd, tmpbuf, length, offset);
ret = pread(fd, tmpbuf, length, offset);

if (ret != length)
set_medium_error(cmd);
Expand Down
6 changes: 3 additions & 3 deletions usr/bs_ssc.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int append_blk(struct scsi_cmd *cmd, uint8_t *data,

/* Write any data */
if (size) {
ret = pwrite64(fd, data, size,
ret = pwrite(fd, data, size,
curr->curr + SSC_BLK_HDR_SIZE);
if (ret != size) {
eprintf("Write of data failed: %m\n");
Expand Down Expand Up @@ -349,7 +349,7 @@ static int resp_var_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
}
}

ret = pread64(cmd->dev->fd, buf, length, h->curr + SSC_BLK_HDR_SIZE);
ret = pread(cmd->dev->fd, buf, length, h->curr + SSC_BLK_HDR_SIZE);
if (ret != length) {
sense_data_build(cmd, MEDIUM_ERROR, ASC_READ_ERROR);
result = SAM_STAT_CHECK_CONDITION;
Expand Down Expand Up @@ -404,7 +404,7 @@ static int resp_fixed_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
goto out;
}

residue = pread64(fd, buf, block_length,
residue = pread(fd, buf, block_length,
h->curr + SSC_BLK_HDR_SIZE);
if (block_length != residue) {
eprintf("Could only read %d bytes, not %d\n",
Expand Down
8 changes: 4 additions & 4 deletions usr/libssc.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int ssc_read_mam_info(int fd, struct MAM_info *i)
if (ret != sizeof(struct MAM))
return 1;

if (lseek64(fd, SSC_1ST_HDR_OFFSET, SEEK_SET) != SSC_1ST_HDR_OFFSET)
if (lseek(fd, SSC_1ST_HDR_OFFSET, SEEK_SET) != SSC_1ST_HDR_OFFSET)
return 1;

SSC_GET_MAM_INFO_VAL(tape_fmt_version, 32);
Expand Down Expand Up @@ -176,7 +176,7 @@ int ssc_write_mam_info(int fd, struct MAM_info *i)
if (ret != sizeof(struct MAM))
return 1;

if (lseek64(fd, SSC_1ST_HDR_OFFSET, SEEK_SET) != SSC_1ST_HDR_OFFSET)
if (lseek(fd, SSC_1ST_HDR_OFFSET, SEEK_SET) != SSC_1ST_HDR_OFFSET)
return 1;

return 0;
Expand All @@ -188,7 +188,7 @@ int ssc_read_blkhdr(int fd, struct blk_header_info *i, loff_t offset)
struct blk_header h, *m = &h;
uint32_t crc = ~0;

count = pread64(fd, m, SSC_BLK_HDR_SIZE, offset);
count = pread(fd, m, SSC_BLK_HDR_SIZE, offset);
if (count != SSC_BLK_HDR_SIZE)
return 1;

Expand Down Expand Up @@ -225,7 +225,7 @@ int ssc_write_blkhdr(int fd, struct blk_header_info *i, loff_t offset)
crc = crc32c(crc, &m->ondisk_sz, SSC_BLK_HDR_SIZE - sizeof(m->h_csum));
*(uint32_t *)m->h_csum = ~crc;

count = pwrite64(fd, m, SSC_BLK_HDR_SIZE, offset);
count = pwrite(fd, m, SSC_BLK_HDR_SIZE, offset);
if (count != SSC_BLK_HDR_SIZE)
return 1;

Expand Down
5 changes: 2 additions & 3 deletions usr/sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#define _FILE_OFFSET_BITS 64
#define __USE_GNU

#include <errno.h>
Expand Down Expand Up @@ -52,15 +51,15 @@ static unsigned int blk_shift = DEFAULT_BLK_SHIFT;
static off_t find_next_data(struct scsi_lu *dev, off_t offset)
{
#ifdef SEEK_DATA
return lseek64(dev->fd, offset, SEEK_DATA);
return lseek(dev->fd, offset, SEEK_DATA);
#else
return offset;
#endif
}
static off_t find_next_hole(struct scsi_lu *dev, off_t offset)
{
#ifdef SEEK_HOLE
return lseek64(dev->fd, offset, SEEK_HOLE);
return lseek(dev->fd, offset, SEEK_HOLE);
#else
return dev->size;
#endif
Expand Down
4 changes: 3 additions & 1 deletion usr/tgtd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __TARGET_DAEMON_H
#define __TARGET_DAEMON_H

#include <limits.h>

#include "log.h"
#include "scsi_cmnd.h"
#include "tgtadm_error.h"
Expand Down Expand Up @@ -173,7 +175,7 @@ struct backingstore_template {
void (*bs_exit)(struct scsi_lu *dev);
int (*bs_cmd_submit)(struct scsi_cmd *cmd);
int bs_oflags_supported;
unsigned long bs_supported_ops[NR_SCSI_OPCODES / __WORDSIZE];
unsigned long bs_supported_ops[NR_SCSI_OPCODES / LONG_BIT];

struct list_head backingstore_siblings;
};
Expand Down
2 changes: 1 addition & 1 deletion usr/tgtimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static int ssc_new(int op, char *path, char *barcode, char *capacity,
h->blk_type = BLK_EOD;
h->blk_num = 1;
h->prev = 0;
h->next = lseek64(fd, 0, SEEK_CUR);
h->next = lseek(fd, 0, SEEK_CUR);
h->curr = h->next;

ret = ssc_write_blkhdr(fd, h, h->next);
Expand Down
4 changes: 2 additions & 2 deletions usr/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ int chrdev_open(char *modname, char *devpath, uint8_t minor, int *fd)
int backed_file_open(char *path, int oflag, uint64_t *size, uint32_t *blksize)
{
int fd, err;
struct stat64 st;
struct stat st;

fd = open(path, oflag);
if (fd < 0) {
eprintf("Could not open %s, %m\n", path);
return fd;
}

err = fstat64(fd, &st);
err = fstat(fd, &st);
if (err < 0) {
eprintf("Cannot get stat %d, %m\n", fd);
goto close_fd;
Expand Down
6 changes: 3 additions & 3 deletions usr/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ void concat_buf_release(struct concat_buf *b);
*/
static inline int unmap_file_region(int fd, off_t offset, off_t length)
{
struct stat64 st;
if (fstat64(fd, &st) < 0)
struct stat st;
if (fstat(fd, &st) < 0)
return -1;
if (S_ISREG(st.st_mode)) {
#ifdef FALLOC_FL_PUNCH_HOLE
Expand All @@ -199,7 +199,7 @@ static inline int unmap_file_region(int fd, off_t offset, off_t length)
return -1;
}

#define BITS_PER_LONG __WORDSIZE
#define BITS_PER_LONG LONG_BIT
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))

Expand Down
Loading